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/nodes/bake.js
CHANGED
|
@@ -6,19 +6,20 @@ import { pointNormals, resolveVertexNormals, triangulate } from '../core/topolog
|
|
|
6
6
|
import { defineNode } from '../graph/registry.js';
|
|
7
7
|
import { NodeError } from '../graph/types.js';
|
|
8
8
|
import { andThen } from '../graph/parallel.js';
|
|
9
|
+
import { partsOf, primWhere } from '../core/report.js';
|
|
9
10
|
import { P, mask } from './util.js';
|
|
10
|
-
import { imageGeo, nameParam, resolutionParam, size2 } from './texture.js';
|
|
11
|
+
import { NAMED_BY_NODE, imageGeo, nameParam, outName, resolutionParam, size2 } from './texture.js';
|
|
11
12
|
/** Most samples a bake may rasterise (output texels × supersample²): 4096², about 1 GB of per-sample arrays at full coverage. */
|
|
12
13
|
const MAX_SAMPLES = 4096 * 4096;
|
|
13
14
|
// ---------------------------------------------------------------- shared params
|
|
14
|
-
const BAKE_PARAMS = (
|
|
15
|
+
const BAKE_PARAMS = () => ({
|
|
15
16
|
resolution: resolutionParam(1024),
|
|
16
17
|
supersample: { type: 'int', default: 1, min: 1, max: 4, desc: 'samples per texel along each axis (2 = 4 samples averaged: smoother edges, 4× the work)', aliases: ['ssaa', 'antialiasing', 'subsampling'] },
|
|
17
18
|
padding: { type: 'int', default: 4, min: 0, max: 256, desc: 'dilate islands by this many texels (no background bleeding in mipmaps)', aliases: ['dilation', 'margin', 'edge_padding'] },
|
|
18
19
|
uv_attrib: { type: 'string', default: 'uv', desc: 'vertex or point uv attribute to bake into', aliases: ['uv_name', 'uvattrib'] },
|
|
19
20
|
group: P.group('prim', 'prims to bake ("" = all); the others leave their texels empty'),
|
|
20
21
|
keep_mesh: { type: 'bool', default: false, desc: 'output the input mesh with the image added (off: only the image)', aliases: ['keep_input', 'keep'] },
|
|
21
|
-
name: nameParam(
|
|
22
|
+
name: nameParam(),
|
|
22
23
|
});
|
|
23
24
|
const INPUTS = [
|
|
24
25
|
{ name: 'geo', desc: 'mesh to bake (needs uv without overlaps: uv_unwrap or uv_layout)' },
|
|
@@ -26,6 +27,12 @@ const INPUTS = [
|
|
|
26
27
|
];
|
|
27
28
|
const cageParam = () => ({ type: 'float', default: 0, min: 0, desc: 'high-res input: search distance along the cage normals on each side (metres; 0 = auto: 2% of the bbox diagonal)', aliases: ['cage_distance', 'max_frontal_distance', 'ray_distance'] });
|
|
28
29
|
const cageNormalsParam = () => ({ type: 'enum', options: ['averaged', 'mesh'], default: 'averaged', desc: 'high-res input: ray directions: averaged normals over every face at a position (no gaps at hard edges) or the mesh\'s own normals', aliases: ['ray_normals', 'average_normals'] });
|
|
30
|
+
/** The params of every bake that reads a high-res mesh on input 1. */
|
|
31
|
+
const HIGH_PARAMS = () => ({
|
|
32
|
+
cage: cageParam(), cage_normals: cageNormalsParam(),
|
|
33
|
+
cage_attrib: { type: 'string', default: 'cage', desc: 'high-res input: a float attribute of the mesh (prim, point or vertex) that sets the cage where it is above 0, e.g. per part with attrib_create {name:"cage", class:"prim", group:"@name=grip", value:0.03}', aliases: ['cage_attribute'] },
|
|
34
|
+
match_name: { type: 'bool', default: false, desc: 'high-res input: each piece projects only onto the high prims with the same prim "name" (parts sharing one atlas do not pick up their neighbours)', aliases: ['match_names', 'by_name'] },
|
|
35
|
+
});
|
|
29
36
|
function readUVNamed(g, name) {
|
|
30
37
|
const f = g.findAttrib(name || 'uv', ['vertex', 'point']);
|
|
31
38
|
if (!f || f.attr.type !== 'float')
|
|
@@ -82,12 +89,13 @@ function setup(ctx) {
|
|
|
82
89
|
function finish(b, vals, ch, background, extra = {}) {
|
|
83
90
|
const { ctx, s } = b, p = ctx.p;
|
|
84
91
|
const { data, coverage } = resolve(s, vals, ch);
|
|
85
|
-
const
|
|
86
|
-
const img = new Image(s.W, s.H, name);
|
|
92
|
+
const img = new Image(s.W, s.H, outName(ctx));
|
|
87
93
|
const pad = Math.max(0, Math.round(p.padding));
|
|
88
94
|
dilate(data, ch, s.W, s.H, coverage, pad, background);
|
|
89
95
|
img.set(MAIN_LAYER, data);
|
|
90
|
-
|
|
96
|
+
// with a high-res mesh: where the projection found nothing, to see which parts need a larger cage
|
|
97
|
+
const layers = b.missed ? { ...extra, missed: { vals: b.missed, ch: 1, background: [0] } } : extra;
|
|
98
|
+
for (const [k, e] of Object.entries(layers)) {
|
|
91
99
|
const r = resolve(s, e.vals, e.ch);
|
|
92
100
|
dilate(r.data, e.ch, s.W, s.H, coverage, pad, e.background);
|
|
93
101
|
img.set(k, r.data);
|
|
@@ -118,14 +126,84 @@ function highOf(ctx) {
|
|
|
118
126
|
* when the kernel ran on this thread.
|
|
119
127
|
*/
|
|
120
128
|
function project(b, high, cage, normals) {
|
|
129
|
+
const { ctx } = b, n = b.s.n;
|
|
121
130
|
const scene = RayScene.of(high);
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
const R = rayDirs(b), C = cagesOf(b, cage);
|
|
132
|
+
const D = new Float64Array(n), NO = new Float64Array(normals ? n * 3 : 0);
|
|
133
|
+
const done = () => {
|
|
134
|
+
const missed = new Float32Array(n);
|
|
135
|
+
for (let i = 0; i < n; i++)
|
|
136
|
+
if (!(D[i] === D[i]))
|
|
137
|
+
missed[i] = 1;
|
|
138
|
+
b.missed = missed;
|
|
139
|
+
let count = 0;
|
|
140
|
+
for (let i = 0; i < n; i++)
|
|
141
|
+
count += missed[i];
|
|
142
|
+
ctx.stat('missed', count);
|
|
143
|
+
return { D, NO, scene, R };
|
|
144
|
+
};
|
|
145
|
+
// match_name: each named piece of the mesh projects onto the high prims of the same name only
|
|
146
|
+
const lowName = b.g.prims.get('name'), highName = high.prims.get('name');
|
|
147
|
+
if (!ctx.p.match_name || !lowName || lowName.type !== 'string' || !highName || highName.type !== 'string') {
|
|
148
|
+
if (ctx.p.match_name)
|
|
149
|
+
ctx.warn(`${ctx.type}: match_name needs a prim "name" on the mesh and on the high mesh; every high prim is matched`);
|
|
150
|
+
const run = ctx.parallelMap('bake_project', {
|
|
151
|
+
count: n, args: { cage }, inputs: { P: b.P, N: R, C }, results: normals ? { D, NO } : { D }, shared: { ...scene.toArrays(), HN: normals ? pointNormalsOf(high) : new Float64Array(0) },
|
|
152
|
+
});
|
|
153
|
+
return andThen(run, done);
|
|
154
|
+
}
|
|
155
|
+
const ln = lowName.data, hn = highName.data;
|
|
156
|
+
const bySample = new Map();
|
|
157
|
+
for (let i = 0; i < n; i++) {
|
|
158
|
+
const k = ln[b.triPrim[b.s.tri[i]]] ?? '';
|
|
159
|
+
const l = bySample.get(k);
|
|
160
|
+
if (l)
|
|
161
|
+
l.push(i);
|
|
162
|
+
else
|
|
163
|
+
bySample.set(k, [i]);
|
|
164
|
+
}
|
|
165
|
+
const lonely = [], runs = [];
|
|
166
|
+
for (const [nm, idx] of bySample) {
|
|
167
|
+
const sel = Uint8Array.from(hn, (x) => (x === nm ? 1 : 0));
|
|
168
|
+
if (!sel.some((x) => x)) {
|
|
169
|
+
lonely.push(nm || '(no name)');
|
|
170
|
+
for (const i of idx)
|
|
171
|
+
D[i] = NaN;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const sub = high.subsetPrims(sel), sc = RayScene.of(sub), m = idx.length;
|
|
175
|
+
const Ps = new Float64Array(m * 3), Ns = new Float64Array(m * 3), Cs = C ? new Float64Array(m) : undefined;
|
|
176
|
+
idx.forEach((i, k) => { for (let c = 0; c < 3; c++) {
|
|
177
|
+
Ps[k * 3 + c] = b.P[i * 3 + c];
|
|
178
|
+
Ns[k * 3 + c] = R[i * 3 + c];
|
|
179
|
+
} if (Cs)
|
|
180
|
+
Cs[k] = C[i]; });
|
|
181
|
+
const Ds = new Float64Array(m), NOs = new Float64Array(normals ? m * 3 : 0);
|
|
182
|
+
const run = ctx.parallelMap('bake_project', {
|
|
183
|
+
count: m, args: { cage }, inputs: { P: Ps, N: Ns, C: Cs }, results: normals ? { D: Ds, NO: NOs } : { D: Ds }, shared: { ...sc.toArrays(), HN: normals ? pointNormalsOf(sub) : new Float64Array(0) },
|
|
184
|
+
});
|
|
185
|
+
runs.push(andThen(run, () => idx.forEach((i, k) => { D[i] = Ds[k]; if (normals)
|
|
186
|
+
for (let c = 0; c < 3; c++)
|
|
187
|
+
NO[i * 3 + c] = NOs[k * 3 + c]; })));
|
|
188
|
+
}
|
|
189
|
+
if (lonely.length)
|
|
190
|
+
ctx.warn(`${ctx.type}: match_name: no high prims named ${lonely.slice(0, 8).map((x) => `"${x}"`).join(', ')}${lonely.length > 8 ? ' …' : ''}; those pieces bake as misses`);
|
|
191
|
+
return runs.some((r) => r instanceof Promise) ? Promise.all(runs).then(done) : done();
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Per-sample cage distances where the mesh carries the cage_attrib attribute (prim, point or vertex; e.g. set per part
|
|
195
|
+
* with attrib_create {name: "cage", class: "prim", group}): its value where > 0, else the node's cage. Null without one.
|
|
196
|
+
*/
|
|
197
|
+
function cagesOf(b, cage) {
|
|
198
|
+
const name = String(b.ctx.p.cage_attrib ?? '').trim();
|
|
199
|
+
const f = name ? b.g.findAttrib(name, ['vertex', 'point', 'prim', 'detail']) : null;
|
|
200
|
+
if (!f || f.attr.type === 'string' || f.attr.isArray)
|
|
201
|
+
return undefined;
|
|
202
|
+
const C = interpolate(b.s, b.tris, vertexValues(b.g, name, 1), 1);
|
|
203
|
+
for (let i = 0; i < C.length; i++)
|
|
204
|
+
if (!(C[i] > 0))
|
|
205
|
+
C[i] = cage;
|
|
206
|
+
return C;
|
|
129
207
|
}
|
|
130
208
|
/** Cage ray directions per sample: averaged normals (default; no gaps at hard edges) or the mesh's own normals. */
|
|
131
209
|
function rayDirs(b) {
|
|
@@ -161,6 +239,24 @@ function pointNormalsOf(g) {
|
|
|
161
239
|
/** andThen() for a callback that may itself return a promise (a cook result); keeps synchronous runs synchronous. */
|
|
162
240
|
const chain = (x, f) => (x instanceof Promise ? x.then(f) : f(x));
|
|
163
241
|
const cageOf = (b) => (b.ctx.p.cage > 0 ? b.ctx.p.cage : 0.02 * b.diag);
|
|
242
|
+
/** Where the projection missed, for its warning: the parts with missed samples (counts) and the first one's place. */
|
|
243
|
+
function missWhere(b) {
|
|
244
|
+
const m = b.missed;
|
|
245
|
+
if (!m)
|
|
246
|
+
return '';
|
|
247
|
+
const prims = [];
|
|
248
|
+
let first = -1;
|
|
249
|
+
for (let i = 0; i < b.s.n; i++)
|
|
250
|
+
if (m[i]) {
|
|
251
|
+
if (first < 0)
|
|
252
|
+
first = i;
|
|
253
|
+
prims.push(b.triPrim[b.s.tri[i]]);
|
|
254
|
+
}
|
|
255
|
+
if (first < 0)
|
|
256
|
+
return '';
|
|
257
|
+
const parts = partsOf(b.g, prims);
|
|
258
|
+
return `; ${parts ? `samples by part: ${parts}; ` : ''}the first at ${primWhere(b.g, b.triPrim[b.s.tri[first]], b.P.subarray(first * 3, first * 3 + 3))}`;
|
|
259
|
+
}
|
|
164
260
|
/** Samples moved onto the high mesh (P, N) where the projection hit; the low surface elsewhere. */
|
|
165
261
|
function onHigh(b, high) {
|
|
166
262
|
return andThen(project(b, high, cageOf(b), true), ({ D, NO, scene, R }) => {
|
|
@@ -178,14 +274,14 @@ function onHigh(b, high) {
|
|
|
178
274
|
}
|
|
179
275
|
}
|
|
180
276
|
if (miss)
|
|
181
|
-
b.ctx.warn(`${b.ctx.type}: ${miss} of ${b.s.n} samples found no high-res surface within the cage (${cageOf(b).toPrecision(3)} m); they use the low surface
|
|
277
|
+
b.ctx.warn(`${b.ctx.type}: ${miss} of ${b.s.n} samples found no high-res surface within the cage (${cageOf(b).toPrecision(3)} m${b.ctx.p.cage_attrib && b.g.findAttrib(b.ctx.p.cage_attrib, ['vertex', 'point', 'prim', 'detail']) ? `, or attribute "${b.ctx.p.cage_attrib}"` : ''}); they use the low surface${missWhere(b)}. Layer "missed" shows where: raise cage there (cage_attrib per part)`);
|
|
182
278
|
return { P, N, scene, D, miss };
|
|
183
279
|
});
|
|
184
280
|
}
|
|
185
281
|
function defineBake(def) {
|
|
186
|
-
defineNode({ category: 'texture', inputs: INPUTS, ...def });
|
|
282
|
+
defineNode({ category: 'texture', inputs: INPUTS, usesNodeName: NAMED_BY_NODE, ...def });
|
|
187
283
|
}
|
|
188
|
-
const BAKE_DOC = 'Input 0 needs non-overlapping uv in 0..1 (uv_unwrap); layer "mask" holds the coverage. ';
|
|
284
|
+
const BAKE_DOC = 'Input 0 needs non-overlapping uv in 0..1 (uv_unwrap); layer "mask" holds the coverage. Bakes that read a high-res mesh on input 1 add layer "missed": 1 where the cage ray found no high surface (stat missed); cage_attrib sets the cage per part and match_name keeps each named piece to the high prims of its name. ';
|
|
189
285
|
// ---------------------------------------------------------------- ray bakes
|
|
190
286
|
function rayBake(ctx, mode) {
|
|
191
287
|
const b = setup(ctx), p = ctx.p;
|
|
@@ -217,7 +313,7 @@ const RAY_PARAMS = {
|
|
|
217
313
|
bias: { type: 'float', default: 0, min: 0, desc: 'ray start offset along the normal against self-hits (0 = auto: 1e-4 of the bbox diagonal)' },
|
|
218
314
|
seed: P.seed(),
|
|
219
315
|
invert: { type: 'bool', default: false, desc: 'write 1 - value' },
|
|
220
|
-
|
|
316
|
+
...HIGH_PARAMS(),
|
|
221
317
|
};
|
|
222
318
|
defineBake({
|
|
223
319
|
type: 'bake_ao',
|
|
@@ -227,15 +323,15 @@ defineBake({
|
|
|
227
323
|
'that hit within max_distance. Combine with bake_curvature for edge wear and dirt masks; pack into ORM with tex_channel.',
|
|
228
324
|
aliases: ['ao_bake', 'bake_ambient_occlusion', 'bake_occlusion'],
|
|
229
325
|
params: {
|
|
230
|
-
...BAKE_PARAMS(
|
|
326
|
+
...BAKE_PARAMS(),
|
|
231
327
|
...RAY_PARAMS,
|
|
232
328
|
max_distance: { type: 'float', default: 0, min: 0, desc: 'hits farther than this do not occlude (metres; 0 = unlimited)', aliases: ['max_occluder_distance', 'distance', 'radius'] },
|
|
233
329
|
cone_angle: { type: 'float', default: 0, min: 0, max: 90, desc: 'half-angle of the ray cone in degrees (0 = auto: 90, the hemisphere)', aliases: ['spread', 'angle'] },
|
|
234
330
|
},
|
|
235
|
-
outputs: 'image <name> (default
|
|
331
|
+
outputs: 'image <name> (default: the node name): C grey 0..1 (1 = open), mask',
|
|
236
332
|
example: {
|
|
237
333
|
nodes: {
|
|
238
|
-
crate: { type: 'crate' },
|
|
334
|
+
crate: { type: 'topotopo/props/crate' },
|
|
239
335
|
uv: { type: 'uv_unwrap', in: ['crate'] },
|
|
240
336
|
ao: { type: 'bake_ao', in: ['uv'], params: { resolution: 512, samples: 24 } },
|
|
241
337
|
},
|
|
@@ -251,12 +347,12 @@ defineBake({
|
|
|
251
347
|
'(translucency, subsurface masks).',
|
|
252
348
|
aliases: ['thickness_bake', 'bake_thick'],
|
|
253
349
|
params: {
|
|
254
|
-
...BAKE_PARAMS(
|
|
350
|
+
...BAKE_PARAMS(),
|
|
255
351
|
...RAY_PARAMS,
|
|
256
352
|
max_distance: { type: 'float', default: 0, min: 0, desc: 'thickness that maps to 1 (metres; 0 = auto: 25% of the bbox diagonal)', aliases: ['distance', 'radius'] },
|
|
257
353
|
cone_angle: { type: 'float', default: 0, min: 0, max: 90, desc: 'half-angle of the ray cone in degrees (0 = auto: 30)', aliases: ['spread', 'angle'] },
|
|
258
354
|
},
|
|
259
|
-
outputs: 'image <name> (default
|
|
355
|
+
outputs: 'image <name> (default: the node name): C grey 0..1, mask',
|
|
260
356
|
example: {
|
|
261
357
|
nodes: {
|
|
262
358
|
ring: { type: 'torus' },
|
|
@@ -275,17 +371,21 @@ defineBake({
|
|
|
275
371
|
'edge carries its signed bend (angle / 90°, + convex), and a texel sums the bends of the edge length within `radius`, ' +
|
|
276
372
|
'weighted (1 - d²/r²)² and normalised so a 90° edge through the texel reads 1. C = 0.5 + 0.5 × strength × value; ' +
|
|
277
373
|
'layers "convex" and "concave" hold the two sides 0..1. Edges whose faces both turn away from a texel (the far side ' +
|
|
278
|
-
'of a thin plank) are ignored; points are matched by position, so unwelded boxes work.
|
|
279
|
-
'
|
|
374
|
+
'of a thin plank) are ignored; points are matched by position, so unwelded boxes work. intersections (on by ' +
|
|
375
|
+
'default) also finds the creases where separate parts cut into each other, as kitbashed meshes have them (a rivet ' +
|
|
376
|
+
'or boss merged onto a plate, a box sunk into another): concave by the angle between the two faces, so dirt ' +
|
|
377
|
+
'gathers there too (stat crossing_edges). tex_histogram_scan or tex_levels on "convex" make an edge-wear mask, ' +
|
|
378
|
+
'on "concave" a dirt or cavity mask.',
|
|
280
379
|
aliases: ['curvature_bake', 'bake_edges', 'edge_wear_bake'],
|
|
281
380
|
params: {
|
|
282
|
-
...BAKE_PARAMS(
|
|
381
|
+
...BAKE_PARAMS(),
|
|
283
382
|
radius: { type: 'float', default: 0, min: 0, desc: 'how far an edge reaches across the surface (metres; 0 = auto: 1% of the bbox diagonal)', aliases: ['width', 'edge_width', 'distance'] },
|
|
284
383
|
strength: { type: 'float', default: 1, min: 0, desc: 'contrast multiplier', aliases: ['intensity', 'contrast'] },
|
|
285
384
|
min_angle: { type: 'float', default: 0.5, min: 0, max: 179, desc: 'edges bending less than this (degrees) are ignored' },
|
|
286
|
-
|
|
385
|
+
intersections: { type: 'bool', default: true, desc: 'also find the concave creases where separate parts cut into each other (kitbashed meshes)', aliases: ['crossings', 'intersection_creases'] },
|
|
386
|
+
...HIGH_PARAMS(),
|
|
287
387
|
},
|
|
288
|
-
outputs: 'image <name> (default
|
|
388
|
+
outputs: 'image <name> (default: the node name): C grey (0.5 = flat), convex, concave, mask',
|
|
289
389
|
example: {
|
|
290
390
|
nodes: {
|
|
291
391
|
box: { type: 'box' },
|
|
@@ -300,11 +400,15 @@ defineBake({
|
|
|
300
400
|
const high = highOf(ctx);
|
|
301
401
|
const go = (P, N, src) => {
|
|
302
402
|
const r = p.radius > 0 ? p.radius : 0.01 * b.diag;
|
|
303
|
-
const
|
|
403
|
+
const counts = { shared: 0, crossing: 0, capped: false };
|
|
404
|
+
const edges = curvatureEdges(src, 1e-6 * (bboxDiagonal(src) || 1), p.min_angle, !!p.intersections, counts);
|
|
405
|
+
if (counts.capped)
|
|
406
|
+
ctx.warn(`${ctx.type}: the search for crossing parts stopped early on this large mesh; some creases where parts cut into each other may be missing`);
|
|
304
407
|
const grid = edgeGrid(edges, r);
|
|
305
408
|
const args = { radius: r, facing: 0.25, origin: grid.origin, cell: grid.cell, dims: grid.dims };
|
|
306
409
|
const V = new Float64Array(b.s.n);
|
|
307
410
|
ctx.stat('edges', edges.count);
|
|
411
|
+
ctx.stat('crossing_edges', counts.crossing);
|
|
308
412
|
const run = ctx.parallelMap('bake_curvature', {
|
|
309
413
|
count: b.s.n, args, inputs: { P, N }, results: { V }, shared: { E: edges.E, D: edges.D, K: edges.K, FN: edges.FN, start: grid.start, items: grid.items },
|
|
310
414
|
});
|
|
@@ -335,13 +439,13 @@ defineBake({
|
|
|
335
439
|
aliases: ['position_bake', 'bake_world_position'],
|
|
336
440
|
inputs: [INPUTS[0]],
|
|
337
441
|
params: {
|
|
338
|
-
...BAKE_PARAMS(
|
|
442
|
+
...BAKE_PARAMS(),
|
|
339
443
|
mode: { type: 'enum', options: ['bbox', 'uniform', 'world'], default: 'bbox', desc: 'how positions map to colour', aliases: ['normalize'] },
|
|
340
444
|
},
|
|
341
|
-
outputs: 'image <name> (default
|
|
445
|
+
outputs: 'image <name> (default: the node name): C RGBA, mask',
|
|
342
446
|
example: {
|
|
343
447
|
nodes: {
|
|
344
|
-
crate: { type: 'crate' },
|
|
448
|
+
crate: { type: 'topotopo/props/crate' },
|
|
345
449
|
uv: { type: 'uv_unwrap', in: ['crate'] },
|
|
346
450
|
pos: { type: 'bake_position', in: ['uv'], params: { resolution: 256 } },
|
|
347
451
|
},
|
|
@@ -368,8 +472,8 @@ defineBake({
|
|
|
368
472
|
summary: 'Bake world-space normals into uv space as RGB (0.5 + 0.5 n): the mesh\'s own, or the high-res input\'s along the cage.',
|
|
369
473
|
description: 'Substance Painter "World Space Normal". ' + BAKE_DOC + 'Without input 1 the mesh\'s interpolated vertex normals (N, else computed with a 60° cusp); with a high-res input its normals where the cage rays hit it. Green-channel masks (tex_channel extract g) give "facing up" for dust and snow.',
|
|
370
474
|
aliases: ['world_normal_bake', 'bake_worldspace_normal'],
|
|
371
|
-
params: { ...BAKE_PARAMS(
|
|
372
|
-
outputs: 'image <name> (default
|
|
475
|
+
params: { ...BAKE_PARAMS(), ...HIGH_PARAMS() },
|
|
476
|
+
outputs: 'image <name> (default: the node name): C RGBA, mask',
|
|
373
477
|
example: {
|
|
374
478
|
nodes: {
|
|
375
479
|
ball: { type: 'sphere', params: { rows: 8, cols: 16 } },
|
|
@@ -406,11 +510,11 @@ defineBake({
|
|
|
406
510
|
'read OpenGL; Unreal DirectX (or flip green on import).',
|
|
407
511
|
aliases: ['normal_bake', 'bake_tangent_normal', 'bake_normal_map'],
|
|
408
512
|
params: {
|
|
409
|
-
...BAKE_PARAMS(
|
|
410
|
-
|
|
513
|
+
...BAKE_PARAMS(),
|
|
514
|
+
...HIGH_PARAMS(),
|
|
411
515
|
format: { type: 'enum', options: ['opengl', 'directx'], default: 'opengl', desc: 'green channel convention', aliases: ['convention'] },
|
|
412
516
|
},
|
|
413
|
-
outputs: 'image <name> (default
|
|
517
|
+
outputs: 'image <name> (default: the node name): C RGBA, mask',
|
|
414
518
|
example: {
|
|
415
519
|
nodes: {
|
|
416
520
|
low: { type: 'box', params: { divisions: [2, 2, 2] } },
|
|
@@ -476,11 +580,11 @@ defineBake({
|
|
|
476
580
|
'or use it as displacement.',
|
|
477
581
|
aliases: ['height_bake', 'bake_displacement', 'displacement_bake'],
|
|
478
582
|
params: {
|
|
479
|
-
...BAKE_PARAMS(
|
|
480
|
-
|
|
583
|
+
...BAKE_PARAMS(),
|
|
584
|
+
...HIGH_PARAMS(),
|
|
481
585
|
mode: { type: 'enum', options: ['cage', 'normalize'], default: 'cage', desc: 'how distances map to 0..1', aliases: ['range'] },
|
|
482
586
|
},
|
|
483
|
-
outputs: 'image <name> (default
|
|
587
|
+
outputs: 'image <name> (default: the node name): C grey 0..1, distance (metres), mask',
|
|
484
588
|
example: {
|
|
485
589
|
nodes: {
|
|
486
590
|
low: { type: 'box', params: { divisions: [2, 2, 2] } },
|
|
@@ -512,7 +616,7 @@ defineBake({
|
|
|
512
616
|
miss++;
|
|
513
617
|
}
|
|
514
618
|
if (miss)
|
|
515
|
-
ctx.warn(`${ctx.type}: ${miss} of ${n} samples found no high-res surface within the cage (${cage.toPrecision(3)} m)`);
|
|
619
|
+
ctx.warn(`${ctx.type}: ${miss} of ${n} samples found no high-res surface within the cage (${cage.toPrecision(3)} m)${missWhere(b)}; layer "missed" shows where`);
|
|
516
620
|
const span = hi > lo ? hi - lo : 1;
|
|
517
621
|
for (let i = 0; i < n; i++) {
|
|
518
622
|
const d = D[i];
|
|
@@ -534,11 +638,11 @@ defineBake({
|
|
|
534
638
|
description: 'Substance Painter "ID" (by uv island). ' + BAKE_DOC + 'Islands are triangles connected through corners that share a point and a uv. C is a random colour per island (seed), layer "id" the island number 0..n-1 (the stat islands counts them).',
|
|
535
639
|
aliases: ['island_id_bake', 'bake_id', 'id_bake', 'bake_uv_islands'],
|
|
536
640
|
inputs: [INPUTS[0]],
|
|
537
|
-
params: { ...BAKE_PARAMS(
|
|
538
|
-
outputs: 'image <name> (default
|
|
641
|
+
params: { ...BAKE_PARAMS(), seed: P.seed() },
|
|
642
|
+
outputs: 'image <name> (default: the node name): C RGBA, id (island number), mask',
|
|
539
643
|
example: {
|
|
540
644
|
nodes: {
|
|
541
|
-
crate: { type: 'crate' },
|
|
645
|
+
crate: { type: 'topotopo/props/crate' },
|
|
542
646
|
uv: { type: 'uv_unwrap', in: ['crate'] },
|
|
543
647
|
ids: { type: 'bake_island_id', in: ['uv'], params: { resolution: 256 } },
|
|
544
648
|
},
|
|
@@ -581,12 +685,12 @@ defineBake({
|
|
|
581
685
|
aliases: ['mask_bake', 'bake_group', 'bake_attribute', 'attribute_bake'],
|
|
582
686
|
inputs: [INPUTS[0]],
|
|
583
687
|
params: {
|
|
584
|
-
...BAKE_PARAMS(
|
|
688
|
+
...BAKE_PARAMS(),
|
|
585
689
|
mask_group: { type: 'group', default: '', groupClass: 'prim', desc: 'prims that read 1 (e.g. "planks", "@P.y>0.5")', aliases: ['from_group', 'mask_prims'] },
|
|
586
690
|
attrib: { type: 'string', default: '', desc: 'numeric attribute to bake when mask_group is empty', aliases: ['attribute', 'from_attrib'] },
|
|
587
691
|
component: { type: 'int', default: 0, min: -1, max: 15, desc: 'vector component of attrib (-1 = luminance of the first three)' },
|
|
588
692
|
},
|
|
589
|
-
outputs: 'image <name> (default
|
|
693
|
+
outputs: 'image <name> (default: the node name): C grey, mask',
|
|
590
694
|
example: {
|
|
591
695
|
nodes: {
|
|
592
696
|
box: { type: 'box' },
|
|
@@ -627,11 +731,11 @@ defineBake({
|
|
|
627
731
|
aliases: ['vertex_color_bake', 'bake_color', 'bake_cd', 'color_bake'],
|
|
628
732
|
inputs: [INPUTS[0]],
|
|
629
733
|
params: {
|
|
630
|
-
...BAKE_PARAMS(
|
|
734
|
+
...BAKE_PARAMS(),
|
|
631
735
|
attrib: { type: 'string', default: 'Cd', desc: 'colour attribute', aliases: ['attribute', 'color_attrib'] },
|
|
632
736
|
alpha_attrib: { type: 'string', default: 'Alpha', desc: 'alpha attribute (missing = 1)' },
|
|
633
737
|
},
|
|
634
|
-
outputs: 'image <name> (default
|
|
738
|
+
outputs: 'image <name> (default: the node name): C RGBA, mask',
|
|
635
739
|
example: {
|
|
636
740
|
nodes: {
|
|
637
741
|
ball: { type: 'sphere', params: { rows: 12, cols: 24 } },
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
+
});
|