@woosh/meep-engine 2.33.6 → 2.33.11

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 (89) hide show
  1. package/core/binary/BinaryBuffer.js +26 -2
  2. package/core/bvh2/LeafNode.js +6 -1
  3. package/core/bvh2/aabb3/AABB3.js +17 -0
  4. package/core/collection/set/compute_set_difference.js +32 -0
  5. package/core/collection/set/compute_set_intersection.js +22 -0
  6. package/core/collection/set/set_remove.js +15 -0
  7. package/core/collection/table/DataType2TypedArrayConstructorMapping.js +2 -0
  8. package/core/collection/table/DataTypeByteSizes.js +21 -0
  9. package/core/collection/table/RowFirstTable.js +1 -88
  10. package/core/collection/table/RowFirstTable.spec.js +3 -1
  11. package/core/collection/table/RowFirstTableSpec.js +1 -19
  12. package/core/collection/table/computeDataTypeByIndex.js +21 -0
  13. package/core/collection/table/deserializeRowFirstTable.js +48 -0
  14. package/core/collection/table/serializeRowFirstTable.js +27 -0
  15. package/core/color/Color.js +1 -0
  16. package/core/color/ColorUtils.js +12 -3
  17. package/core/geom/3d/aabb/aabb3_from_min_max.js +15 -0
  18. package/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +96 -0
  19. package/{engine/graphics/micron/render/v1 → core/geom/3d}/apply_mat4_transform_to_v3_array.js +0 -0
  20. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.js +3 -3
  21. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.spec.js +1 -1
  22. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_sphere_of_2_spheres.js +3 -3
  23. package/{engine/graphics/micron/util → core/geom/3d}/encode_unit3_hemioct.js +0 -0
  24. package/{engine/graphics/micron/render/refinement → core/geom/3d/frustum}/array_normalize_plane.js +1 -1
  25. package/{engine/graphics/micron/render/refinement → core/geom/3d/frustum}/array_setFromProjectionMatrix.js +2 -2
  26. package/{engine/graphics/micron/util → core/geom/3d}/unit_hemioct.spec.js +1 -1
  27. package/{engine/graphics/micron/build → core}/graph/MultiNode.js +0 -0
  28. package/{engine/graphics/micron/build → core}/graph/SquareMatrix.js +2 -2
  29. package/{engine/graphics/micron/build → core}/graph/SquareMatrix.spec.js +1 -1
  30. package/{engine/graphics/micron/build → core}/graph/WeightedEdge.js +1 -1
  31. package/{engine/graphics/micron/build → core}/graph/build_face_graph_from_mesh.js +2 -2
  32. package/{engine/graphics/micron/build/clustering → core/graph}/cluster_mesh_metis.js +2 -6
  33. package/{engine/graphics/micron/build → core}/graph/coarsen_graph.js +1 -1
  34. package/{engine/graphics/micron/build → core}/graph/coarsen_graph.spec.js +1 -1
  35. package/{engine/graphics/micron/build → core}/graph/eigen/eigen.js +0 -0
  36. package/{engine/graphics/micron/build → core}/graph/eigen/eigen.spec.js +1 -1
  37. package/{engine/graphics/micron/build/hierarchy → core/graph/eigen}/eigen_values_find_spectral_gap.js +0 -0
  38. package/{engine/graphics/micron/build → core}/graph/graph_adjacency_matrix.js +0 -0
  39. package/{engine/graphics/micron/build → core}/graph/graph_compute_disconnected_clusters.js +0 -0
  40. package/{engine/graphics/micron/build → core}/graph/graph_degree_matrix.js +0 -0
  41. package/{engine/graphics/micron/build → core}/graph/graph_k_means_cluster.js +5 -5
  42. package/{engine/graphics/micron/build → core}/graph/graph_laplacian_matrix.js +1 -1
  43. package/{engine/graphics/micron/build → core}/graph/metis/metis.js +2 -2
  44. package/{engine/graphics/micron/build → core}/graph/metis/metis_options.js +0 -0
  45. package/{engine/graphics/micron/build → core}/graph/mn_graph_collapse_weighted_edge.js +0 -0
  46. package/core/process/worker/WorkerBuilder.js +21 -6
  47. package/engine/Engine.d.ts +2 -0
  48. package/engine/EngineHarness.js +4 -4
  49. package/engine/ecs/foliage/InstancedFoliage.js +3 -5
  50. package/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +2 -1
  51. package/engine/ecs/transform/Transform.js +2 -1
  52. package/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +22 -37
  53. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +155 -0
  54. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +68 -0
  55. package/engine/graphics/ecs/mesh-v2/prototypeShadedGeometry.js +31 -0
  56. package/engine/graphics/{micron → geometry}/aabb3_to_buffer_geometry.js +0 -0
  57. package/engine/graphics/{micron/build → geometry/buffered}/compute_buffer_geometry_byte_size.js +0 -0
  58. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +1 -1
  59. package/engine/graphics/micron/build/clustering/build_clustering_2.js +2 -2
  60. package/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +1 -1
  61. package/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +3 -3
  62. package/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -72
  63. package/engine/graphics/micron/build/hierarchy/build_merge_graph.js +2 -2
  64. package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +3 -3
  65. package/engine/graphics/micron/build/hierarchy/merge_patches.js +6 -3
  66. package/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +1 -1
  67. package/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +1 -1
  68. package/engine/graphics/micron/build/hierarchy/patch_combine.js +2 -2
  69. package/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +2 -1
  70. package/engine/graphics/micron/format/MicronGeometry.js +12 -0
  71. package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +1 -1
  72. package/engine/graphics/micron/format/MicronGeometryPatch.js +6 -6
  73. package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +101 -0
  74. package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +25 -0
  75. package/engine/graphics/micron/format/serialization/deserialize_patch.js +104 -0
  76. package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +18 -0
  77. package/engine/graphics/micron/format/serialization/serialize_patch.js +84 -0
  78. package/engine/graphics/micron/render/culling/{PathCullingSystem.js → PatchCullingSystem.js} +1 -1
  79. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +1 -1
  80. package/engine/graphics/micron/render/refinement/RefinementSpec.js +1 -1
  81. package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
  82. package/engine/graphics/render/forward_plus/data/TextureBackedMemoryRegion.js +1 -1
  83. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +11 -6
  84. package/engine/graphics/texture/sampler/TextureBinaryBufferSerializer.js +1 -1
  85. package/engine/network/convertPathToURL.js +7 -1
  86. package/engine/plugin/EnginePluginManager.d.ts +9 -0
  87. package/engine/reference/v2/Reference.d.ts +7 -0
  88. package/package.json +1 -1
  89. package/engine/graphics/micron/build/clustering/cluster_mesh_vertices.js +0 -3
