@woosh/meep-engine 2.33.5 → 2.33.10

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 (116) 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/RingBuffer.js +40 -10
  5. package/core/collection/array/typed/typed_array_copy.js +2 -2
  6. package/core/collection/set/compute_set_difference.js +32 -0
  7. package/core/collection/set/compute_set_intersection.js +22 -0
  8. package/core/collection/set/set_remove.js +15 -0
  9. package/core/collection/table/DataType2TypedArrayConstructorMapping.js +2 -0
  10. package/core/collection/table/DataTypeByteSizes.js +21 -0
  11. package/core/collection/table/RowFirstTable.js +1 -88
  12. package/core/collection/table/RowFirstTable.spec.js +3 -1
  13. package/core/collection/table/RowFirstTableSpec.js +1 -19
  14. package/core/collection/table/computeDataTypeByIndex.js +21 -0
  15. package/core/collection/table/deserializeRowFirstTable.js +48 -0
  16. package/core/collection/table/serializeRowFirstTable.js +27 -0
  17. package/core/color/Color.js +1 -0
  18. package/core/color/ColorUtils.js +12 -3
  19. package/core/geom/3d/aabb/aabb3_compute_projected_area.js +5 -4
  20. package/core/geom/3d/aabb/aabb3_from_min_max.js +15 -0
  21. package/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +96 -0
  22. package/{engine/graphics/micron/render/v1 → core/geom/3d}/apply_mat4_transform_to_v3_array.js +0 -0
  23. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.js +3 -3
  24. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.spec.js +1 -1
  25. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_sphere_of_2_spheres.js +3 -3
  26. package/{engine/graphics/micron/util → core/geom/3d}/encode_unit3_hemioct.js +0 -0
  27. package/core/geom/3d/frustum/array_normalize_plane.js +25 -0
  28. package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +60 -0
  29. package/{engine/graphics/micron/util → core/geom/3d}/unit_hemioct.spec.js +1 -1
  30. package/{engine/graphics/micron/build → core}/graph/MultiNode.js +0 -0
  31. package/{engine/graphics/micron/build → core}/graph/SquareMatrix.js +2 -2
  32. package/{engine/graphics/micron/build → core}/graph/SquareMatrix.spec.js +1 -1
  33. package/{engine/graphics/micron/build → core}/graph/WeightedEdge.js +1 -1
  34. package/{engine/graphics/micron/build → core}/graph/build_face_graph_from_mesh.js +2 -2
  35. package/{engine/graphics/micron/build/clustering → core/graph}/cluster_mesh_metis.js +2 -6
  36. package/{engine/graphics/micron/build → core}/graph/coarsen_graph.js +1 -1
  37. package/{engine/graphics/micron/build → core}/graph/coarsen_graph.spec.js +1 -1
  38. package/{engine/graphics/micron/build → core}/graph/eigen/eigen.js +0 -0
  39. package/{engine/graphics/micron/build → core}/graph/eigen/eigen.spec.js +1 -1
  40. package/{engine/graphics/micron/build/hierarchy → core/graph/eigen}/eigen_values_find_spectral_gap.js +0 -0
  41. package/{engine/graphics/micron/build → core}/graph/graph_adjacency_matrix.js +0 -0
  42. package/{engine/graphics/micron/build → core}/graph/graph_compute_disconnected_clusters.js +0 -0
  43. package/{engine/graphics/micron/build → core}/graph/graph_degree_matrix.js +0 -0
  44. package/{engine/graphics/micron/build → core}/graph/graph_k_means_cluster.js +5 -5
  45. package/{engine/graphics/micron/build → core}/graph/graph_laplacian_matrix.js +1 -1
  46. package/{engine/graphics/micron/build → core}/graph/metis/metis.js +2 -2
  47. package/{engine/graphics/micron/build → core}/graph/metis/metis_options.js +0 -0
  48. package/{engine/graphics/micron/build → core}/graph/mn_graph_collapse_weighted_edge.js +0 -0
  49. package/core/process/undo/ActionProcessor.d.ts +2 -0
  50. package/core/process/undo/ActionProcessor.js +59 -1
  51. package/core/process/undo/ActionProcessor.spec.js +59 -0
  52. package/core/process/undo/Mark.js +2 -1
  53. package/engine/Engine.d.ts +2 -0
  54. package/engine/EngineHarness.js +4 -4
  55. package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
  56. package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
  57. package/engine/ecs/foliage/InstancedFoliage.js +3 -5
  58. package/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +2 -1
  59. package/engine/ecs/transform/Transform.js +2 -1
  60. package/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +22 -37
  61. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +155 -0
  62. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +68 -0
  63. package/engine/graphics/ecs/mesh-v2/prototypeShadedGeometry.js +31 -0
  64. package/engine/graphics/{micron → geometry}/aabb3_to_buffer_geometry.js +0 -0
  65. package/engine/graphics/{micron/build → geometry/buffered}/compute_buffer_geometry_byte_size.js +0 -0
  66. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +25 -16
  67. package/engine/graphics/material/SplatMaterial.js +4 -97
  68. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +2 -6
  69. package/engine/graphics/micron/build/clustering/build_clustering_2.js +2 -2
  70. package/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +1 -1
  71. package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -0
  72. package/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +3 -3
  73. package/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -72
  74. package/engine/graphics/micron/build/hierarchy/build_merge_graph.js +2 -2
  75. package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +3 -3
  76. package/engine/graphics/micron/build/hierarchy/merge_patches.js +6 -3
  77. package/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +1 -1
  78. package/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +1 -1
  79. package/engine/graphics/micron/build/hierarchy/patch_combine.js +2 -2
  80. package/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +2 -1
  81. package/engine/graphics/micron/format/MicronGeometry.js +12 -0
  82. package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +1 -1
  83. package/engine/graphics/micron/format/MicronGeometryPatch.js +17 -9
  84. package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
  85. package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +101 -0
  86. package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +25 -0
  87. package/engine/graphics/micron/format/serialization/deserialize_patch.js +104 -0
  88. package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +18 -0
  89. package/engine/graphics/micron/format/serialization/serialize_patch.js +84 -0
  90. package/engine/graphics/micron/render/VirtualGeometryBuilder.js +24 -8
  91. package/engine/graphics/micron/render/culling/{PathCullingSystem.js → PatchCullingSystem.js} +1 -1
  92. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +1 -1
  93. package/engine/graphics/micron/render/refinement/ActivePatchList.js +6 -25
  94. package/engine/graphics/micron/render/refinement/RefinementSpec.js +98 -0
  95. package/engine/graphics/micron/render/v1/MaterialVertexSpec.js +21 -0
  96. package/engine/graphics/micron/render/v1/VGThreeRenderer.js +12 -9
  97. package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
  98. package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
  99. package/engine/graphics/render/forward_plus/data/TextureBackedMemoryRegion.js +1 -1
  100. package/engine/graphics/render/forward_plus/prototypeLightManager.js +1 -1
  101. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +11 -6
  102. package/engine/graphics/shadows/ShadowMapRenderer.js +12 -2
  103. package/engine/graphics/texture/cubemap/load_environment_map.js +29 -3
  104. package/engine/graphics/texture/sampler/Sampler2D.js +18 -62
  105. package/engine/graphics/texture/sampler/TextureBinaryBufferSerializer.js +1 -1
  106. package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +3 -2
  107. package/engine/graphics/texture/sampler/differenceSampler.js +31 -0
  108. package/engine/graphics/texture/sampler/typedArrayConstructorByInstance.js +25 -0
  109. package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +3 -2
  110. package/engine/network/convertPathToURL.js +7 -1
  111. package/engine/plugin/EnginePluginManager.d.ts +9 -0
  112. package/engine/reference/v2/Reference.d.ts +7 -0
  113. package/package.json +1 -1
  114. package/view/minimap/gl/MinimapMarkersGL.js +2 -2
  115. package/engine/graphics/micron/build/clustering/cluster_mesh_vertices.js +0 -3
  116. package/engine/graphics/micron/render/RefinementSpec.js +0 -181
