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
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Strict triangle-pair contact test for self-intersection checks (analysis.selfIntersections with strict: true, used by
|
|
2
|
+
// solidify): two triangles of one mesh may meet only along what they share. Reported:
|
|
3
|
+
// - no shared corner: any contact, touching included (crossing edges, a vertex on the other face, coplanar overlap)
|
|
4
|
+
// - one shared corner: any common point other than that corner (one folds through the other near the corner)
|
|
5
|
+
// - a shared edge: coplanar overlap of positive area (one folded back onto the other); non-coplanar triangles that
|
|
6
|
+
// share an edge can only meet along it
|
|
7
|
+
// Non-coplanar pairs use the interval overlap of both triangles on the line where their planes meet (Möller);
|
|
8
|
+
// coplanar ones are clipped in 2D. Tolerances scale with the mesh size (eps = lengths, rel = areas).
|
|
9
|
+
const dot = (ax, ay, az, bx, by, bz) => ax * bx + ay * by + az * bz;
|
|
10
|
+
/** Signed doubled area of a 2D triangle. */
|
|
11
|
+
const area2 = (ax, ay, bx, by, cx, cy) => (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
|
|
12
|
+
/** Clip CCW triangle a against CCW triangle b (2D, 6 numbers each): intersection polygon area. */
|
|
13
|
+
function clipArea(a, b) {
|
|
14
|
+
let poly = a.slice();
|
|
15
|
+
for (let e = 0; e < 3 && poly.length >= 6; e++) {
|
|
16
|
+
const ax = b[e * 2], ay = b[e * 2 + 1], bx = b[((e + 1) % 3) * 2], by = b[((e + 1) % 3) * 2 + 1];
|
|
17
|
+
const out = [], n = poly.length / 2;
|
|
18
|
+
for (let i = 0; i < n; i++) {
|
|
19
|
+
const cx = poly[i * 2], cy = poly[i * 2 + 1], dx = poly[((i + 1) % n) * 2], dy = poly[((i + 1) % n) * 2 + 1];
|
|
20
|
+
const sc = area2(ax, ay, bx, by, cx, cy), sd = area2(ax, ay, bx, by, dx, dy);
|
|
21
|
+
if (sc >= 0)
|
|
22
|
+
out.push(cx, cy);
|
|
23
|
+
if ((sc >= 0) !== (sd >= 0)) {
|
|
24
|
+
const t = sc / (sc - sd);
|
|
25
|
+
out.push(cx + (dx - cx) * t, cy + (dy - cy) * t);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
poly = out;
|
|
29
|
+
}
|
|
30
|
+
if (poly.length < 6)
|
|
31
|
+
return 0;
|
|
32
|
+
let s = 0;
|
|
33
|
+
for (let i = 0, n = poly.length / 2; i < n; i++) {
|
|
34
|
+
const j = (i + 1) % n;
|
|
35
|
+
s += poly[i * 2] * poly[j * 2 + 1] - poly[j * 2] * poly[i * 2 + 1];
|
|
36
|
+
}
|
|
37
|
+
return Math.abs(s) / 2;
|
|
38
|
+
}
|
|
39
|
+
/** 2D segments p1p2 and q1q2 touch or cross (within eps). */
|
|
40
|
+
function segTouch(p1x, p1y, p2x, p2y, q1x, q1y, q2x, q2y, eps) {
|
|
41
|
+
const lp = Math.hypot(p2x - p1x, p2y - p1y) || 1, lq = Math.hypot(q2x - q1x, q2y - q1y) || 1;
|
|
42
|
+
const d1 = area2(q1x, q1y, q2x, q2y, p1x, p1y) / lq, d2 = area2(q1x, q1y, q2x, q2y, p2x, p2y) / lq;
|
|
43
|
+
const d3 = area2(p1x, p1y, p2x, p2y, q1x, q1y) / lp, d4 = area2(p1x, p1y, p2x, p2y, q2x, q2y) / lp;
|
|
44
|
+
if (((d1 > eps && d2 > eps) || (d1 < -eps && d2 < -eps)) || ((d3 > eps && d4 > eps) || (d3 < -eps && d4 < -eps)))
|
|
45
|
+
return false;
|
|
46
|
+
// collinear-ish: projections must overlap
|
|
47
|
+
const ux = (p2x - p1x) / lp, uy = (p2y - p1y) / lp;
|
|
48
|
+
const a0 = 0, a1 = lp, b0 = (q1x - p1x) * ux + (q1y - p1y) * uy, b1 = (q2x - p1x) * ux + (q2y - p1y) * uy;
|
|
49
|
+
if (Math.abs(d1) <= eps && Math.abs(d2) <= eps)
|
|
50
|
+
return Math.min(a1, Math.max(b0, b1)) - Math.max(a0, Math.min(b0, b1)) >= -eps;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Triangles A (offset a) and B (offset b) in T (9 numbers each) meet beyond what they share: `shared` corners (0, 1
|
|
55
|
+
* or 2; the shared corners must be the same points). eps: length tolerance.
|
|
56
|
+
*/
|
|
57
|
+
export function trianglesContact(T, a, b, shared, eps) {
|
|
58
|
+
const A = [T[a], T[a + 1], T[a + 2], T[a + 3], T[a + 4], T[a + 5], T[a + 6], T[a + 7], T[a + 8]];
|
|
59
|
+
const B = [T[b], T[b + 1], T[b + 2], T[b + 3], T[b + 4], T[b + 5], T[b + 6], T[b + 7], T[b + 8]];
|
|
60
|
+
const nrm = (X) => {
|
|
61
|
+
const ux = X[3] - X[0], uy = X[4] - X[1], uz = X[5] - X[2], wx = X[6] - X[0], wy = X[7] - X[1], wz = X[8] - X[2];
|
|
62
|
+
const nx = uy * wz - uz * wy, ny = uz * wx - ux * wz, nz = ux * wy - uy * wx, l = Math.hypot(nx, ny, nz);
|
|
63
|
+
return l > 0 ? [nx / l, ny / l, nz / l, l / 2] : null;
|
|
64
|
+
};
|
|
65
|
+
const nA = nrm(A), nB = nrm(B);
|
|
66
|
+
if (!nA || !nB)
|
|
67
|
+
return false; // degenerate triangles are reported by the degeneracy checks
|
|
68
|
+
// distances of each triangle's corners to the other's plane
|
|
69
|
+
const dA = [0, 1, 2].map((k) => dot(A[k * 3] - B[0], A[k * 3 + 1] - B[1], A[k * 3 + 2] - B[2], nB[0], nB[1], nB[2]));
|
|
70
|
+
const dB = [0, 1, 2].map((k) => dot(B[k * 3] - A[0], B[k * 3 + 1] - A[1], B[k * 3 + 2] - A[2], nA[0], nA[1], nA[2]));
|
|
71
|
+
const side = (d) => (d.every((x) => x > eps) ? 1 : d.every((x) => x < -eps) ? -1 : 0);
|
|
72
|
+
if (side(dA) !== 0 || side(dB) !== 0)
|
|
73
|
+
return false;
|
|
74
|
+
const coplanar = dA.every((x) => Math.abs(x) <= eps) && dB.every((x) => Math.abs(x) <= eps);
|
|
75
|
+
if (coplanar) {
|
|
76
|
+
// project on the dominant axis plane of A's normal, orient both counter-clockwise
|
|
77
|
+
const ax = Math.abs(nA[0]), ay = Math.abs(nA[1]), az = Math.abs(nA[2]);
|
|
78
|
+
const [i, j] = ax >= ay && ax >= az ? [1, 2] : ay >= az ? [2, 0] : [0, 1];
|
|
79
|
+
const p2 = (X) => { const q = [X[i], X[j], X[3 + i], X[3 + j], X[6 + i], X[6 + j]]; return area2(q[0], q[1], q[2], q[3], q[4], q[5]) < 0 ? [q[0], q[1], q[4], q[5], q[2], q[3]] : q; };
|
|
80
|
+
const pa = p2(A), pb = p2(B);
|
|
81
|
+
const proj = Math.max(ax, ay, az) || 1;
|
|
82
|
+
const ov = clipArea(pa, pb) / proj;
|
|
83
|
+
if (ov > 1e-9 * Math.min(nA[3], nB[3]))
|
|
84
|
+
return true;
|
|
85
|
+
if (shared)
|
|
86
|
+
return false;
|
|
87
|
+
// no area in common: touching edges or corners still count when nothing is shared
|
|
88
|
+
for (let e = 0; e < 3; e++)
|
|
89
|
+
for (let f = 0; f < 3; f++) {
|
|
90
|
+
if (segTouch(pa[e * 2], pa[e * 2 + 1], pa[((e + 1) % 3) * 2], pa[((e + 1) % 3) * 2 + 1], pb[f * 2], pb[f * 2 + 1], pb[((f + 1) % 3) * 2], pb[((f + 1) % 3) * 2 + 1], eps * proj))
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (shared >= 2)
|
|
96
|
+
return false;
|
|
97
|
+
// interval of each triangle on the line L = nA × nB, from the points where its edges meet the other plane
|
|
98
|
+
const Lx = nA[1] * nB[2] - nA[2] * nB[1], Ly = nA[2] * nB[0] - nA[0] * nB[2], Lz = nA[0] * nB[1] - nA[1] * nB[0];
|
|
99
|
+
const interval = (X, d) => {
|
|
100
|
+
let lo = Infinity, hi = -Infinity;
|
|
101
|
+
const add = (x, y, z) => { const s = x * Lx + y * Ly + z * Lz; if (s < lo)
|
|
102
|
+
lo = s; if (s > hi)
|
|
103
|
+
hi = s; };
|
|
104
|
+
for (let k = 0; k < 3; k++) {
|
|
105
|
+
const m = (k + 1) % 3;
|
|
106
|
+
if (Math.abs(d[k]) <= eps)
|
|
107
|
+
add(X[k * 3], X[k * 3 + 1], X[k * 3 + 2]);
|
|
108
|
+
if ((d[k] > eps && d[m] < -eps) || (d[k] < -eps && d[m] > eps)) {
|
|
109
|
+
const t = d[k] / (d[k] - d[m]);
|
|
110
|
+
add(X[k * 3] + (X[m * 3] - X[k * 3]) * t, X[k * 3 + 1] + (X[m * 3 + 1] - X[k * 3 + 1]) * t, X[k * 3 + 2] + (X[m * 3 + 2] - X[k * 3 + 2]) * t);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return [lo, hi];
|
|
114
|
+
};
|
|
115
|
+
const [a0, a1] = interval(A, dA), [b0, b1] = interval(B, dB);
|
|
116
|
+
const ll = Math.hypot(Lx, Ly, Lz) || 1;
|
|
117
|
+
const overlap = (Math.min(a1, b1) - Math.max(a0, b0)) / ll;
|
|
118
|
+
// one shared corner: the planes' line runs through it and both intervals contain it; more than a point in common is a fold
|
|
119
|
+
return shared === 1 ? overlap > eps : overlap >= -eps;
|
|
120
|
+
}
|
|
@@ -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;
|