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/bevel.js
CHANGED
|
@@ -430,7 +430,72 @@ class Ctx {
|
|
|
430
430
|
}
|
|
431
431
|
// ---------------------------------------------------------------- edge bevel
|
|
432
432
|
/**
|
|
433
|
-
*
|
|
433
|
+
* Offsets of bevelled edges of one face that face each other (running opposite ways, each on the other's inner side,
|
|
434
|
+
* overlapping along their length) are scaled down until they add up to the gap between the edges. Returns how many
|
|
435
|
+
* pairs were scaled.
|
|
436
|
+
*/
|
|
437
|
+
function clampFacing(g, he, bevE, offE) {
|
|
438
|
+
const P = g.P;
|
|
439
|
+
const pt = (i) => [P[i * 3], P[i * 3 + 1], P[i * 3 + 2]];
|
|
440
|
+
let pairs = 0;
|
|
441
|
+
const nrm = [0, 0, 0];
|
|
442
|
+
for (let f = 0; f < g.numPrims; f++) {
|
|
443
|
+
const hs = he.faceHalfEdges(f).filter((h) => bevE[he.heEdge[h]]);
|
|
444
|
+
if (hs.length < 2)
|
|
445
|
+
continue;
|
|
446
|
+
primNewell(g, f, nrm);
|
|
447
|
+
const N = unit(nrm, [0, 0, 1]);
|
|
448
|
+
const seg = hs.map((h) => {
|
|
449
|
+
const a = pt(he.heOrigin[h]), b = pt(he.dest(h)), d = unit(sub(b, a), [1, 0, 0]);
|
|
450
|
+
return { e: he.heEdge[h], a, b, d, m: cross3(N, d), A: he.heOrigin[h], B: he.dest(h) };
|
|
451
|
+
});
|
|
452
|
+
for (let i = 0; i < seg.length; i++)
|
|
453
|
+
for (let j = i + 1; j < seg.length; j++) {
|
|
454
|
+
const s1 = seg[i], s2 = seg[j];
|
|
455
|
+
if (s1.A === s2.A || s1.A === s2.B || s1.B === s2.A || s1.B === s2.B)
|
|
456
|
+
continue;
|
|
457
|
+
if (dot(s1.d, s2.d) > -0.8)
|
|
458
|
+
continue; // not facing: corners between them are the corner clamp's
|
|
459
|
+
// each on the other's inner side, and overlapping along the first one's direction
|
|
460
|
+
const mid1 = scale(add(s1.a, s1.b), 0.5), mid2 = scale(add(s2.a, s2.b), 0.5);
|
|
461
|
+
if (dot(s1.m, sub(mid2, mid1)) <= 0 || dot(s2.m, sub(mid1, mid2)) <= 0)
|
|
462
|
+
continue;
|
|
463
|
+
const t0 = dot(sub(s2.a, s1.a), s1.d), t1 = dot(sub(s2.b, s1.a), s1.d), L = len(sub(s1.b, s1.a));
|
|
464
|
+
if (Math.max(t0, t1) <= 0 || Math.min(t0, t1) >= L)
|
|
465
|
+
continue;
|
|
466
|
+
const gap = segmentGap(s1.a, s1.b, s2.a, s2.b);
|
|
467
|
+
const need = offE[s1.e] + offE[s2.e];
|
|
468
|
+
if (!(need > gap) || !(gap > 0))
|
|
469
|
+
continue;
|
|
470
|
+
const k = (gap / need) * 0.999;
|
|
471
|
+
offE[s1.e] *= k;
|
|
472
|
+
offE[s2.e] *= k;
|
|
473
|
+
pairs++;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return pairs;
|
|
477
|
+
}
|
|
478
|
+
/** Smallest distance between segments ab and cd. */
|
|
479
|
+
function segmentGap(a, b, c, d) {
|
|
480
|
+
const u = sub(b, a), v = sub(d, c), w = sub(a, c);
|
|
481
|
+
const A = dot(u, u), B = dot(u, v), Cc = dot(v, v), D = dot(u, w), E = dot(v, w), den = A * Cc - B * B;
|
|
482
|
+
let s = den > 1e-30 ? (B * E - Cc * D) / den : 0, t;
|
|
483
|
+
s = Math.max(0, Math.min(1, s));
|
|
484
|
+
t = Cc > 1e-30 ? (B * s + E) / Cc : 0;
|
|
485
|
+
if (t < 0) {
|
|
486
|
+
t = 0;
|
|
487
|
+
s = A > 1e-30 ? Math.max(0, Math.min(1, -D / A)) : 0;
|
|
488
|
+
}
|
|
489
|
+
else if (t > 1) {
|
|
490
|
+
t = 1;
|
|
491
|
+
s = A > 1e-30 ? Math.max(0, Math.min(1, (B - D) / A)) : 0;
|
|
492
|
+
}
|
|
493
|
+
return len(sub(add(a, scale(u, s)), add(c, scale(v, t))));
|
|
494
|
+
}
|
|
495
|
+
/** Edges whose two faces bend less than this (degrees) are flat: the default selection leaves them alone. */
|
|
496
|
+
export const FLAT_EDGE_DEG = 0.01;
|
|
497
|
+
/**
|
|
498
|
+
* Bevel the given edges (point pairs; null = every edge used by two polygons where the surface bends). Boundary, non-manifold and
|
|
434
499
|
* inconsistently wound edges, and edges at non-manifold points, are skipped with a warning. Returns the input object
|
|
435
500
|
* itself when nothing is bevelled.
|
|
436
501
|
*/
|
|
@@ -463,7 +528,8 @@ export function bevelEdges(g, sel, opts) {
|
|
|
463
528
|
continue;
|
|
464
529
|
if (he.nonManifoldEdges.has(e))
|
|
465
530
|
nNonManifold++;
|
|
466
|
-
|
|
531
|
+
// an edge inside a flat area (a face split in two, a boolean's cut face) has nothing to bevel
|
|
532
|
+
else if (!(he.dihedralAngle(e) < FLAT_EDGE_DEG))
|
|
467
533
|
bevE[e] = 1;
|
|
468
534
|
}
|
|
469
535
|
if (nBoundary)
|
|
@@ -491,7 +557,7 @@ export function bevelEdges(g, sel, opts) {
|
|
|
491
557
|
for (let e = 0; e < ne; e++)
|
|
492
558
|
count += bevE[e];
|
|
493
559
|
if (!count) {
|
|
494
|
-
warnings.push('no edges to bevel: geometry unchanged');
|
|
560
|
+
warnings.push(sel ? 'no edges to bevel: geometry unchanged' : 'no edges to bevel: every edge is flat (both faces in one plane) or open; geometry unchanged');
|
|
495
561
|
return { geo: g, warnings, count: 0, scale: 1 };
|
|
496
562
|
}
|
|
497
563
|
const offsetMode = opts.offsetMode ?? 'distance';
|
|
@@ -507,114 +573,189 @@ export function bevelEdges(g, sel, opts) {
|
|
|
507
573
|
for (let e = 0; e < ne; e++)
|
|
508
574
|
if (bevE[e])
|
|
509
575
|
offE[e] = offsetMode === 'fraction' ? opts.offset * Math.min(minFanLen(he.edgeA[e]), minFanLen(he.edgeB[e])) : opts.offset;
|
|
576
|
+
// two bevelled edges facing each other across a narrow part of a face (the rims of a thin band) share no point, so
|
|
577
|
+
// the corner clamp below never sees them: their offsets may add up to at most the gap between them
|
|
578
|
+
let nFacing = 0;
|
|
579
|
+
if (opts.clamp ?? true)
|
|
580
|
+
nFacing = clampFacing(g, he, bevE, offE);
|
|
510
581
|
const C = new Ctx(g, opts.divisions ?? 0, opts.shape ?? 0);
|
|
511
582
|
const n = C.n;
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
const
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
const
|
|
547
|
-
|
|
548
|
-
if (
|
|
549
|
-
|
|
583
|
+
// Pass A and the crossing constraints at the current offsets: each constraint is [largest scale, its two points].
|
|
584
|
+
const analyse = () => {
|
|
585
|
+
const recs = new Map();
|
|
586
|
+
const cons = [];
|
|
587
|
+
// ---- pass A: symbolic corner chains and offset vectors at scale 1
|
|
588
|
+
for (const [v, fan] of fans) {
|
|
589
|
+
if (!fan)
|
|
590
|
+
continue;
|
|
591
|
+
const k = fan.hs.length, m = fan.edges.length;
|
|
592
|
+
const bev = new Uint8Array(m), d = new Float64Array(m), elen = new Float64Array(m);
|
|
593
|
+
const dir = [];
|
|
594
|
+
let any = false;
|
|
595
|
+
const pv = C.pt(v);
|
|
596
|
+
for (let j = 0; j < m; j++) {
|
|
597
|
+
bev[j] = bevE[fan.edges[j]];
|
|
598
|
+
if (bev[j])
|
|
599
|
+
any = true;
|
|
600
|
+
d[j] = bev[j] ? offE[fan.edges[j]] : 0;
|
|
601
|
+
const w = sub(C.pt(fan.ends[j]), pv);
|
|
602
|
+
elen[j] = len(w);
|
|
603
|
+
dir.push(unit(w, [1, 0, 0]));
|
|
604
|
+
}
|
|
605
|
+
if (!any)
|
|
606
|
+
continue;
|
|
607
|
+
const rec = {
|
|
608
|
+
fan, k, bev, d, dir, elen, slideT: new Float64Array(m).fill(NaN), elems: [],
|
|
609
|
+
slidePt: new Int32Array(m).fill(-1), chains: [], chainSrc: [],
|
|
610
|
+
};
|
|
611
|
+
const sum = new Float64Array(m), cnt = new Int32Array(m);
|
|
612
|
+
const uu = [];
|
|
613
|
+
for (let i = 0; i < k; i++) {
|
|
614
|
+
const N = C.faceN(he.heFace[fan.hs[i]]);
|
|
615
|
+
const jo = i, ji = inIdx(rec, i);
|
|
616
|
+
const uo = dir[jo], ui = dir[ji];
|
|
617
|
+
const upo = unit(sub(uo, scale(N, dot(uo, N))), uo), upi = unit(sub(ui, scale(N, dot(ui, N))), ui);
|
|
618
|
+
const mo = cross3(N, upo), mi = cross3(upi, N);
|
|
619
|
+
if (bev[jo] && bev[ji]) {
|
|
620
|
+
const sig = dot(N, cross3(upo, upi));
|
|
621
|
+
let x;
|
|
622
|
+
if (Math.abs(sig) > 1e-4)
|
|
623
|
+
x = scale(add(scale(upi, d[jo]), scale(upo, d[ji])), 1 / sig);
|
|
624
|
+
else
|
|
625
|
+
x = scale(unit(add(mi, mo), mo), (d[jo] + d[ji]) / 2);
|
|
626
|
+
rec.elems[i] = [{ k: 2, x }];
|
|
627
|
+
}
|
|
628
|
+
else if (bev[jo]) {
|
|
629
|
+
const s = dot(ui, mo);
|
|
630
|
+
sum[ji] += s > 0 ? d[jo] / Math.max(s, 0.2) : d[jo];
|
|
631
|
+
cnt[ji]++;
|
|
632
|
+
rec.elems[i] = [{ k: 1, j: ji }];
|
|
633
|
+
}
|
|
634
|
+
else if (bev[ji]) {
|
|
635
|
+
const s = dot(uo, mi);
|
|
636
|
+
sum[jo] += s > 0 ? d[ji] / Math.max(s, 0.2) : d[ji];
|
|
637
|
+
cnt[jo]++;
|
|
638
|
+
rec.elems[i] = [{ k: 1, j: jo }];
|
|
639
|
+
}
|
|
550
640
|
else
|
|
551
|
-
|
|
552
|
-
rec.elems[i] = [{ k: 2, x }];
|
|
641
|
+
uu.push(i);
|
|
553
642
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
643
|
+
for (let j = 0; j < m; j++)
|
|
644
|
+
if (cnt[j])
|
|
645
|
+
rec.slideT[j] = sum[j] / cnt[j];
|
|
646
|
+
for (const i of uu) {
|
|
647
|
+
const jo = i, ji = inIdx(rec, i);
|
|
648
|
+
const a = Number.isNaN(rec.slideT[ji]) ? { k: 0 } : { k: 1, j: ji };
|
|
649
|
+
const c = Number.isNaN(rec.slideT[jo]) ? { k: 0 } : { k: 1, j: jo };
|
|
650
|
+
rec.elems[i] = a.k === 0 && c.k === 0 ? [a] : [a, c];
|
|
559
651
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
652
|
+
recs.set(v, rec);
|
|
653
|
+
}
|
|
654
|
+
// ---- clamp: largest scale at which nothing crosses
|
|
655
|
+
const vecOf = (rec, el) => (el.k === 0 ? [0, 0, 0] : el.k === 1 ? scale(rec.dir[el.j], rec.slideT[el.j]) : el.x);
|
|
656
|
+
let lambda = Infinity;
|
|
657
|
+
let pair = [-1, -1];
|
|
658
|
+
const limit = (length, coef) => {
|
|
659
|
+
if (coef <= 1e-12)
|
|
660
|
+
return;
|
|
661
|
+
const l = length / coef;
|
|
662
|
+
if (l < lambda)
|
|
663
|
+
lambda = l;
|
|
664
|
+
if (l < 1)
|
|
665
|
+
cons.push([l, pair[0], pair[1]]);
|
|
666
|
+
};
|
|
667
|
+
for (const [v, rec] of recs) {
|
|
668
|
+
const { fan } = rec;
|
|
669
|
+
for (let j = 0; j < fan.edges.length; j++) {
|
|
670
|
+
if (rec.bev[j] || Number.isNaN(rec.slideT[j]))
|
|
671
|
+
continue;
|
|
672
|
+
const w = fan.ends[j], rw = recs.get(w);
|
|
673
|
+
let tw = 0;
|
|
674
|
+
if (rw) {
|
|
675
|
+
const jw = rw.fan.edges.indexOf(fan.edges[j]);
|
|
676
|
+
if (jw >= 0 && !Number.isNaN(rw.slideT[jw]))
|
|
677
|
+
tw = rw.slideT[jw];
|
|
678
|
+
}
|
|
679
|
+
pair = [v, w];
|
|
680
|
+
limit(rec.elen[j], rec.slideT[j] + tw);
|
|
565
681
|
}
|
|
566
|
-
else
|
|
567
|
-
uu.push(i);
|
|
568
682
|
}
|
|
569
|
-
for (let
|
|
570
|
-
if (
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
const
|
|
574
|
-
const
|
|
575
|
-
const
|
|
576
|
-
|
|
683
|
+
for (let e = 0; e < ne; e++) {
|
|
684
|
+
if (!bevE[e])
|
|
685
|
+
continue;
|
|
686
|
+
const h = he.edgeHalf[e], t = he.heTwin[h];
|
|
687
|
+
const a = he.heOrigin[h], c = he.dest(h);
|
|
688
|
+
const ra = recs.get(a), rc = recs.get(c);
|
|
689
|
+
const ja = ra.fan.hs.indexOf(h), jc = rc.fan.hs.indexOf(t);
|
|
690
|
+
const u = unit(sub(C.pt(c), C.pt(a)));
|
|
691
|
+
const L = len(sub(C.pt(c), C.pt(a)));
|
|
692
|
+
// side F_L: a's chain in face(h) (last element), c's chain in face(h) = face before jc (first element)
|
|
693
|
+
pair = [a, c];
|
|
694
|
+
const La = ra.elems[ja][ra.elems[ja].length - 1], Lc = rc.elems[faceBefore(rc, jc)][0];
|
|
695
|
+
limit(L, dot(vecOf(ra, La), u) - dot(vecOf(rc, Lc), u));
|
|
696
|
+
const Ra = ra.elems[faceBefore(ra, ja)][0], Rc = rc.elems[jc][rc.elems[jc].length - 1];
|
|
697
|
+
limit(L, dot(vecOf(ra, Ra), u) - dot(vecOf(rc, Rc), u));
|
|
577
698
|
}
|
|
578
|
-
recs
|
|
579
|
-
}
|
|
580
|
-
// ---- clamp:
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
699
|
+
return { recs, cons, lambda };
|
|
700
|
+
};
|
|
701
|
+
// ---- clamp, locally: where bevels would cross, shrink only the offsets of the edges at the points involved (a
|
|
702
|
+
// few rounds), so one short edge does not flatten every bevel of the mesh; an edge that would keep under a tenth of
|
|
703
|
+
// what the best-kept edges keep (a zero-length or tiny edge next to it) stays sharp. Whatever still crosses is
|
|
704
|
+
// clamped by one factor.
|
|
705
|
+
const clamp = opts.clamp ?? true;
|
|
706
|
+
const off0 = Float64Array.from(offE);
|
|
707
|
+
let { recs, cons, lambda } = analyse();
|
|
708
|
+
let nDropped = 0;
|
|
709
|
+
for (let round = 0; clamp && lambda < 1 && round < 8; round++) {
|
|
710
|
+
const sV = new Map();
|
|
711
|
+
const lower = (v, l) => { if (v >= 0)
|
|
712
|
+
sV.set(v, Math.min(sV.get(v) ?? 1, l)); };
|
|
713
|
+
for (const [l, p, q] of cons) {
|
|
714
|
+
lower(p, l * 0.999);
|
|
715
|
+
lower(q, l * 0.999);
|
|
716
|
+
}
|
|
717
|
+
let best = 0;
|
|
718
|
+
for (let e = 0; e < ne; e++) {
|
|
719
|
+
if (!bevE[e])
|
|
589
720
|
continue;
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
721
|
+
const f = Math.min(sV.get(he.edgeA[e]) ?? 1, sV.get(he.edgeB[e]) ?? 1);
|
|
722
|
+
if (f < 1)
|
|
723
|
+
offE[e] *= f;
|
|
724
|
+
best = Math.max(best, offE[e] / off0[e]);
|
|
725
|
+
}
|
|
726
|
+
// an edge keeping under a tenth of what the best-kept edges keep would only be a sliver: leave it sharp (a huge
|
|
727
|
+
// offset that every edge must give up evenly is not dropped)
|
|
728
|
+
for (let e = 0; e < ne; e++)
|
|
729
|
+
if (bevE[e] && offE[e] < off0[e] * 0.1 * best) {
|
|
730
|
+
bevE[e] = 0;
|
|
731
|
+
offE[e] = 0;
|
|
732
|
+
nDropped++;
|
|
596
733
|
}
|
|
597
|
-
|
|
734
|
+
({ recs, cons, lambda } = analyse());
|
|
735
|
+
}
|
|
736
|
+
let reduced = 0, minLocal = 1;
|
|
737
|
+
for (let e = 0; e < ne; e++)
|
|
738
|
+
if (bevE[e] && offE[e] < off0[e] * 0.9999) {
|
|
739
|
+
reduced++;
|
|
740
|
+
minLocal = Math.min(minLocal, offE[e] / off0[e]);
|
|
598
741
|
}
|
|
599
|
-
|
|
742
|
+
if (nFacing)
|
|
743
|
+
warnings.push(`offset reduced at ${nFacing} pair(s) of edges facing each other across a narrow face (a thin band or rim), so their bevels meet instead of crossing`);
|
|
744
|
+
if (reduced)
|
|
745
|
+
warnings.push(`offset reduced at ${reduced} edge(s) (to ${(minLocal * 100).toFixed(1)}% at least) so neighbouring bevels do not overlap; the other edges keep the full offset`);
|
|
746
|
+
if (nDropped)
|
|
747
|
+
warnings.push(`${nDropped} edge(s) left sharp: a neighbouring edge is too short to fit the bevel (zero-length edges from duplicate points? fuse first)`);
|
|
748
|
+
if (nDropped) {
|
|
749
|
+
count = 0;
|
|
750
|
+
for (let e = 0; e < ne; e++)
|
|
751
|
+
count += bevE[e];
|
|
600
752
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
const h = he.edgeHalf[e], t = he.heTwin[h];
|
|
605
|
-
const a = he.heOrigin[h], c = he.dest(h);
|
|
606
|
-
const ra = recs.get(a), rc = recs.get(c);
|
|
607
|
-
const ja = ra.fan.hs.indexOf(h), jc = rc.fan.hs.indexOf(t);
|
|
608
|
-
const u = unit(sub(C.pt(c), C.pt(a)));
|
|
609
|
-
const L = len(sub(C.pt(c), C.pt(a)));
|
|
610
|
-
// side F_L: a's chain in face(h) (last element), c's chain in face(h) = face before jc (first element)
|
|
611
|
-
const La = ra.elems[ja][ra.elems[ja].length - 1], Lc = rc.elems[faceBefore(rc, jc)][0];
|
|
612
|
-
limit(L, dot(vecOf(ra, La), u) - dot(vecOf(rc, Lc), u));
|
|
613
|
-
const Ra = ra.elems[faceBefore(ra, ja)][0], Rc = rc.elems[jc][rc.elems[jc].length - 1];
|
|
614
|
-
limit(L, dot(vecOf(ra, Ra), u) - dot(vecOf(rc, Rc), u));
|
|
753
|
+
if (!count) {
|
|
754
|
+
warnings.push('no edges to bevel: geometry unchanged');
|
|
755
|
+
return { geo: g, warnings, count: 0, scale: 0 };
|
|
615
756
|
}
|
|
616
757
|
let sc = 1;
|
|
617
|
-
if (
|
|
758
|
+
if (clamp && lambda < 1) {
|
|
618
759
|
sc = lambda * 0.999;
|
|
619
760
|
warnings.push(`offset clamped to ${(sc * 100).toFixed(1)}% so neighbouring bevels do not overlap`);
|
|
620
761
|
}
|
package/dist/core/decimate.d.ts
CHANGED
|
@@ -35,6 +35,8 @@ export interface DecimateResult {
|
|
|
35
35
|
/** attributes that were used to steer, and requested ones that could not be */
|
|
36
36
|
used: string[];
|
|
37
37
|
skipped: string[];
|
|
38
|
+
/** input point of each output point */
|
|
39
|
+
srcPoint: Int32Array;
|
|
38
40
|
}
|
|
39
41
|
export declare class DecimateError extends Error {
|
|
40
42
|
}
|
|
@@ -45,6 +47,16 @@ export declare class DecimateError extends Error {
|
|
|
45
47
|
export declare function parseSteerAttribs(spec: string): SteerAttrib[];
|
|
46
48
|
/** Decimate the (selected) polygons of g to triangles with meshoptimizer; other prims pass through. */
|
|
47
49
|
export declare function decimateMesh(g: Geometry, o: DecimateOptions): DecimateResult;
|
|
50
|
+
/**
|
|
51
|
+
* What keeps the polygons of g from reducing freely (decimateMesh keeps every discontinuity of a render vertex): per
|
|
52
|
+
* cause, how many points hold one. Causes: a vertex attribute whose corners differ at a point ('uv seams', 'hard
|
|
53
|
+
* normals (vertex N)', 'vertex <name>'), a string prim attribute or prim group that changes across it ('prim "<name>"
|
|
54
|
+
* borders', 'group "<name>" borders') and 'open borders' (edges used by one polygon). Largest first.
|
|
55
|
+
*/
|
|
56
|
+
export declare function reductionLocks(g: Geometry): {
|
|
57
|
+
cause: string;
|
|
58
|
+
points: number;
|
|
59
|
+
}[];
|
|
48
60
|
export interface PointDecimateOptions {
|
|
49
61
|
ratio: number;
|
|
50
62
|
targetCount: number;
|
|
@@ -57,3 +69,56 @@ export declare function decimatePoints(g: Geometry, o: PointDecimateOptions): {
|
|
|
57
69
|
kept: number;
|
|
58
70
|
used: string[];
|
|
59
71
|
};
|
|
72
|
+
export interface UVFolds {
|
|
73
|
+
/** overlapping uv triangle pairs, and triangles wound against the rest of their chart (flipped) */
|
|
74
|
+
pairs: number;
|
|
75
|
+
flipped: number;
|
|
76
|
+
/** per triangle of tris: in an overlapping pair or flipped */
|
|
77
|
+
bad: Uint8Array;
|
|
78
|
+
/** the largest overlapping pair (triangle ids), or null */
|
|
79
|
+
largest: [number, number] | null;
|
|
80
|
+
tris: Uint32Array;
|
|
81
|
+
triPrim: Uint32Array;
|
|
82
|
+
uv: Float64Array;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Where the uv of g overlaps itself or flips: overlapping triangle pairs (exact, core/uvoverlap.ts) and triangles
|
|
86
|
+
* whose uv winding is opposite to the majority of their chart (charts: triangles joined by uv-continuous edges, so a
|
|
87
|
+
* mirrored island as a whole is not flipped). null without uv.
|
|
88
|
+
*/
|
|
89
|
+
export declare function uvFolds(g: Geometry): UVFolds | null;
|
|
90
|
+
export interface UVKept {
|
|
91
|
+
/** the input uv had no overlaps, so the output was checked */
|
|
92
|
+
checked: boolean;
|
|
93
|
+
/** reduction steps taken, and steps dropped because they folded the uv even with the points around the folds locked */
|
|
94
|
+
steps: number;
|
|
95
|
+
dropped: number;
|
|
96
|
+
/** decimations run, and points locked around folds */
|
|
97
|
+
runs: number;
|
|
98
|
+
locked: number;
|
|
99
|
+
/** a plain (one-step) reduction of the input: its triangle count and its folds (null when it kept the uv clean) */
|
|
100
|
+
plainTris: number;
|
|
101
|
+
plainFolds: UVFolds | null;
|
|
102
|
+
plainGeo: Geometry | null;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* decimateMesh that keeps a clean uv atlas clean. meshoptimizer rejects flips in 3D only, and a kept corner keeps its
|
|
106
|
+
* uv, so a collapse can fold the uv around it (most of all where the uv map bends: bevels, curved chart borders).
|
|
107
|
+
* When the input uv has no overlaps and the plain decimation folds it (uvFolds), the reduction runs again in up to
|
|
108
|
+
* KEEP_UV_STEPS steps, the triangle count falling by the same factor each step. A step that folds the uv runs again
|
|
109
|
+
* with the points it removed around its folds locked, the rings growing (KEEP_UV_RINGS); a step that still folds is
|
|
110
|
+
* dropped (its locks stay for the next try on the same mesh; a step taken starts the next one with only the caller's
|
|
111
|
+
* locks, since the danger moves with the mesh). Every step taken is checked, so the result has no folds the input did
|
|
112
|
+
* not have; the price is a triangle count above the target where the uv held the reduction (kept.plainTris says what
|
|
113
|
+
* a plain reduction reached). keep false: the plain reduction, unchecked.
|
|
114
|
+
*/
|
|
115
|
+
export declare function decimateKeepUV(g: Geometry, o: DecimateOptions, keep?: boolean): DecimateResult & {
|
|
116
|
+
uv: UVKept;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Where and why decimateKeepUV held the reduction back, in words (the parts a plain reduction folds and its largest
|
|
120
|
+
* fold), or '' when it did not: the plain reduction kept the uv clean, or the steps reached about the same count.
|
|
121
|
+
*/
|
|
122
|
+
export declare function uvKeptText(r: DecimateResult & {
|
|
123
|
+
uv: UVKept;
|
|
124
|
+
}): string;
|