@@ -1,5 +1,5 @@
1
- import { DataType2TypedArrayConstructorMapping } from "../../../../../core/collection/table/DataType2TypedArrayConstructorMapping.js";
2
- import { assert } from "../../../../../core/assert.js";
1
+ import { DataType2TypedArrayConstructorMapping } from "../collection/table/DataType2TypedArrayConstructorMapping.js";
2
+ import { assert } from "../assert.js";
3
3
 
4
4
  export class SquareMatrix {
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { SquareMatrix } from "./SquareMatrix.js";
2
- import { DataType } from "../../../../../core/collection/table/DataType.js";
2
+ import { DataType } from "../collection/table/DataType.js";
3
3
 
4
4
  test('set/get cell', () => {
5
5
  const m = new SquareMatrix(2, DataType.Uint8);
@@ -1,4 +1,4 @@
1
- import { Edge } from "../../../../../core/graph/Edge.js";
1
+ import { Edge } from "./Edge.js";
2
2
 
3
3
  export class WeightedEdge extends Edge {
4
4
  constructor(a, b) {
@@ -1,6 +1,6 @@
1
- import { Graph } from "../../../../../core/graph/v2/Graph.js";
1
+ import { Graph } from "./v2/Graph.js";
2
2
  import { MultiNode } from "./MultiNode.js";
3
- import { compute_face_connection_weight } from "../clustering/compute_face_connection_weight.js";
3
+ import { compute_face_connection_weight } from "../../engine/graphics/micron/build/clustering/compute_face_connection_weight.js";
4
4
  import { WeightedEdge } from "./WeightedEdge.js";
5
5
  import { graph_compute_disconnected_clusters } from "./graph_compute_disconnected_clusters.js";
6
6
 
@@ -1,5 +1,5 @@
1
- import { Metis } from "../graph/metis/metis.js";
2
- import { metis_options } from "../graph/metis/metis_options.js";
1
+ import { Metis } from "./metis/metis.js";
2
+ import { metis_options } from "./metis/metis_options.js";
3
3
 
4
4
  /**
5
5
  * How many times to retry partitioning before giving up
@@ -7,10 +7,6 @@ import { metis_options } from "../graph/metis/metis_options.js";
7
7
  */
8
8
  const MAX_STEPS = 50;
9
9
 
10
- function cluster_mesh_metis_detailed(mesh, patch_size) {
11
-
12
- }
13
-
14
10
  /**
15
11
  *
16
12
  * @param {Uint32Array} result
@@ -1,4 +1,4 @@
1
- import FastBinaryHeap from "../../../../navigation/grid/FastBinaryHeap.js";
1
+ import FastBinaryHeap from "../../engine/navigation/grid/FastBinaryHeap.js";
2
2
  import { mn_graph_collapse_weighted_edge } from "./mn_graph_collapse_weighted_edge.js";
3
3
  import { WeightedEdge } from "./WeightedEdge.js";
4
4
 
@@ -1,4 +1,4 @@
1
- import { Graph } from "../../../../../core/graph/v2/Graph.js";
1
+ import { Graph } from "./v2/Graph.js";
2
2
  import { MultiNode } from "./MultiNode.js";
3
3
  import { WeightedEdge } from "./WeightedEdge.js";
4
4
  import { coarsen_graph } from "./coarsen_graph.js";
@@ -1,5 +1,5 @@
1
1
  import { SquareMatrix } from "../SquareMatrix.js";
2
- import { DataType } from "../../../../../../core/collection/table/DataType.js";
2
+ import { DataType } from "../../collection/table/DataType.js";
3
3
  import { matrix_eigenvalues_in_place } from "./eigen.js";
4
4
 
5
5
  function roughly_equal_array_vectors(actual, expected) {
@@ -1,10 +1,10 @@
1
1
  //
2
- import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
3
- import { randomIntegerBetween } from "../../../../../core/math/MathUtils.js";
2
+ import { seededRandom } from "../math/random/seededRandom.js";
3
+ import { randomIntegerBetween } from "../math/MathUtils.js";
4
4
  import { SquareMatrix } from "./SquareMatrix.js";
5
- import { DataType } from "../../../../../core/collection/table/DataType.js";
6
- import { BitSet } from "../../../../../core/binary/BitSet.js";
7
- import FastBinaryHeap from "../../../../navigation/grid/FastBinaryHeap.js";
5
+ import { DataType } from "../collection/table/DataType.js";
6
+ import { BitSet } from "../binary/BitSet.js";
7
+ import FastBinaryHeap from "../../engine/navigation/grid/FastBinaryHeap.js";
8
8
 
9
9
  /**
10
10
  * @template N
@@ -1,6 +1,6 @@
1
1
  import { graph_degree_matrix } from "./graph_degree_matrix.js";
2
2
  import { SquareMatrix } from "./SquareMatrix.js";
3
- import { DataType } from "../../../../../core/collection/table/DataType.js";
3
+ import { DataType } from "../collection/table/DataType.js";
4
4
  import { graph_adjacency_matrix } from "./graph_adjacency_matrix.js";
5
5
 
6
6
  /**
@@ -1,5 +1,5 @@
1
- import WorkerBuilder from "../../../../../../core/process/worker/WorkerBuilder.js";
2
- import { OnDemandWorkerManager } from "../../../../../../core/process/worker/OnDemandWorkerManager.js";
1
+ import WorkerBuilder from "../../process/worker/WorkerBuilder.js";
2
+ import { OnDemandWorkerManager } from "../../process/worker/OnDemandWorkerManager.js";
3
3
 
4
4
 
5
5
  export class Metis {
@@ -52,17 +52,32 @@ WorkerBuilder.prototype.importScript = function (path) {
52
52
  this.imports.push(path);
53
53
  };
54
54
 
55
+ /**
56
+ *
57
+ * @param {string} code
58
+ * @return {string}
59
+ */
55
60
  function codeToURL(code) {
61
+ const js_mime = 'application/javascript';
62
+
56
63
  let blob;
57
64
  try {
58
- blob = new Blob([code], { type: 'application/javascript' });
65
+ blob = new Blob([code], { type: js_mime });
59
66
  } catch (e) { // Backwards-compatibility
60
- window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
61
- blob = new BlobBuilder();
62
- blob.append(code);
63
- blob = blob.getBlob();
67
+ const BlobBuilder = window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
68
+ if (BlobBuilder !== undefined) {
69
+ blob = new BlobBuilder();
70
+ blob.append(code);
71
+ blob = blob.getBlob();
72
+ }
73
+ }
74
+
75
+ if (blob !== undefined && URL.createObjectURL !== undefined) {
76
+ return URL.createObjectURL(blob);
77
+ } else {
78
+ // build data URL in a slowest way possible
79
+ return `data:${js_mime},${encodeURIComponent(code)}`;
64
80
  }
65
- return URL.createObjectURL(blob);
66
81
  }
67
82
 
68
83
  /**
@@ -8,6 +8,7 @@ import {AssetManager} from "./asset/AssetManager";
8
8
  import {EntityManager} from "./ecs/EntityManager";
9
9
  import View from "../view/View";
10
10
  import Ticker from "./simulation/Ticker";
11
+ import {EnginePluginManager} from "./plugin/EnginePluginManager";
11
12
 
12
13
  export interface IEngineInitializationOptions {
13
14
  entityManager?: EntityManager
@@ -25,6 +26,7 @@ export default class Engine {
25
26
  public readonly devices: { keyboard: KeyboardDevice, pointer: PointerDevice }
26
27
  public readonly assetManager: AssetManager
27
28
  public readonly ticker: Ticker
29
+ public readonly plugins: EnginePluginManager
28
30
 
29
31
  public start(): Promise<any>
30
32
 
@@ -203,10 +203,10 @@ export class EngineHarness {
203
203
  *
204
204
  * @param {Engine} engine
205
205
  * @param {Vector3} [focus]
206
- * @param heightMap
207
- * @param heightRange
208
- * @param pitch
209
- * @param yaw
206
+ * @param [heightMap]
207
+ * @param [heightRange]
208
+ * @param [pitch]
209
+ * @param [yaw]
210
210
  * @param {number} [distance]
211
211
  * @param {Vector2} [terrainSize]
212
212
  * @param {number} [terrainResolution]
@@ -1,9 +1,5 @@
1
1
  import { BinaryNode } from "../../../core/bvh2/BinaryNode.js";
2
- import {
3
- deserializeRowFirstTable,
4
- RowFirstTable,
5
- serializeRowFirstTable
6
- } from "../../../core/collection/table/RowFirstTable.js";
2
+ import { RowFirstTable } from "../../../core/collection/table/RowFirstTable.js";
7
3
  import { InstancedMeshGroup } from "../../graphics/geometry/instancing/InstancedMeshGroup.js";
8
4
  import Vector3 from "../../../core/geom/Vector3.js";
9
5
  import { LeafNode } from "../../../core/bvh2/LeafNode.js";
@@ -19,6 +15,8 @@ import { traverseBinaryNodeUsingVisitor } from "../../../core/bvh2/traversal/tra
19
15
  import { serializeBinaryNodeToBinaryBuffer } from "../../../core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js";
20
16
  import { deserializeBinaryNodeFromBinaryBuffer } from "../../../core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js";
21
17
  import { computeGeometryBoundingSphereMiniball } from "../../graphics/geometry/buffered/computeGeometryBoundingSphereMiniball.js";
18
+ import { serializeRowFirstTable } from "../../../core/collection/table/serializeRowFirstTable.js";
19
+ import { deserializeRowFirstTable } from "../../../core/collection/table/deserializeRowFirstTable.js";
22
20
 
23
21
  /**
24
22
  * @readonly
@@ -1,6 +1,7 @@
1
1
  import { BinaryClassSerializationAdapter } from "../../storage/binary/BinaryClassSerializationAdapter.js";
2
- import { deserializeRowFirstTable, serializeRowFirstTable } from "../../../../core/collection/table/RowFirstTable.js";
3
2
  import { FogOfWar } from "../FogOfWar.js";
3
+ import { serializeRowFirstTable } from "../../../../core/collection/table/serializeRowFirstTable.js";
4
+ import { deserializeRowFirstTable } from "../../../../core/collection/table/deserializeRowFirstTable.js";
4
5
 
5
6
  export class FogOfWarSerializationAdapter extends BinaryClassSerializationAdapter {
6
7
  constructor() {
@@ -6,6 +6,7 @@ import Vector3 from "../../../core/geom/Vector3.js";
6
6
  import Quaternion from "../../../core/geom/Quaternion.js";
7
7
  import { Matrix4 } from "../../../core/geom/Matrix4.js";
8
8
  import { Quaternion as ThreeQuaternion } from "three";
9
+ import { composeMatrix4 } from "../../graphics/util/composeMatrix4.js";
9
10
 
10
11
  const delta = new Vector3();
11
12
 
@@ -175,7 +176,7 @@ export class Transform {
175
176
  * @param {Matrix4} matrix
176
177
  */
177
178
  toThreeMatrix(matrix) {
178
- matrix.compose(this.position, this.rotation, this.scale);
179
+ composeMatrix4(matrix, this.position, this.rotation, this.scale);
179
180
  }
180
181
  }
181
182
 
@@ -1,7 +1,5 @@
1
- import { max2 } from "../../../../core/math/max2.js";
2
- import { min2 } from "../../../../core/math/min2.js";
3
- import { composeMatrix4 } from "../../util/composeMatrix4.js";
4
1
  import { Matrix4 as ThreeMatrix4 } from "three";
2
+ import { aabb3_matrix4_project_by_corners } from "../../../../core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js";
5
3
 
6
4
 
7
5
  const matrix4 = new ThreeMatrix4();
@@ -13,6 +11,12 @@ const matrix4 = new ThreeMatrix4();
13
11
  */
14
12
  const corners = new Float64Array(24);
15
13
 
14
+ /**
15
+ *
16
+ * @type {Float32Array}
17
+ */
18
+ const scratch_aabb = new Float32Array(6);
19
+
16
20
  /**
17
21
  *
18
22
  * @param {LeafNode} bvh
@@ -20,20 +24,7 @@ const corners = new Float64Array(24);
20
24
  * @param {Transform} transform
21
25
  */
22
26
  export function updateNodeByTransformAndBBB(bvh, boundingBox, transform) {
23
- const position = transform.position;
24
- const scale = transform.scale;
25
- const rotation = transform.rotation;
26
-
27
- composeMatrix4(matrix4, position, rotation, scale);
28
-
29
- let x0 = Infinity,
30
- y0 = Infinity,
31
- z0 = Infinity,
32
- x1 = -Infinity,
33
- y1 = -Infinity,
34
- z1 = -Infinity;
35
-
36
- boundingBox.getCorners(corners);
27
+ transform.toThreeMatrix(matrix4);
37
28
 
38
29
  /**
39
30
  * Shortcut elements for faster access
@@ -41,29 +32,23 @@ export function updateNodeByTransformAndBBB(bvh, boundingBox, transform) {
41
32
  */
42
33
  const e = matrix4.elements;
43
34
 
44
- for (let j = 0; j < 24; j += 3) {
45
- const x = corners[j];
46
- const y = corners[j + 1];
47
- const z = corners[j + 2];
48
-
49
- // perform matrix transform on corners
50
-
51
- const w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
35
+ updateNodeByMatrix4AndBBB(bvh, boundingBox, e);
36
+ }
52
37
 
53
- const _x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
54
- const _y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
55
- const _z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
38
+ /**
39
+ *
40
+ * @param {LeafNode} bvh
41
+ * @param {AABB3} boundingBox
42
+ * @param {number[]} matrix4
43
+ */
44
+ export function updateNodeByMatrix4AndBBB(bvh, boundingBox, matrix4) {
45
+ boundingBox.getCorners(corners);
56
46
 
57
- // update AABB bounds
58
47
 
59
- x0 = min2(x0, _x);
60
- y0 = min2(y0, _y);
61
- z0 = min2(z0, _z);
48
+ aabb3_matrix4_project_by_corners(scratch_aabb, corners, matrix4);
62
49
 
63
- x1 = max2(x1, _x);
64
- y1 = max2(y1, _y);
65
- z1 = max2(z1, _z);
66
- }
50
+ bvh.readFromArray(scratch_aabb, 0);
67
51
 
68
- bvh.resize(x0, y0, z0, x1, y1, z1);
52
+ bvh.bubbleRefit();
69
53
  }
54
+
@@ -0,0 +1,155 @@
1
+ import { Mesh, Quaternion } from "three";
2
+ import { updateNodeByMatrix4AndBBB } from "../mesh/updateNodeByTransformAndBBB.js";
3
+ import { LeafNode } from "../../../../core/bvh2/LeafNode.js";
4
+ import { AABB3 } from "../../../../core/bvh2/aabb3/AABB3.js";
5
+
6
+ const _q = new Quaternion();
7
+ const _aabb3 = new AABB3();
8
+
9
+ export class ShadedGeometry {
10
+ constructor() {
11
+ /**
12
+ *
13
+ * @type {THREE.BufferGeometry|null}
14
+ */
15
+ this.geometry = null;
16
+ /**
17
+ *
18
+ * @type {THREE.Material|null}
19
+ */
20
+ this.material = null;
21
+
22
+ /**
23
+ *
24
+ * @type {THREE.Object3D|null}
25
+ * @private
26
+ */
27
+ this.__cached_object = null;
28
+
29
+ /**
30
+ *
31
+ * @type {LeafNode<ShadedGeometry>}
32
+ * @private
33
+ */
34
+ this.__bvh_leaf = new LeafNode(this, 0, 0, 0, 0, 0, 0);
35
+ }
36
+
37
+ get bvh() {
38
+ return this.__bvh_leaf;
39
+ }
40
+
41
+ /**
42
+ *
43
+ * @param {THREE.BufferGeometry} geometry
44
+ * @param {THREE.Material} material
45
+ */
46
+ from(geometry, material) {
47
+ this.geometry = geometry;
48
+ this.material = material;
49
+
50
+ // ensure that geometry has a bounding box
51
+ if (geometry.boundingBox === null) {
52
+ geometry.computeBoundingBox();
53
+ }
54
+
55
+ if (this.__cached_object === null) {
56
+ this.__cached_object = new Mesh(geometry, material);
57
+ } else {
58
+ this.__cached_object.material = material;
59
+ this.__cached_object.geometry = geometry;
60
+ }
61
+ }
62
+
63
+ /**
64
+ *
65
+ * @param geometry
66
+ * @param material
67
+ * @return {ShadedGeometry}
68
+ */
69
+ static from(geometry, material) {
70
+ const r = new ShadedGeometry();
71
+
72
+ r.from(geometry, material);
73
+
74
+ return r;
75
+ }
76
+
77
+ updateTransform() {
78
+ // update matrix
79
+ this.__cached_object.updateMatrix();
80
+
81
+ // update bounds
82
+
83
+ const gbb = this.geometry.boundingBox;
84
+
85
+ _aabb3.setBounds(
86
+ gbb.min.x,
87
+ gbb.min.y,
88
+ gbb.min.z,
89
+ gbb.max.x,
90
+ gbb.max.y,
91
+ gbb.max.z
92
+ );
93
+
94
+ updateNodeByMatrix4AndBBB(this.__bvh_leaf, _aabb3, this.__cached_object.matrix.elements);
95
+ }
96
+
97
+ /**
98
+ *
99
+ * @param {number} x
100
+ * @param {number} y
101
+ * @param {number} z
102
+ */
103
+ setPositionByComponents(x, y, z) {
104
+
105
+ this.__cached_object.position.set(x, y, z);
106
+
107
+ this.updateTransform();
108
+ }
109
+
110
+ /**
111
+ *
112
+ * @param {number} x
113
+ * @param {number} y
114
+ * @param {number} z
115
+ * @param {number} w
116
+ */
117
+ setRotationByComponents(x, y, z, w) {
118
+
119
+ _q.set(x, y, z, w);
120
+
121
+ this.__cached_object.rotation.setFromQuaternion(_q);
122
+
123
+ this.updateTransform();
124
+ }
125
+
126
+ /**
127
+ *
128
+ * @param {number} x
129
+ * @param {number} y
130
+ * @param {number} z
131
+ */
132
+ setScaleByComponents(x, y, z) {
133
+ this.__cached_object.scale.set(x, y, z);
134
+
135
+ this.updateTransform();
136
+ }
137
+
138
+ /**
139
+ *
140
+ * @param {Transform} t
141
+ */
142
+ applyTransform(t) {
143
+ // TODO this can be optimized quite a lot
144
+ const position = t.position;
145
+ this.setPositionByComponents(position.x, position.y, position.z);
146
+
147
+ const rotation = t.rotation;
148
+ this.setRotationByComponents(rotation.x, rotation.y, rotation.z, rotation.w);
149
+
150
+ const scale = t.scale;
151
+ this.setScaleByComponents(scale.x, scale.y, scale.z);
152
+
153
+ this.updateTransform();
154
+ }
155
+ }
@@ -0,0 +1,68 @@
1
+ import { ShadedGeometry } from "./ShadedGeometry.js";
2
+ import { Transform } from "../../../ecs/transform/Transform.js";
3
+ import { System } from "../../../ecs/System.js";
4
+
5
+ export class ShadedGeometrySystem extends System {
6
+ /**
7
+ *
8
+ * @param {Engine} engine
9
+ */
10
+ constructor(engine) {
11
+ super();
12
+ this.dependencies = [ShadedGeometry, Transform];
13
+
14
+ /**
15
+ *s
16
+ * @type {Engine}
17
+ * @private
18
+ */
19
+ this.__engine = engine;
20
+
21
+ /**
22
+ *
23
+ * @type {RenderLayer|null}
24
+ * @private
25
+ */
26
+ this.__render_layer = null;
27
+ }
28
+
29
+ async startup(entityManager, readyCallback, errorCallback) {
30
+
31
+ const engine = this.__engine;
32
+
33
+ this.__render_layer = engine.graphics.layers.create('shaded-geometry');
34
+ this.__render_layer.extractRenderable = (sg) => sg.__cached_object;
35
+
36
+ readyCallback();
37
+ }
38
+
39
+ /**
40
+ *
41
+ * @param {ShadedGeometry} sg
42
+ * @param {Transform} t
43
+ * @param {number} entity
44
+ */
45
+ link(sg, t, entity) {
46
+ t.position.onChanged.add(sg.setPositionByComponents, sg);
47
+ t.rotation.onChanged.add(sg.setRotationByComponents, sg);
48
+ t.scale.onChanged.add(sg.setScaleByComponents, sg);
49
+
50
+ sg.applyTransform(t);
51
+
52
+ this.__render_layer.bvh.insertNode(sg.bvh);
53
+ }
54
+
55
+ /**
56
+ *
57
+ * @param {ShadedGeometry} sg
58
+ * @param {Transform} t
59
+ * @param {number} entity
60
+ */
61
+ unlink(sg, t, entity) {
62
+ t.position.onChanged.remove(sg.setPositionByComponents, sg);
63
+ t.rotation.onChanged.remove(sg.setRotationByComponents, sg);
64
+ t.scale.onChanged.remove(sg.setScaleByComponents, sg);
65
+
66
+ sg.bvh.disconnect();
67
+ }
68
+ }
@@ -0,0 +1,31 @@
1
+ import { EngineHarness } from "../../../EngineHarness.js";
2
+ import { ShadedGeometrySystem } from "./ShadedGeometrySystem.js";
3
+ import EntityBuilder from "../../../ecs/EntityBuilder.js";
4
+ import { Transform } from "../../../ecs/transform/Transform.js";
5
+ import { ShadedGeometry } from "./ShadedGeometry.js";
6
+ import { BoxBufferGeometry, MeshBasicMaterial } from "three";
7
+
8
+ const eh = new EngineHarness();
9
+
10
+ /**
11
+ *
12
+ * @param {Engine} engine
13
+ */
14
+ async function main(engine) {
15
+
16
+ await engine.entityManager.addSystem(new ShadedGeometrySystem(engine));
17
+
18
+ EngineHarness.buildBasics({ engine })
19
+
20
+
21
+ const ecd = engine.entityManager.dataset;
22
+
23
+ new EntityBuilder()
24
+ .add(new Transform())
25
+ .add(ShadedGeometry.from(new BoxBufferGeometry(), new MeshBasicMaterial({
26
+ color: 0xFFFFFF
27
+ })))
28
+ .build(ecd);
29
+ }
30
+
31
+ eh.initialize().then(main);
@@ -11,7 +11,7 @@ import { build_graph_info } from "./debug/build_graph_info.js";
11
11
  import { expandConnectivityByLocality } from "../../../../core/geom/3d/topology/expandConnectivityByLocality.js";
12
12
  import { build_geometry_info } from "./build_geometry_info.js";
13
13
  import { build_leaf_patches_metis } from "./clustering/build_leaf_patches_metis.js";
14
- import { compute_buffer_geometry_byte_size } from "./compute_buffer_geometry_byte_size.js";
14
+ import { compute_buffer_geometry_byte_size } from "../../geometry/buffered/compute_buffer_geometry_byte_size.js";
15
15
 
16
16
 
17
17
  /**
@@ -1,6 +1,6 @@
1
1
  import FastBinaryHeap from "../../../../navigation/grid/FastBinaryHeap.js";
2
- import { mn_graph_collapse_weighted_edge } from "../graph/mn_graph_collapse_weighted_edge.js";
3
- import { build_face_graph_from_mesh } from "../graph/build_face_graph_from_mesh.js";
2
+ import { mn_graph_collapse_weighted_edge } from "../../../../../core/graph/mn_graph_collapse_weighted_edge.js";
3
+ import { build_face_graph_from_mesh } from "../../../../../core/graph/build_face_graph_from_mesh.js";
4
4
 
5
5
  /**
6
6
  *
@@ -1,4 +1,4 @@
1
- import { cluster_mesh_metis } from "./cluster_mesh_metis.js";
1
+ import { cluster_mesh_metis } from "../../../../../core/graph/cluster_mesh_metis.js";
2
2
  import { MICRON_PATCH_SIZE_MAX } from "../MICRON_PATCH_SIZE_MAX.js";
3
3
  import { PatchRepresentation } from "../PatchRepresentation.js";
4
4
  import { TopoMesh } from "../../../../../core/geom/3d/topology/TopoMesh.js";
@@ -1,11 +1,11 @@
1
1
  import { Graph } from "../../../../../core/graph/v2/Graph.js";
2
- import { MultiNode } from "../graph/MultiNode.js";
2
+ import { MultiNode } from "../../../../../core/graph/MultiNode.js";
3
3
  import { merge_patches } from "./merge_patches.js";
4
- import { coarsen_graph } from "../graph/coarsen_graph.js";
4
+ import { coarsen_graph } from "../../../../../core/graph/coarsen_graph.js";
5
5
  import { build_merge_graph } from "./build_merge_graph.js";
6
6
  import { assign_patch_neighbours_from_topology } from "../clustering/assign_patch_neighbours_from_topology.js";
7
7
  import { assert } from "../../../../../core/assert.js";
8
- import { graph_create_off_mesh_links } from "../graph/build_face_graph_from_mesh.js";
8
+ import { graph_create_off_mesh_links } from "../../../../../core/graph/build_face_graph_from_mesh.js";
9
9
  import { build_vertex_quadratics } from "../../../../../core/geom/3d/topology/simplify/quadratic/build_vertex_quadratics.js";
10
10
 
11
11
  /**