@zephyr3d/scene 0.1.0 → 0.1.2
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/README.md +46 -0
- package/dist/animation/animation.js +28 -28
- package/dist/animation/skeleton.js +14 -14
- package/dist/animation/usertrack.js +9 -9
- package/dist/app.js +31 -31
- package/dist/asset/assetmanager.js +50 -50
- package/dist/asset/builtin.js +157 -157
- package/dist/asset/loaders/dds/dds_loader.js +11 -11
- package/dist/asset/loaders/gltf/gltf_loader.js +10 -10
- package/dist/asset/loaders/hdr/hdr.js +5 -5
- package/dist/asset/loaders/image/tga_Loader.js +3 -3
- package/dist/asset/loaders/image/webimage_loader.js +3 -3
- package/dist/asset/loaders/loader.js +19 -19
- package/dist/asset/model.js +57 -57
- package/dist/blitter/blitter.js +35 -35
- package/dist/blitter/box.js +24 -24
- package/dist/blitter/depthlimitedgaussion.js +3 -3
- package/dist/blitter/gaussianblur.js +21 -21
- package/dist/camera/camera.js +68 -68
- package/dist/index.d.ts +2 -0
- package/dist/material/grassmaterial.js +17 -17
- package/dist/material/lambert.js +3 -3
- package/dist/material/lightmodel.js +362 -362
- package/dist/material/material.js +50 -50
- package/dist/material/meshmaterial.js +48 -48
- package/dist/material/unlit.js +3 -3
- package/dist/posteffect/bloom.js +5 -5
- package/dist/posteffect/compositor.js +16 -16
- package/dist/posteffect/fxaa.js +5 -5
- package/dist/posteffect/grayscale.js +5 -5
- package/dist/posteffect/posteffect.js +42 -42
- package/dist/posteffect/sao.js +5 -5
- package/dist/posteffect/tonemap.js +5 -5
- package/dist/posteffect/water.js +6 -6
- package/dist/render/cull_visitor.js +12 -12
- package/dist/render/depth_pass.js +8 -8
- package/dist/render/envlight.js +104 -104
- package/dist/render/render_queue.js +33 -33
- package/dist/render/renderpass.js +18 -18
- package/dist/render/renderscheme.js +14 -14
- package/dist/render/scatteringlut.js +3 -3
- package/dist/render/sky.js +38 -38
- package/dist/render/temporalcache.js +4 -4
- package/dist/render/watermesh.js +5 -5
- package/dist/scene/graph_node.js +25 -25
- package/dist/scene/octree.js +191 -191
- package/dist/scene/scene.js +37 -37
- package/dist/scene/terrain/grass.js +27 -27
- package/dist/scene/terrain/quadtree.js +45 -45
- package/dist/shaders/framework.js +161 -161
- package/dist/shaders/lighting.js +7 -7
- package/dist/shaders/noise.js +43 -43
- package/dist/shadow/shadowmapper.js +76 -76
- package/dist/shadow/ssm.js +34 -34
- package/dist/utility/bounding_volume.js +30 -27
- package/dist/utility/bounding_volume.js.map +1 -1
- package/dist/utility/shprojection.js +14 -14
- package/package.json +70 -70
- package/dist/material/mixins/texture.js +0 -110
- package/dist/material/mixins/texture.js.map +0 -1
package/dist/scene/octree.js
CHANGED
|
@@ -12,9 +12,9 @@ var OctreePlacement;
|
|
|
12
12
|
OctreePlacement[OctreePlacement["NNP"] = 6] = "NNP";
|
|
13
13
|
OctreePlacement[OctreePlacement["NNN"] = 7] = "NNN";
|
|
14
14
|
})(OctreePlacement || (OctreePlacement = {}));
|
|
15
|
-
/**
|
|
16
|
-
* Octree node
|
|
17
|
-
* @public
|
|
15
|
+
/**
|
|
16
|
+
* Octree node
|
|
17
|
+
* @public
|
|
18
18
|
*/ class OctreeNode {
|
|
19
19
|
/** @internal */ _chunk;
|
|
20
20
|
/** @internal */ _position;
|
|
@@ -22,8 +22,8 @@ var OctreePlacement;
|
|
|
22
22
|
/** @internal */ _nodes;
|
|
23
23
|
/** @internal */ _box;
|
|
24
24
|
/** @internal */ _boxLoosed;
|
|
25
|
-
/**
|
|
26
|
-
* Creates an instance of octree node
|
|
25
|
+
/**
|
|
26
|
+
* Creates an instance of octree node
|
|
27
27
|
*/ constructor(){
|
|
28
28
|
this._chunk = null;
|
|
29
29
|
this._position = 0;
|
|
@@ -32,29 +32,29 @@ var OctreePlacement;
|
|
|
32
32
|
this._box = null;
|
|
33
33
|
this._boxLoosed = null;
|
|
34
34
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Get all the scene nodes that this octree node contains
|
|
37
|
-
* @returns An array of the scene nodes
|
|
35
|
+
/**
|
|
36
|
+
* Get all the scene nodes that this octree node contains
|
|
37
|
+
* @returns An array of the scene nodes
|
|
38
38
|
*/ getNodes() {
|
|
39
39
|
return this._nodes;
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Gets the level index of the octree node
|
|
43
|
-
* @returns The level index
|
|
41
|
+
/**
|
|
42
|
+
* Gets the level index of the octree node
|
|
43
|
+
* @returns The level index
|
|
44
44
|
*/ getLevel() {
|
|
45
45
|
return this._chunk.getLevel();
|
|
46
46
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Adds a scene node to this node
|
|
49
|
-
* @param node - The scene node to be added
|
|
47
|
+
/**
|
|
48
|
+
* Adds a scene node to this node
|
|
49
|
+
* @param node - The scene node to be added
|
|
50
50
|
*/ addNode(node) {
|
|
51
51
|
if (node && this._nodes.indexOf(node) < 0) {
|
|
52
52
|
this._nodes.push(node);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Removes a scene node from this node
|
|
57
|
-
* @param node - The scene node to be removed
|
|
55
|
+
/**
|
|
56
|
+
* Removes a scene node from this node
|
|
57
|
+
* @param node - The scene node to be removed
|
|
58
58
|
*/ removeNode(node) {
|
|
59
59
|
const index = this._nodes.indexOf(node);
|
|
60
60
|
if (index >= 0) {
|
|
@@ -64,40 +64,40 @@ var OctreePlacement;
|
|
|
64
64
|
/** Removes all the scene nodes that this octree node contains */ clearNodes() {
|
|
65
65
|
this._nodes = [];
|
|
66
66
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Sets the octree chunk
|
|
69
|
-
* @param chunk - The octree chunk to be set
|
|
67
|
+
/**
|
|
68
|
+
* Sets the octree chunk
|
|
69
|
+
* @param chunk - The octree chunk to be set
|
|
70
70
|
*/ setChunk(chunk) {
|
|
71
71
|
console.assert(!!chunk, 'Invalid chunk');
|
|
72
72
|
this._chunk = chunk;
|
|
73
73
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Gets the octree chunk
|
|
76
|
-
* @returns The octree chunk
|
|
74
|
+
/**
|
|
75
|
+
* Gets the octree chunk
|
|
76
|
+
* @returns The octree chunk
|
|
77
77
|
*/ getChunk() {
|
|
78
78
|
return this._chunk;
|
|
79
79
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Sets the position of the node
|
|
82
|
-
* @param index - Position of the node
|
|
80
|
+
/**
|
|
81
|
+
* Sets the position of the node
|
|
82
|
+
* @param index - Position of the node
|
|
83
83
|
*/ setPosition(index) {
|
|
84
84
|
this._position = index;
|
|
85
85
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Gets the position of the octree node
|
|
88
|
-
* @returns Position of the octree node
|
|
86
|
+
/**
|
|
87
|
+
* Gets the position of the octree node
|
|
88
|
+
* @returns Position of the octree node
|
|
89
89
|
*/ getPosition() {
|
|
90
90
|
return this._position;
|
|
91
91
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Invalidates the cached box
|
|
92
|
+
/**
|
|
93
|
+
* Invalidates the cached box
|
|
94
94
|
*/ invalidateBox() {
|
|
95
95
|
this._box = null;
|
|
96
96
|
this.getParent()?.invalidateBox();
|
|
97
97
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Get the bounding box of the octree node
|
|
100
|
-
* @returns The bounding box of the octree node
|
|
98
|
+
/**
|
|
99
|
+
* Get the bounding box of the octree node
|
|
100
|
+
* @returns The bounding box of the octree node
|
|
101
101
|
*/ getBox() {
|
|
102
102
|
if (this._box === null) {
|
|
103
103
|
const box = new AABB();
|
|
@@ -127,9 +127,9 @@ var OctreePlacement;
|
|
|
127
127
|
}
|
|
128
128
|
return this._box;
|
|
129
129
|
}
|
|
130
|
-
/**
|
|
131
|
-
* Gets the loosed bounding box of the node
|
|
132
|
-
* @returns The loosed bounding box of the node
|
|
130
|
+
/**
|
|
131
|
+
* Gets the loosed bounding box of the node
|
|
132
|
+
* @returns The loosed bounding box of the node
|
|
133
133
|
*/ getBoxLoosed() {
|
|
134
134
|
if (this._boxLoosed === null) {
|
|
135
135
|
console.assert(!!this._chunk, 'Invalid chunk');
|
|
@@ -145,9 +145,9 @@ var OctreePlacement;
|
|
|
145
145
|
}
|
|
146
146
|
return this._boxLoosed;
|
|
147
147
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Gets min point of the node
|
|
150
|
-
* @returns Min point of the node
|
|
148
|
+
/**
|
|
149
|
+
* Gets min point of the node
|
|
150
|
+
* @returns Min point of the node
|
|
151
151
|
*/ getMinPoint() {
|
|
152
152
|
console.assert(!!this._chunk, 'Invalid chunk');
|
|
153
153
|
const d = this._chunk.getDimension();
|
|
@@ -158,9 +158,9 @@ var OctreePlacement;
|
|
|
158
158
|
const pz = Math.floor(Math.floor(this._position / d) / d);
|
|
159
159
|
return new Vector3(px, py, pz).scaleBy(nodeSize).subBy(new Vector3(halfWorldSize, halfWorldSize, halfWorldSize));
|
|
160
160
|
}
|
|
161
|
-
/**
|
|
162
|
-
* Gets max point of the node
|
|
163
|
-
* @returns Max point of the node
|
|
161
|
+
/**
|
|
162
|
+
* Gets max point of the node
|
|
163
|
+
* @returns Max point of the node
|
|
164
164
|
*/ getMaxPoint() {
|
|
165
165
|
console.assert(!!this._chunk, 'Invalid chunk');
|
|
166
166
|
const d = this._chunk.getDimension();
|
|
@@ -171,62 +171,62 @@ var OctreePlacement;
|
|
|
171
171
|
const pz = Math.floor(Math.floor(this._position / d) / d) + 1;
|
|
172
172
|
return new Vector3(px, py, pz).scaleBy(nodeSize).subBy(new Vector3(halfWorldSize, halfWorldSize, halfWorldSize));
|
|
173
173
|
}
|
|
174
|
-
/**
|
|
175
|
-
* Gets the loosed min point of the node
|
|
176
|
-
* @returns Loosed min point of the node
|
|
174
|
+
/**
|
|
175
|
+
* Gets the loosed min point of the node
|
|
176
|
+
* @returns Loosed min point of the node
|
|
177
177
|
*/ getMinPointLoosed() {
|
|
178
178
|
const halfNodeSize = this._chunk.getNodeSize() * 0.5;
|
|
179
179
|
return this.getMinPoint().subBy(new Vector3(halfNodeSize, halfNodeSize, halfNodeSize));
|
|
180
180
|
}
|
|
181
|
-
/**
|
|
182
|
-
* Gets the loosed max point of the node
|
|
183
|
-
* @returns Loosed max point of the node
|
|
181
|
+
/**
|
|
182
|
+
* Gets the loosed max point of the node
|
|
183
|
+
* @returns Loosed max point of the node
|
|
184
184
|
*/ getMaxPointLoosed() {
|
|
185
185
|
const halfNodeSize = this._chunk.getNodeSize() * 0.5;
|
|
186
186
|
return this.getMaxPoint().addBy(new Vector3(halfNodeSize, halfNodeSize, halfNodeSize));
|
|
187
187
|
}
|
|
188
|
-
/**
|
|
189
|
-
* Get reference of the node
|
|
190
|
-
* @returns Reference of the node
|
|
188
|
+
/**
|
|
189
|
+
* Get reference of the node
|
|
190
|
+
* @returns Reference of the node
|
|
191
191
|
*/ getReference() {
|
|
192
192
|
return this._references;
|
|
193
193
|
}
|
|
194
|
-
/**
|
|
195
|
-
* Gets the child node by a given placement
|
|
196
|
-
* @param placement - The placement
|
|
197
|
-
* @returns Child node at the given placement
|
|
194
|
+
/**
|
|
195
|
+
* Gets the child node by a given placement
|
|
196
|
+
* @param placement - The placement
|
|
197
|
+
* @returns Child node at the given placement
|
|
198
198
|
*/ getChild(placement) {
|
|
199
199
|
console.assert(!!this._chunk, 'Invalid chunk');
|
|
200
200
|
const next = this._chunk.getNext();
|
|
201
201
|
return next ? next.getNode(this._chunk.getChildIndex(this._position, placement)) : null;
|
|
202
202
|
}
|
|
203
|
-
/**
|
|
204
|
-
* Gets or creates a child node by a given placement
|
|
205
|
-
* @param placement - The placement
|
|
206
|
-
* @returns The child node fetched
|
|
203
|
+
/**
|
|
204
|
+
* Gets or creates a child node by a given placement
|
|
205
|
+
* @param placement - The placement
|
|
206
|
+
* @returns The child node fetched
|
|
207
207
|
*/ getOrCreateChild(placement) {
|
|
208
208
|
console.assert(!!this._chunk, 'Invalid chunk');
|
|
209
209
|
const next = this._chunk.getNext();
|
|
210
210
|
return next ? next.getOrCreateNode(this._chunk.getChildIndex(this._position, placement)) : null;
|
|
211
211
|
}
|
|
212
|
-
/**
|
|
213
|
-
* Gets parent of the node
|
|
214
|
-
* @returns Parent of the node
|
|
212
|
+
/**
|
|
213
|
+
* Gets parent of the node
|
|
214
|
+
* @returns Parent of the node
|
|
215
215
|
*/ getParent() {
|
|
216
216
|
console.assert(!!this._chunk, 'Invalid chunk');
|
|
217
217
|
const prev = this._chunk.getPrev();
|
|
218
218
|
return prev ? prev.getNode(this._chunk.getParentIndex(this._position)) : null;
|
|
219
219
|
}
|
|
220
|
-
/**
|
|
221
|
-
* Gets or creates the parent node
|
|
222
|
-
* @returns The parent node
|
|
220
|
+
/**
|
|
221
|
+
* Gets or creates the parent node
|
|
222
|
+
* @returns The parent node
|
|
223
223
|
*/ getOrCreateParent() {
|
|
224
224
|
console.assert(!!this._chunk, 'Invalid chunk');
|
|
225
225
|
const prev = this._chunk.getPrev();
|
|
226
226
|
return prev ? prev.getOrCreateNode(this._chunk.getParentIndex(this._position)) : null;
|
|
227
227
|
}
|
|
228
|
-
/**
|
|
229
|
-
* Creates all children of this node
|
|
228
|
+
/**
|
|
229
|
+
* Creates all children of this node
|
|
230
230
|
*/ createChildren() {
|
|
231
231
|
this.getOrCreateChild(OctreePlacement.PPP);
|
|
232
232
|
this.getOrCreateChild(OctreePlacement.PPN);
|
|
@@ -237,9 +237,9 @@ var OctreePlacement;
|
|
|
237
237
|
this.getOrCreateChild(OctreePlacement.NNP);
|
|
238
238
|
this.getOrCreateChild(OctreePlacement.NNN);
|
|
239
239
|
}
|
|
240
|
-
/**
|
|
241
|
-
* Free up all empty children
|
|
242
|
-
* @returns true if some children were freed
|
|
240
|
+
/**
|
|
241
|
+
* Free up all empty children
|
|
242
|
+
* @returns true if some children were freed
|
|
243
243
|
*/ tidy() {
|
|
244
244
|
this._references = 8;
|
|
245
245
|
for(let i = 0; i < 8; i++){
|
|
@@ -254,9 +254,9 @@ var OctreePlacement;
|
|
|
254
254
|
}
|
|
255
255
|
return false;
|
|
256
256
|
}
|
|
257
|
-
/**
|
|
258
|
-
* Traverse this node by a visitor
|
|
259
|
-
* @param v - The visitor
|
|
257
|
+
/**
|
|
258
|
+
* Traverse this node by a visitor
|
|
259
|
+
* @param v - The visitor
|
|
260
260
|
*/ traverse(v) {
|
|
261
261
|
if (v.visit(this)) {
|
|
262
262
|
for(let i = 0; i < 8; i++){
|
|
@@ -268,9 +268,9 @@ var OctreePlacement;
|
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
|
-
/**
|
|
272
|
-
* Octree node chunk
|
|
273
|
-
* @public
|
|
271
|
+
/**
|
|
272
|
+
* Octree node chunk
|
|
273
|
+
* @public
|
|
274
274
|
*/ class OctreeNodeChunk {
|
|
275
275
|
/** @internal */ _level;
|
|
276
276
|
/** @internal */ _dimension;
|
|
@@ -279,9 +279,9 @@ var OctreePlacement;
|
|
|
279
279
|
/** @internal */ _next;
|
|
280
280
|
/** @internal */ _octree;
|
|
281
281
|
/** @internal */ _nodeMap;
|
|
282
|
-
/**
|
|
283
|
-
* Creates an instance of octree chunk
|
|
284
|
-
* @param octree - Octree to which the chunk belongs
|
|
282
|
+
/**
|
|
283
|
+
* Creates an instance of octree chunk
|
|
284
|
+
* @param octree - Octree to which the chunk belongs
|
|
285
285
|
*/ constructor(octree){
|
|
286
286
|
this._octree = octree;
|
|
287
287
|
this._level = 0;
|
|
@@ -291,17 +291,17 @@ var OctreePlacement;
|
|
|
291
291
|
this._prev = null;
|
|
292
292
|
this._nodeMap = new Map();
|
|
293
293
|
}
|
|
294
|
-
/**
|
|
295
|
-
* Gets an octree node at a given index
|
|
296
|
-
* @param index - Index of the node
|
|
297
|
-
* @returns The octree node
|
|
294
|
+
/**
|
|
295
|
+
* Gets an octree node at a given index
|
|
296
|
+
* @param index - Index of the node
|
|
297
|
+
* @returns The octree node
|
|
298
298
|
*/ getNode(index) {
|
|
299
299
|
return this._nodeMap.get(index) || null;
|
|
300
300
|
}
|
|
301
|
-
/**
|
|
302
|
-
* Gets or creates an octree node at a given index
|
|
303
|
-
* @param index - Index of the node
|
|
304
|
-
* @returns The octree node
|
|
301
|
+
/**
|
|
302
|
+
* Gets or creates an octree node at a given index
|
|
303
|
+
* @param index - Index of the node
|
|
304
|
+
* @returns The octree node
|
|
305
305
|
*/ getOrCreateNode(index) {
|
|
306
306
|
let node = this.getNode(index);
|
|
307
307
|
if (!node) {
|
|
@@ -312,10 +312,10 @@ var OctreePlacement;
|
|
|
312
312
|
}
|
|
313
313
|
return node;
|
|
314
314
|
}
|
|
315
|
-
/**
|
|
316
|
-
* Gets or creates an octree node chain at a given index
|
|
317
|
-
* @param index - Index of the head node
|
|
318
|
-
* @returns The head node of the chain
|
|
315
|
+
/**
|
|
316
|
+
* Gets or creates an octree node chain at a given index
|
|
317
|
+
* @param index - Index of the head node
|
|
318
|
+
* @returns The head node of the chain
|
|
319
319
|
*/ getOrCreateNodeChain(index) {
|
|
320
320
|
const node = this.getOrCreateNode(index);
|
|
321
321
|
if (this._prev) {
|
|
@@ -323,9 +323,9 @@ var OctreePlacement;
|
|
|
323
323
|
}
|
|
324
324
|
return node;
|
|
325
325
|
}
|
|
326
|
-
/**
|
|
327
|
-
* Removes an octree node at given index
|
|
328
|
-
* @param index - Index of the node
|
|
326
|
+
/**
|
|
327
|
+
* Removes an octree node at given index
|
|
328
|
+
* @param index - Index of the node
|
|
329
329
|
*/ freeNodeByIndex(index) {
|
|
330
330
|
const node = this._nodeMap.get(index);
|
|
331
331
|
if (node) {
|
|
@@ -333,28 +333,28 @@ var OctreePlacement;
|
|
|
333
333
|
this._nodeMap.delete(index);
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
|
-
/**
|
|
337
|
-
* Removes an octree node
|
|
338
|
-
* @param node - The octree node to be removed
|
|
336
|
+
/**
|
|
337
|
+
* Removes an octree node
|
|
338
|
+
* @param node - The octree node to be removed
|
|
339
339
|
*/ freeNode(node) {
|
|
340
340
|
if (node) {
|
|
341
341
|
console.assert(node.getChunk() === this, 'Invalid chunk');
|
|
342
342
|
this.freeNodeByIndex(node.getPosition());
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
|
-
/**
|
|
346
|
-
* Removes all octree nodes of this chunk
|
|
345
|
+
/**
|
|
346
|
+
* Removes all octree nodes of this chunk
|
|
347
347
|
*/ clearNodes() {
|
|
348
348
|
for (const key of this._nodeMap.keys()){
|
|
349
349
|
this._nodeMap.get(key).clearNodes();
|
|
350
350
|
this._nodeMap.delete(key);
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
|
-
/**
|
|
354
|
-
* Gets the index of a child node at given placement
|
|
355
|
-
* @param index - Index of the parent node
|
|
356
|
-
* @param placement - The placement
|
|
357
|
-
* @returns Index of the child
|
|
353
|
+
/**
|
|
354
|
+
* Gets the index of a child node at given placement
|
|
355
|
+
* @param index - Index of the parent node
|
|
356
|
+
* @param placement - The placement
|
|
357
|
+
* @returns Index of the child
|
|
358
358
|
*/ getChildIndex(index, placement) {
|
|
359
359
|
const dim = this._dimension;
|
|
360
360
|
let px = 2 * (index % dim);
|
|
@@ -396,10 +396,10 @@ var OctreePlacement;
|
|
|
396
396
|
const dimension2 = 2 * dim;
|
|
397
397
|
return pz * dimension2 * dimension2 + py * dimension2 + px;
|
|
398
398
|
}
|
|
399
|
-
/**
|
|
400
|
-
* Gets the index of the parent node
|
|
401
|
-
* @param index - Index of the child node
|
|
402
|
-
* @returns Index of the parent node
|
|
399
|
+
/**
|
|
400
|
+
* Gets the index of the parent node
|
|
401
|
+
* @param index - Index of the child node
|
|
402
|
+
* @returns Index of the parent node
|
|
403
403
|
*/ getParentIndex(index) {
|
|
404
404
|
const dim = this._dimension;
|
|
405
405
|
const px = index % dim >> 1;
|
|
@@ -408,88 +408,88 @@ var OctreePlacement;
|
|
|
408
408
|
const d = dim >> 1;
|
|
409
409
|
return px + py * d + pz * d * d;
|
|
410
410
|
}
|
|
411
|
-
/**
|
|
412
|
-
* Gets the size of the node in this chunk
|
|
413
|
-
* @returns The size of the node in this chunk
|
|
411
|
+
/**
|
|
412
|
+
* Gets the size of the node in this chunk
|
|
413
|
+
* @returns The size of the node in this chunk
|
|
414
414
|
*/ getNodeSize() {
|
|
415
415
|
return this._nodeSize;
|
|
416
416
|
}
|
|
417
|
-
/**
|
|
418
|
-
* Gets the root size of the octree
|
|
419
|
-
* @returns The root size of the octree
|
|
417
|
+
/**
|
|
418
|
+
* Gets the root size of the octree
|
|
419
|
+
* @returns The root size of the octree
|
|
420
420
|
*/ getWorldSize() {
|
|
421
421
|
return this._octree.getRootSize();
|
|
422
422
|
}
|
|
423
|
-
/**
|
|
424
|
-
* Gets the dimension of this chunk
|
|
425
|
-
* @returns Dimension of this chunk
|
|
423
|
+
/**
|
|
424
|
+
* Gets the dimension of this chunk
|
|
425
|
+
* @returns Dimension of this chunk
|
|
426
426
|
*/ getDimension() {
|
|
427
427
|
return this._dimension;
|
|
428
428
|
}
|
|
429
|
-
/**
|
|
430
|
-
* Gets the level index of this chunk
|
|
431
|
-
* @returns Level index of this chunk
|
|
429
|
+
/**
|
|
430
|
+
* Gets the level index of this chunk
|
|
431
|
+
* @returns Level index of this chunk
|
|
432
432
|
*/ getLevel() {
|
|
433
433
|
return this._level;
|
|
434
434
|
}
|
|
435
|
-
/**
|
|
436
|
-
* Check if this chunk is empty
|
|
437
|
-
* @returns true if this chunk is empty, otherwise false
|
|
435
|
+
/**
|
|
436
|
+
* Check if this chunk is empty
|
|
437
|
+
* @returns true if this chunk is empty, otherwise false
|
|
438
438
|
*/ empty() {
|
|
439
439
|
return this._nodeMap.size === 0;
|
|
440
440
|
}
|
|
441
|
-
/**
|
|
442
|
-
* Gets the chunk next to this chunk
|
|
443
|
-
* @returns The next chunk
|
|
441
|
+
/**
|
|
442
|
+
* Gets the chunk next to this chunk
|
|
443
|
+
* @returns The next chunk
|
|
444
444
|
*/ getNext() {
|
|
445
445
|
return this._next;
|
|
446
446
|
}
|
|
447
|
-
/**
|
|
448
|
-
* Gets the chunk previous to this chunk
|
|
449
|
-
* @returns The previous chunk
|
|
447
|
+
/**
|
|
448
|
+
* Gets the chunk previous to this chunk
|
|
449
|
+
* @returns The previous chunk
|
|
450
450
|
*/ getPrev() {
|
|
451
451
|
return this._prev;
|
|
452
452
|
}
|
|
453
|
-
/**
|
|
454
|
-
* Gets the octree that the chunk belongs to
|
|
455
|
-
* @returns The octree
|
|
453
|
+
/**
|
|
454
|
+
* Gets the octree that the chunk belongs to
|
|
455
|
+
* @returns The octree
|
|
456
456
|
*/ getOctree() {
|
|
457
457
|
return this._octree;
|
|
458
458
|
}
|
|
459
|
-
/**
|
|
460
|
-
* Sets the level index of this chunk
|
|
461
|
-
* @param level - The level index to set
|
|
459
|
+
/**
|
|
460
|
+
* Sets the level index of this chunk
|
|
461
|
+
* @param level - The level index to set
|
|
462
462
|
*/ setLevel(level) {
|
|
463
463
|
this._level = level;
|
|
464
464
|
}
|
|
465
|
-
/**
|
|
466
|
-
* Sets the dimension of this chunk
|
|
467
|
-
* @param dimension - The dimension to set
|
|
465
|
+
/**
|
|
466
|
+
* Sets the dimension of this chunk
|
|
467
|
+
* @param dimension - The dimension to set
|
|
468
468
|
*/ setDimension(dimension) {
|
|
469
469
|
this._dimension = dimension;
|
|
470
470
|
}
|
|
471
|
-
/**
|
|
472
|
-
* Sets the size of octree node in this chunk
|
|
473
|
-
* @param size - The node size to set
|
|
471
|
+
/**
|
|
472
|
+
* Sets the size of octree node in this chunk
|
|
473
|
+
* @param size - The node size to set
|
|
474
474
|
*/ setNodeSize(size) {
|
|
475
475
|
this._nodeSize = size;
|
|
476
476
|
}
|
|
477
|
-
/**
|
|
478
|
-
* Sets the next chunk
|
|
479
|
-
* @param chunk - The chunk to set
|
|
477
|
+
/**
|
|
478
|
+
* Sets the next chunk
|
|
479
|
+
* @param chunk - The chunk to set
|
|
480
480
|
*/ setNext(chunk) {
|
|
481
481
|
this._next = chunk;
|
|
482
482
|
}
|
|
483
|
-
/**
|
|
484
|
-
* Sets the previous chunk
|
|
485
|
-
* @param chunk - The chunk to set
|
|
483
|
+
/**
|
|
484
|
+
* Sets the previous chunk
|
|
485
|
+
* @param chunk - The chunk to set
|
|
486
486
|
*/ setPrev(chunk) {
|
|
487
487
|
this._prev = chunk;
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
|
-
/**
|
|
491
|
-
* Octree class
|
|
492
|
-
* @public
|
|
490
|
+
/**
|
|
491
|
+
* Octree class
|
|
492
|
+
* @public
|
|
493
493
|
*/ class Octree {
|
|
494
494
|
/** @internal */ _scene;
|
|
495
495
|
/** @internal */ _chunks;
|
|
@@ -497,11 +497,11 @@ var OctreePlacement;
|
|
|
497
497
|
/** @internal */ _leafSize;
|
|
498
498
|
/** @internal */ _rootNode;
|
|
499
499
|
/** @internal */ _nodeMap;
|
|
500
|
-
/**
|
|
501
|
-
* Creates an instance of octree
|
|
502
|
-
* @param scene - The scene to which the octree belongs
|
|
503
|
-
* @param rootSize - Root size of the octre
|
|
504
|
-
* @param leafSize - Leaf size of the octree
|
|
500
|
+
/**
|
|
501
|
+
* Creates an instance of octree
|
|
502
|
+
* @param scene - The scene to which the octree belongs
|
|
503
|
+
* @param rootSize - Root size of the octre
|
|
504
|
+
* @param leafSize - Leaf size of the octree
|
|
505
505
|
*/ constructor(scene, rootSize = 4096, leafSize = 64){
|
|
506
506
|
this._scene = scene;
|
|
507
507
|
this._chunks = [];
|
|
@@ -511,10 +511,10 @@ var OctreePlacement;
|
|
|
511
511
|
this._nodeMap = new WeakMap();
|
|
512
512
|
this.initialize(rootSize, leafSize);
|
|
513
513
|
}
|
|
514
|
-
/**
|
|
515
|
-
* Initialize the octree with specified root size and leaf size
|
|
516
|
-
* @param rootSize - Root size of the octree
|
|
517
|
-
* @param leafSize - Leaf size of the octree
|
|
514
|
+
/**
|
|
515
|
+
* Initialize the octree with specified root size and leaf size
|
|
516
|
+
* @param rootSize - Root size of the octree
|
|
517
|
+
* @param leafSize - Leaf size of the octree
|
|
518
518
|
*/ initialize(rootSize, leafSize) {
|
|
519
519
|
console.assert(rootSize >= leafSize && leafSize > 0, 'Invalid rootSize or leafSize for octree');
|
|
520
520
|
this.finalize();
|
|
@@ -541,30 +541,30 @@ var OctreePlacement;
|
|
|
541
541
|
this._rootNode = null;
|
|
542
542
|
this._nodeMap = new WeakMap();
|
|
543
543
|
}
|
|
544
|
-
/**
|
|
545
|
-
* Gets the scene to which the octree belongs
|
|
546
|
-
* @returns The scene
|
|
544
|
+
/**
|
|
545
|
+
* Gets the scene to which the octree belongs
|
|
546
|
+
* @returns The scene
|
|
547
547
|
*/ getScene() {
|
|
548
548
|
return this._scene;
|
|
549
549
|
}
|
|
550
|
-
/**
|
|
551
|
-
* Gets the root size of the octree
|
|
552
|
-
* @returns The root size of the octree
|
|
550
|
+
/**
|
|
551
|
+
* Gets the root size of the octree
|
|
552
|
+
* @returns The root size of the octree
|
|
553
553
|
*/ getRootSize() {
|
|
554
554
|
return this._rootSize;
|
|
555
555
|
}
|
|
556
|
-
/**
|
|
557
|
-
* Gets the leaf size of the octree
|
|
558
|
-
* @returns The leaf size of the octree
|
|
556
|
+
/**
|
|
557
|
+
* Gets the leaf size of the octree
|
|
558
|
+
* @returns The leaf size of the octree
|
|
559
559
|
*/ getLeafSize() {
|
|
560
560
|
return this._leafSize;
|
|
561
561
|
}
|
|
562
|
-
/**
|
|
563
|
-
* Locates a node chain in the octree by a sphere
|
|
564
|
-
* @param candidate - The candidate node
|
|
565
|
-
* @param center - center of the sphere
|
|
566
|
-
* @param radius - radius of the sphere
|
|
567
|
-
* @returns Head node of the located node chain
|
|
562
|
+
/**
|
|
563
|
+
* Locates a node chain in the octree by a sphere
|
|
564
|
+
* @param candidate - The candidate node
|
|
565
|
+
* @param center - center of the sphere
|
|
566
|
+
* @param radius - radius of the sphere
|
|
567
|
+
* @returns Head node of the located node chain
|
|
568
568
|
*/ locateNodeChain(candidate, center, radius) {
|
|
569
569
|
let level = this._chunks.length - 1;
|
|
570
570
|
while(level && this._chunks[level].getNodeSize() < 4 * radius){
|
|
@@ -587,31 +587,31 @@ var OctreePlacement;
|
|
|
587
587
|
}
|
|
588
588
|
return this._chunks[level].getOrCreateNodeChain(index);
|
|
589
589
|
}
|
|
590
|
-
/**
|
|
591
|
-
* Gets the root node of the octree
|
|
592
|
-
* @returns Root node of the octree
|
|
590
|
+
/**
|
|
591
|
+
* Gets the root node of the octree
|
|
592
|
+
* @returns Root node of the octree
|
|
593
593
|
*/ getRootNode() {
|
|
594
594
|
if (!this._rootNode) {
|
|
595
595
|
this._rootNode = this._chunks[0].getOrCreateNode(0);
|
|
596
596
|
}
|
|
597
597
|
return this._rootNode;
|
|
598
598
|
}
|
|
599
|
-
/**
|
|
600
|
-
* Gets the number of chunks in the octree
|
|
601
|
-
* @returns The number of chunks in the octree
|
|
599
|
+
/**
|
|
600
|
+
* Gets the number of chunks in the octree
|
|
601
|
+
* @returns The number of chunks in the octree
|
|
602
602
|
*/ getNumChunks() {
|
|
603
603
|
return this._chunks.length;
|
|
604
604
|
}
|
|
605
|
-
/**
|
|
606
|
-
* Gets the chunk by a given index
|
|
607
|
-
* @param level - The chunk index
|
|
608
|
-
* @returns The chunk at given index
|
|
605
|
+
/**
|
|
606
|
+
* Gets the chunk by a given index
|
|
607
|
+
* @param level - The chunk index
|
|
608
|
+
* @returns The chunk at given index
|
|
609
609
|
*/ getChunk(level) {
|
|
610
610
|
return this._chunks[level];
|
|
611
611
|
}
|
|
612
|
-
/**
|
|
613
|
-
* Place a scene node into the octree
|
|
614
|
-
* @param node - The scene node to be placed
|
|
612
|
+
/**
|
|
613
|
+
* Place a scene node into the octree
|
|
614
|
+
* @param node - The scene node to be placed
|
|
615
615
|
*/ placeNode(node) {
|
|
616
616
|
const curNode = this._nodeMap.get(node) || null;
|
|
617
617
|
let locatedNode = this.getRootNode();
|
|
@@ -632,9 +632,9 @@ var OctreePlacement;
|
|
|
632
632
|
locatedNode?.invalidateBox();
|
|
633
633
|
}
|
|
634
634
|
}
|
|
635
|
-
/**
|
|
636
|
-
* Removes a scene node from the octree
|
|
637
|
-
* @param node - The scene node to be removed
|
|
635
|
+
/**
|
|
636
|
+
* Removes a scene node from the octree
|
|
637
|
+
* @param node - The scene node to be removed
|
|
638
638
|
*/ removeNode(node) {
|
|
639
639
|
if (node.isGraphNode()) {
|
|
640
640
|
const curNode = this._nodeMap.get(node) || null;
|