1 | /**
|
---|
2 | * @author mrdoob / http://mrdoob.com/
|
---|
3 | */
|
---|
4 |
|
---|
5 | THREE.Scene = function () {
|
---|
6 |
|
---|
7 | THREE.Object3D.call( this );
|
---|
8 |
|
---|
9 | this.fog = null;
|
---|
10 | this.overrideMaterial = null;
|
---|
11 |
|
---|
12 | this.autoUpdate = true; // checked by the renderer
|
---|
13 | this.matrixAutoUpdate = false;
|
---|
14 |
|
---|
15 | this.__lights = [];
|
---|
16 |
|
---|
17 | this.__objectsAdded = [];
|
---|
18 | this.__objectsRemoved = [];
|
---|
19 |
|
---|
20 | };
|
---|
21 |
|
---|
22 | THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
|
---|
23 |
|
---|
24 | THREE.Scene.prototype.__addObject = function ( object ) {
|
---|
25 |
|
---|
26 | if ( object instanceof THREE.Light ) {
|
---|
27 |
|
---|
28 | if ( this.__lights.indexOf( object ) === - 1 ) {
|
---|
29 |
|
---|
30 | this.__lights.push( object );
|
---|
31 |
|
---|
32 | }
|
---|
33 |
|
---|
34 | if ( object.target && object.target.parent === undefined ) {
|
---|
35 |
|
---|
36 | this.add( object.target );
|
---|
37 |
|
---|
38 | }
|
---|
39 |
|
---|
40 | } else if ( !( object instanceof THREE.Camera || object instanceof THREE.Bone ) ) {
|
---|
41 |
|
---|
42 | this.__objectsAdded.push( object );
|
---|
43 |
|
---|
44 | // check if previously removed
|
---|
45 |
|
---|
46 | var i = this.__objectsRemoved.indexOf( object );
|
---|
47 |
|
---|
48 | if ( i !== -1 ) {
|
---|
49 |
|
---|
50 | this.__objectsRemoved.splice( i, 1 );
|
---|
51 |
|
---|
52 | }
|
---|
53 |
|
---|
54 | }
|
---|
55 |
|
---|
56 | this.dispatchEvent( { type: 'objectAdded', object: object } );
|
---|
57 | object.dispatchEvent( { type: 'addedToScene', scene: this } );
|
---|
58 |
|
---|
59 | for ( var c = 0; c < object.children.length; c ++ ) {
|
---|
60 |
|
---|
61 | this.__addObject( object.children[ c ] );
|
---|
62 |
|
---|
63 | }
|
---|
64 |
|
---|
65 | };
|
---|
66 |
|
---|
67 | THREE.Scene.prototype.__removeObject = function ( object ) {
|
---|
68 |
|
---|
69 | if ( object instanceof THREE.Light ) {
|
---|
70 |
|
---|
71 | var i = this.__lights.indexOf( object );
|
---|
72 |
|
---|
73 | if ( i !== -1 ) {
|
---|
74 |
|
---|
75 | this.__lights.splice( i, 1 );
|
---|
76 |
|
---|
77 | }
|
---|
78 |
|
---|
79 | if ( object.shadowCascadeArray ) {
|
---|
80 |
|
---|
81 | for ( var x = 0; x < object.shadowCascadeArray.length; x ++ ) {
|
---|
82 |
|
---|
83 | this.__removeObject( object.shadowCascadeArray[ x ] );
|
---|
84 |
|
---|
85 | }
|
---|
86 |
|
---|
87 | }
|
---|
88 |
|
---|
89 | } else if ( !( object instanceof THREE.Camera ) ) {
|
---|
90 |
|
---|
91 | this.__objectsRemoved.push( object );
|
---|
92 |
|
---|
93 | // check if previously added
|
---|
94 |
|
---|
95 | var i = this.__objectsAdded.indexOf( object );
|
---|
96 |
|
---|
97 | if ( i !== -1 ) {
|
---|
98 |
|
---|
99 | this.__objectsAdded.splice( i, 1 );
|
---|
100 |
|
---|
101 | }
|
---|
102 |
|
---|
103 | }
|
---|
104 |
|
---|
105 | this.dispatchEvent( { type: 'objectRemoved', object: object } );
|
---|
106 | object.dispatchEvent( { type: 'removedFromScene', scene: this } );
|
---|
107 |
|
---|
108 | for ( var c = 0; c < object.children.length; c ++ ) {
|
---|
109 |
|
---|
110 | this.__removeObject( object.children[ c ] );
|
---|
111 |
|
---|
112 | }
|
---|
113 |
|
---|
114 | };
|
---|
115 |
|
---|
116 | THREE.Scene.prototype.clone = function ( object ) {
|
---|
117 |
|
---|
118 | if ( object === undefined ) object = new THREE.Scene();
|
---|
119 |
|
---|
120 | THREE.Object3D.prototype.clone.call(this, object);
|
---|
121 |
|
---|
122 | if ( this.fog !== null ) object.fog = this.fog.clone();
|
---|
123 | if ( this.overrideMaterial !== null ) object.overrideMaterial = this.overrideMaterial.clone();
|
---|
124 |
|
---|
125 | object.autoUpdate = this.autoUpdate;
|
---|
126 | object.matrixAutoUpdate = this.matrixAutoUpdate;
|
---|
127 |
|
---|
128 | return object;
|
---|
129 |
|
---|
130 | };
|
---|