-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BufferGeometry with morphAttributes does not create mesh with morphTargetInfluences #11277
Comments
The following version of updateMorphTargets: function () {
var geometry = this.geometry;
if ( geometry.isBufferGeometry ) {
var morphAttributes = geometry.morphAttributes;
var keys = Object.keys( morphAttributes );
if ( keys.length > 0 ) {
var morphAttribute = morphAttributes[ keys[ 0 ] ];
if ( morphAttribute !== undefined ) {
this.morphTargetInfluences = [];
for ( var i = 0, l = morphAttribute.length; i < l; i ++ ) {
this.morphTargetInfluences.push( 0 );
}
}
}
} else {
var morphTargets = geometry.morphTargets;
if ( morphTargets !== undefined && morphTargets.length > 0 ) {
this.morphTargetInfluences = [];
this.morphTargetDictionary = {};
for ( var m = 0, ml = morphTargets.length; m < ml; m ++ ) {
this.morphTargetInfluences.push( 0 );
this.morphTargetDictionary[ morphTargets[ m ].name ] = m;
}
}
}
}, |
It looks to me as if MMDLoader is using a similar hack - it's essentially doing bufferGeometry.morphTargets = [];
bufferGeometry.morphTargets.push( morph.name ); https://github.com/mrdoob/three.js/blob/dev/examples/js/loaders/MMDLoader.js#L861, where The problem (or at least one problem!) is that these names are then used to create the Which would be easily solved if |
Correct!
I like the idea because we won't break stuff and it's easy to implement. @mrdoob, @WestLangley What's your opinion about this? |
I've created a PR so we can better see the changes... |
@looeee With the new PR the creation of a morph attribute looks like this: const morphAttribute = new THREE.BufferAttribute( morphPositions, 3 );
morphAttribute.name = 'base'; // optional, .morphTargetDictionary will always be created with default names
geometry.morphAttributes.position.push( morphAttribute ); |
Sweet! 😁 |
If I create a buffer geometry and add a position morph attribute, then create a mesh from it, the mesh doesn't have a morphTargetInfluences property so I can't animate the morph.
Workaround is to add a fake morphTarget to the geometry:
See this pen:
http://codepen.io/looeee/pen/YVxaKL?editors=0010
The text was updated successfully, but these errors were encountered: