topotopo 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +10 -10
- package/README.md +460 -117
- package/dist/cli.js +323 -146
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/bake.d.ts +14 -3
- package/dist/core/bake.js +153 -4
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +76 -3
- package/dist/core/decimate.d.ts +65 -0
- package/dist/core/decimate.js +409 -3
- package/dist/core/erosion.d.ts +37 -0
- package/dist/core/erosion.js +41 -1
- package/dist/core/geometry.d.ts +5 -1
- package/dist/core/geometry.js +203 -3
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/intrinsics.d.ts +7 -0
- package/dist/core/intrinsics.js +94 -0
- package/dist/core/manifold.d.ts +12 -1
- package/dist/core/manifold.js +78 -6
- package/dist/core/materials.d.ts +7 -0
- package/dist/core/materials.js +45 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/repair.d.ts +2 -0
- package/dist/core/repair.js +2 -0
- package/dist/core/report.d.ts +70 -0
- package/dist/core/report.js +275 -0
- package/dist/core/scene.js +2 -1
- package/dist/core/sha256.d.ts +4 -0
- package/dist/core/sha256.js +69 -0
- package/dist/core/shapes.d.ts +3 -0
- package/dist/core/shapes.js +34 -0
- package/dist/core/snippet-lib.d.ts +14 -1
- package/dist/core/snippet-lib.js +39 -13
- package/dist/core/tangents.d.ts +2 -0
- package/dist/core/tangents.js +5 -1
- package/dist/core/texnoise.d.ts +6 -1
- package/dist/core/texnoise.js +6 -2
- package/dist/core/texsdf.d.ts +131 -0
- package/dist/core/texsdf.js +637 -0
- package/dist/core/texture.d.ts +163 -9
- package/dist/core/texture.js +844 -20
- package/dist/core/topology.d.ts +10 -0
- package/dist/core/topology.js +168 -0
- package/dist/core/unwrap.d.ts +72 -0
- package/dist/core/unwrap.js +800 -0
- package/dist/core/usercode.d.ts +27 -0
- package/dist/core/usercode.js +87 -0
- package/dist/core/uv.d.ts +4 -18
- package/dist/core/uv.js +35 -188
- package/dist/core/uvislands.d.ts +62 -0
- package/dist/core/uvislands.js +574 -0
- package/dist/core/uvoverlap.d.ts +58 -0
- package/dist/core/uvoverlap.js +220 -0
- package/dist/core/uvpack.d.ts +64 -0
- package/dist/core/uvpack.js +628 -0
- package/dist/core/uvreport.d.ts +61 -0
- package/dist/core/uvreport.js +207 -143
- package/dist/core/wrangle.d.ts +6 -1
- package/dist/core/wrangle.js +27 -16
- package/dist/core/xatlas.d.ts +16 -1
- package/dist/core/xatlas.js +66 -62
- package/dist/engines.d.ts +63 -0
- package/dist/engines.js +180 -0
- package/dist/explain.d.ts +4 -3
- package/dist/explain.js +129 -12
- package/dist/graph/engine.d.ts +92 -29
- package/dist/graph/engine.js +298 -148
- package/dist/graph/expr.d.ts +6 -3
- package/dist/graph/expr.js +18 -8
- package/dist/graph/outputs.d.ts +23 -0
- package/dist/graph/outputs.js +41 -0
- package/dist/graph/packages.d.ts +72 -0
- package/dist/graph/packages.js +261 -0
- package/dist/graph/parallel.d.ts +3 -1
- package/dist/graph/parallel.js +4 -1
- package/dist/graph/params.d.ts +6 -0
- package/dist/graph/params.js +34 -7
- package/dist/graph/scope.d.ts +55 -0
- package/dist/graph/scope.js +14 -0
- package/dist/graph/types.d.ts +75 -12
- package/dist/graph/types.js +4 -2
- package/dist/graph/vars.d.ts +16 -0
- package/dist/graph/vars.js +80 -0
- package/dist/host/artifacts.d.ts +10 -1
- package/dist/host/artifacts.js +37 -6
- package/dist/host/cook.d.ts +241 -0
- package/dist/host/cook.js +844 -0
- package/dist/host/export-targets.d.ts +42 -5
- package/dist/host/export-targets.js +72 -13
- package/dist/host/godot-commands.d.ts +4 -0
- package/dist/host/godot-commands.js +21 -0
- package/dist/host/godot.d.ts +183 -0
- package/dist/host/godot.js +916 -0
- package/dist/host/node.d.ts +12 -7
- package/dist/host/node.js +27 -9
- package/dist/host/pool.js +51 -2
- package/dist/host/sidecars.d.ts +8 -0
- package/dist/host/sidecars.js +50 -0
- package/dist/host/types.d.ts +19 -6
- package/dist/host/version.d.ts +1 -0
- package/dist/host/version.js +3 -0
- package/dist/host/worker.js +5 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/inspect.d.ts +80 -2
- package/dist/inspect.js +265 -30
- package/dist/io/common.d.ts +25 -5
- package/dist/io/export.js +2 -1
- package/dist/io/files.d.ts +23 -4
- package/dist/io/files.js +60 -8
- package/dist/io/gltf.js +134 -47
- package/dist/io/heightmap.d.ts +3 -0
- package/dist/io/heightmap.js +1 -0
- package/dist/io/import.js +10 -0
- package/dist/io/inspect-scene.d.ts +55 -0
- package/dist/io/inspect-scene.js +155 -0
- package/dist/io/kinds.d.ts +81 -0
- package/dist/io/kinds.js +163 -0
- package/dist/io/points.d.ts +2 -1
- package/dist/io/points.js +3 -1
- package/dist/io/sidecars.d.ts +24 -0
- package/dist/io/sidecars.js +57 -0
- package/dist/io/source.d.ts +65 -0
- package/dist/io/source.js +112 -0
- package/dist/io/targets.d.ts +47 -3
- package/dist/io/targets.js +148 -13
- package/dist/io/textures.js +21 -1
- package/dist/io/unreal.js +5 -1
- package/dist/mcp/docs.d.ts +10 -1
- package/dist/mcp/docs.js +786 -143
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +56 -27
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +196 -103
- package/dist/mcp/verify.d.ts +2 -2
- package/dist/mcp/verify.js +1 -1
- package/dist/mcp/workspace.d.ts +15 -0
- package/dist/mcp/workspace.js +349 -0
- package/dist/nodes/attributes.js +198 -1
- package/dist/nodes/bake.js +151 -47
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +51 -3
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +21 -9
- package/dist/nodes/curves.js +433 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +12 -38
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.js +16 -19
- package/dist/nodes/index.d.ts +1 -0
- package/dist/nodes/index.js +1 -0
- package/dist/nodes/material.js +89 -24
- package/dist/nodes/measure.js +43 -17
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.js +4 -2
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/splines.d.ts +15 -1
- package/dist/nodes/splines.js +112 -105
- package/dist/nodes/texture.d.ts +21 -6
- package/dist/nodes/texture.js +1318 -185
- package/dist/nodes/topology.d.ts +7 -0
- package/dist/nodes/topology.js +133 -6
- package/dist/nodes/transform.js +6 -2
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +5 -1
- package/dist/open.d.ts +19 -0
- package/dist/open.js +12 -0
- package/dist/package.d.ts +288 -0
- package/dist/package.js +772 -0
- package/dist/packages/check.d.ts +32 -0
- package/dist/packages/check.js +169 -0
- package/dist/packages/commands.d.ts +57 -0
- package/dist/packages/commands.js +537 -0
- package/dist/packages/registry.d.ts +796 -0
- package/dist/packages/registry.js +2998 -0
- package/dist/packages/update.d.ts +124 -0
- package/dist/packages/update.js +476 -0
- package/dist/render/options.d.ts +2 -0
- package/dist/render/options.js +44 -5
- package/dist/render/preview.d.ts +15 -4
- package/dist/render/preview.js +6 -4
- package/dist/render/raster.d.ts +66 -5
- package/dist/render/raster.js +506 -138
- package/dist/render/texview.d.ts +6 -0
- package/dist/render/texview.js +27 -0
- package/dist/scan.d.ts +61 -0
- package/dist/scan.js +228 -0
- package/dist/session.d.ts +311 -0
- package/dist/session.js +849 -0
- package/dist/viewer/app/api.js +48 -6
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +27 -7
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +5 -1
- package/dist/viewer/app/guides.js +122 -0
- package/dist/viewer/app/keymap.js +6 -3
- package/dist/viewer/app/layers.js +4 -4
- package/dist/viewer/app/main.js +185 -52
- package/dist/viewer/app/markers.js +60 -0
- package/dist/viewer/app/outliner.js +72 -27
- package/dist/viewer/app/output-info.js +45 -0
- package/dist/viewer/app/outputs.css +147 -8
- package/dist/viewer/app/outputs.js +168 -54
- package/dist/viewer/app/packages.js +614 -0
- package/dist/viewer/app/props.js +176 -52
- package/dist/viewer/app/scene.js +30 -5
- package/dist/viewer/app/select.js +4 -3
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +65 -7
- package/dist/viewer/app/vars.js +47 -0
- package/dist/viewer/app/welcome.js +72 -0
- package/dist/viewer/graph-file.d.ts +62 -0
- package/dist/viewer/graph-file.js +175 -0
- package/dist/viewer/index.html +23 -10
- package/dist/viewer/json-edit.d.ts +13 -0
- package/dist/viewer/json-edit.js +274 -0
- package/dist/viewer/outputs.d.ts +49 -5
- package/dist/viewer/outputs.js +264 -56
- package/dist/viewer/packages.d.ts +121 -0
- package/dist/viewer/packages.js +584 -0
- package/dist/viewer/server.d.ts +14 -9
- package/dist/viewer/server.js +266 -28
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/{gallery → web}/bake.d.ts +4 -4
- package/dist/{gallery → web}/bake.js +24 -15
- package/dist/web/folder-page.d.ts +101 -0
- package/dist/web/folder-page.js +146 -0
- package/dist/web/folders.d.ts +280 -0
- package/dist/web/folders.js +970 -0
- package/dist/web/library.d.ts +91 -0
- package/dist/web/library.js +228 -0
- package/dist/web/markdown.d.ts +45 -0
- package/dist/web/markdown.js +677 -0
- package/dist/web/pages.d.ts +258 -0
- package/dist/web/pages.js +301 -0
- package/dist/web/server.d.ts +24 -0
- package/dist/web/server.js +1068 -0
- package/dist/workspace.d.ts +88 -118
- package/dist/workspace.js +358 -460
- package/integrations/godot/addons/topotopo/LICENSE +202 -0
- package/integrations/godot/addons/topotopo/README.md +57 -0
- package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
- package/integrations/godot/addons/topotopo/dock.gd +266 -0
- package/integrations/godot/addons/topotopo/dock.tscn +72 -0
- package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
- package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
- package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
- package/integrations/godot/addons/topotopo/inspector.gd +38 -0
- package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
- package/integrations/godot/addons/topotopo/package.gd +23 -0
- package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
- package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
- package/integrations/godot/addons/topotopo/plugin.gd +970 -0
- package/integrations/godot/addons/topotopo/record.gd +435 -0
- package/integrations/godot/addons/topotopo/runner.gd +458 -0
- package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
- package/integrations/godot/addons/topotopo/watcher.gd +199 -0
- package/kernels/pkg/README.md +2 -1
- package/kernels/pkg-simd/README.md +2 -1
- package/library/architecture/versions/1.0/architecture.topo +12 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
- package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
- package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
- package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
- package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
- package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
- package/library/architecture/versions/1.0/version.json +1119 -0
- package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
- package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
- package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
- package/library/nature/versions/1.0/graphs/lineup.json +24 -0
- package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
- package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
- package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
- package/library/nature/versions/1.0/nature.topo +12 -0
- package/library/nature/versions/1.0/version.json +534 -0
- package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
- package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
- package/library/props/versions/1.0/graphs/lineup.json +18 -0
- package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
- package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
- package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
- package/library/props/versions/1.0/props.topo +12 -0
- package/library/props/versions/1.0/version.json +336 -0
- package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
- package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
- package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
- package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
- package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
- package/library/street/versions/1.0/graphs/lineup.json +22 -0
- package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
- package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
- package/library/street/versions/1.0/street.topo +12 -0
- package/library/street/versions/1.0/version.json +421 -0
- package/package.json +17 -8
- package/dist/gallery/app/gallery.css +0 -100
- package/dist/gallery/app/gallery.js +0 -80
- package/dist/gallery/cli.d.ts +0 -4
- package/dist/gallery/cli.js +0 -157
- package/dist/gallery/library.d.ts +0 -124
- package/dist/gallery/library.js +0 -366
- package/dist/gallery/pages.d.ts +0 -94
- package/dist/gallery/pages.js +0 -148
- package/dist/gallery/server.d.ts +0 -21
- package/dist/gallery/server.js +0 -391
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/dist/mcp/library.d.ts +0 -12
- package/dist/mcp/library.js +0 -159
- package/shelf/index.json +0 -190
package/dist/core/geometry.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EdgeSet, EDGE_KEY_LIMIT } from './edges.js';
|
|
2
2
|
import { geoContentHash } from './geohash.js';
|
|
3
|
+
import { MATERIALS_DETAIL, MATERIAL_ATTRIB, TEXTURE_SLOTS, readMaterials, writeMaterials } from './materials.js';
|
|
3
4
|
export const ATTRIB_CLASSES = ['point', 'vertex', 'prim', 'detail'];
|
|
4
5
|
export const ARRAY_TYPES = ['float[]', 'int[]', 'string[]'];
|
|
5
6
|
/** Is t an array attribute type ('float[]', 'int[]', 'string[]')? */
|
|
@@ -386,6 +387,195 @@ export class AttribTable {
|
|
|
386
387
|
export function cloneVolumes(vs) {
|
|
387
388
|
return vs.map((v) => (v.kind === 'heightfield' || v.kind === 'image' || v.kind === 'grid' ? v.clone() : v));
|
|
388
389
|
}
|
|
390
|
+
/** Two images with the same name, size and layers, every layer equal value for value (shared arrays compare at once). */
|
|
391
|
+
export function sameImage(a, b) {
|
|
392
|
+
return a === b || (a.name === b.name && samePixels(a, b));
|
|
393
|
+
}
|
|
394
|
+
/** Two images of the same size and layers, every layer equal value for value, whatever their names. */
|
|
395
|
+
export function samePixels(a, b) {
|
|
396
|
+
if (a === b)
|
|
397
|
+
return true;
|
|
398
|
+
if (a.width !== b.width || a.height !== b.height || a.layers.size !== b.layers.size)
|
|
399
|
+
return false;
|
|
400
|
+
for (const [k, x] of a.layers) {
|
|
401
|
+
const y = b.layers.get(k);
|
|
402
|
+
if (!y || y.length !== x.length)
|
|
403
|
+
return false;
|
|
404
|
+
if (y === x)
|
|
405
|
+
continue;
|
|
406
|
+
for (let i = 0; i < x.length; i++)
|
|
407
|
+
if (x[i] !== y[i] && !(x[i] !== x[i] && y[i] !== y[i]))
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
/** The image name of an "image:<name>" texture path, else null. */
|
|
413
|
+
const imageRefName = (p) => (p && p.startsWith('image:') ? p.slice(6).trim() : null);
|
|
414
|
+
/**
|
|
415
|
+
* Inputs of a merge with distinct names for what differs. Each input with its packed sources is one namespace (its
|
|
416
|
+
* materials name its images, its prims its materials). Across inputs, an image name already used for other pixels is
|
|
417
|
+
* renamed "<material>_<name>" after the first of the input's materials that uses it (else "<name>_2", "_3" …), and a
|
|
418
|
+
* material name already used for another definition "<name>_2" …; the input's material tables and prim "material"
|
|
419
|
+
* follow. Two package outputs or asset instances that both call their maps "basecolor" then keep their own maps
|
|
420
|
+
* instead of the first one's, while what several inputs share (the same image, the same material) keeps its name and
|
|
421
|
+
* is stored once. Inputs that need no change are returned as they are.
|
|
422
|
+
*/
|
|
423
|
+
function distinctNames(geos) {
|
|
424
|
+
const groupOf = (g) => (g.packedSources.length ? [g, ...g.packedSources] : [g]);
|
|
425
|
+
if (!geos.some((g) => groupOf(g).some((u) => u.detail.has(MATERIALS_DETAIL) || u.volumes.some((v) => v.kind === 'image'))))
|
|
426
|
+
return geos;
|
|
427
|
+
const images = new Map(), mats = new Map();
|
|
428
|
+
return geos.map((g) => {
|
|
429
|
+
const units = groupOf(g);
|
|
430
|
+
const own = new Map();
|
|
431
|
+
for (const u of units)
|
|
432
|
+
for (const v of u.volumes)
|
|
433
|
+
if (v.kind === 'image' && !own.has(v.name))
|
|
434
|
+
own.set(v.name, v);
|
|
435
|
+
const tables = units.map((u) => (u.detail.has(MATERIALS_DETAIL) ? readMaterials(u) : null));
|
|
436
|
+
const ownMats = new Map();
|
|
437
|
+
for (const t of tables)
|
|
438
|
+
if (t)
|
|
439
|
+
for (const [m, def] of Object.entries(t))
|
|
440
|
+
if (!ownMats.has(m))
|
|
441
|
+
ownMats.set(m, def);
|
|
442
|
+
// images: a name taken by other pixels gets another (the name these pixels already got, when an earlier input
|
|
443
|
+
// carried them too)
|
|
444
|
+
const reImg = new Map(), given = new Set();
|
|
445
|
+
const free = (n) => !images.has(n) && !own.has(n) && !given.has(n);
|
|
446
|
+
for (const [n, v] of own) {
|
|
447
|
+
const seen = images.get(n);
|
|
448
|
+
if (!seen || seen.some((s) => samePixels(s, v)))
|
|
449
|
+
continue;
|
|
450
|
+
let to = '';
|
|
451
|
+
for (const [name, list] of images)
|
|
452
|
+
if (!own.has(name) && list.some((s) => samePixels(s, v))) {
|
|
453
|
+
to = name;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
if (!to) {
|
|
457
|
+
let user = '';
|
|
458
|
+
for (const [m, def] of ownMats)
|
|
459
|
+
if (TEXTURE_SLOTS.some((k) => imageRefName(def.textures?.[k]) === n)) {
|
|
460
|
+
user = m;
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
if (user && free(`${user}_${n}`))
|
|
464
|
+
to = `${user}_${n}`;
|
|
465
|
+
for (let k = 2; !to; k++)
|
|
466
|
+
if (free(`${n}_${k}`))
|
|
467
|
+
to = `${n}_${k}`;
|
|
468
|
+
}
|
|
469
|
+
reImg.set(n, to);
|
|
470
|
+
given.add(to);
|
|
471
|
+
}
|
|
472
|
+
for (const [n, v] of own) {
|
|
473
|
+
const fin = reImg.get(n) ?? n, list = images.get(fin);
|
|
474
|
+
if (!list)
|
|
475
|
+
images.set(fin, [v]);
|
|
476
|
+
else if (!list.some((s) => samePixels(s, v)))
|
|
477
|
+
list.push(v);
|
|
478
|
+
}
|
|
479
|
+
// materials: their image references follow, then a name taken by another definition gets another
|
|
480
|
+
const retex = (def) => {
|
|
481
|
+
if (!reImg.size || !def.textures)
|
|
482
|
+
return def;
|
|
483
|
+
const t = { ...def.textures };
|
|
484
|
+
for (const k of TEXTURE_SLOTS) {
|
|
485
|
+
const r = imageRefName(t[k]);
|
|
486
|
+
if (r && reImg.has(r))
|
|
487
|
+
t[k] = `image:${reImg.get(r)}`;
|
|
488
|
+
}
|
|
489
|
+
return { ...def, textures: t };
|
|
490
|
+
};
|
|
491
|
+
const reMat = new Map(), givenM = new Set();
|
|
492
|
+
for (const [m, def] of ownMats) {
|
|
493
|
+
const key = JSON.stringify(retex(def)), had = mats.get(m);
|
|
494
|
+
if (had === key)
|
|
495
|
+
continue;
|
|
496
|
+
// the name an earlier input already gave this definition (the family "<base>", "<base>_2" … that renames make,
|
|
497
|
+
// so a merge of merges does not keep two names for one material), else m itself when free, else the next free one
|
|
498
|
+
const base = m.replace(/_\d+$/, '');
|
|
499
|
+
let to = '';
|
|
500
|
+
for (let k = 1; !to; k++) {
|
|
501
|
+
const n = k === 1 ? base : `${base}_${k}`, at = mats.get(n);
|
|
502
|
+
if (at === undefined)
|
|
503
|
+
break;
|
|
504
|
+
if (at === key && (n === m || !ownMats.has(n) || reMat.has(n)))
|
|
505
|
+
to = n;
|
|
506
|
+
}
|
|
507
|
+
if (!to && had === undefined) {
|
|
508
|
+
mats.set(m, key);
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
for (let k = 2; !to; k++) {
|
|
512
|
+
const n = `${base}_${k}`;
|
|
513
|
+
if (!mats.has(n) && !ownMats.has(n) && !givenM.has(n))
|
|
514
|
+
to = n;
|
|
515
|
+
}
|
|
516
|
+
if (to === m)
|
|
517
|
+
continue;
|
|
518
|
+
reMat.set(m, to);
|
|
519
|
+
givenM.add(to);
|
|
520
|
+
mats.set(to, key);
|
|
521
|
+
}
|
|
522
|
+
if (!reImg.size && !reMat.size)
|
|
523
|
+
return g;
|
|
524
|
+
// rewrite every unit of the input: image names, tables, prim material
|
|
525
|
+
const rewrite = (u, t) => {
|
|
526
|
+
const touchesImages = u.volumes.some((v) => v.kind === 'image' && reImg.has(v.name));
|
|
527
|
+
const pm = u.prims.get(MATERIAL_ATTRIB);
|
|
528
|
+
const touchesPrims = !!pm && pm.type === 'string' && reMat.size > 0 && pm.data.some((x) => reMat.has(x));
|
|
529
|
+
const touchesTable = !!t && Object.entries(t).some(([m, def]) => reMat.has(m) || TEXTURE_SLOTS.some((k) => reImg.has(imageRefName(def.textures?.[k]) ?? '')));
|
|
530
|
+
if (!touchesImages && !touchesTable && !touchesPrims)
|
|
531
|
+
return u;
|
|
532
|
+
const c = u.clone();
|
|
533
|
+
if (touchesImages)
|
|
534
|
+
c.volumes = c.volumes.map((v) => (v.kind === 'image' && reImg.has(v.name) ? Object.assign(v.clone(), { name: reImg.get(v.name) }) : v));
|
|
535
|
+
if (t && touchesTable) {
|
|
536
|
+
const out = {};
|
|
537
|
+
for (const [m, def] of Object.entries(t))
|
|
538
|
+
out[reMat.get(m) ?? m] = retex(def);
|
|
539
|
+
writeMaterials(c, out);
|
|
540
|
+
}
|
|
541
|
+
if (touchesPrims)
|
|
542
|
+
c.prims.set(MATERIAL_ATTRIB, new Attribute('string', 1, pm.data.map((x) => reMat.get(x) ?? x), ''));
|
|
543
|
+
return c;
|
|
544
|
+
};
|
|
545
|
+
const top = rewrite(g, tables[0]);
|
|
546
|
+
if (units.length > 1) {
|
|
547
|
+
const sources = g.packedSources.map((s, i) => rewrite(s, tables[i + 1]));
|
|
548
|
+
if (sources.some((s, i) => s !== g.packedSources[i])) {
|
|
549
|
+
const t = top === g ? g.clone() : top;
|
|
550
|
+
t.packedSources = sources;
|
|
551
|
+
return t;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return top;
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Volumes of merged inputs with repeated images dropped: an image equal to an earlier one (sameImage: the same name and
|
|
559
|
+
* pixels, as when textured LOD branches each carry the material's maps) is kept once. Same-named images that differ
|
|
560
|
+
* all stay (texture nodes then ask which one to use).
|
|
561
|
+
*/
|
|
562
|
+
function mergeVolumes(vs) {
|
|
563
|
+
const out = [];
|
|
564
|
+
const images = new Map();
|
|
565
|
+
for (const v of vs) {
|
|
566
|
+
if (v.kind === 'image') {
|
|
567
|
+
const seen = images.get(v.name);
|
|
568
|
+
if (seen?.some((s) => sameImage(s, v)))
|
|
569
|
+
continue;
|
|
570
|
+
if (seen)
|
|
571
|
+
seen.push(v);
|
|
572
|
+
else
|
|
573
|
+
images.set(v.name, [v]);
|
|
574
|
+
}
|
|
575
|
+
out.push(v);
|
|
576
|
+
}
|
|
577
|
+
return cloneVolumes(out);
|
|
578
|
+
}
|
|
389
579
|
/**
|
|
390
580
|
* Every Geometry object the engine made (the constructor and Geometry.blank add them). A brand check that runs no user
|
|
391
581
|
* code: `instanceof` and Object.getPrototypeOf call a Proxy's getPrototypeOf trap, and a script node may hand back a
|
|
@@ -903,7 +1093,7 @@ export class Geometry {
|
|
|
903
1093
|
* Concatenate geometries. Attributes are unioned; missing values take attribute defaults.
|
|
904
1094
|
* Display attributes (Cd, Alpha, N, uv) that live on different classes in different inputs
|
|
905
1095
|
* are promoted to vertex attributes first, so every input keeps its look (a point Cd from one
|
|
906
|
-
* input never masks a prim Cd from another).
|
|
1096
|
+
* input never masks a prim Cd from another). An image that several inputs carry (same name and pixels) is kept once.
|
|
907
1097
|
*/
|
|
908
1098
|
static merge(geos) {
|
|
909
1099
|
geos = geos.filter(Boolean);
|
|
@@ -911,7 +1101,7 @@ export class Geometry {
|
|
|
911
1101
|
return new Geometry();
|
|
912
1102
|
if (geos.length === 1)
|
|
913
1103
|
return geos[0].clone();
|
|
914
|
-
geos = unifyDisplayAttribs(geos);
|
|
1104
|
+
geos = unifyDisplayAttribs(distinctNames(geos));
|
|
915
1105
|
const out = Geometry.blank();
|
|
916
1106
|
const total = (f) => geos.reduce((s, g) => s + f(g), 0);
|
|
917
1107
|
const np = total((g) => g.numPoints), nv = total((g) => g.numVertices), nprim = total((g) => g.numPrims);
|
|
@@ -923,6 +1113,16 @@ export class Geometry {
|
|
|
923
1113
|
for (const [k, a] of g.detail.map)
|
|
924
1114
|
if (!out.detail.has(k))
|
|
925
1115
|
out.detail.map.set(k, a.clone());
|
|
1116
|
+
// material tables: the union (names made distinct above)
|
|
1117
|
+
const withTables = geos.filter((g) => g.detail.has(MATERIALS_DETAIL));
|
|
1118
|
+
if (withTables.length > 1) {
|
|
1119
|
+
const union = {};
|
|
1120
|
+
for (const g of withTables)
|
|
1121
|
+
for (const [m, def] of Object.entries(readMaterials(g)))
|
|
1122
|
+
if (!(m in union))
|
|
1123
|
+
union[m] = def;
|
|
1124
|
+
writeMaterials(out, union);
|
|
1125
|
+
}
|
|
926
1126
|
out.primStart = new Int32Array(nprim + 1);
|
|
927
1127
|
out.vertexPoint = new Int32Array(nv);
|
|
928
1128
|
out.primClosed = new Uint8Array(nprim);
|
|
@@ -943,7 +1143,7 @@ export class Geometry {
|
|
|
943
1143
|
out.primGroups = mergeGroups(geos.map((g) => [g.primGroups, g.numPrims]), nprim);
|
|
944
1144
|
out.vertexGroups = mergeGroups(geos.map((g) => [g.vertexGroups, g.numVertices]), nv);
|
|
945
1145
|
out.edgeGroups = mergeEdgeGroups(geos.map((g) => [g.edgeGroups, g.numPoints]));
|
|
946
|
-
out.volumes =
|
|
1146
|
+
out.volumes = mergeVolumes(geos.flatMap((g) => g.volumes));
|
|
947
1147
|
if (geos.some((g) => g.primKind))
|
|
948
1148
|
mergePacked(out, geos);
|
|
949
1149
|
return out;
|
|
@@ -117,6 +117,11 @@ export declare function curvesOf(g: Geometry): {
|
|
|
117
117
|
* height layer. Returns a new field (layers re-gridded when the XZ part rotates or mirrors).
|
|
118
118
|
*/
|
|
119
119
|
export declare function transformHeightfield(src: HeightfieldVolume, m: ArrayLike<number>): Heightfield;
|
|
120
|
+
/**
|
|
121
|
+
* The samples i0..i1 × j0..j1 (inclusive) of a heightfield as a new field with every layer: the same cell size and the
|
|
122
|
+
* same sample positions (origin moved to sample (i0, j0)), no resampling. Needs at least 2 × 2 samples in range.
|
|
123
|
+
*/
|
|
124
|
+
export declare function cropHeightfield(src: HeightfieldVolume, i0: number, i1: number, j0: number, j1: number): Heightfield;
|
|
120
125
|
export interface ToMeshOptions {
|
|
121
126
|
/** take every step-th sample (1 = full resolution); the last row and column are always included */
|
|
122
127
|
step?: number;
|
|
@@ -128,16 +133,34 @@ export interface ToMeshOptions {
|
|
|
128
133
|
uv?: boolean;
|
|
129
134
|
/** point Cd: none, mask (white → red), height (low → high ramp), terrain (grass / rock / sediment / snow / road), preview */
|
|
130
135
|
color?: 'none' | 'mask' | 'height' | 'terrain' | 'preview';
|
|
136
|
+
/**
|
|
137
|
+
* color "mask" and "preview": the layer drawn in red (default "mask"; "none" or null: none). The mask and any layer
|
|
138
|
+
* within 0..1 show as they are (clamped to 0..1), any other layer from its minimum (none) to its maximum (full red).
|
|
139
|
+
*/
|
|
140
|
+
colorLayer?: string | null;
|
|
131
141
|
}
|
|
142
|
+
/** The layer a preview draws in red as a 0..1 value per sample, or null when it is missing or shows nothing. */
|
|
143
|
+
export declare function layerTint(hf: Heightfield, name?: string | null): ((k: number) => number) | null;
|
|
132
144
|
/** The heightfield as a grid of quads facing +Y (points row-major like the layers when step is 1). */
|
|
133
145
|
export declare function heightfieldToMesh(hf: Heightfield, o?: ToMeshOptions): Geometry;
|
|
134
|
-
/**
|
|
135
|
-
|
|
146
|
+
/**
|
|
147
|
+
* How the preview draws a heightfield with at most maxRes quads per side (Infinity: every sample): every step-th
|
|
148
|
+
* sample (the last one always), `shown` samples along X and Z.
|
|
149
|
+
*/
|
|
150
|
+
export declare function heightfieldPreviewStep(hf: HeightfieldVolume, maxRes?: number): {
|
|
151
|
+
step: number;
|
|
152
|
+
shown: [number, number];
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* The render preview of a heightfield: its grid decimated to at most maxRes quads per side, all layers as point
|
|
156
|
+
* attributes, height-ramp Cd with a layer in red: the mask, or `layer` ("none": none).
|
|
157
|
+
*/
|
|
158
|
+
export declare function heightfieldPreviewMesh(hf: HeightfieldVolume, maxRes?: number, layer?: string): Geometry;
|
|
136
159
|
/**
|
|
137
160
|
* For rendering and viewing: a geometry whose heightfields are replaced by their preview meshes (merged with the
|
|
138
|
-
* rest of the geometry). Returns g itself when it holds no heightfield.
|
|
161
|
+
* rest of the geometry), each with `layer` in red (default the mask). Returns g itself when it holds no heightfield.
|
|
139
162
|
*/
|
|
140
|
-
export declare function withHeightfieldPreview(g: Geometry, maxRes?: number): Geometry;
|
|
163
|
+
export declare function withHeightfieldPreview(g: Geometry, maxRes?: number, layer?: string): Geometry;
|
|
141
164
|
/** "1 SDF volume, 1 heightfield, 2 images" style counts (empty string when there are no volumes). */
|
|
142
165
|
export declare function volumeCounts(g: Geometry): string;
|
|
143
166
|
/** Inspect/summary lines for the heightfields of a geometry: grid, extent and per-layer min/max/mean. */
|
package/dist/core/heightfield.js
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
// Cooked geometry is immutable: Geometry.clone() gives each heightfield its own layer map but shares the arrays,
|
|
10
10
|
// so a node writes through `writable(name)` (a private copy) and never into an array it did not allocate.
|
|
11
11
|
// This module holds the volume class, sampling (bilinear, or over Unreal Landscape triangles), grid filters (blur,
|
|
12
|
-
// distance transforms), rasterising meshes and curves onto the grid, conversion to polygons, the
|
|
13
|
-
// the inspect summary.
|
|
12
|
+
// distance transforms), rasterising meshes and curves onto the grid, transforms and crops, conversion to polygons, the
|
|
13
|
+
// render preview and the inspect summary.
|
|
14
14
|
import { AttribTable, Geometry } from './geometry.js';
|
|
15
15
|
import { triangulate } from './topology.js';
|
|
16
16
|
/** Largest grid a node may create (samples). */
|
|
@@ -452,6 +452,36 @@ export function transformHeightfield(src, m) {
|
|
|
452
452
|
}
|
|
453
453
|
return out;
|
|
454
454
|
}
|
|
455
|
+
/**
|
|
456
|
+
* The samples i0..i1 × j0..j1 (inclusive) of a heightfield as a new field with every layer: the same cell size and the
|
|
457
|
+
* same sample positions (origin moved to sample (i0, j0)), no resampling. Needs at least 2 × 2 samples in range.
|
|
458
|
+
*/
|
|
459
|
+
export function cropHeightfield(src, i0, i1, j0, j1) {
|
|
460
|
+
const hf = asHeightfield(src);
|
|
461
|
+
if (!(Number.isInteger(i0) && Number.isInteger(i1) && Number.isInteger(j0) && Number.isInteger(j1)) || i0 < 0 || j0 < 0 || i1 >= hf.width || j1 >= hf.height || i1 - i0 < 1 || j1 - j0 < 1)
|
|
462
|
+
throw new Error(`crop ${i0}..${i1} × ${j0}..${j1} is not a range of at least 2 × 2 samples inside ${hf.width} × ${hf.height}`);
|
|
463
|
+
const w = i1 - i0 + 1, h = j1 - j0 + 1;
|
|
464
|
+
const out = new Heightfield(w, h, hf.cellSize, [hf.x(i0), hf.z(j0)], undefined, hf.name);
|
|
465
|
+
for (const [name, a] of hf.layers) {
|
|
466
|
+
const b = new Float32Array(w * h);
|
|
467
|
+
for (let j = 0; j < h; j++)
|
|
468
|
+
b.set(a.subarray((j0 + j) * hf.width + i0, (j0 + j) * hf.width + i1 + 1), j * w);
|
|
469
|
+
out.layers.set(name, b);
|
|
470
|
+
}
|
|
471
|
+
return out;
|
|
472
|
+
}
|
|
473
|
+
/** The layer a preview draws in red as a 0..1 value per sample, or null when it is missing or shows nothing. */
|
|
474
|
+
export function layerTint(hf, name = 'mask') {
|
|
475
|
+
const a = name === null || name === 'none' ? undefined : hf.layer(name);
|
|
476
|
+
const st = layerStats(a);
|
|
477
|
+
if (!a || !st)
|
|
478
|
+
return null;
|
|
479
|
+
const unit = name === 'mask' || (st.min >= 0 && st.max <= 1);
|
|
480
|
+
const lo = unit ? 0 : st.min, span = unit ? 1 : st.max - st.min;
|
|
481
|
+
if (!(st.max > lo) || !(span > 0))
|
|
482
|
+
return null;
|
|
483
|
+
return (k) => { const x = (a[k] - lo) / span; return x > 0 ? (x < 1 ? x : 1) : 0; };
|
|
484
|
+
}
|
|
455
485
|
const ramp = (stops, t) => {
|
|
456
486
|
if (t <= stops[0][0])
|
|
457
487
|
return stops[0][1];
|
|
@@ -541,24 +571,23 @@ export function heightfieldToMesh(hf, o = {}) {
|
|
|
541
571
|
const Cd = g.points.add('Cd', 'float', 3).data;
|
|
542
572
|
const st = layerStats(H);
|
|
543
573
|
const span = st.max - st.min || 1;
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
const showMask = !!mask && !!mst && mst.max > 0 && (color === 'mask' || color === 'preview');
|
|
574
|
+
// the layer drawn in red (the mask unless colorLayer names another)
|
|
575
|
+
const tint = color === 'mask' || color === 'preview' ? layerTint(hf, o.colorLayer === undefined ? 'mask' : o.colorLayer) : null;
|
|
547
576
|
const slope = color === 'terrain' ? slopeLayer(hf, H) : null;
|
|
548
577
|
const sed = hf.layer('sediment'), deb = hf.layer('debris'), flow = hf.layer('flow'), road = hf.layer('path'), water = hf.layer('water');
|
|
549
578
|
for (let p = 0; p < np; p++) {
|
|
550
579
|
const k = src[p], t = (H[k] - st.min) / span;
|
|
551
580
|
let c;
|
|
552
581
|
if (color === 'mask') {
|
|
553
|
-
const m =
|
|
582
|
+
const m = tint ? tint(k) : 0;
|
|
554
583
|
c = [0.85 + 0.1 * m, 0.85 - 0.7 * m, 0.85 - 0.75 * m];
|
|
555
584
|
}
|
|
556
585
|
else if (color === 'height')
|
|
557
586
|
c = ramp(HEIGHT_RAMP, t);
|
|
558
587
|
else if (color === 'preview') {
|
|
559
588
|
c = ramp(PREVIEW_RAMP, t);
|
|
560
|
-
if (
|
|
561
|
-
const m =
|
|
589
|
+
if (tint) {
|
|
590
|
+
const m = tint(k) * 0.7;
|
|
562
591
|
c = [c[0] + (0.9 - c[0]) * m, c[1] + (0.12 - c[1]) * m, c[2] + (0.1 - c[2]) * m];
|
|
563
592
|
}
|
|
564
593
|
}
|
|
@@ -595,22 +624,31 @@ export function heightfieldToMesh(hf, o = {}) {
|
|
|
595
624
|
}
|
|
596
625
|
return g;
|
|
597
626
|
}
|
|
598
|
-
/**
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
627
|
+
/**
|
|
628
|
+
* How the preview draws a heightfield with at most maxRes quads per side (Infinity: every sample): every step-th
|
|
629
|
+
* sample (the last one always), `shown` samples along X and Z.
|
|
630
|
+
*/
|
|
631
|
+
export function heightfieldPreviewStep(hf, maxRes = 256) {
|
|
632
|
+
const step = Math.max(1, Math.ceil((Math.max(hf.width, hf.height) - 1) / Math.max(1, maxRes)));
|
|
633
|
+
return { step, shown: [steps(hf.width, step).length, steps(hf.height, step).length] };
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* The render preview of a heightfield: its grid decimated to at most maxRes quads per side, all layers as point
|
|
637
|
+
* attributes, height-ramp Cd with a layer in red: the mask, or `layer` ("none": none).
|
|
638
|
+
*/
|
|
639
|
+
export function heightfieldPreviewMesh(hf, maxRes = 256, layer = 'mask') {
|
|
640
|
+
return heightfieldToMesh(asHeightfield(hf), { step: heightfieldPreviewStep(hf, maxRes).step, layers: true, normals: true, color: 'preview', colorLayer: layer });
|
|
603
641
|
}
|
|
604
642
|
/**
|
|
605
643
|
* For rendering and viewing: a geometry whose heightfields are replaced by their preview meshes (merged with the
|
|
606
|
-
* rest of the geometry). Returns g itself when it holds no heightfield.
|
|
644
|
+
* rest of the geometry), each with `layer` in red (default the mask). Returns g itself when it holds no heightfield.
|
|
607
645
|
*/
|
|
608
|
-
export function withHeightfieldPreview(g, maxRes = 256) {
|
|
646
|
+
export function withHeightfieldPreview(g, maxRes = 256, layer = 'mask') {
|
|
609
647
|
if (!g.volumes.some(isHeightfield))
|
|
610
648
|
return g;
|
|
611
649
|
const rest = g.clone();
|
|
612
650
|
rest.volumes = rest.volumes.filter((v) => !isHeightfield(v));
|
|
613
|
-
const previews = g.volumes.filter(isHeightfield).map((v) => heightfieldPreviewMesh(v, maxRes));
|
|
651
|
+
const previews = g.volumes.filter(isHeightfield).map((v) => heightfieldPreviewMesh(v, maxRes, layer));
|
|
614
652
|
return Geometry.merge(rest.numPoints || rest.volumes.length ? [rest, ...previews] : previews);
|
|
615
653
|
}
|
|
616
654
|
// ---------------------------------------------------------------- inspection
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Geometry } from './geometry.ts';
|
|
2
|
+
/** Every prim intrinsic name. */
|
|
3
|
+
export declare const PRIM_INTRINSICS: readonly string[];
|
|
4
|
+
/** The intrinsics prim p has. */
|
|
5
|
+
export declare function primIntrinsicNames(g: Geometry, p: number): string[];
|
|
6
|
+
/** Intrinsic `name` of prim p: a number, a string or an array; throws for an unknown name or one p does not have. */
|
|
7
|
+
export declare function primIntrinsic(g: Geometry, p: number, name: string): number | string | number[];
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// cooked geometry is immutable, so a source's box can be kept as long as the source lives
|
|
2
|
+
const sourceBoxes = new WeakMap();
|
|
3
|
+
const sourceBox = (src) => {
|
|
4
|
+
let b = sourceBoxes.get(src);
|
|
5
|
+
if (!b) {
|
|
6
|
+
b = src.bbox(true);
|
|
7
|
+
sourceBoxes.set(src, b);
|
|
8
|
+
}
|
|
9
|
+
return b;
|
|
10
|
+
};
|
|
11
|
+
const NONE = () => [0, 0, 0, 0, 0, 0];
|
|
12
|
+
const flat = (b) => (b.empty ? NONE() : [b.min[0], b.max[0], b.min[1], b.max[1], b.min[2], b.max[2]]);
|
|
13
|
+
/** typename per prim kind (0 polygon or polyline, 1 packed, 2 Bezier, 3 NURBS) */
|
|
14
|
+
const TYPE_NAMES = ['Poly', 'PackedGeometry', 'BezierCurve', 'NURBCurve'];
|
|
15
|
+
const COMMON = ['bounds', 'typename', 'vertexcount'];
|
|
16
|
+
const SHAPE = ['closed'];
|
|
17
|
+
const PACKED = ['packedbounds', 'transform', 'packedfulltransform', 'packedlocaltransform', 'pivot'];
|
|
18
|
+
/** Every prim intrinsic name. */
|
|
19
|
+
export const PRIM_INTRINSICS = [...COMMON, ...SHAPE, ...PACKED];
|
|
20
|
+
/** The intrinsics prim p has. */
|
|
21
|
+
export function primIntrinsicNames(g, p) {
|
|
22
|
+
return g.isPacked(p) ? [...COMMON, ...PACKED] : [...COMMON, ...SHAPE];
|
|
23
|
+
}
|
|
24
|
+
/** World box of a packed instance: the exact box of its source's box under the instance transform. */
|
|
25
|
+
function instanceBounds(g, p) {
|
|
26
|
+
const src = g.packedSources[g.packedSource[p]], b = src ? sourceBox(src) : null;
|
|
27
|
+
if (!b || b.empty || g.primStart[p + 1] === g.primStart[p])
|
|
28
|
+
return NONE();
|
|
29
|
+
const X = g.packedXform, o = p * 9, a = g.vertexPoint[g.primStart[p]] * 3, P = g.P, out = [];
|
|
30
|
+
for (let r = 0; r < 3; r++) {
|
|
31
|
+
const m0 = X[o + r], m1 = X[o + 3 + r], m2 = X[o + 6 + r];
|
|
32
|
+
const c = P[a + r] + m0 * (b.min[0] + b.max[0]) / 2 + m1 * (b.min[1] + b.max[1]) / 2 + m2 * (b.min[2] + b.max[2]) / 2;
|
|
33
|
+
const e = (Math.abs(m0) * (b.max[0] - b.min[0]) + Math.abs(m1) * (b.max[1] - b.min[1]) + Math.abs(m2) * (b.max[2] - b.min[2])) / 2;
|
|
34
|
+
out.push(c - e, c + e);
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
/** Box of a polygon's or curve's points (a spline's control points). */
|
|
39
|
+
function pointBounds(g, p) {
|
|
40
|
+
const pts = g.primPoints(p), P = g.P;
|
|
41
|
+
if (!pts.length)
|
|
42
|
+
return NONE();
|
|
43
|
+
const out = [Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity];
|
|
44
|
+
for (const q of pts)
|
|
45
|
+
for (let k = 0; k < 3; k++) {
|
|
46
|
+
const v = P[q * 3 + k];
|
|
47
|
+
if (v < out[k * 2])
|
|
48
|
+
out[k * 2] = v;
|
|
49
|
+
if (v > out[k * 2 + 1])
|
|
50
|
+
out[k * 2 + 1] = v;
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
/** Intrinsic `name` of prim p: a number, a string or an array; throws for an unknown name or one p does not have. */
|
|
55
|
+
export function primIntrinsic(g, p, name) {
|
|
56
|
+
if (!Number.isInteger(p) || p < 0 || p >= g.numPrims)
|
|
57
|
+
throw new Error(`prim ${p} is out of range (${g.numPrims} prims)`);
|
|
58
|
+
const packed = g.isPacked(p), type = TYPE_NAMES[g.primKind ? g.primKind[p] : 0] ?? 'Poly';
|
|
59
|
+
switch (name) {
|
|
60
|
+
case 'bounds': return packed ? instanceBounds(g, p) : pointBounds(g, p);
|
|
61
|
+
case 'typename': return type;
|
|
62
|
+
case 'vertexcount': return g.primStart[p + 1] - g.primStart[p];
|
|
63
|
+
case 'closed':
|
|
64
|
+
if (!packed)
|
|
65
|
+
return g.primClosed[p] ? 1 : 0;
|
|
66
|
+
break;
|
|
67
|
+
case 'packedbounds':
|
|
68
|
+
if (packed) {
|
|
69
|
+
const src = g.packedSources[g.packedSource[p]];
|
|
70
|
+
return src ? flat(sourceBox(src)) : NONE();
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
case 'transform':
|
|
74
|
+
if (packed)
|
|
75
|
+
return Array.from(g.packedXform.subarray(p * 9, p * 9 + 9));
|
|
76
|
+
break;
|
|
77
|
+
case 'packedfulltransform':
|
|
78
|
+
case 'packedlocaltransform':
|
|
79
|
+
if (packed) {
|
|
80
|
+
const X = g.packedXform, o = p * 9, P = g.P, has = g.primStart[p + 1] > g.primStart[p], a = has ? g.vertexPoint[g.primStart[p]] * 3 : -1;
|
|
81
|
+
return [X[o], X[o + 1], X[o + 2], 0, X[o + 3], X[o + 4], X[o + 5], 0, X[o + 6], X[o + 7], X[o + 8], 0,
|
|
82
|
+
has ? P[a] : 0, has ? P[a + 1] : 0, has ? P[a + 2] : 0, 1];
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case 'pivot':
|
|
86
|
+
if (packed)
|
|
87
|
+
return [0, 0, 0];
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
const have = primIntrinsicNames(g, p).join(', ');
|
|
91
|
+
if (PRIM_INTRINSICS.includes(name))
|
|
92
|
+
throw new Error(`prim ${p} is ${type}: "${name}" is only on ${PACKED.includes(name) ? 'packed prims' : 'polygons and curves'} (this prim has ${have})`);
|
|
93
|
+
throw new Error(`no intrinsic "${name}" (this prim has ${have})`);
|
|
94
|
+
}
|
package/dist/core/manifold.d.ts
CHANGED
|
@@ -43,6 +43,17 @@ export declare function toPolygons(g: Geometry, plane: Plane): {
|
|
|
43
43
|
polys: [number, number][][];
|
|
44
44
|
offset: number;
|
|
45
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* Contours by nesting: a contour lying wholly inside another is a hole of it (depth 1), one inside a hole an island
|
|
48
|
+
* (depth 2) and so on. Returns the contours wound counter-clockwise at even depth and clockwise at odd depth (so the
|
|
49
|
+
* NonZero rule fills shapes, cuts holes and still unions shapes that only overlap), each one's depth and the index
|
|
50
|
+
* of the contour it lies directly in (-1 at the top).
|
|
51
|
+
*/
|
|
52
|
+
export declare function orientNested(polys: [number, number][][]): {
|
|
53
|
+
polys: [number, number][][];
|
|
54
|
+
depth: number[];
|
|
55
|
+
parent: number[];
|
|
56
|
+
};
|
|
46
57
|
/**
|
|
47
58
|
* A manifold CrossSection from 2D contours. No contours (empty input, points only, open curves) gives an empty
|
|
48
59
|
* section: manifold's constructor throws a raw TypeError on an empty list.
|
|
@@ -52,5 +63,5 @@ export declare function crossSection(polys: [number, number][][], fillRule: 'Eve
|
|
|
52
63
|
export declare function planeMatrix(plane: Plane, offset?: number): number[];
|
|
53
64
|
/** 2D polygons → closed polygons (Houdini-style closed curves) in the world plane. */
|
|
54
65
|
export declare function polygonsToGeo(polys: [number, number][][], plane: Plane, offset?: number, asPolygons?: boolean): Geometry;
|
|
55
|
-
/**
|
|
66
|
+
/** Faces for a CrossSection in the world plane: one polygon per shape, a few for a shape with holes. */
|
|
56
67
|
export declare function crossSectionFaces(cs: any, plane: Plane, offset?: number): Geometry;
|