|
@@ -14,6 +14,10 @@ THREE.Projector = function () {
|
|
|
|
|
|
_renderData = { objects: [], sprites: [], lights: [], elements: [] },
|
|
_renderData = { objects: [], sprites: [], lights: [], elements: [] },
|
|
|
|
|
|
|
|
+ _vA = new THREE.Vector3(),
|
|
|
|
+ _vB = new THREE.Vector3(),
|
|
|
|
+ _vC = new THREE.Vector3(),
|
|
|
|
+
|
|
_vector3 = new THREE.Vector3(),
|
|
_vector3 = new THREE.Vector3(),
|
|
_vector4 = new THREE.Vector4(),
|
|
_vector4 = new THREE.Vector4(),
|
|
|
|
|
|
@@ -101,6 +105,27 @@ THREE.Projector = function () {
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ var projectVertex = function ( vertex ) {
|
|
|
|
+
|
|
|
|
+ var position = vertex.position;
|
|
|
|
+ var positionWorld = vertex.positionWorld;
|
|
|
|
+ var positionScreen = vertex.positionScreen;
|
|
|
|
+
|
|
|
|
+ positionWorld.copy( position ).applyMatrix4( _modelMatrix );
|
|
|
|
+ positionScreen.copy( positionWorld ).applyMatrix4( _viewProjectionMatrix );
|
|
|
|
+
|
|
|
|
+ var invW = 1 / positionScreen.w;
|
|
|
|
+
|
|
|
|
+ positionScreen.x *= invW;
|
|
|
|
+ positionScreen.y *= invW;
|
|
|
|
+ positionScreen.z *= invW;
|
|
|
|
+
|
|
|
|
+ vertex.visible = positionScreen.x >= -1 && positionScreen.x <= 1 &&
|
|
|
|
+ positionScreen.y >= -1 && positionScreen.y <= 1 &&
|
|
|
|
+ positionScreen.z >= -1 && positionScreen.z <= 1;
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+
|
|
var projectObject = function ( object ) {
|
|
var projectObject = function ( object ) {
|
|
|
|
|
|
if ( object.visible === false ) return;
|
|
if ( object.visible === false ) return;
|
|
@@ -197,19 +222,9 @@ THREE.Projector = function () {
|
|
for ( var v = 0, vl = vertices.length; v < vl; v ++ ) {
|
|
for ( var v = 0, vl = vertices.length; v < vl; v ++ ) {
|
|
|
|
|
|
_vertex = getNextVertexInPool();
|
|
_vertex = getNextVertexInPool();
|
|
|
|
+ _vertex.position.copy( vertices[ v ] );
|
|
|
|
|
|
- _vertex.positionWorld.copy( vertices[ v ] ).applyMatrix4( _modelMatrix );
|
|
|
|
- _vertex.positionScreen.copy( _vertex.positionWorld ).applyMatrix4( _viewProjectionMatrix );
|
|
|
|
-
|
|
|
|
- var invW = 1 / _vertex.positionScreen.w;
|
|
|
|
-
|
|
|
|
- _vertex.positionScreen.x *= invW;
|
|
|
|
- _vertex.positionScreen.y *= invW;
|
|
|
|
- _vertex.positionScreen.z *= invW;
|
|
|
|
-
|
|
|
|
- _vertex.visible = ! ( _vertex.positionScreen.x < -1 || _vertex.positionScreen.x > 1 ||
|
|
|
|
- _vertex.positionScreen.y < -1 || _vertex.positionScreen.y > 1 ||
|
|
|
|
- _vertex.positionScreen.z < -1 || _vertex.positionScreen.z > 1 );
|
|
|
|
|
|
+ projectVertex( _vertex );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -229,6 +244,48 @@ THREE.Projector = function () {
|
|
v2 = _vertexPool[ face.b ];
|
|
v2 = _vertexPool[ face.b ];
|
|
v3 = _vertexPool[ face.c ];
|
|
v3 = _vertexPool[ face.c ];
|
|
|
|
|
|
|
|
+ if ( material.morphTargets === true ) {
|
|
|
|
+
|
|
|
|
+ var morphTargets = geometry.morphTargets;
|
|
|
|
+ var morphInfluences = object.morphTargetInfluences;
|
|
|
|
+
|
|
|
|
+ var v1p = v1.position;
|
|
|
|
+ var v2p = v2.position;
|
|
|
|
+ var v3p = v3.position;
|
|
|
|
+
|
|
|
|
+ _vA.set( 0, 0, 0 );
|
|
|
|
+ _vB.set( 0, 0, 0 );
|
|
|
|
+ _vC.set( 0, 0, 0 );
|
|
|
|
+
|
|
|
|
+ for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
|
|
|
|
+
|
|
|
|
+ var targets = morphTargets[ t ].vertices;
|
|
|
|
+ var influence = morphInfluences[ t ];
|
|
|
|
+
|
|
|
|
+ _vA.x += ( targets[ face.a ].x - v1p.x ) * influence;
|
|
|
|
+ _vA.y += ( targets[ face.a ].y - v1p.y ) * influence;
|
|
|
|
+ _vA.z += ( targets[ face.a ].z - v1p.z ) * influence;
|
|
|
|
+
|
|
|
|
+ _vB.x += ( targets[ face.b ].x - v2p.x ) * influence;
|
|
|
|
+ _vB.y += ( targets[ face.b ].y - v2p.y ) * influence;
|
|
|
|
+ _vB.z += ( targets[ face.b ].z - v2p.z ) * influence;
|
|
|
|
+
|
|
|
|
+ _vC.x += ( targets[ face.c ].x - v3p.x ) * influence;
|
|
|
|
+ _vC.y += ( targets[ face.c ].y - v3p.y ) * influence;
|
|
|
|
+ _vC.z += ( targets[ face.c ].z - v3p.z ) * influence;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ v1.position.add( _vA );
|
|
|
|
+ v2.position.add( _vB );
|
|
|
|
+ v3.position.add( _vC );
|
|
|
|
+
|
|
|
|
+ projectVertex( v1 );
|
|
|
|
+ projectVertex( v2 );
|
|
|
|
+ projectVertex( v3 );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
_points3[ 0 ] = v1.positionScreen;
|
|
_points3[ 0 ] = v1.positionScreen;
|
|
_points3[ 1 ] = v2.positionScreen;
|
|
_points3[ 1 ] = v2.positionScreen;
|
|
_points3[ 2 ] = v3.positionScreen;
|
|
_points3[ 2 ] = v3.positionScreen;
|