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

SkinnedMesh: support weight normalization for BufferGeometry #7679

Merged
merged 3 commits into from
Nov 26, 2015
Merged
Changes from all 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
33 changes: 29 additions & 4 deletions src/objects/SkinnedMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {

if ( this.geometry instanceof THREE.Geometry ) {

for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
for ( var i = 0; i < this.geometry.skinWeights.length; i ++ ) {

var sw = this.geometry.skinWeights[ i ];

Expand All @@ -109,15 +109,40 @@ THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {

} else {

sw.set( 1 ); // this will be normalized by the shader anyway
sw.set( 1, 0, 0, 0 ); // do something reasonable

}

}

} else {
} else if ( this.geometry instanceof THREE.BufferGeometry ) {

var vec = new THREE.Vector4();

var skinWeight = this.geometry.attributes.skinWeight;

for ( var i = 0; i < skinWeight.count; i ++ ) {

vec.x = skinWeight.getX( i );
vec.y = skinWeight.getY( i );
vec.z = skinWeight.getZ( i );
vec.w = skinWeight.getW( i );

var scale = 1.0 / vec.lengthManhattan();

if ( scale !== Infinity ) {

// skinning weights assumed to be normalized for THREE.BufferGeometry
vec.multiplyScalar( scale );

} else {

vec.set( 1, 0, 0, 0 ); // do something reasonable

}

skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );

}

}

Expand Down