@woosh/meep-engine 2.33.1 → 2.33.5

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 (73) hide show
  1. package/core/bvh2/aabb3/AABB3.js +18 -0
  2. package/core/bvh2/aabb3/aabb3_intersects_frustum.js +38 -0
  3. package/core/collection/array/copyArray.js +2 -2
  4. package/core/collection/table/RowFirstTableSpec.js +8 -0
  5. package/core/geom/3d/aabb/aabb3_compute_projected_area.js +11 -10
  6. package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -0
  7. package/core/geom/3d/aabb/aabb3_matrix4_project.js +33 -0
  8. package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +41 -0
  9. package/core/geom/3d/plane/plane3_lerp.js +2 -2
  10. package/core/geom/3d/topology/TopoTriangle.js +2 -2
  11. package/core/geom/AABB2.d.ts +2 -0
  12. package/core/geom/Matrix4.js +4 -4
  13. package/core/geom/Vector3.js +5 -5
  14. package/core/model/reactive/model/terminal/ReactiveReference.js +7 -1
  15. package/engine/asset/loaders/GLTFAssetLoader.js +3 -3
  16. package/engine/asset/loaders/material/TextureAttachmensByMaterialType.js +11 -1
  17. package/engine/asset/loaders/material/TextureAttachment.js +12 -1
  18. package/engine/asset/loaders/material/computeTextureEquality.js +1 -1
  19. package/engine/asset/loaders/material/computeTextureHash.js +16 -14
  20. package/engine/asset/loaders/material/traverseMaterialTextures.js +2 -2
  21. package/engine/ecs/animation/OneBoneSurfaceAlignmentSolver.js +2 -2
  22. package/engine/ecs/animation/TwoBoneInverseKinematicsSolver.js +4 -4
  23. package/engine/graphics/GraphicsEngine.d.ts +2 -2
  24. package/engine/graphics/GraphicsEngine.js +20 -62
  25. package/engine/graphics/filter/FlipArrayInPlace.js +25 -0
  26. package/engine/graphics/filter/FlipArrayViaCanvas.js +13 -0
  27. package/engine/graphics/filter/ImageFilter.js +20 -51
  28. package/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +2 -2
  29. package/engine/graphics/material/optimization/MaterialOptimizationContext.js +598 -0
  30. package/engine/graphics/micron/build/PatchRepresentation.js +4 -43
  31. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +3 -70
  32. package/engine/graphics/micron/build/compute_buffer_geometry_byte_size.js +16 -0
  33. package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +1 -1
  34. package/engine/graphics/micron/format/MicronGeometryPatch.js +9 -5
  35. package/engine/graphics/micron/prototypeVirtualGeometry.js +19 -12
  36. package/engine/graphics/micron/render/RefinementSpec.js +104 -33
  37. package/engine/graphics/micron/render/VirtualGeometryBuilder.js +12 -21
  38. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +2 -4
  39. package/engine/graphics/micron/render/instanced/PatchDataTextures.js +1 -0
  40. package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +1 -29
  41. package/engine/graphics/micron/render/refinement/ActivePatchList.js +41 -138
  42. package/engine/graphics/micron/render/refinement/ActivePatchRecord.js +4 -2
  43. package/engine/graphics/micron/render/refinement/is_patch_facing_back.js +43 -0
  44. package/engine/graphics/micron/render/refinement/is_patch_visible.js +37 -0
  45. package/engine/graphics/micron/util/unit_hemioct.spec.js +2 -2
  46. package/engine/graphics/render/buffer/buffers/NormalFrameBuffer.js +12 -2
  47. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +8 -10
  48. package/engine/graphics/render/forward_plus/LightManager.js +5 -7
  49. package/engine/graphics/render/forward_plus/data/NumericType.js +9 -0
  50. package/engine/graphics/render/forward_plus/{TextureBackedMemoryRegion.js → data/TextureBackedMemoryRegion.js} +11 -190
  51. package/engine/graphics/render/forward_plus/data/channelCountToThreIntegerTextureType.js +16 -0
  52. package/engine/graphics/render/forward_plus/data/computeDataType.js +36 -0
  53. package/engine/graphics/render/forward_plus/data/computeThreeTextureFormat.js +18 -0
  54. package/engine/graphics/render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js +63 -0
  55. package/engine/graphics/render/forward_plus/data/computeThreeTextureTypeFromDataType.js +41 -0
  56. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
  57. package/engine/graphics/render/utils/ThreeBypassRenderer.js +1 -3
  58. package/engine/graphics/render/visibility/VisibilityComputer.js +11 -0
  59. package/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.js +198 -0
  60. package/engine/graphics/render/visibility/hiz/buffer/ReductionShader.js +51 -0
  61. package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +179 -0
  62. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +435 -0
  63. package/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +174 -0
  64. package/engine/graphics/render/visibility/hiz/query/QueryShader.js +173 -0
  65. package/engine/graphics/texture/atlas/TextureAtlas.js +1 -1
  66. package/engine/graphics/texture/cubemap/buildCubeURLs.js +13 -0
  67. package/engine/graphics/texture/cubemap/load_environment_map.d.ts +8 -0
  68. package/engine/graphics/texture/cubemap/load_environment_map.js +137 -0
  69. package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +8 -4
  70. package/engine/graphics/texture/virtual/v2/ShaderUsage.js +6 -5
  71. package/engine/graphics/texture/virtual/v2/prototype.js +16 -6
  72. package/package.json +1 -1
  73. package/view/elements/progress/segmented/SegmentedResourceBarView.js +50 -15