@@ -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);
@@ -8,6 +8,7 @@ import {
8
8
  import ThreeFactory from "../../three/ThreeFactory.js";
9
9
  import { StaticMaterialCache } from "../../../asset/loaders/material/StaticMaterialCache.js";
10
10
  import { composeCompile } from "../../material/composeCompile.js";
11
+ import { typed_array_copy } from "../../../../core/collection/array/typed/typed_array_copy.js";
11
12
 
12
13
  /**
13
14
  *
@@ -29,14 +30,14 @@ function InstancedMeshGroup() {
29
30
  * Minimum spare capacity increase during growing
30
31
  * @type {number}
31
32
  */
32
- this.growConstant = 1;
33
+ this.growConstant = 4;
33
34
 
34
- this.shrinkFactor = 0.8;
35
+ this.shrinkFactor = 0.5;
35
36
  /**
36
37
  * Minimum capacity reduction for shrinkage to occur
37
38
  * @type {number}
38
39
  */
39
- this.shrinkConstant = 32;
40
+ this.shrinkConstant = 64;
40
41
 
41
42
  /**
42
43
  *
@@ -217,14 +218,30 @@ InstancedMeshGroup.prototype.setCapacity = function (size) {
217
218
  * @param {number} size
218
219
  */
219
220
  InstancedMeshGroup.prototype.ensureCapacity = function (size) {
221
+
220
222
  const currentCapacity = this.capacity;
223
+
221
224
  if (currentCapacity < size) {
222
- const newCapacityRaw = Math.max(size, currentCapacity * this.growFactor, currentCapacity + this.growConstant);
225
+ // grow
226
+
227
+ const newCapacityRaw = Math.max(
228
+ size,
229
+ currentCapacity * this.growFactor,
230
+ currentCapacity + this.growConstant
231
+ );
232
+
223
233
  const newCapacityInteger = Math.ceil(newCapacityRaw);
234
+
224
235
  this.setCapacity(newCapacityInteger);
225
- } else if (currentCapacity * this.shrinkFactor > size && currentCapacity - this.shrinkConstant > size) {
236
+
237
+ } else if (
238
+ currentCapacity * this.shrinkFactor > size
239
+ && currentCapacity - this.shrinkConstant > size
240
+ ) {
241
+ // shrink
226
242
  this.setCapacity(size);
227
243
  }
244
+
228
245
  };
229
246
 
230
247
  /**
@@ -375,14 +392,6 @@ InstancedMeshGroup.prototype.remove = function (reference) {
375
392
  this.setCount(this.count - 1);
376
393
  };
377
394
 
378
- /**
379
- * @param {Uint8Array|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array} source
380
- * @param {Uint8Array|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array}target
381
- */
382
- function copyArray(source, target) {
383
- target.set(source.subarray(0, Math.min(target.length, source.length)), 0)
384
- }
385
-
386
395
  InstancedMeshGroup.prototype.build = function () {
387
396
  if (this.__threeGeometry !== null) {
388
397
  // dispose old geometry's GPU memory
@@ -415,16 +424,16 @@ InstancedMeshGroup.prototype.build = function () {
415
424
  if (this.__attributePosition !== null) {
416
425
  //copy old data
417
426
  const oldPositionArray = this.__attributePosition.array;
418
- copyArray(oldPositionArray, newPositionArray);
427
+ typed_array_copy(oldPositionArray, newPositionArray);
419
428
  }
420
429
  if (this.__attributeRotation !== null) {
421
430
  //copy old data
422
431
  const oldRotationArray = this.__attributeRotation.array;
423
- copyArray(oldRotationArray, newRotationArray);
432
+ typed_array_copy(oldRotationArray, newRotationArray);
424
433
  }
425
434
  if (this.__attributeScale !== null) {
426
435
  const oldScaleArray = this.__attributeScale.array;
427
- copyArray(oldScaleArray, newScaleArray);
436
+ typed_array_copy(oldScaleArray, newScaleArray);
428
437
 
429
438
  if (newScaleArray.length > oldScaleArray.length) {
430
439
  //fill the rest of the array with scale factor of 1 as a default
@@ -4,7 +4,7 @@
4
4
  import {
5
5
  ClampToEdgeWrapping,
6
6
  Color,
7
- DoubleSide,
7
+ FrontSide,
8
8
  GLSL3,
9
9
  LinearFilter,
10
10
  NormalBlending,
@@ -15,95 +15,10 @@ import {
15
15
  Vector4 as ThreeVector4
16
16
  } from 'three';
17
17
  import TerrainShader from "../shaders/TerrainShader.js";
18
- import Vector4 from "../../../core/geom/Vector4.js";
19
18
  import { Sampler2D } from "../texture/sampler/Sampler2D.js";
20
19
  import sampler2D2Texture from "../texture/sampler/Sampler2D2Texture.js";
21
20
 
22
- /**
23
- *
24
- * @param {Vector4} tex0
25
- * @param {Vector4} tex1
26
- * @param {Vector4} tex2
27
- * @param {Vector4} tex3
28
- * @param {Vector4} splat
29
- * @param {Vector4} result
30
- */
31
- export function blendSplatTextures(tex0, tex1, tex2, tex3, splat, result) {
32
- const b0 = splat.x;
33
- const b1 = splat.y;
34
- const b2 = splat.z;
35
- const b3 = splat.w;
36
-
37
- const bT = b0 + b1 + b2 + b3;
38
-
39
-
40
- result.set(
41
- (tex0.x * b0 + tex1.x * b1 + tex2.x * b2 + tex3.x * b3) / bT,
42
- (tex0.y * b0 + tex1.y * b1 + tex2.y * b2 + tex3.y * b3) / bT,
43
- (tex0.z * b0 + tex1.z * b1 + tex2.z * b2 + tex3.z * b3) / bT,
44
- (tex0.w * b0 + tex1.w * b1 + tex2.w * b2 + tex3.w * b3) / bT
45
- );
46
- }
47
-
48
- /**
49
- *
50
- * @param {Sampler2D[]} diffuse
51
- * @param {Vector2} diffuseRepeat
52
- * @param {Sampler2D} splat
53
- * @param {Vector2} gridSize
54
- * @param {Vector2} resultTextureSize
55
- * @returns {Sampler2D}
56
- */
57
- export function buildTerrainTexture({ diffuse, diffuseRepeat, splat, gridSize, resultTextureSize }) {
58
- const texture0 = diffuse[0];
59
- const texture1 = diffuse[1];
60
- const texture2 = diffuse[2];
61
- const texture3 = diffuse[3];
62
-
63
- const resultData = new Uint8Array(resultTextureSize.x * resultTextureSize.y * 4);
64
-
65
- const result = new Sampler2D(resultData, 4, resultTextureSize.x, resultTextureSize.y);
66
-
67
- //do the splatting
68
- let x, y, u, v;
69
-
70
- const tex0 = new Vector4(0, 0, 0, 0);
71
- const tex1 = new Vector4(0, 0, 0, 0);
72
- const tex2 = new Vector4(0, 0, 0, 0);
73
- const tex3 = new Vector4(0, 0, 0, 0);
74
-
75
- const vSplat = new Vector4(0, 0, 0, 0);
76
-
77
- const vTemp = new Vector4(0, 0, 0, 0);
78
-
79
- for (x = 0; x < resultTextureSize.x; x++) {
80
-
81
- u = x / (resultTextureSize.x - 1);
82
-
83
- for (y = 0; y < resultTextureSize.y; y++) {
84
-
85
- v = y / (resultTextureSize.y - 1);
86
-
87
- const dU = (u * diffuseRepeat.x) % 1;
88
- const dV = (v * diffuseRepeat.y) % 1;
89
-
90
- texture0.sample(dU, dV, tex0);
91
- texture1.sample(dU, dV, tex1);
92
- texture2.sample(dU, dV, tex2);
93
- texture3.sample(dU, dV, tex3);
94
-
95
- splat.sample(u, v, vSplat);
96
-
97
- blendSplatTextures(tex0, tex1, tex2, tex3, vSplat, vTemp);
98
-
99
- result.set(x, y, [vTemp.x, vTemp.y, vTemp.z, 255]);
100
- }
101
- }
102
-
103
- return result;
104
- }
105
-
106
- function whitePixelTexture() {
21
+ export function whitePixelTexture() {
107
22
  const sampler = Sampler2D.uint8(4, 1, 1);
108
23
 
109
24
  for (let i = 0; i < sampler.data.length; i++) {
@@ -205,17 +120,12 @@ export function SplatMaterial(
205
120
  uniforms.gridResolution.value.set(gridResolution.x, gridResolution.y);
206
121
  }
207
122
 
208
-
209
- //this is for the water shader, so that back of the terrain reflects in the water, otherwise edges of shoreline look odd
210
- //TODO check how this can be removed, it would speed water(and ordinary) rendering if back faces could be culled
211
- const side = DoubleSide;
212
-
213
123
  const sm = new ShaderMaterial({
214
124
 
215
125
  uniforms: uniforms,
216
126
  vertexShader: TerrainShader.vertexShader,
217
127
  fragmentShader: TerrainShader.fragmentShader,
218
- side: side,
128
+ side: FrontSide,
219
129
  blending: NormalBlending,
220
130
  depthTest: true,
221
131
  depthWrite: true,
@@ -249,11 +159,8 @@ export function SplatMaterial(
249
159
  sm.aoMap = true;
250
160
  uniforms.aoMap.value = lightMap;
251
161
  uniforms.aoMapIntensity.value = 0.7;
252
- //
253
- // sm.lightMap = true;
254
- // uniforms.lightMap.value = options.lightMap;
255
- // uniforms.lightMapIntensity.value = 1;
256
162
  }
163
+
257
164
  sm.extensions.derivatives = true; //needed for rendering grid
258
165
  sm.needsUpdate = true;
259
166
 
@@ -4,7 +4,6 @@ import { MicronGeometry } from "../format/MicronGeometry.js";
4
4
  import { buildAbstractPatchHierarchy } from "./hierarchy/buildAbstractPatchHierarchy.js";
5
5
  import { MicronGeometryBufferAttributeSpec } from "../format/MicronGeometryBufferAttributeSpec.js";
6
6
  import { typedArrayToDataType } from "../../../../core/collection/array/typedArrayToDataType.js";
7
- import { RowFirstTableSpec } from "../../../../core/collection/table/RowFirstTableSpec.js";
8
7
  import { DataType } from "../../../../core/collection/table/DataType.js";
9
8
  import { MicronGeometryPatch } from "../format/MicronGeometryPatch.js";
10
9
  import { build_clustering_info } from "./debug/build_clustering_info.js";
@@ -12,7 +11,7 @@ import { build_graph_info } from "./debug/build_graph_info.js";
12
11
  import { expandConnectivityByLocality } from "../../../../core/geom/3d/topology/expandConnectivityByLocality.js";
13
12
  import { build_geometry_info } from "./build_geometry_info.js";
14
13
  import { build_leaf_patches_metis } from "./clustering/build_leaf_patches_metis.js";
15
- 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";
16
15
 
17
16
 
18
17
  /**
@@ -202,11 +201,8 @@ export async function buildMicronGeometryFromBufferGeometry(input) {
202
201
  // console.time('build geometry');
203
202
 
204
203
  const vertex_attributes = attributes_from_buffer_geometry(input);
205
- const data_types = buildVertexDataTypeMap(vertex_attributes);
206
- const vertex_data_spec = RowFirstTableSpec.get(data_types);
207
204
 
208
- r.vertex_spec.data = vertex_data_spec;
209
- r.vertex_spec.attributes = vertex_attributes;
205
+ r.vertex_spec.setAttributes(vertex_attributes);
210
206
  r.root = compilePatchGraph(root, input, r.vertex_spec);
211
207
 
212
208
  r.initialize();
@@ -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";
@@ -198,6 +198,8 @@ export function fill_patch_geometry_data(result, buffer_geometry, topo, vertex_d
198
198
  const micron_attributes = vertex_data_spec.attributes;
199
199
  const attribute_count = micron_attributes.length;
200
200
 
201
+ //TODO create a single ArrayBuffer for all attributes to get better cache coherence for rendering
202
+
201
203
  for (let i = 0; i < attribute_count; i++) {
202
204
  const attribute_spec = micron_attributes[i];
203
205
 
@@ -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
  /**