Access and Modify Shapekeys (morphTargetDictionary) in script

Hi there,

I’ve searched for the answer but I couldn’t find a proper answer.
I just imported a .glb file into the scene and trying to access the shapekeys to write an script for talking. (speech synthesis)
However I am unable to find the Morph Targets inside the entity object.

Is there anyway for me to do that?
If there is none, how may i have to do the talking synthesis?


You can access it this way if you use render components and have an entity that contains the render component which has a mesh with morphing:

const renderInstance = entity.render.meshInstances[0].morphInstance

index 0 is just an example … you might want to loop over meshInstances and find the one with morphInstance.

and then you can use setWeight on it: MorphInstance | PlayCanvas API Reference

and example is here … even though this one creates the morph data as well:

You can also try this in the model viewer which uses the PlayCanvas engine, and exposes all morph weights as sliders: PlayCanvas glTF Viewer

1 Like

Thanks for your reply.

I had some issues with the imported GLB file.
so now, i can see some objects in renderInstance.

here is the code i use to log shape key names:

    for(let i = 0; i < entity.children.length; i++){
            let meshInst = entity.children[i].render.meshInstances;
            for(let j = 0; j < meshInst.length; j++){
                let morphInst = meshInst[j].morphInstance;
                if (morphInst) {
                    let targets = morphInst.morph.targets;

The problem is that the name of the shape keys on the base_body (which is the main object of the body, which face shape keys exist on) are changed to a number (like index numbers starting from 0 to last_index) instead of the shape key’s name.

On another object (like Brow) shape key names are correct. However the object I’d like to work on is base_body.