提交 7ff4b5f1 编写于 作者: W WestLangley

SkinnedMesh: support weight normalization for BufferGeometry

上级 3895f7e4
...@@ -97,7 +97,7 @@ THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () { ...@@ -97,7 +97,7 @@ THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
if ( this.geometry instanceof THREE.Geometry ) { 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 ]; var sw = this.geometry.skinWeights[ i ];
...@@ -109,15 +109,40 @@ THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () { ...@@ -109,15 +109,40 @@ THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
} else { } else {
sw.set( 1 ); // this will be normalized by the shader anyway // do nothing
} }
} }
} 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 {
// do nothing
}
skinWeight.setXYZ( i, vec.x, vec.y, vec.z, vec.w )
}
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册