GLTFExporter Bug - MorphTargetAnimations Break Export
See original GitHub issueBug
Any exported scene with Morph Target animations not targeting the root node will fail. In my case it was an animation with multiple meshes each with Morph Targets and each having tracks for each of their Morph Target influences.
See Lines (1593-1597):
if ( trackProperty === PATH_PROPERTIES.morphTargetInfluences ) {
outputItemSize /= trackNode.morphTargetInfluences.length;
}
You end up getting an error “cannot get length of undefined” from the middle line (1595). Because the trackNode var will always point to the root node of your export rather than the node actually being targeted by that animation track.
This is because the function GLTFExporter.Utils.mergeMorphTargetTracks() will always set a merged morphTargetTrack name to “.morphTargetInfluences”.
In turn, when this track is processed, the trackBinding var gets malformed where all properties are undefined except for the propertyName which is equal to “morphTargetInfluences”. Then the trackNode var tries to find the node by checking the trackBinding.nodeName which is undefined, causing the trackNode to always default to the root node of the export.
var trackNode = THREE.PropertyBinding.findNode( root, trackBinding.nodeName );
Any exported scene with Morph Target animations not targeting the root node will fail. This is why.
Fix
I figured out a two line fix for this. But my understanding of merged morphtarget tracks is slim.
On line 2256 (currently blank). Add:
mergedTrack["targetCount"]=targetCount;
And then change line 1595 to:
outputItemSize /= track.targetCount;
Basically all this fix does is add the MorphTargetInfluences length (previously calculated for the targetCount var) to the merged MorphTarget track. Then we are able to reference the appropriate morphTargetInfluence length when the merged track is being processed, even though we don’t have a reference to the correct node.
If anyone has any insight for a better fix. Please let me know you’re up for taking a stab at it. Otherwise I’ll submit this fix as a PR.
I think ideally I’d like an export option for not merging morphtarget tracks, but that will be it’s own Feature Request post.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (7 by maintainers)
Top GitHub Comments
Filed to https://github.com/KhronosGroup/glTF/issues/1675 – feel free to comment there if my summary missed anything!
Hey @abelnation I’m going to make a PR for this tonight. I’m not sure it will solve your issue though as this change is specific to the GLTFExporter lib.
If you want to screenshot the console errors you get, I can confirm and also possibly address related problems in other parts of the codebase. Great to see other people doing more advanced morph target programming in threejs.