topotopo 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +40 -10
- package/README.md +475 -111
- package/dist/cli.js +328 -133
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/analysis.d.ts +5 -1
- package/dist/core/analysis.js +8 -3
- package/dist/core/bake.d.ts +16 -8
- package/dist/core/bake.js +165 -29
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +238 -97
- package/dist/core/decimate.d.ts +65 -0
- package/dist/core/decimate.js +409 -3
- package/dist/core/erosion.d.ts +37 -0
- package/dist/core/erosion.js +41 -1
- package/dist/core/geometry.d.ts +5 -1
- package/dist/core/geometry.js +204 -4
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/imageops.d.ts +6 -0
- package/dist/core/imageops.js +51 -0
- package/dist/core/intrinsics.d.ts +7 -0
- package/dist/core/intrinsics.js +94 -0
- package/dist/core/manifold.d.ts +12 -1
- package/dist/core/manifold.js +78 -6
- package/dist/core/materials.d.ts +11 -0
- package/dist/core/materials.js +56 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/packed.js +11 -0
- package/dist/core/particles.d.ts +1 -1
- package/dist/core/particles.js +1 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/rbd.js +13 -1
- package/dist/core/repair.d.ts +2 -0
- package/dist/core/repair.js +2 -0
- package/dist/core/report.d.ts +70 -0
- package/dist/core/report.js +275 -0
- package/dist/core/scatter.d.ts +1 -1
- package/dist/core/scatter.js +1 -1
- package/dist/core/scene.d.ts +20 -0
- package/dist/core/scene.js +72 -0
- package/dist/core/sha256.d.ts +4 -0
- package/dist/core/sha256.js +69 -0
- package/dist/core/shapes.d.ts +3 -0
- package/dist/core/shapes.js +34 -0
- package/dist/core/snippet-lib.d.ts +15 -2
- package/dist/core/snippet-lib.js +40 -14
- package/dist/core/solidify.d.ts +38 -0
- package/dist/core/solidify.js +356 -0
- package/dist/core/tangents.d.ts +54 -0
- package/dist/core/tangents.js +218 -0
- package/dist/core/texcoord.d.ts +4 -0
- package/dist/core/texcoord.js +14 -0
- package/dist/core/texnoise.d.ts +6 -1
- package/dist/core/texnoise.js +6 -2
- package/dist/core/texsdf.d.ts +131 -0
- package/dist/core/texsdf.js +637 -0
- package/dist/core/texture.d.ts +163 -9
- package/dist/core/texture.js +844 -20
- package/dist/core/topology.d.ts +32 -0
- package/dist/core/topology.js +238 -7
- package/dist/core/traceimage.d.ts +7 -0
- package/dist/core/traceimage.js +221 -0
- package/dist/core/tritri.d.ts +5 -0
- package/dist/core/tritri.js +120 -0
- package/dist/core/unwrap.d.ts +72 -0
- package/dist/core/unwrap.js +800 -0
- package/dist/core/usercode.d.ts +27 -0
- package/dist/core/usercode.js +87 -0
- package/dist/core/uv.d.ts +15 -16
- package/dist/core/uv.js +36 -189
- package/dist/core/uvislands.d.ts +62 -0
- package/dist/core/uvislands.js +574 -0
- package/dist/core/uvoverlap.d.ts +58 -0
- package/dist/core/uvoverlap.js +220 -0
- package/dist/core/uvpack.d.ts +64 -0
- package/dist/core/uvpack.js +628 -0
- package/dist/core/uvreport.d.ts +127 -0
- package/dist/core/uvreport.js +372 -0
- package/dist/core/wrangle.d.ts +6 -1
- package/dist/core/wrangle.js +27 -16
- package/dist/core/xatlas.d.ts +16 -1
- package/dist/core/xatlas.js +95 -61
- package/dist/engines.d.ts +63 -0
- package/dist/engines.js +180 -0
- package/dist/explain.d.ts +4 -3
- package/dist/explain.js +129 -12
- package/dist/graph/engine.d.ts +92 -29
- package/dist/graph/engine.js +298 -148
- package/dist/graph/expr.d.ts +6 -3
- package/dist/graph/expr.js +18 -8
- package/dist/graph/outputs.d.ts +23 -0
- package/dist/graph/outputs.js +41 -0
- package/dist/graph/packages.d.ts +72 -0
- package/dist/graph/packages.js +261 -0
- package/dist/graph/parallel.d.ts +3 -1
- package/dist/graph/parallel.js +4 -1
- package/dist/graph/params.d.ts +6 -0
- package/dist/graph/params.js +34 -7
- package/dist/graph/scope.d.ts +55 -0
- package/dist/graph/scope.js +14 -0
- package/dist/graph/types.d.ts +75 -12
- package/dist/graph/types.js +4 -2
- package/dist/graph/vars.d.ts +16 -0
- package/dist/graph/vars.js +80 -0
- package/dist/host/artifacts.d.ts +10 -1
- package/dist/host/artifacts.js +37 -6
- package/dist/host/cook.d.ts +241 -0
- package/dist/host/cook.js +844 -0
- package/dist/host/export-targets.d.ts +42 -5
- package/dist/host/export-targets.js +72 -13
- package/dist/host/godot-commands.d.ts +4 -0
- package/dist/host/godot-commands.js +21 -0
- package/dist/host/godot.d.ts +183 -0
- package/dist/host/godot.js +916 -0
- package/dist/host/node.d.ts +12 -7
- package/dist/host/node.js +27 -9
- package/dist/host/pool.js +51 -2
- package/dist/host/sidecars.d.ts +8 -0
- package/dist/host/sidecars.js +50 -0
- package/dist/host/types.d.ts +19 -6
- package/dist/host/version.d.ts +1 -0
- package/dist/host/version.js +3 -0
- package/dist/host/worker.js +5 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -2
- package/dist/inspect.d.ts +84 -1
- package/dist/inspect.js +271 -24
- package/dist/io/common.d.ts +33 -5
- package/dist/io/export.js +2 -1
- package/dist/io/files.d.ts +23 -4
- package/dist/io/files.js +60 -8
- package/dist/io/gltf.js +355 -51
- package/dist/io/heightmap.d.ts +3 -0
- package/dist/io/heightmap.js +1 -0
- package/dist/io/import.js +10 -0
- package/dist/io/inspect-scene.d.ts +55 -0
- package/dist/io/inspect-scene.js +155 -0
- package/dist/io/kinds.d.ts +81 -0
- package/dist/io/kinds.js +163 -0
- package/dist/io/points.d.ts +2 -1
- package/dist/io/points.js +3 -1
- package/dist/io/sidecars.d.ts +24 -0
- package/dist/io/sidecars.js +57 -0
- package/dist/io/source.d.ts +65 -0
- package/dist/io/source.js +112 -0
- package/dist/io/targets.d.ts +47 -3
- package/dist/io/targets.js +149 -14
- package/dist/io/textures.js +21 -1
- package/dist/io/unreal.js +5 -1
- package/dist/mcp/docs.d.ts +10 -1
- package/dist/mcp/docs.js +816 -119
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +70 -24
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +207 -108
- package/dist/mcp/verify.d.ts +2 -2
- package/dist/mcp/verify.js +1 -1
- package/dist/mcp/workspace.d.ts +15 -0
- package/dist/mcp/workspace.js +349 -0
- package/dist/nodes/attributes.js +198 -1
- package/dist/nodes/bake.js +207 -83
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +54 -5
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +22 -10
- package/dist/nodes/curves.js +440 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +13 -39
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.d.ts +1 -0
- package/dist/nodes/imageops.js +203 -0
- package/dist/nodes/index.d.ts +4 -0
- package/dist/nodes/index.js +4 -0
- package/dist/nodes/material.js +91 -23
- package/dist/nodes/measure.js +45 -18
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/rbd.js +1 -1
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.d.ts +1 -0
- package/dist/nodes/scene.js +55 -0
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/solidify.d.ts +1 -0
- package/dist/nodes/solidify.js +52 -0
- package/dist/nodes/splines.d.ts +15 -1
- package/dist/nodes/splines.js +112 -105
- package/dist/nodes/texture.d.ts +21 -6
- package/dist/nodes/texture.js +1318 -185
- package/dist/nodes/topology.d.ts +7 -0
- package/dist/nodes/topology.js +133 -6
- package/dist/nodes/transform.js +11 -3
- package/dist/nodes/util.d.ts +1 -1
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +6 -2
- package/dist/open.d.ts +19 -0
- package/dist/open.js +12 -0
- package/dist/package.d.ts +288 -0
- package/dist/package.js +772 -0
- package/dist/packages/check.d.ts +32 -0
- package/dist/packages/check.js +169 -0
- package/dist/packages/commands.d.ts +57 -0
- package/dist/packages/commands.js +537 -0
- package/dist/packages/registry.d.ts +796 -0
- package/dist/packages/registry.js +2998 -0
- package/dist/packages/update.d.ts +124 -0
- package/dist/packages/update.js +476 -0
- package/dist/render/options.d.ts +2 -0
- package/dist/render/options.js +44 -5
- package/dist/render/pbr.d.ts +28 -0
- package/dist/render/pbr.js +378 -0
- package/dist/render/preview.d.ts +69 -0
- package/dist/render/preview.js +26 -0
- package/dist/render/raster.d.ts +78 -7
- package/dist/render/raster.js +600 -145
- package/dist/render/texview.d.ts +7 -1
- package/dist/render/texview.js +34 -2
- package/dist/scan.d.ts +61 -0
- package/dist/scan.js +228 -0
- package/dist/session.d.ts +311 -0
- package/dist/session.js +849 -0
- package/dist/viewer/app/api.js +48 -6
- package/dist/viewer/app/camera.js +1 -1
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +100 -0
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +6 -2
- package/dist/viewer/app/guides.js +123 -1
- package/dist/viewer/app/keymap.js +7 -4
- package/dist/viewer/app/layers.js +5 -5
- package/dist/viewer/app/main.js +186 -53
- package/dist/viewer/app/markers.js +61 -1
- package/dist/viewer/app/outliner.js +72 -27
- package/dist/viewer/app/output-info.js +45 -0
- package/dist/viewer/app/outputs.css +147 -8
- package/dist/viewer/app/outputs.js +168 -54
- package/dist/viewer/app/packages.js +614 -0
- package/dist/viewer/app/props.js +177 -53
- package/dist/viewer/app/scene.js +35 -6
- package/dist/viewer/app/select.js +5 -4
- package/dist/viewer/app/selection.js +1 -1
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +66 -8
- package/dist/viewer/app/units.js +1 -1
- package/dist/viewer/app/vars.js +48 -1
- package/dist/viewer/app/welcome.js +72 -0
- package/dist/viewer/graph-file.d.ts +62 -0
- package/dist/viewer/graph-file.js +175 -0
- package/dist/viewer/index.html +24 -11
- package/dist/viewer/json-edit.d.ts +13 -0
- package/dist/viewer/json-edit.js +274 -0
- package/dist/viewer/outputs.d.ts +49 -5
- package/dist/viewer/outputs.js +264 -56
- package/dist/viewer/packages.d.ts +121 -0
- package/dist/viewer/packages.js +584 -0
- package/dist/viewer/server.d.ts +24 -7
- package/dist/viewer/server.js +289 -31
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/web/bake.d.ts +34 -0
- package/dist/web/bake.js +153 -0
- package/dist/web/folder-page.d.ts +101 -0
- package/dist/web/folder-page.js +146 -0
- package/dist/web/folders.d.ts +280 -0
- package/dist/web/folders.js +970 -0
- package/dist/web/library.d.ts +91 -0
- package/dist/web/library.js +228 -0
- package/dist/web/markdown.d.ts +45 -0
- package/dist/web/markdown.js +677 -0
- package/dist/web/pages.d.ts +258 -0
- package/dist/web/pages.js +301 -0
- package/dist/web/server.d.ts +24 -0
- package/dist/web/server.js +1068 -0
- package/dist/workspace.d.ts +88 -105
- package/dist/workspace.js +359 -375
- package/integrations/godot/addons/topotopo/LICENSE +202 -0
- package/integrations/godot/addons/topotopo/README.md +57 -0
- package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
- package/integrations/godot/addons/topotopo/dock.gd +266 -0
- package/integrations/godot/addons/topotopo/dock.tscn +72 -0
- package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
- package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
- package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
- package/integrations/godot/addons/topotopo/inspector.gd +38 -0
- package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
- package/integrations/godot/addons/topotopo/package.gd +23 -0
- package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
- package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
- package/integrations/godot/addons/topotopo/plugin.gd +970 -0
- package/integrations/godot/addons/topotopo/record.gd +435 -0
- package/integrations/godot/addons/topotopo/runner.gd +458 -0
- package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
- package/integrations/godot/addons/topotopo/watcher.gd +199 -0
- package/kernels/pkg/README.md +23 -29
- package/kernels/pkg-simd/README.md +23 -29
- package/library/architecture/versions/1.0/architecture.topo +12 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
- package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
- package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
- package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
- package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
- package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
- package/library/architecture/versions/1.0/version.json +1119 -0
- package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
- package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
- package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
- package/library/nature/versions/1.0/graphs/lineup.json +24 -0
- package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
- package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
- package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
- package/library/nature/versions/1.0/nature.topo +12 -0
- package/library/nature/versions/1.0/version.json +534 -0
- package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
- package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
- package/library/props/versions/1.0/graphs/lineup.json +18 -0
- package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
- package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
- package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
- package/library/props/versions/1.0/props.topo +12 -0
- package/library/props/versions/1.0/version.json +336 -0
- package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
- package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
- package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
- package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
- package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
- package/library/street/versions/1.0/graphs/lineup.json +22 -0
- package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
- package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
- package/library/street/versions/1.0/street.topo +12 -0
- package/library/street/versions/1.0/version.json +421 -0
- package/package.json +23 -8
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/shelf/index.json +0 -190
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// beam: straight members between two points (posts, rafters, joists, struts, braces), the architecture workhorse.
|
|
2
|
+
// A profile (a rectangle, or any closed curve on input 1) is placed across each beam in a frame from the beam's
|
|
3
|
+
// direction and an up vector, and swept straight from start to end: side faces, optional caps, uv in metres.
|
|
4
|
+
import { GeoBuilder } from '../core/geometry.js';
|
|
5
|
+
import { detectPlane, toPolygons } from '../core/manifold.js';
|
|
6
|
+
import { defineNode } from '../graph/registry.js';
|
|
7
|
+
import { NodeError } from '../graph/types.js';
|
|
8
|
+
const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
9
|
+
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
10
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
11
|
+
const len = (a) => Math.hypot(a[0], a[1], a[2]);
|
|
12
|
+
const unit = (a) => { const l = len(a) || 1; return [a[0] / l, a[1] / l, a[2] / l]; };
|
|
13
|
+
/** Spans from the input: every segment of its curves / polygon edges, or consecutive point pairs (0-1, 2-3 …). */
|
|
14
|
+
function spansOf(g, from) {
|
|
15
|
+
const P = g.P, pt = (i) => [P[i * 3], P[i * 3 + 1], P[i * 3 + 2]];
|
|
16
|
+
const out = [];
|
|
17
|
+
const hasLines = (() => { for (let p = 0; p < g.numPrims; p++)
|
|
18
|
+
if (g.primSize(p) >= 2 && !(g.primKind && g.primKind[p] === 1))
|
|
19
|
+
return true; return false; })();
|
|
20
|
+
if (from === 'segments' || (from === 'auto' && hasLines)) {
|
|
21
|
+
for (let p = 0; p < g.numPrims; p++) {
|
|
22
|
+
if (g.primKind && g.primKind[p] === 1)
|
|
23
|
+
continue;
|
|
24
|
+
const s = g.primStart[p], e = g.primStart[p + 1], n = e - s;
|
|
25
|
+
if (n < 2)
|
|
26
|
+
continue;
|
|
27
|
+
const segs = g.primClosed[p] && n >= 3 ? n : n - 1;
|
|
28
|
+
for (let k = 0; k < segs; k++) {
|
|
29
|
+
const ia = g.vertexPoint[s + k], ib = g.vertexPoint[s + ((k + 1) % n)];
|
|
30
|
+
out.push({ a: pt(ia), b: pt(ib), pa: ia, pb: ib, prim: p });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
for (let i = 0; i + 1 < g.numPoints; i += 2)
|
|
36
|
+
out.push({ a: pt(i), b: pt(i + 1), pa: i, pb: i + 1, prim: -1 });
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/** The profile loops (2D, counter-clockwise) from input 1, or the rectangle. */
|
|
41
|
+
function profilesOf(profile, size) {
|
|
42
|
+
if (!profile) {
|
|
43
|
+
const w = size[0] / 2, h = size[1] / 2;
|
|
44
|
+
return [[[-w, -h], [w, -h], [w, h], [-w, h]]];
|
|
45
|
+
}
|
|
46
|
+
const { polys } = toPolygons(profile, detectPlane(profile));
|
|
47
|
+
const loops = polys.filter((l) => l.length >= 3);
|
|
48
|
+
for (const l of loops) {
|
|
49
|
+
let a = 0;
|
|
50
|
+
for (let i = 0; i < l.length; i++) {
|
|
51
|
+
const [x0, y0] = l[i], [x1, y1] = l[(i + 1) % l.length];
|
|
52
|
+
a += x0 * y1 - x1 * y0;
|
|
53
|
+
}
|
|
54
|
+
if (a < 0)
|
|
55
|
+
l.reverse();
|
|
56
|
+
}
|
|
57
|
+
return loops;
|
|
58
|
+
}
|
|
59
|
+
defineNode({
|
|
60
|
+
type: 'beam',
|
|
61
|
+
category: 'generate',
|
|
62
|
+
summary: 'Beams between two points, between point pairs or along every segment of curves: a rectangle (or any closed profile on input 1) swept straight, with an up vector, caps, uv in metres and a prim name. Posts, rafters, joists, struts, trusses.',
|
|
63
|
+
description: 'Without input 0 one beam runs from start to end. With input 0 every segment of its curves (polylines, and the ' +
|
|
64
|
+
'edges of polygons) becomes a beam (from "segments"), or, for points only, each consecutive pair (0-1, 2-3 …: from ' +
|
|
65
|
+
'"pairs"); "auto" picks segments when there are curves. The profile lies across the beam: its first axis runs to ' +
|
|
66
|
+
'the side, its second along up projected square to the beam (a beam along up takes +Z, else +X, as up), then roll ' +
|
|
67
|
+
'turns it about the beam. The default profile is a size[0] × size[1] rectangle (width to the side, height up), ' +
|
|
68
|
+
'centred on the line; offset shifts it (offset [0, size[1] / 2] puts the line along the bottom face, e.g. joists ' +
|
|
69
|
+
'resting on a line). A closed curve on input 1 replaces it, drawn flat in any plane (shape2d\'s XZ: x to the side, ' +
|
|
70
|
+
'-z up; XY: x to the side, y up): an I-beam, a channel, a round bar; every closed loop is swept, each capped on its ' +
|
|
71
|
+
'own (switch caps off for hollow sections). extend lengthens the start and end (negative shortens, e.g. by half a ' +
|
|
72
|
+
'post\'s width). uv: along the beam (u) and around the profile (v) in metres × uv_scale; caps are mapped flat. Point ' +
|
|
73
|
+
'attributes of the input (Cd, …) are blended along each beam and prim attributes copied from the curve a beam ' +
|
|
74
|
+
'follows; name (with {index} for the beam number) names every beam\'s prims, "" keeps the curve\'s name.',
|
|
75
|
+
aliases: ['strut', 'post', 'rafter', 'joist', 'brace', 'member', 'lumber', 'girder', 'beams'],
|
|
76
|
+
inputs: [
|
|
77
|
+
{ name: 'path', desc: 'optional: curves (each segment a beam) or points (pairs); else start → end', optional: true },
|
|
78
|
+
{ name: 'profile', desc: 'optional: a closed cross-section curve, drawn flat (else the size rectangle)', optional: true },
|
|
79
|
+
],
|
|
80
|
+
params: {
|
|
81
|
+
start: { type: 'vec3', default: [0, 0, 0], desc: 'start point when input 0 is not connected', aliases: ['from', 'p0', 'a'] },
|
|
82
|
+
end: { type: 'vec3', default: [0, 3, 0], desc: 'end point when input 0 is not connected', aliases: ['to', 'p1', 'b'] },
|
|
83
|
+
from: { type: 'enum', options: ['auto', 'segments', 'pairs'], default: 'auto', desc: 'input 0: every curve segment, or consecutive point pairs (auto: segments when there are curves)', aliases: ['mode'] },
|
|
84
|
+
size: { type: 'vec2', default: [0.1, 0.2], min: 0, desc: 'rectangle profile [width to the side, height up] in metres', aliases: ['section', 'dimensions'] },
|
|
85
|
+
up: { type: 'vec3', default: [0, 1, 0], desc: 'which way the profile\'s second axis (the height) faces, projected square to the beam', aliases: ['up_vector'] },
|
|
86
|
+
roll: { type: 'float', default: 0, desc: 'turn the profile about the beam, degrees' },
|
|
87
|
+
offset: { type: 'vec2', default: [0, 0], desc: 'shift of the profile [to the side, up] in metres (the line is its origin)' },
|
|
88
|
+
extend: { type: 'vec2', default: [0, 0], desc: 'lengthen [start, end] along the beam in metres (negative shortens)', aliases: ['overhang', 'extension'] },
|
|
89
|
+
divisions: { type: 'int', default: 1, min: 1, max: 1000, desc: 'segments along the length (for later bending)', aliases: ['segments', 'rows'] },
|
|
90
|
+
caps: { type: 'bool', default: true, desc: 'close both ends', aliases: ['cap', 'end_caps'] },
|
|
91
|
+
uv_scale: { type: 'float', default: 1, min: 0, desc: 'uv units per metre (uv in metres at 1)' },
|
|
92
|
+
name: { type: 'string', default: 'beam', desc: 'prim name of every beam ({index} = the beam number; "" = keep the input curve\'s name)', aliases: ['prim_name'] },
|
|
93
|
+
},
|
|
94
|
+
outputs: 'polygons; prim groups sides, caps; prim string name, prim int beam (the beam number); vertex uv',
|
|
95
|
+
example: {
|
|
96
|
+
nodes: {
|
|
97
|
+
frame: { type: 'curve', params: { points: [[0, 0, 0], [0, 2.4, 0], [3, 2.4, 0], [3, 0, 0]] } },
|
|
98
|
+
posts: { type: 'beam', in: ['frame'], params: { size: [0.12, 0.12], up: [0, 0, 1], name: 'timber_{index}' } },
|
|
99
|
+
},
|
|
100
|
+
output: 'posts',
|
|
101
|
+
},
|
|
102
|
+
cook: (ctx) => {
|
|
103
|
+
const { p, type } = ctx;
|
|
104
|
+
const src = ctx.hasInput(0) ? ctx.input(0) : null;
|
|
105
|
+
const spans = src ? spansOf(src, p.from) : [{ a: p.start, b: p.end, pa: -1, pb: -1, prim: -1 }];
|
|
106
|
+
if (src && !spans.length)
|
|
107
|
+
throw new NodeError(`${type}: input 0 holds no segment (curves with 2+ points, or point pairs)`, 'connect a curve (each segment a beam) or points in pairs');
|
|
108
|
+
const loops = profilesOf(ctx.hasInput(1) ? ctx.input(1) : null, p.size);
|
|
109
|
+
if (!loops.length)
|
|
110
|
+
throw new NodeError(`${type}: input 1 holds no closed profile`, 'a closed curve drawn flat: shape2d, circle, curve {closed:true}');
|
|
111
|
+
const roll = (p.roll * Math.PI) / 180, cr = Math.cos(roll), sr = Math.sin(roll);
|
|
112
|
+
const prof = loops.map((l) => l.map(([x, y]) => { const u = x + p.offset[0], v = y + p.offset[1]; return [u * cr - v * sr, u * sr + v * cr]; }));
|
|
113
|
+
// perimeter distance along each loop (v of the side uv)
|
|
114
|
+
const around = prof.map((l) => { const d = [0]; for (let i = 1; i <= l.length; i++) {
|
|
115
|
+
const a = l[i - 1], b = l[i % l.length];
|
|
116
|
+
d.push(d[i - 1] + Math.hypot(b[0] - a[0], b[1] - a[1]));
|
|
117
|
+
} return d; });
|
|
118
|
+
const b = new GeoBuilder(src);
|
|
119
|
+
if (src)
|
|
120
|
+
for (const n of ['N', 'up', 'orient', 'tangent', 'tangentu', 'tangentv', 'uv'])
|
|
121
|
+
b.skip.point.add(n);
|
|
122
|
+
if (src)
|
|
123
|
+
b.skip.vertex.add('uv');
|
|
124
|
+
const uvA = b.attrib('vertex', 'uv', 3);
|
|
125
|
+
const beamA = b.attrib('prim', 'beam', 1, 'int');
|
|
126
|
+
const nameFmt = String(p.name ?? '');
|
|
127
|
+
const nameA = nameFmt ? b.attrib('prim', 'name', 1, 'string', '') : null;
|
|
128
|
+
const sides = b.group('prim', 'sides'), caps = b.group('prim', 'caps');
|
|
129
|
+
const K = Math.max(1, Math.round(p.divisions)), us = p.uv_scale;
|
|
130
|
+
let skipped = 0, index = 0;
|
|
131
|
+
for (const sp of spans) {
|
|
132
|
+
const d = sub(sp.b, sp.a), L0 = len(d);
|
|
133
|
+
if (!(L0 > 1e-12)) {
|
|
134
|
+
skipped++;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const T = unit(d);
|
|
138
|
+
let upv = p.up;
|
|
139
|
+
if (!(len(upv) > 0) || Math.abs(dot(unit(upv), T)) > 0.9999)
|
|
140
|
+
upv = Math.abs(T[2]) < 0.9999 ? [0, 0, 1] : [1, 0, 0];
|
|
141
|
+
const U = unit(sub(upv, [T[0] * dot(upv, T), T[1] * dot(upv, T), T[2] * dot(upv, T)]));
|
|
142
|
+
const S = cross(U, T);
|
|
143
|
+
const a = [sp.a[0] - T[0] * p.extend[0], sp.a[1] - T[1] * p.extend[0], sp.a[2] - T[2] * p.extend[0]];
|
|
144
|
+
const L = L0 + p.extend[0] + p.extend[1];
|
|
145
|
+
if (!(L > 1e-12)) {
|
|
146
|
+
skipped++;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const prims = [];
|
|
150
|
+
prof.forEach((loop, li) => {
|
|
151
|
+
const n = loop.length;
|
|
152
|
+
// rings of points along the beam, blended between the input points it spans
|
|
153
|
+
const rings = [];
|
|
154
|
+
for (let k = 0; k <= K; k++) {
|
|
155
|
+
const t = k / K, s = (t * L - p.extend[0]) / L0;
|
|
156
|
+
const c = [a[0] + T[0] * t * L, a[1] + T[1] * t * L, a[2] + T[2] * t * L];
|
|
157
|
+
const prov = src && sp.pa >= 0 ? { i: [sp.pa, sp.pb], w: [1 - Math.min(1, Math.max(0, s)), Math.min(1, Math.max(0, s))] } : null;
|
|
158
|
+
rings.push(loop.map(([x, y]) => b.addPoint(c[0] + S[0] * x + U[0] * y, c[1] + S[1] * x + U[1] * y, c[2] + S[2] * x + U[2] * y, prov)));
|
|
159
|
+
}
|
|
160
|
+
const dist = around[li];
|
|
161
|
+
for (let k = 0; k < K; k++) {
|
|
162
|
+
for (let i = 0; i < n; i++) {
|
|
163
|
+
const j = (i + 1) % n;
|
|
164
|
+
const pr = b.addPrim([rings[k][i], rings[k][j], rings[k + 1][j], rings[k + 1][i]], true, sp.prim);
|
|
165
|
+
const u0 = (k / K) * L * us, u1 = ((k + 1) / K) * L * us, v0 = dist[i] * us, v1 = dist[i + 1] * us;
|
|
166
|
+
const base = b.numVertices - 4;
|
|
167
|
+
uvA.set(base, [u0, v0, 0]);
|
|
168
|
+
uvA.set(base + 1, [u0, v1, 0]);
|
|
169
|
+
uvA.set(base + 2, [u1, v1, 0]);
|
|
170
|
+
uvA.set(base + 3, [u1, v0, 0]);
|
|
171
|
+
sides.add(pr);
|
|
172
|
+
prims.push(pr);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (p.caps) {
|
|
176
|
+
// the end cap faces along the beam (the profile's own winding), the start cap against it
|
|
177
|
+
const end = b.addPrim(rings[K], true, sp.prim);
|
|
178
|
+
for (let i = 0; i < n; i++)
|
|
179
|
+
uvA.set(b.numVertices - n + i, [loop[i][0] * us, loop[i][1] * us, 0]);
|
|
180
|
+
const startRing = rings[0].slice().reverse(), startLoop = loop.slice().reverse();
|
|
181
|
+
const start = b.addPrim(startRing, true, sp.prim);
|
|
182
|
+
for (let i = 0; i < n; i++)
|
|
183
|
+
uvA.set(b.numVertices - n + i, [-startLoop[i][0] * us, startLoop[i][1] * us, 0]);
|
|
184
|
+
caps.add(end);
|
|
185
|
+
caps.add(start);
|
|
186
|
+
prims.push(end, start);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
for (const pr of prims) {
|
|
190
|
+
beamA.set(pr, index);
|
|
191
|
+
if (nameA)
|
|
192
|
+
nameA.set(pr, nameFmt.replaceAll('{index}', String(index)));
|
|
193
|
+
}
|
|
194
|
+
index++;
|
|
195
|
+
}
|
|
196
|
+
if (skipped)
|
|
197
|
+
ctx.warn(`${type}: ${skipped} zero-length segment(s) skipped`);
|
|
198
|
+
ctx.stat('beams', index);
|
|
199
|
+
return b.build();
|
|
200
|
+
},
|
|
201
|
+
});
|
package/dist/nodes/bevel.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// Poly bevel: chamfer / round edges and points (Houdini PolyBevel). Kernels in core/bevel.ts.
|
|
2
2
|
import { defineNode } from '../graph/registry.js';
|
|
3
3
|
import { bevelEdges, bevelPoints } from '../core/bevel.js';
|
|
4
|
+
import { primArea, primPerimeter } from '../core/topology.js';
|
|
5
|
+
import { primWhere } from '../core/report.js';
|
|
6
|
+
import { fusePoints } from './transform.js';
|
|
4
7
|
import { edgeMask, mask } from './util.js';
|
|
5
8
|
defineNode({
|
|
6
9
|
type: 'poly_bevel',
|
|
@@ -11,8 +14,9 @@ defineNode({
|
|
|
11
14
|
'for a chamfer (triangle at a box corner), rings of quads for round bevels (a sphere octant at a box corner). A ' +
|
|
12
15
|
'bevelled edge ending at an unbevelled point slides its offset along the neighbouring edges and ends flush; two ' +
|
|
13
16
|
'bevelled edges meeting at a point with one other edge (a cylinder rim) are mitred. Boundary and non-manifold edges ' +
|
|
14
|
-
'are skipped with a warning (chamfering open-mesh boundary edges is out of scope). clamp
|
|
15
|
-
'
|
|
17
|
+
'are skipped with a warning (chamfering open-mesh boundary edges is out of scope). clamp shrinks the offsets only ' +
|
|
18
|
+
'around edges that would cross (huge offsets stay clean; one short edge does not flatten every bevel), and leaves an ' +
|
|
19
|
+
'edge sharp when a zero-length neighbour leaves no room. Point mode truncates the selected points: ' +
|
|
16
20
|
'every edge at the point is cut at "offset", the corner becomes a polygon, or a dome of "divisions" rings. Faces keep ' +
|
|
17
21
|
'their attributes (uv is interpolated inside each face), strips take prim attributes from the larger neighbouring face, ' +
|
|
18
22
|
'corner patches from the first face around the point; N is recomputed if present. Select edges with patterns: ' +
|
|
@@ -23,13 +27,13 @@ defineNode({
|
|
|
23
27
|
params: {
|
|
24
28
|
group: {
|
|
25
29
|
type: 'group', default: '',
|
|
26
|
-
desc: 'edges to bevel (edge pattern or group: "angle>80", "border:top", "p0-1", "rim"; "" = every edge shared by two polygons); with mode "points", a point pattern ("" = all points)',
|
|
30
|
+
desc: 'edges to bevel (edge pattern or group: "angle>80", "border:top", "p0-1", "rim"; "" = every edge shared by two polygons where the surface bends: flat edges inside a plane, such as the splits a boolean leaves in a cut face, are skipped); with mode "points", a point pattern ("" = all points)',
|
|
27
31
|
aliases: ['edges', 'edge_group', 'points'],
|
|
28
32
|
},
|
|
29
33
|
mode: { type: 'enum', options: ['edges', 'points'], default: 'edges', desc: 'bevel edges, or truncate points', aliases: ['bevel_type', 'class'] },
|
|
30
34
|
offset: { type: 'float', default: 0.1, min: 0, desc: 'distance from the edge across each adjacent face (points mode: along each edge)', aliases: ['distance', 'width', 'radius', 'size', 'amount'] },
|
|
31
35
|
offset_mode: { type: 'enum', options: ['distance', 'fraction'], default: 'distance', desc: 'distance = offset in scene units; fraction = offset x the shortest edge at the edge\'s points (stays proportional on small faces)', aliases: ['distance_mode', 'offsetmode'] },
|
|
32
|
-
clamp: { type: 'bool', default: true, desc: '
|
|
36
|
+
clamp: { type: 'bool', default: true, desc: 'shrink the offsets where bevels would cross their neighbours, or the edge facing them across a narrow face (the two rims of a thin band), only at the edges involved (Houdini Clamp Offset, applied locally); warns when it does', aliases: ['clamp_offset', 'clamp_overlap'] },
|
|
33
37
|
divisions: { type: 'int', default: 0, min: 0, max: 64, desc: '0 = flat chamfer (one strip of quads per edge); n = round profile with n+1 strips', aliases: ['segments', 'divs', 'subdivisions'] },
|
|
34
38
|
shape: { type: 'float', default: 0, min: -1, max: 1, desc: 'profile convexity for round bevels: 0 = circular arc, 1 = bulges out to a nearly square corner, -0.5 = straight, -1 = concave cove', aliases: ['profile_shape', 'convexity', 'profile'] },
|
|
35
39
|
},
|
|
@@ -44,6 +48,51 @@ defineNode({
|
|
|
44
48
|
: bevelEdges(g, pattern === '' ? null : edgeMask(g, pattern), opts);
|
|
45
49
|
for (const w of r.warnings)
|
|
46
50
|
warn(w);
|
|
47
|
-
return r.geo;
|
|
51
|
+
return p.mode === 'points' || r.geo === g ? r.geo : closeCollapsed(r.geo, p.offset_mode === 'distance' ? p.offset * 0.01 : 0, warn);
|
|
48
52
|
},
|
|
49
53
|
});
|
|
54
|
+
/**
|
|
55
|
+
* Faces the bevel shrank to a line (an offset at half the thickness of a plate: the bevels of its two edges meet on
|
|
56
|
+
* the side face; with clamp on they stop a hair short) are closed up: a face next to a bevel narrower than minWidth
|
|
57
|
+
* (a hundredth of the offset) or of no area has its points welded, so the strips meet directly and no sliver is
|
|
58
|
+
* exported. Says where.
|
|
59
|
+
*/
|
|
60
|
+
function closeCollapsed(g, minWidth, warn) {
|
|
61
|
+
const bev = g.primGroups.get('bevel');
|
|
62
|
+
if (!bev)
|
|
63
|
+
return g;
|
|
64
|
+
const onBevel = new Uint8Array(g.numPoints);
|
|
65
|
+
for (let p = 0; p < g.numPrims; p++)
|
|
66
|
+
if (bev[p])
|
|
67
|
+
for (const i of g.primPoints(p))
|
|
68
|
+
onBevel[i] = 1;
|
|
69
|
+
const P = g.P;
|
|
70
|
+
const collapsed = [];
|
|
71
|
+
let weld = 0;
|
|
72
|
+
for (let p = 0; p < g.numPrims; p++) {
|
|
73
|
+
if (bev[p] || !g.primClosed[p] || g.primSize(p) < 3)
|
|
74
|
+
continue;
|
|
75
|
+
const ids = g.primPoints(p);
|
|
76
|
+
if (!ids.some((i) => onBevel[i]))
|
|
77
|
+
continue;
|
|
78
|
+
let longest = 0;
|
|
79
|
+
for (let k = 0; k < ids.length; k++) {
|
|
80
|
+
const a = ids[k] * 3, c = ids[(k + 1) % ids.length] * 3;
|
|
81
|
+
longest = Math.max(longest, Math.hypot(P[a] - P[c], P[a + 1] - P[c + 1], P[a + 2] - P[c + 2]));
|
|
82
|
+
}
|
|
83
|
+
const width = longest > 0 ? (2 * primArea(g, p)) / longest : 0;
|
|
84
|
+
if (!(width <= Math.max(minWidth, 1e-9 * primPerimeter(g, p))))
|
|
85
|
+
continue;
|
|
86
|
+
collapsed.push(p);
|
|
87
|
+
weld = Math.max(weld, width);
|
|
88
|
+
}
|
|
89
|
+
if (!collapsed.length)
|
|
90
|
+
return g;
|
|
91
|
+
const b = g.bbox(), size = Math.hypot(b.max[0] - b.min[0], b.max[1] - b.min[1], b.max[2] - b.min[2]);
|
|
92
|
+
const cand = new Uint8Array(g.numPoints);
|
|
93
|
+
for (const p of collapsed)
|
|
94
|
+
for (const i of g.primPoints(p))
|
|
95
|
+
cand[i] = 1;
|
|
96
|
+
warn(`the offset reaches half the width of ${collapsed.length} face(s) (the thickness of a plate, a narrow facet), so the bevels on both sides meet and those faces closed up (first ${primWhere(g, collapsed[0])}); a smaller offset keeps a flat band between them`);
|
|
97
|
+
return fusePoints(g, Math.max(size * 1e-7, weld * 1.5), (i) => !!cand[i]);
|
|
98
|
+
}
|
package/dist/nodes/cloth.js
CHANGED
|
@@ -163,6 +163,8 @@ async function simulate(ctx, mode) {
|
|
|
163
163
|
sim.settleFloor();
|
|
164
164
|
for (let s = 0; s < p.steps; s++) {
|
|
165
165
|
budget.check();
|
|
166
|
+
// a stopped cook stops between steps
|
|
167
|
+
await ctx.checkpoint();
|
|
166
168
|
if (collider) {
|
|
167
169
|
const r = detect();
|
|
168
170
|
if (r instanceof Promise)
|
package/dist/nodes/code.js
CHANGED
|
@@ -17,7 +17,8 @@ import { EdgeSet } from '../core/edges.js';
|
|
|
17
17
|
import { convertSelection } from '../core/groupconvert.js';
|
|
18
18
|
import { appendElements } from '../core/wrangle.js';
|
|
19
19
|
import { composePackedXforms, expandPacked, packedInfo } from '../core/packed.js';
|
|
20
|
-
import { describeGuarded, runUserCode } from '../core/usercode.js';
|
|
20
|
+
import { codeVarDecl, codeVarNames, codeVarValues, describeGuarded, runUserCode } from '../core/usercode.js';
|
|
21
|
+
import { scriptVarsGuard } from '../core/snippet-lib.js';
|
|
21
22
|
import { mask, wrangleTime } from './util.js';
|
|
22
23
|
/** points below which a wrangle stays on the cooking thread (copying the attributes would cost more than it saves) */
|
|
23
24
|
const WRANGLE_MIN_POINTS = 65536;
|
|
@@ -33,6 +34,7 @@ defineNode({
|
|
|
33
34
|
'Vectors are arrays with .x/.y/.z accessors; use add/sub/mul/div/dot/cross/normalize/length/lerp/fit (no operator overloading). ' +
|
|
34
35
|
'Element numbers: @ptnum @primnum @vtxnum @numpt @numprim @elemnum. Groups: @group_name = 1. ' +
|
|
35
36
|
'Time: @Frame @Time @TimeInc (the wrangle re-cooks per frame only when the code uses them). ' +
|
|
37
|
+
'Graph vars by their bare name, read-only, as in "=expr" params: @P.y += height * 0.5 (iteration, value … inside a foreach). ' +
|
|
36
38
|
'Inputs 1-3 are readable with point(1, "P", i), nearpoint(1, pos), xyzdist(1, pos)… ' +
|
|
37
39
|
'Create/delete with addpoint, addprim, removepoint, removeprim (applied after the run). See help topic "wrangle" for the full function list.',
|
|
38
40
|
inputs: [
|
|
@@ -46,7 +48,7 @@ defineNode({
|
|
|
46
48
|
run_over: { type: 'enum', options: ['points', 'prims', 'vertices', 'detail'], default: 'points', desc: 'element class to iterate', aliases: ['class', 'runover'] },
|
|
47
49
|
group: { type: 'group', default: '', desc: 'only run on elements in this group (point, prim or vertex pattern, matching run_over)' },
|
|
48
50
|
},
|
|
49
|
-
usesVars:
|
|
51
|
+
usesVars: (p) => String(p.code ?? ''),
|
|
50
52
|
example: { type: 'wrangle', params: { run_over: 'points', code: '@P.y += sin(@P.x * 4) * 0.2;\n@Cd = hsv2rgb(fit(@P.y, -0.2, 0.2, 0.6, 0), 0.7, 1);' } },
|
|
51
53
|
cook: (ctx) => {
|
|
52
54
|
const { input, inputs, p, vars, engine, warn } = ctx;
|
|
@@ -111,7 +113,7 @@ function scriptLib(ctx, wake, run) {
|
|
|
111
113
|
if (bad)
|
|
112
114
|
throw new Error(`lib.run(${type}): input ${i} is not a Geometry (got ${bad})`);
|
|
113
115
|
}
|
|
114
|
-
const def = engine.resolveDef(type);
|
|
116
|
+
const def = engine.resolveDef(type, ctx.scope);
|
|
115
117
|
if (!def)
|
|
116
118
|
throw new Error(`lib.run: unknown node type "${type}"`);
|
|
117
119
|
// ... and their params as plain data of this realm: json and graph params (a foreach body) are kept as given and
|
|
@@ -130,7 +132,7 @@ function scriptLib(ctx, wake, run) {
|
|
|
130
132
|
throw new Error(`lib.run(${type}): ${rp.errors.join('; ')}`);
|
|
131
133
|
for (const w of rp.warnings)
|
|
132
134
|
ctx.warn(`lib.run(${type}): ${w}`);
|
|
133
|
-
// inherit from ctx through the prototype so its time getters stay lazy
|
|
135
|
+
// inherit from ctx through the prototype so its time getters stay lazy (and the node runs in the script's scope)
|
|
134
136
|
const sub = Object.assign(Object.create(ctx), {
|
|
135
137
|
node: `${ctx.node}/${type}`, type: def.type, p: rp.values, inputs,
|
|
136
138
|
input: (i) => inputs[i] ?? new Geometry(), hasInput: (i) => !!inputs[i], inputSigs: inputs.map(() => 'script'),
|
|
@@ -174,9 +176,10 @@ defineNode({
|
|
|
174
176
|
packed: 'keep',
|
|
175
177
|
summary: 'Arbitrary JS over the whole geometry with the engine library (builder, math, noise, BVH, manifold, lib.run any node). Return a Geometry.',
|
|
176
178
|
aliases: ['python', 'js', 'javascript', 'python_sop'],
|
|
177
|
-
description: 'The body of `async function(geo, inputs, lib
|
|
179
|
+
description: 'The body of `async function(geo, inputs, lib)`. geo is a writable clone of input 0; inputs[i] are the raw inputs. ' +
|
|
178
180
|
'lib: Geometry, GeoBuilder, math, topology, random, noise, KDTree, TriBVH, manifold, merge(geos), run(type, params, ...inputs), warn(msg), ' +
|
|
179
181
|
'frame, time, fps, timeInc (reading them makes the script re-cook per frame). ' +
|
|
182
|
+
'Graph vars by their bare name, read-only, as in "=expr" params (e.g. `lib.run(\'box\', { size: height })`). ' +
|
|
180
183
|
'Must return a Geometry (e.g. `return geo;`).',
|
|
181
184
|
inputs: [
|
|
182
185
|
{ name: 'geo', desc: 'main input (optional)', optional: true },
|
|
@@ -187,7 +190,9 @@ defineNode({
|
|
|
187
190
|
params: {
|
|
188
191
|
code: { type: 'code', default: 'return geo;', desc: 'async function body; may use await lib.run(...)' },
|
|
189
192
|
},
|
|
193
|
+
// every var: besides the ones its code names, the "=expr" params it hands to lib.run can read any of them
|
|
190
194
|
usesVars: true,
|
|
195
|
+
// lib.run resolves node types in the scope, and the nodes it runs read the scope's files
|
|
191
196
|
example: {
|
|
192
197
|
type: 'script',
|
|
193
198
|
params: { code: "const parts = [];\nfor (let i = 0; i < 5; i++) parts.push(await lib.run('box', { size: [1, i + 1, 1], center: [i * 1.5, (i + 1) / 2, 0] }));\nreturn lib.merge(parts);" },
|
|
@@ -195,14 +200,21 @@ defineNode({
|
|
|
195
200
|
async cook(ctx) {
|
|
196
201
|
const { inputs, p, engine } = ctx;
|
|
197
202
|
const ms = engine.scriptTimeoutMs;
|
|
203
|
+
const code = String(p.code ?? '');
|
|
204
|
+
// the graph vars the code names: constants of a function around it, so its own names come first
|
|
205
|
+
const names = codeVarNames(code, ctx.vars);
|
|
206
|
+
const values = codeVarValues(ctx.vars, names);
|
|
198
207
|
let fn;
|
|
199
208
|
try {
|
|
200
209
|
// The realm's AsyncFunction constructor parses the body on its own: code that would close the function it is
|
|
201
|
-
// pasted into (and run while compiling, outside any time limit) is a syntax error.
|
|
202
|
-
//
|
|
210
|
+
// pasted into (and run while compiling, outside any time limit) is a syntax error. Only a body that parses is
|
|
211
|
+
// compiled inside the function that binds the vars. Looked up, called and its error read under the time limit
|
|
212
|
+
// all the same (earlier code may have changed the realm).
|
|
203
213
|
fn = runUserCode(engine.host, () => {
|
|
204
214
|
const AsyncFunction = engine.host.compile('(async function () {}).constructor');
|
|
205
|
-
|
|
215
|
+
new AsyncFunction('geo', 'inputs', 'lib', `"use strict";\n${code}`);
|
|
216
|
+
const make = engine.host.compile(`(function (__vars, __varsGuard) { "use strict"; ${codeVarDecl(names)}\nreturn async function (geo, inputs, lib) { "use strict";\n${code}\n}; })`);
|
|
217
|
+
return make(values, scriptVarsGuard(engine.host));
|
|
206
218
|
}, ms);
|
|
207
219
|
}
|
|
208
220
|
catch (e) {
|
|
@@ -216,7 +228,7 @@ defineNode({
|
|
|
216
228
|
const t0 = Date.now();
|
|
217
229
|
try {
|
|
218
230
|
// the host limits the whole run, awaited continuations included (an `await` must not escape the timeout)
|
|
219
|
-
res = await engine.host.runGuardedAsync((wake) => fn(geo, inputs.map((g) => g ?? new Geometry()), scriptLib(ctx, wake, run)
|
|
231
|
+
res = await engine.host.runGuardedAsync((wake) => fn(geo, inputs.map((g) => g ?? new Geometry()), scriptLib(ctx, wake, run)), ms);
|
|
220
232
|
}
|
|
221
233
|
catch (e) {
|
|
222
234
|
// what the script threw is user code too (a message getter, toString): read it within the rest of the time limit
|
|
@@ -229,7 +241,7 @@ defineNode({
|
|
|
229
241
|
run.stopped = true;
|
|
230
242
|
}
|
|
231
243
|
// what the script returned is user code too: `instanceof` (and Object.getPrototypeOf) run a Proxy's
|
|
232
|
-
// getPrototypeOf trap here, outside the time limit, so only the engine's brand check looks at it
|
|
244
|
+
// getPrototypeOf trap here, outside the time limit, so only the engine's brand check looks at it
|
|
233
245
|
const bad = notGeometry(res);
|
|
234
246
|
if (bad)
|
|
235
247
|
throw new NodeError(`script must return a Geometry (got ${bad})`, 'return geo, a geometry from lib.run, or one built with lib.GeoBuilder / new lib.Geometry()');
|