Closed tugkan84 closed 4 years ago
Hi, the custom model node isn't different from any other node, hence you may combine "custom object" and "face detection" samples. There is a great "3D Overlay" sample from Apple, which might help.
Regards, Oleksandr
Thank you so much. I will check it. I tried to put it together but I guess I'm doing something wrong. If I can find a solution, I'll share it.
Best Regards, Birkan
I had a problem with the model. I handle it Oleksandr, It works like a charm. Thank you very much.
Hi Birkan, It will great if you share the solution you got? Thank see.
I wrote that I hope it will work for you.
import 'dart:developer';
import 'package:arkit_plugin/arkit_plugin.dart'; import 'package:arkit_plugin/widget/arkit_scene_view.dart'; import 'package:flutter/material.dart'; import 'package:vector_math/vector_math_64.dart' as vector;
class ARfacemask extends StatefulWidget { @override _ARfacemaskState createState() => _ARfacemaskState(); }
class _ARfacemaskState extends State
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('ArFaceMask'), ), body: ARKitSceneView( configuration: ARKitConfiguration.faceTracking, onARKitViewCreated: (c) => onArKitViewCreated(c), )); }
void onArKitViewCreated(ARKitController c) { this.arKitController = c; this.arKitController.onAddNodeForAnchor = _handleAddAnchor; this.arKitController.onUpdateNodeForAnchor = _handleUpdateAnchor;
// final node = ARKitNode(
// geometry:
// // ARKitBox(height: 0.1, length: 0.1, width: 0.1),
// ARKitSphere(radius: 1, materials: [
// ARKitMaterial(
// diffuse: ARKitMaterialProperty(image: 'images/house.jpg'),
// doubleSided: true,
// )
// ]),
// position: Vector3.zero(),
// );
// c.add(node);
}
void _handleAddAnchor(ARKitAnchor anchor) { if (!(anchor is ARKitFaceAnchor)) { return; } // final material = ARKitMaterial(fillMode: ARKitFillMode.lines, diffuse: ARKitMaterialProperty(image: 'images/canada.jpg')); final ARKitFaceAnchor faceAnchor = anchor; // faceAnchor.geometry.materials.value = [material];
// anchorId = faceAnchor.identifier;
// node = ARKitNode(geometry: faceAnchor.geometry);
// arKitController.add(node, parentNodeName: faceAnchor.nodeName);
print('we are adding the object');
_createEye(faceAnchor.transform, faceAnchor);
}
void _handleUpdateAnchor(ARKitAnchor anchor) { if (anchor is ARKitFaceAnchor) { final ARKitFaceAnchor faceAnchor = anchor; arKitController.updateFaceGeometry(node, anchor.identifier); arKitController.updateFaceGeometry(referenceNode, anchor.identifier); } }
void _createEye(Matrix4 transform, ARKitAnchor anchor) { final position = vector.Vector3( transform.getColumn(3).x, transform.getColumn(3).y, transform.getColumn(3).z, ); referenceNode = ARKitReferenceNode( url: 'models.scnassets/mask.dae', position: vector.Vector3(-0.5,-1,-9), scale: vector.Vector3(0.18, 0.18, 0.18), renderingOrder: -1, eulerAngles: vector.Vector3(1,1,1), );
print(referenceNode);
arKitController.add(referenceNode, parentNodeName: anchor.nodeName);
} }
Hi, I tried to add a custom .dae model like a medical face mask to face but I couldn't. Do you have any example or solution for that?
Thank you, Birkan