123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /**
- * @author mr.doob / http://mrdoob.com/
- * @author mikael emtinger / http://gomo.se/
- * @author alteredq / http://alteredqualia.com/
- */
- THREE.Object3D = function() {
- this.id = THREE.Object3DCounter.value ++;
- 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.matrixRotation = new THREE.Matrix4(); // this is just to cache it when somewhere it's computed somewhere else (stripped down globalMatrix)
- this.localMatrix = new THREE.Matrix4();
- this.globalMatrix = new THREE.Matrix4();
- this.matrixAutoUpdate = true;
- this.matrixNeedsUpdate = true;
- this.quaternion = new THREE.Quaternion();
- this.useQuaternion = false;
- this.screenPosition = new THREE.Vector4(); // xyzr
- this.boundRadius = 0.0;
- this.boundRadiusScale = 1.0;
- this.visible = true;
- };
- THREE.Object3D.prototype = {
- update: function ( parentGlobalMatrix, forceUpdate, camera ) {
- if ( this.visible ) {
- if ( this.matrixAutoUpdate ) {
- forceUpdate |= this.updateMatrix();
- }
- // update global
- if ( forceUpdate || this.matrixNeedsUpdate ) {
- if ( parentGlobalMatrix ) {
- this.globalMatrix.multiply( parentGlobalMatrix, this.localMatrix );
- } else {
- this.globalMatrix.copy( this.localMatrix );
- }
- this.matrixNeedsUpdate = false;
- forceUpdate = true;
- }
- // update children
- var i, l = this.children.length;
- for ( i = 0; i < l; i++ ) {
- this.children[ i ].update( this.globalMatrix, forceUpdate, camera );
- }
- }
- },
- updateMatrix: function () {
- this.localMatrix.setPosition( this.position );
- if ( this.useQuaternion ) {
- this.localMatrix.setRotationFromQuaternion( this.quaternion );
- } else {
- this.localMatrix.setRotationFromEuler( this.rotation );
- }
- 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;
- },
- addChild: function ( child ) {
- if ( this.children.indexOf( child ) === -1 ) {
- if( child.parent !== undefined )
- child.parent.removeChild( child );
- child.parent = this;
- this.children.push( child );
- }
- },
- removeChild: function ( child ) {
- var childIndex = this.children.indexOf( child );
- if ( childIndex !== -1 ) {
- this.children.splice( childIndex, 1 );
- child.parent = undefined;
- }
- }
- }
- THREE.Object3DCounter = { value: 0 };
|