forked from mhalle/oabrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhierarchyGroup.js
93 lines (54 loc) · 1.85 KB
/
hierarchyGroup.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
function HierarchyGroup () {
this.children =[];
this.hierarchyParents = [];
Object.defineProperty(this, "visible",{
get : function () {
return this.children.some(x=>x.visible);
},
set : function (value) {
this.children.forEach(x => x.visible = value);
}
});
}
HierarchyGroup.prototype = {
constructor: HierarchyGroup,
add : function (object) {
if ( arguments.length > 1 ) {
for ( var i = 0; i < arguments.length; i ++ ) {
this.add( arguments[ i ] );
}
return this;
}
if ( object === this ) {
console.error( "HierarchyGroup : object can't be added as a child of itself.", object );
return this;
}
if ( object instanceof THREE.Object3D || object instanceof HierarchyGroup ) {
//add object only if it has not already been added
if ( this.children.indexOf(object) === -1 ) {
this.children.push(object);
if (!object.hierarchyParents) {
object.hierarchyParents = [];
}
object.hierarchyParents.push(this);
}
} else {
console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D or HierarchyGroup.", object );
}
return this;
},
remove : function (object) {
if ( arguments.length > 1 ) {
for ( var i = 0; i < arguments.length; i ++ ) {
this.remove( arguments[ i ] );
}
return this;
}
if (this.children.indexOf(object) > -1) {
this.children = this.children.filter(x => x !== object);
var parentToRemove = this;
object.hierarchyParents = object.hierarchyParents.filter(x => x !== parentToRemove);
}
return this;
}
};