topotopo 0.2.0 → 0.4.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 +30 -0
- package/README.md +54 -16
- package/dist/cli.js +95 -14
- package/dist/core/analysis.d.ts +5 -1
- package/dist/core/analysis.js +8 -3
- package/dist/core/bake.d.ts +2 -5
- package/dist/core/bake.js +12 -25
- package/dist/core/bevel.js +165 -97
- package/dist/core/geometry.js +1 -1
- package/dist/core/imageops.d.ts +6 -0
- package/dist/core/imageops.js +51 -0
- package/dist/core/materials.d.ts +4 -0
- package/dist/core/materials.js +11 -0
- 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/rbd.js +13 -1
- 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 +71 -0
- package/dist/core/snippet-lib.d.ts +1 -1
- package/dist/core/snippet-lib.js +1 -1
- package/dist/core/solidify.d.ts +38 -0
- package/dist/core/solidify.js +356 -0
- package/dist/core/tangents.d.ts +52 -0
- package/dist/core/tangents.js +214 -0
- package/dist/core/texcoord.d.ts +4 -0
- package/dist/core/texcoord.js +14 -0
- package/dist/core/topology.d.ts +22 -0
- package/dist/core/topology.js +70 -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/uv.d.ts +13 -0
- package/dist/core/uv.js +3 -3
- package/dist/core/uvreport.d.ts +66 -0
- package/dist/core/uvreport.js +308 -0
- package/dist/core/xatlas.js +32 -2
- package/dist/gallery/app/gallery.css +100 -0
- package/dist/gallery/app/gallery.js +80 -0
- package/dist/gallery/bake.d.ts +34 -0
- package/dist/gallery/bake.js +144 -0
- package/dist/gallery/cli.d.ts +4 -0
- package/dist/gallery/cli.js +157 -0
- package/dist/gallery/library.d.ts +124 -0
- package/dist/gallery/library.js +366 -0
- package/dist/gallery/pages.d.ts +94 -0
- package/dist/gallery/pages.js +148 -0
- package/dist/gallery/server.d.ts +21 -0
- package/dist/gallery/server.js +391 -0
- package/dist/graph/engine.js +14 -0
- package/dist/graph/types.d.ts +17 -0
- package/dist/host/artifacts.d.ts +21 -0
- package/dist/host/artifacts.js +58 -0
- package/dist/host/export-targets.d.ts +33 -0
- package/dist/host/export-targets.js +84 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/inspect.d.ts +6 -1
- package/dist/inspect.js +13 -1
- package/dist/io/common.d.ts +8 -0
- package/dist/io/gltf.js +236 -19
- package/dist/io/targets.d.ts +31 -0
- package/dist/io/targets.js +75 -0
- package/dist/mcp/docs.d.ts +1 -1
- package/dist/mcp/docs.js +73 -6
- package/dist/mcp/library.d.ts +12 -0
- package/dist/mcp/library.js +159 -0
- package/dist/mcp/server.js +29 -12
- package/dist/mcp/tools.d.ts +1 -1
- package/dist/mcp/tools.js +102 -43
- package/dist/nodes/bake.js +56 -36
- package/dist/nodes/bevel.js +4 -3
- package/dist/nodes/code.js +33 -7
- package/dist/nodes/curves.js +7 -0
- package/dist/nodes/generate.js +1 -1
- package/dist/nodes/imageops.d.ts +1 -0
- package/dist/nodes/imageops.js +206 -0
- package/dist/nodes/index.d.ts +3 -0
- package/dist/nodes/index.js +3 -0
- package/dist/nodes/material.js +3 -0
- package/dist/nodes/measure.js +3 -2
- package/dist/nodes/rbd.js +1 -1
- package/dist/nodes/scene.d.ts +1 -0
- package/dist/nodes/scene.js +53 -0
- package/dist/nodes/solidify.d.ts +1 -0
- package/dist/nodes/solidify.js +52 -0
- package/dist/nodes/transform.js +5 -1
- package/dist/nodes/util.d.ts +1 -1
- package/dist/nodes/wasmcall.js +1 -1
- package/dist/render/options.js +1 -1
- package/dist/render/pbr.d.ts +28 -0
- package/dist/render/pbr.js +378 -0
- package/dist/render/preview.d.ts +58 -0
- package/dist/render/preview.js +24 -0
- package/dist/render/raster.d.ts +12 -2
- package/dist/render/raster.js +98 -11
- package/dist/render/texview.d.ts +1 -1
- package/dist/render/texview.js +7 -2
- package/dist/viewer/app/camera.js +27 -7
- package/dist/viewer/app/embed.js +80 -0
- package/dist/viewer/app/export-popover.js +68 -0
- package/dist/viewer/app/grid.js +1 -1
- package/dist/viewer/app/guides.js +1 -1
- package/dist/viewer/app/image-view.js +114 -0
- package/dist/viewer/app/keymap.js +15 -3
- package/dist/viewer/app/layers.js +24 -5
- package/dist/viewer/app/main.js +71 -15
- package/dist/viewer/app/markers.js +1 -1
- package/dist/viewer/app/outliner.js +56 -15
- package/dist/viewer/app/outputs.css +73 -0
- package/dist/viewer/app/outputs.js +240 -0
- package/dist/viewer/app/props.js +1 -1
- package/dist/viewer/app/scene.js +6 -2
- package/dist/viewer/app/select.js +14 -3
- package/dist/viewer/app/selection.js +1 -1
- package/dist/viewer/app/status.js +20 -0
- package/dist/viewer/app/style.css +2 -1
- package/dist/viewer/app/units.js +1 -1
- package/dist/viewer/app/vars.js +1 -1
- package/dist/viewer/index.html +20 -6
- package/dist/viewer/outputs.d.ts +54 -0
- package/dist/viewer/outputs.js +436 -0
- package/dist/viewer/server.d.ts +19 -2
- package/dist/viewer/server.js +77 -9
- package/dist/workspace.d.ts +21 -2
- package/dist/workspace.js +124 -4
- package/kernels/pkg/README.md +21 -28
- package/kernels/pkg-simd/README.md +21 -28
- package/package.json +11 -4
package/NOTICE
CHANGED
|
@@ -9,6 +9,7 @@ dependencies or bundled assets.
|
|
|
9
9
|
Summary
|
|
10
10
|
-------
|
|
11
11
|
DejaVu Sans (assets/fonts/DejaVuSans.ttf): Bitstream Vera Fonts licence + public domain (DejaVu changes) (https://dejavu-fonts.github.io/)
|
|
12
|
+
MikkTSpace (in three/examples/jsm/libs/mikktspace.module.js): Zlib (MikkTSpace); MIT (mikktspace-wasm); MIT OR Apache-2.0 (mikktspace crate) (http://www.mikktspace.com/)
|
|
12
13
|
@dimforge/rapier3d-compat@0.21.0: Apache-2.0 (https://rapier.rs)
|
|
13
14
|
@gltf-transform/core@4.5.1: MIT (https://gltf-transform.dev/)
|
|
14
15
|
@gltf-transform/extensions@4.5.1: MIT (https://gltf-transform.dev/extensions.html)
|
|
@@ -289,6 +290,35 @@ from Tavmjong Bah. For further information, contact: tavmjong @ free
|
|
|
289
290
|
|
|
290
291
|
$Id: LICENSE 2133 2007-11-28 02:46:28Z lechimp $
|
|
291
292
|
|
|
293
|
+
==============================================================================
|
|
294
|
+
MikkTSpace (in three/examples/jsm/libs/mikktspace.module.js)
|
|
295
|
+
Licence: Zlib (MikkTSpace); MIT (mikktspace-wasm); MIT OR Apache-2.0 (mikktspace crate)
|
|
296
|
+
Source: http://www.mikktspace.com/
|
|
297
|
+
|
|
298
|
+
TopoTopo computes tangent space (glTF TANGENT export, bake_normal, the PBR preview) with the MikkTSpace WebAssembly
|
|
299
|
+
module that the three.js package ships as examples/jsm/libs/mikktspace.module.js (three.js itself is MIT, listed
|
|
300
|
+
above). That module is mikktspace-wasm by Don McCurdy (https://github.com/donmccurdy/mikktspace-wasm, MIT), a
|
|
301
|
+
WebAssembly build of the Rust crate mikktspace (https://github.com/gltf-rs/mikktspace, MIT OR Apache-2.0), which is a
|
|
302
|
+
port of the reference MikkTSpace implementation by Morten S. Mikkelsen, distributed under the following licence:
|
|
303
|
+
|
|
304
|
+
Copyright (C) 2011 by Morten S. Mikkelsen
|
|
305
|
+
|
|
306
|
+
This software is provided 'as-is', without any express or implied
|
|
307
|
+
warranty. In no event will the authors be held liable for any damages
|
|
308
|
+
arising from the use of this software.
|
|
309
|
+
|
|
310
|
+
Permission is granted to anyone to use this software for any purpose,
|
|
311
|
+
including commercial applications, and to alter it and redistribute it
|
|
312
|
+
freely, subject to the following restrictions:
|
|
313
|
+
|
|
314
|
+
1. The origin of this software must not be misrepresented; you must not
|
|
315
|
+
claim that you wrote the original software. If you use this software
|
|
316
|
+
in a product, an acknowledgment in the product documentation would be
|
|
317
|
+
appreciated but is not required.
|
|
318
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
|
319
|
+
misrepresented as being the original software.
|
|
320
|
+
3. This notice may not be removed or altered from any source distribution.
|
|
321
|
+
|
|
292
322
|
==============================================================================
|
|
293
323
|
@dimforge/rapier3d-compat@0.21.0
|
|
294
324
|
Licence: Apache-2.0
|
package/README.md
CHANGED
|
@@ -61,10 +61,8 @@ graph and its seeds, and the core is browser-ready.
|
|
|
61
61
|
the graph file), show as grey reference layers (a PNG as a flat picture), and `file` nodes read them as
|
|
62
62
|
`inputs/<name>`.
|
|
63
63
|
|
|
64
|
-
**Documentation:** [topotopo.dev](https://topotopo.dev) has the node reference, the shelf and example galleries
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
The design notes, including whether the browser is a limitation, are in [docs/DESIGN.md](docs/DESIGN.md).
|
|
64
|
+
**Documentation:** [topotopo.dev](https://topotopo.dev) has the node reference, the shelf and example galleries and the
|
|
65
|
+
release notes, generated from this repository (`npm run site`).
|
|
68
66
|
|
|
69
67
|

|
|
70
68
|
|
|
@@ -78,12 +76,13 @@ Requires Node ≥ 22.18.
|
|
|
78
76
|
npx topotopo --catalog # node types by category
|
|
79
77
|
npx topotopo --help-node scatter # one node's params, defaults and example
|
|
80
78
|
npx topotopo graph.json --render out.png --export out.glb # cook, render, export
|
|
79
|
+
npx topotopo graph.json --export-all # every output's export target, into exports/ beside it
|
|
81
80
|
npx topotopo view graph.json # live 3D viewer, re-cooks on save; drops go to inputs/ beside it
|
|
82
81
|
npx topotopo mcp --workspace /absolute/path/to/workspace # the MCP server over stdio
|
|
83
82
|
```
|
|
84
83
|
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
The current release is v0.3 ([release notes](docs/release/v0.3-release-notes.md)); v0.2 was the first tagged release
|
|
85
|
+
([release notes](docs/release/v0.2-release-notes.md)). To try unreleased changes, build the tarball from a clone: `npm pack`, then
|
|
87
86
|
`npm install -g ./topotopo-<version>.tgz` (or into a project).
|
|
88
87
|
`import { Engine } from 'topotopo'` gives the engine API (`src/index.ts`) with its type declarations.
|
|
89
88
|
|
|
@@ -113,11 +112,27 @@ To browse the examples in the live 3D viewer without an MCP client:
|
|
|
113
112
|
npm run preview
|
|
114
113
|
```
|
|
115
114
|
|
|
115
|
+
The viewer's left panel has three tabs: **Scene** (the graph's nodes and guides), **Outputs** and **Inputs**.
|
|
116
|
+
**Outputs**, the default, shows all graphs' main results, named deliverables and their textures; click one to
|
|
117
|
+
inspect it alone, and **Scene** in the top bar restores the scene. Publish extra results in graph JSON with
|
|
118
|
+
`"outputs": {"rotor": {"node": "rotor_final", "label": "Rotor"}}`, keeping `"output"` as the default. Each result
|
|
119
|
+
has an **Export** button: the first click asks for a format and a file inside `exports/` and stores that target in
|
|
120
|
+
the graph (`"export": "glb"`, or `{"format": "obj", "path": "parts/rotor.obj", "up_axis": "z"}`, on the graph or on an
|
|
121
|
+
output); later clicks overwrite the same file, and **Export all** writes every target. MCP `export {output}` and the
|
|
122
|
+
CLI's `--export-all` write the same targets. **Inputs** lists your files in `inputs/`, with **Add input** (or drop
|
|
123
|
+
files anywhere on the page); the agent is told about new ones in its next tool answer. Images open in a 2D viewer
|
|
124
|
+
with layers and channels (generated textures default to RGB; use A to inspect packed alpha/AO); JPEG/WebP are for
|
|
125
|
+
viewing only. For `topotopo view graph.json`, `inputs/` and `exports/` are beside that graph.
|
|
126
|
+
|
|
127
|
+
The default **TopoTopo** keymap uses right-drag orbit around the surface beneath the cursor, middle-drag pan and
|
|
128
|
+
wheel zoom toward the cursor. F/A frame, 1–4 select cameras, 5–7 change shading, O toggles orthographic and Space
|
|
129
|
+
toggles quad view. Maya, Houdini and Blender presets, including previously saved choices, remain available.
|
|
130
|
+
|
|
116
131
|
**Threads.** Heavy per-element work (noise displacement, attribute noise, occlusion rays, point wrangles) runs in
|
|
117
132
|
chunks on a pool of worker threads, and independent graph branches cook concurrently. The output is the same bit for
|
|
118
133
|
bit with or without it. `TOPOTOPO_WORKERS` sets the number of threads (default: CPU threads − 1; `0` turns the pool
|
|
119
134
|
off). Threads start on first use and stop after 30 s idle (`TOPOTOPO_WORKERS_IDLE_MS`); small inputs stay on the main
|
|
120
|
-
thread.
|
|
135
|
+
thread.
|
|
121
136
|
|
|
122
137
|
### Connect to Claude Code
|
|
123
138
|
With the package, the server is the `mcp` subcommand of the `topotopo` command:
|
|
@@ -162,18 +177,19 @@ Houdini or Unreal (glTF, OBJ, STL, PLY, .geo, CSV, PNG). The agent's `inputs` to
|
|
|
162
177
|
| tool | purpose |
|
|
163
178
|
|---|---|
|
|
164
179
|
| `catalog` | node types by category (filter/search) |
|
|
165
|
-
| `help` | exact node docs (params, defaults, ranges, aliases, examples) and topics: graph, inputs, expressions, time, wrangle, groups, attributes, sdf, heightfield, textures, loops, instancing, rbd, pcg, curves, particles, assets, uv, render, export, verify, cloth, recipes |
|
|
180
|
+
| `help` | exact node docs (params, defaults, ranges, aliases, examples) and topics: graph, inputs, expressions, time, wrangle, groups, attributes, sdf, heightfield, textures, loops, instancing, rbd, pcg, curves, particles, assets, uv, render, export, verify, cloth, library, recipes |
|
|
166
181
|
| `build` | create/replace a graph and cook it; `dry_run`, `mode: "merge"`, optional `render`, `frame` (also on edit, inspect, render, export); `params` declare the vars a person tunes (type, desc, min, max, options, label, step), shown as controls in the viewer |
|
|
167
182
|
| `edit` | incremental ops: set, add, insert-after, remove (auto-rewire), connect, rename, replace, output, vars, bypass |
|
|
168
183
|
| `inputs` | `list` the files in the workspace `inputs/` folder (kind, size, date, counts, bbox, object names; PNG size and bit depth) and `describe` one: polygons vs open polylines vs loose points vs packed prims, bbox, attributes, groups, every `name` / `role` value, materials |
|
|
169
|
-
| `inspect` | summary, attribute stats, topology health (watertight, pieces, volume, genus), element listings, images (size and per-layer ranges) |
|
|
170
|
-
| `render` | PNG with persp/front/right/top views, `turntable`, a `uv` view (`quad_uv`), uv checker, a `texture` view of images and `textures: true` for base colour maps on meshes, colour by attribute (+ `legend`), group highlight, flipped normals in blue; opt-in overlays: `section` view and `clip` plane with filled caps, edge overlays (`wireframe` all / hard / boundary / groups), `glyphs` (N, up, orient, v), group / piece / attribute labels and point / prim numbers, `shading` flat / matcap / ao, `scale: 2`, `view_labels: false` (no view labels or axis gizmo, as in the shelf thumbnails); a footer line names what is shown (help topic `render`) |
|
|
184
|
+
| `inspect` | summary, attribute stats, topology health (watertight, pieces, volume, genus, render/export triangle slivers), element listings, images (size and per-layer ranges), `detail: "uv"` (exact uv overlaps, collapsed and out-of-tile triangles, charts, utilization, per-piece texel density; `json: true`) |
|
|
185
|
+
| `render` | PNG with persp/front/right/top views, `turntable`, a `uv` view (`quad_uv`), uv checker, a `texture` view of images and `textures: true` for base colour maps on meshes, colour by attribute (+ `legend`), group highlight, flipped normals in blue; opt-in overlays: `section` view and `clip` plane with filled caps, edge overlays (`wireframe` all / hard / boundary / groups), `glyphs` (N, up, orient, v), group / piece / attribute labels and point / prim numbers, `shading` flat / matcap / ao, `shading: "pbr"` (the exported metallic-roughness material with its base colour, normal, orm and roughness maps under a fixed studio rig; deterministic, `exposure` in stops), `scale: 2`, `view_labels: false` (no view labels or axis gizmo, as in the shelf thumbnails); a footer line names what is shown (help topic `render`) |
|
|
171
186
|
| `export` | glb / gltf / obj / usda / ply / stl / json / geo / csv / points.json (packed instances: instance rows + meshes sidecar + one GLB per source); heightfields: png16 / r16 (+ JSON sidecar with the Unreal import numbers) / mask_png / unreal_landscape (a directory bundle); images: textures (one PNG per image; glb/gltf embed and usda writes the textures materials use) |
|
|
172
187
|
| `graphs` | list / get / delete / rename / duplicate workspace graphs (stored as JSON in `workspace/graphs`) |
|
|
173
188
|
| `assets` | save a graph with vars as a reusable node type (like an HDA); list / get / delete; `fork` copies a shelf asset into the workspace to edit |
|
|
174
189
|
| `explain` | describe a node's geometry in words: "reads as" summary, pieces, watertight, genus, flipped normals, symmetry planes, principal axis, wall thickness, degenerate faces, attributes, groups |
|
|
175
190
|
| `diff` | compare two graphs, nodes or frames: counts, bbox delta, attribute/group changes, Hausdorff and mean distance, verdict; `render: true` adds an overlay (grey same, blue only b, orange only a) |
|
|
176
191
|
| `preview` | start the live viewer and return its URL |
|
|
192
|
+
| `library` | the person's libraries of projects (the gallery): `list` / `get` (with thumbnail) / `create` / `update` / `bake`, and `open`, which makes a project the workspace of every tool and the viewer |
|
|
177
193
|
|
|
178
194
|
## Graph format
|
|
179
195
|
|
|
@@ -226,27 +242,31 @@ boundary. Do not cook graphs from untrusted sources in a privileged process.
|
|
|
226
242
|
|
|
227
243
|
## Node types
|
|
228
244
|
|
|
245
|
+
Image cutouts and atlases: [workflow guide](docs/image-cutouts.md), [example graph](examples/image_cutouts.json).
|
|
246
|
+
Four general nodes crop images, trace masks, extend edge pixels and pack aligned maps. Material alpha masking
|
|
247
|
+
is preserved in GLB and shown in the live and headless previews.
|
|
248
|
+
|
|
229
249
|
| category | nodes |
|
|
230
250
|
|---|---|
|
|
231
251
|
| generate | `box` `grid` `sphere` `tube` `torus` `platonic` `points` `point_grid` `parametric_surface` `terrain` `lsystem` `text` |
|
|
232
|
-
| curve | `parametric_curve` `line` `circle` `curve` `spiral` `shape2d` `resample` `carve` `ends` `sweep` `polywire` `revolve` `extrude` `offset_curve` `boolean2d` `fill` `loft` `voronoi2d` `triangulate2d` `bezier` `nurbs` (Bezier/NURBS curve prims, evaluated exactly wherever they are used) `convert_curve` `spline_fit` `fillet_curve` `offset_curve_3d` `project_curve` `curve_attribs` `straight_skeleton` (skeleton, polygon offset, pitched roof) |
|
|
252
|
+
| curve | image contours `trace_image`; `parametric_curve` `line` `circle` `curve` `spiral` `shape2d` `resample` `carve` `ends` `sweep` `polywire` `revolve` `extrude` `offset_curve` `boolean2d` `fill` `loft` `voronoi2d` `triangulate2d` `bezier` `nurbs` (Bezier/NURBS curve prims, evaluated exactly wherever they are used) `convert_curve` `spline_fit` `fillet_curve` `offset_curve_3d` `project_curve` `curve_attribs` `straight_skeleton` (skeleton, polygon offset, pitched roof) |
|
|
233
253
|
| transform | `transform` `match_size` `mirror` |
|
|
234
254
|
| deform | `noise_displace` `twist` `bend` `taper` `smooth` `peak` `jitter` `ray` `soft_transform` `lattice` `path_deform` `point_deform` `rest` |
|
|
235
255
|
| attribute | `attrib_create` `attrib_randomize` `attrib_promote` `attrib_delete` `attrib_rename` `attrib_copy` `attrib_transfer` `attrib_array` `attrib_noise` `color` `material` `measure` `connectivity` (float/int tuples, strings, and float[]/int[]/string[] array attributes) |
|
|
236
256
|
| measure | `curvature` `occlusion` (ambient occlusion, cavity, thickness) `distance` `assert` (in-graph checks: watertight, counts, bbox, edge length, degenerate, self-intersections, attributes, groups, expression) |
|
|
237
257
|
| group | `group` `delete` `group_promote` `group_expand` `group_combine` `group_delete` `group_rename` (point, vertex, prim and edge groups) |
|
|
238
|
-
| topology | `sort` `normal` `fuse` `clean` `reverse` `facet` `triangulate` `subdivide` `poly_extrude` `poly_bevel` `grid_split` `fill_holes` `bound` `decimate` `remesh` (voxel) `remesh_isotropic` `remesh_quad` (field-aligned, quad-dominant) `mesh_repair` `lod` `knife` `polysplit` `edge_divide` `dissolve` `edge_collapse` `polybridge` `polyfill` |
|
|
258
|
+
| topology | `sort` `normal` `fuse` `clean` `reverse` `facet` `triangulate` `subdivide` `poly_extrude` `solidify` (constant-thickness shell, mitred folds, rims; invalid results are errors) `poly_bevel` `grid_split` `fill_holes` `bound` `decimate` `remesh` (voxel) `remesh_isotropic` `remesh_quad` (field-aligned, quad-dominant) `mesh_repair` `lod` `knife` `polysplit` `edge_divide` `dissolve` `edge_collapse` `polybridge` `polyfill` |
|
|
239
259
|
| copy | `copy_xform` `scatter` (count or density per m², density attribute + 0..1 mask, blue noise, relaxation, exact min distance, per-prim cap) `copy_to_points` (real copies or packed instances; variants by attribute or weights) `pack` `unpack` |
|
|
240
260
|
| pcg | `mask` (slope, height, curvature, occlusion, distance, direction, noise, attribute, group, inside; combine) `attribute_from_map` (PNG → attribute by uv or planar projection) `orient` (orient/N/up from normals, a surface, curve tangents, a direction or target; random yaw, tilt, scale) `points_along_curve` `cluster` (k-means, radius) `prune` (overlap, density, expression, near geometry) |
|
|
241
261
|
| solid | `convex_hull` `boolean` `clip` `minkowski` `smooth_solid` `voronoi_fracture` `slice` |
|
|
242
262
|
| sdf | `sdf_shape` `sdf_expr` `sdf_combine` `sdf_modify` `sdf_from_mesh` `sdf_to_mesh` (implicit, lazily sampled); sampled grids (Rust/WASM): `sdf_grid` `grid_combine` `grid_offset` `grid_blur` `grid_dilate` `grid_erode` `grid_resample` `grid_to_mesh` (sharp dual contouring or marching cubes) `grid_to_sdf` `voxel_remesh` |
|
|
243
263
|
| heightfield | `heightfield` `heightfield_noise` `heightfield_from_mesh` `heightfield_from_image` `heightfield_to_mesh` `heightfield_to_sdf` `heightfield_remap` `heightfield_blur` `heightfield_terrace` `heightfield_clip` `heightfield_cutout` `heightfield_layer` `heightfield_mask_by_feature` `heightfield_mask_by_object` `heightfield_mask_noise` `heightfield_mask_blur` `heightfield_mask_expand` `heightfield_erode` `heightfield_fill_sinks` `heightfield_flow` `heightfield_project` `heightfield_path` `heightfield_scatter` `heightfield_resample` `heightfield_transform` (grids in XZ with named layers; export `png16`/`r16`/`mask_png` for Unreal Landscape) |
|
|
244
264
|
| uv | `uv_project` `uv_transform` `uv_unwrap` (xatlas) `uv_flatten` (LSCM) `uv_layout` `uv_autoseam` |
|
|
245
|
-
| texture | generators `tex_noise` `tex_pattern` `tex_cells` `tex_gradient` `tex_shape` `tex_splatter` `tex_scratches` `tex_text`; PNG files `image_file`; filters `tex_blend` `tex_levels` `tex_curves` `tex_blur` `tex_warp` `tex_transform` `tex_edge_detect` `tex_invert` `tex_threshold` `tex_histogram_scan` `tex_normal_from_height` `tex_height_to_ao` `tex_channel` (ORM packing) `tex_colorize` `tex_tile_sampler` `tex_output`; bakes in uv space `bake_ao` `bake_curvature` `bake_thickness` `bake_position` `bake_normal` `bake_world_normal` `bake_height` `bake_island_id` `bake_mask` `bake_vertex_color`; `texture_to_material` `tex_to_heightfield` `heightfield_to_tex` (images are 2D float layers carried on the geometry; glb/usda embed them, export format `textures` writes PNGs) |
|
|
265
|
+
| texture | generators `tex_noise` `tex_pattern` `tex_cells` `tex_gradient` `tex_shape` `tex_splatter` `tex_scratches` `tex_text`; PNG files `image_file`; filters `tex_blend` `tex_levels` `tex_curves` `tex_blur` `tex_warp` `tex_transform` `tex_edge_detect` `tex_invert` `tex_threshold` `tex_histogram_scan` `tex_normal_from_height` `tex_height_to_ao` `tex_channel` (ORM packing) `tex_colorize` `tex_tile_sampler` `tex_output`; cutouts and atlases `tex_crop` `tex_dilate` `tex_pack`; bakes in uv space `bake_ao` `bake_curvature` `bake_thickness` `bake_position` `bake_normal` `bake_world_normal` `bake_height` `bake_island_id` `bake_mask` `bake_vertex_color`; `texture_to_material` `tex_to_heightfield` `heightfield_to_tex` (images are 2D float layers carried on the geometry; glb/usda embed them, export format `textures` writes PNGs) |
|
|
246
266
|
| sim | `particles` (Houdini POPs in one node: emission from points, gravity, drag, wind, curl noise, point/heightfield/SDF fields, attraction, floor and mesh collisions with die/slide/bounce, trails as polylines; steps with the frame, each frame's state cached; bit-identical on the worker pool) `rbd_settle` (drop pieces onto a terrain, container or ground until they rest; Rapier rigid bodies, packed instances stay packed) `rbd_stack` (drop them one at a time into piles) `drape` (XPBD cloth: colliders, floor, pins, wind, self collision) `inflate` (pressure: cushions, balloons) |
|
|
247
267
|
| code | `wrangle` `script` |
|
|
248
268
|
| flow | `merge` `switch` `null` `input` `foreach` `solver` `graph_ref` (plus saved assets) |
|
|
249
|
-
| io | `file` (obj, stl, ply, glb/gltf, geo/bgeo, csv, points.json, json) |
|
|
269
|
+
| io | `file` (obj, stl, ply, glb/gltf, geo/bgeo, csv, points.json, json), `scene_null` (named scene empty / attachment socket: a meshless glTF node under the root, an empty or a mesh) |
|
|
250
270
|
| shelf | graph assets used like nodes, e.g. `stairs` `railing` `roof_skeleton` `house` `crate` `tree_lowpoly` `forest_patch`; every asset is listed with its thumbnail under [Shelf](#shelf) |
|
|
251
271
|
|
|
252
272
|
Every node's inputs, parameters (types, defaults, ranges, options, aliases) and outputs are listed in the generated
|
|
@@ -308,6 +328,23 @@ Landscape heightmap. Generate the sample with `npm run export:demo`; the plugin
|
|
|
308
328
|
the two-node PCG graph, coordinates, automation tests and editor verification steps. It is separate from the npm
|
|
309
329
|
package; copy it into your Unreal project's `Plugins/` directory.
|
|
310
330
|
|
|
331
|
+
## Gallery
|
|
332
|
+
|
|
333
|
+
Keep projects in libraries on your PC and browse them as a website: `topotopo gallery` serves every library's projects
|
|
334
|
+
at http://127.0.0.1:7340 with a page, a thumbnail and an iframe embed for each, so a board or wiki can link a concept
|
|
335
|
+
to the model. A project is a workspace folder with a `project.json` (title, tags, links) and `attachments/` for
|
|
336
|
+
concept art; previews bake by themselves when its graphs change, and agents reach every library through the MCP
|
|
337
|
+
`library` tool.
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
topotopo library add game D:/game-assets
|
|
341
|
+
topotopo library new game props/lantern --title "Lantern" --tags prop
|
|
342
|
+
topotopo gallery
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Each project has a page at `/p/<library>/<id>`, a thumbnail at `/p/<library>/<id>/thumb.png` and an embed for boards at
|
|
346
|
+
`/embed/<library>/<id>`.
|
|
347
|
+
|
|
311
348
|
## Shelf
|
|
312
349
|
|
|
313
350
|
[shelf/](shelf) holds ready-made graph assets (TopoTopo's answer to a shelf of HDAs): walls with windows and doors,
|
|
@@ -434,8 +471,9 @@ a minute and is not part of `npm test`; run it before a release (see [CONTRIBUTI
|
|
|
434
471
|
|
|
435
472
|
`src/core` holds the geometry model and algorithms. `src/graph` holds the node system and cooking engine, and `src/nodes`
|
|
436
473
|
the node library. The renderer is in `src/render`, import/export in `src/io`, and the MCP server, tools and docs in
|
|
437
|
-
`src/mcp`. `src/viewer` has the live preview,
|
|
438
|
-
|
|
474
|
+
`src/mcp`. `src/viewer` has the live preview, `src/gallery` the gallery website of project libraries, and `src/host` the Node
|
|
475
|
+
host (sandbox, files, fonts).
|
|
476
|
+
`dist/` (not in git) is the compiled package: `npm run build` mirrors
|
|
439
477
|
`src/` there one to one, so the shelf, fonts, kernels and worker entry are found relative to either.
|
|
440
478
|
|
|
441
479
|
## Support
|
package/dist/cli.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// node src/cli.ts <graph.json> [--node name] [--frame N | --frames A-B[:step]] [--fps 24]
|
|
4
4
|
// [--render out.png] [--views quad|quad_uv|turntable|persp|front,top|persp,uv|persp,section] [--checker] [--color-by attr]
|
|
5
5
|
// [--wireframe all|hard|boundary|groups] [--section y:0.5] [--clip x:0.5] [--glyphs N|up|orient|v] [--labels groups,pieces,points,prims,attrib:name]
|
|
6
|
-
// [--shading flat|matcap|ao] [--legend] [--size 800] [--render-scale 2] [--export out.glb]
|
|
7
|
-
// [--compress meshopt] [--quantize] [--pcg | --pcg-struct] [--attributes P,N,pscale] [--up-axis z] [--scale 100]
|
|
6
|
+
// [--shading flat|matcap|ao|pbr] [--exposure 0] [--legend] [--size 800] [--render-scale 2] [--export out.glb]
|
|
7
|
+
// [--compress meshopt] [--quantize] [--tangents auto|preserve|none] [--pcg | --pcg-struct] [--attributes P,N,pscale] [--up-axis z] [--scale 100]
|
|
8
8
|
// [--instancing packed|expand] [--instances rows|expand] [--no-meshes]
|
|
9
|
-
// [--inspect summary|attributes|topology|all]
|
|
9
|
+
// [--inspect summary|attributes|topology|all|uv [--uv-resolution 1024] [--json]]
|
|
10
10
|
// --export formats: .glb .gltf .obj .usda .ply .stl .json .geo (Houdini) .csv .points.json
|
|
11
11
|
// Packed instances to .csv/.points.json: one row per instance + <name>.meshes.json + <name>_meshes/<Mesh>.glb.
|
|
12
12
|
// Heightfields: --export terrain.png (16-bit heightmap + terrain.json sidecar for Unreal), .r16/.raw, or
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
// node src/cli.ts mcp [--workspace dir] [--viewer] the MCP server (src/mcp/server.ts) over stdio
|
|
20
20
|
// node src/cli.ts view <graph.json> [--port 7341] live 3D viewer in the browser, re-cooks on every save;
|
|
21
21
|
// files dropped on the page go to inputs/ beside the graph file
|
|
22
|
+
// node src/cli.ts gallery [--port 7340] [--library dir] the gallery website of the libraries (src/gallery/cli.ts)
|
|
23
|
+
// node src/cli.ts library add|list|new|bake … libraries and projects; edit <project> opens the live viewer
|
|
22
24
|
// Installed from npm the same commands are `topotopo …` (package.json bin → dist/cli.js, built by npm run build).
|
|
23
25
|
import fs from 'node:fs';
|
|
24
26
|
import path from 'node:path';
|
|
@@ -27,17 +29,23 @@ import './nodes/index.js';
|
|
|
27
29
|
import { Engine } from './graph/engine.js';
|
|
28
30
|
import { allNodeDefs } from './graph/registry.js';
|
|
29
31
|
import { createNodeHost } from './host/node.js';
|
|
30
|
-
import {
|
|
32
|
+
import { renderGeometryAsync } from './render/raster.js';
|
|
31
33
|
import { parseViews } from './render/raster.js';
|
|
32
34
|
import { renderArgs } from './render/options.js';
|
|
33
35
|
import { encodePNG } from './render/png.js';
|
|
34
36
|
import { EXPORT_FORMATS, exportFormatFromPath } from './io/export.js';
|
|
35
37
|
import { exportFilesAsync } from './io/files.js';
|
|
38
|
+
import { ArtifactStore } from './host/artifacts.js';
|
|
39
|
+
import { prepareTarget, writeTargets } from './host/export-targets.js';
|
|
40
|
+
import { publishedOutputs } from './io/targets.js';
|
|
36
41
|
import { inspect } from './inspect.js';
|
|
42
|
+
import { uvReport } from './core/uvreport.js';
|
|
37
43
|
import { catalogText, nodeDoc } from './mcp/docs.js';
|
|
38
44
|
const argv = process.argv.slice(2);
|
|
39
45
|
const opt = (f) => { const i = argv.indexOf(f); return i >= 0 ? argv[i + 1] : undefined; };
|
|
40
46
|
const fail = (msg) => { console.error(msg); process.exit(1); };
|
|
47
|
+
/** A graph file's name as a graph (view mode) and in receipts and default export file names. */
|
|
48
|
+
const graphName = (file) => path.basename(file).replace(/\.json$/i, '').replace(/[^A-Za-z0-9_-]/g, '_').replace(/^[^A-Za-z]/, 'g$&') || 'graph';
|
|
41
49
|
// the command as the user typed it: the sources from a clone, or the package's bin (dist/cli.js)
|
|
42
50
|
const prog = import.meta.url.endsWith('.ts') ? 'node src/cli.ts' : 'topotopo';
|
|
43
51
|
if (argv.includes('-v') || argv.includes('-V') || argv.includes('--version')) {
|
|
@@ -49,16 +57,17 @@ if (argv.includes('-v') || argv.includes('-V') || argv.includes('--version')) {
|
|
|
49
57
|
if (!argv.length || argv.includes('-h') || argv.includes('--help')) {
|
|
50
58
|
console.log([
|
|
51
59
|
`usage: ${prog} <graph.json> [--node n] [--frame N | --frames A-B[:step]] [--fps 24]`,
|
|
52
|
-
' [--render out.png] [--views quad|quad_uv|turntable|persp|front,top|persp,uv|persp,section] [--checker] [--color-by attr] [--export out.glb] [--inspect all]',
|
|
60
|
+
' [--render out.png] [--views quad|quad_uv|turntable|persp|front,top|persp,uv|persp,section] [--checker] [--color-by attr] [--export out.glb] [--inspect all|topology|uv] [--uv-resolution 1024] [--json] (uv: overlaps, utilization, texel density; --json: the report as JSON)',
|
|
61
|
+
' [--export-all] (every output with an export target in the graph, into exports/ beside it)',
|
|
53
62
|
' render overlays: [--wireframe all|hard|boundary|groups] [--hard-angle 30] [--section y:0.5] [--clip x:0.5[:abs]]',
|
|
54
63
|
' [--glyphs N|up|orient|v] [--glyph-attrib a] [--labels groups,pieces,points,prims,attrib:name] [--legend] [--points]',
|
|
55
|
-
' [--shading flat|matcap|ao] [--size 800] [--render-scale 2] [--azimuth 35] [--elevation 25] [--zoom 1] [--look-at x,y,z] [--ortho-scale w]',
|
|
64
|
+
' [--shading flat|matcap|ao|pbr] [--exposure 0] [--size 800] [--render-scale 2] [--azimuth 35] [--elevation 25] [--zoom 1] [--look-at x,y,z] [--ortho-scale w]',
|
|
56
65
|
' [--textures] (base colour maps on meshes) [--texture name|image/layer|material] (adds the texture view)',
|
|
57
66
|
' [--max-triangles 600000] (packed instances drawn; above it an evenly spread subset)',
|
|
58
67
|
' several renders per cook: repeat --render; options after a --render apply to it, options before the first apply to all',
|
|
59
68
|
' e.g. --views top --render h.png --color-by height --render r.png --color-by river',
|
|
60
69
|
' [--no-view-labels] (no view name labels or axis gizmo, e.g. for thumbnails)',
|
|
61
|
-
' export options: [--compress none|meshopt|draco] [--quantize] [--pcg | --pcg-struct] [--attributes P,N,pscale] [--up-axis y|z] [--scale 100]',
|
|
70
|
+
' export options: [--compress none|meshopt|draco] [--quantize] [--tangents auto|preserve|none] [--pcg | --pcg-struct] [--attributes P,N,pscale] [--up-axis y|z] [--scale 100]',
|
|
62
71
|
' [--instancing packed|expand] (packed instances: glb/usda/geo keep them by default)',
|
|
63
72
|
' [--instances rows|expand] [--no-meshes] (csv/points.json of packed instances: one row per instance + meshes sidecar + GLBs)',
|
|
64
73
|
' export formats: .glb .gltf .obj .usda .ply .stl .json .geo (Houdini) .csv .points.json; heightfields .png (png16) .r16,',
|
|
@@ -68,6 +77,9 @@ if (!argv.length || argv.includes('-h') || argv.includes('--help')) {
|
|
|
68
77
|
` ${prog} --catalog | --help-node <type> | --version`,
|
|
69
78
|
` ${prog} mcp [--workspace dir] [--viewer] (the MCP server over stdio, for MCP clients)`,
|
|
70
79
|
` ${prog} view <graph.json> [--port 7341] (live 3D viewer in the browser; re-cooks when the file is saved; files dropped on the page go to inputs/ beside it)`,
|
|
80
|
+
` ${prog} gallery [--port 7340] [--library <folder>] [--no-bake] (the gallery website: every library's projects, stable links for a board)`,
|
|
81
|
+
` ${prog} library add <name> <folder> | list | new <library> <folder/name> [--title t] [--tags a,b] | bake <project>|--stale|--all`,
|
|
82
|
+
` ${prog} edit <project folder> [--port 7341] (the live viewer on a gallery project)`,
|
|
71
83
|
].join('\n'));
|
|
72
84
|
process.exit(0);
|
|
73
85
|
}
|
|
@@ -97,12 +109,12 @@ if (argv[0] === 'view') {
|
|
|
97
109
|
const dir = path.dirname(path.resolve(file));
|
|
98
110
|
const engine = new Engine(createNodeHost({ baseDir: dir }));
|
|
99
111
|
await engine.init();
|
|
100
|
-
// A scratch workspace holds the graph
|
|
112
|
+
// A scratch workspace holds the graph and assets: the graph file stays the only source. Files dropped on the
|
|
101
113
|
// page go to inputs/ beside the graph file instead, made on the first drop: its file nodes read them as
|
|
102
114
|
// "inputs/<name>" (the path an MCP workspace uses too), and they outlive the viewer.
|
|
103
|
-
const ws = new Workspace(fs.mkdtempSync(path.join(os.tmpdir(), 'topotopo-view-')), engine, { inputs: path.join(dir, 'inputs') });
|
|
115
|
+
const ws = new Workspace(fs.mkdtempSync(path.join(os.tmpdir(), 'topotopo-view-')), engine, { inputs: path.join(dir, 'inputs'), exports: path.join(dir, 'exports') });
|
|
104
116
|
ws.load();
|
|
105
|
-
const name =
|
|
117
|
+
const name = graphName(file);
|
|
106
118
|
const load = async () => {
|
|
107
119
|
let spec;
|
|
108
120
|
try {
|
|
@@ -118,11 +130,36 @@ if (argv[0] === 'view') {
|
|
|
118
130
|
ws.bump(name);
|
|
119
131
|
};
|
|
120
132
|
await load();
|
|
121
|
-
|
|
133
|
+
// an export target set on the page goes into the graph file, the only source here: only "export" keys change
|
|
134
|
+
const persistGraph = (g) => {
|
|
135
|
+
if (g !== name)
|
|
136
|
+
return;
|
|
137
|
+
const spec = ws.getGraph(name), raw = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
138
|
+
if (spec.export === undefined)
|
|
139
|
+
delete raw.export;
|
|
140
|
+
else
|
|
141
|
+
raw.export = spec.export;
|
|
142
|
+
for (const [id, o] of Object.entries(spec.outputs ?? {})) {
|
|
143
|
+
if (!raw.outputs?.[id])
|
|
144
|
+
continue;
|
|
145
|
+
if (o.export === undefined)
|
|
146
|
+
delete raw.outputs[id].export;
|
|
147
|
+
else
|
|
148
|
+
raw.outputs[id].export = o.export;
|
|
149
|
+
}
|
|
150
|
+
fs.writeFileSync(file, JSON.stringify(raw, null, 2) + '\n');
|
|
151
|
+
};
|
|
152
|
+
const v = await startViewer(ws, opt('--port') !== undefined ? Number(opt('--port')) : undefined, { inputsWhere: `beside ${path.basename(file)}`, persistGraph });
|
|
122
153
|
console.log(`view: ${v.url} (watching ${file}; files dropped on the page go to ${path.join(path.dirname(file), 'inputs') + path.sep}; Ctrl+C to stop)`);
|
|
123
154
|
let timer;
|
|
124
155
|
fs.watch(file, () => { clearTimeout(timer); timer = setTimeout(() => { load().catch((e) => console.error(String(e))); }, 150); });
|
|
125
156
|
}
|
|
157
|
+
else if (argv[0] === 'gallery' || argv[0] === 'library' || argv[0] === 'edit') {
|
|
158
|
+
// the gallery website, its libraries and its editor (src/gallery/cli.ts)
|
|
159
|
+
const g = await import('./gallery/cli.js');
|
|
160
|
+
const run = { gallery: g.galleryCommand, library: g.libraryCommand, edit: g.editCommand }[argv[0]];
|
|
161
|
+
await run(argv.slice(1), prog);
|
|
162
|
+
}
|
|
126
163
|
else if (argv[0] === 'mcp') {
|
|
127
164
|
// `topotopo mcp [--workspace dir] [--viewer]`: the MCP server over stdio; src/mcp/server.ts reads the remaining
|
|
128
165
|
// arguments from process.argv and runs until the client closes stdin
|
|
@@ -179,6 +216,8 @@ async function cook() {
|
|
|
179
216
|
const frameArg = opt('--frame');
|
|
180
217
|
if (framesArg && frameArg)
|
|
181
218
|
fail('use either --frame or --frames, not both');
|
|
219
|
+
if (framesArg && argv.includes('--export-all'))
|
|
220
|
+
fail('--export-all writes one frame: use --frame N, not --frames');
|
|
182
221
|
const single = frameArg !== undefined ? Number(frameArg) : undefined;
|
|
183
222
|
if (single !== undefined && !Number.isFinite(single))
|
|
184
223
|
fail(`--frame expects a number, got "${frameArg}"`);
|
|
@@ -194,7 +233,7 @@ async function cook() {
|
|
|
194
233
|
for (const [f, k] of [['--wireframe', 'wireframe'], ['--hard-angle', 'hard_angle'], ['--section', 'section'], ['--clip', 'clip'], ['--glyphs', 'glyphs'],
|
|
195
234
|
['--glyph-attrib', 'glyph_attrib'], ['--glyph-scale', 'glyph_scale'], ['--max-glyphs', 'max_glyphs'], ['--labels', 'labels'], ['--max-labels', 'max_labels'],
|
|
196
235
|
['--shading', 'shading'], ['--ao-radius', 'ao_radius'], ['--size', 'size'], ['--render-scale', 'scale'], ['--azimuth', 'azimuth'], ['--elevation', 'elevation'],
|
|
197
|
-
['--zoom', 'zoom'], ['--look-at', 'look_at'], ['--ortho-scale', 'ortho_scale'], ['--texture', 'texture'], ['--max-triangles', 'max_triangles']])
|
|
236
|
+
['--zoom', 'zoom'], ['--look-at', 'look_at'], ['--ortho-scale', 'ortho_scale'], ['--texture', 'texture'], ['--max-triangles', 'max_triangles'], ['--exposure', 'exposure']])
|
|
198
237
|
if (get(f) !== undefined)
|
|
199
238
|
a[k] = get(f);
|
|
200
239
|
for (const [f, k] of [['--legend', 'legend'], ['--points', 'points'], ['--annotate', 'annotate'], ['--textures', 'textures']])
|
|
@@ -223,6 +262,14 @@ async function cook() {
|
|
|
223
262
|
async function writeOutputs(r, frame) {
|
|
224
263
|
const geo = r.geo;
|
|
225
264
|
const at = (p) => (frame === undefined ? p : framePath(p, frame));
|
|
265
|
+
// Receipts for the viewer's saved files, only for files inside exports/ beside the graph: a run whose output goes
|
|
266
|
+
// elsewhere leaves no exports/ folder behind (the viewer lists that folder's files without receipts too).
|
|
267
|
+
const exportsDir = path.join(path.dirname(path.resolve(file)), 'exports');
|
|
268
|
+
const record = (paths, format) => {
|
|
269
|
+
const inside = paths.every((p) => { const rel = path.relative(exportsDir, path.resolve(p)); return !!rel && !rel.startsWith('..') && !path.isAbsolute(rel); });
|
|
270
|
+
if (inside)
|
|
271
|
+
new ArtifactStore(exportsDir).record(paths, { graph: graphName(file), node: r.target, format });
|
|
272
|
+
};
|
|
226
273
|
for (const { out, get, has } of renders) {
|
|
227
274
|
const ro = renderFlags(get, has);
|
|
228
275
|
const v = get('--views');
|
|
@@ -232,10 +279,11 @@ async function cook() {
|
|
|
232
279
|
if (get('--texture') !== undefined)
|
|
233
280
|
views = !views && v === undefined ? ro.views : views && views.includes('texture') ? views : [...(views ?? parseViews('quad')), 'texture'];
|
|
234
281
|
const title = path.basename(file, '.json') + (r.frame !== 1 ? ` @ frame ${r.frame}` : '');
|
|
235
|
-
const img =
|
|
282
|
+
const img = await renderGeometryAsync(geo, { ...ro, views, colorBy: get('--color-by') ?? null, checker: has('--checker'), title }, (t) => engine.host.readFile(t));
|
|
236
283
|
const p = at(out);
|
|
237
284
|
fs.mkdirSync(path.dirname(path.resolve(p)), { recursive: true });
|
|
238
285
|
fs.writeFileSync(p, encodePNG(img.rgba, img.width, img.height, (d) => zlib.deflateSync(d)));
|
|
286
|
+
record([p], 'png');
|
|
239
287
|
console.log(`rendered ${p} (${img.width}x${img.height})${img.notes.length ? ' — ' + img.notes.join('; ') : ''}`);
|
|
240
288
|
}
|
|
241
289
|
const ex = opt('--export');
|
|
@@ -248,12 +296,15 @@ async function cook() {
|
|
|
248
296
|
const up = opt('--up-axis');
|
|
249
297
|
if (argv.includes('--tile-size') && opt('--tile-size') === undefined)
|
|
250
298
|
fail('--tile-size requires a number of quads (e.g. 1008)');
|
|
299
|
+
if (opt('--tangents') !== undefined && !['auto', 'preserve', 'none'].includes(opt('--tangents')))
|
|
300
|
+
fail(`--tangents must be auto, preserve or none (got "${opt('--tangents')}")`);
|
|
251
301
|
const outDir = fmt === 'unreal_landscape' && !/\.json$/i.test(p) ? path.resolve(p) : path.dirname(path.resolve(p));
|
|
252
302
|
const host = engine.host;
|
|
253
303
|
const { files, summary } = await exportFilesAsync(geo, fmt, p, {
|
|
254
304
|
splitByName: true,
|
|
255
305
|
compress: opt('--compress'),
|
|
256
306
|
quantize: argv.includes('--quantize') || undefined,
|
|
307
|
+
tangents: opt('--tangents'),
|
|
257
308
|
pcg: argv.includes('--pcg') || argv.includes('--pcg-struct') || undefined,
|
|
258
309
|
pcgStruct: argv.includes('--pcg-struct') || undefined,
|
|
259
310
|
attributes: opt('--attributes'),
|
|
@@ -273,6 +324,8 @@ async function cook() {
|
|
|
273
324
|
fs.mkdirSync(path.dirname(path.resolve(f.path)), { recursive: true });
|
|
274
325
|
fs.writeFileSync(f.path, f.bytes);
|
|
275
326
|
}
|
|
327
|
+
if (files.length)
|
|
328
|
+
record(files.map((f) => f.path), fmt);
|
|
276
329
|
console.log(`exported ${files.length === 1 ? files[0].path : files.map((f) => f.path).join(', ')}${files.length > 1 || fmt !== 'glb' ? ` — ${summary}` : ''}`);
|
|
277
330
|
}
|
|
278
331
|
}
|
|
@@ -298,8 +351,36 @@ async function cook() {
|
|
|
298
351
|
if (!r.ok || !r.geo)
|
|
299
352
|
process.exit(1);
|
|
300
353
|
console.log(`cooked ${file} → ${r.target}${r.frame !== 1 ? ` at frame ${r.frame}` : ''} in ${r.ms.toFixed(0)} ms`);
|
|
301
|
-
|
|
354
|
+
if (opt('--inspect') === 'uv' && argv.includes('--json'))
|
|
355
|
+
console.log(JSON.stringify(uvReport(r.geo, { resolution: opt('--uv-resolution') !== undefined ? Number(opt('--uv-resolution')) : undefined }), null, 2));
|
|
356
|
+
else
|
|
357
|
+
console.log(inspect(r.geo, { detail: opt('--inspect') ?? 'summary', uvResolution: opt('--uv-resolution') !== undefined ? Number(opt('--uv-resolution')) : undefined }));
|
|
302
358
|
await writeOutputs(r);
|
|
359
|
+
if (argv.includes('--export-all'))
|
|
360
|
+
await exportAll();
|
|
361
|
+
}
|
|
362
|
+
/** --export-all: every published output with an export target (io/targets.ts), into exports/ beside the graph. */
|
|
363
|
+
async function exportAll() {
|
|
364
|
+
const name = graphName(file), exportsDir = path.join(path.dirname(path.resolve(file)), 'exports');
|
|
365
|
+
const published = publishedOutputs(name, graph, engine.findOutput(graph).name);
|
|
366
|
+
if (!published.some((p) => p.target))
|
|
367
|
+
fail(`--export-all: no output of ${file} has an export target; add "export": "glb" to the graph (default output) or to an entry of "outputs"`);
|
|
368
|
+
const prepared = [];
|
|
369
|
+
for (const p of published) {
|
|
370
|
+
if (!p.target)
|
|
371
|
+
continue;
|
|
372
|
+
const r = await engine.cook(graph, { target: p.node, frame: single, fps });
|
|
373
|
+
report(r);
|
|
374
|
+
if (!r.ok || !r.geo)
|
|
375
|
+
fail(`--export-all: "${p.label}" did not cook; nothing was written`);
|
|
376
|
+
prepared.push(await prepareTarget(r.geo, name, p, exportsDir, engine.host));
|
|
377
|
+
}
|
|
378
|
+
writeTargets(prepared, exportsDir);
|
|
379
|
+
for (const p of prepared)
|
|
380
|
+
console.log(`exported ${p.label} → ${path.join('exports', ...p.target.path.split('/'))} — ${p.summary}`);
|
|
381
|
+
const skipped = published.filter((p) => !p.target).map((p) => p.label);
|
|
382
|
+
if (skipped.length)
|
|
383
|
+
console.log(`no export target (skipped): ${skipped.join(', ')}`);
|
|
303
384
|
}
|
|
304
385
|
// stop the kernel worker threads (idle ones would not hold the process, but a clean exit should not wait on them)
|
|
305
386
|
await engine.host.pool?.close();
|
package/dist/core/analysis.d.ts
CHANGED
|
@@ -220,8 +220,12 @@ export interface SelfIntersectionResult {
|
|
|
220
220
|
* Pairs of non-adjacent triangles (no shared point) that cross each other: an edge of one passes through the
|
|
221
221
|
* interior of the other. Coplanar overlaps and touching configurations are not reported. The BVH limits the
|
|
222
222
|
* candidates; the search stops after maxTests candidate pairs.
|
|
223
|
+
* strict: every pair that meets beyond what it shares (core/tritri.ts): crossings, touching contacts, coplanar
|
|
224
|
+
* overlaps, and triangles with a shared corner or edge that fold through or onto each other. Used by solidify.
|
|
223
225
|
*/
|
|
224
|
-
export declare function selfIntersections(g: Geometry, maxTests?: number
|
|
226
|
+
export declare function selfIntersections(g: Geometry, maxTests?: number, opts?: {
|
|
227
|
+
strict?: boolean;
|
|
228
|
+
}): SelfIntersectionResult;
|
|
225
229
|
/** Points that have another point within tol (both are marked). */
|
|
226
230
|
export declare function duplicatePoints(g: Geometry, tol: number): {
|
|
227
231
|
count: number;
|
package/dist/core/analysis.js
CHANGED
|
@@ -12,6 +12,7 @@ import { Geometry } from './geometry.js';
|
|
|
12
12
|
import { buildEdges, connectivity, pointNeighbors, triangulate } from './topology.js';
|
|
13
13
|
import { halfEdges } from './halfedge.js';
|
|
14
14
|
import { EDGE_BAND, KDTree, TriBVH, invDir } from './spatial.js';
|
|
15
|
+
import { trianglesContact } from './tritri.js';
|
|
15
16
|
import { hash32, hashNumber } from './random.js';
|
|
16
17
|
// ---------------------------------------------------------------- small helpers
|
|
17
18
|
/** A number with 4 significant digits for messages ("0.9993", "1250", "2.5e-6"). */
|
|
@@ -1223,8 +1224,11 @@ export function directedDistance(samples, target) {
|
|
|
1223
1224
|
* Pairs of non-adjacent triangles (no shared point) that cross each other: an edge of one passes through the
|
|
1224
1225
|
* interior of the other. Coplanar overlaps and touching configurations are not reported. The BVH limits the
|
|
1225
1226
|
* candidates; the search stops after maxTests candidate pairs.
|
|
1227
|
+
* strict: every pair that meets beyond what it shares (core/tritri.ts): crossings, touching contacts, coplanar
|
|
1228
|
+
* overlaps, and triangles with a shared corner or edge that fold through or onto each other. Used by solidify.
|
|
1226
1229
|
*/
|
|
1227
|
-
export function selfIntersections(g, maxTests = 2_000_000) {
|
|
1230
|
+
export function selfIntersections(g, maxTests = 2_000_000, opts = {}) {
|
|
1231
|
+
const strict = !!opts.strict;
|
|
1228
1232
|
const prims = new Uint8Array(g.numPrims);
|
|
1229
1233
|
const bvh = new TriBVH(g);
|
|
1230
1234
|
const nt = bvh.numTris, T = bvh.T, vp = g.vertexPoint, tv = bvh.triVtx;
|
|
@@ -1256,7 +1260,8 @@ export function selfIntersections(g, maxTests = 2_000_000) {
|
|
|
1256
1260
|
if (j <= i)
|
|
1257
1261
|
continue;
|
|
1258
1262
|
const b0 = vp[tv[j * 3]], b1 = vp[tv[j * 3 + 1]], b2 = vp[tv[j * 3 + 2]];
|
|
1259
|
-
|
|
1263
|
+
const shared = (b0 === a0 || b0 === a1 || b0 === a2 ? 1 : 0) + (b1 === a0 || b1 === a1 || b1 === a2 ? 1 : 0) + (b2 === a0 || b2 === a1 || b2 === a2 ? 1 : 0);
|
|
1264
|
+
if (shared && !strict)
|
|
1260
1265
|
continue;
|
|
1261
1266
|
const q = j * 9;
|
|
1262
1267
|
if (Math.min(T[q], T[q + 3], T[q + 6]) > mxx || Math.max(T[q], T[q + 3], T[q + 6]) < mnx ||
|
|
@@ -1268,7 +1273,7 @@ export function selfIntersections(g, maxTests = 2_000_000) {
|
|
|
1268
1273
|
break outer;
|
|
1269
1274
|
}
|
|
1270
1275
|
tested++;
|
|
1271
|
-
if (trianglesCross(T, o, q, eps)) {
|
|
1276
|
+
if (strict ? trianglesContact(T, o, q, Math.min(shared, 2), pad) || shared === 3 : trianglesCross(T, o, q, eps)) {
|
|
1272
1277
|
pairs++;
|
|
1273
1278
|
prims[bvh.triPrim[i]] = 1;
|
|
1274
1279
|
prims[bvh.triPrim[j]] = 1;
|
package/dist/core/bake.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ export interface BakeSamples {
|
|
|
42
42
|
export declare function bakeSamples(uv: ArrayLike<number>, tris: ArrayLike<number>, W: number, H: number, S: number, skip?: Uint8Array | null): BakeSamples;
|
|
43
43
|
/** Per-sample interpolation of per-vertex values (`size` floats per vertex index of the triangulation). */
|
|
44
44
|
export declare function interpolate(s: BakeSamples, tris: ArrayLike<number>, vals: ArrayLike<number>, size: number): Float64Array;
|
|
45
|
+
/** Per-sample interpolation of per-triangle-corner values (`size` floats per corner t·3 + k, e.g. MikkTSpace tangents). */
|
|
46
|
+
export declare function interpolateCorners(s: BakeSamples, vals: ArrayLike<number>, size: number): Float64Array;
|
|
45
47
|
/**
|
|
46
48
|
* Average the samples (ch values each) into the W × H output: data (W·H·ch) and coverage (covered fraction of each
|
|
47
49
|
* texel's S × S samples). Texels without samples stay 0 (dilate() fills them).
|
|
@@ -78,11 +80,6 @@ export declare function uvIslands(g: Geometry, uv: ArrayLike<number>, tris: Arra
|
|
|
78
80
|
triIsland: Int32Array;
|
|
79
81
|
count: number;
|
|
80
82
|
};
|
|
81
|
-
/** Tangent per triangle (unnormalised dP/du from uv) and the handedness sign of (dP/du, dP/dv) against the face normal. */
|
|
82
|
-
export declare function triangleTangents(g: Geometry, uv: ArrayLike<number>, tris: ArrayLike<number>): {
|
|
83
|
-
T: Float64Array;
|
|
84
|
-
sign: Float32Array;
|
|
85
|
-
};
|
|
86
83
|
/** Random colour of an island id (stable per id and seed). */
|
|
87
84
|
export declare function idColor(id: number, seed?: number): [number, number, number];
|
|
88
85
|
export interface ProjectArgs {
|
package/dist/core/bake.js
CHANGED
|
@@ -139,6 +139,17 @@ export function interpolate(s, tris, vals, size) {
|
|
|
139
139
|
}
|
|
140
140
|
return out;
|
|
141
141
|
}
|
|
142
|
+
/** Per-sample interpolation of per-triangle-corner values (`size` floats per corner t·3 + k, e.g. MikkTSpace tangents). */
|
|
143
|
+
export function interpolateCorners(s, vals, size) {
|
|
144
|
+
const out = new Float64Array(s.n * size);
|
|
145
|
+
for (let k = 0; k < s.n; k++) {
|
|
146
|
+
const t = s.tri[k], w1 = s.b1[k], w2 = s.b2[k], w0 = 1 - w1 - w2;
|
|
147
|
+
const a = t * 3 * size, b = a + size, c = b + size;
|
|
148
|
+
for (let q = 0; q < size; q++)
|
|
149
|
+
out[k * size + q] = vals[a + q] * w0 + vals[b + q] * w1 + vals[c + q] * w2;
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
142
153
|
/**
|
|
143
154
|
* Average the samples (ch values each) into the W × H output: data (W·H·ch) and coverage (covered fraction of each
|
|
144
155
|
* texel's S × S samples). Texels without samples stay 0 (dilate() fills them).
|
|
@@ -334,7 +345,7 @@ export function vertexPositions(g) {
|
|
|
334
345
|
}
|
|
335
346
|
return out;
|
|
336
347
|
}
|
|
337
|
-
// ---------------------------------------------------------------- islands,
|
|
348
|
+
// ---------------------------------------------------------------- islands, id colours
|
|
338
349
|
/**
|
|
339
350
|
* UV islands: triangles connected through corners with the same point and the same uv (union-find over corner keys).
|
|
340
351
|
* Returns the island of each triangle (0..count-1, in order of first appearance).
|
|
@@ -378,30 +389,6 @@ export function uvIslands(g, uv, tris) {
|
|
|
378
389
|
}
|
|
379
390
|
return { triIsland, count: label.size };
|
|
380
391
|
}
|
|
381
|
-
/** Tangent per triangle (unnormalised dP/du from uv) and the handedness sign of (dP/du, dP/dv) against the face normal. */
|
|
382
|
-
export function triangleTangents(g, uv, tris) {
|
|
383
|
-
const nt = Math.floor(tris.length / 3), P = g.P;
|
|
384
|
-
const T = new Float64Array(nt * 3), sign = new Float32Array(nt);
|
|
385
|
-
for (let t = 0; t < nt; t++) {
|
|
386
|
-
const va = tris[t * 3], vb = tris[t * 3 + 1], vc = tris[t * 3 + 2];
|
|
387
|
-
const a = g.vertexPoint[va] * 3, b = g.vertexPoint[vb] * 3, c = g.vertexPoint[vc] * 3;
|
|
388
|
-
const e1x = P[b] - P[a], e1y = P[b + 1] - P[a + 1], e1z = P[b + 2] - P[a + 2];
|
|
389
|
-
const e2x = P[c] - P[a], e2y = P[c + 1] - P[a + 1], e2z = P[c + 2] - P[a + 2];
|
|
390
|
-
const du1 = uv[vb * 2] - uv[va * 2], dv1 = uv[vb * 2 + 1] - uv[va * 2 + 1], du2 = uv[vc * 2] - uv[va * 2], dv2 = uv[vc * 2 + 1] - uv[va * 2 + 1];
|
|
391
|
-
const det = du1 * dv2 - du2 * dv1;
|
|
392
|
-
const r = Math.abs(det) > 1e-20 ? 1 / det : 0;
|
|
393
|
-
const tx = (e1x * dv2 - e2x * dv1) * r, ty = (e1y * dv2 - e2y * dv1) * r, tz = (e1z * dv2 - e2z * dv1) * r;
|
|
394
|
-
const bx = (e2x * du1 - e1x * du2) * r, by = (e2y * du1 - e1y * du2) * r, bz = (e2z * du1 - e1z * du2) * r;
|
|
395
|
-
const nx = e1y * e2z - e1z * e2y, ny = e1z * e2x - e1x * e2z, nz = e1x * e2y - e1y * e2x;
|
|
396
|
-
// (N × T) · B > 0: right-handed
|
|
397
|
-
const cx = ny * tz - nz * ty, cy = nz * tx - nx * tz, cz = nx * ty - ny * tx;
|
|
398
|
-
T[t * 3] = tx;
|
|
399
|
-
T[t * 3 + 1] = ty;
|
|
400
|
-
T[t * 3 + 2] = tz;
|
|
401
|
-
sign[t] = cx * bx + cy * by + cz * bz < 0 ? -1 : 1;
|
|
402
|
-
}
|
|
403
|
-
return { T, sign };
|
|
404
|
-
}
|
|
405
392
|
/** Random colour of an island id (stable per id and seed). */
|
|
406
393
|
export function idColor(id, seed = 0) {
|
|
407
394
|
const hsh = hash32(Math.imul(id + 1, 0x9e3779b1) ^ hash32(Math.floor(seed * 7919) + 77));
|