3D long hair with head/shoulders torsion
Hi there,
I'm trying to reproduce this type of simulation with 3d mesh hair:
https://lens.snapchat.com/b91e037064334bb78f9aa807d231d2d7
By following this tutorial on the Snap AR channel, I managed to have pretty decent result, and I customized a bit the code to adjust the position of the mesh depending on a empty scene object. My only problem is, I don't manage to adjust the Z position correctly and the mesh seems to be in front of the face as we can see a gap between when I turn my head. Adjusting the Z value results in the overall size becoming smaller, but the gap remains. Is there something I could do about it, or a better technic to achieve this effect?
Thanks
bellow is the code I'm using:
// -----JS CODE-----
// @input SceneObject binding
// @input SceneObject root
// @input SceneObject head
// @input SceneObject nullObj
var bindingTransform = script.binding.getTransform();
var rootTransform = script.root.getTransform();
var rootOriginPosition = rootTransform.getWorldPosition();
var headTransform = script.head.getTransform();
var headOriginRotation = headTransform.getWorldRotation();
var shiftTransform = script.nullObj.getTransform();
function onUpdate()
{
var bindingPos = bindingTransform.getWorldPosition();
var shiftPos = shiftTransform.getWorldPosition();
var pos = bindingPos.add(shiftPos);
rootTransform.setWorldPosition(pos);
var bindingRot = bindingTransform.getWorldRotation();
var rot = bindingRot.multiply(headOriginRotation);
headTransform.setWorldRotation(rot);
}
var updateEvent = script.createEvent("UpdateEvent");
updateEvent.bind(onUpdate);
I would just add a head binding and use that as the parent for you hair. Unless you need to process the position/rotation information, I don't see a need to do the tracking via a script.
The neck attachments tutorial needs a script because you don't want the necklace to track the head rotation, just the head position (with an offset).
Thanks for your feedback modelsbymike3d !
I'm doing this so the hairs resting on the shoulders are not rotating with the head, as in the example filter I posted. If I just put my mesh in the head binding, it will then rotate with the head which is weird...
Gotcha. What I recommend is adjusting the position as needed and then playing with the scale. Your gap could be due to a head occluder (which I'm assuming you are using). The head occluder does not perfectly match the head (even if you use the head mesh for the occluder) so a small gap is to be expected. Unless it is glaringly obvious, users are pretty forgiving of small imperfections because that is just the current state of AR.
Can you provide any screenshots of what the gap looks like and how your scene is setup in Lens Studio?
Hey modelsbymike3d, thanks a lot for your help
As I was taking somne screenshots, I realised that the problem is the mesh is somehow not following at all the binding on the z axis. As I move my head closer or further, you can see the gap I'm talking about is becoming bigger or smaller.
I made a simple project with just that feature to try to debug it, here is how it looks:
Something really strange also, is when I go from my webcam to the multimedia preview in lens studio, the hair is completely off, I cannot set it to be correctly placed for both. I never had this problem before
It seems the mesh is in a completely diffrent 3D space than my head binding...
I'm not sure what the difference between the binding and head inputs are, but when I create a simple scene the script does work to track the cube to the head and the offset is working. It might have to do with the position of your camera or some other parent of the hair. In my simple scene with nearly no scene hierarchy everything is working.
thanks, I will try with an even more simple scene to understand what's going on