topotopo 0.5.1 → 0.5.3

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.
Files changed (41) hide show
  1. package/dist/cli.js +42 -18
  2. package/dist/core/manifold.d.ts +11 -2
  3. package/dist/core/manifold.js +7 -4
  4. package/dist/core/materials.d.ts +3 -2
  5. package/dist/core/materials.js +3 -2
  6. package/dist/core/tangents.d.ts +11 -1
  7. package/dist/core/tangents.js +87 -14
  8. package/dist/core/texture.d.ts +1 -1
  9. package/dist/core/texture.js +12 -3
  10. package/dist/core/topology.d.ts +5 -1
  11. package/dist/core/topology.js +35 -4
  12. package/dist/graph/engine.d.ts +7 -0
  13. package/dist/graph/engine.js +54 -6
  14. package/dist/io/gltf.js +8 -7
  15. package/dist/io/source.d.ts +2 -0
  16. package/dist/io/source.js +10 -1
  17. package/dist/mcp/docs.js +35 -8
  18. package/dist/mcp/tools.js +35 -10
  19. package/dist/nodes/attributes.js +12 -3
  20. package/dist/nodes/bake.js +2 -2
  21. package/dist/nodes/curves.js +7 -7
  22. package/dist/nodes/material.js +3 -3
  23. package/dist/nodes/solid.js +42 -15
  24. package/dist/nodes/texture.js +16 -9
  25. package/dist/nodes/topology.js +3 -2
  26. package/dist/packages/registry.d.ts +21 -8
  27. package/dist/packages/registry.js +57 -24
  28. package/dist/render/options.js +9 -1
  29. package/dist/render/pbr.d.ts +22 -2
  30. package/dist/render/pbr.js +113 -38
  31. package/dist/render/preview.d.ts +2 -0
  32. package/dist/render/raster.d.ts +13 -1
  33. package/dist/render/raster.js +112 -19
  34. package/dist/session.d.ts +25 -6
  35. package/dist/session.js +98 -43
  36. package/dist/viewer/app/api.js +5 -2
  37. package/dist/viewer/app/cooking.js +9 -3
  38. package/dist/viewer/app/main.js +18 -4
  39. package/dist/viewer/server.js +20 -3
  40. package/integrations/godot/addons/topotopo/plugin.cfg +1 -1
  41. package/package.json +3 -3
