2017-08-30 27 views
2

私はUnityで作成したテクスチャにARCoreカメラフィードを表示しようとしていますが、正しく動作させる方法を理解することはできません。ARCoreカメラフィードをUnityテクスチャに描画する

私はこのようなユニティで私のテクスチャを作成しました:

Texture2D unityTexture = new Texture2D(
     480, 
     640, 
     TextureFormat.RGBA32, 
     false); 
unityTexture.filterMode = FilterMode.Point; 
unityTexture.Apply(); 

そして私はTexture2D#GetNativeTexturePtr()によって返された値を使用してJavaに私のテクスチャID上を通過します。私のJavaでは

は、私は次のようにテクスチャを設定しよう:

この方法で
// Called from Unity layer when camera texture is created. 
    public void setUnityCameraTexture(long texId, int width, int height) { 
    int textureId = (int) textId; 
    mSession.setCameraTextureName(textureId); 
    mSession.setDisplayGeometry(width, height); 
    } 

... 

    // Called on each Unity MonoBehaviour.Update(). 
    public void renderFrame() { 
    try { 
     mSession.update(); 
    } catch (CameraException e) { 
     Log.w(TAG, "Error when updating session", e); 
    } 
    } 

、テクスチャが画面にレンダリングされていないと私は、次のエラーログ受信:

E GLConsumer: [SurfaceTexture-1337-7436-0] bindTextureImage: error binding external image: 0x502 
E tango_camera_native: Couldn't get image exposure/skew for timestamp offset! 
E ndk_camera: metadata has: 780757.577090 
E ndk_camera: metadata has: 780757.890735 
E ndk_camera: metadata has: 780757.924221 
E ndk_camera: metadata has: 780757.957402 
E ndk_camera: metadata has: 780757.990704 
E ndk_camera: metadata has: 780758.024007 
E ndk_camera: metadata has: 780758.057341 
E ndk_camera: metadata has: 780758.090735 
E ndk_camera: metadata has: 780758.124007 
E ndk_camera: metadata has: 780758.157341 
E ndk_camera: metadata has: 780758.190613 
E ndk_camera: metadata has: 780758.223977 
E ndk_camera: metadata has: 780758.257432 
E ndk_camera: metadata has: 780758.290643 
E ndk_camera: metadata has: 780758.323946 
E ndk_camera: metadata has: 780758.349104 
W tango_camera_native_jni: jint Java_com_google_tango_jni_TangoCameraNative_UpdateTextureExternalOes(JNIEnv*, jobject, int, int, jdoubleArray): Got a negative timestamp -0.000000 from camera with id 0. 
I Unity : AndroidJavaException: java.lang.RuntimeException: Error during updateTexImage (see logcat for details) 
I Unity : java.lang.RuntimeException: Error during updateTexImage (see logcat for details) 
I Unity :  at android.graphics.SurfaceTexture.nativeUpdateTexImage(Native Method) 
I Unity :  at android.graphics.SurfaceTexture.updateTexImage(SurfaceTexture.java:244) 
I Unity :  at com.google.tango.jni.TangoCameraNative.UpdateTextureExternalOes(Native Method) 
I Unity :  at com.google.tango.jni.TangoCameraNative.updateTextureExternalOes(TangoCameraNative.java:222) 
I Unity :  at com.google.tango.loader.ITangoCameraNative$Stub.onTransact(ITangoCameraNative.java:162) 
I Unity :  at android.os.Binder.transact(Binder.java:499) 
I Unity :  at com.google.tango.loader.ITangoCameraNative$Stub$Proxy.updateTextureExternalOes(ITangoCameraNative.java:436) 
I Unity :  at com.google.atap.tangoservice.TangoCameraNativeLoader.updateTextureExternalOes(TangoCameraNativeLoader.java:178) 
I Unity :  at com.google.atap.tangoservice.Tango.updateTextureExternalOes(Tango.java:512) 
I Unity :  at com.google.ar.core.TangoWrapper.updateTextureExternalOes(Tan 

テクスチャを正しく設定していないのかどうか分かりませんが、助けてくれれば幸いです!

答えて

1

私は適切にテクスチャを設定していませんでした。 ARCore documentationでは、テクスチャをglGenTextures(int, int[], int)で作成し、GL_TEXTURE_EXTERNAL_OESターゲットにバインドする必要があると記載しています。 Unityにテクスチャの作成を許可するのではなく、今度はJavaレイヤーでテクスチャを作成してGL_TEXTURE_EXTERNAL_OESにバインドしてから、テクスチャIDをUnityに渡します。

私のJavaは今、何かのようになります、私もアクセスカスタムユニティGLSLシェーダを作成する必要がありましたこれらの変更に加えて

// Called on Unity Start() 
public Texture2D GetCameraTexture() { 
    IntPtr textureId = GetCameraTextureId(); 
    Texture2D cameraTexture = Texture2D.CreateExternalTexture(
     1080, 
     1920, 
     TextureFormat.RGBA32, 
     false, 
     false, 
     GetTextureId()); 
    return cameraTexture; 
} 

private IntPtr GetCameraTextureId() { 
    // Calls into Java getTextureName method. 
} 

// Called on app resume. 
public void resume() { 
    mSession.resume(mConfig); 
    mSession.setCameraTextureName(mTextureName[0]); 
} 

// Called on each Unity MonoBehaviour.Update(). 
public void renderFrame() { 
    try { 
    mSession.update(); 
    } catch (CameraException e) { 
    Log.w(TAG, "Error when updating session", e); 
    } 
} 

public int getTextureName() { 
    mTextureName = new int[1]; 
    GLES20.glGenTextures(1, mTextureName, 0); 
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureName[0]); 
    return mTextureName[0]; 
} 

そして、私のユニティスクリプトでテクスチャをsamplerExternalOESサンプラーを使用して使用し、それを使用して自分のGameObjectの1つにテクスチャを表示します。これはdocumentationの要件としても指定されています。

+0

あなたは仕事を分かち合えますか?私はあなたがそれをどのようにしたのか見たいと思いますか? –

関連する問題