提交 5b967be2 编写于 作者: A Arseny Kapoulkine

Implement basic support for morphTargetsRelative

This adds the attribute and the necessary plumbing for various JS
functions; there's no support for specifying this for the shader to
consume yet.
上级 c2cf0d97
...@@ -40,6 +40,7 @@ export class BufferGeometry extends EventDispatcher { ...@@ -40,6 +40,7 @@ export class BufferGeometry extends EventDispatcher {
morphAttributes: { morphAttributes: {
[name: string]: ( BufferAttribute | InterleavedBufferAttribute )[]; [name: string]: ( BufferAttribute | InterleavedBufferAttribute )[];
}; };
morphTargetsRelative: boolean;
groups: { start: number; count: number; materialIndex?: number }[]; groups: { start: number; count: number; materialIndex?: number }[];
boundingBox: Box3; boundingBox: Box3;
boundingSphere: Sphere; boundingSphere: Sphere;
......
...@@ -37,6 +37,7 @@ function BufferGeometry() { ...@@ -37,6 +37,7 @@ function BufferGeometry() {
this.attributes = {}; this.attributes = {};
this.morphAttributes = {}; this.morphAttributes = {};
this.morphTargetsRelative = false;
this.groups = []; this.groups = [];
...@@ -596,8 +597,17 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy ...@@ -596,8 +597,17 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
var morphAttribute = morphAttributesPosition[ i ]; var morphAttribute = morphAttributesPosition[ i ];
_box.setFromBufferAttribute( morphAttribute ); _box.setFromBufferAttribute( morphAttribute );
this.boundingBox.expandByPoint( _box.min ); if ( this.morphTargetsRelative ) {
this.boundingBox.expandByPoint( _box.max );
this.boundingBox.expandByVector( _box.min );
this.boundingBox.expandByVector( _box.max );
} else {
this.boundingBox.expandByPoint( _box.min );
this.boundingBox.expandByPoint( _box.max );
}
} }
...@@ -645,8 +655,17 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy ...@@ -645,8 +655,17 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
var morphAttribute = morphAttributesPosition[ i ]; var morphAttribute = morphAttributesPosition[ i ];
_boxMorphTargets.setFromBufferAttribute( morphAttribute ); _boxMorphTargets.setFromBufferAttribute( morphAttribute );
_box.expandByPoint( _boxMorphTargets.min ); if ( this.morphTargetsRelative ) {
_box.expandByPoint( _boxMorphTargets.max );
_box.boundingBox.expandByVector( _boxMorphTargets.min );
_box.boundingBox.expandByVector( _boxMorphTargets.max );
} else {
_box.expandByPoint( _boxMorphTargets.min );
_box.expandByPoint( _boxMorphTargets.max );
}
} }
...@@ -674,11 +693,19 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy ...@@ -674,11 +693,19 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) { for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
var morphAttribute = morphAttributesPosition[ i ]; var morphAttribute = morphAttributesPosition[ i ];
var morphTargetsRelative = this.morphTargetsRelative;
for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) { for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
_vector.fromBufferAttribute( morphAttribute, j ); _vector.fromBufferAttribute( morphAttribute, j );
if ( morphTargetsRelative ) {
_offset.fromBufferAttribute( position, j );
_vector.add( _offset );
}
maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector ) ); maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector ) );
} }
...@@ -1055,7 +1082,12 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy ...@@ -1055,7 +1082,12 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
} }
if ( hasMorphAttributes ) data.data.morphAttributes = morphAttributes; if ( hasMorphAttributes ) {
data.data.morphAttributes = morphAttributes;
data.data.morphTargetsRelative = this.morphTargetsRelative;
}
var groups = this.groups; var groups = this.groups;
...@@ -1167,6 +1199,8 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy ...@@ -1167,6 +1199,8 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
} }
this.morphTargetsRelative = source.morphTargetsRelative;
// groups // groups
var groups = source.groups; var groups = source.groups;
......
...@@ -173,6 +173,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), { ...@@ -173,6 +173,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
var index = geometry.index; var index = geometry.index;
var position = geometry.attributes.position; var position = geometry.attributes.position;
var morphPosition = geometry.morphAttributes.position; var morphPosition = geometry.morphAttributes.position;
var morphTargetsRelative = geometry.morphTargetsRelative;
var uv = geometry.attributes.uv; var uv = geometry.attributes.uv;
var uv2 = geometry.attributes.uv2; var uv2 = geometry.attributes.uv2;
var groups = geometry.groups; var groups = geometry.groups;
...@@ -201,7 +202,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), { ...@@ -201,7 +202,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
b = index.getX( j + 1 ); b = index.getX( j + 1 );
c = index.getX( j + 2 ); c = index.getX( j + 2 );
intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, uv, uv2, a, b, c ); intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
if ( intersection ) { if ( intersection ) {
...@@ -226,7 +227,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), { ...@@ -226,7 +227,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
b = index.getX( i + 1 ); b = index.getX( i + 1 );
c = index.getX( i + 2 ); c = index.getX( i + 2 );
intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, uv, uv2, a, b, c ); intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
if ( intersection ) { if ( intersection ) {
...@@ -259,7 +260,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), { ...@@ -259,7 +260,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
b = j + 1; b = j + 1;
c = j + 2; c = j + 2;
intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, uv, uv2, a, b, c ); intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
if ( intersection ) { if ( intersection ) {
...@@ -284,7 +285,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), { ...@@ -284,7 +285,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
b = i + 1; b = i + 1;
c = i + 2; c = i + 2;
intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, uv, uv2, a, b, c ); intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
if ( intersection ) { if ( intersection ) {
...@@ -388,7 +389,7 @@ function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ...@@ -388,7 +389,7 @@ function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point
} }
function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, uv, uv2, a, b, c ) { function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c ) {
_vA.fromBufferAttribute( position, a ); _vA.fromBufferAttribute( position, a );
_vB.fromBufferAttribute( position, b ); _vB.fromBufferAttribute( position, b );
...@@ -413,9 +414,19 @@ function checkBufferGeometryIntersection( object, material, raycaster, ray, posi ...@@ -413,9 +414,19 @@ function checkBufferGeometryIntersection( object, material, raycaster, ray, posi
_tempB.fromBufferAttribute( morphAttribute, b ); _tempB.fromBufferAttribute( morphAttribute, b );
_tempC.fromBufferAttribute( morphAttribute, c ); _tempC.fromBufferAttribute( morphAttribute, c );
_morphA.addScaledVector( _tempA.sub( _vA ), influence ); if ( morphTargetsRelative ) {
_morphB.addScaledVector( _tempB.sub( _vB ), influence );
_morphC.addScaledVector( _tempC.sub( _vC ), influence ); _morphA.addScaledVector( _tempA, influence );
_morphB.addScaledVector( _tempB, influence );
_morphC.addScaledVector( _tempC, influence );
} else {
_morphA.addScaledVector( _tempA.sub( _vA ), influence );
_morphB.addScaledVector( _tempB.sub( _vB ), influence );
_morphC.addScaledVector( _tempC.sub( _vC ), influence );
}
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册