首页 > 解决方案 > 如何使用 ARCore Android SDK 在 SceneViewer 上加载我的 glTF 文件

问题描述

我正在关注 Google 的文档(https://developers.google.com/ar/develop/java/scene-viewer#ar-only)。

我将 glTF 文件放在assets/models目录中(与 相同的位置Andy.obj

我尝试加载 glTF 2.0 文件(来自KhronosGroup Sample)但失败了:

    Intent sceneViewerIntent = new Intent(Intent.ACTION_VIEW);
    Uri intentUri =
            Uri.parse("https://arvr.google.com/scene-viewer/1.0").buildUpon()
                    .appendQueryParameter("file", "models/BoxTextured.glb")
                    .appendQueryParameter("mode", "ar_preferred")
                    .appendQueryParameter("title", "Untitled")
                    .build();
    sceneViewerIntent.setData(intentUri);
    sceneViewerIntent.setPackage("com.google.ar.core");
    startActivity(sceneViewerIntent);

在文档(上面链接)中,不知道如何编写代码以从本地加载 glTF。

我该怎么做才能在android中解决这个问题?

谢谢。

编辑:源码基于https://github.com/google-ar/arcore-android-sdk/tree/master/samples/hello_ar_java,我工作过HelloArActivity.java,ARCore Android SDK版本是1.17.0

标签: androidarcoregltfsceneview

解决方案


我自己解决了。

将 glTF 的路径设置为绝对路径(如“/sdcard/BoxTextured.glb”,而不是“models/BoxTextured.glb”)

我认为它无法从该函数中找到(也没有转换)相对路径。

//assets/~如果你想使用相对路径,你必须得到一个路径。


编辑:

此外,还有一个Environment类有方法getExternalStorageDirectory().getAbsolutePath()。我可能会解决上述问题。


推荐阅读