topotopo 0.4.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 +10 -10
- package/README.md +460 -117
- package/dist/cli.js +323 -146
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/bake.d.ts +14 -3
- package/dist/core/bake.js +153 -4
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +76 -3
- 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 +203 -3
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- 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 +7 -0
- package/dist/core/materials.js +45 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- 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/scene.js +2 -1
- 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 +14 -1
- package/dist/core/snippet-lib.js +39 -13
- package/dist/core/tangents.d.ts +2 -0
- package/dist/core/tangents.js +5 -1
- 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 +10 -0
- package/dist/core/topology.js +168 -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 +4 -18
- package/dist/core/uv.js +35 -188
- 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 +61 -0
- package/dist/core/uvreport.js +207 -143
- 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 +66 -62
- 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 +2 -2
- package/dist/index.js +1 -1
- package/dist/inspect.d.ts +80 -2
- package/dist/inspect.js +265 -30
- package/dist/io/common.d.ts +25 -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 +134 -47
- 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 +148 -13
- 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 +786 -143
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +56 -27
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +196 -103
- 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 +151 -47
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +51 -3
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +21 -9
- package/dist/nodes/curves.js +433 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +12 -38
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.js +16 -19
- package/dist/nodes/index.d.ts +1 -0
- package/dist/nodes/index.js +1 -0
- package/dist/nodes/material.js +89 -24
- package/dist/nodes/measure.js +43 -17
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.js +4 -2
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- 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 +6 -2
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +5 -1
- 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/preview.d.ts +15 -4
- package/dist/render/preview.js +6 -4
- package/dist/render/raster.d.ts +66 -5
- package/dist/render/raster.js +506 -138
- package/dist/render/texview.d.ts +6 -0
- package/dist/render/texview.js +27 -0
- 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/cooking.js +78 -0
- package/dist/viewer/app/embed.js +27 -7
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +5 -1
- package/dist/viewer/app/guides.js +122 -0
- package/dist/viewer/app/keymap.js +6 -3
- package/dist/viewer/app/layers.js +4 -4
- package/dist/viewer/app/main.js +185 -52
- package/dist/viewer/app/markers.js +60 -0
- 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 +176 -52
- package/dist/viewer/app/scene.js +30 -5
- package/dist/viewer/app/select.js +4 -3
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +65 -7
- package/dist/viewer/app/vars.js +47 -0
- 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 +23 -10
- 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 +14 -9
- package/dist/viewer/server.js +266 -28
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/{gallery → web}/bake.d.ts +4 -4
- package/dist/{gallery → web}/bake.js +24 -15
- 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 -118
- package/dist/workspace.js +358 -460
- 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 +2 -1
- package/kernels/pkg-simd/README.md +2 -1
- 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 +17 -8
- package/dist/gallery/app/gallery.css +0 -100
- package/dist/gallery/app/gallery.js +0 -80
- package/dist/gallery/cli.d.ts +0 -4
- package/dist/gallery/cli.js +0 -157
- package/dist/gallery/library.d.ts +0 -124
- package/dist/gallery/library.js +0 -366
- package/dist/gallery/pages.d.ts +0 -94
- package/dist/gallery/pages.js +0 -148
- package/dist/gallery/server.d.ts +0 -21
- package/dist/gallery/server.js +0 -391
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/dist/mcp/library.d.ts +0 -12
- package/dist/mcp/library.js +0 -159
- package/shelf/index.json +0 -190
package/dist/core/topology.d.ts
CHANGED
|
@@ -77,6 +77,16 @@ export declare function reversePrims(g: Geometry, mask?: ArrayLike<number> | nul
|
|
|
77
77
|
export declare function signedVolume(g: Geometry): number;
|
|
78
78
|
/** Make a closed mesh face outward (flip everything if the signed volume is negative). */
|
|
79
79
|
export declare function orientOutward(g: Geometry): Geometry;
|
|
80
|
+
/**
|
|
81
|
+
* Turn inside-out pieces outward: a connected piece with negative signed volume flips, unless it lies inside another
|
|
82
|
+
* piece's bounds (the inner wall of a hollow solid faces inward on purpose). A mirror without a winding flip, or a
|
|
83
|
+
* hand-built cutter, gives such pieces; booleans would make inverted walls from them. Returns the first prim of each
|
|
84
|
+
* flipped piece.
|
|
85
|
+
*/
|
|
86
|
+
export declare function outwardPieces(g: Geometry): {
|
|
87
|
+
geo: Geometry;
|
|
88
|
+
flipped: number[];
|
|
89
|
+
};
|
|
80
90
|
/** Quick topology health report used by inspect and by solid ops. */
|
|
81
91
|
export declare function topologyReport(g: Geometry): {
|
|
82
92
|
polys: number;
|
package/dist/core/topology.js
CHANGED
|
@@ -478,6 +478,8 @@ export function triangulate(g, primMask) {
|
|
|
478
478
|
tri2 += (flat[b] - flat[a]) * (flat[c + 1] - flat[a + 1]) - (flat[c] - flat[a]) * (flat[b + 1] - flat[a + 1]);
|
|
479
479
|
}
|
|
480
480
|
const flip = poly2 * tri2 < 0;
|
|
481
|
+
if (n > 4 && planarPoly(P, vp, s, n, nrm))
|
|
482
|
+
delaunayFlips(flat, idx);
|
|
481
483
|
for (let k = 0; k < idx.length; k += 3) {
|
|
482
484
|
const a = s + idx[k], b = s + idx[k + 1], c = s + idx[k + 2];
|
|
483
485
|
if (flip)
|
|
@@ -489,6 +491,119 @@ export function triangulate(g, primMask) {
|
|
|
489
491
|
}
|
|
490
492
|
return { tris: Uint32Array.from(tris), triPrim: Uint32Array.from(tp) };
|
|
491
493
|
}
|
|
494
|
+
/** Is polygon s..s+n flat (every corner within a millionth of its size of the plane through its centroid)? */
|
|
495
|
+
function planarPoly(P, vp, s, n, nrm) {
|
|
496
|
+
const l = Math.hypot(nrm[0], nrm[1], nrm[2]);
|
|
497
|
+
if (!(l > 0))
|
|
498
|
+
return false;
|
|
499
|
+
const nx = nrm[0] / l, ny = nrm[1] / l, nz = nrm[2] / l;
|
|
500
|
+
let cx = 0, cy = 0, cz = 0, x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity, z0 = Infinity, z1 = -Infinity;
|
|
501
|
+
for (let k = 0; k < n; k++) {
|
|
502
|
+
const i = vp[s + k] * 3, x = P[i], y = P[i + 1], z = P[i + 2];
|
|
503
|
+
cx += x;
|
|
504
|
+
cy += y;
|
|
505
|
+
cz += z;
|
|
506
|
+
x0 = Math.min(x0, x);
|
|
507
|
+
x1 = Math.max(x1, x);
|
|
508
|
+
y0 = Math.min(y0, y);
|
|
509
|
+
y1 = Math.max(y1, y);
|
|
510
|
+
z0 = Math.min(z0, z);
|
|
511
|
+
z1 = Math.max(z1, z);
|
|
512
|
+
}
|
|
513
|
+
cx /= n;
|
|
514
|
+
cy /= n;
|
|
515
|
+
cz /= n;
|
|
516
|
+
const tol = 1e-6 * Math.hypot(x1 - x0, y1 - y0, z1 - z0);
|
|
517
|
+
for (let k = 0; k < n; k++) {
|
|
518
|
+
const i = vp[s + k] * 3;
|
|
519
|
+
if (Math.abs((P[i] - cx) * nx + (P[i + 1] - cy) * ny + (P[i + 2] - cz) * nz) > tol)
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
return true;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Improve an ear-clipped triangulation of a flat polygon in place by edge flips toward Delaunay: a diagonal whose
|
|
526
|
+
* opposite corner lies inside the other triangle's circumcircle is swapped (when the two triangles form a convex quad),
|
|
527
|
+
* so nearly collinear corners do not leave slivers. The outline is never touched and every corner stays in use.
|
|
528
|
+
*/
|
|
529
|
+
function delaunayFlips(flat, idx) {
|
|
530
|
+
const nt = idx.length / 3;
|
|
531
|
+
if (nt < 2)
|
|
532
|
+
return;
|
|
533
|
+
const X = (i) => flat[i * 2], Y = (i) => flat[i * 2 + 1];
|
|
534
|
+
const orient = (a, b, c) => (X(b) - X(a)) * (Y(c) - Y(a)) - (Y(b) - Y(a)) * (X(c) - X(a));
|
|
535
|
+
// all triangles counter-clockwise for the in-circle test
|
|
536
|
+
const ccw = orient(idx[0], idx[1], idx[2]) > 0;
|
|
537
|
+
const tri = (t) => (ccw ? [idx[t * 3], idx[t * 3 + 1], idx[t * 3 + 2]] : [idx[t * 3], idx[t * 3 + 2], idx[t * 3 + 1]]);
|
|
538
|
+
const set = (t, a, b, c) => { idx[t * 3] = a; if (ccw) {
|
|
539
|
+
idx[t * 3 + 1] = b;
|
|
540
|
+
idx[t * 3 + 2] = c;
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
idx[t * 3 + 1] = c;
|
|
544
|
+
idx[t * 3 + 2] = b;
|
|
545
|
+
} };
|
|
546
|
+
let x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity;
|
|
547
|
+
for (let i = 0; i < flat.length; i += 2) {
|
|
548
|
+
x0 = Math.min(x0, flat[i]);
|
|
549
|
+
x1 = Math.max(x1, flat[i]);
|
|
550
|
+
y0 = Math.min(y0, flat[i + 1]);
|
|
551
|
+
y1 = Math.max(y1, flat[i + 1]);
|
|
552
|
+
}
|
|
553
|
+
const size = Math.max(x1 - x0, y1 - y0);
|
|
554
|
+
const eps = 1e-12 * size ** 4;
|
|
555
|
+
const incircle = (a, b, c, d) => {
|
|
556
|
+
const adx = X(a) - X(d), ady = Y(a) - Y(d), bdx = X(b) - X(d), bdy = Y(b) - Y(d), cdx = X(c) - X(d), cdy = Y(c) - Y(d);
|
|
557
|
+
return (adx * adx + ady * ady) * (bdx * cdy - cdx * bdy) - (bdx * bdx + bdy * bdy) * (adx * cdy - cdx * ady) + (cdx * cdx + cdy * cdy) * (adx * bdy - bdx * ady);
|
|
558
|
+
};
|
|
559
|
+
const edgeKey = (a, b) => (a < b ? a * 1048576 + b : b * 1048576 + a);
|
|
560
|
+
const edges = new Map();
|
|
561
|
+
const link = (t) => { const [a, b, c] = tri(t); for (const [u, w] of [[a, b], [b, c], [c, a]]) {
|
|
562
|
+
const k = edgeKey(u, w);
|
|
563
|
+
const l = edges.get(k);
|
|
564
|
+
if (l)
|
|
565
|
+
l.push(t);
|
|
566
|
+
else
|
|
567
|
+
edges.set(k, [t]);
|
|
568
|
+
} };
|
|
569
|
+
const unlink = (t) => { const [a, b, c] = tri(t); for (const [u, w] of [[a, b], [b, c], [c, a]]) {
|
|
570
|
+
const l = edges.get(edgeKey(u, w));
|
|
571
|
+
if (l)
|
|
572
|
+
l.splice(l.indexOf(t), 1);
|
|
573
|
+
} };
|
|
574
|
+
for (let t = 0; t < nt; t++)
|
|
575
|
+
link(t);
|
|
576
|
+
const todo = [...edges.keys()];
|
|
577
|
+
// each flip strictly improves the triangulation (Delaunay), the budget only guards against rounding loops
|
|
578
|
+
for (let budget = 8 * nt + 64; todo.length && budget > 0;) {
|
|
579
|
+
const l = edges.get(todo.pop());
|
|
580
|
+
if (!l || l.length !== 2)
|
|
581
|
+
continue;
|
|
582
|
+
const [t1, t2] = l, A = tri(t1), B = tri(t2);
|
|
583
|
+
let k = 0;
|
|
584
|
+
for (; k < 3; k++)
|
|
585
|
+
if (B.includes(A[k]) && B.includes(A[(k + 1) % 3]))
|
|
586
|
+
break;
|
|
587
|
+
if (k === 3)
|
|
588
|
+
continue;
|
|
589
|
+
// shared edge a → b in A, opposite corners c (in A) and d (in B)
|
|
590
|
+
const a = A[k], b = A[(k + 1) % 3], c = A[(k + 2) % 3], d = B.find((x) => x !== a && x !== b);
|
|
591
|
+
if (!(incircle(a, b, c, d) > eps))
|
|
592
|
+
continue;
|
|
593
|
+
// the new diagonal c–d must lie inside the quad a, d, b, c
|
|
594
|
+
if (!(orient(c, d, b) > 0 && orient(d, c, a) > 0))
|
|
595
|
+
continue;
|
|
596
|
+
unlink(t1);
|
|
597
|
+
unlink(t2);
|
|
598
|
+
edges.delete(edgeKey(a, b));
|
|
599
|
+
set(t1, a, d, c);
|
|
600
|
+
set(t2, d, b, c);
|
|
601
|
+
link(t1);
|
|
602
|
+
link(t2);
|
|
603
|
+
todo.push(edgeKey(a, d), edgeKey(d, b), edgeKey(b, c), edgeKey(c, a));
|
|
604
|
+
budget--;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
492
607
|
/** Connected components over shared points. Returns component id per prim and per point. */
|
|
493
608
|
export function connectivity(g) {
|
|
494
609
|
const parent = new Int32Array(g.numPoints);
|
|
@@ -572,6 +687,59 @@ export function signedVolume(g) {
|
|
|
572
687
|
export function orientOutward(g) {
|
|
573
688
|
return signedVolume(g) < 0 ? reversePrims(g) : g;
|
|
574
689
|
}
|
|
690
|
+
/**
|
|
691
|
+
* Turn inside-out pieces outward: a connected piece with negative signed volume flips, unless it lies inside another
|
|
692
|
+
* piece's bounds (the inner wall of a hollow solid faces inward on purpose). A mirror without a winding flip, or a
|
|
693
|
+
* hand-built cutter, gives such pieces; booleans would make inverted walls from them. Returns the first prim of each
|
|
694
|
+
* flipped piece.
|
|
695
|
+
*/
|
|
696
|
+
export function outwardPieces(g) {
|
|
697
|
+
const { primClass, count } = connectivity(g);
|
|
698
|
+
if (!count)
|
|
699
|
+
return { geo: g, flipped: [] };
|
|
700
|
+
const { tris, triPrim } = triangulate(g);
|
|
701
|
+
const vol = new Float64Array(count), first = new Int32Array(count).fill(-1);
|
|
702
|
+
const lo = new Float64Array(count * 3).fill(Infinity), hi = new Float64Array(count * 3).fill(-Infinity);
|
|
703
|
+
const P = g.P;
|
|
704
|
+
for (let t = 0; t < tris.length; t += 3) {
|
|
705
|
+
const c = primClass[triPrim[t / 3]];
|
|
706
|
+
const a = g.vertexPoint[tris[t]] * 3, b = g.vertexPoint[tris[t + 1]] * 3, d = g.vertexPoint[tris[t + 2]] * 3;
|
|
707
|
+
vol[c] += P[a] * (P[b + 1] * P[d + 2] - P[b + 2] * P[d + 1]) - P[a + 1] * (P[b] * P[d + 2] - P[b + 2] * P[d]) + P[a + 2] * (P[b] * P[d + 1] - P[b + 1] * P[d]);
|
|
708
|
+
for (const i of [a, b, d])
|
|
709
|
+
for (let k = 0; k < 3; k++) {
|
|
710
|
+
lo[c * 3 + k] = Math.min(lo[c * 3 + k], P[i + k]);
|
|
711
|
+
hi[c * 3 + k] = Math.max(hi[c * 3 + k], P[i + k]);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
for (let p = 0; p < g.numPrims; p++) {
|
|
715
|
+
const c = primClass[p];
|
|
716
|
+
if (c >= 0 && first[c] < 0)
|
|
717
|
+
first[c] = p;
|
|
718
|
+
}
|
|
719
|
+
const inside = (c, o) => {
|
|
720
|
+
for (let k = 0; k < 3; k++)
|
|
721
|
+
if (lo[c * 3 + k] < lo[o * 3 + k] || hi[c * 3 + k] > hi[o * 3 + k])
|
|
722
|
+
return false;
|
|
723
|
+
return true;
|
|
724
|
+
};
|
|
725
|
+
const flip = new Uint8Array(count);
|
|
726
|
+
const flipped = [];
|
|
727
|
+
for (let c = 0; c < count; c++) {
|
|
728
|
+
if (!(vol[c] < 0))
|
|
729
|
+
continue;
|
|
730
|
+
let nested = false;
|
|
731
|
+
for (let o = 0; o < count && !nested; o++)
|
|
732
|
+
if (o !== c && vol[o] > 0 && inside(c, o))
|
|
733
|
+
nested = true;
|
|
734
|
+
if (nested)
|
|
735
|
+
continue;
|
|
736
|
+
flip[c] = 1;
|
|
737
|
+
flipped.push(first[c]);
|
|
738
|
+
}
|
|
739
|
+
if (!flipped.length)
|
|
740
|
+
return { geo: g, flipped };
|
|
741
|
+
return { geo: reversePrims(g, Uint8Array.from(primClass, (c) => (c >= 0 ? flip[c] : 0))), flipped };
|
|
742
|
+
}
|
|
575
743
|
/** Quick topology health report used by inspect and by solid ops. */
|
|
576
744
|
export function topologyReport(g) {
|
|
577
745
|
const E = buildEdges(g);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Geometry } from './geometry.ts';
|
|
2
|
+
import type { XatlasChartOptions } from './xatlas.ts';
|
|
3
|
+
export interface UnwrapOptions {
|
|
4
|
+
chart: XatlasChartOptions;
|
|
5
|
+
/** xatlas input vertex per geometry vertex (seam-split keys), or null: the points */
|
|
6
|
+
vertexKey: Int32Array | null;
|
|
7
|
+
/** per prim: prims with different values never share a chart, or null */
|
|
8
|
+
faceGroup: Int32Array | null;
|
|
9
|
+
straddling: 'split' | 'unfold';
|
|
10
|
+
/** texture size and padding in its texels */
|
|
11
|
+
resolution: number;
|
|
12
|
+
padding: number;
|
|
13
|
+
/** texels per world unit: 0 = the largest density that fits one tile */
|
|
14
|
+
texelsPerUnit: number;
|
|
15
|
+
/** charts that do not fit one tile at texelsPerUnit: atlas = a lower density so they fit the tile, udim = more tiles to the right, stack = more atlases in 0..1 */
|
|
16
|
+
fit: 'atlas' | 'udim' | 'stack';
|
|
17
|
+
/** chart orientation: min_rect = turned to the minimum bounding rectangle (and 90° turns when packing), world = world up (+Y) to +v, keep = as charted */
|
|
18
|
+
orient: 'min_rect' | 'world' | 'keep';
|
|
19
|
+
/** cut charts longer than the tile, and rings and arcs, into parts; join thin charts onto a neighbour (core/uvislands.ts) */
|
|
20
|
+
cutLong: boolean;
|
|
21
|
+
mergeThin: boolean;
|
|
22
|
+
/** prim attribute with a texel weight per polygon ("" = none) */
|
|
23
|
+
texelWeight: string;
|
|
24
|
+
/** island orders the packer tries */
|
|
25
|
+
iterations: number;
|
|
26
|
+
}
|
|
27
|
+
export interface UnwrapResult {
|
|
28
|
+
geo: Geometry;
|
|
29
|
+
/** per output prim: chart (-1: not a polygon), atlas (overflow stack with several atlases, else null) */
|
|
30
|
+
chart: Int32Array;
|
|
31
|
+
atlas: Int32Array | null;
|
|
32
|
+
pieces: number;
|
|
33
|
+
charts: number;
|
|
34
|
+
tiles: number;
|
|
35
|
+
/** polygons with no charted triangle, collapsed onto a neighbour's chart; isolated: no neighbour had a chart */
|
|
36
|
+
degenerate: number;
|
|
37
|
+
firstDegenerate: number;
|
|
38
|
+
isolated: number;
|
|
39
|
+
/** polygons xatlas put in several charts (split into triangles, or unfolded) */
|
|
40
|
+
straddled: number;
|
|
41
|
+
firstStraddled: number;
|
|
42
|
+
/** charts stretched one way (thin strips) flattened again by a conformal map */
|
|
43
|
+
unstretched: number;
|
|
44
|
+
/** charts mirrored back to the polygon winding */
|
|
45
|
+
mirrored: number;
|
|
46
|
+
/** folded charts charted again, by stage: xatlas at a quarter of the cost, a conformal map (LSCM), cut where it overlaps itself; and the charts the cuts made */
|
|
47
|
+
refolded: [number, number, number];
|
|
48
|
+
splitInto: number;
|
|
49
|
+
/** overlapping triangle pairs left inside one chart (folds) and between charts (never expected), output triangle ids */
|
|
50
|
+
folds: number;
|
|
51
|
+
foldPair: [number, number] | null;
|
|
52
|
+
across: number;
|
|
53
|
+
acrossPair: [number, number] | null;
|
|
54
|
+
/** output triangles with 3D area but no uv area */
|
|
55
|
+
collapsed: number;
|
|
56
|
+
/** output triangulation (vertex triples, prim per triangle) and per-vertex uv */
|
|
57
|
+
tris: Uint32Array;
|
|
58
|
+
triPrim: Uint32Array;
|
|
59
|
+
uv: Float64Array;
|
|
60
|
+
/** summed uv area per tile used, and the packer's cap (index of the chart that spans the tile, or -1) */
|
|
61
|
+
coverage: number;
|
|
62
|
+
cappedBy: number;
|
|
63
|
+
/** charts cut into parts (cutLong), the charts they became, and a prim of the first one cut (-1) */
|
|
64
|
+
cut: number;
|
|
65
|
+
cutParts: number;
|
|
66
|
+
firstCut: number;
|
|
67
|
+
/** the texel weight attribute was found */
|
|
68
|
+
weighted: boolean;
|
|
69
|
+
/** thin charts joined onto a neighbour (mergeThin) */
|
|
70
|
+
merged: number;
|
|
71
|
+
}
|
|
72
|
+
export declare function unwrapMesh(X: any, g: Geometry, o: UnwrapOptions): UnwrapResult;
|