我正在尝试将RajawaliSurfaceView
与地球演示渲染器叠加在Google Vision Face Tracker sample上。
我用它来使背景透明:
rajawaliSurfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT);
这是我活动的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:surfaceview="http://schemas.android.com/apk/res-auto"
android:id="@+id/topLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">
<com.google.android.gms.samples.vision.face.facetracker.ui.camera.CameraSourcePreview
android:id="@+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.samples.vision.face.facetracker.ui.camera.GraphicOverlay
android:id="@+id/faceOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.google.android.gms.samples.vision.face.facetracker.ui.camera.CameraSourcePreview>
<org.rajawali3d.surface.RajawaliSurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rajawali_surface"
android:layout_gravity="left|top" />
</FrameLayout>
它编译没有问题,但我没有看到Google Demo项目中的3d模型或FaceGraphic。 尝试在Android Studio中预览布局xml时,我也遇到此错误:
java.lang.NullPointerException
at android.opengl.GLSurfaceView.onResume(GLSurfaceView.java:562)
at org.rajawali3d.surface.RajawaliSurfaceView.onResume(RajawaliSurfaceView.java:106)
at org.rajawali3d.surface.RajawaliSurfaceView.onVisibilityChanged(RajawaliSurfaceView.java:116)
at android.view.View.dispatchAttachedToWindow(View.java:14537)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:42)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:232)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:426)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:510)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:498)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:498)
at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:610)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:607)
at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:366)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:607)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:629)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:652)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:80)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:594)
at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:152)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:452)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:137)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:589)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:351)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
更新1:
我删除了这一行(rajawaliSurfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT);
),希望至少看到3D场景,但没有任何改变,我仍然只看到相机预览。
然而,当我从任何地方恢复应用程序时,我会在相机预览开始前看到旋转的地球一小段时间。
根据this answer,它应该像我预期的那样工作。我该怎么办?
更新2:
(使用this教程)
确定 - 添加行rajawaliSurfaceView.setZOrderOnTop(true);
会在我的相机预览中显示3D场景,但我仍然遇到问题。
无论
rajawaliSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
rajawaliSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
,也不
rajawaliSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
rajawaliSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);
只清除场景的背景。 我总是得到一个完全透明的SurfaceView。我有什么想法可以解决这个问题吗?
(显然xml错误似乎只是一种轻微的麻烦,我不得不忽略。)