我正在努力按照示例使用 ArCore 加载我自己的模型。我找到了以下代码:
ModelRenderable.builder()
// To load as an asset from the 'assets' folder ('src/main/assets/andy.sfb'):
.setSource(this, Uri.parse("andy.sfb"))
// Instead, load as a resource from the 'res/raw' folder ('src/main/res/raw/andy.sfb'):
//.setSource(this, R.raw.andy)
.build()
.thenAccept(renderable -> andyRenderable = renderable)
.exceptionally(
throwable -> {
Log.e(TAG, "Unable to load Renderable.", throwable);
return null;
});
但是我在任何地方都找不到 ModelRenderable 类以及如何导入它。另外,我正在构建应用程序的示例应用程序加载如下模型:
virtualObject.createOnGlThread(/*context=*/ this, "models/andy.obj", "models/andy.png");
virtualObject.setMaterialProperties(0.0f, 2.0f, 0.5f, 6.0f);
但是我的模型没有 png 文件,只有 obj 和 mtl。自动场景表单还创建了 sfa 和 sfb 文件。 哪一种是正确的做法?
最佳答案
这里有关于启动模型的官方文档供引用:https://developers.google.com/ar/develop/java/sceneform#renderables
ModelRenderable
是
com.google.ar.sceneform:core
库,您可以通过将此依赖项添加到您的应用程序级别 build.gradle
来添加它:
implementation 'com.google.ar.sceneform:core:1.13.0'
确保所有其他 arcore/sceneform 依赖项都位于同一版本,在本例中为 1.13.0 。
sfa
的含义是 SceneFormAsset,它以人类可读的形式表示您的模型详细信息,并且不会成为您的应用程序的一部分(它应该位于同一层次结构级别的示例文件夹中)作为您的 src 文件夹)。然而,sfb 是 SceneFormBinary,每次修改 sfa 中的某些内容并构建项目时,都会从 sfa 描述符生成此二进制文件。 sfb 文件应该位于项目的 asset 文件夹中。对于模型加载,您应该使用 sfb
文件:
ModelRenderable.builder()
.setSource(context, Uri.parse("house.sfb"))
关于您的示例代码:如果您不熟悉 OpenGL,我不建议您遵循该示例,最好寻找 SceneForm,这里是一个示例应用程序:https://github.com/google-ar/sceneform-android-sdk/tree/master/samples/solarsystem
关于android - 在 Android Studio 中使用 ArCore 加载模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58749800/