Skip to content
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

Mesh .updateMorphTargets(): Added BufferGeometry support #11285

Merged
merged 5 commits into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/api/core/BufferAttribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ <h3>[property:Boolean isBufferAttribute]</h3>
<h3>[property:Integer itemSize]</h3>
<div>The length of vectors that are being stored in the [page:BufferAttribute.array array].</div>

<h3>[property:String name]</h3>
<div>
Optional name for this attribute instance. Default is an empty string.
</div>

<h3>[property:Boolean needsUpdate]</h3>
<div>
Expand Down
1 change: 1 addition & 0 deletions examples/js/loaders/MMDLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ THREE.MMDLoader.prototype.createMesh = function ( model, texturePath, onProgress
var params = { name: m.name };

var attribute = new THREE.Float32BufferAttribute( model.metadata.vertexCount * 3, 3 );
attribute.name = m.name;

for ( var j = 0; j < model.metadata.vertexCount * 3; j++ ) {

Expand Down
1 change: 1 addition & 0 deletions examples/js/loaders/sea3d/SEA3DLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2876,6 +2876,7 @@ THREE.SEA3D.prototype.readMorpher = function ( sea ) {
var node = sea.node[ i ];

attribs.position[ i ] = new THREE.Float32BufferAttribute( node.vertex, 3 );
attribs.position[ i ].name = node.name;

if ( node.normal ) {

Expand Down
1 change: 1 addition & 0 deletions src/core/BufferAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function BufferAttribute( array, itemSize, normalized ) {
}

this.uuid = _Math.generateUUID();
this.name = '';

this.array = array;
this.itemSize = itemSize;
Expand Down
50 changes: 43 additions & 7 deletions src/objects/Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,53 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {

updateMorphTargets: function () {

var morphTargets = this.geometry.morphTargets;
var geometry = this.geometry;
var m, ml, name;

if ( morphTargets !== undefined && morphTargets.length > 0 ) {
if ( geometry.isBufferGeometry ) {

this.morphTargetInfluences = [];
this.morphTargetDictionary = {};
var morphAttributes = geometry.morphAttributes;
var keys = Object.keys( morphAttributes );

for ( var m = 0, ml = morphTargets.length; m < ml; m ++ ) {
if ( keys.length > 0 ) {

this.morphTargetInfluences.push( 0 );
this.morphTargetDictionary[ morphTargets[ m ].name ] = m;
var morphAttribute = morphAttributes[ keys[ 0 ] ];

if ( morphAttribute !== undefined ) {

this.morphTargetInfluences = [];
this.morphTargetDictionary = {};

for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {

name = morphAttribute[ m ].name || m;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be a good idea to make sure the name is always a string? Or do you think it doesn't matter?

Copy link
Collaborator Author

@Mugen87 Mugen87 May 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe it's cleaner if we always ensure strings. I'll change this 👍


this.morphTargetInfluences.push( 0 );
this.morphTargetDictionary[ name ] = m;

}

}

}

} else {

var morphTargets = geometry.morphTargets;

if ( morphTargets !== undefined && morphTargets.length > 0 ) {

this.morphTargetInfluences = [];
this.morphTargetDictionary = {};

for ( m = 0, ml = morphTargets.length; m < ml; m ++ ) {

name = morphTargets[ m ].name || m;

this.morphTargetInfluences.push( 0 );
this.morphTargetDictionary[ name ] = m;

}

}

Expand Down