olexale / arkit_flutter_plugin

ARKit Flutter Plugin
MIT License
797 stars 225 forks source link

Distance + Plane Sample App - Vector3 issue #106

Closed OliverNarramore closed 3 years ago

OliverNarramore commented 3 years ago

On the sample apps for distance with plane detection, or simply the plane detection sample project, I am receiving the following error:

A value of type 'Vector3' can't be assigned to a variable of type 'ValueNotifier'. Try changing the type of the variable, or casting the right-hand type to 'ValueNotifier'

It affects the following snippets in the distance with plane detection project:

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

and

void _drawText(String text, vector.Vector3 point) { final textGeometry = ARKitText( text: text, extrusionDepth: 1, materials: [ ARKitMaterial( diffuse: ARKitMaterialProperty(color: Colors.red), ) ], ); const scale = 0.001; final vectorScale = vector.Vector3(scale, scale, scale); final node = ARKitNode( geometry: textGeometry, position: point, scale: vectorScale, ); arkitController .getNodeBoundingBox(node) .then((List<vector.Vector3> result) { final minVector = result[0]; final maxVector = result[1]; final dx = (maxVector.x - minVector.x) / 2 * scale; final dy = (maxVector.y - minVector.y) / 2 * scale; final position = vector.Vector3( node.position.x - dx, node.position.y - dy, node.position.z, ); node.position = position; }); arkitController.add(node); }

archonn commented 3 years ago

I think it's because of ARKitNode's attributes changed to ValueNotifier. I solved it by updating the ValueNotifier's value instead of directly assigning a new value.

Try this.

node.position.value = vector.Vector3(planeAnchor.center.x, 0, planeAnchor.center.z);
olexale commented 3 years ago

Thanks @archonn ! As far as I understood the issue is resolved, hence I'm closing the ticket. Feel free to re-open it if it's needed.