如何在 flutter 运行时生成 Sceneform 资产

How to generate a Sceneform asset at runtime in flutter

我是 Flutter 新手,目前正在开发基于 AR 的应用程序。我想在运行时创建可渲染的 3d Sceneform 资产。我知道如何在 build.gradle 文件中定义 Sceneform 资产,但它不是动态的。

编译中制作3d sceneform asset的方法(app级build.gradle):

sceneform.asset('sampledata/earth.obj',
        'default',
        'sampledata/earth.sfa',
        'src/main/assets/earth_model')

但我想在运行时创建一个 sceneform 资产。我正在使用 arcore_flutter_plugin and Google's AR core with sceneform. I am unable to find any assistance/examples to render a 3d sceneform asset at runtime from firebase storage in flutter. All of the documentations available are for java and kotlin. The purpose of rendering sceneform assets at runtime is to load a .sfb file from firebase storage 并在应用程序中呈现它以保持应用程序的轻量级。

如果您深入研究文档文档,您会发现带有参数 objectUrl 的 class ArCoreReferenceNode https://pub.dev/documentation/arcore_flutter_plugin/latest/arcore_flutter_plugin/ArCoreReferenceNode/objectUrl.html.

我将从example app code

final toucanNode = ArCoreReferenceNode(
    name: "Toucano",
    objectUrl:
            "https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/Duck/glTF/Duck.gltf",
    position: plane.pose.translation,
    rotation: plane.pose.rotation,
);

arCoreController.addArCoreNodeWithAnchor(toucanNode);