topotopo 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +10 -10
- package/README.md +460 -117
- package/dist/cli.js +323 -146
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/bake.d.ts +14 -3
- package/dist/core/bake.js +153 -4
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +76 -3
- package/dist/core/decimate.d.ts +65 -0
- package/dist/core/decimate.js +409 -3
- package/dist/core/erosion.d.ts +37 -0
- package/dist/core/erosion.js +41 -1
- package/dist/core/geometry.d.ts +5 -1
- package/dist/core/geometry.js +203 -3
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/intrinsics.d.ts +7 -0
- package/dist/core/intrinsics.js +94 -0
- package/dist/core/manifold.d.ts +12 -1
- package/dist/core/manifold.js +78 -6
- package/dist/core/materials.d.ts +7 -0
- package/dist/core/materials.js +45 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/repair.d.ts +2 -0
- package/dist/core/repair.js +2 -0
- package/dist/core/report.d.ts +70 -0
- package/dist/core/report.js +275 -0
- package/dist/core/scene.js +2 -1
- package/dist/core/sha256.d.ts +4 -0
- package/dist/core/sha256.js +69 -0
- package/dist/core/shapes.d.ts +3 -0
- package/dist/core/shapes.js +34 -0
- package/dist/core/snippet-lib.d.ts +14 -1
- package/dist/core/snippet-lib.js +39 -13
- package/dist/core/tangents.d.ts +2 -0
- package/dist/core/tangents.js +5 -1
- package/dist/core/texnoise.d.ts +6 -1
- package/dist/core/texnoise.js +6 -2
- package/dist/core/texsdf.d.ts +131 -0
- package/dist/core/texsdf.js +637 -0
- package/dist/core/texture.d.ts +163 -9
- package/dist/core/texture.js +844 -20
- package/dist/core/topology.d.ts +10 -0
- package/dist/core/topology.js +168 -0
- package/dist/core/unwrap.d.ts +72 -0
- package/dist/core/unwrap.js +800 -0
- package/dist/core/usercode.d.ts +27 -0
- package/dist/core/usercode.js +87 -0
- package/dist/core/uv.d.ts +4 -18
- package/dist/core/uv.js +35 -188
- package/dist/core/uvislands.d.ts +62 -0
- package/dist/core/uvislands.js +574 -0
- package/dist/core/uvoverlap.d.ts +58 -0
- package/dist/core/uvoverlap.js +220 -0
- package/dist/core/uvpack.d.ts +64 -0
- package/dist/core/uvpack.js +628 -0
- package/dist/core/uvreport.d.ts +61 -0
- package/dist/core/uvreport.js +207 -143
- package/dist/core/wrangle.d.ts +6 -1
- package/dist/core/wrangle.js +27 -16
- package/dist/core/xatlas.d.ts +16 -1
- package/dist/core/xatlas.js +66 -62
- package/dist/engines.d.ts +63 -0
- package/dist/engines.js +180 -0
- package/dist/explain.d.ts +4 -3
- package/dist/explain.js +129 -12
- package/dist/graph/engine.d.ts +92 -29
- package/dist/graph/engine.js +298 -148
- package/dist/graph/expr.d.ts +6 -3
- package/dist/graph/expr.js +18 -8
- package/dist/graph/outputs.d.ts +23 -0
- package/dist/graph/outputs.js +41 -0
- package/dist/graph/packages.d.ts +72 -0
- package/dist/graph/packages.js +261 -0
- package/dist/graph/parallel.d.ts +3 -1
- package/dist/graph/parallel.js +4 -1
- package/dist/graph/params.d.ts +6 -0
- package/dist/graph/params.js +34 -7
- package/dist/graph/scope.d.ts +55 -0
- package/dist/graph/scope.js +14 -0
- package/dist/graph/types.d.ts +75 -12
- package/dist/graph/types.js +4 -2
- package/dist/graph/vars.d.ts +16 -0
- package/dist/graph/vars.js +80 -0
- package/dist/host/artifacts.d.ts +10 -1
- package/dist/host/artifacts.js +37 -6
- package/dist/host/cook.d.ts +241 -0
- package/dist/host/cook.js +844 -0
- package/dist/host/export-targets.d.ts +42 -5
- package/dist/host/export-targets.js +72 -13
- package/dist/host/godot-commands.d.ts +4 -0
- package/dist/host/godot-commands.js +21 -0
- package/dist/host/godot.d.ts +183 -0
- package/dist/host/godot.js +916 -0
- package/dist/host/node.d.ts +12 -7
- package/dist/host/node.js +27 -9
- package/dist/host/pool.js +51 -2
- package/dist/host/sidecars.d.ts +8 -0
- package/dist/host/sidecars.js +50 -0
- package/dist/host/types.d.ts +19 -6
- package/dist/host/version.d.ts +1 -0
- package/dist/host/version.js +3 -0
- package/dist/host/worker.js +5 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/inspect.d.ts +80 -2
- package/dist/inspect.js +265 -30
- package/dist/io/common.d.ts +25 -5
- package/dist/io/export.js +2 -1
- package/dist/io/files.d.ts +23 -4
- package/dist/io/files.js +60 -8
- package/dist/io/gltf.js +134 -47
- package/dist/io/heightmap.d.ts +3 -0
- package/dist/io/heightmap.js +1 -0
- package/dist/io/import.js +10 -0
- package/dist/io/inspect-scene.d.ts +55 -0
- package/dist/io/inspect-scene.js +155 -0
- package/dist/io/kinds.d.ts +81 -0
- package/dist/io/kinds.js +163 -0
- package/dist/io/points.d.ts +2 -1
- package/dist/io/points.js +3 -1
- package/dist/io/sidecars.d.ts +24 -0
- package/dist/io/sidecars.js +57 -0
- package/dist/io/source.d.ts +65 -0
- package/dist/io/source.js +112 -0
- package/dist/io/targets.d.ts +47 -3
- package/dist/io/targets.js +148 -13
- package/dist/io/textures.js +21 -1
- package/dist/io/unreal.js +5 -1
- package/dist/mcp/docs.d.ts +10 -1
- package/dist/mcp/docs.js +786 -143
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +56 -27
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +196 -103
- package/dist/mcp/verify.d.ts +2 -2
- package/dist/mcp/verify.js +1 -1
- package/dist/mcp/workspace.d.ts +15 -0
- package/dist/mcp/workspace.js +349 -0
- package/dist/nodes/attributes.js +198 -1
- package/dist/nodes/bake.js +151 -47
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +51 -3
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +21 -9
- package/dist/nodes/curves.js +433 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +12 -38
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.js +16 -19
- package/dist/nodes/index.d.ts +1 -0
- package/dist/nodes/index.js +1 -0
- package/dist/nodes/material.js +89 -24
- package/dist/nodes/measure.js +43 -17
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.js +4 -2
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/splines.d.ts +15 -1
- package/dist/nodes/splines.js +112 -105
- package/dist/nodes/texture.d.ts +21 -6
- package/dist/nodes/texture.js +1318 -185
- package/dist/nodes/topology.d.ts +7 -0
- package/dist/nodes/topology.js +133 -6
- package/dist/nodes/transform.js +6 -2
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +5 -1
- package/dist/open.d.ts +19 -0
- package/dist/open.js +12 -0
- package/dist/package.d.ts +288 -0
- package/dist/package.js +772 -0
- package/dist/packages/check.d.ts +32 -0
- package/dist/packages/check.js +169 -0
- package/dist/packages/commands.d.ts +57 -0
- package/dist/packages/commands.js +537 -0
- package/dist/packages/registry.d.ts +796 -0
- package/dist/packages/registry.js +2998 -0
- package/dist/packages/update.d.ts +124 -0
- package/dist/packages/update.js +476 -0
- package/dist/render/options.d.ts +2 -0
- package/dist/render/options.js +44 -5
- package/dist/render/preview.d.ts +15 -4
- package/dist/render/preview.js +6 -4
- package/dist/render/raster.d.ts +66 -5
- package/dist/render/raster.js +506 -138
- package/dist/render/texview.d.ts +6 -0
- package/dist/render/texview.js +27 -0
- package/dist/scan.d.ts +61 -0
- package/dist/scan.js +228 -0
- package/dist/session.d.ts +311 -0
- package/dist/session.js +849 -0
- package/dist/viewer/app/api.js +48 -6
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +27 -7
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +5 -1
- package/dist/viewer/app/guides.js +122 -0
- package/dist/viewer/app/keymap.js +6 -3
- package/dist/viewer/app/layers.js +4 -4
- package/dist/viewer/app/main.js +185 -52
- package/dist/viewer/app/markers.js +60 -0
- package/dist/viewer/app/outliner.js +72 -27
- package/dist/viewer/app/output-info.js +45 -0
- package/dist/viewer/app/outputs.css +147 -8
- package/dist/viewer/app/outputs.js +168 -54
- package/dist/viewer/app/packages.js +614 -0
- package/dist/viewer/app/props.js +176 -52
- package/dist/viewer/app/scene.js +30 -5
- package/dist/viewer/app/select.js +4 -3
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +65 -7
- package/dist/viewer/app/vars.js +47 -0
- package/dist/viewer/app/welcome.js +72 -0
- package/dist/viewer/graph-file.d.ts +62 -0
- package/dist/viewer/graph-file.js +175 -0
- package/dist/viewer/index.html +23 -10
- package/dist/viewer/json-edit.d.ts +13 -0
- package/dist/viewer/json-edit.js +274 -0
- package/dist/viewer/outputs.d.ts +49 -5
- package/dist/viewer/outputs.js +264 -56
- package/dist/viewer/packages.d.ts +121 -0
- package/dist/viewer/packages.js +584 -0
- package/dist/viewer/server.d.ts +14 -9
- package/dist/viewer/server.js +266 -28
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/{gallery → web}/bake.d.ts +4 -4
- package/dist/{gallery → web}/bake.js +24 -15
- package/dist/web/folder-page.d.ts +101 -0
- package/dist/web/folder-page.js +146 -0
- package/dist/web/folders.d.ts +280 -0
- package/dist/web/folders.js +970 -0
- package/dist/web/library.d.ts +91 -0
- package/dist/web/library.js +228 -0
- package/dist/web/markdown.d.ts +45 -0
- package/dist/web/markdown.js +677 -0
- package/dist/web/pages.d.ts +258 -0
- package/dist/web/pages.js +301 -0
- package/dist/web/server.d.ts +24 -0
- package/dist/web/server.js +1068 -0
- package/dist/workspace.d.ts +88 -118
- package/dist/workspace.js +358 -460
- package/integrations/godot/addons/topotopo/LICENSE +202 -0
- package/integrations/godot/addons/topotopo/README.md +57 -0
- package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
- package/integrations/godot/addons/topotopo/dock.gd +266 -0
- package/integrations/godot/addons/topotopo/dock.tscn +72 -0
- package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
- package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
- package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
- package/integrations/godot/addons/topotopo/inspector.gd +38 -0
- package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
- package/integrations/godot/addons/topotopo/package.gd +23 -0
- package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
- package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
- package/integrations/godot/addons/topotopo/plugin.gd +970 -0
- package/integrations/godot/addons/topotopo/record.gd +435 -0
- package/integrations/godot/addons/topotopo/runner.gd +458 -0
- package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
- package/integrations/godot/addons/topotopo/watcher.gd +199 -0
- package/kernels/pkg/README.md +2 -1
- package/kernels/pkg-simd/README.md +2 -1
- package/library/architecture/versions/1.0/architecture.topo +12 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
- package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
- package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
- package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
- package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
- package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
- package/library/architecture/versions/1.0/version.json +1119 -0
- package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
- package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
- package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
- package/library/nature/versions/1.0/graphs/lineup.json +24 -0
- package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
- package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
- package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
- package/library/nature/versions/1.0/nature.topo +12 -0
- package/library/nature/versions/1.0/version.json +534 -0
- package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
- package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
- package/library/props/versions/1.0/graphs/lineup.json +18 -0
- package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
- package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
- package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
- package/library/props/versions/1.0/props.topo +12 -0
- package/library/props/versions/1.0/version.json +336 -0
- package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
- package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
- package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
- package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
- package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
- package/library/street/versions/1.0/graphs/lineup.json +22 -0
- package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
- package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
- package/library/street/versions/1.0/street.topo +12 -0
- package/library/street/versions/1.0/version.json +421 -0
- package/package.json +17 -8
- package/dist/gallery/app/gallery.css +0 -100
- package/dist/gallery/app/gallery.js +0 -80
- package/dist/gallery/cli.d.ts +0 -4
- package/dist/gallery/cli.js +0 -157
- package/dist/gallery/library.d.ts +0 -124
- package/dist/gallery/library.js +0 -366
- package/dist/gallery/pages.d.ts +0 -94
- package/dist/gallery/pages.js +0 -148
- package/dist/gallery/server.d.ts +0 -21
- package/dist/gallery/server.js +0 -391
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/dist/mcp/library.d.ts +0 -12
- package/dist/mcp/library.js +0 -159
- package/shelf/index.json +0 -190
package/dist/core/uvreport.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export interface UVOverlap {
|
|
|
19
19
|
prims: [number, number];
|
|
20
20
|
area: number;
|
|
21
21
|
sameChart: boolean;
|
|
22
|
+
/** inTile (two atlas charts), tiling (a tiling chart) or acrossLods (different LODs) */
|
|
23
|
+
kind: 'inTile' | 'tiling' | 'acrossLods';
|
|
24
|
+
/** where the two prims are: "prim 12 of "barrel" (group …) at (x, y, z)" (core/report.ts) */
|
|
25
|
+
where: [string, string];
|
|
22
26
|
}
|
|
23
27
|
export interface UVPiece {
|
|
24
28
|
name: string;
|
|
@@ -27,8 +31,33 @@ export interface UVPiece {
|
|
|
27
31
|
uvArea: number;
|
|
28
32
|
texelsPerMetre?: number;
|
|
29
33
|
}
|
|
34
|
+
export interface UVOverlapClass {
|
|
35
|
+
pairs: number;
|
|
36
|
+
area: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Texel density of atlas charts (tiling charts are left out): sqrt(uv area / surface area), in texels per metre with a
|
|
40
|
+
* resolution (times sqrt(width · height)), else in uv units per metre. overall: all charts together; p05 / median / p95:
|
|
41
|
+
* per chart, weighted by surface area; min / max: over charts holding at least 0.1 % of the surface, with where they are.
|
|
42
|
+
*/
|
|
43
|
+
export interface UVDensity {
|
|
44
|
+
unit: 'texels/m' | 'uv/m';
|
|
45
|
+
charts: number;
|
|
46
|
+
overall: number;
|
|
47
|
+
p05: number;
|
|
48
|
+
median: number;
|
|
49
|
+
p95: number;
|
|
50
|
+
min: number;
|
|
51
|
+
max: number;
|
|
52
|
+
lowest: string | null;
|
|
53
|
+
highest: string | null;
|
|
54
|
+
}
|
|
30
55
|
export interface UVReport {
|
|
31
56
|
attribute: string;
|
|
57
|
+
/** charts run across tile borders: uv for a repeating texture, not an atlas (their overlaps are overlap.tiling) */
|
|
58
|
+
tiling: boolean;
|
|
59
|
+
/** how many charts run across tile borders */
|
|
60
|
+
tilingCharts: number;
|
|
32
61
|
/** false when uv is missing or a bound stopped the analysis early; reasons lists why */
|
|
33
62
|
complete: boolean;
|
|
34
63
|
reasons: string[];
|
|
@@ -37,6 +66,10 @@ export interface UVReport {
|
|
|
37
66
|
nonFinite: number;
|
|
38
67
|
collapsed: number;
|
|
39
68
|
collapsedTriangles: number[];
|
|
69
|
+
/** where the first collapsed triangle is (its prim's part and the triangle's centre), or null */
|
|
70
|
+
firstCollapsed: string | null;
|
|
71
|
+
/** where the first triangle outside the unit tile is, or null */
|
|
72
|
+
firstOutOfTile: string | null;
|
|
40
73
|
/** triangles with uv winding opposite to the majority (mirrored islands are legal; listed for review) */
|
|
41
74
|
mirrored: number;
|
|
42
75
|
outOfTile: number;
|
|
@@ -44,12 +77,19 @@ export interface UVReport {
|
|
|
44
77
|
tiles: string[];
|
|
45
78
|
charts: number;
|
|
46
79
|
uvArea: number;
|
|
80
|
+
/**
|
|
81
|
+
* pairs / area: every overlapping triangle pair; inTile: between atlas charts (what a bake suffers); tiling: a tiling
|
|
82
|
+
* chart is involved (expected); acrossLods: prims of different LODs (expected); examples: inTile pairs first
|
|
83
|
+
*/
|
|
47
84
|
overlap: {
|
|
48
85
|
pairs: number;
|
|
49
86
|
sameChartPairs: number;
|
|
50
87
|
area: number;
|
|
51
88
|
candidatePairs: number;
|
|
52
89
|
testedPairs: number;
|
|
90
|
+
inTile: UVOverlapClass;
|
|
91
|
+
tiling: UVOverlapClass;
|
|
92
|
+
acrossLods: UVOverlapClass;
|
|
53
93
|
examples: UVOverlap[];
|
|
54
94
|
};
|
|
55
95
|
utilization: {
|
|
@@ -58,9 +98,30 @@ export interface UVReport {
|
|
|
58
98
|
rasterSize?: number;
|
|
59
99
|
note: string;
|
|
60
100
|
};
|
|
101
|
+
/** with charts in several tiles and no overlaps: the exact covered share of each tile (UDIM number 1001 + u + 10 v) */
|
|
102
|
+
tileUtilization: {
|
|
103
|
+
tile: number;
|
|
104
|
+
value: number;
|
|
105
|
+
}[];
|
|
106
|
+
/** texel density of the atlas charts (null without any) */
|
|
107
|
+
density: UVDensity | null;
|
|
61
108
|
pieces: UVPiece[];
|
|
62
109
|
resolution?: [number, number];
|
|
63
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Per triangle: 0 = its chart lies in the unit tile, 1 = in one other integer tile (a UDIM tile), 2 = its chart runs
|
|
113
|
+
* across tile borders (a tiling chart). U: 6 uv numbers per triangle; root: the chart of a triangle.
|
|
114
|
+
*/
|
|
115
|
+
export declare function chartKinds(U: Float64Array, nt: number, root: (t: number) => number): Uint8Array;
|
|
116
|
+
/**
|
|
117
|
+
* Charts: triangles joined across uv-continuous edges (both corners share the point and the uv). Returns the chart root
|
|
118
|
+
* of a triangle. U: 6 uv numbers per triangle (corner order of tris).
|
|
119
|
+
*/
|
|
120
|
+
export declare function chartRoots(vertexPoint: ArrayLike<number>, tris: ArrayLike<number>, U: Float64Array, nt: number): (t: number) => number;
|
|
121
|
+
/** The LOD of a name: "barrel_lod1" → 1, "crate_LOD0" → 0, "rock.lod2" → 2; -1 without such a suffix. */
|
|
122
|
+
export declare function lodOf(name: string): number;
|
|
123
|
+
/** Per prim its LOD from the prim "name" (lodOf), or null when no name carries a LOD suffix. */
|
|
124
|
+
export declare function primLods(g: Geometry): Int32Array | null;
|
|
64
125
|
export declare function uvReport(g: Geometry, o?: UVReportOptions, tri?: Triangulation): UVReport;
|
|
65
126
|
/** Short text form of a report for inspect. */
|
|
66
127
|
export declare function uvReportText(r: UVReport): string[];
|
package/dist/core/uvreport.js
CHANGED
|
@@ -1,34 +1,102 @@
|
|
|
1
1
|
import { triangulate } from './topology.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
for (let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
import { primWhere } from './report.js';
|
|
3
|
+
import { COLLAPSED_Q, uvOverlapPairs } from './uvoverlap.js';
|
|
4
|
+
/**
|
|
5
|
+
* Per triangle: 0 = its chart lies in the unit tile, 1 = in one other integer tile (a UDIM tile), 2 = its chart runs
|
|
6
|
+
* across tile borders (a tiling chart). U: 6 uv numbers per triangle; root: the chart of a triangle.
|
|
7
|
+
*/
|
|
8
|
+
export function chartKinds(U, nt, root) {
|
|
9
|
+
const eps = 1e-9, tileOf = new Map(), out = new Uint8Array(nt);
|
|
10
|
+
const triTile = (t) => {
|
|
11
|
+
const o6 = t * 6;
|
|
12
|
+
for (let k = 0; k < 6; k++)
|
|
13
|
+
if (!Number.isFinite(U[o6 + k]))
|
|
14
|
+
return null;
|
|
15
|
+
const tu = Math.floor((U[o6] + U[o6 + 2] + U[o6 + 4]) / 3), tv = Math.floor((U[o6 + 1] + U[o6 + 3] + U[o6 + 5]) / 3);
|
|
16
|
+
for (let k = 0; k < 3; k++) {
|
|
17
|
+
const u = U[o6 + k * 2], v = U[o6 + k * 2 + 1];
|
|
18
|
+
if (u < tu - eps || u > tu + 1 + eps || v < tv - eps || v > tv + 1 + eps)
|
|
19
|
+
return 'x';
|
|
20
|
+
}
|
|
21
|
+
return `${tu},${tv}`;
|
|
22
|
+
};
|
|
23
|
+
const tt = new Array(nt);
|
|
24
|
+
for (let t = 0; t < nt; t++) {
|
|
25
|
+
const k = (tt[t] = triTile(t));
|
|
26
|
+
if (k === null)
|
|
27
|
+
continue;
|
|
28
|
+
const r = root(t), have = tileOf.get(r);
|
|
29
|
+
if (have === undefined)
|
|
30
|
+
tileOf.set(r, k);
|
|
31
|
+
else if (have !== k)
|
|
32
|
+
tileOf.set(r, 'x');
|
|
33
|
+
}
|
|
34
|
+
for (let t = 0; t < nt; t++) {
|
|
35
|
+
if (tt[t] === null)
|
|
36
|
+
continue;
|
|
37
|
+
const k = tileOf.get(root(t));
|
|
38
|
+
out[t] = k === 'x' ? 2 : k === '0,0' ? 0 : 1;
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Charts: triangles joined across uv-continuous edges (both corners share the point and the uv). Returns the chart root
|
|
44
|
+
* of a triangle. U: 6 uv numbers per triangle (corner order of tris).
|
|
45
|
+
*/
|
|
46
|
+
export function chartRoots(vertexPoint, tris, U, nt) {
|
|
47
|
+
const parent = Int32Array.from({ length: nt }, (_, i) => i);
|
|
48
|
+
const find = (x) => { while (parent[x] !== x) {
|
|
49
|
+
parent[x] = parent[parent[x]];
|
|
50
|
+
x = parent[x];
|
|
51
|
+
} return x; };
|
|
52
|
+
const cornerKey = (c) => `${vertexPoint[tris[c]]}:${U[c * 2]}:${U[c * 2 + 1]}`;
|
|
53
|
+
const corner = new Map(), cid = new Int32Array(nt * 3);
|
|
54
|
+
for (let c = 0; c < nt * 3; c++) {
|
|
55
|
+
const k = cornerKey(c);
|
|
56
|
+
let id = corner.get(k);
|
|
57
|
+
if (id === undefined) {
|
|
58
|
+
id = corner.size;
|
|
59
|
+
corner.set(k, id);
|
|
60
|
+
}
|
|
61
|
+
cid[c] = id;
|
|
62
|
+
}
|
|
63
|
+
const edgeOwner = new Map(), nc = corner.size;
|
|
64
|
+
for (let t = 0; t < nt; t++) {
|
|
65
|
+
if (!Number.isFinite(U[t * 6]) || !Number.isFinite(U[t * 6 + 2]) || !Number.isFinite(U[t * 6 + 4]))
|
|
66
|
+
continue;
|
|
67
|
+
for (let k = 0; k < 3; k++) {
|
|
68
|
+
const x = cid[t * 3 + k], y = cid[t * 3 + ((k + 1) % 3)];
|
|
69
|
+
const key = Math.min(x, y) * nc + Math.max(x, y);
|
|
70
|
+
const other = edgeOwner.get(key);
|
|
71
|
+
if (other === undefined)
|
|
72
|
+
edgeOwner.set(key, t);
|
|
73
|
+
else {
|
|
74
|
+
const ra = find(t), rb = find(other);
|
|
75
|
+
if (ra !== rb)
|
|
76
|
+
parent[rb] = ra;
|
|
20
77
|
}
|
|
21
78
|
}
|
|
22
|
-
poly = out;
|
|
23
79
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
80
|
+
return find;
|
|
81
|
+
}
|
|
82
|
+
/** The LOD of a name: "barrel_lod1" → 1, "crate_LOD0" → 0, "rock.lod2" → 2; -1 without such a suffix. */
|
|
83
|
+
export function lodOf(name) {
|
|
84
|
+
const m = /[_.-]lod(\d+)$/i.exec(name);
|
|
85
|
+
return m ? Number(m[1]) : -1;
|
|
86
|
+
}
|
|
87
|
+
/** Per prim its LOD from the prim "name" (lodOf), or null when no name carries a LOD suffix. */
|
|
88
|
+
export function primLods(g) {
|
|
89
|
+
const na = g.prims.get('name');
|
|
90
|
+
if (!na || na.type !== 'string')
|
|
91
|
+
return null;
|
|
92
|
+
const out = new Int32Array(g.numPrims);
|
|
93
|
+
let any = false;
|
|
94
|
+
for (let p = 0; p < g.numPrims; p++) {
|
|
95
|
+
out[p] = lodOf(String(na.get(p) ?? ''));
|
|
96
|
+
if (out[p] >= 0)
|
|
97
|
+
any = true;
|
|
30
98
|
}
|
|
31
|
-
return
|
|
99
|
+
return any ? out : null;
|
|
32
100
|
}
|
|
33
101
|
export function uvReport(g, o = {}, tri = triangulate(g)) {
|
|
34
102
|
const name = o.attribute || 'uv';
|
|
@@ -36,10 +104,10 @@ export function uvReport(g, o = {}, tri = triangulate(g)) {
|
|
|
36
104
|
const res = o.resolution === undefined ? undefined : Array.isArray(o.resolution) ? [o.resolution[0], o.resolution[1]] : [o.resolution, o.resolution];
|
|
37
105
|
const { tris, triPrim } = tri, nt = tris.length / 3;
|
|
38
106
|
const rep = {
|
|
39
|
-
attribute: name, complete: true, reasons: [], missing: false, triangles: nt, nonFinite: 0, collapsed: 0, collapsedTriangles: [], mirrored: 0,
|
|
107
|
+
attribute: name, tiling: false, tilingCharts: 0, complete: true, reasons: [], missing: false, triangles: nt, nonFinite: 0, collapsed: 0, collapsedTriangles: [], firstCollapsed: null, firstOutOfTile: null, mirrored: 0,
|
|
40
108
|
outOfTile: 0, tiles: [], charts: 0, uvArea: 0,
|
|
41
|
-
overlap: { pairs: 0, sameChartPairs: 0, area: 0, candidatePairs: 0, testedPairs: 0, examples: [] },
|
|
42
|
-
utilization: { method: 'none', value: 0, note: '' }, pieces: [], ...(res ? { resolution: res } : {}),
|
|
109
|
+
overlap: { pairs: 0, sameChartPairs: 0, area: 0, candidatePairs: 0, testedPairs: 0, inTile: { pairs: 0, area: 0 }, tiling: { pairs: 0, area: 0 }, acrossLods: { pairs: 0, area: 0 }, examples: [] },
|
|
110
|
+
utilization: { method: 'none', value: 0, note: '' }, tileUtilization: [], density: null, pieces: [], ...(res ? { resolution: res } : {}),
|
|
43
111
|
};
|
|
44
112
|
const f = g.findAttrib(name, ['vertex', 'point']);
|
|
45
113
|
if (!f || f.attr.type !== 'float' || f.attr.isArray) {
|
|
@@ -50,6 +118,12 @@ export function uvReport(g, o = {}, tri = triangulate(g)) {
|
|
|
50
118
|
return rep;
|
|
51
119
|
}
|
|
52
120
|
const a = f.attr, d = a.data, sz = a.size;
|
|
121
|
+
/** a triangle in words: its prim's part, at the triangle's centre in world space */
|
|
122
|
+
const triWhere = (t) => {
|
|
123
|
+
const P = g.P, i0 = g.vertexPoint[tris[t * 3]] * 3, i1 = g.vertexPoint[tris[t * 3 + 1]] * 3, i2 = g.vertexPoint[tris[t * 3 + 2]] * 3;
|
|
124
|
+
const c = [0, 1, 2].map((k) => (P[i0 + k] + P[i1 + k] + P[i2 + k]) / 3);
|
|
125
|
+
return primWhere(g, triPrim[t], c);
|
|
126
|
+
};
|
|
53
127
|
const U = new Float64Array(nt * 6);
|
|
54
128
|
for (let c = 0; c < nt * 3; c++) {
|
|
55
129
|
const v = tris[c], i = (f.cls === 'vertex' ? v : g.vertexPoint[v]) * sz;
|
|
@@ -79,12 +153,17 @@ export function uvReport(g, o = {}, tri = triangulate(g)) {
|
|
|
79
153
|
}
|
|
80
154
|
const cu = (U[o6] + U[o6 + 2] + U[o6 + 4]) / 3, cv = (U[o6 + 1] + U[o6 + 3] + U[o6 + 5]) / 3;
|
|
81
155
|
tiles.add(`${Math.floor(cu)},${Math.floor(cv)}`);
|
|
82
|
-
if (!inside)
|
|
156
|
+
if (!inside) {
|
|
83
157
|
rep.outOfTile++;
|
|
158
|
+
if (rep.firstOutOfTile === null)
|
|
159
|
+
rep.firstOutOfTile = triWhere(t);
|
|
160
|
+
}
|
|
84
161
|
if (!(Math.abs(cr) > COLLAPSED_Q * e2)) {
|
|
85
162
|
rep.collapsed++;
|
|
86
163
|
if (rep.collapsedTriangles.length < maxEx)
|
|
87
164
|
rep.collapsedTriangles.push(t);
|
|
165
|
+
if (rep.firstCollapsed === null)
|
|
166
|
+
rep.firstCollapsed = triWhere(t);
|
|
88
167
|
continue;
|
|
89
168
|
}
|
|
90
169
|
ok[t] = 1;
|
|
@@ -98,62 +177,27 @@ export function uvReport(g, o = {}, tri = triangulate(g)) {
|
|
|
98
177
|
rep.mirrored = Math.min(pos, neg);
|
|
99
178
|
rep.tiles = [...tiles].sort((x, y) => { const [a0, a1] = x.split(',').map(Number), [b0, b1] = y.split(',').map(Number); return a1 - b1 || a0 - b0; });
|
|
100
179
|
// charts: union triangles across uv-continuous edges (same two points, same uv at both)
|
|
101
|
-
const
|
|
102
|
-
const find = (x) => { while (parent[x] !== x) {
|
|
103
|
-
parent[x] = parent[parent[x]];
|
|
104
|
-
x = parent[x];
|
|
105
|
-
} return x; };
|
|
106
|
-
const cornerKey = (c) => `${g.vertexPoint[tris[c]]}:${U[c * 2]}:${U[c * 2 + 1]}`;
|
|
107
|
-
const corner = new Map(), cid = new Int32Array(nt * 3);
|
|
108
|
-
for (let c = 0; c < nt * 3; c++) {
|
|
109
|
-
const k = cornerKey(c);
|
|
110
|
-
let id = corner.get(k);
|
|
111
|
-
if (id === undefined) {
|
|
112
|
-
id = corner.size;
|
|
113
|
-
corner.set(k, id);
|
|
114
|
-
}
|
|
115
|
-
cid[c] = id;
|
|
116
|
-
}
|
|
117
|
-
const edgeOwner = new Map(), nc = corner.size;
|
|
118
|
-
for (let t = 0; t < nt; t++) {
|
|
119
|
-
if (!Number.isFinite(U[t * 6]) || !Number.isFinite(U[t * 6 + 2]) || !Number.isFinite(U[t * 6 + 4]))
|
|
120
|
-
continue;
|
|
121
|
-
for (let k = 0; k < 3; k++) {
|
|
122
|
-
const x = cid[t * 3 + k], y = cid[t * 3 + ((k + 1) % 3)];
|
|
123
|
-
const key = Math.min(x, y) * nc + Math.max(x, y);
|
|
124
|
-
const other = edgeOwner.get(key);
|
|
125
|
-
if (other === undefined)
|
|
126
|
-
edgeOwner.set(key, t);
|
|
127
|
-
else {
|
|
128
|
-
const ra = find(t), rb = find(other);
|
|
129
|
-
if (ra !== rb)
|
|
130
|
-
parent[rb] = ra;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
180
|
+
const find = chartRoots(g.vertexPoint, tris, U, nt);
|
|
134
181
|
const roots = new Set();
|
|
135
182
|
for (let t = 0; t < nt; t++)
|
|
136
183
|
if (Number.isFinite(U[t * 6]) && Number.isFinite(U[t * 6 + 2]) && Number.isFinite(U[t * 6 + 4]))
|
|
137
184
|
roots.add(find(t));
|
|
138
185
|
rep.charts = roots.size;
|
|
139
|
-
//
|
|
186
|
+
// tiling charts (across tile borders) and the LOD of each prim, to classify the overlaps below
|
|
187
|
+
const kind = chartKinds(U, nt, find);
|
|
188
|
+
const tilingRoots = new Set();
|
|
189
|
+
for (let t = 0; t < nt; t++)
|
|
190
|
+
if (kind[t] === 2)
|
|
191
|
+
tilingRoots.add(find(t));
|
|
192
|
+
rep.tilingCharts = tilingRoots.size;
|
|
193
|
+
rep.tiling = tilingRoots.size > 0;
|
|
194
|
+
const lod = primLods(g);
|
|
195
|
+
const classOf = (ta, tb) => kind[ta] === 2 || kind[tb] === 2 ? 'tiling' : lod && lod[triPrim[ta]] >= 0 && lod[triPrim[tb]] >= 0 && lod[triPrim[ta]] !== lod[triPrim[tb]] ? 'acrossLods' : 'inTile';
|
|
196
|
+
// overlaps: grid candidates, exact clipping (core/uvoverlap.ts)
|
|
140
197
|
const valid = [];
|
|
141
|
-
let minU = Infinity, minV = Infinity, maxU = -Infinity, maxV = -Infinity;
|
|
142
198
|
for (let t = 0; t < nt; t++)
|
|
143
|
-
if (ok[t])
|
|
199
|
+
if (ok[t])
|
|
144
200
|
valid.push(t);
|
|
145
|
-
for (let k = 0; k < 3; k++) {
|
|
146
|
-
const u = U[t * 6 + k * 2], v = U[t * 6 + k * 2 + 1];
|
|
147
|
-
if (u < minU)
|
|
148
|
-
minU = u;
|
|
149
|
-
if (u > maxU)
|
|
150
|
-
maxU = u;
|
|
151
|
-
if (v < minV)
|
|
152
|
-
minV = v;
|
|
153
|
-
if (v > maxV)
|
|
154
|
-
maxV = v;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
201
|
const ccw = new Float64Array(nt * 6);
|
|
158
202
|
for (const t of valid) {
|
|
159
203
|
const o6 = t * 6;
|
|
@@ -170,69 +214,34 @@ export function uvReport(g, o = {}, tri = triangulate(g)) {
|
|
|
170
214
|
}
|
|
171
215
|
}
|
|
172
216
|
if (valid.length > 1) {
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
for (const t of valid) {
|
|
195
|
-
const u0 = bb[t * 4], v0 = bb[t * 4 + 1], u1 = bb[t * 4 + 2], v1 = bb[t * 4 + 3];
|
|
196
|
-
for (let y = cellOf(v0, ny, minV); y <= cellOf(v1, ny, minV); y++)
|
|
197
|
-
for (let x = cellOf(u0, nx, minU); x <= cellOf(u1, nx, minU); x++)
|
|
198
|
-
items[fill[y * nx + x]++] = t;
|
|
199
|
-
}
|
|
200
|
-
let tests = 0, stopped = false;
|
|
201
|
-
for (let c = 0; c < nx * ny; c++) {
|
|
202
|
-
const s = counts[c], e = counts[c + 1], cx = c % nx, cy = Math.floor(c / nx);
|
|
203
|
-
for (let i = s; i < e; i++)
|
|
204
|
-
for (let j = i + 1; j < e; j++) {
|
|
205
|
-
const ta = items[i], tb = items[j];
|
|
206
|
-
// bounding boxes overlap with positive extent, and this cell owns the pair
|
|
207
|
-
const lu = Math.max(bb[ta * 4], bb[tb * 4]), lv = Math.max(bb[ta * 4 + 1], bb[tb * 4 + 1]);
|
|
208
|
-
if (lu >= Math.min(bb[ta * 4 + 2], bb[tb * 4 + 2]) || lv >= Math.min(bb[ta * 4 + 3], bb[tb * 4 + 3]))
|
|
209
|
-
continue;
|
|
210
|
-
if (cellOf(lu, nx, minU) !== cx || cellOf(lv, ny, minV) !== cy)
|
|
211
|
-
continue;
|
|
212
|
-
rep.overlap.candidatePairs++;
|
|
213
|
-
if (tests >= maxTests) {
|
|
214
|
-
stopped = true;
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
tests++;
|
|
218
|
-
const A = triIntersectionArea(ccw.subarray(ta * 6, ta * 6 + 6), ccw.subarray(tb * 6, tb * 6 + 6));
|
|
219
|
-
if (A > OVERLAP_REL * Math.min(Math.abs(signed[ta]), Math.abs(signed[tb]))) {
|
|
220
|
-
const t0 = Math.min(ta, tb), t1 = Math.max(ta, tb), same = find(t0) === find(t1);
|
|
221
|
-
rep.overlap.pairs++;
|
|
222
|
-
rep.overlap.area += A;
|
|
223
|
-
if (same)
|
|
224
|
-
rep.overlap.sameChartPairs++;
|
|
225
|
-
if (rep.overlap.examples.length < maxEx)
|
|
226
|
-
rep.overlap.examples.push({ triangles: [t0, t1], prims: [triPrim[t0], triPrim[t1]], area: A, sameChart: same });
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
rep.overlap.testedPairs = tests;
|
|
231
|
-
if (stopped) {
|
|
217
|
+
const scan = uvOverlapPairs(U, valid, signed, (t0, t1, A) => {
|
|
218
|
+
const same = find(t0) === find(t1), k = classOf(t0, t1);
|
|
219
|
+
rep.overlap.pairs++;
|
|
220
|
+
rep.overlap.area += A;
|
|
221
|
+
rep.overlap[k].pairs++;
|
|
222
|
+
rep.overlap[k].area += A;
|
|
223
|
+
if (same)
|
|
224
|
+
rep.overlap.sameChartPairs++;
|
|
225
|
+
// examples: the bake-relevant (inTile) pairs before the expected ones
|
|
226
|
+
const ex = { triangles: [t0, t1], prims: [triPrim[t0], triPrim[t1]], area: A, sameChart: same, kind: k, where: ['', ''] };
|
|
227
|
+
if (rep.overlap.examples.length < maxEx)
|
|
228
|
+
rep.overlap.examples.push(ex);
|
|
229
|
+
else if (k === 'inTile') {
|
|
230
|
+
const j = rep.overlap.examples.findIndex((e) => e.kind !== 'inTile');
|
|
231
|
+
if (j >= 0)
|
|
232
|
+
rep.overlap.examples[j] = ex;
|
|
233
|
+
}
|
|
234
|
+
}, { maxTests });
|
|
235
|
+
rep.overlap.candidatePairs = scan.candidatePairs;
|
|
236
|
+
rep.overlap.testedPairs = scan.testedPairs;
|
|
237
|
+
if (scan.stopped) {
|
|
232
238
|
rep.complete = false;
|
|
233
|
-
rep.reasons.push(`overlap test stopped after ${
|
|
239
|
+
rep.reasons.push(scan.reason ? `overlap test skipped: ${scan.reason}` : `overlap test stopped after ${scan.testedPairs.toLocaleString('en-US')} exact pair tests (maxPairTests) of ${scan.candidatePairs.toLocaleString('en-US')} candidate pairs`);
|
|
234
240
|
}
|
|
235
|
-
|
|
241
|
+
const rank = (e) => (e.kind === 'inTile' ? 0 : 1);
|
|
242
|
+
rep.overlap.examples.sort((x, y) => rank(x) - rank(y) || y.area - x.area || x.triangles[0] - y.triangles[0] || x.triangles[1] - y.triangles[1]);
|
|
243
|
+
for (const e of rep.overlap.examples)
|
|
244
|
+
e.where = [triWhere(e.triangles[0]), triWhere(e.triangles[1])];
|
|
236
245
|
}
|
|
237
246
|
// utilization
|
|
238
247
|
if (rep.overlap.pairs === 0 && rep.outOfTile === 0 && rep.complete) {
|
|
@@ -259,6 +268,44 @@ export function uvReport(g, o = {}, tri = triangulate(g)) {
|
|
|
259
268
|
}
|
|
260
269
|
else
|
|
261
270
|
rep.utilization = { method: 'none', value: 0, note: 'no valid uv triangles' };
|
|
271
|
+
// texel density per atlas chart, and the covered share of each tile
|
|
272
|
+
{
|
|
273
|
+
const P = g.P, vp = g.vertexPoint, surf = new Map(), area = new Map(), first = new Map();
|
|
274
|
+
const tileArea = new Map();
|
|
275
|
+
let s3 = 0, sUV = 0;
|
|
276
|
+
for (let t = 0; t < nt; t++) {
|
|
277
|
+
if (!ok[t] || kind[t] === 2)
|
|
278
|
+
continue;
|
|
279
|
+
const i0 = vp[tris[t * 3]] * 3, i1 = vp[tris[t * 3 + 1]] * 3, i2 = vp[tris[t * 3 + 2]] * 3;
|
|
280
|
+
const ux = P[i1] - P[i0], uy = P[i1 + 1] - P[i0 + 1], uz = P[i1 + 2] - P[i0 + 2], wx = P[i2] - P[i0], wy = P[i2 + 1] - P[i0 + 1], wz = P[i2 + 2] - P[i0 + 2];
|
|
281
|
+
const a3 = 0.5 * Math.hypot(uy * wz - uz * wy, uz * wx - ux * wz, ux * wy - uy * wx), aUV = Math.abs(signed[t]), r = find(t);
|
|
282
|
+
surf.set(r, (surf.get(r) ?? 0) + a3);
|
|
283
|
+
area.set(r, (area.get(r) ?? 0) + aUV);
|
|
284
|
+
if (!first.has(r))
|
|
285
|
+
first.set(r, t);
|
|
286
|
+
s3 += a3;
|
|
287
|
+
sUV += aUV;
|
|
288
|
+
const tu = Math.floor((U[t * 6] + U[t * 6 + 2] + U[t * 6 + 4]) / 3), tv = Math.floor((U[t * 6 + 1] + U[t * 6 + 3] + U[t * 6 + 5]) / 3);
|
|
289
|
+
if (tu >= 0 && tu < 10 && tv >= 0)
|
|
290
|
+
tileArea.set(1001 + tu + 10 * tv, (tileArea.get(1001 + tu + 10 * tv) ?? 0) + aUV);
|
|
291
|
+
}
|
|
292
|
+
if (s3 > 0 && sUV > 0) {
|
|
293
|
+
const k = res ? Math.sqrt(res[0] * res[1]) : 1;
|
|
294
|
+
const list = [...surf].filter(([r, a]) => a > 0 && (area.get(r) ?? 0) > 0).map(([r, a]) => ({ r, a, d: Math.sqrt(area.get(r) / a) * k })).sort((x, y) => x.d - y.d || x.r - y.r);
|
|
295
|
+
const at = (q) => { let acc = 0; for (const c of list) {
|
|
296
|
+
acc += c.a;
|
|
297
|
+
if (acc >= q * s3)
|
|
298
|
+
return c.d;
|
|
299
|
+
} return list[list.length - 1].d; };
|
|
300
|
+
const big = list.filter((c) => c.a >= s3 * 1e-3), lo = big[0] ?? list[0], hi = big[big.length - 1] ?? list[list.length - 1];
|
|
301
|
+
rep.density = {
|
|
302
|
+
unit: res ? 'texels/m' : 'uv/m', charts: list.length, overall: Math.sqrt(sUV / s3) * k, p05: at(0.05), median: at(0.5), p95: at(0.95),
|
|
303
|
+
min: lo.d, max: hi.d, lowest: triWhere(first.get(lo.r)), highest: triWhere(first.get(hi.r)),
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
if (tileArea.size > 1 && rep.overlap.inTile.pairs === 0 && rep.complete)
|
|
307
|
+
rep.tileUtilization = [...tileArea].sort((x, y) => x[0] - y[0]).map(([tile, value]) => ({ tile, value }));
|
|
308
|
+
}
|
|
262
309
|
// per-piece surface and uv area, texel density
|
|
263
310
|
const pa = g.prims.get(o.pieceAttrib || 'name');
|
|
264
311
|
if (pa && pa.type === 'string') {
|
|
@@ -290,12 +337,29 @@ export function uvReportText(r) {
|
|
|
290
337
|
const out = [`uv "${r.attribute}": ${r.complete ? 'COMPLETE' : 'INCOMPLETE'} analysis of ${r.triangles} triangles${r.reasons.length ? ` (${r.reasons.join('; ')})` : ''}`];
|
|
291
338
|
if (r.missing)
|
|
292
339
|
return out;
|
|
293
|
-
out.push(` ${r.charts} charts; tiles ${r.tiles.join(' ') || 'none'}; ${r.outOfTile} triangles outside 0..1; ${r.nonFinite} non-finite; ${r.collapsed} collapsed
|
|
340
|
+
out.push(` ${r.charts} charts; tiles ${r.tiles.join(' ') || 'none'}; ${r.outOfTile} triangles outside 0..1; ${r.nonFinite} non-finite; ${r.collapsed} collapsed; ${r.mirrored} mirrored`);
|
|
341
|
+
if (r.collapsed && r.firstCollapsed)
|
|
342
|
+
out.push(` collapsed (no uv area: bakes and normal maps have no direction there), first ${r.firstCollapsed}`);
|
|
294
343
|
const ov = r.overlap;
|
|
295
|
-
|
|
344
|
+
if (r.tiling)
|
|
345
|
+
out.push(` TILING: ${r.tilingCharts} chart${r.tilingCharts === 1 ? ' runs' : 's run'} across tile borders: uv for a repeating texture, not an atlas; overlap there is expected`);
|
|
346
|
+
out.push(` overlaps in tiles (atlas, what a bake suffers): ${ov.inTile.pairs} triangle pairs, area ${f(ov.inTile.area)}; ${ov.testedPairs} of ${ov.candidatePairs} candidate pairs tested exactly`);
|
|
347
|
+
if (ov.tiling.pairs)
|
|
348
|
+
out.push(` overlaps of tiling charts (expected): ${ov.tiling.pairs} pairs, area ${f(ov.tiling.area)}`);
|
|
349
|
+
if (ov.acrossLods.pairs)
|
|
350
|
+
out.push(` overlaps across LODs (expected: names with different _lodN suffixes share the uv space): ${ov.acrossLods.pairs} pairs, area ${f(ov.acrossLods.area)}`);
|
|
351
|
+
if (ov.sameChartPairs)
|
|
352
|
+
out.push(` ${ov.sameChartPairs} of the ${ov.pairs} overlapping pairs lie within one chart (folds)`);
|
|
296
353
|
for (const e of ov.examples.slice(0, 8))
|
|
297
|
-
out.push(`
|
|
298
|
-
out.push(` utilization ${(r.utilization.value * 100).toFixed(2)}% (${r.utilization.method}${r.utilization.rasterSize ? ` ${r.utilization.rasterSize}²` : ''}): ${r.utilization.note}; uv area ${f(r.uvArea)}`);
|
|
354
|
+
out.push(` ${e.kind === 'inTile' ? '' : `[${e.kind === 'tiling' ? 'tiling' : 'across LODs'}] `}${e.where[0]} × ${e.where[1]}${e.sameChart ? ' (same chart: a fold)' : ''}: uv area ${f(e.area)}`);
|
|
355
|
+
out.push(` utilization ${(r.utilization.value * 100).toFixed(2)}% (${r.utilization.method}${r.utilization.rasterSize ? ` ${r.utilization.rasterSize}²` : ''}): ${r.utilization.note}; uv area ${f(r.uvArea)}${r.tiling ? ' (says little for tiling uv)' : ''}`);
|
|
356
|
+
if (r.outOfTile && r.firstOutOfTile && !r.tiling)
|
|
357
|
+
out.push(` outside 0..1, first ${r.firstOutOfTile}`);
|
|
358
|
+
if (r.tileUtilization.length)
|
|
359
|
+
out.push(` utilization per tile: ${r.tileUtilization.map((t) => `${t.tile} ${(t.value * 100).toFixed(1)}%`).join(', ')}`);
|
|
360
|
+
const d = r.density;
|
|
361
|
+
if (d)
|
|
362
|
+
out.push(` texel density (${d.unit}${d.unit === 'uv/m' ? '; --uv-resolution gives texels/m' : ` at ${r.resolution[0]}×${r.resolution[1]}`}): ${f(d.overall)} over ${d.charts} charts; per chart 5% ${f(d.p05)}, median ${f(d.median)}, 95% ${f(d.p95)} (by area); lowest ${f(d.min)} at ${d.lowest}, highest ${f(d.max)} at ${d.highest}`);
|
|
299
363
|
if (r.pieces.length) {
|
|
300
364
|
const shown = r.pieces.slice(0, 24);
|
|
301
365
|
out.push(` pieces (${r.pieces.length})${r.resolution ? `, texel density at ${r.resolution[0]}×${r.resolution[1]}` : ''}:`);
|
package/dist/core/wrangle.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type { TypedArray } from './kernels.ts';
|
|
|
4
4
|
import type { Host } from '../host/types.ts';
|
|
5
5
|
import type { UserCodeError } from './usercode.ts';
|
|
6
6
|
export type RunOver = 'points' | 'prims' | 'vertices' | 'detail';
|
|
7
|
+
/** The names every wrangle defines (@ptnum … @TimeInc, also readable without the @): a graph var cannot take one. */
|
|
8
|
+
export declare const WRANGLE_NAMES: ReadonlySet<string>;
|
|
7
9
|
export interface WrangleResult {
|
|
8
10
|
geo: Geometry;
|
|
9
11
|
log: string[];
|
|
@@ -25,6 +27,7 @@ export interface WrangleOptions {
|
|
|
25
27
|
runOver: RunOver;
|
|
26
28
|
mask: Uint8Array | null;
|
|
27
29
|
inputs: Geometry[];
|
|
30
|
+
/** the cook's graph vars: those the snippet names are bound by their bare name (frozen copies) */
|
|
28
31
|
vars: Record<string, any>;
|
|
29
32
|
host: Host;
|
|
30
33
|
timeoutMs: number;
|
|
@@ -36,7 +39,8 @@ export declare function runWrangle(geo: Geometry, opts: WrangleOptions): Wrangle
|
|
|
36
39
|
* The work of a point wrangle as a kernel job for the worker pool (CookContext.parallelMap('wrangle', …)), or null
|
|
37
40
|
* when the snippet cannot run in chunks: it must run over points, bind only numeric attributes and groups, and call
|
|
38
41
|
* nothing that reads other elements or edits the geometry (point(), neighbours(), nearpoints(), addpoint(),
|
|
39
|
-
* setpointattrib(), print() … see GEOMETRY_FUNCTIONS), nor touch shared state (globalThis
|
|
42
|
+
* setpointattrib(), print() … see GEOMETRY_FUNCTIONS), nor touch shared state (globalThis). Graph vars are frozen
|
|
43
|
+
* constants in every chunk: writing one fails the same way on any thread.
|
|
40
44
|
*/
|
|
41
45
|
export interface WrangleJob {
|
|
42
46
|
count: number;
|
|
@@ -98,6 +102,7 @@ export declare class WrangleAPI {
|
|
|
98
102
|
attrtype(i: number, cls: AttribClass, name: string): string;
|
|
99
103
|
attr(i: number, cls: AttribClass, name: string, idx: number): string | number | any[];
|
|
100
104
|
primpoints(i: number, p: number): number[];
|
|
105
|
+
primintrinsic(i: number, name: string, p: number): string | number | number[];
|
|
101
106
|
pointprims(i: number, pt: number): number[];
|
|
102
107
|
neighbours(i: number, pt: number): number[];
|
|
103
108
|
private kdOf;
|