@@ -185,7 +185,7 @@ defineNode({
185
185
  'bricks with depth). grid is the opposite, a line mask: 1 on the lines (gap is their width), 0 inside the cells, so ' +
186
186
  'multiplying a material by it darkens all but the lines; for cells separated by grooves use tiles (grid is 1 - tiles ' +
187
187
  'without variation). checker alternates 1 and 0. Layer "id" holds a random 0..1 per cell (tex_colorize it with layer ' +
188
- '"id" for per-brick colour). count = cells along u (columns) and v (rows); bricks and dots shift every other row by ' +
188
+ '"id" for per-brick colour). count = cells along u (columns) and v (rows); stripes are vertical (u count), and with a u count of 1 the v count makes horizontal stripes; bricks and dots shift every other row by ' +
189
189
  'offset (keep the row count even for seamless tiling); hex uses offset for its staggered rows. gap and bevel are ' +
190
190
  'fractions of the smaller cell side; variation darkens cells randomly.',
191
191
  aliases: ['tile_generator', 'bricks', 'brick', 'checker', 'tiles_pattern', 'cop_pattern'],
@@ -551,7 +551,7 @@ defineNode({
551
551
  params: {
552
552
  resolution: resolutionParam(),
553
553
  style: { type: 'enum', options: GRUNGE_STYLES, default: 'dirt', desc: 'dirt patches, vertical leaks or round spots', aliases: ['type', 'mode'] },
554
- scale: { type: 'float', default: 4, min: 0.1, max: 256, desc: 'features across the image width', aliases: ['frequency'] },
554
+ scale: { type: 'float', default: 4, min: 0.1, max: 256, desc: 'features across the image width (1 to 256: larger values are clamped to 256)', aliases: ['frequency'] },
555
555
  coverage: { type: 'float', default: 0.35, min: 0, max: 1, desc: 'fraction of the image that turns white', aliases: ['amount', 'density'] },
556
556
  contrast: { type: 'float', default: 0.6, min: 0, max: 1, desc: 'edge hardness (1 = hard)', aliases: ['hardness'] },
557
557
  detail: { type: 'float', default: 0.4, min: 0, max: 1, desc: 'fine breakup mixed in (0 = smooth shapes)', aliases: ['breakup'] },
@@ -891,14 +891,14 @@ defineNode({
891
891
  usesNodeName: NAMED_BY_NODE,
892
892
  category: 'texture',
893
893
  summary: 'Offset, rotate, scale and tile an image (2D transform with wrap).',
894
- description: 'Substance: Transformation 2D; Houdini COP: Transform. The content is repeated `tile` times, scaled by `scale` (> 1 enlarges), rotated about the centre and shifted by offset (uv). With tileable the source repeats, else the outside is 0. Whole-number tiling and offsets keep a tileable image tileable; other rotations generally do not.',
894
+ description: 'Substance: Transformation 2D; Houdini COP: Transform. The content is repeated `tile` times, scaled by `scale` (> 1 enlarges), rotated about the centre and shifted by offset (uv); tiling is about the lower-left corner, so cell 0 starts at uv (0, 0) and offset 0 keeps the cells aligned with the image edges. With tileable the source repeats, else the outside is 0. Whole-number tiling and offsets keep a tileable image tileable; other rotations generally do not.',
895
895
  aliases: ['transform_texture', 'transformation_2d', 'offset_texture', 'tile_texture', 'cop_transform'],
896
896
  inputs: FILTER_INPUT,
897
897
  params: {
898
898
  offset: { type: 'vec2', default: [0, 0], desc: 'shift in uv (0.5 = half the image)', aliases: ['translate', 't'] },
899
899
  rotate: { type: 'float', default: 0, desc: 'rotation in degrees (counter-clockwise)', aliases: ['rotation', 'r', 'angle'] },
900
900
  scale: { type: 'vec2', default: [1, 1], desc: 'zoom (> 1 enlarges the content)', aliases: ['s', 'zoom'] },
901
- tile: { type: 'vec2', default: [1, 1], min: 0.001, desc: 'repeats of the content along u and v', aliases: ['tiling', 'repeat'] },
901
+ tile: { type: 'vec2', default: [1, 1], min: 0.001, desc: 'repeats of the content along u and v; cells start at the lower-left corner (uv 0, 0), so [1, 2] gives two stacked cells, each the whole image', aliases: ['tiling', 'repeat'] },
902
902
  tileable: tileParam('repeat the source outside 0..1 (else black)'),
903
903
  image: imageParam(), layer: layerParam(), name: renameParam(),
904
904
  },
@@ -2078,8 +2078,8 @@ defineNode({
2078
2078
  orm: { type: 'string', default: '', desc: 'packed occlusion / roughness / metallic image (R, G, B)', aliases: ['orm_map', 'packed'] },
2079
2079
  group: P.group('prim', 'prims that get the material ("" = all prims when the material is new, else none)'),
2080
2080
  base_color_tint: { type: 'color', default: [1, 1, 1], desc: 'base colour factor of a new material (glTF writes white under a base colour map)', aliases: ['tint'] },
2081
- roughness_value: { type: 'float', default: 0.8, min: 0, max: 1, desc: 'roughness of a new material (the ORM green channel when no roughness image is given)' },
2082
- metallic_value: { type: 'float', default: 0, min: 0, max: 1, desc: 'metallic of a new material (the ORM blue channel when no metallic image is given)' },
2081
+ roughness_value: { type: 'float', default: -1, min: -1, max: 1, desc: 'roughness. -1 = unset: 0.8 for a new material; with an orm map the glTF roughnessFactor is 1 (a material on input 0 does not set it). A value is the roughnessFactor that multiplies the ORM green channel; for occlusion / metallic images packed here it fills the green channel when no roughness image is given' },
2082
+ metallic_value: { type: 'float', default: -1, min: -1, max: 1, desc: 'metallic. -1 = unset: 0 for a new material; with an orm map the glTF metallicFactor is 1 (a material on input 0 does not set it). A value is the metallicFactor that multiplies the ORM blue channel; for occlusion / metallic images packed here it fills the blue channel when no metallic image is given' },
2083
2083
  },
2084
2084
  outputs: 'prim "material", detail "materials" with image:<name> texture slots, the referenced images as image volumes',
2085
2085
  example: {
@@ -2128,7 +2128,8 @@ defineNode({
2128
2128
  };
2129
2129
  const table = readMaterials(g);
2130
2130
  const isNew = !table[mat];
2131
- const entry = normalizeMaterial(table[mat] ?? { baseColor: p.base_color_tint, roughness: p.roughness_value, metallic: p.metallic_value });
2131
+ const rv = Number(p.roughness_value) >= 0 ? Number(p.roughness_value) : null, mv = Number(p.metallic_value) >= 0 ? Number(p.metallic_value) : null;
2132
+ let entry = normalizeMaterial(table[mat] ?? { baseColor: p.base_color_tint, roughness: rv ?? 0.8, metallic: mv ?? 0 });
2132
2133
  const tex = { ...(entry.textures ?? {}) };
2133
2134
  const used = [];
2134
2135
  for (const [param, slot] of SLOTS) {
@@ -2154,14 +2155,20 @@ defineNode({
2154
2155
  const out = new Float32Array(n * 4);
2155
2156
  for (let i = 0; i < n; i++) {
2156
2157
  out[i * 4] = O ? O[i] : 1;
2157
- out[i * 4 + 1] = R ? R[i] : entry.roughness;
2158
- out[i * 4 + 2] = M ? M[i] : entry.metallic;
2158
+ out[i * 4 + 1] = R ? R[i] : rv ?? entry.roughness;
2159
+ out[i * 4 + 2] = M ? M[i] : mv ?? entry.metallic;
2159
2160
  out[i * 4 + 3] = 1;
2160
2161
  }
2161
2162
  const orm = new Image(w, h, `${mat}_orm`).set(MAIN_LAYER, out);
2162
2163
  used.push(orm);
2163
2164
  tex.orm = `image:${orm.name}`;
2164
2165
  delete tex.roughness;
2166
+ // the values are baked into the map: the factors that multiply it stay 1
2167
+ entry = { ...entry, roughness: 1, metallic: 1 };
2168
+ }
2169
+ else if (tex.orm) {
2170
+ // glTF semantics: the factors multiply the ORM map, so they default to 1; the input material's scalars do not apply
2171
+ entry = { ...entry, roughness: rv ?? 1, metallic: mv ?? 1 };
2165
2172
  }
2166
2173
  if (!used.length)
2167
2174
  ctx.warn(`${type}: no image named in any slot (base_color, normal, roughness, metallic, occlusion, orm)`);
@@ -1356,9 +1356,10 @@ defineNode({
1356
1356
  defineNode({
1357
1357
  type: 'grid_split',
1358
1358
  category: 'topology',
1359
- summary: 'Split quads into a grid of cells by target size (facades → window cells) or fixed counts. Shared edges stay welded.',
1359
+ summary: 'Split quads into a grid of cells by target size (facades → window cells) or fixed counts. Shared edges stay welded. Only quads are split: cut first, then split.',
1360
+ description: 'Only 4-sided polygons are divided; triangles and n-gons pass through unsplit. After a boolean the faces around the cut are often n-gons, so they stay whole: run grid_split on the quads BEFORE the cut (or triangulate the n-gons first), not after it.',
1360
1361
  aliases: ['divide_quads', 'facade_split', 'quad_split', 'split_faces'],
1361
- inputs: [{ name: 'geo', desc: 'polygon mesh (quads are split; other polygons pass through)' }],
1362
+ inputs: [{ name: 'geo', desc: 'polygon mesh (quads are split; triangles and n-gons pass through unsplit)' }],
1362
1363
  params: {
1363
1364
  group: P.group('prim', 'quads to split ("" = all)'),
1364
1365
  mode: { type: 'enum', options: ['size', 'count'], default: 'size', desc: 'size = divide each edge by length / target size; count = fixed divisions' },
@@ -318,22 +318,35 @@ export declare class PackageUses implements SessionPackages {
318
318
  uses(): Record<string, string>;
319
319
  /**
320
320
  * What exports and publishing resolve package names with: the published copies, whatever this session follows
321
- * (following a working folder is for looking: the viewer, renders). The package's own resolver while nothing is
322
- * followed.
321
+ * (following a working folder is for looking: the viewer, renders), but for the followed packages in `follow` (an
322
+ * export told to use their working folders). The package's own resolver while every followed package is in it.
323
323
  */
324
- publishedResolver(): PackageResolver;
324
+ publishedResolver(follow?: readonly string[]): PackageResolver;
325
+ /** The followed packages among `follow`, sorted. */
326
+ private kept;
325
327
  private publishedAt;
326
328
  /**
327
329
  * SessionPackages.published: while this session follows working folders, the scope exports cook in, like the root
328
- * (its assets, graphs and folder) but resolving packages to their published copies; null while nothing is followed
329
- * (exports cook in the root, as everything else).
330
+ * (its assets, graphs and folder) but resolving packages to their published copies, the followed packages in `follow`
331
+ * to their working folders; null while every followed package is in `follow` (or nothing is followed): exports then
332
+ * cook in the root, as everything else.
330
333
  */
331
- published(): Scope | null;
334
+ published(follow?: readonly string[]): Scope | null;
335
+ /**
336
+ * SessionPackages.unpublished: the followed packages `graph` names that an export would cook from published copies
337
+ * (those not in `follow`) while the package uses no published version of them: such an export cannot cook, and is
338
+ * refused, saying to publish them or to export from their working folders.
339
+ */
340
+ unpublished(graph: GraphSpec, follow?: readonly string[]): {
341
+ package: string;
342
+ dir: string;
343
+ }[];
332
344
  /**
333
345
  * What an export of `graph` made while following says (null when the graph names no followed package): the
334
- * published versions it used, the working folders being for looking only.
346
+ * working folders it used (those in `follow`: no published version, which its source record states under
347
+ * "followed"), and the published versions it used for the others, their working folders being for looking only.
335
348
  */
336
- publishedNote(graph: GraphSpec): string | null;
349
+ publishedNote(graph: GraphSpec, follow?: readonly string[]): string | null;
337
350
  /** SessionPackages: why the graphs cannot use packages (a folder in no package, a manifest that is not valid). */
338
351
  notice(): string | null;
339
352
  /** Load afresh, when next named, the copies that could not load or loaded with a warning (edited by hand). */
@@ -694,6 +694,8 @@ export function gatherCopies(ws) {
694
694
  return out;
695
695
  });
696
696
  }
697
+ /** Whether a context resolves `pkg` to its working folder, when the session follows it. */
698
+ const followsIn = (ctx, pkg) => ctx.follows === true || (ctx.follows !== false && ctx.follows.has(pkg));
697
699
  /**
698
700
  * The packages of TopoTopo's built-in library at `dir`: topotopo/<name> for each folder <name> with versions/, a working
699
701
  * folder too where it holds that package's manifest (in TopoTopo's repository). Sorted by name.
@@ -907,40 +909,69 @@ export class PackageUses {
907
909
  uses() { return this.root.uses; }
908
910
  /**
909
911
  * What exports and publishing resolve package names with: the published copies, whatever this session follows
910
- * (following a working folder is for looking: the viewer, renders). The package's own resolver while nothing is
911
- * followed.
912
+ * (following a working folder is for looking: the viewer, renders), but for the followed packages in `follow` (an
913
+ * export told to use their working folders). The package's own resolver while every followed package is in it.
912
914
  */
913
- publishedResolver() {
914
- if (!this.followed.size)
915
+ publishedResolver(follow = []) {
916
+ const kept = this.kept(follow);
917
+ if (kept.length === this.followed.size)
915
918
  return this.resolver;
916
- return { resolve: (name) => this.resolveIn({ ...this.root, follows: false }, name), names: () => this.namesIn({ ...this.root, follows: false }) };
919
+ // the root as it is when asked (its uses change with use and update)
920
+ const follows = kept.length ? new Set(kept) : false, ctx = () => ({ ...this.root, follows });
921
+ return { resolve: (name) => this.resolveIn(ctx(), name), names: () => this.namesIn(ctx()) };
917
922
  }
918
- publishedAt = null;
923
+ /** The followed packages among `follow`, sorted. */
924
+ kept(follow) { return [...new Set(follow)].filter((p) => this.followed.has(p)).sort(); }
925
+ publishedAt = new Map();
919
926
  /**
920
927
  * SessionPackages.published: while this session follows working folders, the scope exports cook in, like the root
921
- * (its assets, graphs and folder) but resolving packages to their published copies; null while nothing is followed
922
- * (exports cook in the root, as everything else).
928
+ * (its assets, graphs and folder) but resolving packages to their published copies, the followed packages in `follow`
929
+ * to their working folders; null while every followed package is in `follow` (or nothing is followed): exports then
930
+ * cook in the root, as everything else.
923
931
  */
924
- published() {
925
- if (!this.followed.size)
932
+ published(follow = []) {
933
+ const kept = this.kept(follow);
934
+ if (kept.length === this.followed.size)
926
935
  return null;
936
+ const key = kept.join(','), have = this.publishedAt.get(key);
937
+ if (have)
938
+ return have;
927
939
  const root = this.engine.root;
928
- this.publishedAt ??= this.engine.createScope(`published copies ${sha(this.dir ?? '').slice(0, 12)}`, {
929
- folder: root.files.resolvePath('.'), assets: root.assets, graphs: (n) => root.graphs?.(n), packages: this.publishedResolver(),
940
+ const scope = this.engine.createScope(`published copies ${sha(`${this.dir ?? ''}|${key}`).slice(0, 12)}`, {
941
+ folder: root.files.resolvePath('.'), assets: root.assets, graphs: (n) => root.graphs?.(n), packages: this.publishedResolver(kept),
930
942
  });
931
- return this.publishedAt;
943
+ this.publishedAt.set(key, scope);
944
+ return scope;
945
+ }
946
+ /**
947
+ * SessionPackages.unpublished: the followed packages `graph` names that an export would cook from published copies
948
+ * (those not in `follow`) while the package uses no published version of them: such an export cannot cook, and is
949
+ * refused, saying to publish them or to export from their working folders.
950
+ */
951
+ unpublished(graph, follow = []) {
952
+ const named = new Set(packagesNamedIn(graph)), kept = new Set(follow);
953
+ return [...this.followed.values()].filter((f) => named.has(f.package) && !kept.has(f.package) && this.root.uses[f.package] === undefined)
954
+ .map((f) => ({ package: f.package, dir: f.dir }));
932
955
  }
933
956
  /**
934
957
  * What an export of `graph` made while following says (null when the graph names no followed package): the
935
- * published versions it used, the working folders being for looking only.
958
+ * working folders it used (those in `follow`: no published version, which its source record states under
959
+ * "followed"), and the published versions it used for the others, their working folders being for looking only.
936
960
  */
937
- publishedNote(graph) {
938
- const named = new Set(packagesNamedIn(graph));
961
+ publishedNote(graph, follow = []) {
962
+ const named = new Set(packagesNamedIn(graph)), kept = new Set(this.kept(follow));
939
963
  const live = [...this.followed.values()].filter((f) => named.has(f.package));
940
964
  if (!live.length)
941
965
  return null;
942
- const used = live.map((f) => (this.root.uses[f.package] ? `${f.package} ${this.root.uses[f.package]}` : `${f.package} (no published version in use: publish one, and use it)`));
943
- return `this session shows ${live.map((f) => f.package).join(', ')} live from ${live.length === 1 ? 'its working folder' : 'their working folders'}, for looking; the export used the published ${used.join(', ')}`;
966
+ const working = live.filter((f) => kept.has(f.package)), shown = live.filter((f) => !kept.has(f.package));
967
+ const notes = [];
968
+ if (working.length)
969
+ notes.push(`the export used the working folder of ${working.map((f) => f.package).join(', ')}, not a published version: its source record lists ${working.length === 1 ? 'it' : 'them'} under "followed"`);
970
+ if (shown.length) {
971
+ const used = shown.map((f) => (this.root.uses[f.package] ? `${f.package} ${this.root.uses[f.package]}` : `${f.package} (no published version in use: publish one, and use it)`));
972
+ notes.push(`this session shows ${shown.map((f) => f.package).join(', ')} live from ${shown.length === 1 ? 'its working folder' : 'their working folders'}, for looking; the export used the published ${used.join(', ')}`);
973
+ }
974
+ return notes.join('\n');
944
975
  }
945
976
  /** SessionPackages: why the graphs cannot use packages (a folder in no package, a manifest that is not valid). */
946
977
  notice() {
@@ -1078,8 +1109,8 @@ export class PackageUses {
1078
1109
  }
1079
1110
  namesIn(ctx) {
1080
1111
  const pkgs = new Set(Object.keys(ctx.uses));
1081
- if (ctx.follows)
1082
- for (const k of this.followed.keys())
1112
+ for (const k of this.followed.keys())
1113
+ if (followsIn(ctx, k))
1083
1114
  pkgs.add(k);
1084
1115
  if (ctx.self)
1085
1116
  pkgs.add(ctx.self.package);
@@ -1099,7 +1130,7 @@ export class PackageUses {
1099
1130
  // the package's own outputs: the same version (or working folder), with no entry in its uses
1100
1131
  if (ctx.self?.package === pkg)
1101
1132
  return ctx.self.get();
1102
- if (ctx.follows && this.followed.has(pkg))
1133
+ if (this.followed.has(pkg) && followsIn(ctx, pkg))
1103
1134
  return this.loadFollowed(pkg);
1104
1135
  const v = ctx.uses[pkg];
1105
1136
  if (v !== undefined)
@@ -1391,7 +1422,9 @@ export class PackageUses {
1391
1422
  */
1392
1423
  locked(graph) {
1393
1424
  const adds = this.dryRun(graph).adds.map((a) => `the graph names ${a.package}, which ${this.usesFileName} does not use: ${program()} use ${a.package} adds it (a cook without --locked adds it)`);
1394
- return [...adds, ...(this.dir && this.manifest ? this.verifyCopies() : [])];
1425
+ // a working folder followed for this run is no version: a build machine cooks published versions alone
1426
+ const working = this.unpublished(graph).map((u) => `the graph names ${u.package}, which ${this.usesFileName} does not use, and its working folder (followed) is no published version: publish ${u.package} (${program()} publish ${u.dir} --note "...") and use it`);
1427
+ return [...adds, ...working, ...(this.dir && this.manifest ? this.verifyCopies() : [])];
1395
1428
  }
1396
1429
  /** The packages a graph names that the package does not use yet (nor follows, nor is). */
1397
1430
  freshIn(graph) {
@@ -1479,7 +1512,7 @@ export class PackageUses {
1479
1512
  versionToAdd(pkg, v, scanned) {
1480
1513
  const found = this.find(pkg, scanned);
1481
1514
  if (!found.versions.size)
1482
- throw new Error(`${pkg} is in ${found.place} (${found.dir}) but has no published version yet: publish one in its folder (${program()} publish ${found.working ? `${found.dir} ` : ''}--note "...")`);
1515
+ throw new Error(`${pkg} is in ${found.place} (${found.dir}) but has no published version yet: publish one in its folder (${program()} publish ${found.working ? `${found.dir} ` : ''}--note "...")${found.working ? `, or pass --follow ${pkg} to cook and export from its working folder, unpublished (MCP: workspace {action:"follow", package:"${pkg}", on:true}, then export {follow:["${pkg}"]})` : ''}`);
1483
1516
  const version = v ?? newestOf(found.versions.keys());
1484
1517
  const place = found.versions.get(version);
1485
1518
  if (!place)
@@ -1675,7 +1708,7 @@ export class PackageUses {
1675
1708
  this.restamp();
1676
1709
  this.rewatch();
1677
1710
  const v = this.root.uses[pkg];
1678
- return `following ${pkg} for this session: its working folder ${found.dir} (${found.place}) instead of ${v ? `the copy of ${v}` : 'a copy (the package does not use it yet)'}; its edits re-cook, for looking: exports and publishing use the published copy`;
1711
+ return `following ${pkg} for this session: its working folder ${found.dir} (${found.place}) instead of ${v ? `the copy of ${v}` : 'a copy (the package does not use it yet)'}; its edits re-cook, for looking: exports and publishing use the published copy, but an export told to follow it (CLI --follow ${pkg}, MCP export {follow:["${pkg}"]}) exports from the working folder`;
1679
1712
  }
1680
1713
  /**
1681
1714
  * Follow, for this session, every package in use whose one working folder the policy accepts (a
@@ -2,6 +2,7 @@
2
2
  // meta.render and the CLI flags all map to RenderOptions here, so the three stay in sync.
3
3
  // Only keys that are present are set (renderGeometry's defaults apply to the rest).
4
4
  import { UNDERLAY_FITS, parseViews } from './raster.js';
5
+ import { VERTEX_COLOR_MODES } from './pbr.js';
5
6
  const num = (v, key) => {
6
7
  const n = typeof v === 'string' ? Number(v) : v;
7
8
  if (typeof n !== 'number' || !Number.isFinite(n))
@@ -63,7 +64,7 @@ export function renderArgs(a) {
63
64
  o.points = pts === 'auto' ? 'auto' : bool(pts);
64
65
  for (const [s, c] of [['point_numbers', 'pointNumbers'], ['prim_numbers', 'primNumbers'], ['label_groups', 'labelGroups'], ['label_pieces', 'labelPieces'],
65
66
  ['legend', 'legend'], ['checker', 'checker'], ['grid', 'grid'], ['annotate', 'annotate'], ['section_absolute', 'sectionAbsolute'], ['textures', 'textures'], ['view_labels', 'viewLabels'],
66
- ['transparent', 'transparent'], ['sockets', 'sockets'], ['footer', 'footer']]) {
67
+ ['transparent', 'transparent'], ['sockets', 'sockets'], ['footer', 'footer'], ['grey', 'grey']]) {
67
68
  const v = pick(s, c);
68
69
  if (v !== undefined)
69
70
  o[c] = bool(v);
@@ -90,6 +91,13 @@ export function renderArgs(a) {
90
91
  }
91
92
  if (o.underlayOpacity !== undefined && !(o.underlayOpacity >= 0 && o.underlayOpacity <= 1))
92
93
  throw new Error(`render: underlay_opacity expects 0..1, got ${o.underlayOpacity}`);
94
+ // shading pbr: how Cd enters the base colour (cd, or vertexColors in RenderOptions terms)
95
+ const cd = pick('cd', 'vertexColors');
96
+ if (cd !== undefined) {
97
+ if (!VERTEX_COLOR_MODES.includes(cd))
98
+ throw new Error(`render: cd expects ${VERTEX_COLOR_MODES.join(', ')}, got ${JSON.stringify(cd)}`);
99
+ o.vertexColors = cd;
100
+ }
93
101
  const sa = pick('section_axis', 'sectionAxis');
94
102
  if (sa !== undefined)
95
103
  o.sectionAxis = axis(sa, 'section_axis');
@@ -2,6 +2,20 @@ import type { Geometry } from '../core/geometry.ts';
2
2
  import { Image } from '../core/image.ts';
3
3
  /** External texture files read for a PBR render: path → image, or the reason it is not available. */
4
4
  export type PBRTextures = Map<string, Image | string>;
5
+ /**
6
+ * How vertex colour Cd enters the base colour (RenderOptions.vertexColors): 'auto' = the export rule (a named material
7
+ * wins, Cd colours prims without one), 'ignore' = never, 'multiply' = also multiplies a named material's base colour.
8
+ */
9
+ export type VertexColorMode = 'auto' | 'ignore' | 'multiply';
10
+ export declare const VERTEX_COLOR_MODES: VertexColorMode[];
11
+ /** Options of the PBR preview beyond exposure. */
12
+ export interface PBRSceneOptions {
13
+ vertexColors?: VertexColorMode;
14
+ /** value check: every base colour is a neutral 18% grey (base colour maps give alpha only, Cd nothing) */
15
+ grey?: boolean;
16
+ }
17
+ /** The base colour of grey renders: 18% reflectance (linear). */
18
+ export declare const GREY_ALBEDO = 0.18;
5
19
  /** The normals the exporter writes by default (60° cusp): the frame the normal map and TANGENT belong to. */
6
20
  export declare const PBR_CUSP = 60;
7
21
  /**
@@ -9,12 +23,18 @@ export declare const PBR_CUSP = 60;
9
23
  * (image volumes need no reading) through readFile, usually Host.readFile.
10
24
  */
11
25
  export declare function preparePBR(g: Geometry, readFile?: (path: string) => Promise<Uint8Array>): Promise<PBRTextures>;
26
+ /** Per-triangle alpha handling (PBRScene.triAlpha). */
27
+ export declare const ALPHA_OPAQUE = 0, ALPHA_MASK = 1, ALPHA_BLEND = 2;
12
28
  /** Per-triangle data and the per-pixel shader for one render. */
13
29
  export interface PBRScene {
14
30
  /** materials evaluated, maps used, problems: footer and notes */
15
31
  summary: string;
16
- /** shade a pixel; writes display RGB (0..1) into out */
32
+ /** shade a pixel; writes display RGB (0..1) into out[0..2] and the coverage (alpha, 1 on opaque triangles) into out[3] */
17
33
  shade(t: number, w0: number, w1: number, w2: number, dudx: number, dvdx: number, dudy: number, dvdy: number, view: number[], back: boolean, out: number[]): void;
34
+ /** per triangle: ALPHA_OPAQUE, ALPHA_MASK (discard below cutoff(t)) or ALPHA_BLEND (composited after the opaque pass) */
35
+ triAlpha: Uint8Array;
36
+ /** the MASK cutoff of triangle t's material */
37
+ cutoff(t: number): number;
18
38
  /** uv of triangle t at (perspective-correct) weights, for the derivatives */
19
39
  uvAt(t: number, w0: number, w1: number, w2: number, out: number[]): void;
20
40
  hasUV: boolean;
@@ -25,4 +45,4 @@ export interface PBRScene {
25
45
  * Build the shading data for g's triangles (tris / triPrim from topology.triangulate). Synchronous: MikkTSpace must be
26
46
  * loaded (preparePBR or loadMikkTSpace) and external textures read into `files`; notes receive what is not evaluated.
27
47
  */
28
- export declare function pbrScene(g: Geometry, tris: Uint32Array, triPrim: Uint32Array, files: PBRTextures | undefined, exposure: number, notes: string[]): PBRScene;
48
+ export declare function pbrScene(g: Geometry, tris: Uint32Array, triPrim: Uint32Array, files: PBRTextures | undefined, exposure: number, notes: string[], opts?: PBRSceneOptions): PBRScene;