@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,250 +0,0 @@
1
- import LineBuilder from "../../../../../../core/codegen/LineBuilder.js";
2
- import { BinaryDataType } from "../../../../../../core/binary/type/BinaryDataType.js";
3
- import { gen_micron_vertex_attribute_texture_name } from "./gen_micron_vertex_attribute_texture_name.js";
4
- import { MICRON_PATCH_SIZE_MAX } from "../../../build/MICRON_PATCH_SIZE_MAX.js";
5
-
6
- const DEBUG_PATCHES = false;
7
-
8
- /**
9
- *
10
- * @param {{vertexShader,fragmentShader,uniforms:Object<IUniform>}} shader
11
- * @param {Object<IUniform>} uniforms
12
- * @param {VertexDataSpec} spec
13
- * @param {number} column_count
14
- */
15
- export function shader_rewrite_standard(shader, uniforms, spec, column_count) {
16
- Object.assign(shader.uniforms, uniforms);
17
-
18
- const originalVertexShader = shader.vertexShader;
19
-
20
- const vx_lb_preamble = new LineBuilder();
21
-
22
- vx_lb_preamble.add('precision mediump usampler2D;');
23
- vx_lb_preamble.add('precision mediump isampler2D;');
24
-
25
- vx_lb_preamble.add('attribute float micron_patch_address;');
26
- vx_lb_preamble.add('attribute mat4 micron_patch_transform;');
27
-
28
- if (DEBUG_PATCHES) {
29
- // vx_lb_preamble.add('attribute float micron_instance_id;');
30
- vx_lb_preamble.add('varying float v_micron_patch_address;');
31
- vx_lb_preamble.add('varying float v_vertex_id;');
32
- vx_lb_preamble.add('varying float v_micron_instance_id;');
33
- }
34
-
35
- const attributes = spec.attributes;
36
- const attribute_count = attributes.length;
37
-
38
- for (let i = 0; i < attribute_count; i++) {
39
- const attribute = attributes[i];
40
- let type;
41
-
42
- switch (attribute.type) {
43
- case BinaryDataType.Int8:
44
- type = 'isampler2D';
45
- break;
46
- default:
47
- type = 'sampler2D';
48
- break
49
- }
50
-
51
- vx_lb_preamble.add(`uniform sampler2D ${gen_micron_vertex_attribute_texture_name(attribute.name)};`);
52
- }
53
-
54
-
55
- let rewrittenVertexShader = originalVertexShader
56
- .replace(
57
- '#include <uv_vertex>',
58
- `
59
- int micron_patch_address_int = int(micron_patch_address);
60
-
61
- ${
62
- DEBUG_PATCHES ? `
63
- v_micron_patch_address = micron_patch_address;
64
- v_vertex_id = float(gl_VertexID);
65
- // v_micron_instance_id = float(micron_instance_id);
66
- ` : ''
67
- }
68
- int micron_patch_slot_column = micron_patch_address_int % ${column_count};
69
- int micron_patch_slot_x = micron_patch_slot_column * ${MICRON_PATCH_SIZE_MAX * 3};
70
- int micron_patch_slot_y = (micron_patch_address_int - micron_patch_slot_column) / ${column_count};
71
-
72
- ivec2 micron_vertex_uv = ivec2( gl_VertexID + micron_patch_slot_x, micron_patch_slot_y );
73
-
74
- #include <uv_vertex>
75
- `
76
- )
77
- .replace(
78
- '#include <begin_vertex>',
79
- `
80
- vec3 position_micron = texelFetch(${gen_micron_vertex_attribute_texture_name('position')}, micron_vertex_uv, 0).rgb;
81
- vec3 transformed = ( micron_patch_transform * vec4(position_micron,1.0) ).xyz;
82
-
83
- `
84
- );
85
-
86
- const attribute_spec_uv = spec.getAttributeByName('uv');
87
-
88
- if (attribute_spec_uv !== undefined) {
89
- const vx_uv_value = `texelFetch(${gen_micron_vertex_attribute_texture_name('uv')}, micron_vertex_uv, 0).rg`
90
-
91
- rewrittenVertexShader = rewrittenVertexShader.replace(
92
- '#include <uv_vertex>',
93
- `
94
- #ifdef USE_UV
95
- vUv = ( uvTransform * vec3( ${vx_uv_value}, 1 ) ).xy;
96
- #endif
97
- `
98
- );
99
- }
100
-
101
- const attribute_spec_uv2 = spec.getAttributeByName('uv2');
102
-
103
- if (attribute_spec_uv2 !== undefined) {
104
- const vx_uv2_value = `texelFetch(${gen_micron_vertex_attribute_texture_name('uv2')}, micron_vertex_uv, 0).rg`
105
-
106
- rewrittenVertexShader = rewrittenVertexShader.replace(
107
- '#include <uv2_vertex>',
108
- `
109
- #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
110
- vUv2 = ( uv2Transform * vec3( ${vx_uv2_value}, 1 ) ).xy;
111
- #endif
112
- `
113
- );
114
- }
115
-
116
- const attribute_spec_normal = spec.getAttributeByName('normal');
117
-
118
-
119
- if (attribute_spec_normal !== undefined) {
120
- const vx_normal_value = `texelFetch(${gen_micron_vertex_attribute_texture_name('normal')}, micron_vertex_uv, 0).rgb`
121
-
122
- rewrittenVertexShader = rewrittenVertexShader.replace(
123
- '#include <beginnormal_vertex>',
124
- `
125
- vec3 objectNormal = ${vx_normal_value};
126
- #ifdef USE_TANGENT
127
- vec3 objectTangent = vec3( tangent.xyz );
128
- #endif
129
- `
130
- );
131
-
132
- }
133
-
134
- rewrittenVertexShader = rewrittenVertexShader.replace(
135
- '#include <defaultnormal_vertex>',
136
- `
137
- vec3 transformedNormal = objectNormal;
138
-
139
- // this is in lieu of a per-instance normal-matrix
140
- // shear transforms in the instance matrix are not supported
141
- mat3 m = mat3( micron_patch_transform );
142
- transformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );
143
- transformedNormal = m * transformedNormal;
144
-
145
- transformedNormal = normalMatrix * transformedNormal;
146
-
147
- #ifdef FLIP_SIDED
148
- transformedNormal = - transformedNormal;
149
- #endif
150
- #ifdef USE_TANGENT
151
- vec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;
152
- #ifdef FLIP_SIDED
153
- transformedTangent = - transformedTangent;
154
- #endif
155
- #endif
156
- `
157
- );
158
-
159
- const attribute_spec_color = spec.getAttributeByName('color');
160
-
161
- if (attribute_spec_color !== undefined) {
162
- // using color
163
- const vx_color_value = `texelFetch(${gen_micron_vertex_attribute_texture_name('color')}, micron_vertex_uv, 0)`
164
-
165
- rewrittenVertexShader = rewrittenVertexShader.replace(
166
- '#include <color_vertex>',
167
- `
168
- #if defined( USE_COLOR_ALPHA )
169
- vColor = vec4( 1.0 );
170
- #elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )
171
- vColor = vec3( 1.0 );
172
- #endif
173
-
174
- #ifdef USE_COLOR
175
-
176
- #ifdef USE_COLOR_ALPHA
177
- vColor *= ${vx_color_value}.rgba;
178
- #else
179
- vColor *= ${vx_color_value}.rgb;
180
- #endif
181
-
182
- #endif
183
-
184
- `
185
- );
186
-
187
- }
188
-
189
- // shader.defines.USE_COLOR = true;
190
- //
191
- // rewrittenVertexShader = rewrittenVertexShader.replace(
192
- // '#include <color_vertex>',
193
- // `
194
- // #include <color_vertex>
195
- // //vColor = vec3(1.0);
196
- // vColor.xyz = vec3(
197
- // sin(float(micron_patch_address)*123.1),
198
- // sin(float(micron_patch_address)*11.7),
199
- // sin(float(micron_patch_address)*932.183)
200
- // );
201
- // `
202
- // );
203
-
204
- const newVertexShader = vx_lb_preamble.build()
205
- + '\n'
206
- + rewrittenVertexShader;
207
-
208
-
209
- shader.vertexShader = newVertexShader;
210
-
211
- if (DEBUG_PATCHES) {
212
- shader.fragmentShader = shader.fragmentShader.replace(
213
- '#include <color_pars_fragment>',
214
- `#include <color_pars_fragment>
215
- varying float v_micron_patch_address;
216
- varying float v_vertex_id;
217
- varying float v_micron_instance_id;
218
- `
219
- );
220
- shader.fragmentShader = shader.fragmentShader.replace(
221
- '#include <color_fragment>',
222
- // `diffuseColor.rgb = vec3(
223
- // sin(v_micron_patch_address*123.1),
224
- // sin(v_micron_patch_address*11.7),
225
- // sin(v_micron_patch_address*932.183)
226
- // );`
227
- `diffuseColor.rgb = vec3(1.0);`
228
- );
229
-
230
- shader.fragmentShader = shader.fragmentShader.replace(
231
- '#include <dithering_fragment>',
232
- `gl_FragColor.rgb = vec3(
233
- sin(v_micron_patch_address*123.1)*0.5 + 0.5,
234
- sin(v_micron_patch_address*11.7)*0.5 + 0.5,
235
- sin(v_micron_patch_address*932.183)*0.5 + 0.5
236
- );`
237
- // `gl_FragColor.rgb = vec3(
238
- // sin(v_micron_instance_id*123.1)*0.5 + 0.5,
239
- // sin(v_micron_instance_id*11.7)*0.5 + 0.5,
240
- // sin(v_micron_instance_id*932.183)*0.5 + 0.5
241
- // );`
242
- // `gl_FragColor.rgb = vec3(
243
- // v_vertex_id*0.0026041666666666665,
244
- // 1.0,
245
- // 1.0
246
- // );`
247
- //`gl_FragColor.rgb = vec3(1.0);`
248
- );
249
- }
250
- }
@@ -1,37 +0,0 @@
1
- import { ThreeVirtualGeometryAdapter } from "./v1/ThreeVirtualGeometryAdapter.js";
2
- import { Group, Mesh } from "three";
3
-
4
- /**
5
- *
6
- * @param {VertexDataSpec} spec
7
- * @param {VirtualGeometry} virtual_geometry
8
- * @param {THREE.Material[]} materials
9
- * @returns {Mesh}
10
- */
11
- export function makeThreeMeshFromVirtualGeometry(spec, virtual_geometry, materials) {
12
- const adapter = new ThreeVirtualGeometryAdapter();
13
- adapter.__vertex_spec = spec;
14
-
15
- const g = new Group();
16
-
17
- materials.forEach(material =>{
18
-
19
- const mesh = new Mesh(adapter.buffer_geometry, material);
20
- mesh.frustumCulled = false;
21
-
22
- adapter.onRebuild.add(() => {
23
- mesh.geometry = adapter.buffer_geometry;
24
- });
25
-
26
- g.add(mesh);
27
- })
28
-
29
- g.update = () => {
30
- adapter.build(virtual_geometry);
31
- };
32
-
33
- g['@micron'] = true;
34
-
35
-
36
- return g;
37
- }
@@ -1,8 +0,0 @@
1
- /**
2
- *
3
- * @enum {number}
4
- */
5
- export const ActivePatchFlags = {
6
- Visible: 1,
7
- Occluded: 2
8
- };
@@ -1,241 +0,0 @@
1
- import { ActivePatchRecord } from "./ActivePatchRecord.js";
2
- import { ActivePatchFlags } from "./ActivePatchFlags.js";
3
- import { aabb3_project_to_2d } from "../../../../../core/geom/3d/aabb/aabb3_compute_projected_area.js";
4
- import { BitSet } from "../../../../../core/binary/BitSet.js";
5
- import {
6
- aabb3_array_intersects_frustum_array
7
- } from "../../../../../core/geom/3d/aabb/aabb3_array_intersects_frustum_array.js";
8
-
9
- export class ActivePatchList {
10
- constructor() {
11
- /**
12
- * Linked list
13
- * @type {ActivePatchRecord}
14
- */
15
- this.records = null;
16
-
17
- /**
18
- * Used for tracking changes
19
- * @type {number}
20
- */
21
- this.version = 0;
22
-
23
- /**
24
- *
25
- * @type {BitSet}
26
- */
27
- this.unfolded = new BitSet();
28
-
29
- // prevent re-allocation related thrashing
30
- this.unfolded.preventShrink();
31
- }
32
-
33
- clear() {
34
- const unfolded = this.unfolded;
35
-
36
- unfolded.reset();
37
-
38
- ActivePatchRecord.pool_release_all(this.records);
39
-
40
- this.records = null;
41
- }
42
-
43
- /**
44
- *
45
- * @param {MicronGeometry} geometry
46
- */
47
- initializeFromGeometry(geometry) {
48
- this.clear();
49
-
50
- const record = ActivePatchRecord.pool_get();
51
-
52
- record.patch = geometry.root;
53
- record.link_next = null;
54
- record.link_previous = null;
55
-
56
- const unfolded = this.unfolded;
57
- unfolded.set(record.patch.id, true);
58
-
59
- this.records = record;
60
- }
61
-
62
- /**
63
- *
64
- * @param {ActivePatchRecord} record
65
- * @returns {ActivePatchRecord}
66
- */
67
- node_split(record) {
68
-
69
- const sub_patches = record.patch.children;
70
- const sub_patch_count = sub_patches.length;
71
- const unfolded = this.unfolded;
72
-
73
- for (let i = 0; i < sub_patch_count; i++) {
74
- const child = sub_patches[i];
75
-
76
- const child_id = child.id;
77
-
78
- if (unfolded.getAndSet(child_id)) {
79
- // already unfolded, skip
80
- continue;
81
- }
82
-
83
- const child_record = ActivePatchRecord.pool_get();
84
- child_record.patch = child;
85
-
86
- this.record_insert_after(record, child_record);
87
- }
88
-
89
- this.record_remove(record);
90
-
91
- const next = record.link_next;
92
-
93
- ActivePatchRecord.pool_release(record);
94
-
95
- return next;
96
- }
97
-
98
- /**
99
- *
100
- * @param {ActivePatchRecord} record
101
- */
102
- record_remove(record) {
103
- const previous = record.link_previous;
104
- const next = record.link_next;
105
-
106
- if (previous === null) {
107
- this.records = next;
108
- } else {
109
- previous.link_next = next;
110
- }
111
-
112
- if (next !== null) {
113
- next.link_previous = previous;
114
- }
115
- }
116
-
117
- /**
118
- *
119
- * @param {ActivePatchRecord} reference
120
- * @param {ActivePatchRecord} record
121
- */
122
- record_insert_after(reference, record) {
123
- const tail = reference.link_next;
124
-
125
- reference.link_next = record;
126
-
127
- record.link_previous = reference;
128
- record.link_next = tail;
129
-
130
- if (tail !== null) {
131
- tail.link_previous = record;
132
- }
133
- }
134
-
135
- /**
136
- *
137
- * @param {ActivePatchRecord} record
138
- */
139
- insert(record) {
140
- if (this.records === null) {
141
- this.records = record;
142
- } else {
143
- this.record_insert_after(this.records, record);
144
- }
145
- }
146
-
147
- /**
148
- *
149
- * @param {ActivePatchRecord} a
150
- * @param {ActivePatchRecord} b
151
- */
152
- node_merge(a, b) {
153
- a.patch = a.patch.parent;
154
- a.setFlag(ActivePatchFlags.Visible);
155
-
156
- this.record_remove(b);
157
- }
158
-
159
-
160
- /**
161
- * Populate with LOD-X of a given geometry
162
- * @param {MicronGeometry} geometry
163
- * @param {number} lod
164
- */
165
- build_from_lod(geometry, lod) {
166
- // reset current records
167
- this.records = null;
168
-
169
- const patches = geometry.__patches;
170
-
171
- for (let i = 0; i < patches.length; i++) {
172
- const p = patches[i];
173
- if (p.lod !== lod) {
174
- continue;
175
- }
176
- const record = ActivePatchRecord.fromPatch(p);
177
- record.setFlag(ActivePatchFlags.Visible);
178
- this.insert(record);
179
- }
180
-
181
- }
182
-
183
- /**
184
- *
185
- * @param {RefinementSpec} spec
186
- */
187
- refine(spec) {
188
-
189
- const frustum_planes = spec.frustum_f32;
190
- const projection_matrix = spec.projection_matrix;
191
- const error_threshold = spec.error_threshold_normalized;
192
-
193
- let record = this.records
194
-
195
- for (; record !== null;) {
196
-
197
- const node = record.patch;
198
-
199
-
200
- /*
201
- check if node is in view frustum
202
- NOTE: following suggestion in "FastMesh: Efficient View-dependent Meshing" by Renato Pajarola et al, we can do a more coarse frustum test approximating frustum as a cone initially
203
- */
204
- const in_view_frustum = aabb3_array_intersects_frustum_array(node.bounding_box, frustum_planes);
205
-
206
- if (!in_view_frustum) {
207
- // outside of view frustum, cull
208
- record = record.link_next;
209
- continue;
210
- }
211
-
212
- record.setFlag(ActivePatchFlags.Visible);
213
-
214
- /*
215
- scale error to projection space:
216
- 1 - project bounding sphere of the patch to view space
217
- 2 - compute relative scale of the projected sphere
218
- 3 - multiply group error by the projected sphere scale to know the projected error
219
- */
220
-
221
-
222
- // check if record needs to be split
223
- if (node.lod > 0) {
224
-
225
- // not the lowest level of LOD, see if subdivision might be necessary
226
-
227
- // compute average triangle area
228
- const group_screen_area = aabb3_project_to_2d(node.group_bounding_box_corners, projection_matrix);
229
- const screen_space_error = node.group_error * group_screen_area;
230
-
231
- if (screen_space_error > error_threshold) {
232
- // error too large, needs to be split
233
- record = this.node_split(record);
234
- continue;
235
- }
236
- }
237
-
238
- record = record.link_next;
239
- }
240
- }
241
- }
@@ -1,154 +0,0 @@
1
- import { assert } from "../../../../../core/assert.js";
2
-
3
- /**
4
- *
5
- * @type {ActivePatchRecord|null}
6
- */
7
- let patch_pool = null;
8
- let patch_pool_size = 0;
9
-
10
- const patch_limit = 4096;
11
-
12
- export class ActivePatchRecord {
13
- constructor() {
14
- /**
15
- *
16
- * @type {number}
17
- */
18
- this.flags = 0;
19
-
20
- /**
21
- *
22
- * @type {MicronGeometryPatch}
23
- */
24
- this.patch = null;
25
-
26
- /**
27
- * Linked list
28
- * @type {ActivePatchRecord|null}
29
- */
30
- this.link_previous = null;
31
- /**
32
- * Linked list
33
- * @type {ActivePatchRecord|null}
34
- */
35
- this.link_next = null;
36
- }
37
-
38
- /**
39
- * @param {MicronGeometryPatch} patch
40
- * @returns {ActivePatchRecord}
41
- */
42
- static fromPatch(patch) {
43
- assert.equal(patch.isMicronGeometryPatch, true, 'patch.MicronGeometryPatch !== true');
44
-
45
- const r = new ActivePatchRecord();
46
-
47
- r.patch = patch;
48
-
49
- return r;
50
- }
51
-
52
- static pool_get() {
53
- if (patch_pool_size <= 0) {
54
- return new ActivePatchRecord();
55
- }
56
-
57
- const r = patch_pool;
58
-
59
- patch_pool = patch_pool.link_next;
60
- patch_pool_size--;
61
-
62
- // reset record
63
- r.flags = 0;
64
-
65
- return r;
66
- }
67
-
68
- /**
69
- *
70
- * @param {ActivePatchRecord} r
71
- */
72
- static pool_release(r) {
73
- if (patch_pool_size >= patch_limit) {
74
- // just drop
75
- return;
76
- }
77
-
78
- r.link_previous = null;
79
- r.patch = null;
80
- r.link_next = patch_pool;
81
-
82
- patch_pool = r;
83
-
84
- patch_pool_size++;
85
- }
86
-
87
- /**
88
- *
89
- * @param {ActivePatchRecord} r
90
- */
91
- static pool_release_all(r) {
92
- if (r === null) {
93
- return;
94
- }
95
-
96
- let p = r;
97
-
98
- for (; patch_pool_size < patch_limit;) {
99
- const next = p.link_next;
100
- patch_pool_size++;
101
-
102
- if (next === null) {
103
- break;
104
- }
105
-
106
- p = next;
107
- }
108
-
109
- const old_head = patch_pool;
110
-
111
- patch_pool = r;
112
- p.link_next = old_head;
113
- }
114
-
115
- /**
116
- *
117
- * @param {number|ActivePatchFlags} flag
118
- * @returns {void}
119
- */
120
- setFlag(flag) {
121
- this.flags |= flag;
122
- }
123
-
124
- /**
125
- *
126
- * @param {number|ActivePatchFlags} flag
127
- * @returns {void}
128
- */
129
- clearFlag(flag) {
130
- this.flags &= ~flag;
131
- }
132
-
133
- /**
134
- *
135
- * @param {number|ActivePatchFlags} flag
136
- * @param {boolean} value
137
- */
138
- writeFlag(flag, value) {
139
- if (value) {
140
- this.setFlag(flag);
141
- } else {
142
- this.clearFlag(flag);
143
- }
144
- }
145
-
146
- /**
147
- *
148
- * @param {number|ActivePatchFlags} flag
149
- * @returns {boolean}
150
- */
151
- getFlag(flag) {
152
- return (this.flags & flag) === flag;
153
- }
154
- }