topotopo 0.4.0 → 0.5.1
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 +327 -147
- 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 +198 -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 +57 -5
- package/dist/render/preview.d.ts +17 -4
- package/dist/render/preview.js +6 -4
- package/dist/render/raster.d.ts +74 -5
- package/dist/render/raster.js +527 -143
- 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 +13 -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/nodes/flow.js
CHANGED
|
@@ -7,7 +7,7 @@ import { stableStringify } from '../graph/engine.js';
|
|
|
7
7
|
import { hashString } from '../core/random.js';
|
|
8
8
|
import { IMPORT_FORMATS, importFormatFromPath, importGeometryAsync } from '../io/import.js';
|
|
9
9
|
import { readImageFile } from '../io/textures.js';
|
|
10
|
-
import {
|
|
10
|
+
import { scopeSig } from '../graph/scope.js';
|
|
11
11
|
import { fusePoints } from './transform.js';
|
|
12
12
|
import { DEFAULT_TRANSFER, composePackedXforms, expandPacked } from '../core/packed.js';
|
|
13
13
|
defineNode({
|
|
@@ -15,6 +15,7 @@ defineNode({
|
|
|
15
15
|
category: 'flow',
|
|
16
16
|
packed: 'keep',
|
|
17
17
|
summary: 'Combine any number of inputs into one geometry (attributes, groups and material tables are unioned).',
|
|
18
|
+
description: 'Material tables are unioned and images (texture nodes) combined. What several inputs share (the same image, the same material) is kept once. A name two inputs use for different things is made distinct, so each piece keeps its own maps and material: package outputs or asset instances whose maps are all called "basecolor" get theirs renamed "<material>_basecolor" (else "basecolor_2" …), different materials of one name "<name>_2", and the input\'s material table and prim "material" follow. Two different images under one name inside one input are warned about, as texture nodes and materials then cannot tell them apart.',
|
|
18
19
|
aliases: ['combine', 'join'],
|
|
19
20
|
inputs: [{ name: 'inputs', desc: 'any number of geometries', multi: true }],
|
|
20
21
|
params: {},
|
|
@@ -26,12 +27,19 @@ defineNode({
|
|
|
26
27
|
},
|
|
27
28
|
output: 'both',
|
|
28
29
|
},
|
|
29
|
-
cook: ({ inputs }) => {
|
|
30
|
+
cook: ({ inputs, warn }) => {
|
|
30
31
|
const geos = inputs.filter((g) => !!g);
|
|
31
32
|
const out = Geometry.merge(geos);
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const seen = new Set(), twice = new Set();
|
|
34
|
+
for (const v of out.volumes)
|
|
35
|
+
if (v.kind === 'image') {
|
|
36
|
+
if (seen.has(v.name))
|
|
37
|
+
twice.add(v.name);
|
|
38
|
+
else
|
|
39
|
+
seen.add(v.name);
|
|
40
|
+
}
|
|
41
|
+
if (twice.size)
|
|
42
|
+
warn(`merge: different images share the name ${[...twice].map((n) => `"${n}"`).join(', ')}; give them their own names (an image takes its node's name unless its name param is set)`);
|
|
35
43
|
return out;
|
|
36
44
|
},
|
|
37
45
|
});
|
|
@@ -114,7 +122,7 @@ defineNode({
|
|
|
114
122
|
aliases: ['for_each', 'loop', 'foreach_piece', 'for_loop'],
|
|
115
123
|
description: 'The body is a nested graph. Inside it, an {"type":"input","params":{"index":0}} node yields the current piece ' +
|
|
116
124
|
'(or the previous iteration\'s result in feedback mode); index 1 yields the whole input; index 2 the foreach\'s second input. ' +
|
|
117
|
-
'Vars
|
|
125
|
+
'Vars the body\'s "=expr" params and code read by their bare name: iteration, numiterations, value (piece attribute value / element number), ' +
|
|
118
126
|
'attr (object of the element\'s attributes, e.g. attr.height), plus all parent vars. ' +
|
|
119
127
|
'feedback:true is count-based and runs all iterations in one cook at the current time; for feedback over frames use solver.',
|
|
120
128
|
inputs: [
|
|
@@ -129,8 +137,9 @@ defineNode({
|
|
|
129
137
|
body: { type: 'graph', desc: 'subgraph {nodes, output} run per iteration' },
|
|
130
138
|
max_iterations: { type: 'int', default: 10000, min: 1, max: 1000000, desc: 'safety limit' },
|
|
131
139
|
},
|
|
132
|
-
// the body's "=expr" params read the parent vars, so they are part of the cache key
|
|
140
|
+
// the body's "=expr" params and code read the parent vars, so they are part of the cache key
|
|
133
141
|
usesVars: true,
|
|
142
|
+
// the body's node types resolve in the scope
|
|
134
143
|
example: {
|
|
135
144
|
type: 'foreach',
|
|
136
145
|
in: ['pieces'],
|
|
@@ -264,7 +273,7 @@ defineNode({
|
|
|
264
273
|
description: 'Cooking at frame N runs the body for every frame from start_frame to N (once per substep). Inside the body, {"type":"input","params":{"index":0}} ' +
|
|
265
274
|
'is the previous frame\'s result (the initial geometry on start_frame), index 1 the initial geometry, 2 and 3 the extra inputs cooked at that frame. ' +
|
|
266
275
|
'Before start_frame the initial geometry passes through. The body sees the vars iteration (frames since start_frame, from 0), substep, ' +
|
|
267
|
-
'frame, time and timeInc (the step\'s time; frames are fractional between substeps), plus parent vars; wrangles also get @Frame @Time @TimeInc. ' +
|
|
276
|
+
'frame, time and timeInc (the step\'s time; frames are fractional between substeps), plus parent vars, by their bare name; wrangles also get @Frame @Time @TimeInc. ' +
|
|
268
277
|
'Caching: the state after frame f has the signature S(f) = hash(S(f-1), f, extra-input signatures at f), starting from ' +
|
|
269
278
|
'S(start_frame-1) = hash(params, vars, initial input at start_frame). Every frame\'s state is cached under S(f), so cooking frame 11 after frame 10 ' +
|
|
270
279
|
'runs the body once, and going back to an earlier frame is a cache hit. ' +
|
|
@@ -284,8 +293,9 @@ defineNode({
|
|
|
284
293
|
max_frames: { type: 'int', default: 1000, min: 1, max: 1000000, desc: 'safety limit: most frames simulated from start_frame' },
|
|
285
294
|
},
|
|
286
295
|
usesTime: true,
|
|
287
|
-
// the body's "=expr" params read the parent vars
|
|
296
|
+
// the body's "=expr" params and code read the parent vars
|
|
288
297
|
usesVars: true,
|
|
298
|
+
// the body's node types resolve in the scope
|
|
289
299
|
example: {
|
|
290
300
|
type: 'solver',
|
|
291
301
|
in: ['seed'],
|
|
@@ -318,7 +328,7 @@ defineNode({
|
|
|
318
328
|
// chained state signatures (see description)
|
|
319
329
|
const chain = [];
|
|
320
330
|
const extras = [];
|
|
321
|
-
let s = String(hashString('solver|' + stableStringify(p) + '|' + stableStringify(ctx.vars) + '|' + fps + '|' + init.sig));
|
|
331
|
+
let s = String(hashString('solver|' + stableStringify(p) + '|' + stableStringify(ctx.vars) + '|' + fps + '|' + init.sig + scopeSig(ctx.scope)));
|
|
322
332
|
for (let f = start; f <= last; f++) {
|
|
323
333
|
const ex = [await ctx.inputAt(1, f), await ctx.inputAt(2, f)];
|
|
324
334
|
s = String(hashString(s + '|' + f + '|' + ex[0].sig + '|' + ex[1].sig));
|
|
@@ -347,7 +357,7 @@ defineNode({
|
|
|
347
357
|
const fr = r9(f - 1 + (sub + 1) / n), time = r9((fr - 1) / fps);
|
|
348
358
|
const r = await ctx.subcook(p.body, {
|
|
349
359
|
frame: fr, time, timeInc, fps,
|
|
350
|
-
// also as vars, so code
|
|
360
|
+
// also as vars, so code reads frame / time / timeInc by name like iteration
|
|
351
361
|
vars: { ...ctx.vars, iteration: j, substep: sub, frame: fr, time, timeInc },
|
|
352
362
|
inputs: [
|
|
353
363
|
{ geo: state, sig: stateSig },
|
|
@@ -376,27 +386,27 @@ defineNode({
|
|
|
376
386
|
type: 'graph_ref',
|
|
377
387
|
category: 'flow',
|
|
378
388
|
packed: 'keep',
|
|
379
|
-
summary: 'Use the output (or any node) of another graph in the
|
|
389
|
+
summary: 'Use the output (or any node) of another graph in the package — compose scenes from separate graphs.',
|
|
380
390
|
aliases: ['object_merge', 'reference', 'ref'],
|
|
381
391
|
inputs: [],
|
|
382
392
|
params: {
|
|
383
|
-
graph: { type: 'string', default: '', desc: '
|
|
393
|
+
graph: { type: 'string', default: '', desc: 'package graph name' },
|
|
384
394
|
node: { type: 'string', default: '', desc: 'node in that graph ("" = its output)' },
|
|
385
395
|
vars: { type: 'json', default: {}, desc: 'override that graph\'s vars' },
|
|
386
396
|
},
|
|
387
|
-
|
|
388
|
-
|
|
397
|
+
// the graph is the scope's, and its node types resolve there
|
|
398
|
+
signatureExtra: (p, scope) => {
|
|
399
|
+
const g = scope.graphs?.(p.graph);
|
|
389
400
|
return g ? String(hashString(stableStringify(g))) : 'missing';
|
|
390
401
|
},
|
|
391
402
|
example: { type: 'graph_ref', params: { graph: 'island', node: 'ground', vars: { seed: 7 } } },
|
|
392
403
|
async cook(ctx) {
|
|
393
|
-
const { p,
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const g = resolver(p.graph);
|
|
404
|
+
const { p, scope } = ctx;
|
|
405
|
+
if (!scope.graphs && !scope.id)
|
|
406
|
+
throw new NodeError('graph_ref needs a package (not available in this host)');
|
|
407
|
+
const g = scope.graphs?.(p.graph);
|
|
398
408
|
if (!g)
|
|
399
|
-
throw new NodeError(`no graph named "${p.graph}" in the
|
|
409
|
+
throw new NodeError(`no graph named "${p.graph}" in ${scope.id ? `"${scope.id}"` : 'the package'}`);
|
|
400
410
|
const r = await ctx.subcook(g, { target: p.node || undefined, vars: p.vars });
|
|
401
411
|
if (!r.ok || !r.geo)
|
|
402
412
|
throw new NodeError(`graph "${p.graph}" failed: ${r.errors.map((e) => `${e.node}: ${e.message}`).join('; ')}`);
|
|
@@ -462,22 +472,24 @@ defineNode({
|
|
|
462
472
|
aliases: ['import', 'load', 'read'],
|
|
463
473
|
inputs: [],
|
|
464
474
|
params: {
|
|
465
|
-
path: { type: 'path', default: '', desc: 'file or folder path
|
|
475
|
+
path: { type: 'path', default: '', desc: 'file or folder path or file URL; a relative path reads from the package folder (the nearest folder with a .topo file at or above the graph), else from the graph\'s folder (MCP: the package); folder mode needs directory support in the host', aliases: ['file', 'filename'] },
|
|
466
476
|
format: { type: 'enum', options: ['auto', ...IMPORT_FORMATS], default: 'auto', desc: 'file format (auto = by extension; folders always use each file’s extension; ".points.json" = pointsjson; json also reads points streams and Houdini .geo; bgeo = uncompressed binary Houdini geometry, not .bgeo.sc; png = an image volume)' },
|
|
467
477
|
up_axis: { type: 'enum', options: ['y', 'z'], default: 'y', desc: 'source up axis; z converts Z-up files (Blender/Unreal exports) to Y-up' },
|
|
468
478
|
scale: { type: 'float', default: 1, desc: 'uniform scale (e.g. 0.01 for centimetres → metres)' },
|
|
469
479
|
weld: { type: 'bool', default: false, desc: 'fuse coincident points (glTF/STL meshes are split at seams; weld before booleans; expands packed instances)' },
|
|
470
480
|
instancing: { type: 'enum', options: ['packed', 'expand'], default: 'packed', desc: 'glTF shared meshes and EXT_mesh_gpu_instancing: keep instances as packed prims, or expand them into geometry' },
|
|
481
|
+
missing: { type: 'enum', options: ['error', 'empty'], default: 'error', desc: 'a file that is not there: error stops the cook; empty gives no geometry and a warning, for an input a person may not have made yet, such as inputs/markers.json before the first guide is drawn (the cook runs again when it appears)', aliases: ['if_missing', 'optional'] },
|
|
471
482
|
},
|
|
472
|
-
|
|
473
|
-
|
|
483
|
+
// relative paths read the scope's folder
|
|
484
|
+
signatureExtra: (p, scope) => {
|
|
485
|
+
const host = scope.files, files = directoryFiles(p.path, host);
|
|
474
486
|
return files === null ? host.fileStamp(p.path) : JSON.stringify([host.fileStamp(p.path), files.map((f) => [f, host.fileStamp(childPath(p.path, f))])]);
|
|
475
487
|
},
|
|
476
488
|
example: { type: 'file', params: { path: 'props/chair.obj', up_axis: 'z', weld: true } },
|
|
477
|
-
async cook({ p,
|
|
489
|
+
async cook({ p, scope, warn }) {
|
|
478
490
|
if (!p.path)
|
|
479
491
|
throw new NodeError('path is empty');
|
|
480
|
-
const host =
|
|
492
|
+
const host = scope.files, files = directoryFiles(p.path, host);
|
|
481
493
|
const read = async (file, format) => {
|
|
482
494
|
if (format === 'png') {
|
|
483
495
|
// an image, not a mesh: the image_file loader (its defaults), and no axis, scale or weld
|
|
@@ -533,8 +545,20 @@ defineNode({
|
|
|
533
545
|
}
|
|
534
546
|
return g;
|
|
535
547
|
};
|
|
536
|
-
if (files === null)
|
|
537
|
-
|
|
548
|
+
if (files === null) {
|
|
549
|
+
const optional = p.missing === 'empty', absent = () => { warn(`no file "${p.path}" yet: an empty result (missing: "empty")`); return new Geometry(); };
|
|
550
|
+
if (optional && host.fileStamp(p.path) === 'missing')
|
|
551
|
+
return absent();
|
|
552
|
+
try {
|
|
553
|
+
return await read(p.path, p.format === 'auto' ? importFormatFromPath(p.path) : p.format);
|
|
554
|
+
}
|
|
555
|
+
catch (e) {
|
|
556
|
+
// Importers also read dependent buffers/textures. Their ENOENT is an error, not an absent primary file.
|
|
557
|
+
if (optional && host.fileStamp(p.path) === 'missing')
|
|
558
|
+
return absent();
|
|
559
|
+
throw e;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
538
562
|
const parts = [];
|
|
539
563
|
for (const file of files) {
|
|
540
564
|
const fmt = importFormatFromPath(file);
|
|
@@ -552,10 +576,6 @@ defineNode({
|
|
|
552
576
|
}
|
|
553
577
|
parts.push(folderNames(await read(childPath(p.path, file), fmt), file));
|
|
554
578
|
}
|
|
555
|
-
|
|
556
|
-
const materials = mergeMaterialTables(parts);
|
|
557
|
-
if (Object.keys(materials).length)
|
|
558
|
-
writeMaterials(g, materials);
|
|
559
|
-
return g;
|
|
579
|
+
return Geometry.merge(parts);
|
|
560
580
|
},
|
|
561
581
|
});
|
package/dist/nodes/generate.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
import { GeoBuilder, Geometry } from '../core/geometry.js';
|
|
3
3
|
import { defineNode } from '../graph/registry.js';
|
|
4
4
|
import { NodeError } from '../graph/types.js';
|
|
5
|
-
import { runUserCode } from '../core/usercode.js';
|
|
5
|
+
import { codeVarDecl, codeVarNames, codeVarValues, runUserCode } from '../core/usercode.js';
|
|
6
|
+
import { scriptVarsGuard } from '../core/snippet-lib.js';
|
|
6
7
|
import { orientOutward, pointNormals, primNewell } from '../core/topology.js';
|
|
7
8
|
import { rng } from '../core/random.js';
|
|
9
|
+
import { uvSphere } from '../core/shapes.js';
|
|
8
10
|
import { fractal, makeNoise } from '../core/noise.js';
|
|
9
11
|
import { FRAMES, P } from './util.js';
|
|
10
12
|
/** Most points of a point_grid (its counts multiply). */
|
|
@@ -63,37 +65,6 @@ export function makeGrid(size, div, plane, center) {
|
|
|
63
65
|
b.addPrim([id(i, j), id(i + 1, j), id(i + 1, j + 1), id(i, j + 1)]);
|
|
64
66
|
return b.build();
|
|
65
67
|
}
|
|
66
|
-
function uvSphere(r, rows, cols) {
|
|
67
|
-
rows = Math.max(2, rows);
|
|
68
|
-
cols = Math.max(3, cols);
|
|
69
|
-
const b = new GeoBuilder();
|
|
70
|
-
const uv = b.attrib('vertex', 'uv', 3);
|
|
71
|
-
const top = b.addPoint(0, r, 0);
|
|
72
|
-
const ring = [];
|
|
73
|
-
for (let i = 1; i < rows; i++) {
|
|
74
|
-
const th = (Math.PI * i) / rows, row = [];
|
|
75
|
-
for (let c = 0; c < cols; c++) {
|
|
76
|
-
const ph = (2 * Math.PI * c) / cols;
|
|
77
|
-
row.push(b.addPoint(r * Math.sin(th) * Math.cos(ph), r * Math.cos(th), -r * Math.sin(th) * Math.sin(ph)));
|
|
78
|
-
}
|
|
79
|
-
ring.push(row);
|
|
80
|
-
}
|
|
81
|
-
const bot = b.addPoint(0, -r, 0);
|
|
82
|
-
const addUV = (us) => { const v0 = b.numVertices - us.length; us.forEach((t, k) => uv.set(v0 + k, [t[0], t[1], 0])); };
|
|
83
|
-
for (let c = 0; c < cols; c++) {
|
|
84
|
-
const c1 = (c + 1) % cols, u0 = c / cols, u1 = (c + 1) / cols;
|
|
85
|
-
b.addPrim([top, ring[0][c], ring[0][c1]]);
|
|
86
|
-
addUV([[(u0 + u1) / 2, 1], [u0, 1 - 1 / rows], [u1, 1 - 1 / rows]]);
|
|
87
|
-
for (let i = 0; i < rows - 2; i++) {
|
|
88
|
-
b.addPrim([ring[i][c], ring[i + 1][c], ring[i + 1][c1], ring[i][c1]]);
|
|
89
|
-
const va = 1 - (i + 1) / rows, vb = 1 - (i + 2) / rows;
|
|
90
|
-
addUV([[u0, va], [u0, vb], [u1, vb], [u1, va]]);
|
|
91
|
-
}
|
|
92
|
-
b.addPrim([ring[rows - 2][c], bot, ring[rows - 2][c1]]);
|
|
93
|
-
addUV([[u0, 1 / rows], [(u0 + u1) / 2, 0], [u1, 1 / rows]]);
|
|
94
|
-
}
|
|
95
|
-
return b.build();
|
|
96
|
-
}
|
|
97
68
|
const ICO_V = (() => {
|
|
98
69
|
const t = (1 + Math.sqrt(5)) / 2;
|
|
99
70
|
return [[-1, t, 0], [1, t, 0], [-1, -t, 0], [1, -t, 0], [0, -1, t], [0, 1, t], [0, -1, -t], [0, 1, -t], [t, 0, -1], [t, 0, 1], [-t, 0, -1], [-t, 0, 1]];
|
|
@@ -496,20 +467,23 @@ function runExpr(ctx, fn, what = '') {
|
|
|
496
467
|
/**
|
|
497
468
|
* Compile the expression of a parametric node into a function of `args`. The body is parsed on its own first (a
|
|
498
469
|
* complete function body cannot close the wrapper it is pasted into, so nothing runs while compiling); compiling
|
|
499
|
-
* runs under the script timeout all the same (a host without checkSyntax relies on that).
|
|
470
|
+
* runs under the script timeout all the same (a host without checkSyntax relies on that). The graph vars the code
|
|
471
|
+
* names are constants of a function around it, so `args` and the code's own names come first.
|
|
500
472
|
*/
|
|
501
473
|
function compileFn(ctx, args, code) {
|
|
502
474
|
const body = /\breturn\b/.test(code) ? code : `return (${code});`;
|
|
503
475
|
const syntax = ctx.engine.host.checkSyntax?.(`"use strict";${body}`);
|
|
504
476
|
if (syntax)
|
|
505
477
|
throw new NodeError(`${ctx.type}: expression syntax error: ${syntax.message}${code.includes('\n') ? ` (line ${syntax.line})` : ''}`);
|
|
506
|
-
|
|
478
|
+
const names = codeVarNames(code, ctx.vars), values = codeVarValues(ctx.vars, names);
|
|
479
|
+
const host = ctx.engine.host;
|
|
480
|
+
return runExpr(ctx, () => host.compile(`(function(__vars, __varsGuard){"use strict"; ${codeVarDecl(names)}\nreturn function(${args.join(',')}){"use strict";\n${body}\n}; })`)(values, scriptVarsGuard(host)), 'expression syntax error: ');
|
|
507
481
|
}
|
|
508
482
|
defineNode({
|
|
509
483
|
type: 'parametric_curve',
|
|
510
484
|
category: 'curve',
|
|
511
485
|
summary: 'Curve from a JS expression of t returning [x,y,z] (e.g. helices, knots, Lissajous).',
|
|
512
|
-
description: 'The expression runs sandboxed like a wrangle; all points together must be computed within the script timeout (TOPOTOPO_SCRIPT_TIMEOUT_MS, default 30 s).',
|
|
486
|
+
description: 'The expression runs sandboxed like a wrangle and reads graph vars by their bare name ([cos(t*TAU) * radius, t, sin(t*TAU) * radius]); all points together must be computed within the script timeout (TOPOTOPO_SCRIPT_TIMEOUT_MS, default 30 s).',
|
|
513
487
|
inputs: [],
|
|
514
488
|
params: {
|
|
515
489
|
expr: { type: 'code', default: '[cos(t*TAU), t, sin(t*TAU)]', desc: 'JS expression (or body with return) of t (and i) returning [x,y,z]. Snippet helpers available.' },
|
|
@@ -517,7 +491,7 @@ defineNode({
|
|
|
517
491
|
count: { type: 'int', default: 100, min: 2, max: 1000000, desc: 'number of points', aliases: ['points', 'segments'] },
|
|
518
492
|
closed: { type: 'bool', default: false, desc: 'closed curve (polygon)' },
|
|
519
493
|
},
|
|
520
|
-
usesVars:
|
|
494
|
+
usesVars: (p) => String(p.expr ?? ''),
|
|
521
495
|
example: { type: 'parametric_curve', params: { expr: '[(2+cos(3*t))*cos(2*t), sin(3*t), (2+cos(3*t))*sin(2*t)]', range: [0, 6.2832], count: 400, closed: true } },
|
|
522
496
|
cook: (ctx) => {
|
|
523
497
|
const { p } = ctx;
|
|
@@ -538,7 +512,7 @@ defineNode({
|
|
|
538
512
|
type: 'parametric_surface',
|
|
539
513
|
category: 'generate',
|
|
540
514
|
summary: 'Surface from a JS expression of (u, v) returning [x,y,z]; optional wrapping for closed surfaces.',
|
|
541
|
-
description: 'The expression runs sandboxed like a wrangle; all points together must be computed within the script timeout (TOPOTOPO_SCRIPT_TIMEOUT_MS, default 30 s).',
|
|
515
|
+
description: 'The expression runs sandboxed like a wrangle and reads graph vars by their bare name; all points together must be computed within the script timeout (TOPOTOPO_SCRIPT_TIMEOUT_MS, default 30 s).',
|
|
542
516
|
inputs: [],
|
|
543
517
|
params: {
|
|
544
518
|
expr: { type: 'code', default: '[(1+0.5*cos(v*TAU))*cos(u*TAU), 0.5*sin(v*TAU), (1+0.5*cos(v*TAU))*sin(u*TAU)]', desc: 'JS expression of u, v returning [x,y,z]' },
|
|
@@ -549,7 +523,7 @@ defineNode({
|
|
|
549
523
|
wrap_v: { type: 'bool', default: false, desc: 'v is periodic' },
|
|
550
524
|
flip: { type: 'bool', default: false, desc: 'reverse face winding' },
|
|
551
525
|
},
|
|
552
|
-
usesVars:
|
|
526
|
+
usesVars: (p) => String(p.expr ?? ''),
|
|
553
527
|
outputs: 'vertex uv',
|
|
554
528
|
example: { type: 'parametric_surface', params: { expr: '[(u - 0.5) * 4, 0.25 * sin(u * TAU * 2), (v - 0.5) * 2]', divisions: [64, 16] } },
|
|
555
529
|
cook: (ctx) => {
|