@woosh/meep-engine 2.48.18 → 2.48.20

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.
Files changed (30) hide show
  1. package/package.json +1 -1
  2. package/src/core/binary/type/BinaryDataType.d.ts +15 -0
  3. package/src/{engine/graphics/render/forward_plus/data/computeDataType.js → core/binary/type/computeBinaryDataTypeByPrecision.js} +3 -3
  4. package/src/core/geom/2d/quad-tree/qt_query_data_nearest_to_point.js +62 -0
  5. package/src/core/geom/Matrix4.js +4 -1
  6. package/src/core/graph/Edge.js +11 -2
  7. package/src/core/graph/layout/computeDisconnectedSubGraphs.js +1 -0
  8. package/src/core/graph/v2/Graph.js +36 -31
  9. package/src/core/graph/v2/Graph.spec.js +309 -1
  10. package/src/core/process/task/TaskGroup.js +1 -1
  11. package/src/core/process/task/util/task_tree_compute_leaf_tasks.js +21 -0
  12. package/src/engine/graphics/geometry/AttributeSpec.d.ts +2 -2
  13. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +1 -3
  14. package/src/engine/graphics/micron/render/instanced/PatchDataTextures.js +6 -2
  15. package/src/engine/graphics/render/forward_plus/LightManager.js +9 -7
  16. package/src/engine/graphics/{micron/render/instanced → texture}/AttributeDataTexture.js +28 -19
  17. package/src/engine/graphics/{render/forward_plus/data → texture}/TextureBackedMemoryRegion.js +8 -8
  18. package/src/engine/graphics/{render/forward_plus/data → texture}/computeThreeTextureFormat.js +2 -2
  19. package/src/engine/graphics/{render/forward_plus/data → texture}/computeThreeTextureInternalFormatFromDataType.js +1 -1
  20. package/src/engine/graphics/{render/forward_plus/data → texture}/computeThreeTextureTypeFromDataType.js +1 -1
  21. package/src/engine/graphics/texture/sampler/Sampler2D2Canvas.js +1 -1
  22. package/src/engine/graphics/texture/sampler/sampler2DToFloat32Texture.js +1 -3
  23. package/src/generation/GridTaskGroup.js +4 -4
  24. package/src/generation/filtering/numeric/util/populateSampler2DFromCellFilter.js +10 -2
  25. package/src/generation/filtering/numeric/util/sampler_from_filter.js +26 -0
  26. package/src/generation/filtering/numeric/util/visualise_filters_as_grid.js +81 -0
  27. package/src/generation/grid/generation/GridTaskSequence.js +3 -1
  28. /package/src/core/geom/{Matrix3.js → m3_determinant.js} +0 -0
  29. /package/src/{engine/graphics/render/forward_plus/data → core/math}/NumericType.js +0 -0
  30. /package/src/engine/graphics/{render/forward_plus/data → texture}/channelCountToThreIntegerTextureType.js +0 -0
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.48.18",
8
+ "version": "2.48.20",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -0,0 +1,15 @@
1
+ export enum BinaryDataType {
2
+ Uint8= "uint8",
3
+ Uint16= "uint16",
4
+ Uint32= "uint32",
5
+ Uint64= "uint64",
6
+
7
+ Int8= "int8",
8
+ Int16= "int16",
9
+ Int32= "int32",
10
+ Int64= "int64",
11
+
12
+ Float16= 'float16',
13
+ Float32= "float32",
14
+ Float64= "float64"
15
+ }
@@ -1,5 +1,5 @@
1
- import { NumericType } from "./NumericType.js";
2
- import { BinaryDataType } from "../../../../../core/binary/type/BinaryDataType.js";
1
+ import { NumericType } from "../../math/NumericType.js";
2
+ import { BinaryDataType } from "./BinaryDataType.js";
3
3
 
4
4
  /**
5
5
  *
@@ -7,7 +7,7 @@ import { BinaryDataType } from "../../../../../core/binary/type/BinaryDataType.j
7
7
  * @param {number} precision
8
8
  * @returns {BinaryDataType}
9
9
  */
