topotopo 0.3.0 → 0.5.0
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/NOTICE +40 -10
- package/README.md +475 -111
- package/dist/cli.js +328 -133
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/analysis.d.ts +5 -1
- package/dist/core/analysis.js +8 -3
- package/dist/core/bake.d.ts +16 -8
- package/dist/core/bake.js +165 -29
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +238 -97
- package/dist/core/decimate.d.ts +65 -0
- package/dist/core/decimate.js +409 -3
- package/dist/core/erosion.d.ts +37 -0
- package/dist/core/erosion.js +41 -1
- package/dist/core/geometry.d.ts +5 -1
- package/dist/core/geometry.js +204 -4
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/imageops.d.ts +6 -0
- package/dist/core/imageops.js +51 -0
- package/dist/core/intrinsics.d.ts +7 -0
- package/dist/core/intrinsics.js +94 -0
- package/dist/core/manifold.d.ts +12 -1
- package/dist/core/manifold.js +78 -6
- package/dist/core/materials.d.ts +11 -0
- package/dist/core/materials.js +56 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/packed.js +11 -0
- package/dist/core/particles.d.ts +1 -1
- package/dist/core/particles.js +1 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/rbd.js +13 -1
- package/dist/core/repair.d.ts +2 -0
- package/dist/core/repair.js +2 -0
- package/dist/core/report.d.ts +70 -0
- package/dist/core/report.js +275 -0
- package/dist/core/scatter.d.ts +1 -1
- package/dist/core/scatter.js +1 -1
- package/dist/core/scene.d.ts +20 -0
- package/dist/core/scene.js +72 -0
- package/dist/core/sha256.d.ts +4 -0
- package/dist/core/sha256.js +69 -0
- package/dist/core/shapes.d.ts +3 -0
- package/dist/core/shapes.js +34 -0
- package/dist/core/snippet-lib.d.ts +15 -2
- package/dist/core/snippet-lib.js +40 -14
- package/dist/core/solidify.d.ts +38 -0
- package/dist/core/solidify.js +356 -0
- package/dist/core/tangents.d.ts +54 -0
- package/dist/core/tangents.js +218 -0
- package/dist/core/texcoord.d.ts +4 -0
- package/dist/core/texcoord.js +14 -0
- package/dist/core/texnoise.d.ts +6 -1
- package/dist/core/texnoise.js +6 -2
- package/dist/core/texsdf.d.ts +131 -0
- package/dist/core/texsdf.js +637 -0
- package/dist/core/texture.d.ts +163 -9
- package/dist/core/texture.js +844 -20
- package/dist/core/topology.d.ts +32 -0
- package/dist/core/topology.js +238 -7
- package/dist/core/traceimage.d.ts +7 -0
- package/dist/core/traceimage.js +221 -0
- package/dist/core/tritri.d.ts +5 -0
- package/dist/core/tritri.js +120 -0
- package/dist/core/unwrap.d.ts +72 -0
- package/dist/core/unwrap.js +800 -0
- package/dist/core/usercode.d.ts +27 -0
- package/dist/core/usercode.js +87 -0
- package/dist/core/uv.d.ts +15 -16
- package/dist/core/uv.js +36 -189
- package/dist/core/uvislands.d.ts +62 -0
- package/dist/core/uvislands.js +574 -0
- package/dist/core/uvoverlap.d.ts +58 -0
- package/dist/core/uvoverlap.js +220 -0
- package/dist/core/uvpack.d.ts +64 -0
- package/dist/core/uvpack.js +628 -0
- package/dist/core/uvreport.d.ts +127 -0
- package/dist/core/uvreport.js +372 -0
- package/dist/core/wrangle.d.ts +6 -1
- package/dist/core/wrangle.js +27 -16
- package/dist/core/xatlas.d.ts +16 -1
- package/dist/core/xatlas.js +95 -61
- package/dist/engines.d.ts +63 -0
- package/dist/engines.js +180 -0
- package/dist/explain.d.ts +4 -3
- package/dist/explain.js +129 -12
- package/dist/graph/engine.d.ts +92 -29
- package/dist/graph/engine.js +298 -148
- package/dist/graph/expr.d.ts +6 -3
- package/dist/graph/expr.js +18 -8
- package/dist/graph/outputs.d.ts +23 -0
- package/dist/graph/outputs.js +41 -0
- package/dist/graph/packages.d.ts +72 -0
- package/dist/graph/packages.js +261 -0
- package/dist/graph/parallel.d.ts +3 -1
- package/dist/graph/parallel.js +4 -1
- package/dist/graph/params.d.ts +6 -0
- package/dist/graph/params.js +34 -7
- package/dist/graph/scope.d.ts +55 -0
- package/dist/graph/scope.js +14 -0
- package/dist/graph/types.d.ts +75 -12
- package/dist/graph/types.js +4 -2
- package/dist/graph/vars.d.ts +16 -0
- package/dist/graph/vars.js +80 -0
- package/dist/host/artifacts.d.ts +10 -1
- package/dist/host/artifacts.js +37 -6
- package/dist/host/cook.d.ts +241 -0
- package/dist/host/cook.js +844 -0
- package/dist/host/export-targets.d.ts +42 -5
- package/dist/host/export-targets.js +72 -13
- package/dist/host/godot-commands.d.ts +4 -0
- package/dist/host/godot-commands.js +21 -0
- package/dist/host/godot.d.ts +183 -0
- package/dist/host/godot.js +916 -0
- package/dist/host/node.d.ts +12 -7
- package/dist/host/node.js +27 -9
- package/dist/host/pool.js +51 -2
- package/dist/host/sidecars.d.ts +8 -0
- package/dist/host/sidecars.js +50 -0
- package/dist/host/types.d.ts +19 -6
- package/dist/host/version.d.ts +1 -0
- package/dist/host/version.js +3 -0
- package/dist/host/worker.js +5 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -2
- package/dist/inspect.d.ts +84 -1
- package/dist/inspect.js +271 -24
- package/dist/io/common.d.ts +33 -5
- package/dist/io/export.js +2 -1
- package/dist/io/files.d.ts +23 -4
- package/dist/io/files.js +60 -8
- package/dist/io/gltf.js +355 -51
- package/dist/io/heightmap.d.ts +3 -0
- package/dist/io/heightmap.js +1 -0
- package/dist/io/import.js +10 -0
- package/dist/io/inspect-scene.d.ts +55 -0
- package/dist/io/inspect-scene.js +155 -0
- package/dist/io/kinds.d.ts +81 -0
- package/dist/io/kinds.js +163 -0
- package/dist/io/points.d.ts +2 -1
- package/dist/io/points.js +3 -1
- package/dist/io/sidecars.d.ts +24 -0
- package/dist/io/sidecars.js +57 -0
- package/dist/io/source.d.ts +65 -0
- package/dist/io/source.js +112 -0
- package/dist/io/targets.d.ts +47 -3
- package/dist/io/targets.js +149 -14
- package/dist/io/textures.js +21 -1
- package/dist/io/unreal.js +5 -1
- package/dist/mcp/docs.d.ts +10 -1
- package/dist/mcp/docs.js +816 -119
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +70 -24
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +207 -108
- package/dist/mcp/verify.d.ts +2 -2
- package/dist/mcp/verify.js +1 -1
- package/dist/mcp/workspace.d.ts +15 -0
- package/dist/mcp/workspace.js +349 -0
- package/dist/nodes/attributes.js +198 -1
- package/dist/nodes/bake.js +207 -83
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +54 -5
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +22 -10
- package/dist/nodes/curves.js +440 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +13 -39
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.d.ts +1 -0
- package/dist/nodes/imageops.js +203 -0
- package/dist/nodes/index.d.ts +4 -0
- package/dist/nodes/index.js +4 -0
- package/dist/nodes/material.js +91 -23
- package/dist/nodes/measure.js +45 -18
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/rbd.js +1 -1
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.d.ts +1 -0
- package/dist/nodes/scene.js +55 -0
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/solidify.d.ts +1 -0
- package/dist/nodes/solidify.js +52 -0
- package/dist/nodes/splines.d.ts +15 -1
- package/dist/nodes/splines.js +112 -105
- package/dist/nodes/texture.d.ts +21 -6
- package/dist/nodes/texture.js +1318 -185
- package/dist/nodes/topology.d.ts +7 -0
- package/dist/nodes/topology.js +133 -6
- package/dist/nodes/transform.js +11 -3
- package/dist/nodes/util.d.ts +1 -1
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +6 -2
- package/dist/open.d.ts +19 -0
- package/dist/open.js +12 -0
- package/dist/package.d.ts +288 -0
- package/dist/package.js +772 -0
- package/dist/packages/check.d.ts +32 -0
- package/dist/packages/check.js +169 -0
- package/dist/packages/commands.d.ts +57 -0
- package/dist/packages/commands.js +537 -0
- package/dist/packages/registry.d.ts +796 -0
- package/dist/packages/registry.js +2998 -0
- package/dist/packages/update.d.ts +124 -0
- package/dist/packages/update.js +476 -0
- package/dist/render/options.d.ts +2 -0
- package/dist/render/options.js +44 -5
- package/dist/render/pbr.d.ts +28 -0
- package/dist/render/pbr.js +378 -0
- package/dist/render/preview.d.ts +69 -0
- package/dist/render/preview.js +26 -0
- package/dist/render/raster.d.ts +78 -7
- package/dist/render/raster.js +600 -145
- package/dist/render/texview.d.ts +7 -1
- package/dist/render/texview.js +34 -2
- package/dist/scan.d.ts +61 -0
- package/dist/scan.js +228 -0
- package/dist/session.d.ts +311 -0
- package/dist/session.js +849 -0
- package/dist/viewer/app/api.js +48 -6
- package/dist/viewer/app/camera.js +1 -1
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +100 -0
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +6 -2
- package/dist/viewer/app/guides.js +123 -1
- package/dist/viewer/app/keymap.js +7 -4
- package/dist/viewer/app/layers.js +5 -5
- package/dist/viewer/app/main.js +186 -53
- package/dist/viewer/app/markers.js +61 -1
- package/dist/viewer/app/outliner.js +72 -27
- package/dist/viewer/app/output-info.js +45 -0
- package/dist/viewer/app/outputs.css +147 -8
- package/dist/viewer/app/outputs.js +168 -54
- package/dist/viewer/app/packages.js +614 -0
- package/dist/viewer/app/props.js +177 -53
- package/dist/viewer/app/scene.js +35 -6
- package/dist/viewer/app/select.js +5 -4
- package/dist/viewer/app/selection.js +1 -1
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +66 -8
- package/dist/viewer/app/units.js +1 -1
- package/dist/viewer/app/vars.js +48 -1
- package/dist/viewer/app/welcome.js +72 -0
- package/dist/viewer/graph-file.d.ts +62 -0
- package/dist/viewer/graph-file.js +175 -0
- package/dist/viewer/index.html +24 -11
- package/dist/viewer/json-edit.d.ts +13 -0
- package/dist/viewer/json-edit.js +274 -0
- package/dist/viewer/outputs.d.ts +49 -5
- package/dist/viewer/outputs.js +264 -56
- package/dist/viewer/packages.d.ts +121 -0
- package/dist/viewer/packages.js +584 -0
- package/dist/viewer/server.d.ts +24 -7
- package/dist/viewer/server.js +289 -31
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/web/bake.d.ts +34 -0
- package/dist/web/bake.js +153 -0
- package/dist/web/folder-page.d.ts +101 -0
- package/dist/web/folder-page.js +146 -0
- package/dist/web/folders.d.ts +280 -0
- package/dist/web/folders.js +970 -0
- package/dist/web/library.d.ts +91 -0
- package/dist/web/library.js +228 -0
- package/dist/web/markdown.d.ts +45 -0
- package/dist/web/markdown.js +677 -0
- package/dist/web/pages.d.ts +258 -0
- package/dist/web/pages.js +301 -0
- package/dist/web/server.d.ts +24 -0
- package/dist/web/server.js +1068 -0
- package/dist/workspace.d.ts +88 -105
- package/dist/workspace.js +359 -375
- package/integrations/godot/addons/topotopo/LICENSE +202 -0
- package/integrations/godot/addons/topotopo/README.md +57 -0
- package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
- package/integrations/godot/addons/topotopo/dock.gd +266 -0
- package/integrations/godot/addons/topotopo/dock.tscn +72 -0
- package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
- package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
- package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
- package/integrations/godot/addons/topotopo/inspector.gd +38 -0
- package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
- package/integrations/godot/addons/topotopo/package.gd +23 -0
- package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
- package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
- package/integrations/godot/addons/topotopo/plugin.gd +970 -0
- package/integrations/godot/addons/topotopo/record.gd +435 -0
- package/integrations/godot/addons/topotopo/runner.gd +458 -0
- package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
- package/integrations/godot/addons/topotopo/watcher.gd +199 -0
- package/kernels/pkg/README.md +23 -29
- package/kernels/pkg-simd/README.md +23 -29
- package/library/architecture/versions/1.0/architecture.topo +12 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
- package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
- package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
- package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
- package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
- package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
- package/library/architecture/versions/1.0/version.json +1119 -0
- package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
- package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
- package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
- package/library/nature/versions/1.0/graphs/lineup.json +24 -0
- package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
- package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
- package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
- package/library/nature/versions/1.0/nature.topo +12 -0
- package/library/nature/versions/1.0/version.json +534 -0
- package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
- package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
- package/library/props/versions/1.0/graphs/lineup.json +18 -0
- package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
- package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
- package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
- package/library/props/versions/1.0/props.topo +12 -0
- package/library/props/versions/1.0/version.json +336 -0
- package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
- package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
- package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
- package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
- package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
- package/library/street/versions/1.0/graphs/lineup.json +22 -0
- package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
- package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
- package/library/street/versions/1.0/street.topo +12 -0
- package/library/street/versions/1.0/version.json +421 -0
- package/package.json +23 -8
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/shelf/index.json +0 -190
package/dist/core/rbd.js
CHANGED
|
@@ -26,6 +26,7 @@ import { expandPacked, flattenSource } from './packed.js';
|
|
|
26
26
|
import { heightfieldsOf, heightfieldToMesh } from './heightfield.js';
|
|
27
27
|
import { qFromMat, qMul, qNormalize } from './math.js';
|
|
28
28
|
import { rand } from './random.js';
|
|
29
|
+
import { TANGENT_ATTRIB } from './tangents.js';
|
|
29
30
|
export const RBD_SHAPES = ['convex_hull', 'box', 'sphere', 'mesh'];
|
|
30
31
|
export const RBD_PIECE_MODES = ['auto', 'connectivity', 'name', 'attrib'];
|
|
31
32
|
// ------------------------------------------------------------------ small math
|
|
@@ -564,7 +565,7 @@ export class RbdSim {
|
|
|
564
565
|
}
|
|
565
566
|
// bodies in a stable order: by input position (so permuting the input does not change the result); pieces at the
|
|
566
567
|
// same position (to 1e-6 m: rbd_stack's "every crate at the same spot") by a hash of what they are, so permuting
|
|
567
|
-
// coincident pieces of different shapes changes nothing either (
|
|
568
|
+
// coincident pieces of different shapes changes nothing either (ties went by input index). Pieces that
|
|
568
569
|
// tie on that too are interchangeable: same shape, pose and velocities, so the set of results is the same.
|
|
569
570
|
const order = pieces.map((_, i) => i);
|
|
570
571
|
const q6 = (x) => Math.round(x * 1e6);
|
|
@@ -1147,6 +1148,17 @@ function rotateVectors(t, pieceOf, dR, dQ, point) {
|
|
|
1147
1148
|
d[i * 3 + 2] = R[2] * x + R[5] * y + R[8] * z;
|
|
1148
1149
|
}
|
|
1149
1150
|
}
|
|
1151
|
+
else if (name === TANGENT_ATTRIB && a.size === 4) {
|
|
1152
|
+
for (let i = 0; i < t.count; i++) {
|
|
1153
|
+
const k = pieceOf(i);
|
|
1154
|
+
if (k < 0)
|
|
1155
|
+
continue;
|
|
1156
|
+
const R = dR.subarray(k * 9, k * 9 + 9), x = d[i * 4], y = d[i * 4 + 1], z = d[i * 4 + 2];
|
|
1157
|
+
d[i * 4] = R[0] * x + R[3] * y + R[6] * z;
|
|
1158
|
+
d[i * 4 + 1] = R[1] * x + R[4] * y + R[7] * z;
|
|
1159
|
+
d[i * 4 + 2] = R[2] * x + R[5] * y + R[8] * z;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1150
1162
|
else if (point && name === 'orient' && a.size === 4) {
|
|
1151
1163
|
for (let i = 0; i < t.count; i++) {
|
|
1152
1164
|
const k = pieceOf(i);
|
package/dist/core/repair.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface RepairOptions {
|
|
|
16
16
|
maxHoleEdges: number;
|
|
17
17
|
isolated: boolean;
|
|
18
18
|
selfIntersections: SelfIntersectMode;
|
|
19
|
+
/** faces below this area count as degenerate (default: rounding at the mesh's size) */
|
|
20
|
+
minArea?: number;
|
|
19
21
|
}
|
|
20
22
|
export interface RepairReport {
|
|
21
23
|
input: TopoSummary;
|
package/dist/core/repair.js
CHANGED
|
@@ -839,6 +839,8 @@ function segTri(T, a, b, o) {
|
|
|
839
839
|
/** Run the repair steps on g (see the header). */
|
|
840
840
|
export function repairMesh(g, o) {
|
|
841
841
|
const r = new Repair(g);
|
|
842
|
+
if (o.minArea && o.minArea > r.areaEps)
|
|
843
|
+
r.areaEps = o.minArea;
|
|
842
844
|
if (o.fuse !== 'off')
|
|
843
845
|
r.fuse(Math.max(0, o.tolerance), o.fuse);
|
|
844
846
|
if (o.degenerate)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Geometry } from './geometry.ts';
|
|
2
|
+
import type { Triangulation } from './topology.ts';
|
|
3
|
+
/** (x, y, z) in metres at millimetre precision. */
|
|
4
|
+
export declare function posText(p: ArrayLike<number>): string;
|
|
5
|
+
/** The centroid of a prim's points. */
|
|
6
|
+
export declare function primCentroid(g: Geometry, p: number): [number, number, number];
|
|
7
|
+
/** The prim's part: its "name" (prim string attribute), and up to three prim groups holding it. */
|
|
8
|
+
export declare function primPart(g: Geometry, p: number): {
|
|
9
|
+
name: string;
|
|
10
|
+
groups: string[];
|
|
11
|
+
};
|
|
12
|
+
/** The point's part: its point "name", else the name of a prim that uses it; up to three point groups. */
|
|
13
|
+
export declare function pointPart(g: Geometry, i: number, prim?: number): {
|
|
14
|
+
name: string;
|
|
15
|
+
groups: string[];
|
|
16
|
+
};
|
|
17
|
+
/** "prim 12 of "barrel" (groups front) at (x, y, z)": the prim's part and its centroid (or `at`, a point on it). */
|
|
18
|
+
export declare function primWhere(g: Geometry, p: number, at?: ArrayLike<number>): string;
|
|
19
|
+
/** "point 7 of "barrel" at (x, y, z)". */
|
|
20
|
+
export declare function pointWhere(g: Geometry, i: number, prim?: number): string;
|
|
21
|
+
/** "edge 3–7 of "barrel" (prim 12) at (midpoint)": the part of the prim that holds the edge. */
|
|
22
|
+
export declare function edgeWhere(g: Geometry, a: number, b: number, prim?: number): string;
|
|
23
|
+
/** The parts (names) a set of prims belongs to, most prims first: `"barrel" 12, "stock" 3`. */
|
|
24
|
+
export declare function partsOf(g: Geometry, prims: Iterable<number>, max?: number): string;
|
|
25
|
+
export interface SolidReport {
|
|
26
|
+
polys: number;
|
|
27
|
+
/** a closed solid as it is: every polygon edge shared by exactly two polygons */
|
|
28
|
+
closed: boolean;
|
|
29
|
+
/** boundary edges of polygons as the points are */
|
|
30
|
+
boundaryEdges: number;
|
|
31
|
+
/** boundary edges that pair with exactly one coincident boundary edge: vertex splits of uv / normal seams */
|
|
32
|
+
seamEdges: number;
|
|
33
|
+
/** boundary edges left after welding seam splits: real holes */
|
|
34
|
+
openEdges: number;
|
|
35
|
+
firstOpen: string | null;
|
|
36
|
+
/** edges shared by 3 or more polygons (after welding seam splits) */
|
|
37
|
+
nonManifoldEdges: number;
|
|
38
|
+
firstNonManifold: string | null;
|
|
39
|
+
/** edges between neighbouring polygons wound in opposite directions */
|
|
40
|
+
flippedEdges: number;
|
|
41
|
+
firstFlipped: string | null;
|
|
42
|
+
/** closed pieces (after welding) whose faces point inward (negative volume), cavity walls excepted */
|
|
43
|
+
inwardPieces: number;
|
|
44
|
+
firstInward: string | null;
|
|
45
|
+
/** polygons with fewer than 3 points or no area */
|
|
46
|
+
degenerate: number;
|
|
47
|
+
firstDegenerate: string | null;
|
|
48
|
+
/** a closed solid once the seam splits are welded */
|
|
49
|
+
closedAfterWeld: boolean;
|
|
50
|
+
/** connected pieces after welding seam splits */
|
|
51
|
+
pieces: number;
|
|
52
|
+
/** each prim's welded piece (-1 for empty prims), and whether that piece is a closed solid */
|
|
53
|
+
primPiece: Int32Array;
|
|
54
|
+
pieceClosed: Uint8Array;
|
|
55
|
+
}
|
|
56
|
+
export interface SolidReportOptions {
|
|
57
|
+
/** the triangulation, when the caller has it */
|
|
58
|
+
tri?: Triangulation;
|
|
59
|
+
/** look for winding flips (a half-edge structure; default true) */
|
|
60
|
+
flips?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** Whether the mesh is a closed solid, and why not (see the file comment). */
|
|
63
|
+
export declare function solidReport(g: Geometry, o?: SolidReportOptions): SolidReport;
|
|
64
|
+
/** "N open edges (after welding seam splits)", with the seam splits said when there are any. */
|
|
65
|
+
export declare function openEdgesText(r: SolidReport): string;
|
|
66
|
+
/**
|
|
67
|
+
* Why a mesh is not a closed solid, one line per cause with the count, where the first one is and the fix; [] when
|
|
68
|
+
* it is one (after welding seam splits).
|
|
69
|
+
*/
|
|
70
|
+
export declare function solidCauses(r: SolidReport): string[];
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { buildEdges, primArea, triangulate } from './topology.js';
|
|
2
|
+
import { halfEdges } from './halfedge.js';
|
|
3
|
+
/** (x, y, z) in metres at millimetre precision. */
|
|
4
|
+
export function posText(p) {
|
|
5
|
+
const f = (x) => (Number.isFinite(x) ? (Math.abs(x) < 5e-4 ? 0 : x).toFixed(3) : String(x));
|
|
6
|
+
return `(${f(p[0])}, ${f(p[1])}, ${f(p[2])})`;
|
|
7
|
+
}
|
|
8
|
+
/** The centroid of a prim's points. */
|
|
9
|
+
export function primCentroid(g, p) {
|
|
10
|
+
const s = g.primStart[p], e = g.primStart[p + 1], P = g.P;
|
|
11
|
+
let x = 0, y = 0, z = 0;
|
|
12
|
+
for (let v = s; v < e; v++) {
|
|
13
|
+
const i = g.vertexPoint[v] * 3;
|
|
14
|
+
x += P[i];
|
|
15
|
+
y += P[i + 1];
|
|
16
|
+
z += P[i + 2];
|
|
17
|
+
}
|
|
18
|
+
const n = Math.max(1, e - s);
|
|
19
|
+
return [x / n, y / n, z / n];
|
|
20
|
+
}
|
|
21
|
+
/** The prim's part: its "name" (prim string attribute), and up to three prim groups holding it. */
|
|
22
|
+
export function primPart(g, p) {
|
|
23
|
+
const na = g.prims.get('name');
|
|
24
|
+
const name = na && na.type === 'string' ? String(na.get(p) ?? '') : '';
|
|
25
|
+
const groups = [];
|
|
26
|
+
for (const [k, m] of g.primGroups) {
|
|
27
|
+
if (m[p])
|
|
28
|
+
groups.push(k);
|
|
29
|
+
if (groups.length >= 3)
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
return { name, groups };
|
|
33
|
+
}
|
|
34
|
+
/** The point's part: its point "name", else the name of a prim that uses it; up to three point groups. */
|
|
35
|
+
export function pointPart(g, i, prim = -1) {
|
|
36
|
+
const pa = g.points.get('name');
|
|
37
|
+
let name = pa && pa.type === 'string' ? String(pa.get(i) ?? '') : '';
|
|
38
|
+
if (!name && prim >= 0)
|
|
39
|
+
name = primPart(g, prim).name;
|
|
40
|
+
const groups = [];
|
|
41
|
+
for (const [k, m] of g.pointGroups) {
|
|
42
|
+
if (m[i])
|
|
43
|
+
groups.push(k);
|
|
44
|
+
if (groups.length >= 3)
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return { name, groups };
|
|
48
|
+
}
|
|
49
|
+
const partText = (pt) => `${pt.name ? ` of "${pt.name}"` : ''}${pt.groups.length ? ` (group${pt.groups.length > 1 ? 's' : ''} ${pt.groups.join(', ')})` : ''}`;
|
|
50
|
+
/** "prim 12 of "barrel" (groups front) at (x, y, z)": the prim's part and its centroid (or `at`, a point on it). */
|
|
51
|
+
export function primWhere(g, p, at) {
|
|
52
|
+
return `prim ${p}${partText(primPart(g, p))} at ${posText(at ?? primCentroid(g, p))}`;
|
|
53
|
+
}
|
|
54
|
+
/** "point 7 of "barrel" at (x, y, z)". */
|
|
55
|
+
export function pointWhere(g, i, prim = -1) {
|
|
56
|
+
return `point ${i}${partText(pointPart(g, i, prim))} at ${posText([g.P[i * 3], g.P[i * 3 + 1], g.P[i * 3 + 2]])}`;
|
|
57
|
+
}
|
|
58
|
+
/** "edge 3–7 of "barrel" (prim 12) at (midpoint)": the part of the prim that holds the edge. */
|
|
59
|
+
export function edgeWhere(g, a, b, prim = -1) {
|
|
60
|
+
const P = g.P, m = [(P[a * 3] + P[b * 3]) / 2, (P[a * 3 + 1] + P[b * 3 + 1]) / 2, (P[a * 3 + 2] + P[b * 3 + 2]) / 2];
|
|
61
|
+
const pt = prim >= 0 ? primPart(g, prim) : { name: '', groups: [] };
|
|
62
|
+
return `edge ${a}–${b}${partText(pt)}${prim >= 0 ? ` (prim ${prim})` : ''} at ${posText(m)}`;
|
|
63
|
+
}
|
|
64
|
+
/** The parts (names) a set of prims belongs to, most prims first: `"barrel" 12, "stock" 3`. */
|
|
65
|
+
export function partsOf(g, prims, max = 4) {
|
|
66
|
+
const na = g.prims.get('name');
|
|
67
|
+
if (!na || na.type !== 'string')
|
|
68
|
+
return '';
|
|
69
|
+
const by = new Map();
|
|
70
|
+
for (const p of prims) {
|
|
71
|
+
const k = String(na.get(p) ?? '');
|
|
72
|
+
by.set(k, (by.get(k) ?? 0) + 1);
|
|
73
|
+
}
|
|
74
|
+
const list = [...by].sort((x, y) => y[1] - x[1]);
|
|
75
|
+
return list.slice(0, max).map(([k, n]) => `"${k}" ${n}`).join(', ') + (list.length > max ? `, … ${list.length - max} more` : '');
|
|
76
|
+
}
|
|
77
|
+
/** Whether the mesh is a closed solid, and why not (see the file comment). */
|
|
78
|
+
export function solidReport(g, o = {}) {
|
|
79
|
+
const E = buildEdges(g), P = g.P, np = g.numPoints;
|
|
80
|
+
let polys = 0, degenerate = 0, firstDeg = -1;
|
|
81
|
+
for (let p = 0; p < g.numPrims; p++) {
|
|
82
|
+
if (!g.primClosed[p] || g.isPacked(p) || g.isSpline(p))
|
|
83
|
+
continue;
|
|
84
|
+
polys++;
|
|
85
|
+
if (g.primSize(p) < 3 || primArea(g, p) < 1e-14) {
|
|
86
|
+
degenerate++;
|
|
87
|
+
if (firstDeg < 0)
|
|
88
|
+
firstDeg = p;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// canonical point per position among the points of boundary edges (a seam split always leaves its coincident
|
|
92
|
+
// copies on boundary edges; points elsewhere stay themselves)
|
|
93
|
+
const b = g.bbox();
|
|
94
|
+
const diag = Math.hypot(b.max[0] - b.min[0], b.max[1] - b.min[1], b.max[2] - b.min[2]) || 1;
|
|
95
|
+
const q = diag * 1e-7, canon = Int32Array.from({ length: np }, (_, i) => i), byPos = new Map();
|
|
96
|
+
const onBoundary = new Uint8Array(np);
|
|
97
|
+
for (let e = 0; e < E.a.length; e++)
|
|
98
|
+
if (E.count[e] === 1 && g.primClosed[E.firstPrim[e]]) {
|
|
99
|
+
onBoundary[E.a[e]] = 1;
|
|
100
|
+
onBoundary[E.b[e]] = 1;
|
|
101
|
+
}
|
|
102
|
+
for (let i = 0; i < np; i++) {
|
|
103
|
+
if (!onBoundary[i])
|
|
104
|
+
continue;
|
|
105
|
+
const k = `${Math.round(P[i * 3] / q)},${Math.round(P[i * 3 + 1] / q)},${Math.round(P[i * 3 + 2] / q)}`;
|
|
106
|
+
const c = byPos.get(k);
|
|
107
|
+
if (c === undefined)
|
|
108
|
+
byPos.set(k, i);
|
|
109
|
+
else
|
|
110
|
+
canon[i] = c;
|
|
111
|
+
}
|
|
112
|
+
// boundary edges of polygons, grouped by their welded end points
|
|
113
|
+
let boundary = 0, rawNonManifold = 0, firstNM = -1;
|
|
114
|
+
const groups = new Map();
|
|
115
|
+
for (let e = 0; e < E.a.length; e++) {
|
|
116
|
+
if (!g.primClosed[E.firstPrim[e]])
|
|
117
|
+
continue;
|
|
118
|
+
if (E.count[e] > 2) {
|
|
119
|
+
rawNonManifold++;
|
|
120
|
+
if (firstNM < 0)
|
|
121
|
+
firstNM = e;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (E.count[e] !== 1)
|
|
125
|
+
continue;
|
|
126
|
+
boundary++;
|
|
127
|
+
const ca = canon[E.a[e]], cb = canon[E.b[e]];
|
|
128
|
+
if (ca === cb)
|
|
129
|
+
continue;
|
|
130
|
+
const k = ca < cb ? `${ca},${cb}` : `${cb},${ca}`;
|
|
131
|
+
let l = groups.get(k);
|
|
132
|
+
if (!l)
|
|
133
|
+
groups.set(k, (l = []));
|
|
134
|
+
l.push(e);
|
|
135
|
+
}
|
|
136
|
+
let seam = 0, open = 0, firstOpen = -1, nonManifold = rawNonManifold;
|
|
137
|
+
for (const l of groups.values()) {
|
|
138
|
+
if (l.length === 2)
|
|
139
|
+
seam += 2;
|
|
140
|
+
else if (l.length === 1) {
|
|
141
|
+
open++;
|
|
142
|
+
if (firstOpen < 0 || l[0] < firstOpen)
|
|
143
|
+
firstOpen = l[0];
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
nonManifold += 1;
|
|
147
|
+
if (firstNM < 0)
|
|
148
|
+
firstNM = l[0];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// winding flips (as the points are: a seam split separates the two sides anyway)
|
|
152
|
+
const he = o.flips === false ? null : halfEdges(g);
|
|
153
|
+
let firstFlip = -1;
|
|
154
|
+
if (he)
|
|
155
|
+
for (const e of he.flippedEdges) {
|
|
156
|
+
if (firstFlip < 0 || e < firstFlip)
|
|
157
|
+
firstFlip = e;
|
|
158
|
+
}
|
|
159
|
+
// welded pieces: union of canonical points along polygons
|
|
160
|
+
const parent = Int32Array.from({ length: np }, (_, i) => i);
|
|
161
|
+
const find = (x) => { while (parent[x] !== x) {
|
|
162
|
+
parent[x] = parent[parent[x]];
|
|
163
|
+
x = parent[x];
|
|
164
|
+
} return x; };
|
|
165
|
+
for (let p = 0; p < g.numPrims; p++) {
|
|
166
|
+
const s = g.primStart[p], e = g.primStart[p + 1];
|
|
167
|
+
if (e - s < 1)
|
|
168
|
+
continue;
|
|
169
|
+
const r0 = find(canon[g.vertexPoint[s]]);
|
|
170
|
+
for (let v = s + 1; v < e; v++) {
|
|
171
|
+
const r = find(canon[g.vertexPoint[v]]);
|
|
172
|
+
if (r !== r0)
|
|
173
|
+
parent[r] = r0;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const pieceOf = new Map();
|
|
177
|
+
const primPiece = new Int32Array(g.numPrims).fill(-1);
|
|
178
|
+
for (let p = 0; p < g.numPrims; p++) {
|
|
179
|
+
if (g.primStart[p + 1] === g.primStart[p])
|
|
180
|
+
continue;
|
|
181
|
+
const r = find(canon[g.vertexPoint[g.primStart[p]]]);
|
|
182
|
+
let k = pieceOf.get(r);
|
|
183
|
+
if (k === undefined)
|
|
184
|
+
pieceOf.set(r, (k = pieceOf.size));
|
|
185
|
+
primPiece[p] = k;
|
|
186
|
+
}
|
|
187
|
+
// per welded piece: open after welding?, signed volume, bbox
|
|
188
|
+
const n = pieceOf.size;
|
|
189
|
+
const openPiece = new Uint8Array(n), vol = new Float64Array(n), mn = new Float64Array(n * 3).fill(Infinity), mx = new Float64Array(n * 3).fill(-Infinity);
|
|
190
|
+
for (const l of groups.values())
|
|
191
|
+
if (l.length !== 2)
|
|
192
|
+
for (const e of l)
|
|
193
|
+
openPiece[primPiece[E.firstPrim[e]]] = 1;
|
|
194
|
+
for (let e = 0; e < E.a.length; e++)
|
|
195
|
+
if (E.count[e] > 2 && g.primClosed[E.firstPrim[e]])
|
|
196
|
+
openPiece[primPiece[E.firstPrim[e]]] = 1;
|
|
197
|
+
for (let p = 0; p < g.numPrims; p++)
|
|
198
|
+
if (!g.primClosed[p] && primPiece[p] >= 0)
|
|
199
|
+
openPiece[primPiece[p]] = 1;
|
|
200
|
+
const { tris, triPrim } = o.tri ?? triangulate(g);
|
|
201
|
+
for (let t = 0; t < tris.length; t += 3) {
|
|
202
|
+
const k = primPiece[triPrim[t / 3]];
|
|
203
|
+
if (k < 0)
|
|
204
|
+
continue;
|
|
205
|
+
const a = g.vertexPoint[tris[t]] * 3, c1 = g.vertexPoint[tris[t + 1]] * 3, c2 = g.vertexPoint[tris[t + 2]] * 3;
|
|
206
|
+
vol[k] += (P[a] * (P[c1 + 1] * P[c2 + 2] - P[c1 + 2] * P[c2 + 1]) - P[a + 1] * (P[c1] * P[c2 + 2] - P[c1 + 2] * P[c2]) + P[a + 2] * (P[c1] * P[c2 + 1] - P[c1 + 1] * P[c2])) / 6;
|
|
207
|
+
for (const i of [a, c1, c2])
|
|
208
|
+
for (let d = 0; d < 3; d++) {
|
|
209
|
+
mn[k * 3 + d] = Math.min(mn[k * 3 + d], P[i + d]);
|
|
210
|
+
mx[k * 3 + d] = Math.max(mx[k * 3 + d], P[i + d]);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
let inward = 0, firstInwardPrim = -1;
|
|
214
|
+
for (let k = 0; k < n; k++) {
|
|
215
|
+
if (openPiece[k] || !(vol[k] < 0))
|
|
216
|
+
continue;
|
|
217
|
+
// the wall of a cavity: inside the bbox of a larger outward-facing closed piece
|
|
218
|
+
let cavity = false;
|
|
219
|
+
for (let j = 0; j < n && !cavity; j++) {
|
|
220
|
+
if (j === k || openPiece[j] || !(vol[j] > -vol[k]))
|
|
221
|
+
continue;
|
|
222
|
+
cavity = [0, 1, 2].every((d) => mn[j * 3 + d] <= mn[k * 3 + d] && mx[j * 3 + d] >= mx[k * 3 + d]);
|
|
223
|
+
}
|
|
224
|
+
if (cavity)
|
|
225
|
+
continue;
|
|
226
|
+
inward++;
|
|
227
|
+
if (firstInwardPrim < 0)
|
|
228
|
+
firstInwardPrim = primPiece.indexOf(k);
|
|
229
|
+
}
|
|
230
|
+
const fe = (e) => (e < 0 ? null : edgeWhere(g, E.a[e], E.b[e], E.firstPrim[e]));
|
|
231
|
+
const fl = (e) => {
|
|
232
|
+
if (e < 0 || !he)
|
|
233
|
+
return null;
|
|
234
|
+
const faces = he.edgeFaces(e);
|
|
235
|
+
return edgeWhere(g, he.edgeA[e], he.edgeB[e], faces[0] ?? -1);
|
|
236
|
+
};
|
|
237
|
+
const pieceClosed = new Uint8Array(n);
|
|
238
|
+
for (let k = 0; k < n; k++)
|
|
239
|
+
pieceClosed[k] = openPiece[k] ? 0 : 1;
|
|
240
|
+
return {
|
|
241
|
+
polys, closed: polys > 0 && boundary === 0 && rawNonManifold === 0,
|
|
242
|
+
boundaryEdges: boundary, seamEdges: seam, openEdges: open, firstOpen: fe(firstOpen),
|
|
243
|
+
nonManifoldEdges: nonManifold, firstNonManifold: fe(firstNM),
|
|
244
|
+
flippedEdges: he ? he.flippedEdges.size : 0, firstFlipped: fl(firstFlip),
|
|
245
|
+
inwardPieces: inward, firstInward: firstInwardPrim >= 0 ? primWhere(g, firstInwardPrim) : null,
|
|
246
|
+
degenerate, firstDegenerate: firstDeg >= 0 ? primWhere(g, firstDeg) : null,
|
|
247
|
+
closedAfterWeld: polys > 0 && open === 0 && nonManifold === 0,
|
|
248
|
+
pieces: n, primPiece, pieceClosed,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/** "N open edges (after welding seam splits)", with the seam splits said when there are any. */
|
|
252
|
+
export function openEdgesText(r) {
|
|
253
|
+
const seams = r.seamEdges ? `; ${r.seamEdges} boundary edges are uv/normal seam splits` : '';
|
|
254
|
+
return `${r.openEdges} open edge${r.openEdges === 1 ? '' : 's'} (after welding seam splits${seams})`;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Why a mesh is not a closed solid, one line per cause with the count, where the first one is and the fix; [] when
|
|
258
|
+
* it is one (after welding seam splits).
|
|
259
|
+
*/
|
|
260
|
+
export function solidCauses(r) {
|
|
261
|
+
const out = [];
|
|
262
|
+
if (!r.polys)
|
|
263
|
+
return ['no polygons: solid operations need a closed polygon mesh'];
|
|
264
|
+
if (r.openEdges)
|
|
265
|
+
out.push(`${openEdgesText(r)}, first ${r.firstOpen}: fill_holes or fuse (weld points), or cap the open ends`);
|
|
266
|
+
if (r.nonManifoldEdges)
|
|
267
|
+
out.push(`${r.nonManifoldEdges} non-manifold edge${r.nonManifoldEdges === 1 ? '' : 's'} (shared by 3+ polygons), first ${r.firstNonManifold}: separate the touching parts (boolean union) or remove the duplicate faces (clean)`);
|
|
268
|
+
if (r.flippedEdges)
|
|
269
|
+
out.push(`${r.flippedEdges} edge${r.flippedEdges === 1 ? '' : 's'} with inconsistent winding between neighbouring polygons (flipped faces), first ${r.firstFlipped}: clean with fix_winding, or reverse the flipped part`);
|
|
270
|
+
if (r.inwardPieces)
|
|
271
|
+
out.push(`${r.inwardPieces} closed piece${r.inwardPieces === 1 ? '' : 's'} facing inward, first ${r.firstInward}: reverse it`);
|
|
272
|
+
if (r.degenerate)
|
|
273
|
+
out.push(`${r.degenerate} degenerate face${r.degenerate === 1 ? '' : 's'} (no area), first ${r.firstDegenerate}: clean (remove degenerate) or mesh_repair`);
|
|
274
|
+
return out;
|
|
275
|
+
}
|
package/dist/core/scatter.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type RunKernel = (kernel: string, job: ScatterJob, opts?: {
|
|
|
21
21
|
}>;
|
|
22
22
|
type Maybe<T> = T | Promise<T>;
|
|
23
23
|
/**
|
|
24
|
-
* Loaded-WASM auto policy, calibrated with interleaved medians
|
|
24
|
+
* Loaded-WASM auto policy, calibrated with interleaved medians.
|
|
25
25
|
* `workers` is zero for an unavailable/cold pool or a stage below its pool threshold.
|
|
26
26
|
* Large elimination lists and projection passes benefit from multiple JS workers
|
|
27
27
|
* despite faster individual Rust loops. Minimum-distance rejection stays in WASM.
|
package/dist/core/scatter.js
CHANGED
|
@@ -24,7 +24,7 @@ import { hypot3 } from './math.js';
|
|
|
24
24
|
/** f(x) for a value, x.then(f) for a promise (f may return a promise: it is flattened either way). */
|
|
25
25
|
const then = (x, f) => (x instanceof Promise ? x.then(f) : f(x));
|
|
26
26
|
/**
|
|
27
|
-
* Loaded-WASM auto policy, calibrated with interleaved medians
|
|
27
|
+
* Loaded-WASM auto policy, calibrated with interleaved medians.
|
|
28
28
|
* `workers` is zero for an unavailable/cold pool or a stage below its pool threshold.
|
|
29
29
|
* Large elimination lists and projection passes benefit from multiple JS workers
|
|
30
30
|
* despite faster individual Rust loops. Minimum-distance rejection stays in WASM.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Geometry } from './geometry.ts';
|
|
2
|
+
import type { Quat, Vec3 } from './math.ts';
|
|
3
|
+
export declare const EMPTY_ATTRIB = "scene_empty";
|
|
4
|
+
export declare const PARENT_ATTRIB = "parent";
|
|
5
|
+
/** Point attributes the empty contract owns (not written as extras). */
|
|
6
|
+
export declare const EMPTY_RESERVED: Set<string>;
|
|
7
|
+
export interface SceneEmpty {
|
|
8
|
+
point: number;
|
|
9
|
+
name: string;
|
|
10
|
+
parent: string;
|
|
11
|
+
P: Vec3;
|
|
12
|
+
orient: Quat;
|
|
13
|
+
scale: Vec3;
|
|
14
|
+
/** other point attributes that differ from their defaults */
|
|
15
|
+
extras: Record<string, number | number[] | string>;
|
|
16
|
+
}
|
|
17
|
+
/** Points marked scene_empty = 1. Throws when a marked point is used by a primitive (it would be drawn). */
|
|
18
|
+
export declare function sceneEmpties(g: Geometry): SceneEmpty[];
|
|
19
|
+
/** A geometry holding one empty (merge it with the rest). */
|
|
20
|
+
export declare function emptyGeometry(name: string, parent: string, P: Vec3, orient: Quat, scale: Vec3): Geometry;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Geometry as Geo, defaultValueFor } from './geometry.js';
|
|
2
|
+
import { posText } from './report.js';
|
|
3
|
+
export const EMPTY_ATTRIB = 'scene_empty';
|
|
4
|
+
export const PARENT_ATTRIB = 'parent';
|
|
5
|
+
/** Point attributes the empty contract owns (not written as extras). */
|
|
6
|
+
export const EMPTY_RESERVED = new Set(['P', 'orient', 'scale', 'name', PARENT_ATTRIB, EMPTY_ATTRIB, 'pscale', 'path']);
|
|
7
|
+
/** Points marked scene_empty = 1. Throws when a marked point is used by a primitive (it would be drawn). */
|
|
8
|
+
export function sceneEmpties(g) {
|
|
9
|
+
const m = g.points.get(EMPTY_ATTRIB);
|
|
10
|
+
if (!m || m.type !== 'int' || m.size !== 1)
|
|
11
|
+
return [];
|
|
12
|
+
const flag = m.data;
|
|
13
|
+
let any = false;
|
|
14
|
+
for (let i = 0; i < g.numPoints; i++)
|
|
15
|
+
if (flag[i]) {
|
|
16
|
+
any = true;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
if (!any)
|
|
20
|
+
return [];
|
|
21
|
+
const used = new Uint8Array(g.numPoints);
|
|
22
|
+
for (let v = 0; v < g.numVertices; v++)
|
|
23
|
+
used[g.vertexPoint[v]] = 1;
|
|
24
|
+
const str = (n, i) => { const a = g.points.get(n); return a && a.type === 'string' ? String(a.get(i) ?? '') : ''; };
|
|
25
|
+
const vec = (n, i, size, def) => {
|
|
26
|
+
const a = g.points.get(n);
|
|
27
|
+
if (!a || a.type !== 'float' || a.size !== size)
|
|
28
|
+
return def.slice();
|
|
29
|
+
return Array.from(a.data.subarray(i * size, i * size + size));
|
|
30
|
+
};
|
|
31
|
+
const out = [];
|
|
32
|
+
for (let i = 0; i < g.numPoints; i++) {
|
|
33
|
+
if (!flag[i])
|
|
34
|
+
continue;
|
|
35
|
+
if (used[i])
|
|
36
|
+
throw new Error(`scene empty "${str('name', i)}" (point ${i} at ${posText([g.P[i * 3], g.P[i * 3 + 1], g.P[i * 3 + 2]])}) is marked ${EMPTY_ATTRIB} but used by a primitive; empties must be isolated points`);
|
|
37
|
+
const extras = {};
|
|
38
|
+
for (const [k, a] of g.points.map) {
|
|
39
|
+
if (EMPTY_RESERVED.has(k) || a.isArray)
|
|
40
|
+
continue;
|
|
41
|
+
const v = a.get(i), d = a.def;
|
|
42
|
+
if (a.type === 'string') {
|
|
43
|
+
if (v !== '' && v !== d)
|
|
44
|
+
extras[k] = v;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const arr = Array.isArray(v) ? v : [v];
|
|
48
|
+
if (!arr.every(Number.isFinite))
|
|
49
|
+
continue;
|
|
50
|
+
const def = Array.isArray(d) ? d : [];
|
|
51
|
+
if (arr.every((x, c) => x === (def[c] ?? 0)))
|
|
52
|
+
continue;
|
|
53
|
+
extras[k] = arr.length === 1 ? arr[0] : arr;
|
|
54
|
+
}
|
|
55
|
+
const q = vec('orient', i, 4, [0, 0, 0, 1]), ql = Math.hypot(q[0], q[1], q[2], q[3]) || 1;
|
|
56
|
+
out.push({
|
|
57
|
+
point: i, name: str('name', i), parent: str(PARENT_ATTRIB, i), P: [g.P[i * 3], g.P[i * 3 + 1], g.P[i * 3 + 2]],
|
|
58
|
+
orient: [q[0] / ql, q[1] / ql, q[2] / ql, q[3] / ql], scale: vec('scale', i, 3, [1, 1, 1]), extras,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/** A geometry holding one empty (merge it with the rest). */
|
|
64
|
+
export function emptyGeometry(name, parent, P, orient, scale) {
|
|
65
|
+
const g = new Geo({ positions: P });
|
|
66
|
+
g.points.add(EMPTY_ATTRIB, 'int', 1).set(0, 1);
|
|
67
|
+
g.points.add('name', 'string', 1).set(0, name);
|
|
68
|
+
g.points.add(PARENT_ATTRIB, 'string', 1).set(0, parent);
|
|
69
|
+
g.points.add('orient', 'float', 4, defaultValueFor('orient', 4, 'float')).set(0, orient);
|
|
70
|
+
g.points.add('scale', 'float', 3, defaultValueFor('scale', 3, 'float')).set(0, scale);
|
|
71
|
+
return g;
|
|
72
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// SHA-256 (FIPS 180-4) in plain TypeScript, so a content hash reads the same in every host (export sources, io/source.ts).
|
|
2
|
+
const K = Uint32Array.from([
|
|
3
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
4
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
5
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
6
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
7
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
8
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
9
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
10
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
11
|
+
]);
|
|
12
|
+
/** The 32-byte SHA-256 digest of `data`. */
|
|
13
|
+
export function sha256(data) {
|
|
14
|
+
// message + 0x80 + zero padding + 64-bit big-endian bit length, a multiple of 64 bytes
|
|
15
|
+
const n = data.length, blocks = Math.ceil((n + 9) / 64);
|
|
16
|
+
const msg = new Uint8Array(blocks * 64);
|
|
17
|
+
msg.set(data);
|
|
18
|
+
msg[n] = 0x80;
|
|
19
|
+
const dv = new DataView(msg.buffer);
|
|
20
|
+
dv.setUint32(msg.length - 8, Math.floor(n / 0x20000000));
|
|
21
|
+
dv.setUint32(msg.length - 4, (n * 8) >>> 0);
|
|
22
|
+
const H = Uint32Array.from([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
|
|
23
|
+
const W = new Uint32Array(64);
|
|
24
|
+
for (let b = 0; b < blocks; b++) {
|
|
25
|
+
for (let t = 0; t < 16; t++)
|
|
26
|
+
W[t] = dv.getUint32(b * 64 + t * 4);
|
|
27
|
+
for (let t = 16; t < 64; t++) {
|
|
28
|
+
const x = W[t - 15], y = W[t - 2];
|
|
29
|
+
const s0 = ((x >>> 7) | (x << 25)) ^ ((x >>> 18) | (x << 14)) ^ (x >>> 3);
|
|
30
|
+
const s1 = ((y >>> 17) | (y << 15)) ^ ((y >>> 19) | (y << 13)) ^ (y >>> 10);
|
|
31
|
+
W[t] = (W[t - 16] + s0 + W[t - 7] + s1) >>> 0;
|
|
32
|
+
}
|
|
33
|
+
let a = H[0], bb = H[1], c = H[2], d = H[3], e = H[4], f = H[5], g = H[6], h = H[7];
|
|
34
|
+
for (let t = 0; t < 64; t++) {
|
|
35
|
+
const S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
|
|
36
|
+
const t1 = (h + S1 + ((e & f) ^ (~e & g)) + K[t] + W[t]) >>> 0;
|
|
37
|
+
const S0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
|
|
38
|
+
const t2 = (S0 + ((a & bb) ^ (a & c) ^ (bb & c))) >>> 0;
|
|
39
|
+
h = g;
|
|
40
|
+
g = f;
|
|
41
|
+
f = e;
|
|
42
|
+
e = (d + t1) >>> 0;
|
|
43
|
+
d = c;
|
|
44
|
+
c = bb;
|
|
45
|
+
bb = a;
|
|
46
|
+
a = (t1 + t2) >>> 0;
|
|
47
|
+
}
|
|
48
|
+
H[0] = (H[0] + a) >>> 0;
|
|
49
|
+
H[1] = (H[1] + bb) >>> 0;
|
|
50
|
+
H[2] = (H[2] + c) >>> 0;
|
|
51
|
+
H[3] = (H[3] + d) >>> 0;
|
|
52
|
+
H[4] = (H[4] + e) >>> 0;
|
|
53
|
+
H[5] = (H[5] + f) >>> 0;
|
|
54
|
+
H[6] = (H[6] + g) >>> 0;
|
|
55
|
+
H[7] = (H[7] + h) >>> 0;
|
|
56
|
+
}
|
|
57
|
+
const out = new Uint8Array(32), ov = new DataView(out.buffer);
|
|
58
|
+
for (let i = 0; i < 8; i++)
|
|
59
|
+
ov.setUint32(i * 4, H[i]);
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
/** SHA-256 as 64 lower-case hex digits; a string is hashed as its UTF-8 bytes. */
|
|
63
|
+
export function sha256Hex(data) {
|
|
64
|
+
const d = sha256(typeof data === 'string' ? new TextEncoder().encode(data) : data);
|
|
65
|
+
let s = '';
|
|
66
|
+
for (const x of d)
|
|
67
|
+
s += x.toString(16).padStart(2, '0');
|
|
68
|
+
return s;
|
|
69
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Primitive shapes shared by the generator nodes and the previews (render/texview.ts material spheres).
|
|
2
|
+
import { GeoBuilder } from './geometry.js';
|
|
3
|
+
/** Latitude/longitude sphere of radius r around the origin, with vertex uv (u around from +X, v up). */
|
|
4
|
+
export function uvSphere(r, rows, cols) {
|
|
5
|
+
rows = Math.max(2, rows);
|
|
6
|
+
cols = Math.max(3, cols);
|
|
7
|
+
const b = new GeoBuilder();
|
|
8
|
+
const uv = b.attrib('vertex', 'uv', 3);
|
|
9
|
+
const top = b.addPoint(0, r, 0);
|
|
10
|
+
const ring = [];
|
|
11
|
+
for (let i = 1; i < rows; i++) {
|
|
12
|
+
const th = (Math.PI * i) / rows, row = [];
|
|
13
|
+
for (let c = 0; c < cols; c++) {
|
|
14
|
+
const ph = (2 * Math.PI * c) / cols;
|
|
15
|
+
row.push(b.addPoint(r * Math.sin(th) * Math.cos(ph), r * Math.cos(th), -r * Math.sin(th) * Math.sin(ph)));
|
|
16
|
+
}
|
|
17
|
+
ring.push(row);
|
|
18
|
+
}
|
|
19
|
+
const bot = b.addPoint(0, -r, 0);
|
|
20
|
+
const addUV = (us) => { const v0 = b.numVertices - us.length; us.forEach((t, k) => uv.set(v0 + k, [t[0], t[1], 0])); };
|
|
21
|
+
for (let c = 0; c < cols; c++) {
|
|
22
|
+
const c1 = (c + 1) % cols, u0 = c / cols, u1 = (c + 1) / cols;
|
|
23
|
+
b.addPrim([top, ring[0][c], ring[0][c1]]);
|
|
24
|
+
addUV([[(u0 + u1) / 2, 1], [u0, 1 - 1 / rows], [u1, 1 - 1 / rows]]);
|
|
25
|
+
for (let i = 0; i < rows - 2; i++) {
|
|
26
|
+
b.addPrim([ring[i][c], ring[i + 1][c], ring[i + 1][c1], ring[i][c1]]);
|
|
27
|
+
const va = 1 - (i + 1) / rows, vb = 1 - (i + 2) / rows;
|
|
28
|
+
addUV([[u0, va], [u0, vb], [u1, vb], [u1, va]]);
|
|
29
|
+
}
|
|
30
|
+
b.addPrim([ring[rows - 2][c], bot, ring[rows - 2][c1]]);
|
|
31
|
+
addUV([[u0, 1 / rows], [(u0 + u1) / 2, 0], [u1, 1 / rows]]);
|
|
32
|
+
}
|
|
33
|
+
return b.build();
|
|
34
|
+
}
|