forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScene.js
105 lines (57 loc) · 1.71 KB
/
Scene.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* @author mr.doob / http://mrdoob.com/
*/
THREE.Scene = function () {
THREE.Object3D.call( this );
this.fog = null;
this.overrideMaterial = null;
this.matrixAutoUpdate = false;
this.__objects = [];
this.__lights = [];
this.__objectsAdded = [];
this.__objectsRemoved = [];
};
THREE.Scene.prototype = new THREE.Object3D();
THREE.Scene.prototype.constructor = THREE.Scene;
THREE.Scene.prototype.__addObject = function ( object ) {
if ( object instanceof THREE.Light ) {
if ( this.__lights.indexOf( object ) === - 1 ) {
this.__lights.push( object );
}
} else if ( !( object instanceof THREE.Camera || object instanceof THREE.Bone ) ) {
if ( this.__objects.indexOf( object ) === - 1 ) {
this.__objects.push( object );
this.__objectsAdded.push( object );
// check if previously removed
var i = this.__objectsRemoved.indexOf( object );
if ( i !== -1 ) {
this.__objectsRemoved.splice( i, 1 );
}
}
}
for ( var c = 0; c < object.children.length; c ++ ) {
this.__addObject( object.children[ c ] );
}
};
THREE.Scene.prototype.__removeObject = function ( object ) {
if ( object instanceof THREE.Light ) {
var i = this.__lights.indexOf( object );
if ( i !== -1 ) {
this.__lights.splice( i, 1 );
}
} else if ( !( object instanceof THREE.Camera ) ) {
var i = this.__objects.indexOf( object );
if( i !== -1 ) {
this.__objects.splice( i, 1 );
this.__objectsRemoved.push( object );
// check if previously added
var ai = this.__objectsAdded.indexOf( object );
if ( ai !== -1 ) {
this.__objectsAdded.splice( ai, 1 );
}
}
}
for ( var c = 0; c < object.children.length; c ++ ) {
this.__removeObject( object.children[ c ] );
}
};