10
- export function computeDataType(type, precision) {
10
+ export function computeBinaryDataTypeByPrecision(type, precision) {
11
11
  if (type === NumericType.Uint) {
12
12
  if (precision <= 8) {
13
13
  return BinaryDataType.Uint8;
@@ -0,0 +1,62 @@
1
+ import { aabb2_sqrDistanceToPoint } from "../AABB2Math.js";
2
+ import { max2 } from "../../../math/max2.js";
3
+
4
+ /**
5
+ *
6
+ * @type {QuadTreeNode[]}
7
+ */
8
+ const node_stack = [];
9
+
10
+ /**
11
+ * @template N
12
+ * @param {QuadTreeNode<N>} tree
13
+ * @param {number} x
14
+ * @param {number} y
15
+ * @param {number} [max_distance]
16
+ * @returns {QuadTreeDatum<N>}
17
+ */
18
+ export function qt_query_data_nearest_to_point(tree, x, y, max_distance = Infinity) {
19
+
20
+ let stack_pointer = 0;
21
+
22
+ node_stack[stack_pointer] = tree;
23
+ stack_pointer++;
24
+
25
+ let best_leaf_data = undefined;
26
+ let best_distance_sqr = max_distance * max_distance;
27
+
28
+ while (stack_pointer > 0) {
29
+
30
+ --stack_pointer;
31
+ const node = node_stack[stack_pointer];
32
+
33
+ const distance_sqr = max2(0, aabb2_sqrDistanceToPoint(node.x0, node.y0, node.x1, node.y1, x, y));
34
+
35
+ if (distance_sqr >= best_distance_sqr) {
36
+ // too far
37
+ continue;
38
+ }
39
+
40
+ const data = node.data;
41
+
42
+ for (let i = 0; i < data.length; i++) {
43
+ const datum = data[i];
44
+
45
+ const distance_sqr = max2(0, aabb2_sqrDistanceToPoint(datum.x0, datum.y0, datum.x1, datum.y1, x, y));
46
+
47
+ if (distance_sqr < best_distance_sqr) {
48
+ best_leaf_data = datum;
49
+ best_distance_sqr = distance_sqr;
50
+ }
51
+ }
52
+
53
+ if (node.isSplit()) {
54
+ node_stack[stack_pointer++] = node.topLeft;
55
+ node_stack[stack_pointer++] = node.topRight;
56
+ node_stack[stack_pointer++] = node.bottomLeft;
57
+ node_stack[stack_pointer++] = node.bottomRight;
58
+ }
59
+ }
60
+
61
+ return best_leaf_data;
62
+ }
@@ -4,6 +4,9 @@ const _z = new Vector3();
4
4
  const _x = new Vector3();
5
5
  const _y = new Vector3();
6
6
 
7
+ /**
8
+ * @deprecated use arrays instead or mat4 from gl-matrix
9
+ */
7
10
  export class Matrix4 {
8
11
  /**
9
12
  *
@@ -197,7 +200,7 @@ export class Matrix4 {
197
200
  const sz = Math.hypot(this.c0, this.c1, this.c2);
198
201
 
199
202
  // if determine is negative, we need to invert one scale
200
- const det = this.determinant();
203
+ const det = this.determinant();
201
204
  if (det < 0) sx = -sx;
202
205
 
203
206
  position.set(
@@ -26,8 +26,8 @@ export class Edge {
26
26
  * @constructor
27
27
  */
28
28
  constructor(a, b) {
29
- assert.notEqual(a, undefined, 'a is undefined');
30
- assert.notEqual(b, undefined, 'b is undefined');
29
+ assert.defined(a, 'a');
30
+ assert.defined(b, 'b');
31
31
 
32
32
  /**
33
33
  *
@@ -46,6 +46,11 @@ export class Edge {
46
46
  this.direction = EdgeDirectionType.Undirected;
47
47
  }
48
48
 
49
+ /**
50
+ *
51
+ * @param {N} node
52
+ * @return {boolean}
53
+ */
49
54
  contains(node) {
50
55
  return this.first === node || this.second === node;
51
56
  }
@@ -86,6 +91,8 @@ export class Edge {
86
91
  * @returns {number}
87
92
  */
88
93
  angle() {
94
+ console.error('method is deprecated, do not use');
95
+
89
96
  const delta = this.second.clone().sub(this.first);
90
97
  return Math.atan2(delta.y, delta.x);
91
98
  }
@@ -104,6 +111,8 @@ export class Edge {
104
111
  * @returns {number}
105
112
  */
106
113
  get length() {
114
+ console.error('method is deprecated, do not use');
115
+
107
116
  return this.first.distanceTo(this.second);
108
117
  }
109
118
  }
@@ -1,4 +1,5 @@
1
1
  /**
2
+ * NOTE: use {@link graph_compute_disconnected_clusters} instead where possible
2
3
  * @param {{connections:Connection[]}[]} nodes
3
4
  * @return {Array}
4
5
  */
@@ -26,29 +26,31 @@ function construct_path(goal_node_container, cameFrom) {
26
26
  export class Graph {
27
27
 
28
28
  /**
29
- * @template N
29
+ *
30
+ * @type {Map<N, NodeContainer<N>>}
31
+ * @private
32
+ */
33
+ __nodes = new Map();
34
+ /**
35
+ *
36
+ * @type {Set<Edge<N>>}
37
+ * @private
30
38
  */
31
- constructor() {
39
+ __edges = new Set();
40
+
41
+ on = {
32
42
  /**
33
- *
34
- * @type {Map<N, NodeContainer<N>>}
35
- * @private
43
+ * @type {Signal<N,this>}
36
44
  */
37
- this.__nodes = new Map();
45
+ nodeAdded: new Signal(),
38
46
  /**
39
- *
40
- * @type {Set<Edge<N>>}
41
- * @private
47
+ * @type {Signal<N,this>}
42
48
  */
43
- this.__edges = new Set();
44
-
45
- this.on = {
46
- nodeAdded: new Signal(),
47
- nodeRemoved: new Signal(),
48
- edgeAdded: new Signal(),
49
- edgeRemoved: new Signal()
50
- };
51
- }
49
+ nodeRemoved: new Signal(),
50
+ edgeAdded: new Signal(),
51
+ edgeRemoved: new Signal()
52
+ };
53
+
52
54
 
53
55
  /**
54
56
  *
@@ -115,6 +117,14 @@ export class Graph {
115
117
  return this.__nodes.size;
116
118
  }
117
119
 
120
+ /**
121
+ *
122
+ * @returns {number}
123
+ */
124
+ getNodeCount() {
125
+ return this.__nodes.size;
126
+ }
127
+
118
128
  /**
119
129
  *
120
130
  * @param {function(N):boolean} filter
@@ -169,14 +179,6 @@ export class Graph {
169
179
  return this.__nodes.keys();
170
180
  }
171
181
 
172
- /**
173
- *
174
- * @returns {number}
175
- */
176
- getNodeCount() {
177
- return this.__nodes.size;
178
- }
179
-
180
182
  /**
181
183
  * Do not modify this set directly
182
184
  * @return {Set<Edge<N>>}
@@ -217,8 +219,10 @@ export class Graph {
217
219
  const context_0 = this.__nodes.get(edge.first);
218
220
  const context_1 = this.__nodes.get(edge.second);
219
221
 
220
- if (context_0 === undefined || context_1 === undefined) {
221
- throw new Error('One or more of the edge nodes are not part of the graph');
222
+ if (context_0 === undefined) {
223
+ throw new Error(`First node(=${edge.first}) of the edge is not part of the graph`);
224
+ } else if (context_1 === undefined) {
225
+ throw new Error(`Second node(=${edge.second}) of the edge is not part of the graph`);
222
226
  }
223
227
 
224
228
  context_0.addEdge(edge);
@@ -246,6 +250,7 @@ export class Graph {
246
250
  const context_1 = this.__nodes.get(edge.second);
247
251
 
248
252
  if (context_0 === undefined || context_1 === undefined) {
253
+ // this is a critical error, it should never happen as long as the API is used correctly
249
254
  throw new Error('One or both nodes of the edge are not present on the graph. This is a critical error');
250
255
  }
251
256
 
@@ -316,7 +321,7 @@ export class Graph {
316
321
  const context_a = this.__nodes.get(a);
317
322
 
318
323
  if (context_a === undefined) {
319
- // a is not in the graph
324
+ // A is not in the graph
320
325
  return undefined;
321
326
  }
322
327
 
@@ -334,10 +339,10 @@ export class Graph {
334
339
  * @param {N} to
335
340
  * @returns {Edge<N>|undefined}
336
341
  */
337
- getAnyDirectedEdge(from, to){
342
+ getAnyDirectedEdge(from, to) {
338
343
  const ctx_a = this.__nodes.get(from);
339
344
 
340
- if(ctx_a === undefined){
345
+ if (ctx_a === undefined) {
341
346
  return undefined;
342
347
  }
343
348
 
@@ -1,10 +1,89 @@
1
- import { Edge } from "../Edge.js";
1
+ import { Edge, EdgeDirectionType } from "../Edge.js";
2
2
  import { Graph } from "./Graph.js";
3
+ import { jest } from "@jest/globals";
3
4
 
4
5
  test("constructor doesn't throw", () => {
5
6
  expect(() => new Graph()).not.toThrow();
6
7
  });
7
8
 
9
+ test("adding same node twice", () => {
10
+
11
+ const graph = new Graph();
12
+
13
+ expect(graph.addNode(1)).toBe(true);
14
+ expect(graph.addNode(1)).toBe(false); // node already added
15
+
16
+ });
17
+
18
+ test("adding node triggers nodeAdded signal", () => {
19
+
20
+ const graph = new Graph();
21
+
22
+ const callback = jest.fn();
23
+
24
+ graph.on.nodeAdded.add(callback);
25
+
26
+ graph.addNode(7);
27
+
28
+ expect(callback).toHaveBeenCalledTimes(1);
29
+ expect(callback).toHaveBeenCalledWith(7, graph);
30
+
31
+ });
32
+
33
+ test("removing node triggers nodeRemoved signal", () => {
34
+
35
+ const graph = new Graph();
36
+
37
+ const callback = jest.fn();
38
+
39
+ graph.on.nodeRemoved.add(callback);
40
+
41
+ graph.addNode(7);
42
+
43
+ expect(callback).not.toHaveBeenCalled();
44
+
45
+ graph.removeNode(1); // trying to remove non-existent node
46
+
47
+ expect(callback).not.toHaveBeenCalled();
48
+
49
+ graph.removeNode(7);
50
+
51
+ expect(callback).toHaveBeenCalledTimes(1);
52
+ expect(callback).toHaveBeenCalledWith(7, graph);
53
+
54
+ graph.removeNode(7); //node was already removed, so we expect nothing to happen
55
+
56
+ expect(callback).toHaveBeenCalledTimes(1);
57
+ });
58
+
59
+ test("check node existence", () => {
60
+
61
+ const graph = new Graph();
62
+
63
+ expect(graph.hasNode(1)).toBe(false);
64
+
65
+ graph.addNode(1);
66
+
67
+ expect(graph.hasNode(1)).toBe(true);
68
+
69
+ });
70
+
71
+ test("removing node that does not exist", () => {
72
+ const graph = new Graph();
73
+
74
+ expect(graph.removeNode(1)).toBe(false);
75
+
76
+ });
77
+
78
+ test("removing same node twice", () => {
79
+ const graph = new Graph();
80
+
81
+ graph.addNode(1);
82
+
83
+ expect(graph.removeNode(1)).toBe(true);
84
+ expect(graph.removeNode(1)).toBe(false);
85
+ });
86
+
8
87
  test("nodeCount", () => {
9
88
  const g = new Graph();
10
89
 
@@ -19,6 +98,122 @@ test("nodeCount", () => {
19
98
  expect(g.nodeCount).toBe(0);
20
99
  });
21
100
 
101
+ test("findNode on empty graph", () => {
102
+ const graph = new Graph();
103
+
104
+ expect(graph.findNode(n => n === 1)).toBe(undefined);
105
+ });
106
+
107
+ test("findNode that doesn't exist on graph with 1 node", () => {
108
+ const graph = new Graph();
109
+
110
+ graph.addNode(3);
111
+
112
+ expect(graph.findNode(n => n === 1)).toBe(undefined);
113
+ });
114
+
115
+ test("findNode amongst two", () => {
116
+ const graph = new Graph();
117
+
118
+ graph.addNode(1);
119
+ graph.addNode(3);
120
+
121
+ expect(graph.findNode(n => n === 3)).toBe(3);
122
+ });
123
+
124
+ test("getNodeDegree", () => {
125
+
126
+ const graph = new Graph();
127
+
128
+ expect(graph.getNodeDegree(1)).toBe(0);
129
+
130
+ graph.addNode(1);
131
+
132
+ expect(graph.getNodeDegree(1)).toBe(0);
133
+
134
+ graph.addNode(3);
135
+
136
+ expect(graph.getNodeDegree(1)).toBe(0);
137
+ expect(graph.getNodeDegree(3)).toBe(0);
138
+
139
+ graph.createEdge(1, 3, EdgeDirectionType.Forward);
140
+
141
+ expect(graph.getNodeDegree(1)).toBe(1);
142
+ expect(graph.getNodeDegree(3)).toBe(1);
143
+ });
144
+
145
+ test("createEdge", () => {
146
+ const graph = new Graph();
147
+
148
+ graph.addNode(1);
149
+ graph.addNode(2);
150
+
151
+ graph.createEdge(1, 2, EdgeDirectionType.Forward);
152
+
153
+ expect(graph.edgeCount).toBe(1);
154
+
155
+ expect(graph.edgeExistsBetween(1, 2)).toBe(true);
156
+ });
157
+
158
+ test("adding edge where one of the nodes is not part of the graph should throw and exception", () => {
159
+ const graph = new Graph();
160
+
161
+ expect(() => graph.addEdge(new Edge(1, 2))).toThrow();
162
+
163
+ graph.addNode(1);
164
+
165
+ expect(() => graph.addEdge(new Edge(1, 2))).toThrow();
166
+
167
+ graph.removeNode(1);
168
+ graph.addNode(2);
169
+
170
+ expect(() => graph.addEdge(new Edge(1, 2))).toThrow();
171
+ });
172
+
173
+ test("add one valid edge", () => {
174
+
175
+ const graph = new Graph();
176
+
177
+ graph.addNode(1);
178
+ graph.addNode(2);
179
+
180
+ const edge = new Edge(1, 2);
181
+ expect(graph.addEdge(edge)).toBe(true);
182
+
183
+ expect(graph.hasEdge(edge)).toBe(true);
184
+
185
+ expect(graph.edgeCount).toBe(1);
186
+ });
187
+
188
+ test("add same edge twice", () => {
189
+
190
+ const graph = new Graph();
191
+
192
+ graph.addNode(1);
193
+ graph.addNode(2);
194
+
195
+ const edge = new Edge(1, 2);
196
+
197
+ expect(graph.addEdge(edge)).toBe(true);
198
+ expect(graph.addEdge(edge)).toBe(false); //already exists
199
+
200
+ expect(graph.hasEdge(edge)).toBe(true);
201
+
202
+ expect(graph.edgeCount).toBe(1);
203
+ });
204
+
205
+ test("remove non-existing edge", () => {
206
+
207
+ const graph = new Graph();
208
+
209
+ graph.addNode(1);
210
+ graph.addNode(2);
211
+
212
+ const edge = new Edge(1, 2);
213
+
214
+ expect(graph.removeEdge(edge)).toBe(false);
215
+ });
216
+
22
217
  test("edgeCount", () => {
23
218
  const g = new Graph();
24
219
 
@@ -54,3 +249,116 @@ test("after removing an edge, neighborhood is properly updated", () => {
54
249
  expect(g.getAttachedEdges(t, 1)).toBe(0);
55
250
  expect(g.getAttachedEdges(t, 2)).toBe(0);
56
251
  });
252
+
253
+ test("edgeExistsBetween", () => {
254
+ const graph = new Graph();
255
+
256
+ expect(graph.edgeExistsBetween(1, 2)).toBe(false);
257
+ expect(graph.edgeExistsBetween(2, 1)).toBe(false);
258
+
259
+ graph.addNode(1);
260
+
261
+ expect(graph.edgeExistsBetween(1, 2)).toBe(false);
262
+ expect(graph.edgeExistsBetween(2, 1)).toBe(false);
263
+
264
+ graph.addNode(2);
265
+
266
+ expect(graph.edgeExistsBetween(1, 2)).toBe(false);
267
+ expect(graph.edgeExistsBetween(2, 1)).toBe(false);
268
+
269
+ graph.createEdge(1, 2, EdgeDirectionType.Forward);
270
+
271
+ expect(graph.edgeExistsBetween(1, 2)).toBe(true);
272
+ expect(graph.edgeExistsBetween(2, 1)).toBe(true);
273
+
274
+ });
275
+
276
+ test("nodeHasEdges", () => {
277
+ const graph = new Graph();
278
+
279
+ expect(graph.nodeHasEdges(1)).toBe(false);
280
+
281
+ graph.addNode(1);
282
+
283
+ expect(graph.nodeHasEdges(1)).toBe(false);
284
+
285
+ graph.addNode(2);
286
+
287
+ expect(graph.nodeHasEdges(1)).toBe(false);
288
+
289
+ graph.createEdge(1, 2, EdgeDirectionType.Forward);
290
+
291
+ expect(graph.nodeHasEdges(1)).toBe(true);
292
+ expect(graph.nodeHasEdges(2)).toBe(true);
293
+ });
294
+
295
+ test("getAnyEdgeBetween", () => {
296
+
297
+ const graph = new Graph();
298
+
299
+ expect(graph.getAnyEdgeBetween(1, 2)).toBe(undefined);
300
+ expect(graph.getAnyEdgeBetween(2, 1)).toBe(undefined);
301
+
302
+ graph.addNode(1);
303
+
304
+ expect(graph.getAnyEdgeBetween(1, 2)).toBe(undefined);
305
+ expect(graph.getAnyEdgeBetween(2, 1)).toBe(undefined);
306
+
307
+ graph.addNode(2);
308
+
309
+ expect(graph.getAnyEdgeBetween(1, 2)).toBe(undefined);
310
+ expect(graph.getAnyEdgeBetween(2, 1)).toBe(undefined);
311
+
312
+ const edge = graph.createEdge(1, 2, EdgeDirectionType.Forward);
313
+
314
+ expect(graph.getAnyEdgeBetween(1, 2)).toBe(edge);
315
+ expect(graph.getAnyEdgeBetween(2, 1)).toBe(edge);
316
+ });
317
+
318
+ test("find path from node to itself", () => {
319
+ const graph = new Graph();
320
+
321
+ graph.addNode(1);
322
+
323
+ const path = graph.findPath(1, 1);
324
+
325
+ expect(path).toEqual([1]);
326
+ });
327
+
328
+ test("find path with 2 hops", () => {
329
+ const graph = new Graph();
330
+
331
+ graph.addNode(1);
332
+ graph.addNode(2);
333
+ graph.addNode(3);
334
+
335
+ graph.createEdge(1, 2, EdgeDirectionType.Forward);
336
+ graph.createEdge(2, 3, EdgeDirectionType.Forward);
337
+
338
+ const path = graph.findPath(1, 3);
339
+
340
+ expect(path).toEqual([1, 2, 3]);
341
+ });
342
+
343
+ test("clear method removes all nodes", () => {
344
+ const graph = new Graph();
345
+
346
+ graph.addNode(1);
347
+
348
+ graph.clear();
349
+
350
+ expect(graph.nodeCount).toBe(0);
351
+ });
352
+
353
+ test("clear method removes all edges", () => {
354
+ const graph = new Graph();
355
+
356
+ graph.addNode(1);
357
+ graph.addNode(2);
358
+
359
+ graph.createEdge(1, 2, EdgeDirectionType.Forward);
360
+
361
+ graph.clear();
362
+
363
+ expect(graph.edgeCount).toBe(0);
364
+ });
@@ -11,7 +11,7 @@ import TaskState from "./TaskState.js";
11
11
 
12
12
  /**
13
13
  *
14
- * @param {Task[]} subtasks
14
+ * @param {(Task|TaskGroup)[]} subtasks
15
15
  * @param {string} [name]
16
16
  * @constructor
17
17
  */
@@ -0,0 +1,21 @@
1
+ /**
2
+ *
3
+ * @param {TaskGroup|Task} root
4
+ * @return {number}
5
+ */
6
+ export function task_tree_compute_leaf_tasks(root) {
7
+ let result = 0;
8
+
9
+ if (root.isTaskGroup) {
10
+
11
+ const children = root.children;
12
+ const n = children.length;
13
+ for (let i = 0; i < n; i++) {
14
+ result += task_tree_compute_leaf_tasks(children[i]);
15
+ }
16
+ } else {
17
+ result += 1;
18
+ }
19
+
20
+ return result;
21
+ }
@@ -1,8 +1,8 @@
1
- import {DataType} from "../../../core/parser/simple/DataType";
1
+ import {BinaryDataType} from "../../../core/binary/type/BinaryDataType";
2
2
 
3
3
  export class AttributeSpec {
4
4
  readonly name: string
5
- readonly type: DataType
5
+ readonly type: BinaryDataType
6
6
  readonly itemSize: number
7
7
  readonly normalized: boolean
8
8
  }
@@ -21,9 +21,7 @@ import { convertTexture2Sampler2D } from "../../texture/sampler/convertTexture2S
21
21
  import { BUFFER_GEOMETRY_UVS } from "./BUFFER_GEOMETRY_UVS.js";
22
22
  import { is_compliant_mesh } from "./is_compliant_mesh.js";
23
23
  import { MaterialDescriptor } from "./MaterialDescriptor.js";
24
- import {
25
- computeThreeTextureTypeFromDataType
26
- } from "../../render/forward_plus/data/computeThreeTextureTypeFromDataType.js";
24
+ import { computeThreeTextureTypeFromDataType } from "../../texture/computeThreeTextureTypeFromDataType.js";
27
25
  import { typedArrayToDataType } from "../../../../core/collection/array/typedArrayToDataType.js";
28
26
  import { BinaryDataType } from "../../../../core/binary/type/BinaryDataType.js";
29
27
  import {
@@ -1,9 +1,10 @@
1
1
  import { assert } from "../../../../../core/assert.js";
2
2
  import { BitSet } from "../../../../../core/binary/BitSet.js";
3
- import { AttributeDataTexture } from "./AttributeDataTexture.js";
3
+ import { AttributeDataTexture } from "../../../texture/AttributeDataTexture.js";
4
4
  import { max3 } from "../../../../../core/math/max3.js";
5
5
  import { gen_micron_vertex_attribute_texture_name } from "./shader/gen_micron_vertex_attribute_texture_name.js";
6
6
  import { min2 } from "../../../../../core/math/min2.js";
7
+ import { MICRON_PATCH_SIZE_MAX } from "../../build/MICRON_PATCH_SIZE_MAX.js";
7
8
 
8
9
  /**
9
10
  *
@@ -23,6 +24,9 @@ const ALLOCATION_GROW_FACTOR = 1.2;
23
24
  */
24
25
  const MAX_TEXTURE_SIZE = 16384;
25
26
 
27
+ const VERTICES_PER_TRIANGLE = 3;
28
+ const ATTRIBUTE_TEXTURE_SLOT_WIDTH =MICRON_PATCH_SIZE_MAX * VERTICES_PER_TRIANGLE;
29
+
26
30
  export class PatchDataTextures {
27
31
  /**
28
32
  *
@@ -70,7 +74,7 @@ export class PatchDataTextures {
70
74
  const attribute_count = spec.attributes.length;
71
75
 
72
76
  for (let i = 0; i < attribute_count; i++) {
73
- attributes[i] = new AttributeDataTexture(spec.attributes[i], this.__column_count);
77
+ attributes[i] = new AttributeDataTexture(spec.attributes[i], this.__column_count, ATTRIBUTE_TEXTURE_SLOT_WIDTH);
74
78
  }
75
79
 
76
80
  }
@@ -18,15 +18,17 @@ import { computeFrustumCorners } from "./computeFrustumCorners.js";
18
18
  import { read_plane_pair } from "./cluster/read_plane_pair.js";
19
19
  import { read_frustum_planes_to_array } from "../../../../core/geom/3d/frustum/read_frustum_planes_to_array.js";
20
20
  import { compute_cluster_planes_from_points } from "./cluster/compute_cluster_planes_from_points.js";
21
- import { TextureBackedMemoryRegion } from "./data/TextureBackedMemoryRegion.js";
21
+ import { TextureBackedMemoryRegion } from "../../texture/TextureBackedMemoryRegion.js";
22
22
  import { assert } from "../../../../core/assert.js";
23
23
  import {
24
24
  DataType2TypedArrayConstructorMapping
25
25
  } from "../../../../core/binary/type/DataType2TypedArrayConstructorMapping.js";
26
- import { NumericType } from "./data/NumericType.js";
27
- import { computeDataType } from "./data/computeDataType.js";
28
- import { computeThreeTextureTypeFromDataType } from "./data/computeThreeTextureTypeFromDataType.js";
29
- import { computeThreeTextureInternalFormatFromDataType } from "./data/computeThreeTextureInternalFormatFromDataType.js";
26
+ import { NumericType } from "../../../../core/math/NumericType.js";
27
+ import { computeBinaryDataTypeByPrecision } from "../../../../core/binary/type/computeBinaryDataTypeByPrecision.js";
28
+ import { computeThreeTextureTypeFromDataType } from "../../texture/computeThreeTextureTypeFromDataType.js";
29
+ import {
30
+ computeThreeTextureInternalFormatFromDataType
31
+ } from "../../texture/computeThreeTextureInternalFormatFromDataType.js";
30
32
  import { BinaryUint32BVH } from "../../../../core/bvh2/binary/2/BinaryUint32BVH.js";
31
33
  import { mat4 } from "gl-matrix";
32
34
  import { TextureAtlas } from "../../texture/atlas/TextureAtlas.js";
@@ -394,7 +396,7 @@ export class LightManager {
394
396
  const rounded_value = Math.ceil(bit_count);
395
397
 
396
398
  this.__cluster_texture_precision = rounded_value;
397
- const dataType = computeDataType(NumericType.Uint, rounded_value);
399
+ const dataType = computeBinaryDataTypeByPrecision(NumericType.Uint, rounded_value);
398
400
 
399
401
  const threeTextureType = computeThreeTextureTypeFromDataType(dataType);
400
402
 
@@ -415,7 +417,7 @@ export class LightManager {
415
417
  }
416
418
 
417
419
  __build_cluster_texture() {
418
- const dataType = computeDataType(NumericType.Uint, this.__cluster_texture_precision);
420
+ const dataType = computeBinaryDataTypeByPrecision(NumericType.Uint, this.__cluster_texture_precision);
419
421
 
420
422
  const threeTextureType = computeThreeTextureTypeFromDataType(dataType);
421
423
 
@@ -1,29 +1,31 @@
1
- import { assert } from "../../../../../core/assert.js";
2
- import { MICRON_PATCH_SIZE_MAX } from "../../build/MICRON_PATCH_SIZE_MAX.js";
3
- import { typed_array_copy } from "../../../../../core/collection/array/typed/typed_array_copy.js";
4
- import { channelCountToThreeTextureFormat } from "../../../texture/channelCountToThreeTextureFormat.js";
1
+ import { assert } from "../../../core/assert.js";
2
+ import { typed_array_copy } from "../../../core/collection/array/typed/typed_array_copy.js";
3
+ import { channelCountToThreeTextureFormat } from "./channelCountToThreeTextureFormat.js";
5
4
  import { DataTexture, NearestFilter } from "three";
6
- import { compute_micron_buffer_array_constructor } from "../../build/compute_micron_buffer_array_constructor.js";
5
+ import { computeThreeTextureTypeFromDataType } from "./computeThreeTextureTypeFromDataType.js";
6
+ import { computeThreeTextureInternalFormatFromDataType } from "./computeThreeTextureInternalFormatFromDataType.js";
7
+ import { DataTypeByteSizes } from "../../../core/binary/type/DataTypeByteSizes.js";
8
+ import { normalized_internal_format } from "./normalized_internal_format.js";
7
9
  import {
8
- computeThreeTextureTypeFromDataType
9
- } from "../../../render/forward_plus/data/computeThreeTextureTypeFromDataType.js";
10
- import {
11
- computeThreeTextureInternalFormatFromDataType
12
- } from "../../../render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js";
13
- import { DataTypeByteSizes } from "../../../../../core/binary/type/DataTypeByteSizes.js";
14
- import { normalized_internal_format } from "../../../texture/normalized_internal_format.js";
10
+ compute_typed_array_constructor_from_data_type
11
+ } from "../../../core/binary/type/DataType2TypedArrayConstructorMapping.js";
15
12
 
16
13
  export class AttributeDataTexture {
17
14
  /**
18
15
  *
19
16
  * @param {AttributeSpec} spec
20
17
  * @param {number} column_count
18
+ * @param {number} slot_width number of data points stored per slot
21
19
  */
22
- constructor(spec, column_count) {
20
+ constructor(spec, column_count, slot_width) {
23
21
  assert.defined(spec, 'spec');
24
22
  assert.equal(spec.isAttributeSpec, true, 'spec.isAttributeSpec !== true');
25
23
 
26
24
  assert.isNonNegativeInteger(column_count, 'column_count');
25
+ assert.greaterThan(column_count, 0, 'column_count > 0');
26
+
27
+ assert.isNonNegativeInteger(slot_width, 'slot_width');
28
+ assert.greaterThan(slot_width, 0, 'slot_width > 0');
27
29
 
28
30
  /**
29
31
  *
@@ -48,6 +50,13 @@ export class AttributeDataTexture {
48
50
  */
49
51
  this.__texture = null;
50
52
 
53
+ /**
54
+ * Number of data points stored per slot
55
+ * @type {number}
56
+ * @private
57
+ */
58
+ this.__slot_width = slot_width;
59
+
51
60
  this.build();
52
61
  }
53
62
 
@@ -76,8 +85,7 @@ export class AttributeDataTexture {
76
85
  }
77
86
 
78
87
  computeSlotWidth() {
79
- const VERTICES_PER_TRIANGLE = 3;
80
- return MICRON_PATCH_SIZE_MAX * VERTICES_PER_TRIANGLE;
88
+ return this.__slot_width;
81
89
  }
82
90
 
83
91
  /**
@@ -109,7 +117,7 @@ export class AttributeDataTexture {
109
117
 
110
118
  const old_data = image.data;
111
119
 
112
- const TypedArray = compute_micron_buffer_array_constructor(spec.type);
120
+ const TypedArray = compute_typed_array_constructor_from_data_type(spec.type);
113
121
  const new_data = new TypedArray(width * height * spec.itemSize);
114
122
 
115
123
  // retain data
@@ -127,7 +135,7 @@ export class AttributeDataTexture {
127
135
  build() {
128
136
  const spec = this.__spec;
129
137
 
130
- const TypedArray = compute_micron_buffer_array_constructor(spec.type);
138
+ const TypedArray = compute_typed_array_constructor_from_data_type(spec.type);
131
139
 
132
140
  const width = this.computeSlotWidth() * this.__column_count;
133
141
  const height = Math.ceil(this.__capacity / this.__column_count);
@@ -287,8 +295,9 @@ export class AttributeDataTexture {
287
295
  * @return {AttributeDataTexture}
288
296
  * @param {AttributeSpec} spec
289
297
  * @param {number} column_count
298
+ * @param {number} slot_width
290
299
  */
291
- static from(spec, column_count) {
292
- return new AttributeDataTexture(spec, column_count);
300
+ static from(spec, column_count, slot_width) {
301
+ return new AttributeDataTexture(spec, column_count, slot_width);
293
302
  }
294
303
  }
@@ -1,16 +1,16 @@
1
1
  import { ClampToEdgeWrapping, DataTexture, NearestFilter, RedFormat, UnsignedByteType } from "three";
2
- import { BinaryDataType } from "../../../../../core/binary/type/BinaryDataType.js";
3
- import { assert } from "../../../../../core/assert.js";
2
+ import { BinaryDataType } from "../../../core/binary/type/BinaryDataType.js";
3
+ import { assert } from "../../../core/assert.js";
4
4
  import {
5
5
  DataType2TypedArrayConstructorMapping
6
- } from "../../../../../core/binary/type/DataType2TypedArrayConstructorMapping.js";
7
- import { max2 } from "../../../../../core/math/max2.js";
8
- import { NumericType } from "./NumericType.js";
9
- import { computeDataType } from "./computeDataType.js";
6
+ } from "../../../core/binary/type/DataType2TypedArrayConstructorMapping.js";
7
+ import { max2 } from "../../../core/math/max2.js";
8
+ import { NumericType } from "../../../core/math/NumericType.js";
9
+ import { computeBinaryDataTypeByPrecision } from "../../../core/binary/type/computeBinaryDataTypeByPrecision.js";
10
10
  import { computeThreeTextureTypeFromDataType } from "./computeThreeTextureTypeFromDataType.js";
11
11
  import { computeThreeTextureInternalFormatFromDataType } from "./computeThreeTextureInternalFormatFromDataType.js";
12
12
  import { computeThreeTextureFormat } from "./computeThreeTextureFormat.js";
13
- import { DataTypeByteSizes } from "../../../../../core/binary/type/DataTypeByteSizes.js";
13
+ import { DataTypeByteSizes } from "../../../core/binary/type/DataTypeByteSizes.js";
14
14
 
15
15
  /**
16
16
  * How wide a data texture is
@@ -168,7 +168,7 @@ export class TextureBackedMemoryRegion {
168
168
  * @private
169
169
  */
170
170
  __update_data_type() {
171
- const new_data_type = computeDataType(this.__type, this.__precision);
171
+ const new_data_type = computeBinaryDataTypeByPrecision(this.__type, this.__precision);
172
172
 
173
173
  if (new_data_type !== this.__data_type) {
174
174
  this.__data_type = new_data_type;
@@ -1,6 +1,6 @@
1
- import { NumericType } from "./NumericType.js";
1
+ import { NumericType } from "../../../core/math/NumericType.js";
2
2
  import { channelCountToThreIntegerTextureType } from "./channelCountToThreIntegerTextureType.js";
3
- import { channelCountToThreeTextureFormat } from "../../../texture/channelCountToThreeTextureFormat.js";
3
+ import { channelCountToThreeTextureFormat } from "./channelCountToThreeTextureFormat.js";
4
4
 
5
5
  /**
6
6
  *
@@ -1,4 +1,4 @@
1
- import { BinaryDataType } from "../../../../../core/binary/type/BinaryDataType.js";
1
+ import { BinaryDataType } from "../../../core/binary/type/BinaryDataType.js";
2
2
 
3
3
  /**
4
4
  *
@@ -1,4 +1,4 @@
1
- import { BinaryDataType } from "../../../../../core/binary/type/BinaryDataType.js";
1
+ import { BinaryDataType } from "../../../core/binary/type/BinaryDataType.js";
2
2
  import {
3
3
  ByteType,
4
4
  FloatType,
@@ -23,7 +23,7 @@ function convertSampler2D2Canvas(sampler, scale = 255, offset = 0, canvas, fillD
23
23
  canvas = document.createElement("canvas");
24
24
  }
25
25
 
26
- const converted_sampler = Sampler2D.uint8(4, sampler.width, sampler.height);
26
+ const converted_sampler = Sampler2D.uint8clamped(4, sampler.width, sampler.height);
27
27
 
28
28
  const width = sampler.width;
29
29
  const height = sampler.height;
@@ -1,9 +1,7 @@
1
1
  import { ClampToEdgeWrapping, DataTexture, FloatType, LinearFilter, NearestFilter } from "three";
2
2
  import { assert } from "../../../../core/assert.js";
3
3
  import { channelCountToThreeTextureFormat } from "../channelCountToThreeTextureFormat.js";
4
- import {
5
- computeThreeTextureInternalFormatFromDataType
6
- } from "../../render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js";
4
+ import { computeThreeTextureInternalFormatFromDataType } from "../computeThreeTextureInternalFormatFromDataType.js";
7
5
  import { BinaryDataType } from "../../../../core/binary/type/BinaryDataType.js";
8
6
 
9
7
  /**
@@ -46,7 +46,7 @@ export class GridTaskGroup extends GridTaskGenerator {
46
46
 
47
47
  /**
48
48
  *
49
- * @type {TaskGroup[]}
49
+ * @type {(TaskGroup|Task)[]}
50
50
  */
51
51
  const tasks = [];
52
52
 
@@ -85,13 +85,13 @@ export class GridTaskGroup extends GridTaskGenerator {
85
85
  const dependencyTask = tasks[dependencyIndex];
86
86
 
87
87
  task.addDependency(dependencyTask);
88
- }
89
88
 
90
- if (!ENV_PRODUCTION) {
91
- catchGeneratorErrors(generator, task);
92
89
  }
90
+
91
+ catchGeneratorErrors(generator, task);
93
92
  }
94
93
 
94
+
95
95
  return new TaskGroup(tasks, 'Grid Generator');
96
96
  }
97
97
  }
@@ -1,3 +1,5 @@
1
+ import { assert } from "../../../../core/assert.js";
2
+
1
3
  /**
2
4
  * Utility function, mainly useful for visualizing filter values
3
5
  * @param {Sampler2D} result
@@ -5,14 +7,20 @@
5
7
  * @param {GridData} grid
6
8
  */
7
9
  export function populateSampler2DFromCellFilter({ result, filter, grid }) {
10
+ assert.defined(result,'result');
11
+ assert.defined(filter,'filter');
12
+ assert.defined(grid,'grid');
8
13
 
9
14
  if (!filter.initialized) {
10
15
  filter.initialize(grid, 0);
11
16
  }
12
17
 
13
- for (let y = 0; y < result.height; y++) {
18
+ const result_height = result.height;
19
+ const v_scale_result = 1 / (result_height - 1);
20
+
21
+ for (let y = 0; y < result_height; y++) {
14
22
 
15
- const v = y / (result.height - 1);
23
+ const v = y * v_scale_result;
16
24
 
17
25
  const grid_y = v * (grid.height - 1);
18
26
 
@@ -0,0 +1,26 @@
1
+ import { assert } from "../../../../core/assert.js";
2
+ import { Sampler2D } from "../../../../engine/graphics/texture/sampler/Sampler2D.js";
3
+ import { populateSampler2DFromCellFilter } from "./populateSampler2DFromCellFilter.js";
4
+
5
+ /**
6
+ *
7
+ * @param {GridData} grid
8
+ * @param {CellFilter} filter
9
+ * @param {number} resolution_scale must be a positive integer
10
+ */
11
+ export function sampler_from_filter(grid, filter, resolution_scale = 1) {
12
+ assert.isNonNegativeInteger(resolution_scale, 'scale');
13
+ assert.defined(grid, 'grid');
14
+ assert.defined(filter, 'filter');
15
+
16
+
17
+ const result = Sampler2D.uint8(1, grid.width * resolution_scale, grid.height * resolution_scale);
18
+
19
+ populateSampler2DFromCellFilter({
20
+ result: result,
21
+ filter: filter,
22
+ grid
23
+ })
24
+
25
+ return result;
26
+ }
@@ -0,0 +1,81 @@
1
+ import { assert } from "../../../../core/assert.js";
2
+ import EmptyView from "../../../../view/elements/EmptyView.js";
3
+ import { CanvasView } from "../../../../view/elements/CanvasView.js";
4
+ import { sampler_from_filter } from "./sampler_from_filter.js";
5
+ import sampler2D2Canvas from "../../../../engine/graphics/texture/sampler/Sampler2D2Canvas.js";
6
+ import LabelView from "../../../../view/common/LabelView.js";
7
+
8
+ /**
9
+ *
10
+ * @param {GridData} grid
11
+ * @param {{name:string, filter:CellFilter}[]} projections
12
+ * @param {number} [resolution_scale]
13
+ * @param {number} [grid_width]
14
+ * @returns {View}
15
+ */
16
+ export function visualise_filters_as_grid({
17
+ grid,
18
+ projections,
19
+ resolution_scale = 4,
20
+ grid_width = 4
21
+ }) {
22
+
23
+ assert.defined(grid, 'grid');
24
+ assert.defined(projections, 'projections');
25
+ assert.isArray(projections, 'projections');
26
+
27
+ const tile_size = [
28
+ grid.width * resolution_scale,
29
+ grid.height * resolution_scale
30
+ ];
31
+
32
+ const vContainer = new EmptyView();
33
+
34
+ for (let i = 0; i < projections.length; i++) {
35
+
36
+ const x = i % grid_width;
37
+ const y = Math.floor(i / grid_width);
38
+
39
+ const { filter, name = "unnamed" } = projections[i];
40
+
41
+ const tile = new EmptyView();
42
+
43
+ const vCanvas = new CanvasView();
44
+
45
+ const sampler = sampler_from_filter(grid, filter, resolution_scale);
46
+
47
+ vCanvas.size.set(sampler.width, sampler.height);
48
+ vCanvas.transformOrigin.set(0, 0);
49
+
50
+ sampler2D2Canvas(sampler, 255, 0, vCanvas.el)
51
+
52
+ tile.css({
53
+ position: "absolute",
54
+ left: "0",
55
+ top: "0"
56
+ });
57
+
58
+ tile.position.set((tile_size[0] + 1) * x, (tile_size[1] + 1) * y);
59
+
60
+ const label = new LabelView(name, {
61
+ css: {
62
+ top: "0",
63
+ left: "0",
64
+ position: "absolute",
65
+ padding: "4px",
66
+ color: "white",
67
+ textShadow: "0 0 2px black"
68
+ }
69
+ });
70
+
71
+ tile.addChild(vCanvas);
72
+ tile.addChild(label);
73
+
74
+ tile.size.set(vCanvas.size.x * resolution_scale, vCanvas.size.y * resolution_scale)
75
+
76
+ vContainer.addChild(tile);
77
+
78
+ }
79
+
80
+ return vContainer;
81
+ }
@@ -43,7 +43,9 @@ export class GridTaskSequence extends GridTaskGenerator {
43
43
 
44
44
  if (i > 0) {
45
45
  // add dependence on previous task
46
- task.addDependency(tasks[i - 1]);
46
+ const dependency = tasks[i - 1];
47
+
48
+ task.addDependency(dependency);
47
49
  }
48
50
 
49
51
  tasks.push(task);
File without changes