Hi all,
We are trying to animate avatar eye blink, for this we exported avatar from blender in glb format by selecting avatar “shape keys” while exporting, but we are unable to find the method to simulate eye blinks. pls suggest
Thanks
vij
Hi all,
We are trying to animate avatar eye blink, for this we exported avatar from blender in glb format by selecting avatar “shape keys” while exporting, but we are unable to find the method to simulate eye blinks. pls suggest
Thanks
vij
@vijay_krishna, in looking at your scene, all of the morph targets you need are in your mesh. If you look at the mesh containing the morph targets - head or eyelashes - you will see all of the morph target gradients in the inspector. You can set these values through animations or by directly setting the gradient value in code. It appears that your eyelashes have their own morph targets so you will need to run animations on both the head and eyelashes simultaneously so that they stay in sync. It does appear, however, this version of your mesh does not have all of the morph targets on the eyelashes because there were no morph targets to blink the left eyelashes. This would need to be fixed in Blender.
To get access to your morph targets in code, you simply need to create a morph target manager and load the morphs from the mesh. Once you have the morphs, you can use them as a target of an animation. Here is an example of animating a morph target imported from a mesh where we are blending animations coming from the glTF itself and adding extra animation to blend between the morph targets in time with the animation in the glTF.
These resources should get you unblocked, but please feel free to ping back if you have more questions.
Thanks @PatrickRyan for stepping-in…
Tried with yur logic, am stuck while reading the exact morph target…
Maybe i need yur help here
@PatrickRyan we can ignore eyelashes for a while and try only get eyeblinks
am unable to get eyeblink animation by adjusting the Morph parameters as well
Is something am missing ?
@vijay_krishna, I was looking into your scene, but now I am getting an access denied error on your glb file. If you can update your PG or share a link to it, I can continue debugging.
@vijay_krishna, here is the working version of your playground. There were a few differences between your asset and the one that was loaded in the previous example I shared, so let me go through the process you would need for a more complex model like this one.
Animation keys
The values in the keys you pass will be the exact animation curves you want to play, so you will need to modify the animation keys as you need for the animation you wish to play on your morphs.
Mesh array
In the original example, there were three meshes that all needed the same operations done to them so I created an array of the meshes to apply the same actions to each. In your case, unless you can group different meshes that have similar naming conventions, you likely won’t need an array to iterate through. It may be more readable to just hold each mesh that has morphs that need to be animated in a constant rather than needing to iterate an array.
Mesh Target
You will need to create an array to hold like targets, in this case the left and right eye blink. However, you will have to plan out how you are grouping your targets as there may be actions where you need to assign the same animation to several targets like blinking or raising eyebrows. There will be others like a wink where you will want to have isolated targets, so I would think carefully about what actions your character will go through to help organize your targets. In this example, since we were only making the character blink, I just used a quick array to hold them.
Animation Group
Whenever you need to be playing animations at the same time that need to sync, like blinking, you will want to put the animations into an animation group. Then you can call play, pause, stop, etc on the group and all morphs will be affected at once and always be in sync.
Getting the targets for the morphs
Here you will want to iterate through the mesh.morphTargetManager._targets
and look for the targets by name. In our case, the ones we wanted have “Blink” as a part of their name. But you may need to be more prescriptive in searching for the correct target. Once we find the targets that match the strings we are looking for, we use mesh.morphTargetManager.getTarget(index)
to assign the targets to our array.
Play Animation
We just need to create an animation per target at this point. We pass each target we found in the previous step to a new animation with the “influence” property as the animation target. We also pass the animation group that will hold both eye blink animations. Once we have all of the animations in the group, we call animationGroup.start()
on the group which will synchronize the animations for both eyes.
I commented heavily on the PG, so you should be able to follow what is going on. However, if you have more questions, please feel free to reach out.
Thanks @PatrickRyan for yur time and efforts
I understand that shared different glb file actually was trying different ways… Will be using eyeblinks during walking animation, as u said will use Animation Group to play simultaneously
you helped me in my difficult times…
once again thnk u so much…
trying to get eyeblinks some where am making mistake.
can somebody throw some light …
Might be nothing, but eyelids are on the head. There is an error in the console where the headMesh is said to be null:
BJS - [14:23:20]: Unable to load from https://fashion-desings.s3.ap-south-1.amazonaws.com/common/casuals/tshirts/userchoice/tshirt_walking.glb: Error in onSuccess callback: TypeError: headMesh is null
done…