We have a character in our scene that has morphTargets to animate its face. The problem is that once we change to another scene with the same character, the face can no longer be animated. After some digging I was able to find out that once the last entity that holds the render asset gets destroyed, all morph targets of the asset are cleared via this function inside the class Morph:
Steps to reproduce this issue:
Add 2 entities with a render component to a scene which both have the same render asset.
find the render asset in the console via pc.app.assets.get(assetId)
renderAsset.resource.meshes[0].morph.targets is an array which holds all morph targets
destroy one of the entities, renderAsset.resource.meshes[0].morph.targets still holds all morph targets
destroy the second entity, now renderAsset.resource.meshes[0].morph.targets is an empty array
How can I get the morph targets back? I tried reloading the asset via the asset registry, but that didn’t work?
Hi @yaustar . I’m a colleague of @AliMoe , so if you can send me a pm I would send you the link to the model we are testing this. (Or I’ll send it to you per email).
I executed each line seperately in the chrome dev tools console, so naturally there were a lot of frames between each function call. And I didn’t get a not defined error, but I was able to look at the targets array. It was empty
I also tried it like this to trigger this process when changing scenes, but without success:
I think I would need a repro to really know for sure on what’s going there. The example project I have with the egg doesn’t have an issue with morph targets not loading.
The order doesn’t matter as if the asset is already loaded, the callback in ready is called immediately.
Can you add me to the project in which it is working for you? Maybe I’m just missing something pretty obvious.
I’m trying to use the morph targets like this:
var meshInstance = this.entity.render.meshInstances[0];
var targetCount = meshInstance.morphInstance.morph.targets.length;
this.entity.render.meshInstances.forEach((meshInstance) => {
for (let i = 0; i < targetCount; i++) {
meshInstance.morphInstance.setWeight(i, weights[i]);
}
});
There are no errors when executing this code, but targetCount is 0, so no weights will be set. Even if I set it to weights.length, the morph targets are not loaded again
I don’t think there are any playcanvas frames if you’re stepping lines in the debugger … the application is paused in the debugger and does not handle loading of assets.
@mvaligursky I know, but thats why I said I executed these steps in the Chrome Dev Tool Console I didn’t stop the execution of the application with the debugger
Press 1 to destroy the entity (see right side of mouth moving)
Press 2 to create it again (notice no morph target animation)
Press 1 to destroy the entity
Press 3 to reload the asset
Wait a bit
Press 2 to create the entity (see right side of mouth moving)