【问题标题】:Black screen after loading SceneView, using Scenform, into a fragment使用Scenform将SceneView加载到片段后黑屏
【发布时间】:2020-05-29 21:01:08
【问题描述】:

我正在开展一个项目,该项目将在一个片段中包含一个 3D 模型查看器。为了做到这一点,我决定使用sceneform。在我的标签片段中尝试显示 SceneView 后,我遇到了问题。

一切都是按照示例和sceneform文档完成的,但是sceneView显示黑屏,不管我分配什么颜色。

这里是场景加载器

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        vw = inflater.inflate(R.layout.fragment_open_gl, container, false);
        sceneView = vw.findViewById(R.id.scene_view);
        return vw;
    }

还有片段:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".OpenGL">

    <com.google.ar.sceneform.SceneView
        android:id="@+id/scene_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/Crimson"/>

</FrameLayout>

【问题讨论】:

    标签: android 3d augmented-reality sceneform


    【解决方案1】:

    我通过添加暂停和恢复场景视图以及片段解决了这个问题:

        @Override
        public void onPause() {
            super.onPause();
            sceneView.pause();
        }
    
        @Override
        public void onResume() {
            super.onResume();
            try {
                sceneView.resume();
            } catch (CameraNotAvailableException e) {
                e.printStackTrace();
            }
        }
    

    【讨论】:

    • 太糟糕了,我现在才发现它。在将场景表单作为 UI 组件实现到 RN 中时遇到了同样的问题,并在上​​面浪费了大量时间。对于将来看到的任何人,如果您没有 onResume 方法在您的实现中覆盖,您必须 sceneView.resume !卡米尔你本可以救我的命。遗憾的是,我只是在弄清楚之后才偶然发现这一点。无论如何,谢谢:)
    • 非常有帮助的答案。
    • 我已经尝试过了,但这对我不起作用,请你看看stackoverflow.com/questions/65125461/…
    • 我遇到了同样的问题,我将背景颜色更改为白色并放置节点,它开始完美运行
    • 这个修复了黑屏,但是FrameLayout在调用sceneView.pause()时有内存泄漏
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-06
    • 2015-04-17
    相关资源
    最近更新 更多