@woosh/meep-engine 2.48.19 → 2.48.21

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 (117) 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/graph/layout/computeDisconnectedSubGraphs.js +1 -0
  6. package/src/core/process/task/TaskGroup.js +1 -1
  7. package/src/core/process/task/util/task_tree_compute_leaf_tasks.js +21 -0
  8. package/src/engine/graphics/geometry/AttributeSpec.d.ts +2 -2
  9. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +1 -3
  10. package/src/engine/graphics/render/forward_plus/LightManager.js +9 -7
  11. package/src/engine/graphics/{micron/render/instanced → texture}/AttributeDataTexture.js +28 -19
  12. package/src/engine/graphics/{render/forward_plus/data → texture}/TextureBackedMemoryRegion.js +8 -8
  13. package/src/engine/graphics/{render/forward_plus/data → texture}/computeThreeTextureFormat.js +2 -2
  14. package/src/engine/graphics/{render/forward_plus/data → texture}/computeThreeTextureInternalFormatFromDataType.js +1 -1
  15. package/src/engine/graphics/{render/forward_plus/data → texture}/computeThreeTextureTypeFromDataType.js +1 -1
  16. package/src/engine/graphics/texture/sampler/Sampler2D2Canvas.js +1 -1
  17. package/src/engine/graphics/texture/sampler/sampler2DToFloat32Texture.js +1 -3
  18. package/src/generation/GridTaskGroup.js +4 -4
  19. package/src/generation/filtering/numeric/util/populateSampler2DFromCellFilter.js +10 -2
  20. package/src/generation/filtering/numeric/util/sampler_from_filter.js +26 -0
  21. package/src/generation/filtering/numeric/util/visualise_filters_as_grid.js +81 -0
  22. package/src/generation/grid/generation/GridTaskSequence.js +3 -1
  23. package/src/engine/graphics/micron/MICRON_GEOMETRY_FIELD.js +0 -1
  24. package/src/engine/graphics/micron/MICRON_URI_FIELD.js +0 -1
  25. package/src/engine/graphics/micron/build/MICRON_PATCH_SIZE_MAX.js +0 -5
  26. package/src/engine/graphics/micron/build/PatchRepresentation.js +0 -424
  27. package/src/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +0 -311
  28. package/src/engine/graphics/micron/build/build_geometry_info.js +0 -21
  29. package/src/engine/graphics/micron/build/clustering/assignInitialPatchNeighbours.js +0 -63
  30. package/src/engine/graphics/micron/build/clustering/assign_patch_neighbours_from_topology.js +0 -46
  31. package/src/engine/graphics/micron/build/clustering/build_clustering_2.js +0 -37
  32. package/src/engine/graphics/micron/build/clustering/build_leaf_patches.js +0 -326
  33. package/src/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +0 -76
  34. package/src/engine/graphics/micron/build/clustering/computeBorderLengthChange.js +0 -59
  35. package/src/engine/graphics/micron/build/clustering/computeFaceCurvatureScore.js +0 -57
  36. package/src/engine/graphics/micron/build/clustering/computeOpenFaceFreedom.js +0 -35
  37. package/src/engine/graphics/micron/build/clustering/compute_face_connection_weight.js +0 -35
  38. package/src/engine/graphics/micron/build/clustering/populateOpenFaceNeighboursForPatch.js +0 -56
  39. package/src/engine/graphics/micron/build/clustering/validate_leaf_patch_connectivity.js +0 -44
  40. package/src/engine/graphics/micron/build/compute_micron_buffer_array_constructor.js +0 -24
  41. package/src/engine/graphics/micron/build/compute_vertex_remap_cost.js +0 -29
  42. package/src/engine/graphics/micron/build/debug/build_clustering_info.js +0 -58
  43. package/src/engine/graphics/micron/build/debug/build_graph_info.js +0 -59
  44. package/src/engine/graphics/micron/build/fill_patch_geometry_data.js +0 -270
  45. package/src/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +0 -196
  46. package/src/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -162
  47. package/src/engine/graphics/micron/build/hierarchy/build_merge_graph.js +0 -89
  48. package/src/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +0 -146
  49. package/src/engine/graphics/micron/build/hierarchy/compute_patches_shared_vertex_count.js +0 -32
  50. package/src/engine/graphics/micron/build/hierarchy/compute_patches_shared_vertices.js +0 -34
  51. package/src/engine/graphics/micron/build/hierarchy/merge_patches.js +0 -581
  52. package/src/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +0 -53
  53. package/src/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +0 -515
  54. package/src/engine/graphics/micron/build/hierarchy/patch_combine.js +0 -180
  55. package/src/engine/graphics/micron/build/hierarchy/patch_fill_holes_by_uncollapse.js +0 -60
  56. package/src/engine/graphics/micron/build/hierarchy/patch_stitch_parent_border.js +0 -320
  57. package/src/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +0 -547
  58. package/src/engine/graphics/micron/build/hierarchy/qvdr_build_tree.js +0 -140
  59. package/src/engine/graphics/micron/buildPatchwork.js +0 -68
  60. package/src/engine/graphics/micron/convert_three_object_to_micron.js +0 -179
  61. package/src/engine/graphics/micron/debug/VirtualGeometryStats.js +0 -42
  62. package/src/engine/graphics/micron/format/MICRON_GEOMETRY_PROPERTY_NAME.js +0 -1
  63. package/src/engine/graphics/micron/format/MicronGeometry.d.ts +0 -21
  64. package/src/engine/graphics/micron/format/MicronGeometry.js +0 -334
  65. package/src/engine/graphics/micron/format/MicronGeometryPatch.d.ts +0 -3
  66. package/src/engine/graphics/micron/format/MicronGeometryPatch.js +0 -205
  67. package/src/engine/graphics/micron/format/MicronGeometryPatchOccurance.js +0 -50
  68. package/src/engine/graphics/micron/format/ThreeMicronMesh.d.ts +0 -10
  69. package/src/engine/graphics/micron/format/ThreeMicronMesh.js +0 -45
  70. package/src/engine/graphics/micron/format/VirtualGeometry.js +0 -158
  71. package/src/engine/graphics/micron/format/micron_build_proxy_geometry.js +0 -205
  72. package/src/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +0 -123
  73. package/src/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.spec.js +0 -63
  74. package/src/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.js +0 -83
  75. package/src/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.spec.js +0 -51
  76. package/src/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +0 -25
  77. package/src/engine/graphics/micron/format/serialization/deserialize_patch.js +0 -106
  78. package/src/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +0 -18
  79. package/src/engine/graphics/micron/format/serialization/serialize_patch.js +0 -84
  80. package/src/engine/graphics/micron/format/validate_patch_bounds.js +0 -69
  81. package/src/engine/graphics/micron/plugin/GLTFAssetTransformer.js +0 -265
  82. package/src/engine/graphics/micron/plugin/GLTF_MICRON_ID_FIELD.js +0 -5
  83. package/src/engine/graphics/micron/plugin/MicronRenderPlugin.d.ts +0 -8
  84. package/src/engine/graphics/micron/plugin/MicronRenderPlugin.js +0 -150
  85. package/src/engine/graphics/micron/plugin/serialization/BufferGeometrySerializationAdapter.js +0 -176
  86. package/src/engine/graphics/micron/plugin/shaded_geometry/MicronShadedGeometryRenderAdapter.js +0 -216
  87. package/src/engine/graphics/micron/prototypeMicronProxyBuild.js +0 -227
  88. package/src/engine/graphics/micron/prototypeVirtualGeometry.js +0 -911
  89. package/src/engine/graphics/micron/render/PatchCacheKey.js +0 -79
  90. package/src/engine/graphics/micron/render/VIRTUAL_MESH_FLAG.d.ts +0 -1
  91. package/src/engine/graphics/micron/render/VIRTUAL_MESH_FLAG.js +0 -1
  92. package/src/engine/graphics/micron/render/VirtualGeometryBuilder.js +0 -207
  93. package/src/engine/graphics/micron/render/approximateTriangleArea.js +0 -25
  94. package/src/engine/graphics/micron/render/culling/PatchCullingSystem.js +0 -129
  95. package/src/engine/graphics/micron/render/instanced/PatchDataTextures.js +0 -325
  96. package/src/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +0 -175
  97. package/src/engine/graphics/micron/render/instanced/shader/constants.js +0 -3
  98. package/src/engine/graphics/micron/render/instanced/shader/gen_micron_vertex_attribute_texture_name.js +0 -8
  99. package/src/engine/graphics/micron/render/instanced/shader/shader_rewrite_standard.js +0 -250
  100. package/src/engine/graphics/micron/render/makeThreeMeshFromVirtualGeometry.js +0 -37
  101. package/src/engine/graphics/micron/render/refinement/ActivePatchFlags.js +0 -8
  102. package/src/engine/graphics/micron/render/refinement/ActivePatchList.js +0 -241
  103. package/src/engine/graphics/micron/render/refinement/ActivePatchRecord.js +0 -154
  104. package/src/engine/graphics/micron/render/refinement/RefinementSpec.js +0 -84
  105. package/src/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +0 -133
  106. package/src/engine/graphics/micron/render/refinement/is_patch_facing_back.js +0 -43
  107. package/src/engine/graphics/micron/render/refinement/is_patch_visible.js +0 -37
  108. package/src/engine/graphics/micron/render/v1/MaterialContext.js +0 -150
  109. package/src/engine/graphics/micron/render/v1/MaterialVertexSpec.js +0 -115
  110. package/src/engine/graphics/micron/render/v1/MicronRenderContext.js +0 -145
  111. package/src/engine/graphics/micron/render/v1/ThreeVirtualGeometryAdapter.js +0 -255
  112. package/src/engine/graphics/micron/render/v1/VGThreeRenderer.js +0 -142
  113. package/src/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +0 -54
  114. package/src/engine/graphics/micron/simplifyGeometry.js +0 -26
  115. package/src/engine/graphics/micron/util/patchToBufferGeometry.js +0 -19
  116. /package/src/{engine/graphics/render/forward_plus/data → core/math}/NumericType.js +0 -0
  117. /package/src/engine/graphics/{render/forward_plus/data → texture}/channelCountToThreIntegerTextureType.js +0 -0
