我正在尝试RajawaliSurfaceView
用 Earth Demo-Renderer 覆盖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 场景,但没有任何改变,我仍然只看到相机预览。
但是,当从任何地方恢复应用程序时,在相机预览开始之前,我看到旋转的地球只有几分之一秒。
根据这个答案,它应该像我预期的那样工作。我需要做什么?
更新2:(
使用本教程)
好的 - 添加线条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 错误似乎只是我不得不忽略的轻微烦恼。)