[在Android Studio中使用ArCore加载模型

问题描述 投票:1回答:1

我正在努力遵循示例以将自己的模型加载到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文件。哪一种是正确的方法?

android android-studio arcore
1个回答
4
投票
implementation 'com.google.ar.sceneform:core:1.13.0'

确保其他所有arcore / sceneform依赖项都在同一版本上,在本例中为1.13.0。

sfa的意思是SceneFormAsset,它以易于理解的形式表示您的模型详细信息,并且不属于您的应用程序(它应位于与src文件夹位于同一层次结构级别的samplefolder中)。 sfb是SceneFormBinary,每次您在sfa中修改某些内容并构建项目时,此二进制文件都是从sfa描述符生成的。 sfb文件应位于项目的资产文件夹中。对于模型加载,应使用sfb文件:

ModelRenderable.builder()
        .setSource(context, Uri.parse("house.sfb"))

关于您的示例代码:如果您不熟悉OpenGL,我不建议您遵循该示例,最好寻找SceneForm,这是一个示例应用程序:https://github.com/google-ar/sceneform-android-sdk/tree/master/samples/solarsystem

© www.soinside.com 2019 - 2024. All rights reserved.