|
@@ -1185,44 +1185,37 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
if ( hasMorphPosition ) {
|
|
if ( hasMorphPosition ) {
|
|
|
|
|
|
- var positionAttribute;
|
|
|
|
|
|
+ // Three.js morph formula is
|
|
|
|
+ // position
|
|
|
|
+ // + weight0 * ( morphTarget0 - position )
|
|
|
|
+ // + weight1 * ( morphTarget1 - position )
|
|
|
|
+ // ...
|
|
|
|
+ // while the glTF one is
|
|
|
|
+ // position
|
|
|
|
+ // + weight0 * morphTarget0
|
|
|
|
+ // + weight1 * morphTarget1
|
|
|
|
+ // ...
|
|
|
|
+ // then adding position to morphTarget.
|
|
|
|
+ // So morphTarget value will depend on mesh's position, then cloning attribute
|
|
|
|
+ // for the case if attribute is shared among two or more meshes.
|
|
|
|
+
|
|
|
|
+ var positionAttribute = cloneBufferAttribute( geometry.attributes.position );
|
|
|
|
|
|
if ( target.POSITION !== undefined ) {
|
|
if ( target.POSITION !== undefined ) {
|
|
|
|
|
|
- // Three.js morph formula is
|
|
|
|
- // position
|
|
|
|
- // + weight0 * ( morphTarget0 - position )
|
|
|
|
- // + weight1 * ( morphTarget1 - position )
|
|
|
|
- // ...
|
|
|
|
- // while the glTF one is
|
|
|
|
- // position
|
|
|
|
- // + weight0 * morphTarget0
|
|
|
|
- // + weight1 * morphTarget1
|
|
|
|
- // ...
|
|
|
|
- // then adding position to morphTarget.
|
|
|
|
- // So morphTarget value will depend on mesh's position, then cloning attribute
|
|
|
|
- // for the case if attribute is shared among two or more meshes.
|
|
|
|
-
|
|
|
|
- positionAttribute = cloneBufferAttribute( accessors[ target.POSITION ] );
|
|
|
|
- var position = geometry.attributes.position;
|
|
|
|
|
|
+ var morphPosition = accessors[ target.POSITION ];
|
|
|
|
|
|
for ( var j = 0, jl = positionAttribute.count; j < jl; j ++ ) {
|
|
for ( var j = 0, jl = positionAttribute.count; j < jl; j ++ ) {
|
|
|
|
|
|
positionAttribute.setXYZ(
|
|
positionAttribute.setXYZ(
|
|
j,
|
|
j,
|
|
- positionAttribute.getX( j ) + position.getX( j ),
|
|
|
|
- positionAttribute.getY( j ) + position.getY( j ),
|
|
|
|
- positionAttribute.getZ( j ) + position.getZ( j )
|
|
|
|
|
|
+ positionAttribute.getX( j ) + morphPosition.getX( j ),
|
|
|
|
+ positionAttribute.getY( j ) + morphPosition.getY( j ),
|
|
|
|
+ positionAttribute.getZ( j ) + morphPosition.getZ( j )
|
|
);
|
|
);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- // Copying the original position not to affect the final position.
|
|
|
|
- // See the formula above.
|
|
|
|
- positionAttribute = cloneBufferAttribute( geometry.attributes.position );
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
positionAttribute.name = attributeName;
|
|
positionAttribute.name = attributeName;
|
|
@@ -1232,30 +1225,25 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
if ( hasMorphNormal ) {
|
|
if ( hasMorphNormal ) {
|
|
|
|
|
|
- var normalAttribute;
|
|
|
|
|
|
+ // see target.POSITION's comment
|
|
|
|
|
|
- if ( target.NORMAL !== undefined ) {
|
|
|
|
|
|
+ var normalAttribute = cloneBufferAttribute( geometry.attributes.normal );
|
|
|
|
|
|
- // see target.POSITION's comment
|
|
|
|
|
|
+ if ( target.NORMAL !== undefined ) {
|
|
|
|
|
|
- normalAttribute = cloneBufferAttribute( accessors[ target.NORMAL ] );
|
|
|
|
- var normal = geometry.attributes.normal;
|
|
|
|
|
|
+ var morphNormal = geometry.attributes.normal;
|
|
|
|
|
|
for ( var j = 0, jl = normalAttribute.count; j < jl; j ++ ) {
|
|
for ( var j = 0, jl = normalAttribute.count; j < jl; j ++ ) {
|
|
|
|
|
|
normalAttribute.setXYZ(
|
|
normalAttribute.setXYZ(
|
|
j,
|
|
j,
|
|
- normalAttribute.getX( j ) + normal.getX( j ),
|
|
|
|
- normalAttribute.getY( j ) + normal.getY( j ),
|
|
|
|
- normalAttribute.getZ( j ) + normal.getZ( j )
|
|
|
|
|
|
+ normalAttribute.getX( j ) + morphNormal.getX( j ),
|
|
|
|
+ normalAttribute.getY( j ) + morphNormal.getY( j ),
|
|
|
|
+ normalAttribute.getZ( j ) + morphNormal.getZ( j )
|
|
);
|
|
);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- normalAttribute = cloneBufferAttribute( geometry.attributes.normal );
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
normalAttribute.name = attributeName;
|
|
normalAttribute.name = attributeName;
|