mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-09 04:56:01 +10:00
Reworking Scene Graph setup.
This commit is contained in:
@@ -53,11 +53,12 @@
|
||||
info.innerHTML = 'Drag to spin the cube';
|
||||
container.appendChild( info );
|
||||
|
||||
scene = new THREE.Scene();
|
||||
|
||||
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
|
||||
camera.position.y = 150;
|
||||
camera.position.z = 500;
|
||||
|
||||
scene = new THREE.Scene();
|
||||
scene.add( camera );
|
||||
|
||||
// Cube
|
||||
|
||||
|
||||
@@ -44,10 +44,12 @@
|
||||
container = document.createElement( 'div' );
|
||||
document.body.appendChild( container );
|
||||
|
||||
scene = new THREE.Scene();
|
||||
|
||||
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
|
||||
camera.position.z = 500;
|
||||
|
||||
scene = new THREE.Scene();
|
||||
camera.target = new THREE.Vector3();
|
||||
scene.add( camera );
|
||||
|
||||
var geometry = new THREE.CubeGeometry( 100, 100, 100 );
|
||||
var material = new THREE.MeshNormalMaterial();
|
||||
@@ -65,7 +67,6 @@
|
||||
mesh.rotation.y = Math.random() * 360 * ( Math.PI / 180 );
|
||||
mesh.matrixAutoUpdate = false;
|
||||
mesh.updateMatrix();
|
||||
|
||||
group.add( mesh );
|
||||
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@
|
||||
|
||||
// find intersections
|
||||
|
||||
camera.update();
|
||||
camera.updateMatrixWorld();
|
||||
|
||||
var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
var camera, scene, renderer;
|
||||
|
||||
var cube, plane, target = new THREE.Vector3();
|
||||
var cube, plane, objects = [];
|
||||
|
||||
var targetRotation = 0;
|
||||
var targetRotationOnMouseDown = 0;
|
||||
@@ -37,19 +37,15 @@
|
||||
var windowHalfX = window.innerWidth / 2;
|
||||
var windowHalfY = window.innerHeight / 2;
|
||||
|
||||
var moveForward = false,
|
||||
moveBackwards = false,
|
||||
moveUp = false,
|
||||
moveDown = false,
|
||||
moveLeft = false,
|
||||
moveRight = false,
|
||||
var moveForward = false;
|
||||
var moveBackwards = false;
|
||||
var moveLeft = false;
|
||||
var moveRight = false;
|
||||
var moveUp = false;
|
||||
var moveDown = false;
|
||||
|
||||
yawLeft = false,
|
||||
yawRight = false,
|
||||
pitchUp = false,
|
||||
pitchDown = false,
|
||||
rollLeft = false,
|
||||
rollRight = false;
|
||||
var targetMoveLeft = false;
|
||||
var targetMoveRight = false;
|
||||
|
||||
var debugContext;
|
||||
|
||||
@@ -65,6 +61,7 @@
|
||||
camera.position.x = 1000;
|
||||
camera.position.y = 1000;
|
||||
camera.position.z = 1000;
|
||||
camera.target = new THREE.Vector3( 0, 150, 0 );
|
||||
|
||||
scene = new THREE.Scene();
|
||||
|
||||
@@ -86,7 +83,7 @@
|
||||
geometry = new THREE.CubeGeometry( 100, 100, 100 );
|
||||
material = new THREE.MeshDepthMaterial( { near: 1, far: 2000 } );
|
||||
|
||||
for (var i = 0; i < 20; i ++ ) {
|
||||
for ( var i = 0; i < 20; i ++ ) {
|
||||
|
||||
cube = new THREE.Mesh( geometry, material );
|
||||
cube.overdraw = true;
|
||||
@@ -98,7 +95,9 @@
|
||||
cube.rotation.y = Math.random() * 200 - 100;
|
||||
cube.rotation.z = Math.random() * 200 - 100;
|
||||
|
||||
scene.add(cube);
|
||||
scene.add( cube );
|
||||
|
||||
objects.push( cube );
|
||||
|
||||
}
|
||||
|
||||
@@ -146,18 +145,16 @@
|
||||
|
||||
function onDocumentKeyDown( event ) {
|
||||
|
||||
switch( event.keyCode ) {
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
case 38: moveForward = true; break; // up
|
||||
case 40: moveBackwards = true; break; // down
|
||||
case 37: moveLeft = true; break; // left
|
||||
case 39: moveRight = true; break; // right
|
||||
case 65: yawLeft = true; break; // a
|
||||
case 68: yawRight = true; break; // d
|
||||
case 87: moveUp/*pitchUp*/ = true; break; // w
|
||||
case 83: moveDown/*pitchDown*/ = true; break; // s
|
||||
case 90: rollLeft = true; break; // z
|
||||
case 67: rollRight = true; break; // c
|
||||
case 87: moveUp = true; break; // w
|
||||
case 83: moveDown = true; break; // s
|
||||
case 65: targetMoveLeft = true; break; // a
|
||||
case 68: targetMoveRight = true; break; // d
|
||||
|
||||
}
|
||||
|
||||
@@ -165,18 +162,16 @@
|
||||
|
||||
function onDocumentKeyUp( event ) {
|
||||
|
||||
switch( event.keyCode ) {
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
case 38: moveForward = false; break; // up
|
||||
case 40: moveBackwards = false; break; // down
|
||||
case 37: moveLeft = false; break; // left
|
||||
case 39: moveRight = false; break; // right
|
||||
case 65: yawLeft = false; break; // a
|
||||
case 68: yawRight = false; break; // d
|
||||
case 87: moveUp/*pitchUp*/ = false; break; // w
|
||||
case 83: moveDown/*pitchDown*/ = false; break; // s
|
||||
case 90: rollLeft = false; break; // z
|
||||
case 67: rollRight = false; break; // c
|
||||
case 87: moveUp = false; break; // w
|
||||
case 83: moveDown = false; break; // s
|
||||
case 65: targetMoveLeft = false; break; // a
|
||||
case 68: targetMoveRight = false; break; // d
|
||||
|
||||
}
|
||||
|
||||
@@ -195,25 +190,19 @@
|
||||
|
||||
function render() {
|
||||
|
||||
if ( moveForward ) camera.position.z -= 10; // camera.moveZ( 10 );
|
||||
if ( moveBackwards ) camera.position.z += 10; // camera.moveZ( - 10 );
|
||||
if ( moveForward ) camera.position.z -= 10;
|
||||
if ( moveBackwards ) camera.position.z += 10;
|
||||
|
||||
if ( moveUp ) camera.position.y += 10; // camera.moveZ( 10 );
|
||||
if ( moveDown ) camera.position.y -= 10; // camera.moveZ( - 10 );
|
||||
if ( moveLeft ) camera.position.x -= 10;
|
||||
if ( moveRight ) camera.position.x += 10;
|
||||
|
||||
if ( moveLeft ) camera.position.x -= 10; // camera.moveX( - 10 );
|
||||
if ( moveRight ) camera.position.x += 10; // camera.moveX( 10 );
|
||||
if ( moveUp ) camera.position.y += 10;
|
||||
if ( moveDown ) camera.position.y -= 10;
|
||||
|
||||
if ( pitchUp ) camera.rotation.x += 0.01; // camera.rotateX( 1 );
|
||||
if ( pitchDown ) camera.rotation.x -= 0.01; // camera.rotateX( - 1 );
|
||||
if ( targetMoveLeft ) camera.target.x -= 10;
|
||||
if ( targetMoveRight ) camera.target.x += 10;
|
||||
|
||||
if ( yawLeft ) target.x -= 10; // camera.rotation.y += 0.01; // camera.rotateY( 1 );
|
||||
if ( yawRight ) target.x += 10; // camera.rotation.y -= 0.01; // camera.rotateY( - 1 );
|
||||
|
||||
if ( rollLeft ) camera.rotation.z += 0.01; // camera.rotateZ( 1 );
|
||||
if ( rollRight ) camera.rotation.z -= 0.01; // camera.rotateZ( - 1 );
|
||||
|
||||
camera.lookAt( target );
|
||||
camera.lookAt( camera.target );
|
||||
|
||||
debugContext.clearRect( - 256, - 256, 512, 512 );
|
||||
|
||||
@@ -228,14 +217,14 @@
|
||||
// camera
|
||||
|
||||
debugContext.moveTo( camera.position.x * 0.1, camera.position.z * 0.1 );
|
||||
debugContext.lineTo( target.x * 0.1, target.z * 0.1 );
|
||||
debugContext.lineTo( camera.target.x * 0.1, camera.target.z * 0.1 );
|
||||
debugContext.rect( camera.position.x * 0.1 - 5, camera.position.z * 0.1 - 5, 10, 10 );
|
||||
debugContext.rect( target.x * 0.1 - 5, target.z * 0.1 - 5, 10, 10 );
|
||||
debugContext.rect( camera.target.x * 0.1 - 5, camera.target.z * 0.1 - 5, 10, 10 );
|
||||
debugContext.rect( - 50, - 50, 100, 100 );
|
||||
|
||||
for ( var i = 1; i < scene.objects.length; i++ ) {
|
||||
for ( var i = 0; i < objects.length; i++ ) {
|
||||
|
||||
var object = scene.objects[i];
|
||||
var object = objects[ i ];
|
||||
|
||||
object.rotation.x += 0.01;
|
||||
object.rotation.y += 0.005;
|
||||
|
||||
@@ -38,15 +38,15 @@
|
||||
var windowHalfX = window.innerWidth / 2;
|
||||
var windowHalfY = window.innerHeight / 2;
|
||||
|
||||
var moveForward = false, moveBackwards = false,
|
||||
moveUp = false, moveDown = false,
|
||||
moveLeft = false, moveRight = false,
|
||||
var moveForward = false;
|
||||
var moveBackwards = false;
|
||||
var moveLeft = false;
|
||||
var moveRight = false;
|
||||
var moveUp = false;
|
||||
var moveDown = false;
|
||||
|
||||
yawLeft = false, yawRight = false,
|
||||
pitchUp = false, pitchDown = false,
|
||||
rollLeft = false, rollRight = false;
|
||||
|
||||
var target = new THREE.Vector3( 0, 150, 0 );
|
||||
var targetMoveLeft = false;
|
||||
var targetMoveRight = false;
|
||||
|
||||
var debugContext;
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
|
||||
camera.position.y = 150;
|
||||
camera.position.z = 400;
|
||||
camera.target = new THREE.Vector3( 0, 150, 0 );
|
||||
|
||||
scene = new THREE.Scene();
|
||||
|
||||
@@ -157,18 +158,16 @@
|
||||
|
||||
function onDocumentKeyDown( event ) {
|
||||
|
||||
switch( event.keyCode ) {
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
case 38: moveForward = true; break; // up
|
||||
case 40: moveBackwards = true; break; // down
|
||||
case 37: moveLeft = true; break; // left
|
||||
case 39: moveRight = true; break; // right
|
||||
case 65: yawLeft = true; break; // a
|
||||
case 68: yawRight = true; break; // d
|
||||
case 87: moveUp/*pitchUp*/ = true; break; // w
|
||||
case 83: moveDown/*pitchDown*/ = true; break; // s
|
||||
case 90: rollLeft = true; break; // z
|
||||
case 67: rollRight = true; break; // c
|
||||
case 87: moveUp = true; break; // w
|
||||
case 83: moveDown = true; break; // s
|
||||
case 65: targetMoveLeft = true; break; // a
|
||||
case 68: targetMoveRight = true; break; // d
|
||||
|
||||
}
|
||||
|
||||
@@ -176,18 +175,16 @@
|
||||
|
||||
function onDocumentKeyUp( event ) {
|
||||
|
||||
switch( event.keyCode ) {
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
case 38: moveForward = false; break; // up
|
||||
case 40: moveBackwards = false; break; // down
|
||||
case 37: moveLeft = false; break; // left
|
||||
case 39: moveRight = false; break; // right
|
||||
case 65: yawLeft = false; break; // a
|
||||
case 68: yawRight = false; break; // d
|
||||
case 87: moveUp/*pitchUp*/ = false; break; // w
|
||||
case 83: moveDown/*pitchDown*/ = false; break; // s
|
||||
case 90: rollLeft = false; break; // z
|
||||
case 67: rollRight = false; break; // c
|
||||
case 87: moveUp = false; break; // w
|
||||
case 83: moveDown = false; break; // s
|
||||
case 65: targetMoveLeft = false; break; // a
|
||||
case 68: targetMoveRight = false; break; // d
|
||||
|
||||
}
|
||||
|
||||
@@ -206,25 +203,19 @@
|
||||
|
||||
function render() {
|
||||
|
||||
if ( moveForward ) camera.position.z -= 5;
|
||||
if ( moveBackwards ) camera.position.z += 5;
|
||||
if ( moveForward ) camera.position.z -= 10;
|
||||
if ( moveBackwards ) camera.position.z += 10;
|
||||
|
||||
if ( moveUp ) camera.position.y += 5;
|
||||
if ( moveDown ) camera.position.y -= 5;
|
||||
if ( moveLeft ) camera.position.x -= 10;
|
||||
if ( moveRight ) camera.position.x += 10;
|
||||
|
||||
if ( moveLeft ) camera.position.x -= 5;
|
||||
if ( moveRight ) camera.position.x += 5;
|
||||
if ( moveUp ) camera.position.y += 10;
|
||||
if ( moveDown ) camera.position.y -= 10;
|
||||
|
||||
if ( pitchUp ) camera.rotation.x += 0.01;
|
||||
if ( pitchDown ) camera.rotation.x -= 0.01;
|
||||
if ( targetMoveLeft ) camera.target.x -= 10;
|
||||
if ( targetMoveRight ) camera.target.x += 10;
|
||||
|
||||
if ( yawLeft ) target.x -= 5;
|
||||
if ( yawRight ) target.x += 5;
|
||||
|
||||
if ( rollLeft ) camera.rotation.z += 0.01;
|
||||
if ( rollRight ) camera.rotation.z -= 0.01;
|
||||
|
||||
camera.lookAt( target );
|
||||
camera.lookAt( camera.target );
|
||||
|
||||
debugContext.clearRect( -256, -256, 512, 512 );
|
||||
|
||||
@@ -239,9 +230,9 @@
|
||||
// camera
|
||||
|
||||
debugContext.moveTo( camera.position.x * 0.1, camera.position.z * 0.1 );
|
||||
debugContext.lineTo( target.x * 0.1, target.z * 0.1 );
|
||||
debugContext.lineTo( camera.target.x * 0.1, camera.target.z * 0.1 );
|
||||
debugContext.rect( camera.position.x * 0.1 - 5, camera.position.z * 0.1 - 5, 10, 10 );
|
||||
debugContext.rect( target.x * 0.1 - 5, target.z * 0.1 - 5, 10, 10 );
|
||||
debugContext.rect( camera.target.x * 0.1 - 5, camera.target.z * 0.1 - 5, 10, 10 );
|
||||
debugContext.rect( - 50, - 50, 100, 100 );
|
||||
|
||||
for ( var i = 0, l = objects.length; i < l; i++ ) {
|
||||
|
||||
+85
-79
@@ -102,6 +102,72 @@ THREE.Matrix4.prototype = {
|
||||
|
||||
},
|
||||
|
||||
multiply: function ( a, b ) {
|
||||
|
||||
var a11 = a.n11, a12 = a.n12, a13 = a.n13, a14 = a.n14,
|
||||
a21 = a.n21, a22 = a.n22, a23 = a.n23, a24 = a.n24,
|
||||
a31 = a.n31, a32 = a.n32, a33 = a.n33, a34 = a.n34,
|
||||
a41 = a.n41, a42 = a.n42, a43 = a.n43, a44 = a.n44,
|
||||
|
||||
b11 = b.n11, b12 = b.n12, b13 = b.n13, b14 = b.n14,
|
||||
b21 = b.n21, b22 = b.n22, b23 = b.n23, b24 = b.n24,
|
||||
b31 = b.n31, b32 = b.n32, b33 = b.n33, b34 = b.n34,
|
||||
b41 = b.n41, b42 = b.n42, b43 = b.n43, b44 = b.n44;
|
||||
|
||||
this.n11 = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
|
||||
this.n12 = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
|
||||
this.n13 = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
|
||||
this.n14 = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
|
||||
|
||||
this.n21 = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
|
||||
this.n22 = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
|
||||
this.n23 = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
|
||||
this.n24 = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
|
||||
|
||||
this.n31 = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
|
||||
this.n32 = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
|
||||
this.n33 = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
|
||||
this.n34 = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
|
||||
|
||||
this.n41 = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
|
||||
this.n42 = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
|
||||
this.n43 = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
|
||||
this.n44 = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
multiplySelf: function ( m ) {
|
||||
|
||||
return this.multiply( this, m );
|
||||
|
||||
},
|
||||
|
||||
multiplyToArray: function ( a, b, r ) {
|
||||
|
||||
this.multiply( a, b );
|
||||
|
||||
r[ 0 ] = this.n11; r[ 1 ] = this.n21; r[ 2 ] = this.n31; r[ 3 ] = this.n41;
|
||||
r[ 4 ] = this.n12; r[ 5 ] = this.n22; r[ 6 ] = this.n32; r[ 7 ] = this.n42;
|
||||
r[ 8 ] = this.n13; r[ 9 ] = this.n23; r[ 10 ] = this.n33; r[ 11 ] = this.n43;
|
||||
r[ 12 ] = this.n14; r[ 13 ] = this.n24; r[ 14 ] = this.n34; r[ 15 ] = this.n44;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
multiplyScalar: function ( s ) {
|
||||
|
||||
this.n11 *= s; this.n12 *= s; this.n13 *= s; this.n14 *= s;
|
||||
this.n21 *= s; this.n22 *= s; this.n23 *= s; this.n24 *= s;
|
||||
this.n31 *= s; this.n32 *= s; this.n33 *= s; this.n34 *= s;
|
||||
this.n41 *= s; this.n42 *= s; this.n43 *= s; this.n44 *= s;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
multiplyVector3: function ( v ) {
|
||||
|
||||
var vx = v.x, vy = v.y, vz = v.z,
|
||||
@@ -156,74 +222,6 @@ THREE.Matrix4.prototype = {
|
||||
|
||||
},
|
||||
|
||||
multiply: function ( a, b ) {
|
||||
|
||||
var a11 = a.n11, a12 = a.n12, a13 = a.n13, a14 = a.n14,
|
||||
a21 = a.n21, a22 = a.n22, a23 = a.n23, a24 = a.n24,
|
||||
a31 = a.n31, a32 = a.n32, a33 = a.n33, a34 = a.n34,
|
||||
a41 = a.n41, a42 = a.n42, a43 = a.n43, a44 = a.n44,
|
||||
|
||||
b11 = b.n11, b12 = b.n12, b13 = b.n13, b14 = b.n14,
|
||||
b21 = b.n21, b22 = b.n22, b23 = b.n23, b24 = b.n24,
|
||||
b31 = b.n31, b32 = b.n32, b33 = b.n33, b34 = b.n34,
|
||||
b41 = b.n41, b42 = b.n42, b43 = b.n43, b44 = b.n44;
|
||||
|
||||
this.n11 = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
|
||||
this.n12 = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
|
||||
this.n13 = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
|
||||
this.n14 = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
|
||||
|
||||
this.n21 = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
|
||||
this.n22 = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
|
||||
this.n23 = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
|
||||
this.n24 = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
|
||||
|
||||
this.n31 = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
|
||||
this.n32 = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
|
||||
this.n33 = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
|
||||
this.n34 = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
|
||||
|
||||
this.n41 = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
|
||||
this.n42 = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
|
||||
this.n43 = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
|
||||
this.n44 = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
multiplyToArray: function ( a, b, r ) {
|
||||
|
||||
this.multiply( a, b );
|
||||
|
||||
r[ 0 ] = this.n11; r[ 1 ] = this.n21; r[ 2 ] = this.n31; r[ 3 ] = this.n41;
|
||||
r[ 4 ] = this.n12; r[ 5 ] = this.n22; r[ 6 ] = this.n32; r[ 7 ] = this.n42;
|
||||
r[ 8 ] = this.n13; r[ 9 ] = this.n23; r[ 10 ] = this.n33; r[ 11 ] = this.n43;
|
||||
r[ 12 ] = this.n14; r[ 13 ] = this.n24; r[ 14 ] = this.n34; r[ 15 ] = this.n44;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
multiplySelf: function ( m ) {
|
||||
|
||||
this.multiply( this, m );
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
multiplyScalar: function ( s ) {
|
||||
|
||||
this.n11 *= s; this.n12 *= s; this.n13 *= s; this.n14 *= s;
|
||||
this.n21 *= s; this.n22 *= s; this.n23 *= s; this.n24 *= s;
|
||||
this.n31 *= s; this.n32 *= s; this.n33 *= s; this.n34 *= s;
|
||||
this.n41 *= s; this.n42 *= s; this.n43 *= s; this.n44 *= s;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
determinant: function () {
|
||||
|
||||
var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14,
|
||||
@@ -742,23 +740,31 @@ THREE.Matrix4.prototype = {
|
||||
this.n24 = m.n24;
|
||||
this.n34 = m.n34;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
extractRotation: function ( m, s ) {
|
||||
extractRotation: function ( m ) {
|
||||
|
||||
var invScaleX = 1 / s.x, invScaleY = 1 / s.y, invScaleZ = 1 / s.z;
|
||||
var vector = THREE.Matrix4.__v1;
|
||||
|
||||
this.n11 = m.n11 * invScaleX;
|
||||
this.n21 = m.n21 * invScaleX;
|
||||
this.n31 = m.n31 * invScaleX;
|
||||
var scaleX = vector.set( m.n11, m.n21, m.n31 ).length();
|
||||
var scaleY = vector.set( m.n12, m.n22, m.n32 ).length();
|
||||
var scaleZ = vector.set( m.n13, m.n23, m.n33 ).length();
|
||||
|
||||
this.n12 = m.n12 * invScaleY;
|
||||
this.n22 = m.n22 * invScaleY;
|
||||
this.n32 = m.n32 * invScaleY;
|
||||
this.n11 = m.n11 / scaleX;
|
||||
this.n21 = m.n21 / scaleX;
|
||||
this.n31 = m.n31 / scaleX;
|
||||
|
||||
this.n13 = m.n13 * invScaleZ;
|
||||
this.n23 = m.n23 * invScaleZ;
|
||||
this.n33 = m.n33 * invScaleZ;
|
||||
this.n12 = m.n12 / scaleY;
|
||||
this.n22 = m.n22 / scaleY;
|
||||
this.n32 = m.n32 / scaleY;
|
||||
|
||||
this.n13 = m.n13 / scaleZ;
|
||||
this.n23 = m.n23 / scaleZ;
|
||||
this.n33 = m.n33 / scaleZ;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
+11
-45
@@ -4,7 +4,7 @@
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
|
||||
THREE.Object3D = function() {
|
||||
THREE.Object3D = function () {
|
||||
|
||||
this.name = '';
|
||||
|
||||
@@ -101,7 +101,7 @@ THREE.Object3D.prototype = {
|
||||
|
||||
if ( this.children.indexOf( object ) === - 1 ) {
|
||||
|
||||
if( object.parent !== undefined ) {
|
||||
if ( object.parent !== undefined ) {
|
||||
|
||||
object.parent.remove( object );
|
||||
|
||||
@@ -110,50 +110,18 @@ THREE.Object3D.prototype = {
|
||||
object.parent = this;
|
||||
this.children.push( object );
|
||||
|
||||
// add to scene
|
||||
|
||||
var scene = this;
|
||||
|
||||
while ( scene.parent !== undefined ) {
|
||||
|
||||
scene = scene.parent;
|
||||
|
||||
}
|
||||
|
||||
if ( scene !== undefined && scene instanceof THREE.Scene ) {
|
||||
|
||||
scene.addChildRecurse( object );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
remove: function ( object ) {
|
||||
|
||||
var scene = this;
|
||||
var index = this.children.indexOf( object );
|
||||
|
||||
var childIndex = this.children.indexOf( object );
|
||||
|
||||
if ( childIndex !== - 1 ) {
|
||||
if ( index !== - 1 ) {
|
||||
|
||||
object.parent = undefined;
|
||||
this.children.splice( childIndex, 1 );
|
||||
|
||||
// remove from scene
|
||||
|
||||
while ( scene.parent !== undefined ) {
|
||||
|
||||
scene = scene.parent;
|
||||
|
||||
}
|
||||
|
||||
if ( scene !== undefined && scene instanceof THREE.Scene ) {
|
||||
|
||||
scene.removeChildRecurse( object );
|
||||
|
||||
}
|
||||
this.children.splice( index, 1 );
|
||||
|
||||
}
|
||||
|
||||
@@ -216,17 +184,17 @@ THREE.Object3D.prototype = {
|
||||
|
||||
},
|
||||
|
||||
update: function ( parentMatrixWorld, forceUpdate, camera ) {
|
||||
updateMatrixWorld: function ( force ) {
|
||||
|
||||
this.matrixAutoUpdate && this.updateMatrix();
|
||||
|
||||
// update matrixWorld
|
||||
|
||||
if ( this.matrixWorldNeedsUpdate || forceUpdate ) {
|
||||
if ( this.matrixWorldNeedsUpdate || force ) {
|
||||
|
||||
if ( parentMatrixWorld ) {
|
||||
if ( this.parent ) {
|
||||
|
||||
this.matrixWorld.multiply( parentMatrixWorld, this.matrix );
|
||||
this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix );
|
||||
|
||||
} else {
|
||||
|
||||
@@ -234,11 +202,9 @@ THREE.Object3D.prototype = {
|
||||
|
||||
}
|
||||
|
||||
this.matrixRotationWorld.extractRotation( this.matrixWorld, this.scale );
|
||||
|
||||
this.matrixWorldNeedsUpdate = false;
|
||||
|
||||
forceUpdate = true;
|
||||
force = true;
|
||||
|
||||
}
|
||||
|
||||
@@ -246,7 +212,7 @@ THREE.Object3D.prototype = {
|
||||
|
||||
for ( var i = 0, l = this.children.length; i < l; i ++ ) {
|
||||
|
||||
this.children[ i ].update( this.matrixWorld, forceUpdate, camera );
|
||||
this.children[ i ].updateMatrixWorld( force );
|
||||
|
||||
}
|
||||
|
||||
|
||||
+31
-20
@@ -79,32 +79,39 @@ THREE.Projector = function() {
|
||||
|
||||
};
|
||||
|
||||
this.projectObjects = function ( scene, camera, sort ) {
|
||||
|
||||
var o, ol, objects, object, matrix;
|
||||
this.projectObjects = function ( object, sort ) {
|
||||
|
||||
_objectList.length = 0;
|
||||
_objectCount = 0;
|
||||
|
||||
objects = scene.objects;
|
||||
var projectObject = function ( object ) {
|
||||
|
||||
for ( o = 0, ol = objects.length; o < ol; o ++ ) {
|
||||
if ( object.visible == false ) return;
|
||||
|
||||
object = objects[ o ];
|
||||
if ( object instanceof THREE.Particle || object instanceof THREE.Line ||
|
||||
( object instanceof THREE.Mesh && ( !object.frustumCulled || isInFrustum( object ) ) ) ) {
|
||||
|
||||
if ( !object.visible || ( object instanceof THREE.Mesh && ( object.frustumCulled && !isInFrustum( object ) ) ) ) continue;
|
||||
_object = getNextObjectInPool();
|
||||
|
||||
_object = getNextObjectInPool();
|
||||
_vector3.copy( object.position );
|
||||
_projScreenMatrix.multiplyVector3( _vector3 );
|
||||
|
||||
_vector3.copy( object.position );
|
||||
_projScreenMatrix.multiplyVector3( _vector3 );
|
||||
_object.object = object;
|
||||
_object.z = _vector3.z;
|
||||
|
||||
_object.object = object;
|
||||
_object.z = _vector3.z;
|
||||
_objectList.push( _object );
|
||||
|
||||
_objectList.push( _object );
|
||||
}
|
||||
|
||||
}
|
||||
for ( var c = 0, cl = object.children.length; c < cl; c ++ ) {
|
||||
|
||||
projectObject( object.children[ c ] );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
projectObject( scene );
|
||||
|
||||
sort && _objectList.sort( painterSort );
|
||||
|
||||
@@ -112,8 +119,6 @@ THREE.Projector = function() {
|
||||
|
||||
};
|
||||
|
||||
// TODO: Rename to projectElements?
|
||||
|
||||
this.projectScene = function ( scene, camera, sort ) {
|
||||
|
||||
var near = camera.near, far = camera.far,
|
||||
@@ -130,9 +135,14 @@ THREE.Projector = function() {
|
||||
_lineCount = 0;
|
||||
_particleCount = 0;
|
||||
|
||||
camera.matrixAutoUpdate && camera.update( undefined, true );
|
||||
if ( camera.parent == null ) {
|
||||
|
||||
scene.update( undefined, false, camera );
|
||||
console.warn( "Camera is not on the Scene. Adding it..." );
|
||||
scene.add( camera );
|
||||
|
||||
}
|
||||
|
||||
scene.updateMatrixWorld();
|
||||
|
||||
THREE.Matrix4.makeInvert( camera.matrixWorld, camera.matrixWorldInverse );
|
||||
|
||||
@@ -140,7 +150,7 @@ THREE.Projector = function() {
|
||||
|
||||
computeFrustum( _projScreenMatrix );
|
||||
|
||||
objects = this.projectObjects( scene, camera, true );
|
||||
objects = this.projectObjects( scene, true );
|
||||
|
||||
for ( o = 0, ol = objects.length; o < ol; o++ ) {
|
||||
|
||||
@@ -149,7 +159,6 @@ THREE.Projector = function() {
|
||||
if ( !object.visible ) continue;
|
||||
|
||||
objectMatrix = object.matrixWorld;
|
||||
objectMatrixRotation = object.matrixRotationWorld;
|
||||
|
||||
objectMaterials = object.materials;
|
||||
objectOverdraw = object.overdraw;
|
||||
@@ -163,6 +172,8 @@ THREE.Projector = function() {
|
||||
faces = geometry.faces;
|
||||
faceVertexUvs = geometry.faceVertexUvs;
|
||||
|
||||
objectMatrixRotation = object.matrixRotationWorld.extractRotation( object.matrixWorld );
|
||||
|
||||
for ( v = 0, vl = vertices.length; v < vl; v ++ ) {
|
||||
|
||||
_vertex = getNextVertexInPool();
|
||||
|
||||
+3
-1
@@ -15,7 +15,7 @@ THREE.Ray.prototype = {
|
||||
|
||||
intersectScene: function ( scene ) {
|
||||
|
||||
return this.intersectObjects( scene.objects );
|
||||
return this.intersectObjects( scene.children );
|
||||
|
||||
},
|
||||
|
||||
@@ -90,6 +90,8 @@ THREE.Ray.prototype = {
|
||||
objMatrix,
|
||||
intersectPoint;
|
||||
|
||||
object.matrixRotationWorld.extractRotation( object.matrixWorld );
|
||||
|
||||
for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
|
||||
|
||||
face = geometry.faces[ f ];
|
||||
|
||||
@@ -188,7 +188,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||
_context.fillRect( _clipRect.getX(), _clipRect.getY(), _clipRect.getWidth(), _clipRect.getHeight() );
|
||||
*/
|
||||
|
||||
_enableLighting = scene.lights.length > 0;
|
||||
// _enableLighting = scene.lights.length > 0;
|
||||
|
||||
if ( _enableLighting ) {
|
||||
|
||||
|
||||
+1
-107
@@ -1,6 +1,5 @@
|
||||
/**
|
||||
* @author mr.doob / http://mrdoob.com/
|
||||
* @author mikael emtinger / http://gomo.se/
|
||||
*/
|
||||
|
||||
THREE.Scene = function () {
|
||||
@@ -8,119 +7,14 @@ THREE.Scene = function () {
|
||||
THREE.Object3D.call( this );
|
||||
|
||||
this.fog = null;
|
||||
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
this.overrideMaterial = null;
|
||||
|
||||
this.collisions = null;
|
||||
|
||||
this.objects = [];
|
||||
this.lights = [];
|
||||
|
||||
this.__objectsAdded = [];
|
||||
this.__objectsRemoved = [];
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
};
|
||||
|
||||
THREE.Scene.prototype = new THREE.Object3D();
|
||||
THREE.Scene.prototype.constructor = THREE.Scene;
|
||||
THREE.Scene.prototype.supr = THREE.Object3D.prototype;
|
||||
|
||||
THREE.Scene.prototype.add = function ( object ) {
|
||||
|
||||
this.supr.add.call( this, object );
|
||||
this.addChildRecurse( object );
|
||||
|
||||
}
|
||||
|
||||
THREE.Scene.prototype.addChildRecurse = function ( child ) {
|
||||
|
||||
if ( child instanceof THREE.Light ) {
|
||||
|
||||
if ( this.lights.indexOf( child ) === - 1 ) {
|
||||
|
||||
this.lights.push( child );
|
||||
|
||||
}
|
||||
|
||||
} else if ( !( child instanceof THREE.Camera || child instanceof THREE.Bone ) ) {
|
||||
|
||||
if ( this.objects.indexOf( child ) === - 1 ) {
|
||||
|
||||
this.objects.push( child );
|
||||
this.__objectsAdded.push( child );
|
||||
|
||||
// check if previously removed
|
||||
|
||||
var i = this.__objectsRemoved.indexOf( child );
|
||||
|
||||
if ( i !== -1 ) {
|
||||
|
||||
this.__objectsRemoved.splice( i, 1 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for ( var c = 0; c < child.children.length; c ++ ) {
|
||||
|
||||
this.addChildRecurse( child.children[ c ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
THREE.Scene.prototype.remove = function ( object ) {
|
||||
|
||||
this.supr.remove.call( this, object );
|
||||
this.removeChildRecurse( object );
|
||||
|
||||
}
|
||||
|
||||
THREE.Scene.prototype.removeChildRecurse = function ( child ) {
|
||||
|
||||
if ( child instanceof THREE.Light ) {
|
||||
|
||||
var i = this.lights.indexOf( child );
|
||||
|
||||
if ( i !== -1 ) {
|
||||
|
||||
this.lights.splice( i, 1 );
|
||||
|
||||
}
|
||||
|
||||
} else if ( !( child instanceof THREE.Camera ) ) {
|
||||
|
||||
var i = this.objects.indexOf( child );
|
||||
|
||||
if( i !== -1 ) {
|
||||
|
||||
this.objects.splice( i, 1 );
|
||||
this.__objectsRemoved.push( child );
|
||||
|
||||
// check if previously added
|
||||
|
||||
var ai = this.__objectsAdded.indexOf( child );
|
||||
|
||||
if ( ai !== -1 ) {
|
||||
|
||||
this.__objectsAdded.splice( ai, 1 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for ( var c = 0; c < child.children.length; c ++ ) {
|
||||
|
||||
this.removeChildRecurse( child.children[ c ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
|
||||
|
||||
Reference in New Issue
Block a user