topotopo 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +40 -10
- package/README.md +475 -111
- package/dist/cli.js +328 -133
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/analysis.d.ts +5 -1
- package/dist/core/analysis.js +8 -3
- package/dist/core/bake.d.ts +16 -8
- package/dist/core/bake.js +165 -29
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +238 -97
- package/dist/core/decimate.d.ts +65 -0
- package/dist/core/decimate.js +409 -3
- package/dist/core/erosion.d.ts +37 -0
- package/dist/core/erosion.js +41 -1
- package/dist/core/geometry.d.ts +5 -1
- package/dist/core/geometry.js +204 -4
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/imageops.d.ts +6 -0
- package/dist/core/imageops.js +51 -0
- package/dist/core/intrinsics.d.ts +7 -0
- package/dist/core/intrinsics.js +94 -0
- package/dist/core/manifold.d.ts +12 -1
- package/dist/core/manifold.js +78 -6
- package/dist/core/materials.d.ts +11 -0
- package/dist/core/materials.js +56 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/packed.js +11 -0
- package/dist/core/particles.d.ts +1 -1
- package/dist/core/particles.js +1 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/rbd.js +13 -1
- package/dist/core/repair.d.ts +2 -0
- package/dist/core/repair.js +2 -0
- package/dist/core/report.d.ts +70 -0
- package/dist/core/report.js +275 -0
- package/dist/core/scatter.d.ts +1 -1
- package/dist/core/scatter.js +1 -1
- package/dist/core/scene.d.ts +20 -0
- package/dist/core/scene.js +72 -0
- package/dist/core/sha256.d.ts +4 -0
- package/dist/core/sha256.js +69 -0
- package/dist/core/shapes.d.ts +3 -0
- package/dist/core/shapes.js +34 -0
- package/dist/core/snippet-lib.d.ts +15 -2
- package/dist/core/snippet-lib.js +40 -14
- package/dist/core/solidify.d.ts +38 -0
- package/dist/core/solidify.js +356 -0
- package/dist/core/tangents.d.ts +54 -0
- package/dist/core/tangents.js +218 -0
- package/dist/core/texcoord.d.ts +4 -0
- package/dist/core/texcoord.js +14 -0
- package/dist/core/texnoise.d.ts +6 -1
- package/dist/core/texnoise.js +6 -2
- package/dist/core/texsdf.d.ts +131 -0
- package/dist/core/texsdf.js +637 -0
- package/dist/core/texture.d.ts +163 -9
- package/dist/core/texture.js +844 -20
- package/dist/core/topology.d.ts +32 -0
- package/dist/core/topology.js +238 -7
- package/dist/core/traceimage.d.ts +7 -0
- package/dist/core/traceimage.js +221 -0
- package/dist/core/tritri.d.ts +5 -0
- package/dist/core/tritri.js +120 -0
- package/dist/core/unwrap.d.ts +72 -0
- package/dist/core/unwrap.js +800 -0
- package/dist/core/usercode.d.ts +27 -0
- package/dist/core/usercode.js +87 -0
- package/dist/core/uv.d.ts +15 -16
- package/dist/core/uv.js +36 -189
- package/dist/core/uvislands.d.ts +62 -0
- package/dist/core/uvislands.js +574 -0
- package/dist/core/uvoverlap.d.ts +58 -0
- package/dist/core/uvoverlap.js +220 -0
- package/dist/core/uvpack.d.ts +64 -0
- package/dist/core/uvpack.js +628 -0
- package/dist/core/uvreport.d.ts +127 -0
- package/dist/core/uvreport.js +372 -0
- package/dist/core/wrangle.d.ts +6 -1
- package/dist/core/wrangle.js +27 -16
- package/dist/core/xatlas.d.ts +16 -1
- package/dist/core/xatlas.js +95 -61
- package/dist/engines.d.ts +63 -0
- package/dist/engines.js +180 -0
- package/dist/explain.d.ts +4 -3
- package/dist/explain.js +129 -12
- package/dist/graph/engine.d.ts +92 -29
- package/dist/graph/engine.js +298 -148
- package/dist/graph/expr.d.ts +6 -3
- package/dist/graph/expr.js +18 -8
- package/dist/graph/outputs.d.ts +23 -0
- package/dist/graph/outputs.js +41 -0
- package/dist/graph/packages.d.ts +72 -0
- package/dist/graph/packages.js +261 -0
- package/dist/graph/parallel.d.ts +3 -1
- package/dist/graph/parallel.js +4 -1
- package/dist/graph/params.d.ts +6 -0
- package/dist/graph/params.js +34 -7
- package/dist/graph/scope.d.ts +55 -0
- package/dist/graph/scope.js +14 -0
- package/dist/graph/types.d.ts +75 -12
- package/dist/graph/types.js +4 -2
- package/dist/graph/vars.d.ts +16 -0
- package/dist/graph/vars.js +80 -0
- package/dist/host/artifacts.d.ts +10 -1
- package/dist/host/artifacts.js +37 -6
- package/dist/host/cook.d.ts +241 -0
- package/dist/host/cook.js +844 -0
- package/dist/host/export-targets.d.ts +42 -5
- package/dist/host/export-targets.js +72 -13
- package/dist/host/godot-commands.d.ts +4 -0
- package/dist/host/godot-commands.js +21 -0
- package/dist/host/godot.d.ts +183 -0
- package/dist/host/godot.js +916 -0
- package/dist/host/node.d.ts +12 -7
- package/dist/host/node.js +27 -9
- package/dist/host/pool.js +51 -2
- package/dist/host/sidecars.d.ts +8 -0
- package/dist/host/sidecars.js +50 -0
- package/dist/host/types.d.ts +19 -6
- package/dist/host/version.d.ts +1 -0
- package/dist/host/version.js +3 -0
- package/dist/host/worker.js +5 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -2
- package/dist/inspect.d.ts +84 -1
- package/dist/inspect.js +271 -24
- package/dist/io/common.d.ts +33 -5
- package/dist/io/export.js +2 -1
- package/dist/io/files.d.ts +23 -4
- package/dist/io/files.js +60 -8
- package/dist/io/gltf.js +355 -51
- package/dist/io/heightmap.d.ts +3 -0
- package/dist/io/heightmap.js +1 -0
- package/dist/io/import.js +10 -0
- package/dist/io/inspect-scene.d.ts +55 -0
- package/dist/io/inspect-scene.js +155 -0
- package/dist/io/kinds.d.ts +81 -0
- package/dist/io/kinds.js +163 -0
- package/dist/io/points.d.ts +2 -1
- package/dist/io/points.js +3 -1
- package/dist/io/sidecars.d.ts +24 -0
- package/dist/io/sidecars.js +57 -0
- package/dist/io/source.d.ts +65 -0
- package/dist/io/source.js +112 -0
- package/dist/io/targets.d.ts +47 -3
- package/dist/io/targets.js +149 -14
- package/dist/io/textures.js +21 -1
- package/dist/io/unreal.js +5 -1
- package/dist/mcp/docs.d.ts +10 -1
- package/dist/mcp/docs.js +816 -119
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +70 -24
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +207 -108
- package/dist/mcp/verify.d.ts +2 -2
- package/dist/mcp/verify.js +1 -1
- package/dist/mcp/workspace.d.ts +15 -0
- package/dist/mcp/workspace.js +349 -0
- package/dist/nodes/attributes.js +198 -1
- package/dist/nodes/bake.js +207 -83
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +54 -5
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +22 -10
- package/dist/nodes/curves.js +440 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +13 -39
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.d.ts +1 -0
- package/dist/nodes/imageops.js +203 -0
- package/dist/nodes/index.d.ts +4 -0
- package/dist/nodes/index.js +4 -0
- package/dist/nodes/material.js +91 -23
- package/dist/nodes/measure.js +45 -18
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/rbd.js +1 -1
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.d.ts +1 -0
- package/dist/nodes/scene.js +55 -0
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/solidify.d.ts +1 -0
- package/dist/nodes/solidify.js +52 -0
- package/dist/nodes/splines.d.ts +15 -1
- package/dist/nodes/splines.js +112 -105
- package/dist/nodes/texture.d.ts +21 -6
- package/dist/nodes/texture.js +1318 -185
- package/dist/nodes/topology.d.ts +7 -0
- package/dist/nodes/topology.js +133 -6
- package/dist/nodes/transform.js +11 -3
- package/dist/nodes/util.d.ts +1 -1
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +6 -2
- package/dist/open.d.ts +19 -0
- package/dist/open.js +12 -0
- package/dist/package.d.ts +288 -0
- package/dist/package.js +772 -0
- package/dist/packages/check.d.ts +32 -0
- package/dist/packages/check.js +169 -0
- package/dist/packages/commands.d.ts +57 -0
- package/dist/packages/commands.js +537 -0
- package/dist/packages/registry.d.ts +796 -0
- package/dist/packages/registry.js +2998 -0
- package/dist/packages/update.d.ts +124 -0
- package/dist/packages/update.js +476 -0
- package/dist/render/options.d.ts +2 -0
- package/dist/render/options.js +44 -5
- package/dist/render/pbr.d.ts +28 -0
- package/dist/render/pbr.js +378 -0
- package/dist/render/preview.d.ts +69 -0
- package/dist/render/preview.js +26 -0
- package/dist/render/raster.d.ts +78 -7
- package/dist/render/raster.js +600 -145
- package/dist/render/texview.d.ts +7 -1
- package/dist/render/texview.js +34 -2
- package/dist/scan.d.ts +61 -0
- package/dist/scan.js +228 -0
- package/dist/session.d.ts +311 -0
- package/dist/session.js +849 -0
- package/dist/viewer/app/api.js +48 -6
- package/dist/viewer/app/camera.js +1 -1
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +100 -0
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +6 -2
- package/dist/viewer/app/guides.js +123 -1
- package/dist/viewer/app/keymap.js +7 -4
- package/dist/viewer/app/layers.js +5 -5
- package/dist/viewer/app/main.js +186 -53
- package/dist/viewer/app/markers.js +61 -1
- package/dist/viewer/app/outliner.js +72 -27
- package/dist/viewer/app/output-info.js +45 -0
- package/dist/viewer/app/outputs.css +147 -8
- package/dist/viewer/app/outputs.js +168 -54
- package/dist/viewer/app/packages.js +614 -0
- package/dist/viewer/app/props.js +177 -53
- package/dist/viewer/app/scene.js +35 -6
- package/dist/viewer/app/select.js +5 -4
- package/dist/viewer/app/selection.js +1 -1
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +66 -8
- package/dist/viewer/app/units.js +1 -1
- package/dist/viewer/app/vars.js +48 -1
- package/dist/viewer/app/welcome.js +72 -0
- package/dist/viewer/graph-file.d.ts +62 -0
- package/dist/viewer/graph-file.js +175 -0
- package/dist/viewer/index.html +24 -11
- package/dist/viewer/json-edit.d.ts +13 -0
- package/dist/viewer/json-edit.js +274 -0
- package/dist/viewer/outputs.d.ts +49 -5
- package/dist/viewer/outputs.js +264 -56
- package/dist/viewer/packages.d.ts +121 -0
- package/dist/viewer/packages.js +584 -0
- package/dist/viewer/server.d.ts +24 -7
- package/dist/viewer/server.js +289 -31
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/web/bake.d.ts +34 -0
- package/dist/web/bake.js +153 -0
- package/dist/web/folder-page.d.ts +101 -0
- package/dist/web/folder-page.js +146 -0
- package/dist/web/folders.d.ts +280 -0
- package/dist/web/folders.js +970 -0
- package/dist/web/library.d.ts +91 -0
- package/dist/web/library.js +228 -0
- package/dist/web/markdown.d.ts +45 -0
- package/dist/web/markdown.js +677 -0
- package/dist/web/pages.d.ts +258 -0
- package/dist/web/pages.js +301 -0
- package/dist/web/server.d.ts +24 -0
- package/dist/web/server.js +1068 -0
- package/dist/workspace.d.ts +88 -105
- package/dist/workspace.js +359 -375
- package/integrations/godot/addons/topotopo/LICENSE +202 -0
- package/integrations/godot/addons/topotopo/README.md +57 -0
- package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
- package/integrations/godot/addons/topotopo/dock.gd +266 -0
- package/integrations/godot/addons/topotopo/dock.tscn +72 -0
- package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
- package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
- package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
- package/integrations/godot/addons/topotopo/inspector.gd +38 -0
- package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
- package/integrations/godot/addons/topotopo/package.gd +23 -0
- package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
- package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
- package/integrations/godot/addons/topotopo/plugin.gd +970 -0
- package/integrations/godot/addons/topotopo/record.gd +435 -0
- package/integrations/godot/addons/topotopo/runner.gd +458 -0
- package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
- package/integrations/godot/addons/topotopo/watcher.gd +199 -0
- package/kernels/pkg/README.md +23 -29
- package/kernels/pkg-simd/README.md +23 -29
- package/library/architecture/versions/1.0/architecture.topo +12 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
- package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
- package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
- package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
- package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
- package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
- package/library/architecture/versions/1.0/version.json +1119 -0
- package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
- package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
- package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
- package/library/nature/versions/1.0/graphs/lineup.json +24 -0
- package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
- package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
- package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
- package/library/nature/versions/1.0/nature.topo +12 -0
- package/library/nature/versions/1.0/version.json +534 -0
- package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
- package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
- package/library/props/versions/1.0/graphs/lineup.json +18 -0
- package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
- package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
- package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
- package/library/props/versions/1.0/props.topo +12 -0
- package/library/props/versions/1.0/version.json +336 -0
- package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
- package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
- package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
- package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
- package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
- package/library/street/versions/1.0/graphs/lineup.json +22 -0
- package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
- package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
- package/library/street/versions/1.0/street.topo +12 -0
- package/library/street/versions/1.0/version.json +421 -0
- package/package.json +23 -8
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/shelf/index.json +0 -190
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { Geometry } from './geometry.ts';
|
|
2
|
+
import type { Triangulation } from './topology.ts';
|
|
3
|
+
export interface UVReportOptions {
|
|
4
|
+
/** uv attribute (vertex or point; default "uv") */
|
|
5
|
+
attribute?: string;
|
|
6
|
+
/** texture size in texels for texel density: n or [width, height] */
|
|
7
|
+
resolution?: number | [number, number];
|
|
8
|
+
/** prim string attribute naming pieces (default "name") */
|
|
9
|
+
pieceAttrib?: string;
|
|
10
|
+
/** most exact pair tests (default 4,000,000) */
|
|
11
|
+
maxPairTests?: number;
|
|
12
|
+
/** most overlap examples / collapsed triangle ids listed (default 16) */
|
|
13
|
+
maxExamples?: number;
|
|
14
|
+
/** raster estimate grid size (default 1024) */
|
|
15
|
+
rasterSize?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface UVOverlap {
|
|
18
|
+
triangles: [number, number];
|
|
19
|
+
prims: [number, number];
|
|
20
|
+
area: number;
|
|
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];
|
|
26
|
+
}
|
|
27
|
+
export interface UVPiece {
|
|
28
|
+
name: string;
|
|
29
|
+
triangles: number;
|
|
30
|
+
surfaceArea: number;
|
|
31
|
+
uvArea: number;
|
|
32
|
+
texelsPerMetre?: number;
|
|
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
|
+
}
|
|
55
|
+
export interface UVReport {
|
|
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;
|
|
61
|
+
/** false when uv is missing or a bound stopped the analysis early; reasons lists why */
|
|
62
|
+
complete: boolean;
|
|
63
|
+
reasons: string[];
|
|
64
|
+
missing: boolean;
|
|
65
|
+
triangles: number;
|
|
66
|
+
nonFinite: number;
|
|
67
|
+
collapsed: number;
|
|
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;
|
|
73
|
+
/** triangles with uv winding opposite to the majority (mirrored islands are legal; listed for review) */
|
|
74
|
+
mirrored: number;
|
|
75
|
+
outOfTile: number;
|
|
76
|
+
/** UDIM-style tiles touched: "u,v" integer pairs (0,0 is the unit tile) */
|
|
77
|
+
tiles: string[];
|
|
78
|
+
charts: number;
|
|
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
|
+
*/
|
|
84
|
+
overlap: {
|
|
85
|
+
pairs: number;
|
|
86
|
+
sameChartPairs: number;
|
|
87
|
+
area: number;
|
|
88
|
+
candidatePairs: number;
|
|
89
|
+
testedPairs: number;
|
|
90
|
+
inTile: UVOverlapClass;
|
|
91
|
+
tiling: UVOverlapClass;
|
|
92
|
+
acrossLods: UVOverlapClass;
|
|
93
|
+
examples: UVOverlap[];
|
|
94
|
+
};
|
|
95
|
+
utilization: {
|
|
96
|
+
method: 'exact' | 'raster-estimate' | 'none';
|
|
97
|
+
value: number;
|
|
98
|
+
rasterSize?: number;
|
|
99
|
+
note: string;
|
|
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;
|
|
108
|
+
pieces: UVPiece[];
|
|
109
|
+
resolution?: [number, number];
|
|
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;
|
|
125
|
+
export declare function uvReport(g: Geometry, o?: UVReportOptions, tri?: Triangulation): UVReport;
|
|
126
|
+
/** Short text form of a report for inspect. */
|
|
127
|
+
export declare function uvReportText(r: UVReport): string[];
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { triangulate } from './topology.js';
|
|
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;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
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;
|
|
98
|
+
}
|
|
99
|
+
return any ? out : null;
|
|
100
|
+
}
|
|
101
|
+
export function uvReport(g, o = {}, tri = triangulate(g)) {
|
|
102
|
+
const name = o.attribute || 'uv';
|
|
103
|
+
const maxEx = Math.max(0, Math.floor(o.maxExamples ?? 16)), maxTests = Math.max(0, Math.floor(o.maxPairTests ?? 4_000_000));
|
|
104
|
+
const res = o.resolution === undefined ? undefined : Array.isArray(o.resolution) ? [o.resolution[0], o.resolution[1]] : [o.resolution, o.resolution];
|
|
105
|
+
const { tris, triPrim } = tri, nt = tris.length / 3;
|
|
106
|
+
const rep = {
|
|
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,
|
|
108
|
+
outOfTile: 0, tiles: [], charts: 0, uvArea: 0,
|
|
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 } : {}),
|
|
111
|
+
};
|
|
112
|
+
const f = g.findAttrib(name, ['vertex', 'point']);
|
|
113
|
+
if (!f || f.attr.type !== 'float' || f.attr.isArray) {
|
|
114
|
+
rep.missing = true;
|
|
115
|
+
rep.complete = false;
|
|
116
|
+
rep.reasons.push(`no float vertex or point attribute "${name}"`);
|
|
117
|
+
rep.utilization.note = 'no uv';
|
|
118
|
+
return rep;
|
|
119
|
+
}
|
|
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
|
+
};
|
|
127
|
+
const U = new Float64Array(nt * 6);
|
|
128
|
+
for (let c = 0; c < nt * 3; c++) {
|
|
129
|
+
const v = tris[c], i = (f.cls === 'vertex' ? v : g.vertexPoint[v]) * sz;
|
|
130
|
+
U[c * 2] = d[i];
|
|
131
|
+
U[c * 2 + 1] = sz > 1 ? d[i + 1] : 0;
|
|
132
|
+
}
|
|
133
|
+
// per triangle: validity, signed area, tiles
|
|
134
|
+
const ok = new Uint8Array(nt), signed = new Float64Array(nt), tiles = new Set();
|
|
135
|
+
let pos = 0, neg = 0;
|
|
136
|
+
for (let t = 0; t < nt; t++) {
|
|
137
|
+
const o6 = t * 6;
|
|
138
|
+
let finite = true;
|
|
139
|
+
for (let k = 0; k < 6; k++)
|
|
140
|
+
if (!Number.isFinite(U[o6 + k]))
|
|
141
|
+
finite = false;
|
|
142
|
+
if (!finite) {
|
|
143
|
+
rep.nonFinite++;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const du1 = U[o6 + 2] - U[o6], dv1 = U[o6 + 3] - U[o6 + 1], du2 = U[o6 + 4] - U[o6], dv2 = U[o6 + 5] - U[o6 + 1];
|
|
147
|
+
const cr = du1 * dv2 - du2 * dv1, e2 = du1 * du1 + dv1 * dv1 + du2 * du2 + dv2 * dv2 + (du2 - du1) ** 2 + (dv2 - dv1) ** 2;
|
|
148
|
+
let inside = true;
|
|
149
|
+
for (let k = 0; k < 3; k++) {
|
|
150
|
+
const u = U[o6 + k * 2], v = U[o6 + k * 2 + 1];
|
|
151
|
+
if (u < 0 || u > 1 || v < 0 || v > 1)
|
|
152
|
+
inside = false;
|
|
153
|
+
}
|
|
154
|
+
const cu = (U[o6] + U[o6 + 2] + U[o6 + 4]) / 3, cv = (U[o6 + 1] + U[o6 + 3] + U[o6 + 5]) / 3;
|
|
155
|
+
tiles.add(`${Math.floor(cu)},${Math.floor(cv)}`);
|
|
156
|
+
if (!inside) {
|
|
157
|
+
rep.outOfTile++;
|
|
158
|
+
if (rep.firstOutOfTile === null)
|
|
159
|
+
rep.firstOutOfTile = triWhere(t);
|
|
160
|
+
}
|
|
161
|
+
if (!(Math.abs(cr) > COLLAPSED_Q * e2)) {
|
|
162
|
+
rep.collapsed++;
|
|
163
|
+
if (rep.collapsedTriangles.length < maxEx)
|
|
164
|
+
rep.collapsedTriangles.push(t);
|
|
165
|
+
if (rep.firstCollapsed === null)
|
|
166
|
+
rep.firstCollapsed = triWhere(t);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
ok[t] = 1;
|
|
170
|
+
signed[t] = cr / 2;
|
|
171
|
+
rep.uvArea += Math.abs(cr) / 2;
|
|
172
|
+
if (cr > 0)
|
|
173
|
+
pos++;
|
|
174
|
+
else
|
|
175
|
+
neg++;
|
|
176
|
+
}
|
|
177
|
+
rep.mirrored = Math.min(pos, neg);
|
|
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; });
|
|
179
|
+
// charts: union triangles across uv-continuous edges (same two points, same uv at both)
|
|
180
|
+
const find = chartRoots(g.vertexPoint, tris, U, nt);
|
|
181
|
+
const roots = new Set();
|
|
182
|
+
for (let t = 0; t < nt; t++)
|
|
183
|
+
if (Number.isFinite(U[t * 6]) && Number.isFinite(U[t * 6 + 2]) && Number.isFinite(U[t * 6 + 4]))
|
|
184
|
+
roots.add(find(t));
|
|
185
|
+
rep.charts = roots.size;
|
|
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)
|
|
197
|
+
const valid = [];
|
|
198
|
+
for (let t = 0; t < nt; t++)
|
|
199
|
+
if (ok[t])
|
|
200
|
+
valid.push(t);
|
|
201
|
+
const ccw = new Float64Array(nt * 6);
|
|
202
|
+
for (const t of valid) {
|
|
203
|
+
const o6 = t * 6;
|
|
204
|
+
if (signed[t] > 0)
|
|
205
|
+
for (let k = 0; k < 6; k++)
|
|
206
|
+
ccw[o6 + k] = U[o6 + k];
|
|
207
|
+
else {
|
|
208
|
+
ccw[o6] = U[o6];
|
|
209
|
+
ccw[o6 + 1] = U[o6 + 1];
|
|
210
|
+
ccw[o6 + 2] = U[o6 + 4];
|
|
211
|
+
ccw[o6 + 3] = U[o6 + 5];
|
|
212
|
+
ccw[o6 + 4] = U[o6 + 2];
|
|
213
|
+
ccw[o6 + 5] = U[o6 + 3];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (valid.length > 1) {
|
|
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) {
|
|
238
|
+
rep.complete = false;
|
|
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`);
|
|
240
|
+
}
|
|
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])];
|
|
245
|
+
}
|
|
246
|
+
// utilization
|
|
247
|
+
if (rep.overlap.pairs === 0 && rep.outOfTile === 0 && rep.complete) {
|
|
248
|
+
rep.utilization = { method: 'exact', value: rep.uvArea, note: 'sum of uv triangle areas in the unit tile (no overlaps, nothing outside)' };
|
|
249
|
+
}
|
|
250
|
+
else if (valid.length) {
|
|
251
|
+
const N = Math.max(16, Math.min(4096, Math.floor(o.rasterSize ?? 1024)));
|
|
252
|
+
const cov = new Uint8Array(N * N);
|
|
253
|
+
for (const t of valid) {
|
|
254
|
+
const o6 = t * 6, ax = ccw[o6] * N, ay = ccw[o6 + 1] * N, bx = ccw[o6 + 2] * N, by = ccw[o6 + 3] * N, cx = ccw[o6 + 4] * N, cy = ccw[o6 + 5] * N;
|
|
255
|
+
const x0 = Math.max(0, Math.floor(Math.min(ax, bx, cx))), x1 = Math.min(N - 1, Math.ceil(Math.max(ax, bx, cx))), y0 = Math.max(0, Math.floor(Math.min(ay, by, cy))), y1 = Math.min(N - 1, Math.ceil(Math.max(ay, by, cy)));
|
|
256
|
+
for (let y = y0; y <= y1; y++)
|
|
257
|
+
for (let x = x0; x <= x1; x++) {
|
|
258
|
+
const px = x + 0.5, py = y + 0.5;
|
|
259
|
+
if ((bx - ax) * (py - ay) - (by - ay) * (px - ax) >= 0 && (cx - bx) * (py - by) - (cy - by) * (px - bx) >= 0 && (ax - cx) * (py - cy) - (ay - cy) * (px - cx) >= 0)
|
|
260
|
+
cov[y * N + x] = 1;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
let k = 0;
|
|
264
|
+
for (let i = 0; i < cov.length; i++)
|
|
265
|
+
k += cov[i];
|
|
266
|
+
const why = [rep.overlap.pairs ? 'overlapping triangles' : '', rep.outOfTile ? 'triangles outside the unit tile (excluded from the estimate)' : '', rep.complete ? '' : 'an incomplete overlap test'].filter(Boolean).join(', ');
|
|
267
|
+
rep.utilization = { method: 'raster-estimate', value: k / (N * N), rasterSize: N, note: `ESTIMATE: fraction of ${N} × ${N} sample points of the unit tile covered (summed areas would count overlaps twice; because of ${why})` };
|
|
268
|
+
}
|
|
269
|
+
else
|
|
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
|
+
}
|
|
309
|
+
// per-piece surface and uv area, texel density
|
|
310
|
+
const pa = g.prims.get(o.pieceAttrib || 'name');
|
|
311
|
+
if (pa && pa.type === 'string') {
|
|
312
|
+
const by = new Map(), P = g.P, vp = g.vertexPoint;
|
|
313
|
+
for (let t = 0; t < nt; t++) {
|
|
314
|
+
const key = String(pa.get(triPrim[t]) ?? '');
|
|
315
|
+
let pc = by.get(key);
|
|
316
|
+
if (!pc) {
|
|
317
|
+
pc = { name: key, triangles: 0, surfaceArea: 0, uvArea: 0 };
|
|
318
|
+
by.set(key, pc);
|
|
319
|
+
}
|
|
320
|
+
const i0 = vp[tris[t * 3]] * 3, i1 = vp[tris[t * 3 + 1]] * 3, i2 = vp[tris[t * 3 + 2]] * 3;
|
|
321
|
+
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];
|
|
322
|
+
pc.triangles++;
|
|
323
|
+
pc.surfaceArea += 0.5 * Math.hypot(uy * wz - uz * wy, uz * wx - ux * wz, ux * wy - uy * wx);
|
|
324
|
+
if (ok[t])
|
|
325
|
+
pc.uvArea += Math.abs(signed[t]);
|
|
326
|
+
}
|
|
327
|
+
rep.pieces = [...by.values()].sort((x, y) => (x.name < y.name ? -1 : x.name > y.name ? 1 : 0));
|
|
328
|
+
if (res)
|
|
329
|
+
for (const pc of rep.pieces)
|
|
330
|
+
pc.texelsPerMetre = pc.surfaceArea > 0 ? Math.sqrt((pc.uvArea * res[0] * res[1]) / pc.surfaceArea) : 0;
|
|
331
|
+
}
|
|
332
|
+
return rep;
|
|
333
|
+
}
|
|
334
|
+
/** Short text form of a report for inspect. */
|
|
335
|
+
export function uvReportText(r) {
|
|
336
|
+
const f = (x) => (Math.abs(x) >= 1e-3 || x === 0 ? +x.toPrecision(4) : x.toExponential(2));
|
|
337
|
+
const out = [`uv "${r.attribute}": ${r.complete ? 'COMPLETE' : 'INCOMPLETE'} analysis of ${r.triangles} triangles${r.reasons.length ? ` (${r.reasons.join('; ')})` : ''}`];
|
|
338
|
+
if (r.missing)
|
|
339
|
+
return out;
|
|
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}`);
|
|
343
|
+
const ov = r.overlap;
|
|
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)`);
|
|
353
|
+
for (const e of ov.examples.slice(0, 8))
|
|
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}`);
|
|
363
|
+
if (r.pieces.length) {
|
|
364
|
+
const shown = r.pieces.slice(0, 24);
|
|
365
|
+
out.push(` pieces (${r.pieces.length})${r.resolution ? `, texel density at ${r.resolution[0]}×${r.resolution[1]}` : ''}:`);
|
|
366
|
+
for (const p of shown)
|
|
367
|
+
out.push(` ${p.name || '""'}: ${p.triangles} tris, surface ${f(p.surfaceArea)} m², uv ${f(p.uvArea)}${p.texelsPerMetre !== undefined ? `, ${f(p.texelsPerMetre)} texels/m` : ''}`);
|
|
368
|
+
if (r.pieces.length > shown.length)
|
|
369
|
+
out.push(` … ${r.pieces.length - shown.length} more`);
|
|
370
|
+
}
|
|
371
|
+
return out;
|
|
372
|
+
}
|
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;
|
package/dist/core/wrangle.js
CHANGED
|
@@ -6,14 +6,17 @@
|
|
|
6
6
|
// i[]@nbrs = nearpoints(0, @P, 0.5); // array attributes: f[] i[] s[] (read = copy, written back)
|
|
7
7
|
// if (@P.y < 0) removepoint(0, @ptnum);
|
|
8
8
|
// @group_top = @N.y > 0.9; // group membership
|
|
9
|
+
// @P.y += height * 0.5; // graph vars by their bare name, read-only
|
|
9
10
|
//
|
|
10
11
|
// The snippet is compiled into a kernel that loops over elements, binding each
|
|
11
|
-
// referenced attribute to a local variable and writing it back afterwards.
|
|
12
|
+
// referenced attribute to a local variable and writing it back afterwards. The graph vars
|
|
13
|
+
// the snippet names are constants of a scope around the kernel, so its own names come first.
|
|
12
14
|
import { Attribute, Geometry, defaultValueFor, isArrayType } from './geometry.js';
|
|
13
15
|
import { primCentroid, primNormals, pointNeighbors, pointPrims } from './topology.js';
|
|
16
|
+
import { primIntrinsic } from './intrinsics.js';
|
|
14
17
|
import { KDTree, TriBVH } from './spatial.js';
|
|
15
|
-
import { GEOMETRY_FUNCTIONS, REALM_CONTROL } from './snippet-lib.js';
|
|
16
|
-
import { runUserCode } from './usercode.js';
|
|
18
|
+
import { GEOMETRY_FUNCTIONS, REALM_CONTROL, scriptVarsGuard } from './snippet-lib.js';
|
|
19
|
+
import { codeVarDecl, codeVarNames, codeVarValues, runUserCode } from './usercode.js';
|
|
17
20
|
const CLASS_OF = { points: 'point', prims: 'prim', vertices: 'vertex', detail: 'detail' };
|
|
18
21
|
const PREFIX_TYPE = {
|
|
19
22
|
f: { type: 'float', size: 1 }, i: { type: 'int', size: 1 }, v: { type: 'float', size: 3 },
|
|
@@ -34,6 +37,8 @@ const KNOWN = {
|
|
|
34
37
|
};
|
|
35
38
|
const SPECIAL = new Set(['ptnum', 'primnum', 'vtxnum', 'elemnum', 'numpt', 'numprim', 'numvtx', 'numelem', 'Frame', 'Time', 'TimeInc']);
|
|
36
39
|
const TIME_REFS = ['Frame', 'Time', 'TimeInc'];
|
|
40
|
+
/** The names every wrangle defines (@ptnum … @TimeInc, also readable without the @): a graph var cannot take one. */
|
|
41
|
+
export const WRANGLE_NAMES = SPECIAL;
|
|
37
42
|
const REF = /(?<![\w$.@])([fivpus](?:\[\])?)?@([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
38
43
|
/** compiled kernels per host: a kernel belongs to its host's realm (its library globals and geometry API live there) */
|
|
39
44
|
const kernelCaches = new WeakMap();
|
|
@@ -62,7 +67,6 @@ export function runWrangle(geo, opts) {
|
|
|
62
67
|
return finishWrangle(w);
|
|
63
68
|
}
|
|
64
69
|
const CROSS_ELEMENT = new RegExp(String.raw `\b(${GEOMETRY_FUNCTIONS.join('|')}|globalThis|this|eval|Function)\b`);
|
|
65
|
-
const WRITES_VARS = /\bvars\b[^;\n]*?((?<![=!<>])=(?!=)|\+\+|--)/;
|
|
66
70
|
/**
|
|
67
71
|
* Run a wrangle, letting `par` execute a point wrangle in chunks: par(job, serial) runs the job on worker threads
|
|
68
72
|
* (or calls serial() to run it here) and may return a promise. Same result as runWrangle, bit for bit: chunks run the
|
|
@@ -81,7 +85,7 @@ export function runWrangleParallel(geo, opts, par) {
|
|
|
81
85
|
function wrangleJob(w, opts) {
|
|
82
86
|
if (w.runOver !== 'points' || w.n < 2)
|
|
83
87
|
return null;
|
|
84
|
-
if (CROSS_ELEMENT.test(w.body)
|
|
88
|
+
if (CROSS_ELEMENT.test(w.body))
|
|
85
89
|
return null;
|
|
86
90
|
const inputs = {}, outputs = {};
|
|
87
91
|
for (let i = 0; i < w.bindings.length; i++) {
|
|
@@ -95,13 +99,6 @@ function wrangleJob(w, opts) {
|
|
|
95
99
|
else
|
|
96
100
|
outputs['b' + i] = b.data;
|
|
97
101
|
}
|
|
98
|
-
let vars;
|
|
99
|
-
try {
|
|
100
|
-
vars = structuredClone(opts.vars);
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
102
|
if (opts.mask)
|
|
106
103
|
inputs.mask = opts.mask;
|
|
107
104
|
const e = w.env;
|
|
@@ -109,7 +106,8 @@ function wrangleJob(w, opts) {
|
|
|
109
106
|
count: w.n, inputs, outputs,
|
|
110
107
|
args: {
|
|
111
108
|
source: w.source, bindings: w.bindings.length, n: w.n, numpt: e.numpt, numprim: e.numprim, numvtx: e.numvtx,
|
|
112
|
-
|
|
109
|
+
// the vars the snippet reads (plain data; the worker freezes its copy)
|
|
110
|
+
frame: e.frame, time: e.time, timeInc: e.timeInc, vars: e.vars, timeoutMs: opts.timeoutMs, bodyLine: w.bodyLine, code: opts.code,
|
|
113
111
|
},
|
|
114
112
|
};
|
|
115
113
|
}
|
|
@@ -219,12 +217,16 @@ function prepareWrangle(geo, opts) {
|
|
|
219
217
|
}
|
|
220
218
|
}
|
|
221
219
|
// ---- generate kernel source
|
|
220
|
+
// the graph vars the snippet names (iteration, numiterations in a loop body …): constants of the outer function,
|
|
221
|
+
// so the kernel's own names and the snippet's locals come first
|
|
222
|
+
const varNames = codeVarNames(opts.code, opts.vars);
|
|
222
223
|
const src = [];
|
|
223
224
|
src.push('(function(__env){', '"use strict";');
|
|
225
|
+
src.push(codeVarDecl(varNames, '__env.vars', '__env.varsGuard'));
|
|
226
|
+
src.push('return (function(){');
|
|
224
227
|
// __s/__e: the element range of a chunk (the whole range when absent); numelem stays the total
|
|
225
228
|
src.push('const __n=__env.n, __s=__env.s|0, __e=__env.e===undefined?__env.n:__env.e, __mask=__env.mask, __vp=__env.vp, __vprim=__env.vprim, __B=__env.B;');
|
|
226
229
|
src.push('const numpt=__env.numpt, numprim=__env.numprim, numvtx=__env.numvtx, numelem=__n, Frame=__env.frame, Time=__env.time, TimeInc=__env.timeInc;');
|
|
227
|
-
src.push('const vars=__env.vars, iteration=vars.iteration, numiterations=vars.numiterations;');
|
|
228
230
|
src.push('let ptnum=0, primnum=0, vtxnum=0, elemnum=0;');
|
|
229
231
|
bindings.forEach((b, i) => src.push(`const __d${i}=__B[${i}].data; let ${b.local};`));
|
|
230
232
|
// user code inside a closure so `return` exits just this element
|
|
@@ -283,7 +285,7 @@ function prepareWrangle(geo, opts) {
|
|
|
283
285
|
else
|
|
284
286
|
src.push(`__wf(__d${i},${ix},${b.size},${b.local});`);
|
|
285
287
|
});
|
|
286
|
-
src.push('}', '})');
|
|
288
|
+
src.push('}', '})();', '})');
|
|
287
289
|
const source = src.join('\n');
|
|
288
290
|
let kernelCache = kernelCaches.get(opts.host);
|
|
289
291
|
if (!kernelCache)
|
|
@@ -312,7 +314,8 @@ function prepareWrangle(geo, opts) {
|
|
|
312
314
|
n, mask: runOver === 'detail' ? null : opts.mask, vp: g.vertexPoint, vprim,
|
|
313
315
|
B: bindings, numpt: g.numPoints, numprim: g.numPrims, numvtx: g.numVertices,
|
|
314
316
|
frame: opts.time?.frame ?? opts.vars.frame ?? 1, time: opts.time?.time ?? opts.vars.time ?? 0,
|
|
315
|
-
timeInc: opts.time?.timeInc ?? opts.vars.timeInc ?? 1 / 24,
|
|
317
|
+
timeInc: opts.time?.timeInc ?? opts.vars.timeInc ?? 1 / 24,
|
|
318
|
+
vars: codeVarValues(opts.vars, varNames), varsGuard: scriptVarsGuard(opts.host),
|
|
316
319
|
centroid: (p) => primCentroid(g, p),
|
|
317
320
|
};
|
|
318
321
|
return { g, n, runOver, bindings, log, kernel, source, body, bodyLine, env, api };
|
|
@@ -539,6 +542,14 @@ export class WrangleAPI {
|
|
|
539
542
|
return a.get(idx);
|
|
540
543
|
}
|
|
541
544
|
primpoints(i, p) { return this.geo(i).primPoints(p); }
|
|
545
|
+
primintrinsic(i, name, p) {
|
|
546
|
+
try {
|
|
547
|
+
return primIntrinsic(this.geo(i), Number(p), String(name));
|
|
548
|
+
}
|
|
549
|
+
catch (e) {
|
|
550
|
+
throw new Error(`primintrinsic(${i}, ${JSON.stringify(String(name))}, ${p}): ${e.message}`);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
542
553
|
pointprims(i, pt) {
|
|
543
554
|
let m = this.pp.get(i);
|
|
544
555
|
if (!m) {
|