@@ -1,8 +1,5 @@
1
- import { BitSet } from "../../../../core/binary/BitSet.js";
2
1
  import { TopoMesh } from "../../../../core/geom/3d/topology/TopoMesh.js";
3
2
  import { PatchRepresentation } from "./PatchRepresentation.js";
4
- import { max3 } from "../../../../core/math/max3.js";
5
- import { min3 } from "../../../../core/math/min3.js";
6
3
  import { MicronGeometry } from "../format/MicronGeometry.js";
7
4
  import { buildAbstractPatchHierarchy } from "./hierarchy/buildAbstractPatchHierarchy.js";
8
5
  import { MicronGeometryBufferAttributeSpec } from "../format/MicronGeometryBufferAttributeSpec.js";
@@ -15,6 +12,7 @@ import { build_graph_info } from "./debug/build_graph_info.js";
15
12
  import { expandConnectivityByLocality } from "../../../../core/geom/3d/topology/expandConnectivityByLocality.js";
16
13
  import { build_geometry_info } from "./build_geometry_info.js";
17
14
  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";
18
16
 
19
17
 
20
18
  /**
@@ -38,55 +36,6 @@ function buildVertexDataTypeMap(attributes) {
38
36
  return data_types;
39
37
  }
40
38
 
41
-
42
- /**
43
- *
44
- * @param {FastBinaryHeap} candidates
45
- * @param {BitSet} open_set
46
- * @param {TopoMesh} mesh
47
- */
48
- function pickCandidateForNextPatch(candidates, open_set, mesh) {
49
-
50
- }
51
-
52
- /**
53
- *
54
- * @param {AABB3} bounds
55
- * @param {TopoTriangle} face
56
- */
57
- function expandBoundsByFace(bounds, face) {
58
- const vertices = face.vertices;
59
-
60
- const vA = vertices[0];
61
- const vB = vertices[1];
62
- const vC = vertices[2];
63
-
64
- bounds._expandToFitPoint(vA.x, vA.y, vA.z);
65
- bounds._expandToFitPoint(vB.x, vB.y, vB.z);
66
- bounds._expandToFitPoint(vC.x, vC.y, vC.z);
67
- }
68
-
69
- /**
70
- *
71
- * @param {AABB3} bounds
72
- * @param {TopoVertex} vA
73
- * @param {TopoVertex} vB
74
- * @param {TopoVertex} vC
75
- * @returns {number}
76
- */
77
- function computeBoundsTriangleInclusionCost(bounds, vA, vB, vC) {
78
- // compute AABB of triangle
79
- const x0 = min3(vA.x, vB.x, vC.x);
80
- const y0 = min3(vA.y, vB.y, vC.y);
81
- const z0 = min3(vA.z, vB.z, vC.z);
82
-
83
- const x1 = max3(vA.x, vB.x, vC.x);
84
- const y1 = max3(vA.y, vB.y, vC.y);
85
- const z1 = max3(vA.z, vB.z, vC.z);
86
-
87
- return bounds._costForInclusion(x0, y0, z0, x1, y1, z1);
88
- }
89
-
90
39
  /**
91
40
  *
92
41
  * @param {MicronGeometryBufferAttributeSpec} spec
@@ -120,6 +69,7 @@ function format_attribute(spec, source, name) {
120
69
 
121
70
  switch (name) {
122
71
  case 'uv':
72
+ case 'uv2':
123
73
  custom_attribute_format_uv(spec, source);
124
74
  break;
125
75
  case 'tangent':
@@ -157,23 +107,6 @@ function attributes_from_buffer_geometry(buffer_geometry) {
157
107
  return result;
158
108
  }
159
109
 
160
- /**
161
- *
162
- * @param {THREE.BufferGeometry} g
163
- * @returns {number}
164
- */
165
- export function compute_buffer_geometry_byte_size(g) {
166
- let result = 0;
167
-
168
- result += g.getIndex().array.buffer.byteLength;
169
-
170
- for (const attribute_name in g.attributes) {
171
- result += g.attributes[attribute_name].array.buffer.byteLength;
172
- }
173
-
174
- return result;
175
- }
176
-
177
110
  const PRINT_VERBOSE_STATS = false;
