android - 如何使用 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
解决方案
我自己解决了。
将 glTF 的路径设置为绝对路径(如“/sdcard/BoxTextured.glb”,而不是“models/BoxTextured.glb”)
我认为它无法从该函数中找到(也没有转换)相对路径。
//assets/~
如果你想使用相对路径,你必须得到一个路径。
编辑:
此外,还有一个Environment
类有方法getExternalStorageDirectory().getAbsolutePath()
。我可能会解决上述问题。
推荐阅读
- abp - ABP/Swashbuckle - 使用 Swashbuckle CLI 生成 swagger 文档
- flutter - 如何实际检查 null 以符合 Dart 中的 Sound null-safety
- python - 我们可以将消息从 Pub/sub 主题拉到 Angular 吗?
- kubernetes - GCP - 我可以将 Compute Engine 用于生产 MySQL 数据库吗
- javascript - 是否可以使用 React '获取'元素样式并将其渲染到 DOM 上?
- javascript - reactjs中使用firebase身份验证的登录功能
- php - 我需要帮助使用 PHP/jQuery/AJAX 获取动态行数的 MySQL 数据
- javascript - 如何仅为 Javascript onclick 回调选择元素的背景空白?
- java - 在Java中为Oracle SQL IN子句将列表转换为字符串
- python - 要以交替方式将列表中的项目添加到两个新列表中,为什么这段代码不起作用?(它说 player_1 没有定义)