topotopo 0.3.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 +35 -14
- package/dist/cli.js +28 -10
- 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/host/export-targets.js +1 -1
- 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.js +1 -1
- package/dist/mcp/docs.d.ts +1 -1
- package/dist/mcp/docs.js +58 -4
- 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.js +16 -10
- package/dist/nodes/bake.js +56 -36
- package/dist/nodes/bevel.js +4 -3
- package/dist/nodes/code.js +1 -1
- 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 +1 -1
- package/dist/viewer/app/embed.js +80 -0
- package/dist/viewer/app/grid.js +1 -1
- package/dist/viewer/app/guides.js +1 -1
- package/dist/viewer/app/keymap.js +1 -1
- package/dist/viewer/app/layers.js +1 -1
- package/dist/viewer/app/main.js +1 -1
- package/dist/viewer/app/markers.js +1 -1
- package/dist/viewer/app/outliner.js +1 -1
- package/dist/viewer/app/props.js +1 -1
- package/dist/viewer/app/scene.js +6 -2
- package/dist/viewer/app/select.js +1 -1
- package/dist/viewer/app/selection.js +1 -1
- package/dist/viewer/app/status.js +1 -1
- package/dist/viewer/app/style.css +1 -1
- package/dist/viewer/app/units.js +1 -1
- package/dist/viewer/app/vars.js +1 -1
- package/dist/viewer/index.html +1 -1
- package/dist/viewer/server.d.ts +14 -2
- package/dist/viewer/server.js +30 -10
- package/dist/workspace.d.ts +13 -0
- package/dist/workspace.js +87 -1
- package/kernels/pkg/README.md +21 -28
- package/kernels/pkg-simd/README.md +21 -28
- package/package.json +9 -3
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
|
|
|
@@ -134,7 +132,7 @@ toggles quad view. Maya, Houdini and Blender presets, including previously saved
|
|
|
134
132
|
chunks on a pool of worker threads, and independent graph branches cook concurrently. The output is the same bit for
|
|
135
133
|
bit with or without it. `TOPOTOPO_WORKERS` sets the number of threads (default: CPU threads − 1; `0` turns the pool
|
|
136
134
|
off). Threads start on first use and stop after 30 s idle (`TOPOTOPO_WORKERS_IDLE_MS`); small inputs stay on the main
|
|
137
|
-
thread.
|
|
135
|
+
thread.
|
|
138
136
|
|
|
139
137
|
### Connect to Claude Code
|
|
140
138
|
With the package, the server is the `mcp` subcommand of the `topotopo` command:
|
|
@@ -179,18 +177,19 @@ Houdini or Unreal (glTF, OBJ, STL, PLY, .geo, CSV, PNG). The agent's `inputs` to
|
|
|
179
177
|
| tool | purpose |
|
|
180
178
|
|---|---|
|
|
181
179
|
| `catalog` | node types by category (filter/search) |
|
|
182
|
-
| `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 |
|
|
183
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 |
|
|
184
182
|
| `edit` | incremental ops: set, add, insert-after, remove (auto-rewire), connect, rename, replace, output, vars, bypass |
|
|
185
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 |
|
|
186
|
-
| `inspect` | summary, attribute stats, topology health (watertight, pieces, volume, genus), element listings, images (size and per-layer ranges) |
|
|
187
|
-
| `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`) |
|
|
188
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) |
|
|
189
187
|
| `graphs` | list / get / delete / rename / duplicate workspace graphs (stored as JSON in `workspace/graphs`) |
|
|
190
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 |
|
|
191
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 |
|
|
192
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) |
|
|
193
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 |
|
|
194
193
|
|
|
195
194
|
## Graph format
|
|
196
195
|
|
|
@@ -243,27 +242,31 @@ boundary. Do not cook graphs from untrusted sources in a privileged process.
|
|
|
243
242
|
|
|
244
243
|
## Node types
|
|
245
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
|
+
|
|
246
249
|
| category | nodes |
|
|
247
250
|
|---|---|
|
|
248
251
|
| generate | `box` `grid` `sphere` `tube` `torus` `platonic` `points` `point_grid` `parametric_surface` `terrain` `lsystem` `text` |
|
|
249
|
-
| 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) |
|
|
250
253
|
| transform | `transform` `match_size` `mirror` |
|
|
251
254
|
| deform | `noise_displace` `twist` `bend` `taper` `smooth` `peak` `jitter` `ray` `soft_transform` `lattice` `path_deform` `point_deform` `rest` |
|
|
252
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) |
|
|
253
256
|
| measure | `curvature` `occlusion` (ambient occlusion, cavity, thickness) `distance` `assert` (in-graph checks: watertight, counts, bbox, edge length, degenerate, self-intersections, attributes, groups, expression) |
|
|
254
257
|
| group | `group` `delete` `group_promote` `group_expand` `group_combine` `group_delete` `group_rename` (point, vertex, prim and edge groups) |
|
|
255
|
-
| 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` |
|
|
256
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` |
|
|
257
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) |
|
|
258
261
|
| solid | `convex_hull` `boolean` `clip` `minkowski` `smooth_solid` `voronoi_fracture` `slice` |
|
|
259
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` |
|
|
260
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) |
|
|
261
264
|
| uv | `uv_project` `uv_transform` `uv_unwrap` (xatlas) `uv_flatten` (LSCM) `uv_layout` `uv_autoseam` |
|
|
262
|
-
| 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) |
|
|
263
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) |
|
|
264
267
|
| code | `wrangle` `script` |
|
|
265
268
|
| flow | `merge` `switch` `null` `input` `foreach` `solver` `graph_ref` (plus saved assets) |
|
|
266
|
-
| 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) |
|
|
267
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) |
|
|
268
271
|
|
|
269
272
|
Every node's inputs, parameters (types, defaults, ranges, options, aliases) and outputs are listed in the generated
|
|
@@ -325,6 +328,23 @@ Landscape heightmap. Generate the sample with `npm run export:demo`; the plugin
|
|
|
325
328
|
the two-node PCG graph, coordinates, automation tests and editor verification steps. It is separate from the npm
|
|
326
329
|
package; copy it into your Unreal project's `Plugins/` directory.
|
|
327
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
|
+
|
|
328
348
|
## Shelf
|
|
329
349
|
|
|
330
350
|
[shelf/](shelf) holds ready-made graph assets (TopoTopo's answer to a shelf of HDAs): walls with windows and doors,
|
|
@@ -451,8 +471,9 @@ a minute and is not part of `npm test`; run it before a release (see [CONTRIBUTI
|
|
|
451
471
|
|
|
452
472
|
`src/core` holds the geometry model and algorithms. `src/graph` holds the node system and cooking engine, and `src/nodes`
|
|
453
473
|
the node library. The renderer is in `src/render`, import/export in `src/io`, and the MCP server, tools and docs in
|
|
454
|
-
`src/mcp`. `src/viewer` has the live preview,
|
|
455
|
-
|
|
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
|
|
456
477
|
`src/` there one to one, so the shelf, fonts, kernels and worker entry are found relative to either.
|
|
457
478
|
|
|
458
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,7 +29,7 @@ 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';
|
|
@@ -37,6 +39,7 @@ import { ArtifactStore } from './host/artifacts.js';
|
|
|
37
39
|
import { prepareTarget, writeTargets } from './host/export-targets.js';
|
|
38
40
|
import { publishedOutputs } from './io/targets.js';
|
|
39
41
|
import { inspect } from './inspect.js';
|
|
42
|
+
import { uvReport } from './core/uvreport.js';
|
|
40
43
|
import { catalogText, nodeDoc } from './mcp/docs.js';
|
|
41
44
|
const argv = process.argv.slice(2);
|
|
42
45
|
const opt = (f) => { const i = argv.indexOf(f); return i >= 0 ? argv[i + 1] : undefined; };
|
|
@@ -54,17 +57,17 @@ if (argv.includes('-v') || argv.includes('-V') || argv.includes('--version')) {
|
|
|
54
57
|
if (!argv.length || argv.includes('-h') || argv.includes('--help')) {
|
|
55
58
|
console.log([
|
|
56
59
|
`usage: ${prog} <graph.json> [--node n] [--frame N | --frames A-B[:step]] [--fps 24]`,
|
|
57
|
-
' [--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)',
|
|
58
61
|
' [--export-all] (every output with an export target in the graph, into exports/ beside it)',
|
|
59
62
|
' render overlays: [--wireframe all|hard|boundary|groups] [--hard-angle 30] [--section y:0.5] [--clip x:0.5[:abs]]',
|
|
60
63
|
' [--glyphs N|up|orient|v] [--glyph-attrib a] [--labels groups,pieces,points,prims,attrib:name] [--legend] [--points]',
|
|
61
|
-
' [--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]',
|
|
62
65
|
' [--textures] (base colour maps on meshes) [--texture name|image/layer|material] (adds the texture view)',
|
|
63
66
|
' [--max-triangles 600000] (packed instances drawn; above it an evenly spread subset)',
|
|
64
67
|
' several renders per cook: repeat --render; options after a --render apply to it, options before the first apply to all',
|
|
65
68
|
' e.g. --views top --render h.png --color-by height --render r.png --color-by river',
|
|
66
69
|
' [--no-view-labels] (no view name labels or axis gizmo, e.g. for thumbnails)',
|
|
67
|
-
' 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]',
|
|
68
71
|
' [--instancing packed|expand] (packed instances: glb/usda/geo keep them by default)',
|
|
69
72
|
' [--instances rows|expand] [--no-meshes] (csv/points.json of packed instances: one row per instance + meshes sidecar + GLBs)',
|
|
70
73
|
' export formats: .glb .gltf .obj .usda .ply .stl .json .geo (Houdini) .csv .points.json; heightfields .png (png16) .r16,',
|
|
@@ -74,6 +77,9 @@ if (!argv.length || argv.includes('-h') || argv.includes('--help')) {
|
|
|
74
77
|
` ${prog} --catalog | --help-node <type> | --version`,
|
|
75
78
|
` ${prog} mcp [--workspace dir] [--viewer] (the MCP server over stdio, for MCP clients)`,
|
|
76
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)`,
|
|
77
83
|
].join('\n'));
|
|
78
84
|
process.exit(0);
|
|
79
85
|
}
|
|
@@ -148,6 +154,12 @@ if (argv[0] === 'view') {
|
|
|
148
154
|
let timer;
|
|
149
155
|
fs.watch(file, () => { clearTimeout(timer); timer = setTimeout(() => { load().catch((e) => console.error(String(e))); }, 150); });
|
|
150
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
|
+
}
|
|
151
163
|
else if (argv[0] === 'mcp') {
|
|
152
164
|
// `topotopo mcp [--workspace dir] [--viewer]`: the MCP server over stdio; src/mcp/server.ts reads the remaining
|
|
153
165
|
// arguments from process.argv and runs until the client closes stdin
|
|
@@ -221,7 +233,7 @@ async function cook() {
|
|
|
221
233
|
for (const [f, k] of [['--wireframe', 'wireframe'], ['--hard-angle', 'hard_angle'], ['--section', 'section'], ['--clip', 'clip'], ['--glyphs', 'glyphs'],
|
|
222
234
|
['--glyph-attrib', 'glyph_attrib'], ['--glyph-scale', 'glyph_scale'], ['--max-glyphs', 'max_glyphs'], ['--labels', 'labels'], ['--max-labels', 'max_labels'],
|
|
223
235
|
['--shading', 'shading'], ['--ao-radius', 'ao_radius'], ['--size', 'size'], ['--render-scale', 'scale'], ['--azimuth', 'azimuth'], ['--elevation', 'elevation'],
|
|
224
|
-
['--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']])
|
|
225
237
|
if (get(f) !== undefined)
|
|
226
238
|
a[k] = get(f);
|
|
227
239
|
for (const [f, k] of [['--legend', 'legend'], ['--points', 'points'], ['--annotate', 'annotate'], ['--textures', 'textures']])
|
|
@@ -267,7 +279,7 @@ async function cook() {
|
|
|
267
279
|
if (get('--texture') !== undefined)
|
|
268
280
|
views = !views && v === undefined ? ro.views : views && views.includes('texture') ? views : [...(views ?? parseViews('quad')), 'texture'];
|
|
269
281
|
const title = path.basename(file, '.json') + (r.frame !== 1 ? ` @ frame ${r.frame}` : '');
|
|
270
|
-
const img =
|
|
282
|
+
const img = await renderGeometryAsync(geo, { ...ro, views, colorBy: get('--color-by') ?? null, checker: has('--checker'), title }, (t) => engine.host.readFile(t));
|
|
271
283
|
const p = at(out);
|
|
272
284
|
fs.mkdirSync(path.dirname(path.resolve(p)), { recursive: true });
|
|
273
285
|
fs.writeFileSync(p, encodePNG(img.rgba, img.width, img.height, (d) => zlib.deflateSync(d)));
|
|
@@ -284,12 +296,15 @@ async function cook() {
|
|
|
284
296
|
const up = opt('--up-axis');
|
|
285
297
|
if (argv.includes('--tile-size') && opt('--tile-size') === undefined)
|
|
286
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')}")`);
|
|
287
301
|
const outDir = fmt === 'unreal_landscape' && !/\.json$/i.test(p) ? path.resolve(p) : path.dirname(path.resolve(p));
|
|
288
302
|
const host = engine.host;
|
|
289
303
|
const { files, summary } = await exportFilesAsync(geo, fmt, p, {
|
|
290
304
|
splitByName: true,
|
|
291
305
|
compress: opt('--compress'),
|
|
292
306
|
quantize: argv.includes('--quantize') || undefined,
|
|
307
|
+
tangents: opt('--tangents'),
|
|
293
308
|
pcg: argv.includes('--pcg') || argv.includes('--pcg-struct') || undefined,
|
|
294
309
|
pcgStruct: argv.includes('--pcg-struct') || undefined,
|
|
295
310
|
attributes: opt('--attributes'),
|
|
@@ -336,7 +351,10 @@ async function cook() {
|
|
|
336
351
|
if (!r.ok || !r.geo)
|
|
337
352
|
process.exit(1);
|
|
338
353
|
console.log(`cooked ${file} → ${r.target}${r.frame !== 1 ? ` at frame ${r.frame}` : ''} in ${r.ms.toFixed(0)} ms`);
|
|
339
|
-
|
|
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 }));
|
|
340
358
|
await writeOutputs(r);
|
|
341
359
|
if (argv.includes('--export-all'))
|
|
342
360
|
await exportAll();
|
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));
|