178
111
 
179
112
  /**
@@ -261,7 +194,7 @@ export async function buildMicronGeometryFromBufferGeometry(input) {
261
194
  const r = new MicronGeometry();
262
195
 
263
196
  r.proxy = input; // TODO use r.buildProxy(1) instead
264
-
197
+
265
198
  r.source_triangle_count = index_attribute.count / 3;
266
199
  r.source_vertex_count = input.getAttribute('position').count;
267
200
  r.source_byte_size = compute_buffer_geometry_byte_size(input);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Estimated GPU-side geometry size
3
+ * @param {THREE.BufferGeometry} g
4
+ * @returns {number}
5
+ */
6
+ export function compute_buffer_geometry_byte_size(g) {
7
+ let result = 0;
8
+
9
+ result += g.getIndex().array.buffer.byteLength;
10
+
11
+ for (const attribute_name in g.attributes) {
12
+ result += g.attributes[attribute_name].array.buffer.byteLength;
13
+ }
14
+
15
+ return result;
16
+ }
@@ -40,8 +40,8 @@ export class MicronGeometryBufferAttributeSpec {
40
40
  equals(other) {
41
41
  return this.type === other.type
42
42
  && this.itemSize === other.itemSize
43
- && this.name === other.name
44
43
  && this.normalized === other.normalized
44
+ && this.name === other.name
45
45
  ;
46
46
  }
47
47
 
@@ -1,4 +1,3 @@
1
- import { AABB3 } from "../../../../core/bvh2/aabb3/AABB3.js";
2
1
  import { squirrel3 } from "../../../../core/math/hash/squirrel3.js";
3
2
  import { ConicRay } from "../../../../core/geom/ConicRay.js";
4
3
  import { vec4 } from "gl-matrix";
@@ -16,15 +15,20 @@ export class MicronGeometryPatch {
16
15
 
17
16
  /**
18
17
  * Bounds are used to determine screen error and whether a patch should be subdivided or not for rendering
19
- * @type {AABB3}
18
+ * @type {number[]}
20
19
  */
21
- this.bounding_box = new AABB3(0, 0, 0, 0, 0, 0);
20
+ this.bounding_box = new Float32Array(6);
22
21
 
23
22
  /**
24
23
  *
25
- * @type {AABB3}
24
+ * @type {number[]|Float32Array}
25
+ */
26
+ this.group_bounding_box = new Float32Array(6);
27
+ /**
28
+ *
29
+ * @type {number[]|Float32Array}
26
30
  */
27
- this.group_bounding_box = new AABB3(0, 0, 0, 0, 0, 0);
31
+ this.group_bounding_box_corners = new Float32Array(24);
28
32
 
29
33
  /**
30
34
  *
@@ -53,7 +53,7 @@ background.wrapS = RepeatWrapping;
53
53
  background.wrapT = RepeatWrapping;
54
54
 
55
55
  const metrics = new MetricCollection();
56
- const METRIC_BUFFER_SIZE = 100;
56
+ const METRIC_BUFFER_SIZE = 1000;
57
57
  metrics.create({
58
58
  name: 'vg_build', buffer_size: METRIC_BUFFER_SIZE
59
59
  });
@@ -153,17 +153,21 @@ async function micron_add_object(object) {
153
153
  if (t.isMesh && material !== null) {
154
154
 
155
155
  const attachments = TextureAttachmentsByMaterialType[material.type];
156
- const n = attachments.length;
157
156
 
158
- for (let i = 0; i < n; i++) {
159
- const a = attachments[i];
160
- const texture = a.read(material);
157
+ if (attachments !== undefined) {
161
158
 
162
- if (texture !== undefined && texture !== null) {
163
- texture.anisotropy = 8;
159
+ const n = attachments.length;
160
+
161
+ for (let i = 0; i < n; i++) {
162
+ const a = attachments[i];
163
+ const texture = a.read(material);
164
+
165
+ if (texture !== undefined && texture !== null) {
166
+ texture.anisotropy = 8;
167
+ }
164
168
  }
165
- }
166
169
 
170
+ }
167
171
 
168
172
  }
169
173
  });
@@ -228,7 +232,7 @@ function init() {
228
232
  pointLight.add(mesh);
229
233
 
230
234
  // add directional light
231
- directionalLight = new DirectionalLight(0xFFAAAA, 0.7);
235
+ directionalLight = new DirectionalLight(0xFFAAAA, 0.8);
232
236
  directionalLight.position.set(-500, 1000, 300);
233
237
  directionalLight.castShadow = true;
234
238
  const shadow_camera = directionalLight.shadow.camera;
@@ -452,12 +456,15 @@ function init() {
452
456
 
453
457
  // sample_gltf_sponza();
454
458
  // sample_gltf_rts_factory();
455
- // sample_lucy();
459
+ sample_lucy();
456
460
  // sample_gltf_hapro_2();
457
461
  // sample_gltf_hapro_1();
458
462
  // sample_gltf_broken_isiflow();
459
- gltf_grid('data/models/moicon/Kople/EVCharger1.gltf');
463
+ // gltf_grid('data/models/moicon/Kople/EVCharger1.gltf');
460
464
  // gltf_grid('data/models/RTS_Buildings_Humans/18/Building_R_18_out/Building_R_18.gltf');
465
+ // gltf_sample('data/models/moicon/08-clickable-assets/model.gltf');
466
+ // gltf_sample('data/models/moicon/05-ground-floor/model.gltf');
467
+ // gltf_sample('data/models/moicon/isiflow_Oct_15_21/0/model.gltf');
461
468
 
462
469
  document.addEventListener("mousemove", onDocumentMouseMove);
463
470
 
@@ -528,7 +535,7 @@ function createScene(geometry, m1, scale) {
528
535
  geometry.computeVertexNormals();
529
536
 
530
537
 
531
- const grid_size = 10;
538
+ const grid_size = 100;
532
539
  const grid_spacing = 2000;
533
540
 
534
541
  for (let i = 0; i < grid_size; i++) {
@@ -1,23 +1,89 @@
1
1
  import Vector2 from "../../../../core/geom/Vector2.js";
2
- import { Frustum, Matrix4 } from "three";
2
+ import { Matrix4 } from "three";
3
3
  import { mat4 } from "gl-matrix";
4
+ import { v3_length } from "../../../../core/geom/Vector3.js";
4
5
 
6
+ /**
7
+ * Normalize a plane in-place
8
+ * @param {number[]} source
9
+ * @param {number} source_offset
10
+ */
11
+ function array_normalize_plane(source, source_offset) {
12
+ const _x = source[source_offset];
13
+ const _y = source[source_offset + 1];
14
+ const _z = source[source_offset + 2];
5
15
 
6
- function setFromProjectionMatrix(planes, me) {
16
+ const length = v3_length(_x, _y, _z);
7
17
 
8
- const me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3];
9
- const me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7];
10
- const me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
11
- const me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
18
+ const inverseNormalLength = 1.0 / length;
12
19
 
13
- planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
14
- planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
15
- planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
16
- planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
17
- planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
18
- planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
20
+ /*
21
+ By re-using values already in the registers instead of using *= we save a few extra READ ops
22
+ */
23
+ source[source_offset] = _x * inverseNormalLength;
24
+ source[source_offset + 1] = _y * inverseNormalLength;
25
+ source[source_offset + 2] = _z * inverseNormalLength;
26
+
27
+ source[source_offset + 3] *= inverseNormalLength;
28
+ }
29
+
30
+ /**
31
+ *
32
+ * @param {number[]} destination
33
+ * @param {number} destination_offset
34
+ * @param {number} x
35
+ * @param {number} y
36
+ * @param {number} z
37
+ * @param {number} w
38
+ */
39
+ function array_set_plane_normalized(destination, destination_offset, x, y, z, w) {
40
+ const length = v3_length(x, y, z);
41
+
42
+ const inverseNormalLength = 1.0 / length;
43
+
44
+ destination[destination_offset] = x * inverseNormalLength;
45
+ destination[destination_offset + 1] = y * inverseNormalLength;
46
+ destination[destination_offset + 2] = z * inverseNormalLength;
47
+ destination[destination_offset + 3] = w * inverseNormalLength;
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @param {number[]|Float32Array} frustum_planes
53
+ * @param {number[]} me
54
+ */
55
+ function array_setFromProjectionMatrix(frustum_planes, me) {
56
+
57
+ const me0 = me[0];
58
+ const me3 = me[3];
59
+
60
+ const me4 = me[4];
61
+ const me7 = me[7];
19
62
 
63
+ const me8 = me[8];
64
+ const me11 = me[11];
20
65
 
66
+ const me12 = me[12];
67
+ const me15 = me[15];
68
+
69
+ array_set_plane_normalized(frustum_planes, 0, me3 - me0, me7 - me4, me11 - me8, me15 - me12);
70
+ array_set_plane_normalized(frustum_planes, 4, me3 + me0, me7 + me4, me11 + me8, me15 + me12);
71
+
72
+ const me1 = me[1];
73
+ const me5 = me[5];
74
+ const me9 = me[9];
75
+ const me13 = me[13];
76
+
77
+ array_set_plane_normalized(frustum_planes, 8, me3 + me1, me7 + me5, me11 + me9, me15 + me13);
78
+ array_set_plane_normalized(frustum_planes, 12, me3 - me1, me7 - me5, me11 - me9, me15 - me13);
79
+
80
+ const me2 = me[2];
81
+ const me6 = me[6];
82
+ const me10 = me[10];
83
+ const me14 = me[14];
84
+
85
+ array_set_plane_normalized(frustum_planes, 16, me3 - me2, me7 - me6, me11 - me10, me15 - me14);
86
+ array_set_plane_normalized(frustum_planes, 20, me3 + me2, me7 + me6, me11 + me10, me15 + me14);
21
87
  }
22
88
 
23
89
  export class RefinementSpec {
@@ -43,11 +109,18 @@ export class RefinementSpec {
43
109
  */
44
110
  this.error_threshold = 1;
45
111
 
112
+ /**
113
+ * Error threshold as a fraction of the screen area instead of pixels, derived internally from pixel value
114
+ * @type {number}
115
+ */
116
+ this.error_threshold_normalized = 1;
117
+
46
118
  /**
47
119
  * Object-space camera frustum
48
- * @type {Frustum}
120
+ * Frustum planes in compact form
121
+ * @type {Float32Array}
49
122
  */
50
- this.frustum = new Frustum();
123
+ this.frustum_f32 = new Float32Array(24);
51
124
 
52
125
  /**
53
126
  * Model world transform
@@ -74,6 +147,18 @@ export class RefinementSpec {
74
147
  this.view_position = new Float32Array(3);
75
148
  }
76
149
 
150
+ get frustum() {
151
+ throw new Error('deprecated, use .frustum_f32 instead');
152
+ }
153
+
154
+ setResolution(x, y) {
155
+ this.resolution.set(x, y);
156
+
157
+ this.viewport_area = x * y;
158
+
159
+ this.error_threshold_normalized = this.error_threshold / this.viewport_area;
160
+ }
161
+
77
162
  /**
78
163
  *
79
164
  * @param {Matrix4} transform world-space object transform
@@ -85,26 +170,12 @@ export class RefinementSpec {
85
170
  _transform.set(transform.elements);
86
171
 
87
172
  // build projection matrix
88
- mat4.multiply(this.projection_matrix, matrix_world_inverse.elements, _transform);
89
- mat4.multiply(this.projection_matrix, matrix_projection.elements, this.projection_matrix);
173
+ const projection_matrix = this.projection_matrix;
90
174
 
91
- // compute view frustum in model-space
92
- setFromProjectionMatrix(this.frustum.planes, this.projection_matrix);
93
-
94
- /*
95
-
96
- // get inverse of model view matrix
97
- model_view_matrix.invert();
98
-
99
- // get view origin position in the prjected space
100
- const inv_mv = model_view_matrix.elements;
101
- const view_position = this.view_position;
175
+ mat4.multiply(projection_matrix, matrix_world_inverse.elements, _transform);
176
+ mat4.multiply(projection_matrix, matrix_projection.elements, projection_matrix);
102
177
 
103
- // extract position component from transform matrix
104
- view_position[0] = inv_mv[12];
105
- view_position[1] = inv_mv[13];
106
- view_position[2] = inv_mv[14];
107
-
108
- */
178
+ // compute view frustum in model-space
179
+ array_setFromProjectionMatrix(this.frustum_f32, projection_matrix);
109
180
  }
110
181
  }
@@ -48,10 +48,10 @@ export class VirtualGeometryBuilder {
48
48
 
49
49
  /**
50
50
  *
51
- * @type {WeakMap<ThreeMicronMesh, ActivePatchList>}
51
+ * @type {ActivePatchList}
52
52
  * @private
53
53
  */
54
- this.__acls = new WeakMap();
54
+ this.__acl = new ActivePatchList();
55
55
 
56
56
  /**
57
57
  * How much error to accept when deciding to subdivide a cluster
@@ -76,12 +76,8 @@ export class VirtualGeometryBuilder {
76
76
  this.__flags__enforce_dependency_splits = true;
77
77
  }
78
78
 
79
- /**
80
- * Drop all cached data, forcing a complete rebuild next time
81
- * Useful for testing and debugging
82
- */
83
- dropCache() {
84
- this.__acls = new WeakMap();
79
+ dropCache(){
80
+ this.__acl.clear();
85
81
  }
86
82
 
87
83
  /**
@@ -129,8 +125,6 @@ export class VirtualGeometryBuilder {
129
125
  return;
130
126
  }
131
127
 
132
- const children = object.children;
133
-
134
128
  if (object.isMicronMesh) {
135
129
  /**
136
130
  *
@@ -139,14 +133,7 @@ export class VirtualGeometryBuilder {
139
133
  const micron_geometry = object.geometry;
140
134
  if (micron_geometry !== undefined) {
141
135
  // get acl
142
-
143
- let acl = this.__acls.get(object);
144
-
145
-
146
- if (acl === undefined) {
147
- acl = new ActivePatchList();
148
- this.__acls.set(object, acl);
149
- }
136
+ const acl = this.__acl;
150
137
 
151
138
  acl.initializeFromGeometry(micron_geometry);
152
139
 
@@ -159,7 +146,9 @@ export class VirtualGeometryBuilder {
159
146
  }
160
147
  }
161
148
 
149
+ const children = object.children;
162
150
  const children_count = children.length;
151
+
163
152
  for (let i = 0; i < children_count; i++) {
164
153
  const child = children[i];
165
154
 
@@ -252,9 +241,10 @@ export class VirtualGeometryBuilder {
252
241
 
253
242
  // update refinement spec
254
243
  refinement_spec.error_threshold = this.error_bias;
255
- refinement_spec.resolution.copy(this.resolution);
256
244
 
257
- refinement_spec.viewport_area = this.resolution.x * this.resolution.y;
245
+ const resolution = this.resolution;
246
+
247
+ refinement_spec.setResolution(resolution.x, resolution.y);
258
248
 
259
249
  // clear output
260
250
  this.output.clear();
@@ -262,9 +252,10 @@ export class VirtualGeometryBuilder {
262
252
  this.__info_enforced_node_splits = 0;
263
253
 
264
254
  const n = this.input_scene_length;
255
+ const input_objects = this.input_scene;
265
256
 
266
257
  for (let i = 0; i < n; i++) {
267
- const object3D = this.input_scene[i];
258
+ const object3D = input_objects[i];
268
259
 
269
260
  this.buildForObject(object3D);
270
261
  }
@@ -2,14 +2,12 @@ import { assert } from "../../../../../core/assert.js";
2
2
  import { MICRON_PATCH_SIZE_MAX } from "../../build/MICRON_PATCH_SIZE_MAX.js";
3
3
  import { typed_array_copy } from "../../../../../core/collection/array/typed/typed_array_copy.js";
4
4
  import { channelCountToThreeTextureFormat } from "../../../texture/channelCountToThreeTextureFormat.js";
5
- import {
6
- computeThreeTextureInternalFormatFromDataType,
7
- computeThreeTextureTypeFromDataType
8
- } from "../../../render/forward_plus/TextureBackedMemoryRegion.js";
9
5
  import { DataTexture, NearestFilter } from "three";
10
6
  import { DataTypeByteSizes } from "../../../../../core/collection/table/RowFirstTableSpec.js";
11
7
  import { DataType } from "../../../../../core/collection/table/DataType.js";
12
8
  import { compute_micron_buffer_array_constructor } from "../../build/compute_micron_buffer_array_constructor.js";
9
+ import { computeThreeTextureTypeFromDataType } from "../../../render/forward_plus/data/computeThreeTextureTypeFromDataType.js";
10
+ import { computeThreeTextureInternalFormatFromDataType } from "../../../render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js";
13
11
 
14
12
  /**
15
13
  *
@@ -253,6 +253,7 @@ export class PatchDataTextures {
253
253
  capacity + 1
254
254
  );
255
255
 
256
+ // Clamp to maximum texture size
256
257
  next_capacity = min2(next_capacity, MAX_TEXTURE_SIZE * this.__column_count);
257
258
 
258
259
  if (next_capacity < capacity) {
@@ -8,7 +8,7 @@ import {
8
8
  } from "three";
9
9
  import { MICRON_PATCH_SIZE_MAX } from "../../build/MICRON_PATCH_SIZE_MAX.js";
10
10
  import Signal from "../../../../../core/events/signal/Signal.js";
11
- import { ATTRIBUTE_INSTANCE_ID, ATTRIBUTE_NAME_ADDRESS, ATTRIBUTE_NAME_TRANSFORM } from "./shader/constants.js";
11
+ import { ATTRIBUTE_NAME_ADDRESS, ATTRIBUTE_NAME_TRANSFORM } from "./shader/constants.js";
12
12
  import { shader_rewrite_standard } from "./shader/shader_rewrite_standard.js";
13
13
 
14
14
 
@@ -98,20 +98,8 @@ export class ThreeInstancedAdapter {
98
98
  const ia_patch_ref = new InstancedBufferAttribute(new Uint16Array(capacity), 1, false);
99
99
  ia_patch_ref.setUsage(StreamDrawUsage);
100
100
 
101
-
102
- /**
103
- * This is a workaround for bug in WebGLBindingStates
104
- * @see https://github.com/mrdoob/three.js/issues/22843
105
- * @type {number}
106
- */
107
- ia_patch_ref.data = 0;
108
-
109
101
  geo.setAttribute(ATTRIBUTE_NAME_ADDRESS, ia_patch_ref);
110
102
 
111
- const ia_instance_id = new InstancedBufferAttribute(new Uint16Array(capacity), 1, false);
112
- ia_instance_id.setUsage(StreamDrawUsage);
113
- geo.setAttribute(ATTRIBUTE_INSTANCE_ID, ia_instance_id);
114
-
115
103
  // signal
116
104
  this.onRebuild.send0();
117
105
  }
@@ -151,7 +139,6 @@ export class ThreeInstancedAdapter {
151
139
  */
152
140
  build(patches, patch_count) {
153
141
  this.__prepare_capacity(patch_count);
154
- // this.__build_geometry();
155
142
 
156
143
  const geo = this.__buffer_geometry;
157
144
 
@@ -163,21 +150,8 @@ export class ThreeInstancedAdapter {
163
150
  const patch_address_attribute = geo.getAttribute(ATTRIBUTE_NAME_ADDRESS);
164
151
  const patch_address_array = patch_address_attribute.array;
165
152
 
166
- /**
167
- * This is a workaround for bug in WebGLBindingStates
168
- * @see https://github.com/mrdoob/three.js/issues/22843
169
- * @type {number}
170
- */
171
- patch_address_attribute.data++;
172
-
173
153
  patch_address_attribute.needsUpdate = true;
174
154
 
175
-
176
- const patch_instance_id_attribute = geo.getAttribute(ATTRIBUTE_INSTANCE_ID);
177
- const patch_instance_id_array = patch_instance_id_attribute.array;
178
-
179
- patch_instance_id_attribute.needsUpdate = true;
180
-
181
155
  const patch_data = this.__patch_data;
182
156
 
183
157
  for (let i = 0; i < patch_count; i++) {
@@ -190,8 +164,6 @@ export class ThreeInstancedAdapter {
190
164
  const patch_slot_id = patch_data.ensure(occurrence.patch);
191
165
 
192
166
  patch_address_array[i] = patch_slot_id;
193
-
194
- patch_instance_id_array[i] = occurrence.instance_id;
195
167
  }
196
168
  }
197
169
  }