2

enter image description hereI am trying to use ar_flutter_plugin. In the flutter example on pub.dev they are using a gltb file as 3D Object named Chicken_01.gltb which is working correctly. But when I tried other gltb files after downloading from internet, they are not working, even no other object is working whether I provider link or as a local object. Somebody also raised this same issue on their github repo page. I have tried many things, but I am not able to understand what's going on with this. Please help

Note: I want to do this for android.

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

  @override
  State<LocalAndWebObjectsView> createState() => _LocalAndWebObjectsViewState();
}

class _LocalAndWebObjectsViewState extends State<LocalAndWebObjectsView> {
  late ARSessionManager arSessionManager;
  late ARObjectManager arObjectManager;

//String localObjectReference;
  ARNode? localObjectNode;

//String webObjectReference;
  ARNode? webObjectNode;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Local / Web Objects"),
      ),
      body: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 10),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            SizedBox(
              height: MediaQuery.of(context).size.height * .8,
              child: ClipRRect(
                borderRadius: BorderRadius.circular(22),
                child: Container(
                  color: Colors.black,
                  child: ARView(
                    onARViewCreated: onARViewCreated,
                  ),
                ),
              ),
            ),
            Row(
              children: [
                Expanded(
                  child: ElevatedButton(
                      onPressed: () {
                        onLocalObjectButtonPressed();
                      },
                      child: const Text("Add / Remove Local Object")),
                ),
                const SizedBox(
                  width: 10,
                ),
                Expanded(
                  child: ElevatedButton(
                      onPressed: () {
                        onWebObjectAtButtonPressed();
                      },
                      child: const Text("Add / Remove Web Object")),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  void onARViewCreated(
    ARSessionManager arSessionManager,
    ARObjectManager arObjectManager,
    ARAnchorManager arAnchorManager,
    ARLocationManager arLocationManager,
  ) {
    this.arSessionManager = arSessionManager;
    this.arObjectManager = arObjectManager;

    this.arSessionManager.onInitialize(
          showFeaturePoints: false,
          showPlanes: true,
          customPlaneTexturePath: "triangle.png",
          showWorldOrigin: true,
          handleTaps: false,
        );

    this.arObjectManager.onInitialize();
  }

  Future<void> onLocalObjectButtonPressed() async {

    if (localObjectNode != null) {
      arObjectManager.removeNode(localObjectNode!);
      localObjectNode = null;
    } else {

      var newNode = ARNode(
          type: NodeType.localGLTF2,
          uri: "assets/Chicken_01/Chicken_01.gltf",
          scale: vec.Vector3(0.2, 0.2, 0.2),
          position: vec.Vector3(0.0, 0.0, 0.0),
          rotation: vec.Vector4(1.0, 0.0, 0.0, 0.0));

      bool? didAddLocalNode = await arObjectManager.addNode(newNode);
      localObjectNode = (didAddLocalNode!) ? newNode : null;
    }
  }

  Future<void> onWebObjectAtButtonPressed() async {
    if (webObjectNode != null) {
      arObjectManager.removeNode(webObjectNode!);
      webObjectNode = null;
    } else {
      var newNode = ARNode(
          type: NodeType.webGLB,
          uri:
              "https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/Duck/glTF-Binary/Duck.glb",
          scale: vec.Vector3(0.2, 0.2, 0.2));
      bool? didAddWebNode = await arObjectManager.addNode(newNode);
      webObjectNode = (didAddWebNode!) ? newNode : null;
    }
  }
}

The Error I have attached the 3d object files and the error screenshot which is coming when pressing the button to show the object.

  • 1
    Did you solve the problem please? I'm facing the same issue. Can you share with me a solution? – Mounir Dec 13 '22 at 10:51
  • 1
    @Mounir I couldn't solve this problem for the offline ones. But for the files from Github, we have to turn on the "raw" flag by adding the "?raw=true" after the url. You can see the discussion here - https://github.com/CariusLars/ar_flutter_plugin/discussions/31 – Sapinder Singh Dec 15 '22 at 02:36

1 Answers1

0

Make sure that the folder that contains your specific .gltf file also has the corresponding .bin file. You don't have to access it in the "uri" attribute just make sure it is present. So, the reason "Chicken_01.gltf" works is most likely because the folder "Chicken_01" also has the corresponding "Chicken_01.bin" file.