@@ -1,205 +0,0 @@
1
- import { ConicRay } from "../../../../core/geom/ConicRay.js";
2
- import { vec4 } from "gl-matrix";
3
- import { assert } from "../../../../core/assert.js";
4
-
5
-
6
- const EMPTY_ARRAY_UINT8 = new Uint8Array(0);
7
-
8
- /**
9
- * Patches are organized into a tree hierarchy
10
- */
11
- export class MicronGeometryPatch {
12
- constructor() {
13
- /**
14
- * Unique identification number in the context of a single geometry
15
- * @type {number}
16
- */
17
- this.id = 0;
18
-
19
- /**
20
- * Bounds are used to determine screen error and whether a patch should be subdivided or not for rendering
21
- * @type {number[]}
22
- */
23
- this.bounding_box = null;
24
-
25
- /**
26
- *
27
- * @type {vec4|number[]}
28
- */
29
- this.bounding_sphere = vec4.create();
30
-
31
- /**
32
- *
33
- * @type {number[]|Float32Array}
34
- */
35
- this.group_bounding_box = null;
36
-
37
- /**
38
- * TODO get rid of this, use bounding box instead for smaller memory footprint
39
- * @type {number[]|Float32Array}
40
- */
41
- this.group_bounding_box_corners = null;
42
-
43
- /**
44
- * Continuous memory region for various pieces of data to get better memory access patterns
45
- * All pieces of data end up in a continuous piece of memory, resulting in better cache coherence
46
- * @type {ArrayBuffer}
47
- */
48
- const array_buffer = new ArrayBuffer(144);
49
- this.allocate_metadata(array_buffer, 0);
50
-
51
- /**
52
- *
53
- * @type {vec4|number[]}
54
- */
55
- this.group_bounding_sphere = vec4.create();
56
-
57
- /**
58
- *
59
- * @type {number}
60
- */
61
- this.group_error = 0;
62
-
63
- /**
64
- *
65
- * @type {MicronGeometryPatch[]}
66
- */
67
- this.parents = [];
68
-
69
- /**
70
- *
71
- * @type {MicronGeometryPatch[]}
72
- */
73
- this.children = [];
74
-
75
- /**
76
- * Level of detail, lower number means more detailed
77
- * @type {number}
78
- */
79
- this.lod = 0;
80
-
81
- /**
82
- *
83
- * @type {number}
84
- */
85
- this.polygon_count = 0;
86
-
87
- /**
88
- * Number of vertices in the patch
89
- * @type {number}
90
- */
91
- this.vertex_count = 0;
92
-
93
- /**
94
- * Accessors to the buffer array of attribute data
95
- * @type {Float32Array|Float64Array|Uint8Array|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array[]}
96
- */
97
- this.vertex_attribute_arrays = [];
98
-
99
- /**
100
- *
101
- * @type {Uint8Array|Uint16Array|null}
102
- */
103
- this.face_indices = EMPTY_ARRAY_UINT8;
104
-
105
- /**
106
- * Bounding cone of all of the face normals
107
- * @type {ConicRay}
108
- */
109
- this.normal_cone = new ConicRay();
110
-
111
- /*
112
- TODO compute polygon side distribution, use a gaussian spherics or spherical harmonics representation
113
- Having a distribution will allow us to better estimate smallest polygon area based on view angle
114
- Better estimation of area => better error estimation => better image quality
115
-
116
- IDEA 2) We can use spherics to approximate projected area of the patch within it's bounding_box
117
- */
118
- }
119
-
120
- /**
121
- *
122
- * @param {ArrayBuffer} buffer
123
- * @param {number} offset
124
- * @returns {number}
125
- */
126
- allocate_metadata(buffer, offset) {
127
- assert.isNonNegativeInteger(offset, 'offset');
128
- assert.greaterThanOrEqual(buffer.byteLength, offset + 144, 'buffer underflow');
129
-
130
- this.bounding_box = new Float32Array(buffer, offset, 6);
131
-
132
- this.group_bounding_box = new Float32Array(buffer, offset + 24, 6);
133
-
134
- this.group_bounding_box_corners = new Float32Array(buffer, offset + 48, 24);
135
-
136
- return 144;
137
- }
138
-
139
- hash() {
140
- return this.id;
141
- }
142
-
143
- computeByteSize() {
144
- let result = 0;
145
-
146
- result += this.face_indices.buffer.byteLength;
147
-
148
- const attribute_arrays = this.vertex_attribute_arrays;
149
- const attribute_count = attribute_arrays.length;
150
-
151
- for (let i = 0; i < attribute_count; i++) {
152
- const attribute_array = attribute_arrays[i];
153
-
154
- result += attribute_array.buffer.byteLength;
155
- }
156
-
157
- return result;
158
- }
159
-
160
-
161
- /**
162
- *
163
- * @param {function(MicronGeometryPatch)} callback
164
- * @param {*} [thisArg]
165
- */
166
- traverse(callback, thisArg) {
167
- const stack = [this];
168
- let stack_cursor = 1;
169
- const seen_nodes = new Set();
170
- seen_nodes.add(this);
171
-
172
-
173
- while (stack_cursor > 0) {
174
- stack_cursor--;
175
-
176
- const patch = stack[stack_cursor];
177
-
178
-
179
- callback.call(thisArg, patch);
180
-
181
- const children = patch.children;
182
- const child_count = children.length;
183
-
184
- for (let i = 0; i < child_count; i++) {
185
- const child = children[i];
186
-
187
- if (seen_nodes.has(child)) {
188
- continue;
189
- }
190
-
191
- seen_nodes.add(child);
192
-
193
- stack[stack_cursor++] = child;
194
- }
195
- }
196
- }
197
-
198
- }
199
-
200
-
201
- /**
202
- * @readonly
203
- * @type {boolean}
204
- */
205
- MicronGeometryPatch.prototype.isMicronGeometryPatch = true;
@@ -1,50 +0,0 @@
1
- import { squirrel3 } from "../../../../core/math/hash/squirrel3.js";
2
- import { isArrayEqualStrict } from "../../../../core/collection/array/isArrayEqualStrict.js";
3
-
4
- export class MicronGeometryPatchOccurrence {
5
- constructor() {
6
- /**
7
- *
8
- * @type {number}
9
- */
10
- this.geometry_id = -1;
11
-
12
- /**
13
- *
14
- * @type {number}
15
- */
16
- this.instance_id = -1;
17
-
18
- /**
19
- *
20
- * @type {MicronGeometryPatch|null}
21
- */
22
- this.patch = null;
23
- /**
24
- *
25
- * @type {number[]|Float32Array|null}
26
- */
27
- this.transform = null;
28
- }
29
-
30
- hash() {
31
- return squirrel3(this.patch.id)
32
- ^ squirrel3(this.geometry_id)
33
- ^ this.instance_id;
34
- }
35
-
36
- /**
37
- *
38
- * @param {MicronGeometryPatchOccurrence} other
39
- * @returns {boolean}
40
- */
41
- equals(other) {
42
- return this.geometry_id === other.geometry_id
43
- && this.instance_id === other.instance_id
44
- && this.patch.id === other.patch.id
45
- && isArrayEqualStrict(this.transform, other.transform)
46
- ;
47
- }
48
-
49
-
50
- }
@@ -1,10 +0,0 @@
1
- import {Material, Object3D} from "three";
2
- import {MicronGeometry} from "./MicronGeometry";
3
-
4
- export class ThreeMicronMesh extends Object3D {
5
- readonly instance_id: number
6
- material: Material
7
- geometry: MicronGeometry
8
-
9
- readonly isMicronMesh: boolean
10
- }
@@ -1,45 +0,0 @@
1
- import { Object3D } from "three";
2
-
3
- let instance_id = 0;
4
-
5
- export class ThreeMicronMesh extends Object3D {
6
- /**
7
- *
8
- * @param {MicronGeometry} geometry
9
- * @param {THREE.Material} material
10
- */
11
- constructor(geometry, material) {
12
- super();
13
-
14
- /**
15
- *
16
- * @type {number}
17
- */
18
- this.instance_id = instance_id++;
19
-
20
- /**
21
- *
22
- * @type {Material}
23
- */
24
- this.material = material;
25
-
26
- /**
27
- *
28
- * @type {MicronGeometry}
29
- */
30
- this.geometry = geometry;
31
- }
32
-
33
- copy(other,r) {
34
- this.material = other.material;
35
- this.geometry = other.geometry;
36
-
37
- return super.copy(other,r);
38
- }
39
- }
40
-
41
- /**
42
- * @readonly
43
- * @type {boolean}
44
- */
45
- ThreeMicronMesh.prototype.isMicronMesh = true;
@@ -1,158 +0,0 @@
1
- import { MicronGeometryPatchOccurrence } from "./MicronGeometryPatchOccurance.js";
2
- import { max3 } from "../../../../core/math/max3.js";
3
-
4
- const DEFAULT_CAPACITY = 10000;
5
- /**
6
- *
7
- * @type {number}
8
- */
9
- const CAPACITY_GROW_FACTOR = 1.2;
10
- /**
11
- *
12
- * @type {number}
13
- */
14
- const CAPACITY_GROW_MIN_STEP = 64;
15
-
16
- /**
17
- * Number of words making up a single patch element
18
- * @type {number}
19
- */
20
- const PATCH_WORD_COUNT = 3;
21
-
22
- export class VirtualGeometry {
23
- constructor() {
24
- this.__capacity = DEFAULT_CAPACITY;
25
- /**
26
- * pack patch instance as [INSTANCE_ID, GEOMETRY_ID, PATCH_ID]
27
- * @type {number[]}
28
- */
29
- this.patches = new Uint32Array(this.__capacity * PATCH_WORD_COUNT);
30
-
31
-
32
- /**
33
- *
34
- * @type {number}
35
- */
36
- this.patch_count = 0;
37
-
38
- /**
39
- * Lookup table of matrix transforms
40
- * @type {number[][]}
41
- */
42
- this.lookup_instance_transforms = [];
43
-
44
- /**
45
- * Lookup table of geometries
46
- * @type {MicronGeometry[]}
47
- */
48
- this.loolup_geometries = [];
49
-
50
- /**
51
- *
52
- * @type {number}
53
- */
54
- this.stats_instance_count = 0;
55
- this.stats_source_triangle_count = 0;
56
- this.stats_source_vertex_count = 0;
57
- this.stats_source_byte_size = 0;
58
- }
59
-
60
- /**
61
- *
62
- * @param {number} patch_count how much must be supported
63
- * @return {boolean} true if capacity was sufficient, false if had to be resized
64
- */
65
- ensureCapacity(patch_count) {
66
- if (this.__capacity < patch_count) {
67
- // grow capacity
68
-
69
- const new_capacity = Math.ceil(max3(
70
- patch_count,
71
- patch_count * CAPACITY_GROW_FACTOR,
72
- patch_count + CAPACITY_GROW_MIN_STEP
73
- ));
74
-
75
- const new_array = new Uint32Array(new_capacity * PATCH_WORD_COUNT);
76
-
77
- new_array.set(this.patches);
78
-
79
- this.patches = new_array;
80
-
81
- this.__capacity = new_capacity;
82
-
83
- return false;
84
- }
85
-
86
- return true;
87
- }
88
-
89
- resetStats() {
90
- this.stats_instance_count = 0;
91
- this.stats_source_triangle_count = 0;
92
- this.stats_source_vertex_count = 0;
93
- this.stats_source_byte_size = 0;
94
- }
95
-
96
- /**
97
- *
98
- * @returns {number}
99
- */
100
- computeFaceCount() {
101
- let r = 0;
102
- const patch_count = this.patch_count;
103
- const patches = this.patches;
104
-
105
- for (let i = 0; i < patch_count; i++) {
106
- const i3 = i * PATCH_WORD_COUNT;
107
-
108
- const geometry_id = patches[i3 + 1];
109
- const patch_id = patches[i3 + 2];
110
-
111
- const geometry = this.loolup_geometries[geometry_id];
112
-
113
- const patch = geometry.patches[patch_id];
114
-
115
- r += patch.polygon_count;
116
- }
117
-
118
- return r;
119
- }
120
-
121
- /**
122
- *
123
- * @returns {number}
124
- */
125
- computeVertexCount() {
126
- let r = 0;
127
- const patch_count = this.patch_count;
128
- const patches = this.patches;
129
- for (let i = 0; i < patch_count; i++) {
130
- const i3 = i * PATCH_WORD_COUNT;
131
-
132
- const geometry_id = patches[i3 + 1];
133
- const patch_id = patches[i3 + 2];
134
-
135
- const geometry = this.loolup_geometries[geometry_id];
136
-
137
- const patch = geometry.patches[patch_id];
138
-
139
- r += patch.vertex_count;
140
- }
141
-
142
- return r;
143
- }
144
-
145
- /**
146
- *
147
- * @param {MicronGeometryPatchOccurrence} patch
148
- */
149
- add(patch) {
150
- throw new Error('Deprecated');
151
- }
152
-
153
- clear() {
154
- this.patch_count = 0;
155
-
156
- this.resetStats();
157
- }
158
- }
@@ -1,205 +0,0 @@
1
- //
2
-
3
- import BinaryHeap from "../../../../core/collection/heap/FastBinaryHeap.js";
4
- import { BufferAttribute, BufferGeometry } from "three";
5
- import { UintArrayForCount } from "../../../../core/collection/array/typed/uint_array_for_count.js";
6
- import {
7
- compute_typed_array_constructor_from_data_type
8
- } from "../../../../core/binary/type/DataType2TypedArrayConstructorMapping.js";
9
- import { BitSet } from "../../../../core/binary/BitSet.js";
10
- import { min2 } from "../../../../core/math/min2.js";
11
- import { max2 } from "../../../../core/math/max2.js";
12
-
13
- /**
14
- *
15
- * @param {MicronGeometry} micron_geometry
16
- * @param {number} fraction
17
- * @param {number} min_face_count
18
- * @returns {MicronGeometryPatch[]}
19
- */
20
- function collect_patches(micron_geometry, fraction, min_face_count) {
21
- /**
22
- *
23
- * @type {BinaryHeap<MicronGeometryPatch>}
24
- */
25
- const heap = new BinaryHeap(patch => {
26
- // LOD is a good proxy for how much detail there is in a patch
27
- return -patch.lod;
28
- });
29
-
30
- let closed_set = new BitSet();
31
-
32
- let current_polycount = 0;
33
-
34
- /**
35
- *
36
- * @param {MicronGeometryPatch} patch
37
- */
38
- function add(patch) {
39
-
40
- closed_set.set(patch.id, true);
41
-
42
- heap.push(patch);
43
-
44
- current_polycount += patch.polygon_count;
45
- }
46
-
47
- /**
48
- *
49
- * @param {MicronGeometryPatch} patch
50
- */
51
- function refine(patch) {
52
- const children = patch.children;
53
- const child_count = children.length;
54
-
55
-
56
- for (let i = 0; i < child_count; i++) {
57
- const child = children[i];
58
-
59
- if (closed_set.get(child.id)) {
60
- // already refined
61
- continue;
62
- }
63
-
64
- add(child);
65
-
66
- const parents = child.parents;
67
-
68
- const parent_count = parents.length;
69
- for (let j = 0; j < parent_count; j++) {
70
- const parent = parents[j];
71
-
72
- if (parent === parent) {
73
- continue;
74
- }
75
-
76
- // remove and refine other patches in the same group
77
- if (heap.delete(parent)) {
78
- refine(parent);
79
- }
80
- }
81
- }
82
- }
83
-
84
- add(micron_geometry.root);
85
-
86
- const target_polycount_threshold = max2(
87
- micron_geometry.source_triangle_count * fraction,
88
- min2(
89
- min_face_count,
90
- micron_geometry.source_triangle_count
91
- )
92
- );
93
-
94
- while (current_polycount < target_polycount_threshold) {
95
- const p = heap.peek();
96
-
97
- if (p === undefined || p.lod === 0) {
98
- // no refinement possible
99
- break;
100
- }
101
-
102
- heap.pop();
103
-
104
- current_polycount -= p.polygon_count;
105
-
106
- refine(p);
107
- }
108
-
109
- const result = [];
110
-
111
- // collect
112
- while (!heap.isEmpty()) {
113
- result.push(heap.pop());
114
- }
115
-
116
- return result;
117
- }
118
-
119
- /**
120
- *
121
- * @param {MicronGeometryPatch[]} patches
122
- * @param {VertexDataSpec} vertex_spec
123
- * @returns {THREE.BufferGeometry}
124
- */
125
- function assemble_patches_to_geometry(patches, vertex_spec) {
126
- const geo = new BufferGeometry();
127
-
128
- //compute total number of vertices and faces
129
- let total_faces = 0;
130
- let total_vertices = 0;
131
-
132
- for (let i = 0; i < patches.length; i++) {
133
- const patch = patches[i];
134
-
135
- total_faces += patch.polygon_count;
136
- total_vertices += patch.vertex_count;
137
- }
138
-
139
- const index_data = new (UintArrayForCount(total_vertices))(total_faces * 3);
140
-
141
- geo.setIndex(new BufferAttribute(index_data, 1, false));
142
-
143
- const attribute_arrays = [];
144
-
145
- const attribute_specs = vertex_spec.attributes;
146
- const attribute_count = attribute_specs.length;
147
- for (let i = 0; i < attribute_count; i++) {
148
- const attribute = attribute_specs[i];
149
-
150
- const TA = compute_typed_array_constructor_from_data_type(attribute.type);
151
-
152
- const attribute_data = new TA(total_vertices * 3);
153
-
154
- attribute_arrays[i] = attribute_data;
155
-
156
- geo.setAttribute(attribute.name, new BufferAttribute(attribute_data, attribute.itemSize, attribute.normalized));
157
- }
158
-
159
- let index_cursor = 0;
160
- let vertex_cursor = 0;
161
-
162
- // add patches to resulting geometry
163
- for (let i = 0; i < patches.length; i++) {
164
- const patch = patches[i];
165
-
166
- const local_index_size = patch.polygon_count * 3;
167
-
168
- // copy transformed indices
169
- for (let j = 0; j < local_index_size; j++) {
170
- const local_index = patch.face_indices[j];
171
-
172
- index_data[index_cursor + j] = local_index + vertex_cursor;
173
- }
174
-
175
- // copy vertex data
176
-
177
- for (let j = 0; j < attribute_count; j++) {
178
- const attribute_destination = attribute_arrays[j];
179
-
180
- const attribute_source = patch.vertex_attribute_arrays[j];
181
- const destination_offset = vertex_cursor * attribute_specs[j].itemSize;
182
-
183
- attribute_destination.set(attribute_source, destination_offset);
184
- }
185
-
186
- vertex_cursor += patch.vertex_count;
187
- index_cursor += local_index_size;
188
- }
189
-
190
- return geo;
191
- }
192
-
193
-
194
- /**
195
- *
196
- * @param {MicronGeometry} micron_geometry
197
- * @param {number} fraction
198
- * @param {number} [min_face_count]
199
- * @returns {THREE.BufferGeometry}
200
- */
201
- export function micron_build_proxy_geometry(micron_geometry, fraction, min_face_count = 128) {
202
- const patches = collect_patches(micron_geometry, fraction, min_face_count);
203
-
204
- return assemble_patches_to_geometry(patches, micron_geometry.vertex_spec);
205
- }