Search code examples
spark-ar-studio

Constrain facemesh to 3D object in SparkAR


I am trying to constrain a facemesh to a 3D object so that it will rotate around the surface of the 3D object in response to the face tracker instead of moving off to the side. Currently, the facemesh is a child of the cylinder, but is not attached to it in a way that would rotate around the cylinder surface.

faceMesh on 3D object

Currently, I am attempting to use the bounding box patch to determine the area to clamp the face mesh to. So far, the mesh is related to the 3D object bounding box, but will not constrain to its surface. Adjustment to the clamp patch variables will move the face mesh within the space, but not constrain it either.

Patch pt 1 Patch pt 2


Solution

  • The answer is much simpler than I first attempted. Using the patch editor:

    • Unpack the 3D rotation from the facefinder.
    • take the from range from the X and Y positions
    • look at the maximum and minimum ranges of the face tracker rotation/position values to set To and From Ranges
    • create a null object and make it a child of the stationary 3D object
    • make the face mesh a child of the null object
    • connect the output of the face tracker's rotation/position to the rotation/position value of the null object.