topotopo 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +30 -0
- package/README.md +35 -14
- package/dist/cli.js +28 -10
- package/dist/core/analysis.d.ts +5 -1
- package/dist/core/analysis.js +8 -3
- package/dist/core/bake.d.ts +2 -5
- package/dist/core/bake.js +12 -25
- package/dist/core/bevel.js +165 -97
- package/dist/core/geometry.js +1 -1
- package/dist/core/imageops.d.ts +6 -0
- package/dist/core/imageops.js +51 -0
- package/dist/core/materials.d.ts +4 -0
- package/dist/core/materials.js +11 -0
- package/dist/core/packed.js +11 -0
- package/dist/core/particles.d.ts +1 -1
- package/dist/core/particles.js +1 -1
- package/dist/core/rbd.js +13 -1
- package/dist/core/scatter.d.ts +1 -1
- package/dist/core/scatter.js +1 -1
- package/dist/core/scene.d.ts +20 -0
- package/dist/core/scene.js +71 -0
- package/dist/core/snippet-lib.d.ts +1 -1
- package/dist/core/snippet-lib.js +1 -1
- package/dist/core/solidify.d.ts +38 -0
- package/dist/core/solidify.js +356 -0
- package/dist/core/tangents.d.ts +52 -0
- package/dist/core/tangents.js +214 -0
- package/dist/core/texcoord.d.ts +4 -0
- package/dist/core/texcoord.js +14 -0
- package/dist/core/topology.d.ts +22 -0
- package/dist/core/topology.js +70 -7
- package/dist/core/traceimage.d.ts +7 -0
- package/dist/core/traceimage.js +221 -0
- package/dist/core/tritri.d.ts +5 -0
- package/dist/core/tritri.js +120 -0
- package/dist/core/uv.d.ts +13 -0
- package/dist/core/uv.js +3 -3
- package/dist/core/uvreport.d.ts +66 -0
- package/dist/core/uvreport.js +308 -0
- package/dist/core/xatlas.js +32 -2
- package/dist/gallery/app/gallery.css +100 -0
- package/dist/gallery/app/gallery.js +80 -0
- package/dist/gallery/bake.d.ts +34 -0
- package/dist/gallery/bake.js +144 -0
- package/dist/gallery/cli.d.ts +4 -0
- package/dist/gallery/cli.js +157 -0
- package/dist/gallery/library.d.ts +124 -0
- package/dist/gallery/library.js +366 -0
- package/dist/gallery/pages.d.ts +94 -0
- package/dist/gallery/pages.js +148 -0
- package/dist/gallery/server.d.ts +21 -0
- package/dist/gallery/server.js +391 -0
- package/dist/host/export-targets.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/inspect.d.ts +6 -1
- package/dist/inspect.js +13 -1
- package/dist/io/common.d.ts +8 -0
- package/dist/io/gltf.js +236 -19
- package/dist/io/targets.js +1 -1
- package/dist/mcp/docs.d.ts +1 -1
- package/dist/mcp/docs.js +58 -4
- package/dist/mcp/library.d.ts +12 -0
- package/dist/mcp/library.js +159 -0
- package/dist/mcp/server.js +29 -12
- package/dist/mcp/tools.js +16 -10
- package/dist/nodes/bake.js +56 -36
- package/dist/nodes/bevel.js +4 -3
- package/dist/nodes/code.js +1 -1
- package/dist/nodes/curves.js +7 -0
- package/dist/nodes/generate.js +1 -1
- package/dist/nodes/imageops.d.ts +1 -0
- package/dist/nodes/imageops.js +206 -0
- package/dist/nodes/index.d.ts +3 -0
- package/dist/nodes/index.js +3 -0
- package/dist/nodes/material.js +3 -0
- package/dist/nodes/measure.js +3 -2
- package/dist/nodes/rbd.js +1 -1
- package/dist/nodes/scene.d.ts +1 -0
- package/dist/nodes/scene.js +53 -0
- package/dist/nodes/solidify.d.ts +1 -0
- package/dist/nodes/solidify.js +52 -0
- package/dist/nodes/transform.js +5 -1
- package/dist/nodes/util.d.ts +1 -1
- package/dist/nodes/wasmcall.js +1 -1
- package/dist/render/options.js +1 -1
- package/dist/render/pbr.d.ts +28 -0
- package/dist/render/pbr.js +378 -0
- package/dist/render/preview.d.ts +58 -0
- package/dist/render/preview.js +24 -0
- package/dist/render/raster.d.ts +12 -2
- package/dist/render/raster.js +98 -11
- package/dist/render/texview.d.ts +1 -1
- package/dist/render/texview.js +7 -2
- package/dist/viewer/app/camera.js +1 -1
- package/dist/viewer/app/embed.js +80 -0
- package/dist/viewer/app/grid.js +1 -1
- package/dist/viewer/app/guides.js +1 -1
- package/dist/viewer/app/keymap.js +1 -1
- package/dist/viewer/app/layers.js +1 -1
- package/dist/viewer/app/main.js +1 -1
- package/dist/viewer/app/markers.js +1 -1
- package/dist/viewer/app/outliner.js +1 -1
- package/dist/viewer/app/props.js +1 -1
- package/dist/viewer/app/scene.js +6 -2
- package/dist/viewer/app/select.js +1 -1
- package/dist/viewer/app/selection.js +1 -1
- package/dist/viewer/app/status.js +1 -1
- package/dist/viewer/app/style.css +1 -1
- package/dist/viewer/app/units.js +1 -1
- package/dist/viewer/app/vars.js +1 -1
- package/dist/viewer/index.html +1 -1
- package/dist/viewer/server.d.ts +14 -2
- package/dist/viewer/server.js +30 -10
- package/dist/workspace.d.ts +13 -0
- package/dist/workspace.js +87 -1
- package/kernels/pkg/README.md +21 -28
- package/kernels/pkg-simd/README.md +21 -28
- package/package.json +9 -3
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// General-purpose image extraction, contour tracing, padding and atlas assembly.
|
|
2
|
+
import { Geometry, GeoBuilder } from '../core/geometry.js';
|
|
3
|
+
import { Image, imagesOf, toGrey, MAX_PIXELS } from '../core/image.js';
|
|
4
|
+
import { cropImage, dilateImage } from '../core/imageops.js';
|
|
5
|
+
import { traceMask } from '../core/traceimage.js';
|
|
6
|
+
import { skylinePack } from '../core/uv.js';
|
|
7
|
+
import { defineNode } from '../graph/registry.js';
|
|
8
|
+
import { NodeError } from '../graph/types.js';
|
|
9
|
+
import { source, withLayer, checkSize, resolutionParam } from './texture.js';
|
|
10
|
+
const imageParam = () => ({ type: 'string', default: '', desc: 'image name (empty selects the first image)' });
|
|
11
|
+
const layerParam = () => ({ type: 'string', default: '', desc: 'layer name (empty selects the main layer)' });
|
|
12
|
+
const nameParam = () => ({ type: 'string', default: '', desc: 'output image name (empty keeps the source name)' });
|
|
13
|
+
const channelParam = (def = 'alpha') => ({ type: 'enum', options: ['alpha', 'luminance', 'r', 'g', 'b'], default: def, desc: 'channel to read; alpha requires RGBA, luminance/R/G/B accept grey' });
|
|
14
|
+
function channel(data, ch, which) {
|
|
15
|
+
if (which === 'luminance')
|
|
16
|
+
return toGrey(data, ch);
|
|
17
|
+
if (ch === 1) {
|
|
18
|
+
if (which === 'alpha')
|
|
19
|
+
throw new NodeError('alpha channel requires RGBA; select luminance for a grey mask');
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
const c = which === 'alpha' ? 3 : 'rgb'.indexOf(which);
|
|
23
|
+
return Float32Array.from({ length: data.length / 4 }, (_, i) => data[i * 4 + c]);
|
|
24
|
+
}
|
|
25
|
+
defineNode({
|
|
26
|
+
type: 'tex_crop', category: 'texture', packed: 'keep',
|
|
27
|
+
summary: 'Extract an exact pixel rectangle, optionally resize it; all image layers stay aligned.',
|
|
28
|
+
description: 'Origin is [x,y] from the top left. Size 0 on an axis means the remaining source extent; resolution 0 keeps the crop size. Outside pixels are zero, never wrapped. Filtered resize uses area averaging down and bilinear up; nearest preserves discrete masks. Values are not colour-converted. Other geometry/images pass through.',
|
|
29
|
+
inputs: [{ name: 'image', desc: 'geometry carrying an image' }],
|
|
30
|
+
params: {
|
|
31
|
+
image: imageParam(), name: nameParam(),
|
|
32
|
+
origin: { type: 'ivec2', default: [0, 0], min: -1000000, max: 1000000, desc: 'crop origin in pixels, from the top left; negative origins add zero padding' },
|
|
33
|
+
size: { type: 'ivec2', default: [0, 0], min: 0, max: 8192, desc: 'crop width/height in pixels; 0 = source extent minus origin' },
|
|
34
|
+
resolution: { type: 'ivec2', default: [0, 0], min: 0, max: 8192, desc: 'output width/height; 0 = cropped size on that axis' },
|
|
35
|
+
filter: { type: 'enum', options: ['filtered', 'nearest'], default: 'filtered', desc: 'resampling filter (no resampling when the crop and output sizes match)' },
|
|
36
|
+
},
|
|
37
|
+
outputs: 'selected image replaced by its cropped/resized layers',
|
|
38
|
+
example: { nodes: { img: { type: 'tex_pattern', params: { resolution: [64, 32] } }, out: { type: 'tex_crop', in: ['img'], params: { origin: [8, 4], size: [32, 16] } } }, output: 'out' },
|
|
39
|
+
cook: (ctx) => {
|
|
40
|
+
const { p } = ctx, s = source(ctx, 0, p.image);
|
|
41
|
+
const [x, y] = p.origin, w = p.size[0] || s.img.width - x, h = p.size[1] || s.img.height - y;
|
|
42
|
+
const ow = p.resolution[0] || w, oh = p.resolution[1] || h;
|
|
43
|
+
checkSize(w, h, ctx.type);
|
|
44
|
+
checkSize(ow, oh, ctx.type);
|
|
45
|
+
const name = p.name.trim() || s.img.name, g = s.g.clone();
|
|
46
|
+
const img = cropImage(s.img, x, y, w, h, ow, oh, p.filter === 'nearest', name);
|
|
47
|
+
g.volumes[s.index] = img;
|
|
48
|
+
g.volumes = g.volumes.filter((v) => v === img || v.kind !== 'image' || v.name !== name);
|
|
49
|
+
return g;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
defineNode({
|
|
53
|
+
type: 'tex_dilate', category: 'texture', packed: 'keep',
|
|
54
|
+
summary: 'Extend nearest valid image values into an invalid band, preserving opacity by default.',
|
|
55
|
+
description: 'Validity comes from RGBA alpha or an explicit, same-sized mask. Grey images need a mask input. Valid pixels and pixels beyond radius are untouched. Nearest-site ties prefer the topmost, then leftmost source. No wrapping or colour conversion. Other layers pass through; preserve_alpha keeps every original RGBA alpha value. Uses the same exact distance transform as wide bake padding.',
|
|
56
|
+
inputs: [{ name: 'image', desc: 'image to pad' }, { name: 'mask', desc: 'optional explicit validity mask (same dimensions)', optional: true }],
|
|
57
|
+
params: {
|
|
58
|
+
image: imageParam(), layer: layerParam(), name: nameParam(),
|
|
59
|
+
radius: { type: 'int', default: 8, min: 0, max: 8192, desc: 'maximum Euclidean distance in pixels from a valid source' },
|
|
60
|
+
mask_image: imageParam(), mask_layer: layerParam(), mask_channel: channelParam('luminance'),
|
|
61
|
+
mask_threshold: { type: 'float', default: 0, desc: 'mask values strictly greater than this are valid' },
|
|
62
|
+
preserve_alpha: { type: 'bool', default: true, desc: 'keep original alpha at every RGBA pixel while padding RGB' },
|
|
63
|
+
},
|
|
64
|
+
outputs: 'selected image layer padded; original mask/alpha preserved',
|
|
65
|
+
example: { nodes: { img: { type: 'tex_shape', params: { resolution: 32, falloff: 0 } }, out: { type: 'tex_dilate', in: ['img', 'img'], params: { radius: 3 } } }, output: 'out' },
|
|
66
|
+
cook: (ctx) => {
|
|
67
|
+
const { p } = ctx, s = source(ctx, 0, p.image, p.layer);
|
|
68
|
+
let mask;
|
|
69
|
+
if (ctx.hasInput(1)) {
|
|
70
|
+
const m = source(ctx, 1, p.mask_image, p.mask_layer);
|
|
71
|
+
if (m.img.width !== s.img.width || m.img.height !== s.img.height)
|
|
72
|
+
throw new NodeError('tex_dilate: mask dimensions must match the source image');
|
|
73
|
+
mask = channel(m.data, m.ch, p.mask_channel);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
if (s.ch !== 4)
|
|
77
|
+
throw new NodeError('tex_dilate: a grey image requires an explicit mask input');
|
|
78
|
+
mask = channel(s.data, s.ch, 'alpha');
|
|
79
|
+
}
|
|
80
|
+
return withLayer(s, dilateImage(s.data, s.ch, s.img.width, s.img.height, mask, p.mask_threshold, p.radius, p.preserve_alpha), p.name);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
defineNode({
|
|
84
|
+
type: 'trace_image', category: 'curve',
|
|
85
|
+
summary: 'Trace a thresholded image into closed XY contours, with holes and disconnected components.',
|
|
86
|
+
description: 'Traces pixel-cell boundaries (not a bounding rectangle). Foreground is 4-connected: diagonal contacts stay separate. Simplification is conservative, topology-preserving, and bounded by tolerance in pixels. min_area filters entire foreground components by pixel area, retaining their holes. The full canvas maps to [0,width] × [0,width*height/widthPixels] in XY, including transparent margins. After fill use uv_project {method:"planar",axis:"z",scale:[width,width*heightPixels/widthPixels]}; fill does not preserve contour attributes. More than 1,000,000 boundary edges fails with a hint.',
|
|
87
|
+
inputs: [{ name: 'image', desc: 'geometry carrying the image to trace' }],
|
|
88
|
+
params: {
|
|
89
|
+
image: imageParam(), layer: layerParam(), channel: channelParam(),
|
|
90
|
+
threshold: { type: 'float', default: 0.5, desc: 'values at least this threshold are foreground' },
|
|
91
|
+
tolerance: { type: 'float', default: 0.5, min: 0, max: 8192, desc: 'maximum contour simplification error in source pixels; 0 only removes collinear points' },
|
|
92
|
+
min_area: { type: 'float', default: 0, min: 0, max: MAX_PIXELS, desc: 'minimum connected foreground component area in pixels; 0 retains all components' },
|
|
93
|
+
width: { type: 'float', default: 1, min: 0.000001, desc: 'full image canvas width in metres; height follows image aspect' },
|
|
94
|
+
},
|
|
95
|
+
outputs: 'closed curves; point uv; prim class (component ID), contour_id and hole (0/1); detail image_size and image_width',
|
|
96
|
+
example: { nodes: { img: { type: 'tex_shape', params: { resolution: [64, 32], shape: 'disc', falloff: 0 } }, out: { type: 'trace_image', in: ['img'], params: { channel: 'luminance' } } }, output: 'out' },
|
|
97
|
+
cook: (ctx) => {
|
|
98
|
+
const { p } = ctx, s = source(ctx, 0, p.image, p.layer);
|
|
99
|
+
const loops = traceMask(channel(s.data, s.ch, p.channel), s.img.width, s.img.height, p.threshold, p.min_area, p.tolerance);
|
|
100
|
+
const b = new GeoBuilder(), scale = p.width / s.img.width;
|
|
101
|
+
for (const loop of loops) {
|
|
102
|
+
// Pixel-space winding is reversed by Y-up, so reverse the sequence as well.
|
|
103
|
+
const points = loop.points.slice().reverse().map(([x, y]) => b.addPoint(x * scale, (s.img.height - y) * scale, 0));
|
|
104
|
+
b.addPrim(points, true);
|
|
105
|
+
}
|
|
106
|
+
const g = b.build(), cls = g.prims.add('class', 'int', 1), hole = g.prims.add('hole', 'int', 1), contour = g.prims.add('contour_id', 'int', 1);
|
|
107
|
+
loops.forEach((l, i) => { cls.set(i, l.component); hole.set(i, l.hole ? 1 : 0); contour.set(i, i); });
|
|
108
|
+
const uv = g.points.add('uv', 'float', 3);
|
|
109
|
+
for (let i = 0; i < g.numPoints; i++)
|
|
110
|
+
uv.set(i, [g.P[i * 3] / p.width, g.P[i * 3 + 1] / (s.img.height * scale), 0]);
|
|
111
|
+
g.detail.add('image_size', 'int', 2).set(0, [s.img.width, s.img.height]);
|
|
112
|
+
g.detail.add('image_width', 'float', 1).set(0, p.width);
|
|
113
|
+
return g;
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
defineNode({
|
|
117
|
+
type: 'tex_pack', category: 'texture',
|
|
118
|
+
summary: 'Pack named images into aligned atlases and output per-item UV placement attributes.',
|
|
119
|
+
description: 'items is [{name:"leaf",maps:{color:"leaf_color",normal:"leaf_normal"}}]. Empty items packs each input image under the channel C. Every item must have the same map labels; images within an item must match dimensions and images within a channel must have matching channel counts. The selected images use their main layer. Native resolution, no rotation/downscaling, zero gutters. Outputs <name>_<channel> images and placement points in item order. rect is [x,y,width,height] in top-left pixels; atlasUV = localUV * uv_scale + uv_offset (V up). Connect the image output to texture_to_material and read placement attributes with a wrangle; do not merge placement points into your mesh. Padding is separate: tex_dilate. Limits: 4096 items, normal per-image pixel limit, at most 1 GiB of output image layers.',
|
|
120
|
+
inputs: [{ name: 'images', desc: 'geometry carrying named source images (combine with merge)' }],
|
|
121
|
+
params: {
|
|
122
|
+
items: { type: 'json', default: [], desc: 'array of {name, maps:{channel:imageName}}; empty = each image becomes one item in channel C' },
|
|
123
|
+
resolution: resolutionParam(2048),
|
|
124
|
+
padding: { type: 'int', default: 8, min: 0, max: 8192, desc: 'empty gutter on every side of each item, in pixels' },
|
|
125
|
+
name: { type: 'string', default: 'atlas', desc: 'atlas image name prefix; images are named <name>_<channel>' },
|
|
126
|
+
},
|
|
127
|
+
outputs: 'atlas images; points with name, rect, uv_offset and uv_scale; detail atlas_size',
|
|
128
|
+
example: { nodes: { a: { type: 'tex_shape', params: { resolution: 32, name: 'disc' } }, b: { type: 'tex_pattern', params: { resolution: [32, 16], name: 'pattern' } }, images: { type: 'merge', in: ['a', 'b'] }, out: { type: 'tex_pack', in: ['images'], params: { resolution: 128, padding: 4 } } }, output: 'out' },
|
|
129
|
+
cook: ({ input, p }) => {
|
|
130
|
+
const images = imagesOf(input(0)), pool = new Map();
|
|
131
|
+
for (const im of images) {
|
|
132
|
+
if (pool.has(im.name))
|
|
133
|
+
throw new NodeError('tex_pack: duplicate input image name "' + im.name + '"');
|
|
134
|
+
pool.set(im.name, im);
|
|
135
|
+
}
|
|
136
|
+
if (!Array.isArray(p.items))
|
|
137
|
+
throw new NodeError('tex_pack: items must be an array of {name,maps}');
|
|
138
|
+
const items = p.items.length ? p.items : images.map((im) => ({ name: im.name, maps: { C: im.name } }));
|
|
139
|
+
if (!items.length || items.length > 4096)
|
|
140
|
+
throw new NodeError('tex_pack: needs 1..4096 items');
|
|
141
|
+
const prefix = p.name.trim();
|
|
142
|
+
if (!prefix)
|
|
143
|
+
throw new NodeError('tex_pack: name must not be empty');
|
|
144
|
+
const names = new Set();
|
|
145
|
+
let labels = [];
|
|
146
|
+
const sources = items.map((item, i) => {
|
|
147
|
+
if (!item || typeof item.name !== 'string' || !item.name.trim() || names.has(item.name))
|
|
148
|
+
throw new NodeError('tex_pack: item names must be non-empty and unique');
|
|
149
|
+
names.add(item.name);
|
|
150
|
+
if (!item.maps || typeof item.maps !== 'object' || Array.isArray(item.maps))
|
|
151
|
+
throw new NodeError('tex_pack: item "' + item.name + '" needs a maps object');
|
|
152
|
+
const keys = Object.keys(item.maps).sort();
|
|
153
|
+
if (!keys.length || keys.some((k) => !k.trim()))
|
|
154
|
+
throw new NodeError('tex_pack: map labels must not be empty');
|
|
155
|
+
if (i === 0)
|
|
156
|
+
labels = keys;
|
|
157
|
+
else if (JSON.stringify(keys) !== JSON.stringify(labels))
|
|
158
|
+
throw new NodeError('tex_pack: items must have matching map labels');
|
|
159
|
+
const maps = keys.map((key) => {
|
|
160
|
+
const ref = item.maps[key], img = typeof ref === 'string' ? pool.get(ref) : null;
|
|
161
|
+
if (!img)
|
|
162
|
+
throw new NodeError('tex_pack: missing image "' + ref + '" for ' + item.name + '.' + key);
|
|
163
|
+
if (!img.channels(img.mainLayer))
|
|
164
|
+
throw new NodeError('tex_pack: image "' + ref + '" has no valid main layer');
|
|
165
|
+
return img;
|
|
166
|
+
});
|
|
167
|
+
if (maps.some((im) => im.width !== maps[0].width || im.height !== maps[0].height))
|
|
168
|
+
throw new NodeError('tex_pack: map dimensions must match within item "' + item.name + '"');
|
|
169
|
+
return maps;
|
|
170
|
+
});
|
|
171
|
+
const [w, h] = p.resolution;
|
|
172
|
+
checkSize(w, h, 'tex_pack');
|
|
173
|
+
const channels = sources[0].map((im) => im.channels(im.mainLayer));
|
|
174
|
+
for (const maps of sources)
|
|
175
|
+
if (maps.some((im, i) => im.channels(im.mainLayer) !== channels[i]))
|
|
176
|
+
throw new NodeError('tex_pack: channel counts must match for each map label');
|
|
177
|
+
if (w * h * channels.reduce((a, b) => a + b, 0) > MAX_PIXELS * 16)
|
|
178
|
+
throw new NodeError('tex_pack: output layers exceed 1 GiB; reduce resolution or channel count');
|
|
179
|
+
const rects = sources.map((maps, id) => ({ id, w: maps[0].width + p.padding * 2, h: maps[0].height + p.padding * 2 }));
|
|
180
|
+
rects.sort((a, b) => Math.max(b.w, b.h) - Math.max(a.w, a.h) || b.w * b.h - a.w * a.h || a.id - b.id);
|
|
181
|
+
const places = skylinePack(rects, w, 1, false, h);
|
|
182
|
+
if (!places)
|
|
183
|
+
throw new NodeError('tex_pack: items and gutters do not fit ' + w + ' × ' + h + '; increase resolution, reduce padding, or resize inputs with tex_crop');
|
|
184
|
+
const g = new Geometry({ positions: items.flatMap(() => [0, 0, 0]) });
|
|
185
|
+
const name = g.points.add('name', 'string', 1), rect = g.points.add('rect', 'int', 4);
|
|
186
|
+
const offset = g.points.add('uv_offset', 'float', 2), scale = g.points.add('uv_scale', 'float', 2);
|
|
187
|
+
const atlases = labels.map((label, i) => new Image(w, h, prefix + '_' + label).set('C', new Float32Array(w * h * channels[i])));
|
|
188
|
+
items.forEach((item, i) => {
|
|
189
|
+
const x = places[i].x + p.padding, y = places[i].y + p.padding, iw = sources[i][0].width, ih = sources[i][0].height;
|
|
190
|
+
name.set(i, item.name);
|
|
191
|
+
rect.set(i, [x, y, iw, ih]);
|
|
192
|
+
offset.set(i, [x / w, 1 - (y + ih) / h]);
|
|
193
|
+
scale.set(i, [iw / w, ih / h]);
|
|
194
|
+
g.P[i * 3] = (x + iw / 2) / w;
|
|
195
|
+
g.P[i * 3 + 1] = 1 - (y + ih / 2) / h;
|
|
196
|
+
sources[i].forEach((im, c) => {
|
|
197
|
+
const ch = channels[c], data = im.layer(im.mainLayer), dest = atlases[c].layer('C');
|
|
198
|
+
for (let row = 0; row < ih; row++)
|
|
199
|
+
dest.set(data.subarray(row * iw * ch, (row + 1) * iw * ch), ((y + row) * w + x) * ch);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
g.volumes = atlases;
|
|
203
|
+
g.detail.add('atlas_size', 'int', 2).set(0, [w, h]);
|
|
204
|
+
return g;
|
|
205
|
+
},
|
|
206
|
+
});
|
package/dist/nodes/index.d.ts
CHANGED
|
@@ -25,7 +25,10 @@ import './uv.ts';
|
|
|
25
25
|
import './measure.ts';
|
|
26
26
|
import './pcg.ts';
|
|
27
27
|
import './texture.ts';
|
|
28
|
+
import './imageops.ts';
|
|
28
29
|
import './bake.ts';
|
|
29
30
|
import './particles.ts';
|
|
30
31
|
import './rbd.ts';
|
|
31
32
|
import './cloth.ts';
|
|
33
|
+
import './scene.ts';
|
|
34
|
+
import './solidify.ts';
|
package/dist/nodes/index.js
CHANGED
|
@@ -26,7 +26,10 @@ import './uv.js';
|
|
|
26
26
|
import './measure.js';
|
|
27
27
|
import './pcg.js';
|
|
28
28
|
import './texture.js';
|
|
29
|
+
import './imageops.js';
|
|
29
30
|
import './bake.js';
|
|
30
31
|
import './particles.js';
|
|
31
32
|
import './rbd.js';
|
|
32
33
|
import './cloth.js';
|
|
34
|
+
import './scene.js';
|
|
35
|
+
import './solidify.js';
|
package/dist/nodes/material.js
CHANGED
|
@@ -25,6 +25,8 @@ defineNode({
|
|
|
25
25
|
roughness: { type: 'float', default: 0.5, min: 0, max: 1, desc: 'roughness 0..1', aliases: ['rough'] },
|
|
26
26
|
emissive: { type: 'color', default: [0, 0, 0], desc: 'emitted colour; components above 1 export with KHR_materials_emissive_strength', aliases: ['emission', 'emit'] },
|
|
27
27
|
alpha: { type: 'float', default: 1, min: 0, max: 1, desc: 'opacity; below 1 exports with alphaMode BLEND', aliases: ['opacity', 'opac'] },
|
|
28
|
+
alpha_mode: { type: 'enum', options: ['auto', 'opaque', 'mask', 'blend'], default: 'auto', desc: 'auto preserves legacy scalar/vertex opacity; mask cuts out pixels below alpha_cutoff; explicit modes override auto' },
|
|
29
|
+
alpha_cutoff: { type: 'float', default: 0.5, min: 0, max: 1, desc: 'mask: discard where material alpha × texture alpha × vertex Alpha is below this value' },
|
|
28
30
|
double_sided: { type: 'bool', default: false, desc: 'render both faces', aliases: ['doublesided', 'two_sided'] },
|
|
29
31
|
unlit: { type: 'bool', default: false, desc: 'unlit shading (KHR_materials_unlit)', aliases: ['emissive_only', 'flat'] },
|
|
30
32
|
base_color_map: { type: 'path', default: '', desc: 'base colour texture (sRGB PNG/JPEG path, or "image:<name>" for an image the geometry carries; "" = none); uses the uv attribute', aliases: ['basecolor_map', 'albedo_map', 'diffuse_map', 'color_map', 'basecolor_texture', 'base_color_texture'] },
|
|
@@ -46,6 +48,7 @@ defineNode({
|
|
|
46
48
|
table[name] = normalizeMaterial({
|
|
47
49
|
baseColor: p.base_color, metallic: p.metallic, roughness: p.roughness, emissive: p.emissive,
|
|
48
50
|
alpha: p.alpha, doubleSided: !!p.double_sided, unlit: !!p.unlit,
|
|
51
|
+
alphaMode: p.alpha_mode, alphaCutoff: p.alpha_cutoff,
|
|
49
52
|
textures: { baseColor: p.base_color_map, normal: p.normal_map, roughness: p.roughness_map },
|
|
50
53
|
});
|
|
51
54
|
writeMaterials(g, table);
|
package/dist/nodes/measure.js
CHANGED
|
@@ -323,6 +323,7 @@ defineNode({
|
|
|
323
323
|
min_edge_length: { type: 'float', default: 0, min: 0, desc: 'no edge shorter than this (0 = off)' },
|
|
324
324
|
no_degenerate: { type: 'bool', default: false, desc: 'no zero-area polygons (area <= tolerance²) and no two points within tolerance of each other' },
|
|
325
325
|
no_self_intersections: { type: 'bool', default: false, desc: 'no two non-adjacent triangles cross each other (BVH search, capped at max_tests)', aliases: ['no_intersections'] },
|
|
326
|
+
strict_intersections: { type: 'bool', default: false, desc: 'no_self_intersections also fails on touching contacts, coplanar overlaps and triangles folding through a shared corner or onto a shared edge', aliases: ['strict'] },
|
|
326
327
|
max_tests: { type: 'int', default: 2000000, min: 1000, max: 1000000000, desc: 'self-intersections: candidate triangle pairs to test before stopping (the message says when it stopped)', advanced: true },
|
|
327
328
|
attrib: { type: 'string', default: '', desc: 'attribute that must exist ("" = off)', aliases: ['attribute'] },
|
|
328
329
|
attrib_class: { type: 'enum', options: ['auto', 'point', 'vertex', 'prim', 'detail'], default: 'auto', desc: 'where attrib must live (auto = any class: vertex, point, prim, detail)' },
|
|
@@ -476,10 +477,10 @@ defineNode({
|
|
|
476
477
|
}
|
|
477
478
|
if (p.no_self_intersections) {
|
|
478
479
|
checks++;
|
|
479
|
-
const r = selfIntersections(g, p.max_tests);
|
|
480
|
+
const r = selfIntersections(g, p.max_tests, { strict: p.strict_intersections });
|
|
480
481
|
const capped = r.capped ? ` (search stopped after ${r.tested.toLocaleString('en-US')} candidate pairs: there may be more)` : '';
|
|
481
482
|
if (r.pairs) {
|
|
482
|
-
fail('no_self_intersections', `${r.pairs} pair(s) of crossing triangles${capped}`);
|
|
483
|
+
fail('no_self_intersections', `${r.pairs} pair(s) of ${p.strict_intersections ? 'intersecting or touching' : 'crossing'} triangles${capped}`);
|
|
483
484
|
for (let q = 0; q < g.numPrims; q++)
|
|
484
485
|
if (r.prims[q])
|
|
485
486
|
primFail[q] = 1;
|
package/dist/nodes/rbd.js
CHANGED
|
@@ -79,7 +79,7 @@ async function cookRbd(ctx, stack) {
|
|
|
79
79
|
const statics = ctx.hasInput(1) ? staticMesh(ctx.input(1), notes) : null;
|
|
80
80
|
for (const m of notes)
|
|
81
81
|
ctx.warn(m);
|
|
82
|
-
// auto: the ground plane stands in for a collision input that is not connected (
|
|
82
|
+
// auto: the ground plane stands in for a collision input that is not connected (it was also added when the
|
|
83
83
|
// input was connected but had no triangles, unlike the param says)
|
|
84
84
|
const ground = p.ground_plane === 'on' || (p.ground_plane === 'auto' && !ctx.hasInput(1)) ? Number(p.ground) : null;
|
|
85
85
|
if (ctx.hasInput(1) && !statics && ground === null)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Scene output nodes: scene_null adds a named scene empty (an attachment socket) that exports as a meshless node.
|
|
2
|
+
// Contract: core/scene.ts.
|
|
3
|
+
import { Geometry } from '../core/geometry.js';
|
|
4
|
+
import { m4trs, qFromMat } from '../core/math.js';
|
|
5
|
+
import { emptyGeometry } from '../core/scene.js';
|
|
6
|
+
import { defineNode } from '../graph/registry.js';
|
|
7
|
+
import { NodeError } from '../graph/types.js';
|
|
8
|
+
defineNode({
|
|
9
|
+
type: 'scene_null',
|
|
10
|
+
category: 'io',
|
|
11
|
+
packed: 'keep',
|
|
12
|
+
summary: 'Add a named scene empty (attachment socket): a meshless node in glTF export, parented to the root, another empty or a mesh.',
|
|
13
|
+
description: 'Houdini: a Null object; Blender/Unreal: an Empty / socket. Adds one isolated point marked scene_empty = 1 with point ' +
|
|
14
|
+
'attributes name, parent, orient and scale (help topic "export"). translation, rotation and scale are in geometry ' +
|
|
15
|
+
'(model) space, so later transform nodes move the empty with the mesh; glTF export writes it as a node without a ' +
|
|
16
|
+
'mesh under its parent with the local transform that keeps this geometry-space placement. parent names another ' +
|
|
17
|
+
'empty or a mesh (the prim "name" of the pieces export splits by); missing, ambiguous and cyclic parents are export ' +
|
|
18
|
+
'errors. Other point attributes set on the empty (e.g. a "forward" vector) export as node extras. Ordinary loose ' +
|
|
19
|
+
'points still export as POINTS.',
|
|
20
|
+
aliases: ['null_object', 'empty', 'socket', 'locator', 'scene_empty', 'attachment_point'],
|
|
21
|
+
inputs: [{ name: 'geo', desc: 'geometry to add the empty to (optional)', optional: true }],
|
|
22
|
+
params: {
|
|
23
|
+
name: { type: 'string', default: 'socket', desc: 'node name of the empty (unique when something parents to it)', aliases: ['node_name', 'socket_name'] },
|
|
24
|
+
parent: { type: 'string', default: '', desc: 'parent: "" = scene root, else the name of another empty or of a mesh (prim "name")', aliases: ['parent_name', 'attach_to'] },
|
|
25
|
+
translation: { type: 'vec3', default: [0, 0, 0], desc: 'position in geometry (model) space, metres', aliases: ['translate', 't', 'position'] },
|
|
26
|
+
rotation: { type: 'vec3', default: [0, 0, 0], desc: 'rotation in geometry space, degrees (x, then y, then z)', aliases: ['rotate', 'r'] },
|
|
27
|
+
scale: { type: 'vec3', default: [1, 1, 1], desc: 'scale', aliases: ['s'] },
|
|
28
|
+
},
|
|
29
|
+
outputs: 'the input plus one point: scene_empty 1, name, parent, orient, scale',
|
|
30
|
+
example: {
|
|
31
|
+
nodes: {
|
|
32
|
+
body: { type: 'box', params: { size: [0.12, 0.2, 0.12] } },
|
|
33
|
+
named: { type: 'attrib_create', in: ['body'], params: { name: 'name', class: 'prim', value: 'housing' } },
|
|
34
|
+
wick: { type: 'scene_null', in: ['named'], params: { name: 'wick', parent: 'housing', translation: [0, -0.05, 0] } },
|
|
35
|
+
flame: { type: 'scene_null', in: ['wick'], params: { name: 'flame', parent: 'wick', translation: [0, -0.03, 0], rotation: [0, 45, 0] } },
|
|
36
|
+
},
|
|
37
|
+
output: 'flame',
|
|
38
|
+
},
|
|
39
|
+
cook: (ctx) => {
|
|
40
|
+
const { p } = ctx;
|
|
41
|
+
const name = String(p.name ?? '').trim(), parent = String(p.parent ?? '').trim();
|
|
42
|
+
if (!name)
|
|
43
|
+
throw new NodeError('scene_null: name is empty', 'give the empty a name, e.g. "handle"');
|
|
44
|
+
if (parent === name)
|
|
45
|
+
throw new NodeError(`scene_null: "${name}" cannot be its own parent`, 'use "" for the scene root or name another empty or mesh');
|
|
46
|
+
const s = p.scale;
|
|
47
|
+
if (!s.every((x) => Number.isFinite(x) && x !== 0))
|
|
48
|
+
throw new NodeError(`scene_null: scale (${s.join(', ')}) needs finite, non-zero components`, 'a zero scale cannot be inverted for children');
|
|
49
|
+
const q = qFromMat(m4trs([0, 0, 0], p.rotation, [1, 1, 1]));
|
|
50
|
+
const e = emptyGeometry(name, parent, p.translation, q, s);
|
|
51
|
+
return ctx.hasInput(0) ? Geometry.merge([ctx.input(0), e]) : e;
|
|
52
|
+
},
|
|
53
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// solidify (shell): constant-thickness walls from a polygon surface. Algorithm and rejection rules: core/solidify.ts.
|
|
2
|
+
import { SolidifyError, solidify } from '../core/solidify.js';
|
|
3
|
+
import { defineNode } from '../graph/registry.js';
|
|
4
|
+
import { NodeError } from '../graph/types.js';
|
|
5
|
+
defineNode({
|
|
6
|
+
type: 'solidify',
|
|
7
|
+
category: 'topology',
|
|
8
|
+
summary: 'Give a consistently wound polygon surface a constant wall thickness (inside, centred or outside), with rim faces; invalid results are errors, never repaired.',
|
|
9
|
+
description: 'Blender: Solidify (complex mode); Houdini: PolyExtrude with output back + side, or Thicken. Select the intended ' +
|
|
10
|
+
'surface upstream. Every point moves along the mitre of its faces\' offset planes, so each face of both surface copies ' +
|
|
11
|
+
'is exactly its share of thickness away from the original: folds keep their full wall (mitred corners), open ' +
|
|
12
|
+
'boundaries get rim faces. offset -1 grows the wall behind the surface (against the face normal; the input stays the ' +
|
|
13
|
+
'outer face), 0 centres it, +1 grows it outward (the input becomes the inner face). Groups outer, inner, rim; ' +
|
|
14
|
+
'attributes follow their source elements; uv is copied to both surfaces and the rim gets metric uv (u along the ' +
|
|
15
|
+
'boundary, v across the thickness); N and tangent are dropped (recompute downstream). Errors instead of a broken ' +
|
|
16
|
+
'shell: polylines, non-manifold edges or points, inconsistent winding, collapsed faces, mitres longer than ' +
|
|
17
|
+
'miter_limit × thickness, corners whose offset planes do not meet (saddles, twists), surface copies that turn inside ' +
|
|
18
|
+
'out, and any self-intersection of the result (crossings, coplanar overlaps, contacts beyond shared edges). Use ' +
|
|
19
|
+
'poly_extrude for per-face extrusion and sdf shells for organic thickening.',
|
|
20
|
+
aliases: ['shell', 'thicken', 'solidify_surface', 'wall_thickness'],
|
|
21
|
+
inputs: [{ name: 'geo', desc: 'a polygon surface with consistent winding (a sheet, a folded panel or a closed hull)' }],
|
|
22
|
+
params: {
|
|
23
|
+
thickness: { type: 'float', default: 0.01, min: 0, desc: 'wall thickness in metres (must be positive)', aliases: ['thick', 'width', 'depth'] },
|
|
24
|
+
offset: { type: 'float', default: 0, min: -1, max: 1, desc: 'where the wall grows relative to the face winding: -1 inside (behind the normal), 0 centred, +1 outside', aliases: ['bias', 'side'] },
|
|
25
|
+
fill_rim: { type: 'bool', default: true, desc: 'close open boundaries with rim faces (off: two separate surfaces)', aliases: ['rim', 'cap_rim', 'fill'] },
|
|
26
|
+
miter_limit: { type: 'float', default: 4, min: 1, desc: 'largest allowed point offset as a multiple of the thickness at folds (4 ≈ folds up to 150°)', aliases: ['mitre_limit', 'miter'] },
|
|
27
|
+
},
|
|
28
|
+
outputs: 'the shell: prim groups outer, inner, rim',
|
|
29
|
+
example: {
|
|
30
|
+
nodes: {
|
|
31
|
+
panel: { type: 'grid', params: { size: [0.4, 0.3], rows: 3, cols: 4 } },
|
|
32
|
+
fold: { type: 'wrangle', in: ['panel'], params: { snippet: 'if (@P.x > 0.05) { @P.y = @P.x - 0.05; @P.x = 0.05; }' } },
|
|
33
|
+
wall: { type: 'solidify', in: ['fold'], params: { thickness: 0.01, offset: -1 } },
|
|
34
|
+
},
|
|
35
|
+
output: 'wall',
|
|
36
|
+
},
|
|
37
|
+
cook: (ctx) => {
|
|
38
|
+
const { p } = ctx;
|
|
39
|
+
try {
|
|
40
|
+
const r = solidify(ctx.input(0), { thickness: p.thickness, offset: p.offset, fillRim: p.fill_rim, miterLimit: p.miter_limit });
|
|
41
|
+
ctx.stat('rim_faces', r.stats.rim);
|
|
42
|
+
ctx.stat('max_miter', +r.stats.maxMiter.toFixed(4));
|
|
43
|
+
ctx.stat('max_residual', +r.stats.maxResidual.toExponential(2));
|
|
44
|
+
return r.geo;
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
if (e instanceof SolidifyError)
|
|
48
|
+
throw new NodeError(e.message, e.hint);
|
|
49
|
+
throw e;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
});
|
package/dist/nodes/transform.js
CHANGED
|
@@ -12,7 +12,8 @@ import { transformSdfGrid } from '../core/sdfgrid.js';
|
|
|
12
12
|
import { AXES, P, getPointNormals, mask } from './util.js';
|
|
13
13
|
import { evalRamp } from '../graph/params.js';
|
|
14
14
|
import { andThen } from '../graph/parallel.js';
|
|
15
|
-
import { composePackedXforms } from '../core/packed.js';
|
|
15
|
+
import { composePackedXforms, xform3 } from '../core/packed.js';
|
|
16
|
+
import { TANGENT_ATTRIB, transformTangents } from '../core/tangents.js';
|
|
16
17
|
/**
|
|
17
18
|
* Apply a matrix to positions and vector-like attributes of selected points. Packed prims move with their anchor
|
|
18
19
|
* point and compose the matrix's rotation/scale into their transform.
|
|
@@ -72,6 +73,9 @@ export function applyMatrix(src, m, ptMask = null) {
|
|
|
72
73
|
d.set(q, i * 4);
|
|
73
74
|
}
|
|
74
75
|
}
|
|
76
|
+
else if (name === TANGENT_ATTRIB && a.size === 4 && cls !== 'prim') {
|
|
77
|
+
transformTangents(d, t.count, xform3(m), sel);
|
|
78
|
+
}
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
81
|
// volumes first: a mirroring matrix used to return before them, leaving SDFs and heightfields untransformed
|
package/dist/nodes/util.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare function emptyIfNone(g: Geometry | null): Geometry;
|
|
|
43
43
|
/** Build a polyline/polygon geometry from point lists. */
|
|
44
44
|
export declare function polyGeo(curves: number[][][], closed: boolean | boolean[]): Geometry;
|
|
45
45
|
/**
|
|
46
|
-
* The wall-clock budget of one cook of a long-running node (engine.simTimeoutMs from now;
|
|
46
|
+
* The wall-clock budget of one cook of a long-running node (engine.simTimeoutMs from now; a simulation had
|
|
47
47
|
* no time limit, so large but valid params could keep an MCP server busy for hours). `check()` throws a NodeError that
|
|
48
48
|
* names the node once the budget is spent (call it between steps, batches or iterations); `left()` is what remains, for
|
|
49
49
|
* the limit of a pool task that runs work which cannot be stopped from here (a WASM call).
|
package/dist/nodes/wasmcall.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Long WASM kernel calls under a node's time limit
|
|
1
|
+
// Long WASM kernel calls under a node's time limit. remesh_quad and the kernel backend of
|
|
2
2
|
// heightfield_erode run one call into the Rust/WASM kernels (src/wasm/kernels.ts) that nothing on its own thread can
|
|
3
3
|
// stop. When the host has a worker pool and the call is big, it runs on a pool worker instead, as the task "wasm"
|
|
4
4
|
// (src/host/worker.ts) with the rest of the node's time limit as the task's limit: a call that runs too long is stopped
|
package/dist/render/options.js
CHANGED
|
@@ -29,7 +29,7 @@ export function renderArgs(a) {
|
|
|
29
29
|
o.views = parseViews(a.views);
|
|
30
30
|
for (const [s, c] of [['size', 'size'], ['azimuth', 'azimuth'], ['elevation', 'elevation'], ['zoom', 'zoom'], ['hard_angle', 'hardAngle'], ['max_labels', 'maxLabels'],
|
|
31
31
|
['glyph_scale', 'glyphScale'], ['max_glyphs', 'maxGlyphs'], ['ao_radius', 'aoRadius'], ['ortho_scale', 'orthoScale'], ['scale', 'scale'], ['ssaa', 'ssaa'],
|
|
32
|
-
['max_triangles', 'maxTriangles']]) {
|
|
32
|
+
['max_triangles', 'maxTriangles'], ['exposure', 'exposure']]) {
|
|
33
33
|
const v = pick(s, c);
|
|
34
34
|
if (v !== undefined)
|
|
35
35
|
o[c] = num(v, s);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Geometry } from '../core/geometry.ts';
|
|
2
|
+
import { Image } from '../core/image.ts';
|
|
3
|
+
/** External texture files read for a PBR render: path → image, or the reason it is not available. */
|
|
4
|
+
export type PBRTextures = Map<string, Image | string>;
|
|
5
|
+
/** The normals the exporter writes by default (60° cusp): the frame the normal map and TANGENT belong to. */
|
|
6
|
+
export declare const PBR_CUSP = 60;
|
|
7
|
+
/**
|
|
8
|
+
* Asynchronous preparation for shading "pbr": loads MikkTSpace and reads every texture file the material tables name
|
|
9
|
+
* (image volumes need no reading) through readFile, usually Host.readFile.
|
|
10
|
+
*/
|
|
11
|
+
export declare function preparePBR(g: Geometry, readFile?: (path: string) => Promise<Uint8Array>): Promise<PBRTextures>;
|
|
12
|
+
/** Per-triangle data and the per-pixel shader for one render. */
|
|
13
|
+
export interface PBRScene {
|
|
14
|
+
/** materials evaluated, maps used, problems: footer and notes */
|
|
15
|
+
summary: string;
|
|
16
|
+
/** shade a pixel; writes display RGB (0..1) into out */
|
|
17
|
+
shade(t: number, w0: number, w1: number, w2: number, dudx: number, dvdx: number, dudy: number, dvdy: number, view: number[], back: boolean, out: number[]): void;
|
|
18
|
+
/** uv of triangle t at (perspective-correct) weights, for the derivatives */
|
|
19
|
+
uvAt(t: number, w0: number, w1: number, w2: number, out: number[]): void;
|
|
20
|
+
hasUV: boolean;
|
|
21
|
+
/** place the camera-relative light rig for a view (camera right, up, forward in world space) */
|
|
22
|
+
camera(r: number[], u: number[], f: number[]): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Build the shading data for g's triangles (tris / triPrim from topology.triangulate). Synchronous: MikkTSpace must be
|
|
26
|
+
* loaded (preparePBR or loadMikkTSpace) and external textures read into `files`; notes receive what is not evaluated.
|
|
27
|
+
*/
|
|
28
|
+
export declare function pbrScene(g: Geometry, tris: Uint32Array, triPrim: Uint32Array, files: PBRTextures | undefined, exposure: number, notes: string[]): PBRScene;
|