@shapediver/viewer.shared.node-tree 2.3.4 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/implementation/AbstractTree.d.ts +14 -0
- package/dist/implementation/AbstractTree.d.ts.map +1 -0
- package/dist/implementation/{Tree.js → AbstractTree.js} +21 -29
- package/dist/implementation/AbstractTree.js.map +1 -0
- package/dist/implementation/{TreeNode.d.ts → AbstractTreeNode.d.ts} +21 -24
- package/dist/implementation/AbstractTreeNode.d.ts.map +1 -0
- package/dist/implementation/AbstractTreeNode.js +296 -0
- package/dist/implementation/AbstractTreeNode.js.map +1 -0
- package/dist/implementation/AbstractTreeNodeData.d.ts +2 -2
- package/dist/implementation/AbstractTreeNodeData.d.ts.map +1 -1
- package/dist/implementation/AbstractTreeNodeData.js +10 -0
- package/dist/implementation/AbstractTreeNodeData.js.map +1 -1
- package/dist/implementation/three/AbstractTreeNodeDataThreeJs.d.ts +9 -0
- package/dist/implementation/three/AbstractTreeNodeDataThreeJs.d.ts.map +1 -0
- package/dist/implementation/three/AbstractTreeNodeDataThreeJs.js +23 -0
- package/dist/implementation/three/AbstractTreeNodeDataThreeJs.js.map +1 -0
- package/dist/implementation/three/Tree.d.ts +7 -0
- package/dist/implementation/three/Tree.d.ts.map +1 -0
- package/dist/implementation/three/Tree.js +26 -0
- package/dist/implementation/three/Tree.js.map +1 -0
- package/dist/implementation/three/TreeNodeThreejs.d.ts +12 -0
- package/dist/implementation/three/TreeNodeThreejs.d.ts.map +1 -0
- package/dist/implementation/three/TreeNodeThreejs.js +35 -0
- package/dist/implementation/three/TreeNodeThreejs.js.map +1 -0
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/interfaces/ITree.d.ts +11 -7
- package/dist/interfaces/ITree.d.ts.map +1 -1
- package/dist/interfaces/ITreeNode.d.ts +85 -30
- package/dist/interfaces/ITreeNode.d.ts.map +1 -1
- package/dist/interfaces/ITreeNodeData.d.ts +16 -2
- package/dist/interfaces/ITreeNodeData.d.ts.map +1 -1
- package/dist/interfaces/three/ITreeNodeDataThreeJs.d.ts +10 -0
- package/dist/interfaces/three/ITreeNodeDataThreeJs.d.ts.map +1 -0
- package/dist/interfaces/three/ITreeNodeDataThreeJs.js +3 -0
- package/dist/interfaces/three/ITreeNodeDataThreeJs.js.map +1 -0
- package/dist/interfaces/three/ITreeNodeThreeJs.d.ts +16 -0
- package/dist/interfaces/three/ITreeNodeThreeJs.d.ts.map +1 -0
- package/dist/interfaces/three/ITreeNodeThreeJs.js +3 -0
- package/dist/interfaces/three/ITreeNodeThreeJs.js.map +1 -0
- package/dist/interfaces/three/ITreeThreeJs.d.ts +5 -0
- package/dist/interfaces/three/ITreeThreeJs.d.ts.map +1 -0
- package/dist/interfaces/{ISDObject.js → three/ITreeThreeJs.js} +1 -1
- package/dist/interfaces/three/ITreeThreeJs.js.map +1 -0
- package/package.json +4 -4
- package/src/implementation/{Tree.ts → AbstractTree.ts} +12 -13
- package/src/implementation/{TreeNode.ts → AbstractTreeNode.ts} +39 -44
- package/src/implementation/AbstractTreeNodeData.ts +5 -2
- package/src/implementation/three/AbstractTreeNodeDataThreeJs.ts +11 -0
- package/src/implementation/three/Tree.ts +12 -0
- package/src/implementation/three/TreeNodeThreeJs.ts +20 -0
- package/src/index.ts +10 -12
- package/src/interfaces/ITree.ts +11 -7
- package/src/interfaces/ITreeNode.ts +89 -55
- package/src/interfaces/ITreeNodeData.ts +25 -2
- package/src/interfaces/three/ITreeNodeDataThreeJs.ts +12 -0
- package/src/interfaces/three/ITreeNodeThreeJs.ts +18 -0
- package/src/interfaces/three/ITreeThreeJs.ts +4 -0
- package/dist/implementation/Tree.d.ts +0 -13
- package/dist/implementation/Tree.d.ts.map +0 -1
- package/dist/implementation/Tree.js.map +0 -1
- package/dist/implementation/TreeNode.d.ts.map +0 -1
- package/dist/implementation/TreeNode.js +0 -295
- package/dist/implementation/TreeNode.js.map +0 -1
- package/dist/interfaces/ISDObject.d.ts +0 -7
- package/dist/interfaces/ISDObject.d.ts.map +0 -1
- package/dist/interfaces/ISDObject.js.map +0 -1
- package/src/interfaces/ISDObject.ts +0 -11
|
@@ -5,33 +5,28 @@ import { Box, IBox } from '@shapediver/viewer.shared.math'
|
|
|
5
5
|
|
|
6
6
|
import { ITransformation, ITreeNode } from '../interfaces/ITreeNode'
|
|
7
7
|
import { ITreeNodeData } from '../interfaces/ITreeNodeData'
|
|
8
|
-
import { ISDObject } from '../interfaces/ISDObject'
|
|
9
8
|
|
|
10
|
-
export class
|
|
9
|
+
export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<any>>, U extends ITreeNodeData<any>> implements ITreeNode<T, U> {
|
|
11
10
|
// #region Properties (13)
|
|
12
11
|
|
|
13
12
|
readonly #uuidGenerator: UuidGenerator = <UuidGenerator>container.resolve(UuidGenerator);
|
|
14
13
|
|
|
15
|
-
readonly #children:
|
|
16
|
-
readonly #data:
|
|
14
|
+
readonly #children: T[] = [];
|
|
15
|
+
readonly #data: U[] = [];
|
|
17
16
|
#transformations: ITransformation[] = [];
|
|
18
17
|
|
|
19
18
|
readonly #id: string;
|
|
20
|
-
|
|
19
|
+
#name: string = '';
|
|
21
20
|
#version: string;
|
|
22
|
-
#parent?:
|
|
21
|
+
#parent?: T;
|
|
23
22
|
|
|
24
23
|
readonly #boundingBox: IBox = new Box();
|
|
25
|
-
readonly #transformedNodes: {
|
|
26
|
-
[key: string]: ISDObject
|
|
27
|
-
} = {};
|
|
28
|
-
|
|
29
24
|
#excludeViewports: string[] = [];
|
|
30
25
|
#restrictViewports: string[] = [];
|
|
31
26
|
|
|
32
27
|
#visible: boolean = true;
|
|
33
28
|
#skinNode: boolean = false;
|
|
34
|
-
#bones:
|
|
29
|
+
#bones: T[] = [];
|
|
35
30
|
#boneInverses: mat4[] = [];
|
|
36
31
|
#originalId: string;
|
|
37
32
|
|
|
@@ -49,8 +44,8 @@ export class TreeNode implements ITreeNode {
|
|
|
49
44
|
*/
|
|
50
45
|
constructor(
|
|
51
46
|
name: string = 'node',
|
|
52
|
-
parent?:
|
|
53
|
-
data:
|
|
47
|
+
parent?: T,
|
|
48
|
+
data: U[] = [],
|
|
54
49
|
transformations: ITransformation[] = []
|
|
55
50
|
) {
|
|
56
51
|
this.#name = name.replace(/\./g, "_");
|
|
@@ -69,11 +64,11 @@ export class TreeNode implements ITreeNode {
|
|
|
69
64
|
// #region Public Accessors (19)
|
|
70
65
|
|
|
71
66
|
|
|
72
|
-
public get bones():
|
|
67
|
+
public get bones(): T[] {
|
|
73
68
|
return this.#bones;
|
|
74
69
|
}
|
|
75
70
|
|
|
76
|
-
public set bones(value:
|
|
71
|
+
public set bones(value: T[]) {
|
|
77
72
|
this.#bones = value;
|
|
78
73
|
this.updateVersion();
|
|
79
74
|
}
|
|
@@ -91,7 +86,7 @@ export class TreeNode implements ITreeNode {
|
|
|
91
86
|
return this.#boundingBox;
|
|
92
87
|
}
|
|
93
88
|
|
|
94
|
-
public get children():
|
|
89
|
+
public get children(): T[] {
|
|
95
90
|
return this.#children;
|
|
96
91
|
}
|
|
97
92
|
|
|
@@ -103,7 +98,7 @@ export class TreeNode implements ITreeNode {
|
|
|
103
98
|
this.#originalId = value;
|
|
104
99
|
}
|
|
105
100
|
|
|
106
|
-
public get data():
|
|
101
|
+
public get data(): U[] {
|
|
107
102
|
return this.#data;
|
|
108
103
|
}
|
|
109
104
|
|
|
@@ -124,6 +119,10 @@ export class TreeNode implements ITreeNode {
|
|
|
124
119
|
return this.#name;
|
|
125
120
|
}
|
|
126
121
|
|
|
122
|
+
public set name(value: string) {
|
|
123
|
+
this.#name = value;
|
|
124
|
+
}
|
|
125
|
+
|
|
127
126
|
public get nodeMatrix(): mat4 {
|
|
128
127
|
const matrix: mat4 = mat4.create();
|
|
129
128
|
for (let transform of this.#transformations)
|
|
@@ -131,11 +130,11 @@ export class TreeNode implements ITreeNode {
|
|
|
131
130
|
return matrix;
|
|
132
131
|
}
|
|
133
132
|
|
|
134
|
-
public get parent():
|
|
133
|
+
public get parent(): T | undefined {
|
|
135
134
|
return this.#parent;
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
public set parent(value:
|
|
137
|
+
public set parent(value: T | undefined) {
|
|
139
138
|
// check if it was removed from previous parent
|
|
140
139
|
if (this.#parent)
|
|
141
140
|
this.#parent.removeChild(this);
|
|
@@ -173,12 +172,6 @@ export class TreeNode implements ITreeNode {
|
|
|
173
172
|
this.#transformations = value;
|
|
174
173
|
}
|
|
175
174
|
|
|
176
|
-
public get transformedNodes(): {
|
|
177
|
-
[key: string]: ISDObject
|
|
178
|
-
} {
|
|
179
|
-
return this.#transformedNodes;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
175
|
public get version(): string {
|
|
183
176
|
return this.#version;
|
|
184
177
|
}
|
|
@@ -202,7 +195,7 @@ export class TreeNode implements ITreeNode {
|
|
|
202
195
|
for (let transform of this.#transformations)
|
|
203
196
|
mat4.multiply(matrix, matrix, transform.matrix);
|
|
204
197
|
|
|
205
|
-
let node:
|
|
198
|
+
let node: AbstractTreeNode<any, any> = this;
|
|
206
199
|
while (node.parent) {
|
|
207
200
|
mat4.multiply(matrix, node.parent.nodeMatrix, matrix);
|
|
208
201
|
node = node.parent;
|
|
@@ -215,17 +208,17 @@ export class TreeNode implements ITreeNode {
|
|
|
215
208
|
|
|
216
209
|
// #region Public Methods (16)
|
|
217
210
|
|
|
218
|
-
public addChild(child:
|
|
211
|
+
public addChild(child: T): boolean {
|
|
219
212
|
if (this.hasChild(child)) return false;
|
|
220
213
|
|
|
221
214
|
this.#children.push(child);
|
|
222
215
|
if (child.parent)
|
|
223
216
|
child.parent.removeChild(child);
|
|
224
|
-
(<
|
|
217
|
+
(<AbstractTreeNode<any, any>>child.parent) = this;
|
|
225
218
|
return true;
|
|
226
219
|
}
|
|
227
220
|
|
|
228
|
-
public addData(data:
|
|
221
|
+
public addData(data: U): boolean {
|
|
229
222
|
this.#data.push(data);
|
|
230
223
|
return true;
|
|
231
224
|
}
|
|
@@ -235,8 +228,9 @@ export class TreeNode implements ITreeNode {
|
|
|
235
228
|
return true;
|
|
236
229
|
}
|
|
237
230
|
|
|
238
|
-
public clone():
|
|
239
|
-
const clone = new
|
|
231
|
+
public clone(): T {
|
|
232
|
+
const clone = new (<any>this.constructor);
|
|
233
|
+
clone.name = this.name;
|
|
240
234
|
clone.originalId = this.originalId;
|
|
241
235
|
clone.visible = this.visible;
|
|
242
236
|
for (let child of this.#children)
|
|
@@ -252,8 +246,9 @@ export class TreeNode implements ITreeNode {
|
|
|
252
246
|
return clone;
|
|
253
247
|
}
|
|
254
248
|
|
|
255
|
-
public cloneInstance():
|
|
256
|
-
const clone = new
|
|
249
|
+
public cloneInstance(): T {
|
|
250
|
+
const clone = new (<any>this.constructor);
|
|
251
|
+
clone.name = this.name;
|
|
257
252
|
clone.originalId = this.originalId;
|
|
258
253
|
clone.visible = this.visible;
|
|
259
254
|
for (let child of this.#children)
|
|
@@ -269,14 +264,14 @@ export class TreeNode implements ITreeNode {
|
|
|
269
264
|
return clone;
|
|
270
265
|
}
|
|
271
266
|
|
|
272
|
-
public getChild(id: string):
|
|
267
|
+
public getChild(id: string): T | undefined {
|
|
273
268
|
for (let i = 0; i < this.#children.length; i++)
|
|
274
269
|
if (this.#children[i].id === id)
|
|
275
270
|
return this.#children[i];
|
|
276
271
|
return;
|
|
277
272
|
}
|
|
278
273
|
|
|
279
|
-
public getData(id: string):
|
|
274
|
+
public getData(id: string): U | undefined {
|
|
280
275
|
for (let i = 0; i < this.#data.length; i++)
|
|
281
276
|
if (this.#data[i].id === id)
|
|
282
277
|
return this.#data[i];
|
|
@@ -285,7 +280,7 @@ export class TreeNode implements ITreeNode {
|
|
|
285
280
|
|
|
286
281
|
public getPath(): string {
|
|
287
282
|
let path = this.name;
|
|
288
|
-
let node:
|
|
283
|
+
let node: T | undefined = this.parent;
|
|
289
284
|
while (node) {
|
|
290
285
|
path = node.name + '.' + path;
|
|
291
286
|
node = node.parent;
|
|
@@ -300,11 +295,11 @@ export class TreeNode implements ITreeNode {
|
|
|
300
295
|
return;
|
|
301
296
|
}
|
|
302
297
|
|
|
303
|
-
public hasChild(child:
|
|
298
|
+
public hasChild(child: T): boolean {
|
|
304
299
|
return this.#children.includes(child);
|
|
305
300
|
}
|
|
306
301
|
|
|
307
|
-
public hasData(data:
|
|
302
|
+
public hasData(data: U): boolean {
|
|
308
303
|
return this.#data.includes(data);
|
|
309
304
|
}
|
|
310
305
|
|
|
@@ -312,15 +307,15 @@ export class TreeNode implements ITreeNode {
|
|
|
312
307
|
return this.#transformations.includes(transformation);
|
|
313
308
|
}
|
|
314
309
|
|
|
315
|
-
public removeChild(child:
|
|
310
|
+
public removeChild(child: T): boolean {
|
|
316
311
|
const index = this.#children.indexOf(child);
|
|
317
312
|
if (index === -1) return false;
|
|
318
313
|
this.#children.splice(index, 1);
|
|
319
|
-
(<
|
|
314
|
+
(<T | undefined>child.parent) = undefined;
|
|
320
315
|
return true;
|
|
321
316
|
}
|
|
322
317
|
|
|
323
|
-
public removeData(data:
|
|
318
|
+
public removeData(data: U): boolean {
|
|
324
319
|
const index = this.#data.indexOf(data);
|
|
325
320
|
if (index === -1) return false;
|
|
326
321
|
this.#data.splice(index, 1);
|
|
@@ -334,15 +329,15 @@ export class TreeNode implements ITreeNode {
|
|
|
334
329
|
return true;
|
|
335
330
|
}
|
|
336
331
|
|
|
337
|
-
public traverse(callback: (node:
|
|
338
|
-
callback(this);
|
|
332
|
+
public traverse(callback: (node: T) => void): void {
|
|
333
|
+
callback(<T><unknown>this);
|
|
339
334
|
|
|
340
335
|
for(let i = 0; i < this.children.length; i++)
|
|
341
336
|
this.children[i].traverse(callback);
|
|
342
337
|
}
|
|
343
338
|
|
|
344
339
|
public updateVersion(): void {
|
|
345
|
-
let node = <
|
|
340
|
+
let node = <AbstractTreeNode<any, any>>this;
|
|
346
341
|
while (node.parent) {
|
|
347
342
|
node = node.parent;
|
|
348
343
|
(<any>node.version) = this.#uuidGenerator.create();
|
|
@@ -3,7 +3,7 @@ import { UuidGenerator, EventEngine, EVENTTYPE } from '@shapediver/viewer.shared
|
|
|
3
3
|
|
|
4
4
|
import { ITreeNodeData } from '../interfaces/ITreeNodeData'
|
|
5
5
|
|
|
6
|
-
export abstract class AbstractTreeNodeData implements ITreeNodeData {
|
|
6
|
+
export abstract class AbstractTreeNodeData<T extends ITreeNodeData<any>> implements ITreeNodeData<T> {
|
|
7
7
|
// #region Properties (3)
|
|
8
8
|
|
|
9
9
|
#version: string;
|
|
@@ -56,7 +56,10 @@ export abstract class AbstractTreeNodeData implements ITreeNodeData {
|
|
|
56
56
|
/**
|
|
57
57
|
* Clones the tree node data.
|
|
58
58
|
*/
|
|
59
|
-
public
|
|
59
|
+
public clone(): T {
|
|
60
|
+
const clone = new (<any>this.constructor);
|
|
61
|
+
return clone;
|
|
62
|
+
};
|
|
60
63
|
|
|
61
64
|
// #endregion Public Abstract Methods (1)
|
|
62
65
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ITreeNodeDataThreeJs } from "../../interfaces/three/ITreeNodeDataThreeJs";
|
|
2
|
+
import { AbstractTreeNodeData } from "../AbstractTreeNodeData";
|
|
3
|
+
|
|
4
|
+
export abstract class AbstractTreeNodeDataThreeJs extends AbstractTreeNodeData<ITreeNodeDataThreeJs> implements ITreeNodeDataThreeJs {
|
|
5
|
+
#threeJsObject: { [key: string]: THREE.Object3D | THREE.BufferGeometry | THREE.Material | undefined } = {};
|
|
6
|
+
#updateCallbackThreeJsObject: ((newObj: THREE.Object3D | THREE.BufferGeometry | THREE.Material | undefined, oldObj: THREE.Object3D | THREE.BufferGeometry | THREE.Material | undefined, viewport: string) => void) | null = null;
|
|
7
|
+
|
|
8
|
+
public get threeJsObject(): { [key: string]: THREE.Object3D | THREE.BufferGeometry | THREE.Material | undefined } {
|
|
9
|
+
return this.#threeJsObject;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { singleton } from "tsyringe";
|
|
2
|
+
import { ITreeNodeThreeJs } from "../../interfaces/three/ITreeNodeThreeJs";
|
|
3
|
+
import { ITreeThreeJs } from "../../interfaces/three/ITreeThreeJs";
|
|
4
|
+
import { AbstractTree } from "../AbstractTree";
|
|
5
|
+
import { TreeNodeThreeJs } from "./TreeNodeThreejs";
|
|
6
|
+
|
|
7
|
+
@singleton()
|
|
8
|
+
export class Tree extends AbstractTree<ITreeNodeThreeJs> implements ITreeThreeJs {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(new TreeNodeThreeJs('root'))
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ITreeNodeDataThreeJs } from "../../interfaces/three/ITreeNodeDataThreeJs";
|
|
2
|
+
import { ITreeNodeThreeJs } from "../../interfaces/three/ITreeNodeThreeJs";
|
|
3
|
+
import { AbstractTreeNode } from "../AbstractTreeNode";
|
|
4
|
+
|
|
5
|
+
export class TreeNodeThreeJs extends AbstractTreeNode<ITreeNodeThreeJs, ITreeNodeDataThreeJs> implements ITreeNodeThreeJs {
|
|
6
|
+
#threeJsObject: { [key: string]: THREE.Object3D } = {};
|
|
7
|
+
#updateCallbackThreeJsObject: ((newObj: THREE.Object3D, oldObj: THREE.Object3D, viewport: string) => void) | null = null;
|
|
8
|
+
|
|
9
|
+
public get threeJsObject(): { [key: string]: THREE.Object3D } {
|
|
10
|
+
return this.#threeJsObject;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public get updateCallbackThreeJsObject(): ((newObj: THREE.Object3D, oldObj: THREE.Object3D, viewport: string) => void) | null {
|
|
14
|
+
return this.#updateCallbackThreeJsObject;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public set updateCallbackThreeJsObject(value: ((newObj: THREE.Object3D, oldObj: THREE.Object3D, viewport: string) => void) | null) {
|
|
18
|
+
this.#updateCallbackThreeJsObject = value;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { ITransformation } from './interfaces/ITreeNode'
|
|
2
|
+
import { TreeNodeThreeJs } from './implementation/three/TreeNodeThreejs'
|
|
3
|
+
import { ITreeNodeThreeJs } from './interfaces/three/ITreeNodeThreeJs'
|
|
4
|
+
import { Tree } from './implementation/three/Tree'
|
|
5
|
+
import { ITreeThreeJs } from './interfaces/three/ITreeThreeJs'
|
|
6
|
+
import { ITreeNodeDataThreeJs } from './interfaces/three/ITreeNodeDataThreeJs'
|
|
7
|
+
import { AbstractTreeNodeDataThreeJs } from './implementation/three/AbstractTreeNodeDataThreeJs'
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
|
-
ITree, Tree
|
|
10
|
+
ITreeThreeJs as ITree, Tree
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export {
|
|
14
|
-
ITreeNode, TreeNode, ITransformation
|
|
14
|
+
ITreeNodeThreeJs as ITreeNode, TreeNodeThreeJs as TreeNode, ITransformation
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export {
|
|
18
|
-
ITreeNodeData,
|
|
19
|
-
ISDObject,
|
|
20
|
-
AbstractTreeNodeData
|
|
18
|
+
ITreeNodeDataThreeJs as ITreeNodeData, AbstractTreeNodeDataThreeJs as AbstractTreeNodeData
|
|
21
19
|
}
|
package/src/interfaces/ITree.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { ITreeNode } from "./ITreeNode";
|
|
2
|
+
import { ITreeNodeData } from "./ITreeNodeData";
|
|
2
3
|
|
|
3
|
-
export interface ITree {
|
|
4
|
+
export interface ITree<T extends ITreeNode<any, ITreeNodeData<any>>> {
|
|
4
5
|
// #region Properties (1)
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The root of the tree.
|
|
9
|
+
*/
|
|
10
|
+
readonly root: T;
|
|
7
11
|
|
|
8
12
|
// #endregion Properties (1)
|
|
9
13
|
|
|
@@ -16,7 +20,7 @@ export interface ITree {
|
|
|
16
20
|
* @param parent the targeted parent node
|
|
17
21
|
* @param root optional root at which the process begins, root node will be used per default
|
|
18
22
|
*/
|
|
19
|
-
addNode(node:
|
|
23
|
+
addNode(node: T, parent?: T, root?: T): boolean;
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* Add the node at the corresponding path. (paths are dot separated ids)
|
|
@@ -25,7 +29,7 @@ export interface ITree {
|
|
|
25
29
|
* @param path the path at which the node should be added
|
|
26
30
|
* @param root optional root at which the process begins, root node will be used per default
|
|
27
31
|
*/
|
|
28
|
-
addNodeAtPath(node:
|
|
32
|
+
addNodeAtPath(node: T, path?: string, root?: T): boolean;
|
|
29
33
|
|
|
30
34
|
/**
|
|
31
35
|
* Get the node at the provided path.
|
|
@@ -34,7 +38,7 @@ export interface ITree {
|
|
|
34
38
|
* @param root
|
|
35
39
|
* @returns
|
|
36
40
|
*/
|
|
37
|
-
getNodeAtPath(path?: string, root?:
|
|
41
|
+
getNodeAtPath(path?: string, root?: T): T | null;
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
44
|
* Remove a node from the tree.
|
|
@@ -42,7 +46,7 @@ export interface ITree {
|
|
|
42
46
|
* @param node the node to remove
|
|
43
47
|
* @param root optional root at which the process begins, root node will be used per default
|
|
44
48
|
*/
|
|
45
|
-
removeNode(node:
|
|
49
|
+
removeNode(node: T, root?: T): boolean;
|
|
46
50
|
|
|
47
51
|
/**
|
|
48
52
|
* Remove a node via the path of it.
|
|
@@ -50,7 +54,7 @@ export interface ITree {
|
|
|
50
54
|
* @param path the path of the node to be removed
|
|
51
55
|
* @param root optional root at which the process begins, root node will be used per default
|
|
52
56
|
*/
|
|
53
|
-
removeNodeAtPath(path: string, root?:
|
|
57
|
+
removeNodeAtPath(path: string, root?: T): boolean;
|
|
54
58
|
|
|
55
59
|
// #endregion Public Methods (5)
|
|
56
60
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { mat4 } from 'gl-matrix'
|
|
2
2
|
import { IBox } from '@shapediver/viewer.shared.math'
|
|
3
3
|
import { ITreeNodeData } from './ITreeNodeData'
|
|
4
|
-
import { ISDObject } from './ISDObject'
|
|
5
4
|
|
|
6
5
|
export interface ITransformation {
|
|
7
6
|
// #region Properties (2)
|
|
@@ -12,147 +11,182 @@ export interface ITransformation {
|
|
|
12
11
|
// #endregion Properties (2)
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
export interface ITreeNode {
|
|
16
|
-
// #region Properties (
|
|
17
|
-
|
|
18
|
-
readonly children: ITreeNode[];
|
|
19
|
-
readonly data: ITreeNodeData[];
|
|
14
|
+
export interface ITreeNode<T extends ITreeNode<any, ITreeNodeData<any>>, U extends ITreeNodeData<any>> {
|
|
15
|
+
// #region Properties (17)
|
|
20
16
|
|
|
17
|
+
/**
|
|
18
|
+
* The bounding box of this tree node.
|
|
19
|
+
*/
|
|
20
|
+
readonly boundingBox: IBox;
|
|
21
|
+
/**
|
|
22
|
+
* The children of this tree node. Can be added and remove via {@link addChild} and {@link removeChild}.
|
|
23
|
+
*/
|
|
24
|
+
readonly children: T[];
|
|
25
|
+
/**
|
|
26
|
+
* The data of this tree node.
|
|
27
|
+
* The data can include Geometry, Materials, Lights, Cameras, but also informational or custom data.
|
|
28
|
+
*
|
|
29
|
+
* Can be added and remove via {@link addData} and {@link removeData}.
|
|
30
|
+
*/
|
|
31
|
+
readonly data: U[];
|
|
32
|
+
/**
|
|
33
|
+
* The ID of the tree node.
|
|
34
|
+
*/
|
|
21
35
|
readonly id: string;
|
|
22
|
-
|
|
36
|
+
/**
|
|
37
|
+
* The name of the tree node.
|
|
38
|
+
*/
|
|
23
39
|
readonly name: string;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
/**
|
|
41
|
+
* The matrix of the tree node.
|
|
42
|
+
* This is computed via all transformations in the {@link transformations} property.
|
|
43
|
+
*/
|
|
27
44
|
readonly nodeMatrix: mat4;
|
|
45
|
+
/**
|
|
46
|
+
* The original ID of the tree node, if it was copied.
|
|
47
|
+
*/
|
|
48
|
+
readonly originalId: string;
|
|
49
|
+
/**
|
|
50
|
+
* The parent of the tree node.
|
|
51
|
+
* This property is automatically managed by {@link addChild} and {@link removeChild}.
|
|
52
|
+
*/
|
|
53
|
+
readonly parent?: T;
|
|
54
|
+
/**
|
|
55
|
+
* The version of the tree node.
|
|
56
|
+
* If the version changes, the node will be marked for an update.
|
|
57
|
+
* A version change can be triggered via {@link updateVersion}.
|
|
58
|
+
*/
|
|
59
|
+
readonly version: string;
|
|
60
|
+
/**
|
|
61
|
+
* The world matrix of the tree node.
|
|
62
|
+
* This includes also the transformations of all parents.
|
|
63
|
+
*/
|
|
28
64
|
readonly worldMatrix: mat4;
|
|
29
65
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
66
|
+
/**
|
|
67
|
+
* The inverse matrices for the bones, if specified.
|
|
68
|
+
*/
|
|
69
|
+
boneInverses: mat4[];
|
|
70
|
+
/**
|
|
71
|
+
* The optional bones that build a skeleton for animations.
|
|
72
|
+
*/
|
|
73
|
+
bones: T[];
|
|
74
|
+
/**
|
|
75
|
+
* The viewports to exclude this tree node from.
|
|
76
|
+
*/
|
|
35
77
|
excludeViewports: string[];
|
|
78
|
+
/**
|
|
79
|
+
* The viewports to restrict this tree node to.
|
|
80
|
+
*/
|
|
36
81
|
restrictViewports: string[];
|
|
37
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Property to mark this node as a skin node. (default: false)
|
|
84
|
+
*/
|
|
85
|
+
skinNode: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* The transformation to be applied to this tree node.
|
|
88
|
+
*/
|
|
38
89
|
transformations: ITransformation[];
|
|
90
|
+
/**
|
|
91
|
+
* Option to make this tree node visible. (default: true)
|
|
92
|
+
*/
|
|
39
93
|
visible: boolean;
|
|
40
94
|
|
|
41
|
-
|
|
42
|
-
bones: ITreeNode[];
|
|
43
|
-
boneInverses: mat4[];
|
|
44
|
-
|
|
45
|
-
// #endregion Properties (16)
|
|
95
|
+
// #endregion Properties (17)
|
|
46
96
|
|
|
47
|
-
// #region Public Methods (
|
|
97
|
+
// #region Public Methods (17)
|
|
48
98
|
|
|
49
99
|
/**
|
|
50
100
|
* Add a child to the children of this node.
|
|
51
101
|
*
|
|
52
102
|
* @param child the child to add
|
|
53
103
|
*/
|
|
54
|
-
addChild(child:
|
|
55
|
-
|
|
104
|
+
addChild(child: T): boolean;
|
|
56
105
|
/**
|
|
57
106
|
* Add a data item to node.
|
|
58
107
|
*
|
|
59
108
|
* @param data the data to add
|
|
60
109
|
*/
|
|
61
|
-
addData(data:
|
|
62
|
-
|
|
110
|
+
addData(data: U): boolean;
|
|
63
111
|
/**
|
|
64
112
|
* Add a transformation to this node.
|
|
65
113
|
*
|
|
66
114
|
* @param transformation the transformation to add
|
|
67
115
|
*/
|
|
68
116
|
addTransformation(transformation: ITransformation): boolean;
|
|
69
|
-
|
|
70
117
|
/**
|
|
71
118
|
* Clones this node and all its children.
|
|
72
119
|
* The data objects like GeometryData, MaterialData, etc. are cloned as well.
|
|
73
120
|
* Depending on the size of the node and the amount of children, this can therefore be relatively slow.
|
|
74
121
|
*/
|
|
75
|
-
clone():
|
|
76
|
-
|
|
122
|
+
clone(): T;
|
|
77
123
|
/**
|
|
78
124
|
* Clones this node and all its children.
|
|
79
125
|
* The data objects like GeometryData, MaterialData, etc. are not copied in this case.
|
|
80
126
|
*/
|
|
81
|
-
cloneInstance():
|
|
82
|
-
|
|
127
|
+
cloneInstance(): T;
|
|
83
128
|
/**
|
|
84
129
|
* Returns the child with the specified id
|
|
85
130
|
*/
|
|
86
|
-
getChild(id: string):
|
|
87
|
-
|
|
131
|
+
getChild(id: string): T | undefined;
|
|
88
132
|
/**
|
|
89
133
|
* Returns the data item with the specified id
|
|
90
134
|
*/
|
|
91
|
-
getData(id: string):
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Returns the transformation with the specified id
|
|
95
|
-
*/
|
|
96
|
-
getTransformation(id: string): ITransformation | undefined;
|
|
97
|
-
|
|
135
|
+
getData(id: string): U | undefined;
|
|
98
136
|
/**
|
|
99
137
|
* Return the path to this node.
|
|
100
138
|
*/
|
|
101
139
|
getPath(): string;
|
|
102
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Returns the transformation with the specified id
|
|
142
|
+
*/
|
|
143
|
+
getTransformation(id: string): ITransformation | undefined;
|
|
103
144
|
/**
|
|
104
145
|
* Check for existence of a child from the children of this node.
|
|
105
146
|
*
|
|
106
147
|
* @param child the child to check
|
|
107
148
|
*/
|
|
108
|
-
hasChild(child:
|
|
109
|
-
|
|
149
|
+
hasChild(child: T): boolean;
|
|
110
150
|
/**
|
|
111
151
|
* Check for existence of a data item of this node.
|
|
112
152
|
*
|
|
113
153
|
* @param data the data item to check
|
|
114
154
|
*/
|
|
115
|
-
hasData(data:
|
|
116
|
-
|
|
155
|
+
hasData(data: U): boolean;
|
|
117
156
|
/**
|
|
118
157
|
* Check for existence of a transformation of this node.
|
|
119
158
|
*
|
|
120
159
|
* @param data the transformation to check
|
|
121
160
|
*/
|
|
122
161
|
hasTransformation(transformation: ITransformation): boolean;
|
|
123
|
-
|
|
124
162
|
/**
|
|
125
163
|
* Remove a child from the children of this node.
|
|
126
164
|
*
|
|
127
165
|
* @param child the child to remove
|
|
128
166
|
*/
|
|
129
|
-
removeChild(child:
|
|
130
|
-
|
|
167
|
+
removeChild(child: T): boolean;
|
|
131
168
|
/**
|
|
132
169
|
* Remove a data item from this node.
|
|
133
170
|
*
|
|
134
171
|
* @param data the data to remove
|
|
135
172
|
*/
|
|
136
|
-
removeData(data:
|
|
137
|
-
|
|
173
|
+
removeData(data: U): boolean;
|
|
138
174
|
/**
|
|
139
175
|
* Remove a transformation from this node.
|
|
140
176
|
*
|
|
141
177
|
* @param transformation the transformation to remove
|
|
142
178
|
*/
|
|
143
179
|
removeTransformation(transformation: ITransformation): boolean;
|
|
144
|
-
|
|
145
180
|
/**
|
|
146
181
|
* Traverse this node and all it's children and executes the callback for all of them
|
|
147
182
|
*
|
|
148
183
|
* @param callback
|
|
149
184
|
*/
|
|
150
|
-
traverse(callback: (node:
|
|
151
|
-
|
|
185
|
+
traverse(callback: (node: T) => void): void;
|
|
152
186
|
/**
|
|
153
|
-
* Update the version
|
|
187
|
+
* Update the version.
|
|
154
188
|
*/
|
|
155
189
|
updateVersion(): void;
|
|
156
190
|
|
|
157
|
-
// #endregion Public Methods (
|
|
191
|
+
// #endregion Public Methods (17)
|
|
158
192
|
}
|
|
@@ -1,6 +1,29 @@
|
|
|
1
|
-
export interface ITreeNodeData {
|
|
1
|
+
export interface ITreeNodeData<T extends ITreeNodeData<any>> {
|
|
2
|
+
// #region Properties (2)
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The ID of the tree node data.
|
|
6
|
+
*/
|
|
2
7
|
id: string;
|
|
8
|
+
/**
|
|
9
|
+
* The version of the tree node data.
|
|
10
|
+
* If the version changes, the node data will be marked for an update.
|
|
11
|
+
* A version change can be triggered via {@link updateVersion}.
|
|
12
|
+
*/
|
|
3
13
|
version: string;
|
|
14
|
+
|
|
15
|
+
// #endregion Properties (2)
|
|
16
|
+
|
|
17
|
+
// #region Public Methods (2)
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Clones this node tree data.
|
|
21
|
+
*/
|
|
22
|
+
clone(): T;
|
|
23
|
+
/**
|
|
24
|
+
* Update the version.
|
|
25
|
+
*/
|
|
4
26
|
updateVersion(): void;
|
|
5
|
-
|
|
27
|
+
|
|
28
|
+
// #endregion Public Methods (2)
|
|
6
29
|
}
|