简体   繁体   中英

How can I build with Flutter and ARKit a custom object?

I use the plugin arkit_plugin with the version 1.0.5 https://pub.dev/packages/arkit_plugin

My Flutter version is 2.5.3

The plugin has an example in it's documentation for custom objects. Therefore I copy pasted the example to test it. In my case the object is not showing at all. It is a.dae file and I tried it with a.obj file too but it didn't work either.

class ArkitSceneView extends StatefulWidget {
  const ArkitSceneView({Key? key}) : super(key: key);

  @override
  State<ArkitSceneView> createState() => _ArkitSceneViewState();
}

class _ArkitSceneViewState extends State<ArkitSceneView> {
  late ARKitController arkitController;
  ARKitReferenceNode? node;

  @override
  void dispose() {
    arkitController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return ARKitSceneView(
        onARKitViewCreated: onARKitViewCreated
    );
  }

  void onARKitViewCreated(ARKitController arkitController) {
    this.arkitController = arkitController;
    arkitController.addCoachingOverlay(CoachingOverlayGoal.horizontalPlane);
    arkitController.onAddNodeForAnchor = _handleAddAnchor;
  }

  void _handleAddAnchor(ARKitAnchor anchor) {
    if (anchor is ARKitPlaneAnchor) {
      _addPlane(arkitController, anchor);
    }
  }

  void _addPlane(ARKitController controller, ARKitPlaneAnchor anchor) {
    if (node != null) {
      controller.remove(node!.name);
    }
    node = ARKitReferenceNode(
      url: 'models.scnassets/dash.dae',
      scale: vector.Vector3.all(0.3),
    );
    controller.add(node!, parentNodeName: anchor.nodeName);
  }
}

Did you try to place your model in Xcode? Like this- 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM