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/nodes/uv.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { defineNode } from '../graph/registry.js';
|
|
2
2
|
import { NodeError } from '../graph/types.js';
|
|
3
|
-
import { primArea, primNormals } from '../core/topology.js';
|
|
4
|
-
import { buildCharts, chartNeedsCut, cutGraph, edgeGroupTest, findIslands, lscm, normaliseCharts,
|
|
3
|
+
import { primArea, primNormals, triangulate } from '../core/topology.js';
|
|
4
|
+
import { buildCharts, chartNeedsCut, cutGraph, edgeGroupTest, findIslands, lscm, normaliseCharts, pairsWhere, pointPairTest, polygonSides, primComponents, cornerClasses, readUV, uvSeamPairs, writeUV, } from '../core/uv.js';
|
|
5
|
+
import { packCharts } from '../core/uvpack.js';
|
|
6
|
+
import { cutLongCharts, islandWeights, packsDenser, worldAngles } from '../core/uvislands.js';
|
|
7
|
+
import { uvOverlapCheck, uvPairText } from '../core/uvoverlap.js';
|
|
8
|
+
import { primWhere } from '../core/report.js';
|
|
5
9
|
import { loadXatlas, runXatlas } from '../core/xatlas.js';
|
|
10
|
+
import { unwrapMesh } from '../core/unwrap.js';
|
|
6
11
|
import { mask, P } from './util.js';
|
|
7
12
|
const SEAM_GROUP = 'seams';
|
|
8
13
|
/** Total polygon area and triangle count estimate (for the automatic chart-size limit). */
|
|
@@ -71,23 +76,108 @@ function islandsFrom(g, uv, comp, count) {
|
|
|
71
76
|
}
|
|
72
77
|
return out;
|
|
73
78
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
/** Padding in texels of `resolution` (units "uv": a fraction of the tile), at most a fifth of the tile. */
|
|
80
|
+
function paddingTexels(padding, units, resolution) {
|
|
81
|
+
const res = Math.max(1, resolution);
|
|
82
|
+
const pad = units === 'uv' ? padding * res : padding;
|
|
83
|
+
return Math.max(0, Math.min(0.2 * res, pad));
|
|
77
84
|
}
|
|
78
85
|
const LAYOUT_PARAMS = {
|
|
79
|
-
padding: { type: 'float', default: 4, min: 0, desc: 'gap between islands, in texels at `resolution` (or uv units with units:"uv")' },
|
|
86
|
+
padding: { type: 'float', default: 4, min: 0, desc: 'gap between islands, in texels at `resolution` (or uv units with units:"uv"); half of it, rounded up, to the tile border' },
|
|
80
87
|
units: { type: 'enum', options: ['texels', 'uv'], default: 'texels', desc: 'unit of padding' },
|
|
81
|
-
resolution: { type: 'int', default: 1024, min: 16, max: 16384, desc: 'texture size
|
|
88
|
+
resolution: { type: 'int', default: 1024, min: 16, max: 16384, desc: 'texture size: padding is in its texels, and islands are placed on its texel grid (at most 2048 cells per tile)' },
|
|
82
89
|
};
|
|
90
|
+
/**
|
|
91
|
+
* Lay islands out with the raster packer (core/uvpack.ts); prims in no island keep their uv and are obstacles. Texel
|
|
92
|
+
* weights, world angles and cuts come from core/uvislands.ts. The result is checked exactly (core/uvoverlap.ts):
|
|
93
|
+
* overlaps between islands (never expected: a packing bug) and overlaps inside islands (kept from the input) are
|
|
94
|
+
* reported with the parts they are in.
|
|
95
|
+
*/
|
|
96
|
+
function layoutIslands(g, uv, islands, islandOfPrim, o, warn) {
|
|
97
|
+
const res = { uv, labels: islandOfPrim, count: islands.length, cut: 0, weighted: false };
|
|
98
|
+
if (!islands.length)
|
|
99
|
+
return res;
|
|
100
|
+
const tiles = o.fit === 'udim' ? Math.max(1, Math.floor(o.tiles)) : 1;
|
|
101
|
+
const tpu = Math.max(0, o.texelsPerUnit), fixed = tpu > 0 ? tpu / Math.max(1, o.resolution) : 0, spill = fixed > 0 && o.fit === 'udim';
|
|
102
|
+
const tri = triangulate(g);
|
|
103
|
+
const pack = (labels, isls) => {
|
|
104
|
+
const per = isls.map(() => []);
|
|
105
|
+
const obstacles = [];
|
|
106
|
+
for (let t = 0; t < tri.triPrim.length; t++) {
|
|
107
|
+
const k = labels[tri.triPrim[t]];
|
|
108
|
+
if (k >= 0)
|
|
109
|
+
per[k].push(tri.tris[t * 3], tri.tris[t * 3 + 1], tri.tris[t * 3 + 2]);
|
|
110
|
+
else
|
|
111
|
+
for (let c = 0; c < 3; c++) {
|
|
112
|
+
const v = tri.tris[t * 3 + c];
|
|
113
|
+
obstacles.push(uv[v * 2], uv[v * 2 + 1]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const weights = o.texelWeight ? islandWeights(g, labels, isls.length, o.texelWeight) : null;
|
|
117
|
+
const angles = o.orient === 'world' ? worldAngles(g, uv, labels, isls.length) : null;
|
|
118
|
+
const r = packCharts(uv, isls.map((isl, k) => ({ verts: isl.verts, tris: per[k], area3: isl.area3, areaUV: isl.areaUV })), {
|
|
119
|
+
resolution: o.resolution, padding: o.padding, turns: o.orient === 'min_rect', orient: o.orient === 'min_rect' ? 'min_rect' : 'keep', scaleMode: o.scaleMode,
|
|
120
|
+
tiles, iterations: o.iterations, seed: o.seed, weights, angles, obstacles: obstacles.length ? Float64Array.from(obstacles) : null,
|
|
121
|
+
texelsPerUnit: spill ? tpu : 0, maxTexelsPerUnit: spill ? 0 : tpu,
|
|
122
|
+
});
|
|
123
|
+
return { labels, isls, r, weights, obstacles: obstacles.length > 0 };
|
|
124
|
+
};
|
|
125
|
+
let best = pack(islandOfPrim, islands);
|
|
126
|
+
res.weighted = !!best.weights;
|
|
127
|
+
if (o.cutLong) {
|
|
128
|
+
const c = cutLongCharts(g, uv, islandOfPrim, islands.length, { scaleMode: o.scaleMode, weights: best.weights, tiles, tileScale: spill ? fixed : 0, maxTileScale: spill ? 0 : fixed });
|
|
129
|
+
if (c.cut) {
|
|
130
|
+
// the parts only when they pack denser: a ring's hole often takes the small islands well enough
|
|
131
|
+
const alt = pack(c.labels, islandsFrom(g, uv, c.labels, c.count));
|
|
132
|
+
if (packsDenser(alt.r, best.r)) {
|
|
133
|
+
best = alt;
|
|
134
|
+
res.labels = c.labels;
|
|
135
|
+
res.count = c.count;
|
|
136
|
+
res.cut = c.cut;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const { labels, isls, r } = best;
|
|
141
|
+
if (!r.packed) {
|
|
142
|
+
const why = best.obstacles ? 'the prims outside the group and the padding leave no room' : `${o.padding} texels of padding at resolution ${o.resolution} leave no room`;
|
|
143
|
+
warn(`${o.node}: the ${isls.length} islands do not fit ${tiles > 1 ? `${tiles} tiles` : 'the tile'} at any scale (${why}); uv unchanged`);
|
|
144
|
+
return res;
|
|
145
|
+
}
|
|
146
|
+
res.uv = r.uv;
|
|
147
|
+
const chk = uvOverlapCheck(r.uv, tri.tris, tri.triPrim, labels);
|
|
148
|
+
if (chk.across && chk.firstAcross)
|
|
149
|
+
warn(`${o.node}: ${chk.across} triangle pairs of different islands overlap after packing; this is a bug, please report it with the graph. Largest: ${uvPairText(g, r.uv, tri.tris, tri.triPrim, chk.firstAcross.t[0], chk.firstAcross.t[1])}`);
|
|
150
|
+
if (chk.within && chk.firstWithin)
|
|
151
|
+
warn(`${o.node}: ${chk.within} overlapping triangle pairs inside islands were already in the input (folds${o.islandAttrib ? `, or pieces joined by island_attrib "${o.islandAttrib}"` : ''}); packing moves each island whole, so they stay. Largest: ${uvPairText(g, r.uv, tri.tris, tri.triPrim, chk.firstWithin.t[0], chk.firstWithin.t[1])}`);
|
|
152
|
+
const used = r.uvArea / Math.max(1, r.tilesUsed);
|
|
153
|
+
if (r.cappedBy >= 0 && used < 0.5)
|
|
154
|
+
warn(`${o.node}: islands cover ${(used * 100).toFixed(0)}% of the tile because the longest island (${primWhere(g, isls[r.cappedBy].prims[0])}) spans the tile and sets the scale; ${o.cutLong ? 'cut it with seams' : 'cut_long cuts it'} for a denser layout`);
|
|
155
|
+
if (tpu > 0 && r.texelsPerUnit < tpu * 0.999)
|
|
156
|
+
warn(`${o.node}: at ${tpu} texels per unit the islands do not fit ${tiles > 1 ? `${tiles} tiles` : 'the tile'}; packed at ${+r.texelsPerUnit.toPrecision(4)} texels per unit${o.fit === 'atlas' ? ' (fit "udim" keeps the density over more tiles)' : ' (raise udims for more tiles)'}`);
|
|
157
|
+
return res;
|
|
158
|
+
}
|
|
83
159
|
// ---------------------------------------------------------------- uv_unwrap
|
|
84
160
|
defineNode({
|
|
85
161
|
type: 'uv_unwrap',
|
|
86
162
|
category: 'uv',
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
'
|
|
90
|
-
'
|
|
163
|
+
renamed: {
|
|
164
|
+
udim: 'it is gone: fit "udim" fills UDIM tiles at the texel density (what udim: true did), fit "atlas" (the default) keeps everything in the 0..1 tile',
|
|
165
|
+
rotate_charts: 'it is now orient: "min_rect" (rotate_charts: true) or "keep" (false); "world" turns world up to +v',
|
|
166
|
+
bruteforce: 'it is gone: the packer tries `iterations` orders and keeps the tightest',
|
|
167
|
+
block_align: 'it is gone: charts are packed at the texel, with `padding` between them',
|
|
168
|
+
},
|
|
169
|
+
summary: 'Automatic UV unwrap: xatlas cuts and flattens charts per connected piece; they are packed without overlaps into the 0..1 square. Polygons are kept.',
|
|
170
|
+
description: 'Charts grow over faces of similar orientation (weights below); each chart is flattened (LSCM, planar or ortho). Every connected piece is ' +
|
|
171
|
+
'charted on its own, so a small part of a merged model unwraps as it would alone. Polygons are triangulated for xatlas; the output keeps the ' +
|
|
172
|
+
'polygons, with per-corner uv (seams split vertices, not points). A polygon xatlas cuts across two charts becomes its triangles ' +
|
|
173
|
+
'(straddling split), so its uv stays exact. Faces with no area are not charted: their uv collapses onto a neighbour\'s chart. A chart that ' +
|
|
174
|
+
'folds onto itself is charted again (xatlas at a lower cost, then a conformal map) and, if it still folds, cut where it overlaps. Thin ' +
|
|
175
|
+
'charts (bevel strips) join a neighbouring chart where their seam lines up (merge_thin); charts longer than the tile, rings and arcs are ' +
|
|
176
|
+
'cut into parts when that packs denser (cut_long). The charts are packed like uv_layout: oriented (orient), on the texel grid of ' +
|
|
177
|
+
'`resolution`, `padding` texels apart, uniform texel density times the texel_weight attribute, never overlapping, into the 0..1 tile ' +
|
|
178
|
+
'(fit atlas) or more tiles at a fixed texels_per_unit (fit udim or stack); the result is checked and every warning names the part. Big ' +
|
|
179
|
+
'smooth meshes chart slowly: max_chart_area -1 (auto) limits chart size above ~1000 triangles; a higher max_cost makes fewer, larger ' +
|
|
180
|
+
'charts (less padding). Writes prim chart (and atlas with fit stack).',
|
|
91
181
|
aliases: ['uvunwrap', 'autouv', 'xatlas', 'uv_auto', 'unwrap'],
|
|
92
182
|
inputs: [{ name: 'geo', desc: 'polygon geometry (polylines are skipped)' }],
|
|
93
183
|
params: {
|
|
@@ -101,17 +191,20 @@ defineNode({
|
|
|
101
191
|
texture_seam_weight: { type: 'float', default: 0.5, min: 0, desc: 'weight of existing texture seams' },
|
|
102
192
|
max_cost: { type: 'float', default: 2, min: 0.01, desc: 'a chart stops growing when the weighted cost exceeds this; lower = more, flatter charts' },
|
|
103
193
|
max_iterations: { type: 'int', default: 1, min: 1, max: 16, desc: 'chart growing/seeding iterations (higher = better charts, slower)' },
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
194
|
+
straddling: { type: 'enum', options: ['split', 'unfold'], default: 'split', desc: 'a polygon xatlas cuts across charts: split = it becomes its triangles, each with its chart\'s exact uv; unfold = it stays one polygon, its other corners mapped onto its main chart (can overlap a neighbour)' },
|
|
195
|
+
padding: { type: 'int', default: 2, min: 0, max: 64, desc: 'texels between charts (half of it, rounded up, to the tile border)' },
|
|
196
|
+
resolution: { type: 'int', default: 1024, min: 16, max: 16384, desc: 'texture size: padding is in its texels and charts are placed on its texel grid' },
|
|
197
|
+
texels_per_unit: { type: 'float', default: 0, min: 0, desc: 'texel density (texels per world unit); 0 = the largest density at which every chart fits one tile' },
|
|
198
|
+
fit: { type: 'enum', options: ['atlas', 'udim', 'stack'], default: 'atlas', desc: 'charts that do not fit one tile at texels_per_unit: atlas = a lower density so they fit the 0..1 tile, udim = keep the density and fill more tiles to the right (1002, 1003, …), stack = more atlases all in 0..1 (prim atlas tells them apart)' },
|
|
199
|
+
orient: { type: 'enum', options: ['min_rect', 'world', 'keep'], default: 'min_rect', desc: 'chart orientation: min_rect = turned to its minimum bounding rectangle, with 90° turns while packing (densest); world = world up (+Y) points to +v (horizontal charts: +X to +u), no turns; keep = as charted. Rotations keep the uv winding' },
|
|
200
|
+
merge_thin: { type: 'bool', default: true, desc: 'join thin charts (bevel strips, narrow bands: narrower than three paddings) onto a neighbouring chart where their shared seam lines up and nothing overlaps, so fewer charts lose space to padding (and fewer seams); off = the charts as cut' },
|
|
201
|
+
cut_long: { type: 'bool', default: true, desc: 'cut charts longer than the tile, and rings and arcs whose hull is mostly empty, across their length into parts, when that packs denser (each cut is a seam); off = charts stay whole' },
|
|
202
|
+
texel_weight: { type: 'string', default: 'texel_weight', desc: 'prim attribute scaling the texel density of each chart (mean over its polygons by area; 2 = twice the texels per metre, values <= 0 count as 1, so attrib_create with a group weights those parts); missing = all 1' },
|
|
203
|
+
iterations: { type: 'int', default: 4, min: 1, max: 64, desc: 'chart orders the packer tries; the densest wins' },
|
|
111
204
|
},
|
|
112
|
-
outputs: 'vertex uv, prim chart, prim atlas (several atlases
|
|
205
|
+
outputs: 'vertex uv, prim chart, prim atlas (fit stack with several atlases)',
|
|
113
206
|
example: { type: 'uv_unwrap', in: ['geo'], params: { padding: 4, resolution: 1024 } },
|
|
114
|
-
cook: async ({ input, p, warn }) => {
|
|
207
|
+
cook: async ({ input, p, warn, stat }) => {
|
|
115
208
|
const src = input(0);
|
|
116
209
|
const g = src.clone();
|
|
117
210
|
if (!g.numPrims)
|
|
@@ -135,149 +228,54 @@ defineNode({
|
|
|
135
228
|
roundnessWeight: p.roundness, straightnessWeight: p.straightness, normalSeamWeight: p.normal_seam_weight,
|
|
136
229
|
textureSeamWeight: p.texture_seam_weight, maxCost: p.max_cost, maxIterations: Math.max(1, Math.min(16, p.max_iterations)), fixWinding: true,
|
|
137
230
|
};
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
padding: Math.max(0, p.padding),
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return Math.hypot(uy * wz - uz * wy, uz * wx - ux * wz, ux * wy - uy * wx);
|
|
154
|
-
};
|
|
155
|
-
const tileOf = (atlas) => (p.udim && res.atlasCount > 1 && atlas > 0 ? atlas : 0);
|
|
156
|
-
const nt = res.triPrim.length;
|
|
157
|
-
let straddled = 0;
|
|
158
|
-
for (let t0 = 0; t0 < nt;) {
|
|
159
|
-
const prim = res.triPrim[t0];
|
|
160
|
-
let t1 = t0;
|
|
161
|
-
while (t1 < nt && res.triPrim[t1] === prim)
|
|
162
|
-
t1++;
|
|
163
|
-
// dominant chart by area
|
|
164
|
-
const acc = new Map();
|
|
165
|
-
for (let t = t0; t < t1; t++)
|
|
166
|
-
if (res.triChart[t] >= 0)
|
|
167
|
-
acc.set(res.triChart[t], (acc.get(res.triChart[t]) ?? 0) + triArea(t) + 1e-30);
|
|
168
|
-
let best = -1, bw = -1;
|
|
169
|
-
for (const [c, a] of acc)
|
|
170
|
-
if (a > bw) {
|
|
171
|
-
bw = a;
|
|
172
|
-
best = c;
|
|
173
|
-
}
|
|
174
|
-
if (acc.size > 1)
|
|
175
|
-
straddled++;
|
|
176
|
-
if (best >= 0) {
|
|
177
|
-
primChart[prim] = best;
|
|
178
|
-
for (let t = t0; t < t1; t++) {
|
|
179
|
-
if (res.triChart[t] !== best)
|
|
180
|
-
continue;
|
|
181
|
-
primAtlas[prim] = res.triAtlas[t];
|
|
182
|
-
const du = tileOf(res.triAtlas[t]);
|
|
183
|
-
for (let k = 0; k < 3; k++) {
|
|
184
|
-
const i = t * 3 + k, v = res.tris[i];
|
|
185
|
-
uv[v * 2] = res.cornerUV[i * 2] / norm + du;
|
|
186
|
-
uv[v * 2 + 1] = res.cornerUV[i * 2 + 1] / norm;
|
|
187
|
-
assigned[v] = 1;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
// corners only in triangles of other charts: unfold across an assigned edge (similarity transform)
|
|
191
|
-
for (let pass = 0; pass < t1 - t0; pass++) {
|
|
192
|
-
let progress = false;
|
|
193
|
-
for (let t = t0; t < t1; t++) {
|
|
194
|
-
const cs = [res.tris[t * 3], res.tris[t * 3 + 1], res.tris[t * 3 + 2]];
|
|
195
|
-
const un = cs.filter((v) => !assigned[v]);
|
|
196
|
-
if (un.length !== 1)
|
|
197
|
-
continue;
|
|
198
|
-
const ks = [0, 1, 2].filter((k) => assigned[cs[k]]), ku = [0, 1, 2].find((k) => !assigned[cs[k]]);
|
|
199
|
-
const [ka, kb] = ks;
|
|
200
|
-
const sax = res.cornerUV[(t * 3 + ka) * 2], say = res.cornerUV[(t * 3 + ka) * 2 + 1];
|
|
201
|
-
const sbx = res.cornerUV[(t * 3 + kb) * 2], sby = res.cornerUV[(t * 3 + kb) * 2 + 1];
|
|
202
|
-
const scx = res.cornerUV[(t * 3 + ku) * 2], scy = res.cornerUV[(t * 3 + ku) * 2 + 1];
|
|
203
|
-
const va = cs[ka], vb = cs[kb], vc = cs[ku];
|
|
204
|
-
const dx = sbx - sax, dy = sby - say, d2 = dx * dx + dy * dy;
|
|
205
|
-
if (d2 < 1e-20)
|
|
206
|
-
continue;
|
|
207
|
-
const tx = uv[vb * 2] - uv[va * 2], ty = uv[vb * 2 + 1] - uv[va * 2 + 1];
|
|
208
|
-
// complex ratio (tx + i ty) / (dx + i dy)
|
|
209
|
-
const cr = (tx * dx + ty * dy) / d2, ci = (ty * dx - tx * dy) / d2;
|
|
210
|
-
const qx = scx - sax, qy = scy - say;
|
|
211
|
-
uv[vc * 2] = uv[va * 2] + qx * cr - qy * ci;
|
|
212
|
-
uv[vc * 2 + 1] = uv[va * 2 + 1] + qx * ci + qy * cr;
|
|
213
|
-
assigned[vc] = 1;
|
|
214
|
-
progress = true;
|
|
215
|
-
}
|
|
216
|
-
if (!progress)
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
t0 = t1;
|
|
221
|
-
}
|
|
222
|
-
// corners xatlas ignored (zero-area faces): take the uv of another corner on the same point
|
|
223
|
-
const ptUV = new Map();
|
|
224
|
-
for (let v = 0; v < nv; v++)
|
|
225
|
-
if (assigned[v] && !ptUV.has(vp[v]))
|
|
226
|
-
ptUV.set(vp[v], v);
|
|
227
|
-
let unplaced = 0;
|
|
228
|
-
for (let pr = 0; pr < g.numPrims; pr++) {
|
|
229
|
-
if (!g.primClosed[pr] || g.primSize(pr) < 3)
|
|
230
|
-
continue;
|
|
231
|
-
for (let v = g.primStart[pr]; v < g.primStart[pr + 1]; v++) {
|
|
232
|
-
if (assigned[v])
|
|
233
|
-
continue;
|
|
234
|
-
const o = ptUV.get(vp[v]);
|
|
235
|
-
if (o !== undefined) {
|
|
236
|
-
uv[v * 2] = uv[o * 2];
|
|
237
|
-
uv[v * 2 + 1] = uv[o * 2 + 1];
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
uv[v * 2] = 0;
|
|
241
|
-
uv[v * 2 + 1] = 0;
|
|
242
|
-
unplaced++;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
// charts must keep the polygon winding (fixWinding, no packing transposes, and a repack in runXatlas otherwise)
|
|
247
|
-
const chartSum = new Map();
|
|
248
|
-
for (let pr = 0; pr < g.numPrims; pr++) {
|
|
249
|
-
const c = primChart[pr];
|
|
250
|
-
if (c < 0)
|
|
251
|
-
continue;
|
|
252
|
-
const s = g.primStart[pr], e = g.primStart[pr + 1];
|
|
253
|
-
let a = 0;
|
|
254
|
-
for (let v = s; v < e; v++) {
|
|
255
|
-
const w = v + 1 < e ? v + 1 : s;
|
|
256
|
-
a += uv[v * 2] * uv[w * 2 + 1] - uv[w * 2] * uv[v * 2 + 1];
|
|
257
|
-
}
|
|
258
|
-
chartSum.set(c, (chartSum.get(c) ?? 0) + a);
|
|
259
|
-
}
|
|
260
|
-
const mirrored = [...chartSum.values()].filter((a) => a < 0).length;
|
|
261
|
-
if (mirrored)
|
|
262
|
-
warn(`${mirrored} charts are mirrored (uv winding opposite to the polygons)`);
|
|
263
|
-
writeUV(g, uv);
|
|
264
|
-
writePrimInt(g, 'chart', primChart);
|
|
265
|
-
g.prims.delete('atlas');
|
|
266
|
-
if (res.atlasCount > 1)
|
|
267
|
-
writePrimInt(g, 'atlas', primAtlas);
|
|
231
|
+
const r = unwrapMesh(X, g, {
|
|
232
|
+
chart, vertexKey, faceGroup, straddling: p.straddling === 'unfold' ? 'unfold' : 'split', resolution: Math.max(16, p.resolution || 1024),
|
|
233
|
+
padding: Math.max(0, p.padding), texelsPerUnit: Math.max(0, p.texels_per_unit), fit: p.fit, orient: p.orient, cutLong: !!p.cut_long, mergeThin: !!p.merge_thin,
|
|
234
|
+
texelWeight: String(p.texel_weight ?? ''), iterations: Math.max(1, Math.min(64, Math.floor(p.iterations) || 1)),
|
|
235
|
+
});
|
|
236
|
+
const out = r.geo;
|
|
237
|
+
writeUV(out, r.uv);
|
|
238
|
+
writePrimInt(out, 'chart', r.chart);
|
|
239
|
+
out.prims.delete('atlas');
|
|
240
|
+
if (r.atlas)
|
|
241
|
+
writePrimInt(out, 'atlas', r.atlas);
|
|
242
|
+
const at = (prim) => primWhere(out, prim);
|
|
243
|
+
const firstOf = (k) => { for (let q = 0; q < out.numPrims; q++)
|
|
244
|
+
if (r.chart[q] === k)
|
|
245
|
+
return q; return -1; };
|
|
268
246
|
let open = 0;
|
|
269
247
|
for (let pr = 0; pr < g.numPrims; pr++)
|
|
270
248
|
if (!g.primClosed[pr])
|
|
271
249
|
open++;
|
|
272
250
|
if (open)
|
|
273
|
-
warn(
|
|
274
|
-
if (
|
|
275
|
-
warn(
|
|
276
|
-
if (
|
|
277
|
-
warn(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
251
|
+
warn(`uv_unwrap: ${open} polylines skipped (only polygons are unwrapped)`);
|
|
252
|
+
if (r.degenerate || r.isolated)
|
|
253
|
+
warn(`uv_unwrap: ${r.degenerate + r.isolated} polygons have no area (xatlas cannot chart them); their uv is collapsed${r.degenerate ? ' onto a neighbour\'s chart' : ''}${r.isolated ? ` (${r.isolated} with no charted neighbour, each piece's on a spot of its own)` : ''}. First: ${primWhere(src, r.firstDegenerate)}`);
|
|
254
|
+
if (r.straddled)
|
|
255
|
+
warn(`uv_unwrap: ${r.straddled} polygons were cut across xatlas charts; ${p.straddling === 'unfold' ? 'their other corners were mapped onto the main chart (may overlap a neighbour)' : 'each became its triangles, which keep their charts\' uv'}. First: ${primWhere(src, r.firstStraddled)}`);
|
|
256
|
+
const [rc, , rs] = r.refolded;
|
|
257
|
+
if (rs)
|
|
258
|
+
warn(`uv_unwrap: ${rc} charts folded onto themselves and were charted again (xatlas at a lower cost, then a conformal map); ${rs} still folded (a crack or a cone no flat map avoids) and were cut where they overlap, into ${r.splitInto} charts`);
|
|
259
|
+
if (r.folds && r.foldPair)
|
|
260
|
+
warn(`uv_unwrap: ${r.folds} triangle pairs overlap inside charts (folds). Largest: ${uvPairText(out, r.uv, r.tris, r.triPrim, r.foldPair[0], r.foldPair[1])}`);
|
|
261
|
+
if (r.across && r.acrossPair)
|
|
262
|
+
warn(`uv_unwrap: ${r.across} triangle pairs of different charts overlap; this is a bug, please report it with the graph. Largest: ${uvPairText(out, r.uv, r.tris, r.triPrim, r.acrossPair[0], r.acrossPair[1])}`);
|
|
263
|
+
if (r.collapsed)
|
|
264
|
+
warn(`uv_unwrap: ${r.collapsed} triangles with area got no uv area (collapsed: bakes and normal maps have no direction there)`);
|
|
265
|
+
if (r.tiles > 1)
|
|
266
|
+
warn(`uv_unwrap: at ${p.texels_per_unit} texels per unit the charts fill ${r.tiles} ${p.fit === 'stack' ? 'atlases, stacked in 0..1 (see prim atlas)' : 'UDIM tiles (1001..)'}; fit "atlas" keeps one tile`);
|
|
267
|
+
if (r.cappedBy >= 0 && r.coverage < 0.5) {
|
|
268
|
+
const q = firstOf(r.cappedBy);
|
|
269
|
+
if (q >= 0)
|
|
270
|
+
warn(`uv_unwrap: charts cover ${(r.coverage * 100).toFixed(0)}% of the tile because the longest chart (${at(q)}) spans the tile and sets the scale; ${p.cut_long ? 'lower max_chart_area or max_boundary_length to cut it' : 'cut_long cuts it'}`);
|
|
271
|
+
}
|
|
272
|
+
if (p.texel_weight && p.texel_weight !== 'texel_weight' && !r.weighted)
|
|
273
|
+
warn(`uv_unwrap: texel_weight "${p.texel_weight}" is not a numeric prim attribute; every chart has weight 1`);
|
|
274
|
+
if (r.cut)
|
|
275
|
+
stat('charts cut', r.cut);
|
|
276
|
+
if (r.merged)
|
|
277
|
+
stat('thin charts joined', r.merged);
|
|
278
|
+
return out;
|
|
281
279
|
},
|
|
282
280
|
});
|
|
283
281
|
// ---------------------------------------------------------------- uv_flatten
|
|
@@ -372,7 +370,10 @@ defineNode({
|
|
|
372
370
|
let out = uv;
|
|
373
371
|
if (p.layout && islands.length) {
|
|
374
372
|
const fresh = islandsFrom(g, uv, comp, charts.length);
|
|
375
|
-
out =
|
|
373
|
+
out = layoutIslands(g, uv, fresh, comp, {
|
|
374
|
+
orient: 'min_rect', scaleMode: 'uniform', padding: paddingTexels(p.padding, p.units, p.resolution), resolution: p.resolution,
|
|
375
|
+
fit: 'atlas', tiles: 1, texelsPerUnit: 0, iterations: 4, seed: 0, texelWeight: 'texel_weight', cutLong: false, node: 'uv_flatten',
|
|
376
|
+
}, warn).uv;
|
|
376
377
|
}
|
|
377
378
|
writeUV(g, out);
|
|
378
379
|
if (gm) {
|
|
@@ -395,26 +396,38 @@ defineNode({
|
|
|
395
396
|
defineNode({
|
|
396
397
|
type: 'uv_layout',
|
|
397
398
|
category: 'uv',
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
'
|
|
399
|
+
renamed: { rotate: 'it is now orient: "min_rect" (rotate: true) or "keep" (false); "world" turns world up to +v' },
|
|
400
|
+
summary: 'Pack UV islands into the 0..1 square (or UDIM tiles) without overlaps: rotate to minimal bounds (or keep, or align to the world), equalise texel density, fill every gap.',
|
|
401
|
+
description: 'Islands are polygon regions whose uv is continuous across shared edges, or the values of island_attrib. Each island is oriented ' +
|
|
402
|
+
'(orient: its minimum-area bounding rectangle, as it is, or world up to +v), scaled so texel density is uniform (scale_mode uniform: uv ' +
|
|
403
|
+
'area ∝ 3D area, times the texel_weight attribute) and placed on the texel grid of `resolution`: bottom-left, into any gap its shape ' +
|
|
404
|
+
'fits (inside rings, between the arms of other islands), `padding` texels from every other island and half of it from the tile border, ' +
|
|
405
|
+
'so islands never overlap. The scale is the largest at which every island fits (or texels_per_unit); iterations tries other island ' +
|
|
406
|
+
'orders and keeps the densest. fit atlas keeps everything in the 0..1 tile; fit udim fills UDIM tiles 1001, 1002, … (u offset, ten per ' +
|
|
407
|
+
'row; an island goes to the first tile it fits), up to udims. cut_long cuts islands longer than the tile, and rings and arcs, into parts ' +
|
|
408
|
+
'when the parts pack denser (each cut is a seam). Prims outside `group` keep their uv and the islands keep clear of them. The result is checked: overlaps ' +
|
|
409
|
+
'inside an island (folds, or pieces joined by island_attrib) come from the input and are reported with the part they are in; islands ' +
|
|
410
|
+
'that do not fit at any scale leave the uv unchanged, with a warning.',
|
|
402
411
|
aliases: ['uvlayout', 'uvpack', 'uv_pack', 'pack_uv'],
|
|
403
412
|
inputs: [{ name: 'geo', desc: 'geometry with uv' }],
|
|
404
413
|
params: {
|
|
405
414
|
island_attrib: { type: 'string', default: '', desc: 'prim attribute defining islands (e.g. "chart"); "" = connected uv regions' },
|
|
406
|
-
group: P.group('prim', 'prims to lay out
|
|
407
|
-
|
|
415
|
+
group: P.group('prim', 'prims to lay out; the others keep their uv and the islands keep clear of them (with padding)'),
|
|
416
|
+
orient: { type: 'enum', options: ['min_rect', 'keep', 'world'], default: 'min_rect', desc: 'island orientation: min_rect = turned to its minimum bounding rectangle, with 90° turns while packing (densest); keep = as it is, no turns; world = world up (+Y) points to +v (horizontal islands: +X to +u), no turns. Rotations keep the uv winding' },
|
|
408
417
|
scale_mode: { type: 'enum', options: ['uniform', 'keep'], default: 'uniform', desc: 'uniform = same texel density on every island (by 3D area); keep = keep the relative uv scale' },
|
|
418
|
+
texel_weight: { type: 'string', default: 'texel_weight', desc: 'prim attribute scaling the texel density of each island (mean over its polygons by area; 2 = twice the texels per metre, values <= 0 count as 1, so attrib_create with a group weights those parts); missing = all 1' },
|
|
409
419
|
...LAYOUT_PARAMS,
|
|
410
|
-
|
|
411
|
-
|
|
420
|
+
texels_per_unit: { type: 'float', default: 0, min: 0, desc: 'texel density at `resolution` (texels per world unit with scale_mode uniform); 0 = the largest at which every island fits' },
|
|
421
|
+
fit: { type: 'enum', options: ['atlas', 'udim'], default: 'atlas', desc: 'atlas = everything in the 0..1 tile (a texels_per_unit too high for it is lowered, with a warning); udim = UDIM tiles 1001, 1002, …: the islands keep texels_per_unit and spill into more tiles (up to udims), or fill udims tiles at the largest scale' },
|
|
422
|
+
udims: { type: 'int', default: 1, min: 1, max: 100, desc: 'fit udim: the most UDIM tiles to fill' },
|
|
423
|
+
cut_long: { type: 'bool', default: true, desc: 'cut islands longer than the tile, and rings and arcs whose hull is mostly empty, across their length into parts, when that packs denser (each cut is a seam; prim island tells the parts apart); off = islands stay whole' },
|
|
424
|
+
iterations: { type: 'int', default: 4, min: 1, max: 64, desc: 'island orders tried (longest side first, then tallest, largest box, largest area, then shuffles by seed); the densest wins' },
|
|
412
425
|
seed: P.seed(),
|
|
413
426
|
write_island: { type: 'bool', default: true, desc: 'write prim int attribute island' },
|
|
414
427
|
},
|
|
415
428
|
outputs: 'vertex uv, prim island',
|
|
416
429
|
example: { type: 'uv_layout', in: ['geo'], params: { padding: 8, resolution: 2048 } },
|
|
417
|
-
cook: ({ input, p, warn }) => {
|
|
430
|
+
cook: ({ input, p, warn, stat }) => {
|
|
418
431
|
const g = input(0).clone();
|
|
419
432
|
const uv = readUV(g);
|
|
420
433
|
if (!uv)
|
|
@@ -429,13 +442,18 @@ defineNode({
|
|
|
429
442
|
warn(`island_attrib "${p.island_attrib}" is not a numeric prim attribute; using uv connectivity`);
|
|
430
443
|
}
|
|
431
444
|
const { islands, islandOfPrim } = findIslands(g, uv, attr, gm);
|
|
432
|
-
const out =
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
445
|
+
const out = layoutIslands(g, uv, islands, islandOfPrim, {
|
|
446
|
+
orient: p.orient, scaleMode: p.scale_mode, padding: paddingTexels(p.padding, p.units, p.resolution), resolution: p.resolution,
|
|
447
|
+
fit: p.fit, tiles: p.udims, texelsPerUnit: Math.max(0, p.texels_per_unit), iterations: p.iterations, seed: Math.floor(Number(p.seed) || 0),
|
|
448
|
+
texelWeight: String(p.texel_weight ?? ''), cutLong: !!p.cut_long, node: 'uv_layout', islandAttrib: attr ? p.island_attrib : undefined,
|
|
449
|
+
}, warn);
|
|
450
|
+
if (p.texel_weight && p.texel_weight !== 'texel_weight' && !out.weighted)
|
|
451
|
+
warn(`uv_layout: texel_weight "${p.texel_weight}" is not a numeric prim attribute; every island has weight 1`);
|
|
452
|
+
if (out.cut)
|
|
453
|
+
stat('islands cut', out.cut);
|
|
454
|
+
writeUV(g, out.uv);
|
|
437
455
|
if (p.write_island)
|
|
438
|
-
writePrimInt(g, 'island',
|
|
456
|
+
writePrimInt(g, 'island', out.labels);
|
|
439
457
|
return g;
|
|
440
458
|
},
|
|
441
459
|
});
|
package/dist/nodes/wasmcall.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// (the worker is replaced) and the node fails with its budget error. The worker runs the same WASM module on copies of
|
|
6
6
|
// the same arrays, so the result is the same bits. Small calls, and hosts without a pool, run here.
|
|
7
7
|
import { kernelsWasmVariant } from '../wasm/kernels.js';
|
|
8
|
+
import { NodeError, STOPPED } from '../graph/types.js';
|
|
8
9
|
/**
|
|
9
10
|
* Run a call on loaded kernels, on whichever thread. Arrays: remesh_quad positions, tris, crease_edges, locked_edges,
|
|
10
11
|
* direction_edges; erode_* height, hardness?, freeze?, rain?, initialWater? (pipe); fill_sinks height, mask?;
|
|
@@ -39,10 +40,13 @@ export async function wasmCallUnderBudget(ctx, kernels, call, arrays, size, minS
|
|
|
39
40
|
return runWasmCall(kernels, call, present);
|
|
40
41
|
budget.check();
|
|
41
42
|
try {
|
|
42
|
-
|
|
43
|
+
// a stopped cook stops the call too (its worker is replaced)
|
|
44
|
+
const r = await pool.run({ kernel: 'wasm', args: { ...call, variant: kernelsWasmVariant }, arrays: present, timeoutMs: Math.max(1, budget.left()), ...(ctx.signal ? { signal: ctx.signal } : {}) });
|
|
43
45
|
return r.value;
|
|
44
46
|
}
|
|
45
47
|
catch (e) {
|
|
48
|
+
if (e?.code === 'STOPPED')
|
|
49
|
+
throw new NodeError(STOPPED);
|
|
46
50
|
if (e?.kernel === undefined && /^kernel "wasm" timed out/.test(String(e?.message)))
|
|
47
51
|
throw budget.error();
|
|
48
52
|
// no worker could start, or the worker selected another WASM build: run it here
|
package/dist/open.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Engine } from './graph/engine.ts';
|
|
2
|
+
import { Session } from './session.ts';
|
|
3
|
+
import type { SessionOptions } from './session.ts';
|
|
4
|
+
import type { PackageUses } from './packages/registry.ts';
|
|
5
|
+
export interface OpenOptions extends SessionOptions {
|
|
6
|
+
/** packages whose working folders to follow this session */
|
|
7
|
+
follow?: string[];
|
|
8
|
+
/** the folder of TopoTopo's built-in library (default: the one TopoTopo ships) */
|
|
9
|
+
builtin?: string;
|
|
10
|
+
/** follow what other processes write into the folder (Session.watch) */
|
|
11
|
+
watch?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface Opened {
|
|
14
|
+
session: Session;
|
|
15
|
+
packages: PackageUses;
|
|
16
|
+
loaded: ReturnType<Session['load']>;
|
|
17
|
+
}
|
|
18
|
+
/** A session on `dir`, with the packages its package uses, its graphs and its assets. */
|
|
19
|
+
export declare function openPackage(engine: Engine, dir: string, o?: OpenOptions): Opened;
|
package/dist/open.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Session } from './session.js';
|
|
2
|
+
import { openPackages } from './packages/registry.js';
|
|
3
|
+
/** A session on `dir`, with the packages its package uses, its graphs and its assets. */
|
|
4
|
+
export function openPackage(engine, dir, o = {}) {
|
|
5
|
+
const packages = openPackages(engine, dir, { follow: o.follow, builtin: o.builtin });
|
|
6
|
+
const session = new Session(dir, engine, o);
|
|
7
|
+
session.packages = packages;
|
|
8
|
+
const loaded = session.load();
|
|
9
|
+
if (o.watch)
|
|
10
|
+
session.watch();
|
|
11
|
+
return { session, packages, loaded };
|
|
12
|
+
}
|