olexale / arkit_flutter_plugin

ARKit Flutter Plugin
MIT License
796 stars 225 forks source link

Arkit bugged #142

Closed maxTeste closed 3 years ago

maxTeste commented 3 years ago

@olexale I'm using this plugin and change it a bit, so i changed the plugin a bit and how it works is: when i open the plugin it will make the plane and for the object to appear I have to click on the area i want it. The 3d object is only 1 dae file, that have everything in it, dont need more files like the idleFixed.dae. But the plugin has a bug which is that: it loads the 3D object but doesn't load the textures of the object. I tested the code with the custom_object_page.dart and it works fine, but as I said I changed the code and when showing the object it comes without textures. already tested with iphone 7 and ipad.

same object with the code from custom_object_page.dart works 100% same object with the code bellow, the textures don't work:

code that I use and don't load the textures of object :

import 'package:arkit_plugin/arkit_plugin.dart'; import 'package:flutter/material.dart'; import 'package:vector_math/vector_math_64.dart' as vector; import "dart:math" as math;

class CustomObjectPage extends StatefulWidget { @override _CustomObjectPageState createState() => _CustomObjectPageState(); }

class _CustomObjectPageState extends State { ARKitController arkitController; ARKitReferenceNode node; String anchorId; ARKitNode nodePanoDourado = null, boxNode; ARKitPlane plane;

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

@override Widget build(BuildContext context) => Scaffold( appBar: AppBar(title: const Text('Custom object on plane Sample')), body: Container( child: ARKitSceneView( showFeaturePoints: false, planeDetection: ARPlaneDetection.horizontal, //onARKitViewCreated: onARKitViewCreated, enableTapRecognizer: true,

        enablePinchRecognizer: true,
        enablePanRecognizer: true,
        enableRotationRecognizer: true,
        detectionImagesGroupName: "AR Resources",
        onARKitViewCreated: onARKitViewCreated,
        autoenablesDefaultLighting: false,
        maximumNumberOfTrackedImages: 1,
      ),
    ),
  );

void onARKitViewCreated(ARKitController arkitController) { this.arkitController = arkitController; //this.arkitController.onAddNodeForAnchor = _handleAddAnchor; this.arkitController.onNodePan = (pan) => _onPanHandler(pan); this.arkitController.onUpdateNodeForAnchor = _handleUpdateAnchor;

this.arkitController.onARTap = (ar) {
  final point = ar.firstWhere(
        (o) => o.type == ARKitHitTestResultType.featurePoint,
    orElse: () => null,
  );
  if (point != null) {
    _onARTapHandler(point);
  }
};

}

void _handleUpdateAnchor(ARKitAnchor anchor) { if (anchor.identifier != anchorId) { return; } final ARKitPlaneAnchor planeAnchor = anchor; nodePanoDourado.position = vector.Vector3(planeAnchor.center.x, 0, planeAnchor.center.z); //print("55555555"); plane.width.value = planeAnchor.extent.x; plane.height.value = planeAnchor.extent.z; //print("333333333");

}

void _onPanHandler(List pan) { final panNode = pan.firstWhere((e) => boxNode.name == boxNode.name, orElse: null);

if (panNode != null) {
  final old = boxNode.eulerAngles;
  final newAngleX = panNode.translation.x * math.pi / 180;
  boxNode.eulerAngles = vector.Vector3(newAngleX, old.y, old.z);
}

}

void _onARTapHandler(ARKitTestResult point) { final position = vector.Vector3( point.worldTransform.getColumn(3).x, point.worldTransform.getColumn(3).y, point.worldTransform.getColumn(3).z, );

ARKitReferenceNode node = ARKitReferenceNode(
  //url: 'models.scnassets/dash.dae',
  url: 'models.scnassets/30.dae',
  scale: vector.Vector3.all(0.02),
  position:vector.Vector3(
      position.x,
      position.y,
      position.z
  ),
);
this.arkitController.add(node);

}

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

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

sikandernoori commented 3 years ago

I had Similar Issue when I Started Working on this Plugin, which I overcame eventually It's not a Bug, It has something todo with Settings on scn in XCODE when you add file to SCENE xcassets and than adding proper Light in scene.

That's how I fixed it.

maxTeste commented 3 years ago

resolved. property in relation to light when creating ARKitSceneView