@woosh/meep-engine 2.48.20 → 2.48.22
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.
- package/package.json +1 -1
- package/src/{engine/graphics/micron/build/clustering → core/geom/3d/topology/util}/compute_face_connection_weight.js +40 -35
- package/src/core/graph/build_face_graph_from_mesh.js +1 -1
- package/src/engine/graphics/ecs/mesh-v2/sample/load_gltf.js +0 -3
- package/src/engine/graphics/micron/MICRON_GEOMETRY_FIELD.js +0 -1
- package/src/engine/graphics/micron/MICRON_URI_FIELD.js +0 -1
- package/src/engine/graphics/micron/build/MICRON_PATCH_SIZE_MAX.js +0 -5
- package/src/engine/graphics/micron/build/PatchRepresentation.js +0 -424
- package/src/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +0 -311
- package/src/engine/graphics/micron/build/build_geometry_info.js +0 -21
- package/src/engine/graphics/micron/build/clustering/assignInitialPatchNeighbours.js +0 -63
- package/src/engine/graphics/micron/build/clustering/assign_patch_neighbours_from_topology.js +0 -46
- package/src/engine/graphics/micron/build/clustering/build_clustering_2.js +0 -37
- package/src/engine/graphics/micron/build/clustering/build_leaf_patches.js +0 -326
- package/src/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +0 -76
- package/src/engine/graphics/micron/build/clustering/computeBorderLengthChange.js +0 -59
- package/src/engine/graphics/micron/build/clustering/computeFaceCurvatureScore.js +0 -57
- package/src/engine/graphics/micron/build/clustering/computeOpenFaceFreedom.js +0 -35
- package/src/engine/graphics/micron/build/clustering/populateOpenFaceNeighboursForPatch.js +0 -56
- package/src/engine/graphics/micron/build/clustering/validate_leaf_patch_connectivity.js +0 -44
- package/src/engine/graphics/micron/build/compute_micron_buffer_array_constructor.js +0 -24
- package/src/engine/graphics/micron/build/compute_vertex_remap_cost.js +0 -29
- package/src/engine/graphics/micron/build/debug/build_clustering_info.js +0 -58
- package/src/engine/graphics/micron/build/debug/build_graph_info.js +0 -59
- package/src/engine/graphics/micron/build/fill_patch_geometry_data.js +0 -270
- package/src/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +0 -196
- package/src/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -162
- package/src/engine/graphics/micron/build/hierarchy/build_merge_graph.js +0 -89
- package/src/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +0 -146
- package/src/engine/graphics/micron/build/hierarchy/compute_patches_shared_vertex_count.js +0 -32
- package/src/engine/graphics/micron/build/hierarchy/compute_patches_shared_vertices.js +0 -34
- package/src/engine/graphics/micron/build/hierarchy/merge_patches.js +0 -581
- package/src/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +0 -53
- package/src/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +0 -515
- package/src/engine/graphics/micron/build/hierarchy/patch_combine.js +0 -180
- package/src/engine/graphics/micron/build/hierarchy/patch_fill_holes_by_uncollapse.js +0 -60
- package/src/engine/graphics/micron/build/hierarchy/patch_stitch_parent_border.js +0 -320
- package/src/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +0 -547
- package/src/engine/graphics/micron/build/hierarchy/qvdr_build_tree.js +0 -140
- package/src/engine/graphics/micron/buildPatchwork.js +0 -68
- package/src/engine/graphics/micron/convert_three_object_to_micron.js +0 -179
- package/src/engine/graphics/micron/debug/VirtualGeometryStats.js +0 -42
- package/src/engine/graphics/micron/format/MICRON_GEOMETRY_PROPERTY_NAME.js +0 -1
- package/src/engine/graphics/micron/format/MicronGeometry.d.ts +0 -21
- package/src/engine/graphics/micron/format/MicronGeometry.js +0 -334
- package/src/engine/graphics/micron/format/MicronGeometryPatch.d.ts +0 -3
- package/src/engine/graphics/micron/format/MicronGeometryPatch.js +0 -205
- package/src/engine/graphics/micron/format/MicronGeometryPatchOccurance.js +0 -50
- package/src/engine/graphics/micron/format/ThreeMicronMesh.d.ts +0 -10
- package/src/engine/graphics/micron/format/ThreeMicronMesh.js +0 -45
- package/src/engine/graphics/micron/format/VirtualGeometry.js +0 -158
- package/src/engine/graphics/micron/format/micron_build_proxy_geometry.js +0 -205
- package/src/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +0 -123
- package/src/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.spec.js +0 -63
- package/src/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.js +0 -83
- package/src/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.spec.js +0 -51
- package/src/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +0 -25
- package/src/engine/graphics/micron/format/serialization/deserialize_patch.js +0 -106
- package/src/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +0 -18
- package/src/engine/graphics/micron/format/serialization/serialize_patch.js +0 -84
- package/src/engine/graphics/micron/format/validate_patch_bounds.js +0 -69
- package/src/engine/graphics/micron/plugin/GLTFAssetTransformer.js +0 -265
- package/src/engine/graphics/micron/plugin/GLTF_MICRON_ID_FIELD.js +0 -5
- package/src/engine/graphics/micron/plugin/MicronRenderPlugin.d.ts +0 -8
- package/src/engine/graphics/micron/plugin/MicronRenderPlugin.js +0 -150
- package/src/engine/graphics/micron/plugin/serialization/BufferGeometrySerializationAdapter.js +0 -176
- package/src/engine/graphics/micron/plugin/shaded_geometry/MicronShadedGeometryRenderAdapter.js +0 -216
- package/src/engine/graphics/micron/prototypeMicronProxyBuild.js +0 -227
- package/src/engine/graphics/micron/prototypeVirtualGeometry.js +0 -911
- package/src/engine/graphics/micron/render/PatchCacheKey.js +0 -79
- package/src/engine/graphics/micron/render/VIRTUAL_MESH_FLAG.d.ts +0 -1
- package/src/engine/graphics/micron/render/VIRTUAL_MESH_FLAG.js +0 -1
- package/src/engine/graphics/micron/render/VirtualGeometryBuilder.js +0 -207
- package/src/engine/graphics/micron/render/approximateTriangleArea.js +0 -25
- package/src/engine/graphics/micron/render/culling/PatchCullingSystem.js +0 -129
- package/src/engine/graphics/micron/render/instanced/PatchDataTextures.js +0 -329
- package/src/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +0 -175
- package/src/engine/graphics/micron/render/instanced/shader/constants.js +0 -3
- package/src/engine/graphics/micron/render/instanced/shader/gen_micron_vertex_attribute_texture_name.js +0 -8
- package/src/engine/graphics/micron/render/instanced/shader/shader_rewrite_standard.js +0 -250
- package/src/engine/graphics/micron/render/makeThreeMeshFromVirtualGeometry.js +0 -37
- package/src/engine/graphics/micron/render/refinement/ActivePatchFlags.js +0 -8
- package/src/engine/graphics/micron/render/refinement/ActivePatchList.js +0 -241
- package/src/engine/graphics/micron/render/refinement/ActivePatchRecord.js +0 -154
- package/src/engine/graphics/micron/render/refinement/RefinementSpec.js +0 -84
- package/src/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +0 -133
- package/src/engine/graphics/micron/render/refinement/is_patch_facing_back.js +0 -43
- package/src/engine/graphics/micron/render/refinement/is_patch_visible.js +0 -37
- package/src/engine/graphics/micron/render/v1/MaterialContext.js +0 -150
- package/src/engine/graphics/micron/render/v1/MaterialVertexSpec.js +0 -115
- package/src/engine/graphics/micron/render/v1/MicronRenderContext.js +0 -145
- package/src/engine/graphics/micron/render/v1/ThreeVirtualGeometryAdapter.js +0 -255
- package/src/engine/graphics/micron/render/v1/VGThreeRenderer.js +0 -142
- package/src/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +0 -54
- package/src/engine/graphics/micron/simplifyGeometry.js +0 -26
- package/src/engine/graphics/micron/util/patchToBufferGeometry.js +0 -19
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import { TopoMesh } from "../../../../core/geom/3d/topology/struct/TopoMesh.js";
|
|
2
|
-
import { PatchRepresentation } from "./PatchRepresentation.js";
|
|
3
|
-
import { MicronGeometry } from "../format/MicronGeometry.js";
|
|
4
|
-
import { buildAbstractPatchHierarchy } from "./hierarchy/buildAbstractPatchHierarchy.js";
|
|
5
|
-
import { AttributeSpec } from "../../geometry/AttributeSpec.js";
|
|
6
|
-
import { typedArrayToDataType } from "../../../../core/collection/array/typedArrayToDataType.js";
|
|
7
|
-
import { BinaryDataType } from "../../../../core/binary/type/BinaryDataType.js";
|
|
8
|
-
import { MicronGeometryPatch } from "../format/MicronGeometryPatch.js";
|
|
9
|
-
import { build_clustering_info } from "./debug/build_clustering_info.js";
|
|
10
|
-
import { build_graph_info } from "./debug/build_graph_info.js";
|
|
11
|
-
import { build_geometry_info } from "./build_geometry_info.js";
|
|
12
|
-
import { build_leaf_patches_metis } from "./clustering/build_leaf_patches_metis.js";
|
|
13
|
-
import { compute_buffer_geometry_byte_size } from "../../geometry/buffered/compute_buffer_geometry_byte_size.js";
|
|
14
|
-
import { deinterleaveBufferGeometry } from "../../geometry/buffered/deinterleaveBufferGeometry.js";
|
|
15
|
-
import { update_topo_face_normals } from "../../../../core/geom/3d/topology/update_topo_face_normals.js";
|
|
16
|
-
import { mergeVertices } from "three/examples/jsm/utils/BufferGeometryUtils.js";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Returns current time in milliseconds
|
|
20
|
-
* Wrapper to ensure support of both web as well as node.js
|
|
21
|
-
* @return {number}
|
|
22
|
-
*/
|
|
23
|
-
function current_time_millis() {
|
|
24
|
-
if (typeof performance !== 'undefined') {
|
|
25
|
-
return performance.now();
|
|
26
|
-
} else {
|
|
27
|
-
return Date.now();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @param {AttributeSpec} spec
|
|
34
|
-
* @param {THREE.BufferAttribute} source
|
|
35
|
-
*/
|
|
36
|
-
function custom_attribute_format_normal(spec, source) {
|
|
37
|
-
// compress normals
|
|
38
|
-
spec.normalized = true;
|
|
39
|
-
spec.type = BinaryDataType.Int8;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
* @param {AttributeSpec} spec
|
|
45
|
-
* @param {THREE.BufferAttribute} source
|
|
46
|
-
*/
|
|
47
|
-
function custom_attribute_format_uv(spec, source) {
|
|
48
|
-
// TODO make sure we only do this when source actually fits in half-float
|
|
49
|
-
spec.type = BinaryDataType.Float16;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
* @param {AttributeSpec} spec
|
|
55
|
-
* @param {THREE.BufferAttribute} source
|
|
56
|
-
*/
|
|
57
|
-
function custom_attribute_format_color(spec, source) {
|
|
58
|
-
// crush color data to 8 bit
|
|
59
|
-
spec.type = BinaryDataType.Uint8;
|
|
60
|
-
spec.normalized = true;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
* @param {AttributeSpec} spec
|
|
66
|
-
* @param {THREE.BufferAttribute} source
|
|
67
|
-
* @param {string} name
|
|
68
|
-
*/
|
|
69
|
-
function format_attribute(spec, source, name) {
|
|
70
|
-
|
|
71
|
-
spec.name = name;
|
|
72
|
-
|
|
73
|
-
switch (name) {
|
|
74
|
-
case 'uv':
|
|
75
|
-
case 'uv2':
|
|
76
|
-
custom_attribute_format_uv(spec, source);
|
|
77
|
-
break;
|
|
78
|
-
case 'tangent':
|
|
79
|
-
case 'normal':
|
|
80
|
-
custom_attribute_format_normal(spec, source);
|
|
81
|
-
break;
|
|
82
|
-
case 'color':
|
|
83
|
-
custom_attribute_format_color(spec, source);
|
|
84
|
-
break;
|
|
85
|
-
default:
|
|
86
|
-
spec.normalized = source.normalized;
|
|
87
|
-
spec.type = typedArrayToDataType(source.array)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
spec.itemSize = source.itemSize;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
* @param {THREE.BufferGeometry} buffer_geometry
|
|
96
|
-
* @returns {AttributeSpec[]}
|
|
97
|
-
*/
|
|
98
|
-
function attributes_from_buffer_geometry(buffer_geometry) {
|
|
99
|
-
const result = [];
|
|
100
|
-
|
|
101
|
-
const source_attributes = buffer_geometry.attributes;
|
|
102
|
-
for (const attributesKey in source_attributes) {
|
|
103
|
-
const source_attribute = source_attributes[attributesKey];
|
|
104
|
-
const spec = new AttributeSpec();
|
|
105
|
-
|
|
106
|
-
format_attribute(spec, source_attribute, attributesKey);
|
|
107
|
-
|
|
108
|
-
result.push(spec);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// to ensure that input order of attributes does not matter, we sort the attributes by name
|
|
112
|
-
result.sort(AttributeSpec.byName);
|
|
113
|
-
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const PRINT_VERBOSE_STATS = false;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
*
|
|
121
|
-
* @param {THREE.BufferGeometry} input
|
|
122
|
-
* @returns {Promise<MicronGeometry>}
|
|
123
|
-
*/
|
|
124
|
-
export async function buildMicronGeometryFromBufferGeometry(input) {
|
|
125
|
-
let source_geometry = deinterleaveBufferGeometry(input);
|
|
126
|
-
|
|
127
|
-
// merge vertices to create better connectivity
|
|
128
|
-
source_geometry = mergeVertices(source_geometry);
|
|
129
|
-
|
|
130
|
-
// build topology representation
|
|
131
|
-
const topoMesh = new TopoMesh();
|
|
132
|
-
|
|
133
|
-
const position_attribute = source_geometry.getAttribute("position");
|
|
134
|
-
const index_attribute = source_geometry.index;
|
|
135
|
-
|
|
136
|
-
const face_index_array = index_attribute.array;
|
|
137
|
-
const vertex_position_array = position_attribute.array;
|
|
138
|
-
|
|
139
|
-
topoMesh.build(vertex_position_array, face_index_array);
|
|
140
|
-
|
|
141
|
-
// compute aabb
|
|
142
|
-
// const geometry_aabb = new AABB3();
|
|
143
|
-
// aabb3_from_v3_array(geometry_aabb, vertex_position_array, vertex_position_array.length);
|
|
144
|
-
|
|
145
|
-
// weld_duplicate_vertices(topoMesh, geometry_aabb);
|
|
146
|
-
|
|
147
|
-
// debugValidateMesh(topoMesh);
|
|
148
|
-
|
|
149
|
-
// expandConnectivityByLocality(topoMesh, geometry_aabb);
|
|
150
|
-
// collapse_all_degenerate_edges(topoMesh.getEdges(), topoMesh);
|
|
151
|
-
|
|
152
|
-
// ensure faces have normals for mesh simplification
|
|
153
|
-
update_topo_face_normals(Array.from(topoMesh.getFaces()), topoMesh.getFaces().size);
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Used to generate neighbourhood assignment
|
|
157
|
-
* @type {Map<number, PatchRepresentation>}
|
|
158
|
-
*/
|
|
159
|
-
const face_to_patch_map = new Map();
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Used to generate neighbourhood assignment
|
|
164
|
-
* @type {Map<number, PatchRepresentation[]>}
|
|
165
|
-
*/
|
|
166
|
-
const vertex_to_patch_map = new Map();
|
|
167
|
-
|
|
168
|
-
// TODO drop patches with 0 volume (degenerate triangles)
|
|
169
|
-
|
|
170
|
-
const t_build_leaf_patches_start = current_time_millis();
|
|
171
|
-
|
|
172
|
-
const patches = await build_leaf_patches_metis(
|
|
173
|
-
topoMesh,
|
|
174
|
-
face_index_array,
|
|
175
|
-
vertex_position_array,
|
|
176
|
-
face_to_patch_map,
|
|
177
|
-
vertex_to_patch_map
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
if (PRINT_VERBOSE_STATS) {
|
|
181
|
-
console.log(`build leaf patches: ${(current_time_millis() - t_build_leaf_patches_start)}ms`);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
console.log(build_clustering_info(patches));
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// verify total poly count
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
// determine patch neighbours by checking common edges
|
|
191
|
-
// console.time('assign initial neighbours');
|
|
192
|
-
// assignInitialPatchNeighbours(patches, face_to_patch_map);
|
|
193
|
-
// console.timeEnd('assign initial neighbours');
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const t_build_hierarchy_start = current_time_millis();
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
*
|
|
200
|
-
* @type {PatchRepresentation}
|
|
201
|
-
*/
|
|
202
|
-
const root = await buildAbstractPatchHierarchy(patches);
|
|
203
|
-
|
|
204
|
-
if (PRINT_VERBOSE_STATS) {
|
|
205
|
-
console.log(`build hierarchy: ${(current_time_millis() - t_build_hierarchy_start)}ms`);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// console.profile('simplification');
|
|
209
|
-
// console.time('simplification');
|
|
210
|
-
// build_simplified_clusters(root, topoMesh);
|
|
211
|
-
// console.timeEnd('simplification');
|
|
212
|
-
// console.profileEnd('simplification');
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
// compute number of patches over the triangle limit
|
|
216
|
-
|
|
217
|
-
// assign IDs to the patches
|
|
218
|
-
assign_ids_to_hierarchy(root);
|
|
219
|
-
|
|
220
|
-
if (PRINT_VERBOSE_STATS) {
|
|
221
|
-
console.log(build_graph_info(root));
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const r = new MicronGeometry();
|
|
225
|
-
|
|
226
|
-
r.proxy = source_geometry; // TODO use r.buildProxy(1) instead
|
|
227
|
-
|
|
228
|
-
r.source_triangle_count = index_attribute.count / 3;
|
|
229
|
-
r.source_vertex_count = source_geometry.getAttribute('position').count;
|
|
230
|
-
r.source_byte_size = compute_buffer_geometry_byte_size(source_geometry);
|
|
231
|
-
|
|
232
|
-
// console.time('build geometry');
|
|
233
|
-
|
|
234
|
-
const vertex_attributes = attributes_from_buffer_geometry(source_geometry);
|
|
235
|
-
|
|
236
|
-
r.vertex_spec.setAttributes(vertex_attributes);
|
|
237
|
-
r.root = compilePatchGraph(root, source_geometry, r.vertex_spec);
|
|
238
|
-
|
|
239
|
-
r.initialize();
|
|
240
|
-
|
|
241
|
-
// console.timeEnd('build geometry');
|
|
242
|
-
|
|
243
|
-
if (PRINT_VERBOSE_STATS) {
|
|
244
|
-
console.log(build_geometry_info(r));
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// assign dependencies
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return r;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
*
|
|
255
|
-
* @param {PatchRepresentation} node
|
|
256
|
-
* @param {THREE.BufferGeometry} geometry
|
|
257
|
-
* @param {VertexDataSpec} vertex_spec
|
|
258
|
-
* @returns {MicronGeometryPatch}
|
|
259
|
-
*/
|
|
260
|
-
function compilePatchGraph(node, geometry, vertex_spec) {
|
|
261
|
-
// map nodes
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
*
|
|
265
|
-
* @type {Map<number, PatchRepresentation>}
|
|
266
|
-
*/
|
|
267
|
-
const id_to_rep_map = new Map();
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
*
|
|
271
|
-
* @type {Map<number, MicronGeometryPatch>}
|
|
272
|
-
*/
|
|
273
|
-
const id_to_concrete_map = new Map();
|
|
274
|
-
|
|
275
|
-
node.traverse(patch => {
|
|
276
|
-
const patch_id = patch.id;
|
|
277
|
-
|
|
278
|
-
id_to_rep_map.set(patch_id, patch);
|
|
279
|
-
|
|
280
|
-
const concrete = new MicronGeometryPatch();
|
|
281
|
-
|
|
282
|
-
patch.buildMicronGeometryPatch(concrete, geometry, vertex_spec);
|
|
283
|
-
|
|
284
|
-
id_to_concrete_map.set(patch_id, concrete);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
// assemble graph structure
|
|
288
|
-
for (const id of id_to_rep_map.keys()) {
|
|
289
|
-
const concrete = id_to_concrete_map.get(id);
|
|
290
|
-
const rep = id_to_rep_map.get(id);
|
|
291
|
-
|
|
292
|
-
concrete.children = rep.children.map(c => id_to_concrete_map.get(c.id));
|
|
293
|
-
concrete.parents = rep.parents.map(c => id_to_concrete_map.get(c.id));
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return id_to_concrete_map.get(node.id);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
*
|
|
301
|
-
* @param {PatchRepresentation} root
|
|
302
|
-
*/
|
|
303
|
-
function assign_ids_to_hierarchy(root) {
|
|
304
|
-
let patch_id_counter = 0;
|
|
305
|
-
|
|
306
|
-
root.traverse(p => {
|
|
307
|
-
|
|
308
|
-
p.id = patch_id_counter++
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { prettyPrint } from "../../../../core/NumberFormat.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {MicronGeometry} g
|
|
6
|
-
* @return {string}
|
|
7
|
-
*/
|
|
8
|
-
export function build_geometry_info(g) {
|
|
9
|
-
const micron_byte_size = g.computeByteSize();
|
|
10
|
-
const micron_vertex_count = g.__patches.reduce((acc,p)=>acc+p.vertex_count,0);
|
|
11
|
-
const micron_triangle_count = g.__patches.reduce((acc,p)=>acc+p.polygon_count,0);
|
|
12
|
-
|
|
13
|
-
return `Geometry Stats:
|
|
14
|
-
Source Byte Size: ${prettyPrint(g.source_byte_size)}
|
|
15
|
-
Source Bits Per Triangle: ${prettyPrint(g.source_byte_size/g.source_triangle_count)}
|
|
16
|
-
Source Bits Per Vertex: ${prettyPrint(g.source_byte_size/g.source_vertex_count)}
|
|
17
|
-
|
|
18
|
-
Micron Byte Size: ${prettyPrint(micron_byte_size)} (${(micron_byte_size * 100 / g.source_byte_size).toPrecision(3)}% of source)
|
|
19
|
-
Micron Bits Per Triangle: ${prettyPrint(micron_byte_size/micron_triangle_count)}
|
|
20
|
-
Micron Bits Per Vertex: ${prettyPrint(micron_byte_size/micron_vertex_count)}`;
|
|
21
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { array_push_if_unique } from "../../../../../core/collection/array/array_push_if_unique.js";
|
|
2
|
-
import { BitSet } from "../../../../../core/binary/BitSet.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* TODO: consider tracking neighbours in the patch construction loop, to avoid these super-nested loops
|
|
6
|
-
* NOTE: assumes that all patches reference common topology, that is they reference same instances of edges, faces and vertices
|
|
7
|
-
* @param {PatchRepresentation[]} patches
|
|
8
|
-
* @param {Map<number,PatchRepresentation>} face_to_patch_map
|
|
9
|
-
*/
|
|
10
|
-
export function assignInitialPatchNeighbours(patches, face_to_patch_map) {
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @type {BitSet}
|
|
15
|
-
*/
|
|
16
|
-
const closed_vertices = new BitSet();
|
|
17
|
-
|
|
18
|
-
const patch_count = patches.length;
|
|
19
|
-
for (let i = 0; i < patch_count; i++) {
|
|
20
|
-
const patch = patches[i];
|
|
21
|
-
|
|
22
|
-
const mesh = patch.topology_snapshot;
|
|
23
|
-
|
|
24
|
-
const patch_vertices = mesh.vertices;
|
|
25
|
-
const patch_vertex_count = patch_vertices.length;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (let j = 0; j < patch_vertex_count; j++) {
|
|
29
|
-
const patch_vertex = patch_vertices[j];
|
|
30
|
-
|
|
31
|
-
const vertex_index = patch_vertex.index;
|
|
32
|
-
|
|
33
|
-
if (closed_vertices.get(vertex_index)) {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
closed_vertices.set(vertex_index, true);
|
|
38
|
-
|
|
39
|
-
const vertex_faces = patch_vertex.faces;
|
|
40
|
-
const vertex_face_count = vertex_faces.length;
|
|
41
|
-
|
|
42
|
-
for (let k = 0; k < vertex_face_count; k++) {
|
|
43
|
-
const face = vertex_faces[k];
|
|
44
|
-
|
|
45
|
-
const neighbour_patch = face_to_patch_map.get(face.index);
|
|
46
|
-
|
|
47
|
-
if (neighbour_patch === patch) {
|
|
48
|
-
// neighbour is within the origin patch
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// neighbouring face is in a different patch, record that
|
|
53
|
-
array_push_if_unique(patch.neighbours, neighbour_patch);
|
|
54
|
-
array_push_if_unique(neighbour_patch.neighbours, patch);
|
|
55
|
-
|
|
56
|
-
// record border vertex for both patches
|
|
57
|
-
patch.vertices_shared.add(vertex_index);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
package/src/engine/graphics/micron/build/clustering/assign_patch_neighbours_from_topology.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { array_push_if_unique } from "../../../../../core/collection/array/array_push_if_unique.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {PatchRepresentation[]} patches
|
|
6
|
-
*/
|
|
7
|
-
export function assign_patch_neighbours_from_topology(patches) {
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @type {Map<number, PatchRepresentation[]>}
|
|
11
|
-
*/
|
|
12
|
-
const vertex_to_patch_map = new Map();
|
|
13
|
-
|
|
14
|
-
const patch_count = patches.length;
|
|
15
|
-
for (let i = 0; i < patch_count; i++) {
|
|
16
|
-
const patch = patches[i];
|
|
17
|
-
|
|
18
|
-
const mesh = patch.topology_snapshot;
|
|
19
|
-
|
|
20
|
-
const vertices = mesh.vertices;
|
|
21
|
-
const vertex_count = vertices.length;
|
|
22
|
-
for (let j = 0; j < vertex_count; j++) {
|
|
23
|
-
const vertex = vertices[j];
|
|
24
|
-
|
|
25
|
-
const vertex_index = vertex.index;
|
|
26
|
-
|
|
27
|
-
const existing = vertex_to_patch_map.get(vertex_index);
|
|
28
|
-
|
|
29
|
-
if (existing === undefined) {
|
|
30
|
-
// not yet registered, most common expected case
|
|
31
|
-
vertex_to_patch_map.set(vertex_index, [patch]);
|
|
32
|
-
} else {
|
|
33
|
-
const existing_patches_count = existing.length;
|
|
34
|
-
for (let k = 0; k < existing_patches_count; k++) {
|
|
35
|
-
const neighbour_patch = existing[k];
|
|
36
|
-
|
|
37
|
-
// neighbouring face is in a different patch, record that
|
|
38
|
-
array_push_if_unique(patch.neighbours, neighbour_patch);
|
|
39
|
-
array_push_if_unique(neighbour_patch.neighbours, patch);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
existing.push(patch);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import FastBinaryHeap from "../../../../../core/collection/heap/FastBinaryHeap.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
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {TopoMesh} mesh
|
|
8
|
-
* @param {number} max_face_count faces per cluster
|
|
9
|
-
*/
|
|
10
|
-
export function build_clustering_2(mesh, max_face_count) {
|
|
11
|
-
// initialize all faces to individual clusters
|
|
12
|
-
const graph = build_face_graph_from_mesh(mesh);
|
|
13
|
-
|
|
14
|
-
// simplify graph by collapsing heaviest edges recursively
|
|
15
|
-
const open_set = new FastBinaryHeap(function (edge) {
|
|
16
|
-
return edge.weight;
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
// add all edges to the heap
|
|
20
|
-
const edges = graph.getEdges();
|
|
21
|
-
|
|
22
|
-
for (let edge of edges) {
|
|
23
|
-
open_set.push(edge);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
while (!open_set.isEmpty()) {
|
|
27
|
-
const edge = open_set.pop();
|
|
28
|
-
|
|
29
|
-
if (!mn_graph_collapse_weighted_edge(graph, edge, max_face_count, open_set)) {
|
|
30
|
-
// collapse was rejected, remove the edge from the graph
|
|
31
|
-
graph.removeEdge(edge);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// graph is partitioned at this point
|
|
36
|
-
console.warn(graph);
|
|
37
|
-
}
|