getMorphTarget via key value instead of index value

Hey there,

I have been trying to set morph target influences manually given a list of targets with their corresponding values.

The issue I am having is that my list of morphTargets has a different order and also a different length, so it would be easier to do mesh.morphTargetManager.getTarget(name of morph target) rather than passing the index. Is it possible to do this in Babylon.js?

Hello @r0bert0 , how are you doing?

Can you provide a Playground example of what you are trying to achieve?

Hey, I am good thanks I hope you are well.

This playground is a good example of what I am trying to do: https://playground.babylonjs.com/#WGZLGJ#3267

On line 27: we use .getTarget(1) i.e. an index value but I want to do something like:.getTarget(“name of morph target”) for example “Blink Right Eye”.

Thank you very much for the playground example @r0bert0!

You are right, at the moment the MorphTargetManager class only supports assigning by index. However, you can use the name information to find the appropriate target. I updated your playground example for doing exactly that:

glTF Loader Demo | Babylon.js Playground (babylonjs.com)

Depending on how many morph target you have in your model this can give you a performance hit, but if you will be always updating the same model maybe you can use a dictionary to store the target names and indexes as shown in this other example:

glTF Loader Demo | Babylon.js Playground (babylonjs.com)

1 Like

Thank you @srzerbetto for the code examples. This is helps me a lot. I will try to use your ideas for my morph targets :slight_smile:

1 Like