|
@@ -7,27 +7,27 @@
|
|
|
THREE.Object3D = function() {
|
|
|
|
|
|
this.id = THREE.Object3DCounter.value ++;
|
|
|
-
|
|
|
- this.visible = true;
|
|
|
- this.autoUpdateMatrix = true;
|
|
|
+
|
|
|
+ this.visible = true;
|
|
|
+ this.autoUpdateMatrix = true;
|
|
|
this.matrixNeedsToUpdate = true;
|
|
|
-
|
|
|
- this.parent = undefined;
|
|
|
- this.children = [];
|
|
|
-
|
|
|
- this.position = new THREE.Vector3();
|
|
|
- this.rotation = new THREE.Vector3();
|
|
|
- this.scale = new THREE.Vector3( 1.0, 1.0, 1.0 );
|
|
|
- this.localMatrix = new THREE.Matrix4();
|
|
|
- this.globalMatrix = new THREE.Matrix4();
|
|
|
- this.quaternion = new THREE.Quaternion();
|
|
|
- this.useQuaternion = false;
|
|
|
- this.screenPosition = new THREE.Vector4(); // xyzr
|
|
|
-
|
|
|
- this.boundRadius = 0.0;
|
|
|
- this.boundRadiusScale = 1.0;
|
|
|
-
|
|
|
- this.rotationMatrix = new THREE.Matrix4(); // this is just to cache it when somewhere it's computed somewhere else (stripped down globalMatrix)
|
|
|
+
|
|
|
+ this.parent = undefined;
|
|
|
+ this.children = [];
|
|
|
+
|
|
|
+ this.position = new THREE.Vector3();
|
|
|
+ this.rotation = new THREE.Vector3();
|
|
|
+ this.scale = new THREE.Vector3( 1.0, 1.0, 1.0 );
|
|
|
+ this.localMatrix = new THREE.Matrix4();
|
|
|
+ this.globalMatrix = new THREE.Matrix4();
|
|
|
+ this.quaternion = new THREE.Quaternion();
|
|
|
+ this.useQuaternion = false;
|
|
|
+ this.screenPosition = new THREE.Vector4(); // xyzr
|
|
|
+
|
|
|
+ this.boundRadius = 0.0;
|
|
|
+ this.boundRadiusScale = 1.0;
|
|
|
+
|
|
|
+ this.rotationMatrix = new THREE.Matrix4(); // this is just to cache it when somewhere it's computed somewhere else (stripped down globalMatrix)
|
|
|
|
|
|
};
|
|
|
|
|
@@ -39,24 +39,24 @@ THREE.Object3D = function() {
|
|
|
THREE.Object3D.prototype.update = function( parentGlobalMatrix, forceUpdate, camera ) {
|
|
|
|
|
|
// visible and auto update?
|
|
|
-
|
|
|
+
|
|
|
if( this.visible ) {
|
|
|
|
|
|
// update local
|
|
|
-
|
|
|
+
|
|
|
if( this.autoUpdateMatrix )
|
|
|
forceUpdate |= this.updateMatrix();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
// update global
|
|
|
|
|
|
if( forceUpdate || this.matrixNeedsToUpdate ) {
|
|
|
-
|
|
|
+
|
|
|
if( parentGlobalMatrix )
|
|
|
this.globalMatrix.multiply( parentGlobalMatrix, this.localMatrix );
|
|
|
else
|
|
|
this.globalMatrix.copy( this.localMatrix );
|
|
|
-
|
|
|
+
|
|
|
this.matrixNeedsToUpdate = false;
|
|
|
forceUpdate = true;
|
|
|
|
|
@@ -64,13 +64,13 @@ THREE.Object3D.prototype.update = function( parentGlobalMatrix, forceUpdate, cam
|
|
|
|
|
|
|
|
|
// update children
|
|
|
-
|
|
|
+
|
|
|
var i, l = this.children.length;
|
|
|
-
|
|
|
+
|
|
|
for( i = 0; i < l; i++ ) {
|
|
|
-
|
|
|
+
|
|
|
this.children[ i ].update( this.globalMatrix, forceUpdate, camera );
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -83,39 +83,39 @@ THREE.Object3D.prototype.update = function( parentGlobalMatrix, forceUpdate, cam
|
|
|
*/
|
|
|
|
|
|
THREE.Object3D.prototype.updateMatrix = function() {
|
|
|
-
|
|
|
+
|
|
|
// update position
|
|
|
-
|
|
|
- this.localMatrix.setPosition( this.position );
|
|
|
-
|
|
|
+
|
|
|
+ this.localMatrix.setPosition( this.position );
|
|
|
+
|
|
|
// update quaternion
|
|
|
-
|
|
|
+
|
|
|
if( this.useQuaternion ) {
|
|
|
-
|
|
|
+
|
|
|
if( this.quaternion.isDirty ) {
|
|
|
-
|
|
|
+
|
|
|
this.localMatrix.setRotationFromQuaternion( this.quaternion );
|
|
|
this.quaternion.isDirty = false;
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// update rotation
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
-
|
|
|
+
|
|
|
this.localMatrix.setRotationFromEuler( this.rotation );
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// update scale
|
|
|
-
|
|
|
+
|
|
|
if( this.scale.x !== 1 || this.scale.y !== 1 || this.scale.z !== 1 ) {
|
|
|
-
|
|
|
+
|
|
|
this.localMatrix.scale( this.scale );
|
|
|
this.boundRadiusScale = Math.max( this.scale.x, Math.max( this.scale.y, this.scale.z ) );
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return true;
|
|
|
|
|
|
};
|
|
@@ -126,12 +126,12 @@ THREE.Object3D.prototype.updateMatrix = function() {
|
|
|
*/
|
|
|
|
|
|
THREE.Object3D.prototype.addChild = function( child ) {
|
|
|
-
|
|
|
+
|
|
|
if( this.children.indexOf( child ) === -1 ) {
|
|
|
|
|
|
if( child.parent !== undefined )
|
|
|
child.parent.removeChild( child );
|
|
|
-
|
|
|
+
|
|
|
child.parent = this;
|
|
|
this.children.push( child );
|
|
|
|
|
@@ -145,11 +145,11 @@ THREE.Object3D.prototype.addChild = function( child ) {
|
|
|
*/
|
|
|
|
|
|
THREE.Object3D.prototype.removeChild = function( child ) {
|
|
|
-
|
|
|
- var childIndex = this.children.indexOf( child );
|
|
|
-
|
|
|
+
|
|
|
+ var childIndex = this.children.indexOf( child );
|
|
|
+
|
|
|
if( childIndex !== -1 ) {
|
|
|
-
|
|
|
+
|
|
|
this.children.splice( childIndex, 1 );
|
|
|
child.parent = undefined;
|
|
|
|