topotopo 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (354) hide show
  1. package/NOTICE +40 -10
  2. package/README.md +475 -111
  3. package/dist/cli.js +328 -133
  4. package/dist/config.d.ts +48 -0
  5. package/dist/config.js +170 -0
  6. package/dist/core/analysis.d.ts +5 -1
  7. package/dist/core/analysis.js +8 -3
  8. package/dist/core/bake.d.ts +16 -8
  9. package/dist/core/bake.js +165 -29
  10. package/dist/core/bevel.d.ts +3 -1
  11. package/dist/core/bevel.js +238 -97
  12. package/dist/core/decimate.d.ts +65 -0
  13. package/dist/core/decimate.js +409 -3
  14. package/dist/core/erosion.d.ts +37 -0
  15. package/dist/core/erosion.js +41 -1
  16. package/dist/core/geometry.d.ts +5 -1
  17. package/dist/core/geometry.js +204 -4
  18. package/dist/core/heightfield.d.ts +27 -4
  19. package/dist/core/heightfield.js +54 -16
  20. package/dist/core/imageops.d.ts +6 -0
  21. package/dist/core/imageops.js +51 -0
  22. package/dist/core/intrinsics.d.ts +7 -0
  23. package/dist/core/intrinsics.js +94 -0
  24. package/dist/core/manifold.d.ts +12 -1
  25. package/dist/core/manifold.js +78 -6
  26. package/dist/core/materials.d.ts +11 -0
  27. package/dist/core/materials.js +56 -0
  28. package/dist/core/noise.d.ts +9 -0
  29. package/dist/core/noise.js +10 -1
  30. package/dist/core/packed.js +11 -0
  31. package/dist/core/particles.d.ts +1 -1
  32. package/dist/core/particles.js +1 -1
  33. package/dist/core/polymerge.d.ts +21 -0
  34. package/dist/core/polymerge.js +327 -0
  35. package/dist/core/rbd.js +13 -1
  36. package/dist/core/repair.d.ts +2 -0
  37. package/dist/core/repair.js +2 -0
  38. package/dist/core/report.d.ts +70 -0
  39. package/dist/core/report.js +275 -0
  40. package/dist/core/scatter.d.ts +1 -1
  41. package/dist/core/scatter.js +1 -1
  42. package/dist/core/scene.d.ts +20 -0
  43. package/dist/core/scene.js +72 -0
  44. package/dist/core/sha256.d.ts +4 -0
  45. package/dist/core/sha256.js +69 -0
  46. package/dist/core/shapes.d.ts +3 -0
  47. package/dist/core/shapes.js +34 -0
  48. package/dist/core/snippet-lib.d.ts +15 -2
  49. package/dist/core/snippet-lib.js +40 -14
  50. package/dist/core/solidify.d.ts +38 -0
  51. package/dist/core/solidify.js +356 -0
  52. package/dist/core/tangents.d.ts +54 -0
  53. package/dist/core/tangents.js +218 -0
  54. package/dist/core/texcoord.d.ts +4 -0
  55. package/dist/core/texcoord.js +14 -0
  56. package/dist/core/texnoise.d.ts +6 -1
  57. package/dist/core/texnoise.js +6 -2
  58. package/dist/core/texsdf.d.ts +131 -0
  59. package/dist/core/texsdf.js +637 -0
  60. package/dist/core/texture.d.ts +163 -9
  61. package/dist/core/texture.js +844 -20
  62. package/dist/core/topology.d.ts +32 -0
  63. package/dist/core/topology.js +238 -7
  64. package/dist/core/traceimage.d.ts +7 -0
  65. package/dist/core/traceimage.js +221 -0
  66. package/dist/core/tritri.d.ts +5 -0
  67. package/dist/core/tritri.js +120 -0
  68. package/dist/core/unwrap.d.ts +72 -0
  69. package/dist/core/unwrap.js +800 -0
  70. package/dist/core/usercode.d.ts +27 -0
  71. package/dist/core/usercode.js +87 -0
  72. package/dist/core/uv.d.ts +15 -16
  73. package/dist/core/uv.js +36 -189
  74. package/dist/core/uvislands.d.ts +62 -0
  75. package/dist/core/uvislands.js +574 -0
  76. package/dist/core/uvoverlap.d.ts +58 -0
  77. package/dist/core/uvoverlap.js +220 -0
  78. package/dist/core/uvpack.d.ts +64 -0
  79. package/dist/core/uvpack.js +628 -0
  80. package/dist/core/uvreport.d.ts +127 -0
  81. package/dist/core/uvreport.js +372 -0
  82. package/dist/core/wrangle.d.ts +6 -1
  83. package/dist/core/wrangle.js +27 -16
  84. package/dist/core/xatlas.d.ts +16 -1
  85. package/dist/core/xatlas.js +95 -61
  86. package/dist/engines.d.ts +63 -0
  87. package/dist/engines.js +180 -0
  88. package/dist/explain.d.ts +4 -3
  89. package/dist/explain.js +129 -12
  90. package/dist/graph/engine.d.ts +92 -29
  91. package/dist/graph/engine.js +298 -148
  92. package/dist/graph/expr.d.ts +6 -3
  93. package/dist/graph/expr.js +18 -8
  94. package/dist/graph/outputs.d.ts +23 -0
  95. package/dist/graph/outputs.js +41 -0
  96. package/dist/graph/packages.d.ts +72 -0
  97. package/dist/graph/packages.js +261 -0
  98. package/dist/graph/parallel.d.ts +3 -1
  99. package/dist/graph/parallel.js +4 -1
  100. package/dist/graph/params.d.ts +6 -0
  101. package/dist/graph/params.js +34 -7
  102. package/dist/graph/scope.d.ts +55 -0
  103. package/dist/graph/scope.js +14 -0
  104. package/dist/graph/types.d.ts +75 -12
  105. package/dist/graph/types.js +4 -2
  106. package/dist/graph/vars.d.ts +16 -0
  107. package/dist/graph/vars.js +80 -0
  108. package/dist/host/artifacts.d.ts +10 -1
  109. package/dist/host/artifacts.js +37 -6
  110. package/dist/host/cook.d.ts +241 -0
  111. package/dist/host/cook.js +844 -0
  112. package/dist/host/export-targets.d.ts +42 -5
  113. package/dist/host/export-targets.js +72 -13
  114. package/dist/host/godot-commands.d.ts +4 -0
  115. package/dist/host/godot-commands.js +21 -0
  116. package/dist/host/godot.d.ts +183 -0
  117. package/dist/host/godot.js +916 -0
  118. package/dist/host/node.d.ts +12 -7
  119. package/dist/host/node.js +27 -9
  120. package/dist/host/pool.js +51 -2
  121. package/dist/host/sidecars.d.ts +8 -0
  122. package/dist/host/sidecars.js +50 -0
  123. package/dist/host/types.d.ts +19 -6
  124. package/dist/host/version.d.ts +1 -0
  125. package/dist/host/version.js +3 -0
  126. package/dist/host/worker.js +5 -2
  127. package/dist/index.d.ts +5 -3
  128. package/dist/index.js +3 -2
  129. package/dist/inspect.d.ts +84 -1
  130. package/dist/inspect.js +271 -24
  131. package/dist/io/common.d.ts +33 -5
  132. package/dist/io/export.js +2 -1
  133. package/dist/io/files.d.ts +23 -4
  134. package/dist/io/files.js +60 -8
  135. package/dist/io/gltf.js +355 -51
  136. package/dist/io/heightmap.d.ts +3 -0
  137. package/dist/io/heightmap.js +1 -0
  138. package/dist/io/import.js +10 -0
  139. package/dist/io/inspect-scene.d.ts +55 -0
  140. package/dist/io/inspect-scene.js +155 -0
  141. package/dist/io/kinds.d.ts +81 -0
  142. package/dist/io/kinds.js +163 -0
  143. package/dist/io/points.d.ts +2 -1
  144. package/dist/io/points.js +3 -1
  145. package/dist/io/sidecars.d.ts +24 -0
  146. package/dist/io/sidecars.js +57 -0
  147. package/dist/io/source.d.ts +65 -0
  148. package/dist/io/source.js +112 -0
  149. package/dist/io/targets.d.ts +47 -3
  150. package/dist/io/targets.js +149 -14
  151. package/dist/io/textures.js +21 -1
  152. package/dist/io/unreal.js +5 -1
  153. package/dist/mcp/docs.d.ts +10 -1
  154. package/dist/mcp/docs.js +816 -119
  155. package/dist/mcp/inputs.d.ts +12 -5
  156. package/dist/mcp/inputs.js +50 -13
  157. package/dist/mcp/server.js +70 -24
  158. package/dist/mcp/tools.d.ts +14 -7
  159. package/dist/mcp/tools.js +207 -108
  160. package/dist/mcp/verify.d.ts +2 -2
  161. package/dist/mcp/verify.js +1 -1
  162. package/dist/mcp/workspace.d.ts +15 -0
  163. package/dist/mcp/workspace.js +349 -0
  164. package/dist/nodes/attributes.js +198 -1
  165. package/dist/nodes/bake.js +207 -83
  166. package/dist/nodes/beam.d.ts +1 -0
  167. package/dist/nodes/beam.js +201 -0
  168. package/dist/nodes/bevel.js +54 -5
  169. package/dist/nodes/cloth.js +2 -0
  170. package/dist/nodes/code.js +22 -10
  171. package/dist/nodes/curves.js +440 -93
  172. package/dist/nodes/flow.js +53 -33
  173. package/dist/nodes/generate.js +13 -39
  174. package/dist/nodes/heightfield.js +248 -77
  175. package/dist/nodes/imageops.d.ts +1 -0
  176. package/dist/nodes/imageops.js +203 -0
  177. package/dist/nodes/index.d.ts +4 -0
  178. package/dist/nodes/index.js +4 -0
  179. package/dist/nodes/material.js +91 -23
  180. package/dist/nodes/measure.js +45 -18
  181. package/dist/nodes/particles.js +2 -0
  182. package/dist/nodes/pcg.js +6 -5
  183. package/dist/nodes/procedural.js +4 -3
  184. package/dist/nodes/rbd.js +1 -1
  185. package/dist/nodes/remesh.js +71 -15
  186. package/dist/nodes/scene.d.ts +1 -0
  187. package/dist/nodes/scene.js +55 -0
  188. package/dist/nodes/sdf.js +10 -5
  189. package/dist/nodes/solid.js +20 -5
  190. package/dist/nodes/solidify.d.ts +1 -0
  191. package/dist/nodes/solidify.js +52 -0
  192. package/dist/nodes/splines.d.ts +15 -1
  193. package/dist/nodes/splines.js +112 -105
  194. package/dist/nodes/texture.d.ts +21 -6
  195. package/dist/nodes/texture.js +1318 -185
  196. package/dist/nodes/topology.d.ts +7 -0
  197. package/dist/nodes/topology.js +133 -6
  198. package/dist/nodes/transform.js +11 -3
  199. package/dist/nodes/util.d.ts +1 -1
  200. package/dist/nodes/uv.js +192 -174
  201. package/dist/nodes/wasmcall.js +6 -2
  202. package/dist/open.d.ts +19 -0
  203. package/dist/open.js +12 -0
  204. package/dist/package.d.ts +288 -0
  205. package/dist/package.js +772 -0
  206. package/dist/packages/check.d.ts +32 -0
  207. package/dist/packages/check.js +169 -0
  208. package/dist/packages/commands.d.ts +57 -0
  209. package/dist/packages/commands.js +537 -0
  210. package/dist/packages/registry.d.ts +796 -0
  211. package/dist/packages/registry.js +2998 -0
  212. package/dist/packages/update.d.ts +124 -0
  213. package/dist/packages/update.js +476 -0
  214. package/dist/render/options.d.ts +2 -0
  215. package/dist/render/options.js +44 -5
  216. package/dist/render/pbr.d.ts +28 -0
  217. package/dist/render/pbr.js +378 -0
  218. package/dist/render/preview.d.ts +69 -0
  219. package/dist/render/preview.js +26 -0
  220. package/dist/render/raster.d.ts +78 -7
  221. package/dist/render/raster.js +600 -145
  222. package/dist/render/texview.d.ts +7 -1
  223. package/dist/render/texview.js +34 -2
  224. package/dist/scan.d.ts +61 -0
  225. package/dist/scan.js +228 -0
  226. package/dist/session.d.ts +311 -0
  227. package/dist/session.js +849 -0
  228. package/dist/viewer/app/api.js +48 -6
  229. package/dist/viewer/app/camera.js +1 -1
  230. package/dist/viewer/app/cooking.js +78 -0
  231. package/dist/viewer/app/embed.js +100 -0
  232. package/dist/viewer/app/export-popover.js +118 -16
  233. package/dist/viewer/app/grid.js +6 -2
  234. package/dist/viewer/app/guides.js +123 -1
  235. package/dist/viewer/app/keymap.js +7 -4
  236. package/dist/viewer/app/layers.js +5 -5
  237. package/dist/viewer/app/main.js +186 -53
  238. package/dist/viewer/app/markers.js +61 -1
  239. package/dist/viewer/app/outliner.js +72 -27
  240. package/dist/viewer/app/output-info.js +45 -0
  241. package/dist/viewer/app/outputs.css +147 -8
  242. package/dist/viewer/app/outputs.js +168 -54
  243. package/dist/viewer/app/packages.js +614 -0
  244. package/dist/viewer/app/props.js +177 -53
  245. package/dist/viewer/app/scene.js +35 -6
  246. package/dist/viewer/app/select.js +5 -4
  247. package/dist/viewer/app/selection.js +1 -1
  248. package/dist/viewer/app/status.js +12 -15
  249. package/dist/viewer/app/style.css +66 -8
  250. package/dist/viewer/app/units.js +1 -1
  251. package/dist/viewer/app/vars.js +48 -1
  252. package/dist/viewer/app/welcome.js +72 -0
  253. package/dist/viewer/graph-file.d.ts +62 -0
  254. package/dist/viewer/graph-file.js +175 -0
  255. package/dist/viewer/index.html +24 -11
  256. package/dist/viewer/json-edit.d.ts +13 -0
  257. package/dist/viewer/json-edit.js +274 -0
  258. package/dist/viewer/outputs.d.ts +49 -5
  259. package/dist/viewer/outputs.js +264 -56
  260. package/dist/viewer/packages.d.ts +121 -0
  261. package/dist/viewer/packages.js +584 -0
  262. package/dist/viewer/server.d.ts +24 -7
  263. package/dist/viewer/server.js +289 -31
  264. package/dist/web/app/web.css +419 -0
  265. package/dist/web/app/web.js +188 -0
  266. package/dist/web/bake.d.ts +34 -0
  267. package/dist/web/bake.js +153 -0
  268. package/dist/web/folder-page.d.ts +101 -0
  269. package/dist/web/folder-page.js +146 -0
  270. package/dist/web/folders.d.ts +280 -0
  271. package/dist/web/folders.js +970 -0
  272. package/dist/web/library.d.ts +91 -0
  273. package/dist/web/library.js +228 -0
  274. package/dist/web/markdown.d.ts +45 -0
  275. package/dist/web/markdown.js +677 -0
  276. package/dist/web/pages.d.ts +258 -0
  277. package/dist/web/pages.js +301 -0
  278. package/dist/web/server.d.ts +24 -0
  279. package/dist/web/server.js +1068 -0
  280. package/dist/workspace.d.ts +88 -105
  281. package/dist/workspace.js +359 -375
  282. package/integrations/godot/addons/topotopo/LICENSE +202 -0
  283. package/integrations/godot/addons/topotopo/README.md +57 -0
  284. package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
  285. package/integrations/godot/addons/topotopo/dock.gd +266 -0
  286. package/integrations/godot/addons/topotopo/dock.tscn +72 -0
  287. package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
  288. package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
  289. package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
  290. package/integrations/godot/addons/topotopo/inspector.gd +38 -0
  291. package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
  292. package/integrations/godot/addons/topotopo/package.gd +23 -0
  293. package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
  294. package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
  295. package/integrations/godot/addons/topotopo/plugin.gd +970 -0
  296. package/integrations/godot/addons/topotopo/record.gd +435 -0
  297. package/integrations/godot/addons/topotopo/runner.gd +458 -0
  298. package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
  299. package/integrations/godot/addons/topotopo/watcher.gd +199 -0
  300. package/kernels/pkg/README.md +23 -29
  301. package/kernels/pkg-simd/README.md +23 -29
  302. package/library/architecture/versions/1.0/architecture.topo +12 -0
  303. package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
  304. package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
  305. package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
  306. package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
  307. package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
  308. package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
  309. package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
  310. package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
  311. package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
  312. package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
  313. package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
  314. package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
  315. package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
  316. package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
  317. package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
  318. package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
  319. package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
  320. package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
  321. package/library/architecture/versions/1.0/version.json +1119 -0
  322. package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
  323. package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
  324. package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
  325. package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
  326. package/library/nature/versions/1.0/graphs/lineup.json +24 -0
  327. package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
  328. package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
  329. package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
  330. package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
  331. package/library/nature/versions/1.0/nature.topo +12 -0
  332. package/library/nature/versions/1.0/version.json +534 -0
  333. package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
  334. package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
  335. package/library/props/versions/1.0/graphs/lineup.json +18 -0
  336. package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
  337. package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
  338. package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
  339. package/library/props/versions/1.0/props.topo +12 -0
  340. package/library/props/versions/1.0/version.json +336 -0
  341. package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
  342. package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
  343. package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
  344. package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
  345. package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
  346. package/library/street/versions/1.0/graphs/lineup.json +22 -0
  347. package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
  348. package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
  349. package/library/street/versions/1.0/street.topo +12 -0
  350. package/library/street/versions/1.0/version.json +421 -0
  351. package/package.json +23 -8
  352. package/dist/graph/migrate.d.ts +0 -23
  353. package/dist/graph/migrate.js +0 -58
  354. package/shelf/index.json +0 -190
@@ -1,7 +1,7 @@
1
1
  // Render options from tool arguments: the snake_case keys of the MCP render tool, an example's
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
- import { parseViews } from './raster.js';
4
+ import { UNDERLAY_FITS, parseViews } from './raster.js';
5
5
  const num = (v, key) => {
6
6
  const n = typeof v === 'string' ? Number(v) : v;
7
7
  if (typeof n !== 'number' || !Number.isFinite(n))
@@ -20,6 +20,25 @@ export function parsePlane(s, key) {
20
20
  const [a, off, abs] = s.split(':');
21
21
  return { axis: axis(a, key), offset: off === undefined || off === '' ? 0.5 : num(off, key), absolute: abs === 'abs' || abs === 'absolute' };
22
22
  }
23
+ /** Pixels per view: 800, "800", "1600x900" (also 1600×900 or 1600,900) or [1600, 900]. */
24
+ export function parseSize(v) {
25
+ const bad = () => new Error(`render: size expects pixels per view, n or "WxH" (e.g. 800 or "1600x900"), got ${JSON.stringify(v)}`);
26
+ if (Array.isArray(v)) {
27
+ if (v.length !== 2 || !v.every((x) => Number.isFinite(+x) && +x > 0))
28
+ throw bad();
29
+ return [+v[0], +v[1]];
30
+ }
31
+ if (typeof v === 'string' && /[x×,]/i.test(v)) {
32
+ const m = /^\s*(\d+(?:\.\d+)?)\s*[x×,]\s*(\d+(?:\.\d+)?)\s*$/i.exec(v);
33
+ if (!m)
34
+ throw bad();
35
+ return [Number(m[1]), Number(m[2])];
36
+ }
37
+ const n = typeof v === 'string' ? Number(v) : v;
38
+ if (typeof n !== 'number' || !Number.isFinite(n) || n <= 0)
39
+ throw bad();
40
+ return n;
41
+ }
23
42
  /** Map tool-style arguments (snake_case; camelCase also accepted) to RenderOptions. */
24
43
  export function renderArgs(a) {
25
44
  const o = {};
@@ -27,9 +46,11 @@ export function renderArgs(a) {
27
46
  const pick = (snake, camel = snake) => (has(snake) ? a[snake] : has(camel) ? a[camel] : undefined);
28
47
  if (has('views'))
29
48
  o.views = parseViews(a.views);
30
- for (const [s, c] of [['size', 'size'], ['azimuth', 'azimuth'], ['elevation', 'elevation'], ['zoom', 'zoom'], ['hard_angle', 'hardAngle'], ['max_labels', 'maxLabels'],
49
+ if (has('size'))
50
+ o.size = parseSize(a.size);
51
+ for (const [s, c] of [['azimuth', 'azimuth'], ['elevation', 'elevation'], ['zoom', 'zoom'], ['hard_angle', 'hardAngle'], ['max_labels', 'maxLabels'],
31
52
  ['glyph_scale', 'glyphScale'], ['max_glyphs', 'maxGlyphs'], ['ao_radius', 'aoRadius'], ['ortho_scale', 'orthoScale'], ['scale', 'scale'], ['ssaa', 'ssaa'],
32
- ['max_triangles', 'maxTriangles']]) {
53
+ ['max_triangles', 'maxTriangles'], ['exposure', 'exposure'], ['underlay_opacity', 'underlayOpacity']]) {
33
54
  const v = pick(s, c);
34
55
  if (v !== undefined)
35
56
  o[c] = num(v, s);
@@ -41,16 +62,34 @@ export function renderArgs(a) {
41
62
  if (pts !== undefined)
42
63
  o.points = pts === 'auto' ? 'auto' : bool(pts);
43
64
  for (const [s, c] of [['point_numbers', 'pointNumbers'], ['prim_numbers', 'primNumbers'], ['label_groups', 'labelGroups'], ['label_pieces', 'labelPieces'],
44
- ['legend', 'legend'], ['checker', 'checker'], ['grid', 'grid'], ['annotate', 'annotate'], ['section_absolute', 'sectionAbsolute'], ['textures', 'textures'], ['view_labels', 'viewLabels']]) {
65
+ ['legend', 'legend'], ['checker', 'checker'], ['grid', 'grid'], ['annotate', 'annotate'], ['section_absolute', 'sectionAbsolute'], ['textures', 'textures'], ['view_labels', 'viewLabels'],
66
+ ['transparent', 'transparent'], ['sockets', 'sockets']]) {
45
67
  const v = pick(s, c);
46
68
  if (v !== undefined)
47
69
  o[c] = bool(v);
48
70
  }
49
- for (const [s, c] of [['color_by', 'colorBy'], ['label_attrib', 'labelAttrib'], ['glyph_attrib', 'glyphAttrib'], ['glyphs', 'glyphs'], ['shading', 'shading'], ['title', 'title'], ['texture', 'texture']]) {
71
+ for (const [s, c] of [['color_by', 'colorBy'], ['label_attrib', 'labelAttrib'], ['glyph_attrib', 'glyphAttrib'], ['glyphs', 'glyphs'], ['shading', 'shading'], ['title', 'title'], ['texture', 'texture'],
72
+ ['heightfield_layer', 'heightfieldLayer'], ['underlay', 'underlay']]) {
50
73
  const v = pick(s, c);
51
74
  if (v !== undefined)
52
75
  o[c] = String(v);
53
76
  }
77
+ // heightfields: quads per side (default 256), or "full" for every sample
78
+ const hr = pick('heightfield_res', 'heightfieldRes');
79
+ if (hr !== undefined) {
80
+ const v = hr === 'full' || hr === Infinity ? Infinity : typeof hr === 'string' || typeof hr === 'number' ? Number(hr) : NaN;
81
+ if (!(v >= 1))
82
+ throw new Error(`render: heightfield_res expects quads per side (1 or more) or "full", got ${JSON.stringify(hr)}`);
83
+ o.heightfieldRes = v;
84
+ }
85
+ const uf = pick('underlay_fit', 'underlayFit');
86
+ if (uf !== undefined) {
87
+ if (!UNDERLAY_FITS.includes(uf))
88
+ throw new Error(`render: underlay_fit expects ${UNDERLAY_FITS.join(', ')}, got ${JSON.stringify(uf)}`);
89
+ o.underlayFit = uf;
90
+ }
91
+ if (o.underlayOpacity !== undefined && !(o.underlayOpacity >= 0 && o.underlayOpacity <= 1))
92
+ throw new Error(`render: underlay_opacity expects 0..1, got ${o.underlayOpacity}`);
54
93
  const sa = pick('section_axis', 'sectionAxis');
55
94
  if (sa !== undefined)
56
95
  o.sectionAxis = axis(sa, 'section_axis');
@@ -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;
@@ -0,0 +1,378 @@
1
+ import { Image, channelsOf, imageRef, referenceableImages, resizeLayer } from '../core/image.js';
2
+ import { DEFAULT_MATERIAL, mergeMaterialTables, primMaterials, readMaterials } from '../core/materials.js';
3
+ import { cornerTangents, loadMikkTSpace, mikkTSpaceReady, shadingFrame, vertexUV } from '../core/tangents.js';
4
+ import { imageRowOfV } from '../core/texcoord.js';
5
+ import { resolveVertexNormals } from '../core/topology.js';
6
+ import { decodePNG } from '../io/png-decode.js';
7
+ import { imageFromPNG } from '../io/textures.js';
8
+ /** The normals the exporter writes by default (60° cusp): the frame the normal map and TANGENT belong to. */
9
+ export const PBR_CUSP = 60;
10
+ /**
11
+ * Asynchronous preparation for shading "pbr": loads MikkTSpace and reads every texture file the material tables name
12
+ * (image volumes need no reading) through readFile, usually Host.readFile.
13
+ */
14
+ export async function preparePBR(g, readFile) {
15
+ await loadMikkTSpace();
16
+ const files = new Map();
17
+ const table = mergeMaterialTables([g, ...g.packedSources]);
18
+ for (const m of Object.values(table))
19
+ for (const path of Object.values(m.textures ?? {})) {
20
+ if (!path || imageRef(path) !== null || files.has(path))
21
+ continue;
22
+ if (!readFile) {
23
+ files.set(path, 'no file access in this render');
24
+ continue;
25
+ }
26
+ let bytes;
27
+ try {
28
+ bytes = await readFile(path);
29
+ }
30
+ catch (e) {
31
+ files.set(path, `cannot be read (${e?.message ?? e})`);
32
+ continue;
33
+ }
34
+ if (!(bytes.length >= 8 && bytes[0] === 0x89 && bytes[1] === 0x50)) {
35
+ files.set(path, 'is not a PNG (only PNG textures are decoded for the preview)');
36
+ continue;
37
+ }
38
+ try {
39
+ files.set(path, imageFromPNG(decodePNG(bytes), path));
40
+ }
41
+ catch (e) {
42
+ files.set(path, `is not a readable PNG (${e?.message ?? e})`);
43
+ }
44
+ }
45
+ return files;
46
+ }
47
+ const srgbToLinear = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
48
+ const linearToSrgb = (c) => (c <= 0.0031308 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - 0.055);
49
+ /** Mip chain of a layer (1 or 4 channels), optionally sRGB-decoded first (colour), area-averaged down to 1 × 1. */
50
+ function mips(img, srgb) {
51
+ const src = img.layer(img.mainLayer), ch = channelsOf(src, img.count) || 1;
52
+ const base = srgb ? Float32Array.from(src, (x, i) => (ch === 4 && i % 4 === 3 ? x : srgbToLinear(Math.max(0, x)))) : src;
53
+ const out = [{ w: img.width, h: img.height, ch, data: base }];
54
+ let m = out[0];
55
+ while (m.w > 1 || m.h > 1) {
56
+ const w = Math.max(1, m.w >> 1), h = Math.max(1, m.h >> 1);
57
+ m = { w, h, ch, data: resizeLayer(m.data, ch, m.w, m.h, w, h, true) };
58
+ out.push(m);
59
+ }
60
+ return out;
61
+ }
62
+ const wrap = (i, n) => ((i % n) + n) % n;
63
+ /** Bilinear sample of one mip level (repeat wrap) into out[0..3] (grey layers fill rgb, alpha 1). */
64
+ function bilinear(m, u, v, out, k) {
65
+ const x = u * m.w - 0.5, y = imageRowOfV(v, m.h) - 0.5;
66
+ const x0 = Math.floor(x), y0 = Math.floor(y), tx = x - x0, ty = y - y0;
67
+ const i0 = wrap(x0, m.w), i1 = wrap(x0 + 1, m.w), j0 = wrap(y0, m.h), j1 = wrap(y0 + 1, m.h);
68
+ const d = m.data, ch = m.ch;
69
+ for (let c = 0; c < 4; c++) {
70
+ const cc = ch === 4 ? c : c === 3 ? -1 : 0;
71
+ let s = 1;
72
+ if (cc >= 0) {
73
+ const a = d[(j0 * m.w + i0) * ch + cc], b = d[(j0 * m.w + i1) * ch + cc], e = d[(j1 * m.w + i0) * ch + cc], f = d[(j1 * m.w + i1) * ch + cc];
74
+ const t = a + (b - a) * tx, q = e + (f - e) * tx;
75
+ s = t + (q - t) * ty;
76
+ }
77
+ out[c] += s * k;
78
+ }
79
+ }
80
+ /** Trilinear sample: lod in level-0 texels per pixel (log2), blended between the two nearest levels. */
81
+ function sampleTri(chain, u, v, lod, out) {
82
+ out[0] = out[1] = out[2] = out[3] = 0;
83
+ const l = Math.max(0, Math.min(chain.length - 1, lod)), l0 = Math.floor(l), f = l - l0;
84
+ bilinear(chain[l0], u, v, out, 1 - f);
85
+ if (f > 0 && l0 + 1 < chain.length)
86
+ bilinear(chain[l0 + 1], u, v, out, f);
87
+ }
88
+ const norm = (v) => { const l = Math.hypot(v[0], v[1], v[2]) || 1; return [v[0] / l, v[1] / l, v[2] / l]; };
89
+ // studio rig in camera space (x right, y up, z towards the viewer): key upper left, fill right, rim behind
90
+ const RIG = [
91
+ { d: norm([-0.45, 0.65, 0.6]), c: [1.9, 1.85, 1.76] },
92
+ { d: norm([0.75, 0.1, 0.45]), c: [0.42, 0.45, 0.5] },
93
+ { d: norm([0.3, 0.55, -0.78]), c: [1.1, 1.1, 1.1] },
94
+ ];
95
+ // world-up environment for indirect light
96
+ const SKY = [0.34, 0.37, 0.42], HORIZON = [0.27, 0.27, 0.27], GROUND = [0.08, 0.075, 0.07];
97
+ /** Environment radiance along world direction d, widened by roughness (a cheap stand-in for a prefiltered map). */
98
+ function env(dy, rough, out) {
99
+ const w = 0.25 + rough * 0.9;
100
+ const t = Math.max(-1, Math.min(1, dy / w));
101
+ for (let c = 0; c < 3; c++)
102
+ out[c] = t >= 0 ? HORIZON[c] + (SKY[c] - HORIZON[c]) * t : HORIZON[c] + (GROUND[c] - HORIZON[c]) * -t;
103
+ }
104
+ /** ACES filmic curve (Narkowicz fit). */
105
+ const acesCurve = (x) => Math.max(0, Math.min(1, (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14)));
106
+ /**
107
+ * Tone map linear radiance in place and encode to sRGB: the ACES curve on the brightest channel, the others scaled by
108
+ * the same factor, so bright coloured highlights (a red metal) keep their hue instead of washing out to white.
109
+ */
110
+ function tone(c) {
111
+ const m = Math.max(c[0], c[1], c[2]);
112
+ const k = m > 0 ? acesCurve(m) / m : 0;
113
+ for (let i = 0; i < 3; i++)
114
+ c[i] = linearToSrgb(Math.max(0, c[i] * k));
115
+ }
116
+ /**
117
+ * Build the shading data for g's triangles (tris / triPrim from topology.triangulate). Synchronous: MikkTSpace must be
118
+ * loaded (preparePBR or loadMikkTSpace) and external textures read into `files`; notes receive what is not evaluated.
119
+ */
120
+ export function pbrScene(g, tris, triPrim, files, exposure, notes) {
121
+ if (!mikkTSpaceReady())
122
+ throw new Error('shading "pbr" needs the asynchronous render entry (renderGeometryAsync): MikkTSpace is not loaded');
123
+ const nTri = tris.length / 3;
124
+ const table = readMaterials(g), pm = primMaterials(g), imgs = referenceableImages(g);
125
+ const uv = vertexUV(g, 'uv');
126
+ const N = resolveVertexNormals(g, PBR_CUSP);
127
+ const P = g.P, vp = g.vertexPoint;
128
+ const problems = [];
129
+ const mipCache = new Map();
130
+ const mapOf = (mat, slot, path, srgb) => {
131
+ if (!path)
132
+ return null;
133
+ const key = `${path}\u0000${srgb}`;
134
+ if (mipCache.has(key))
135
+ return mipCache.get(key);
136
+ let img = null;
137
+ const ref = imageRef(path);
138
+ if (ref !== null) {
139
+ img = imgs.get(ref) ?? null;
140
+ if (!img)
141
+ problems.push(`material "${mat}" ${slot} "image:${ref}" is not carried by the geometry`);
142
+ }
143
+ else {
144
+ const f = files?.get(path);
145
+ if (f instanceof Image)
146
+ img = f;
147
+ else
148
+ problems.push(`material "${mat}" ${slot} "${path}" ${f ?? 'was not loaded (render through renderGeometryAsync with readFile)'}`);
149
+ }
150
+ const chain = img ? mips(img, srgb) : null;
151
+ mipCache.set(key, chain);
152
+ return chain;
153
+ };
154
+ // vertex colour as glTF COLOR_0: per material, only when Cd is not all white over its prims
155
+ const cdF = g.findAttrib('Cd', ['vertex', 'point', 'prim', 'detail']);
156
+ const cdA = cdF && cdF.attr.type === 'float' ? cdF.attr : null;
157
+ const cdIndex = (v, p) => (cdF.cls === 'vertex' ? v : cdF.cls === 'point' ? vp[v] : cdF.cls === 'prim' ? p : 0);
158
+ const cdOf = (v, p, out) => {
159
+ const d = cdA.data, s = cdA.size, i = cdIndex(v, p) * s;
160
+ out[0] = d[i];
161
+ out[1] = s > 1 ? d[i + 1] : d[i];
162
+ out[2] = s > 2 ? d[i + 2] : d[i];
163
+ };
164
+ const mats = new Map(), vcol = new Map();
165
+ const transparent = [];
166
+ const matOf = (name) => {
167
+ let m = mats.get(name);
168
+ if (m)
169
+ return m;
170
+ const src = (name && table[name]) || DEFAULT_MATERIAL;
171
+ const label = name || 'default';
172
+ const t = src.textures ?? {};
173
+ const emax = Math.max(1, ...src.emissive);
174
+ m = {
175
+ name: label, base: src.baseColor.map((c) => srgbToLinear(Math.max(0, Math.min(1, c)))),
176
+ metallic: src.metallic, roughness: src.roughness,
177
+ emissive: src.emissive.map((e) => srgbToLinear(Math.max(0, Math.min(1, e / emax))) * emax), unlit: src.unlit,
178
+ baseMap: mapOf(label, 'base colour', t.baseColor, true), normalMap: mapOf(label, 'normal', t.normal, false),
179
+ ormMap: mapOf(label, 'orm', t.orm, false), roughMap: t.orm ? null : mapOf(label, 'roughness', t.roughness, false), size: [1, 1],
180
+ };
181
+ for (const c of [m.baseMap, m.normalMap, m.ormMap, m.roughMap])
182
+ if (c) {
183
+ m.size[0] = Math.max(m.size[0], c[0].w);
184
+ m.size[1] = Math.max(m.size[1], c[0].h);
185
+ }
186
+ if (src.alpha < 1)
187
+ transparent.push(`material "${label}" alpha ${src.alpha}`);
188
+ else if (m.baseMap && m.baseMap[0].ch === 4 && m.baseMap[0].data.some((x, i) => i % 4 === 3 && x < 1))
189
+ transparent.push(`material "${label}" base colour map alpha`);
190
+ mats.set(name, m);
191
+ return m;
192
+ };
193
+ const triMat = new Array(nTri);
194
+ const cdWhite = new Map();
195
+ if (cdA) {
196
+ const c = [0, 0, 0];
197
+ for (let t = 0; t < nTri; t++) {
198
+ const p = triPrim[t], name = pm ? pm[p] : '';
199
+ if (cdWhite.get(name) === false)
200
+ continue;
201
+ let white = cdWhite.get(name) ?? true;
202
+ for (let k = 0; k < 3 && white; k++) {
203
+ cdOf(tris[t * 3 + k], p, c);
204
+ if (c[0] !== 1 || c[1] !== 1 || c[2] !== 1)
205
+ white = false;
206
+ }
207
+ cdWhite.set(name, white);
208
+ }
209
+ }
210
+ for (let t = 0; t < nTri; t++) {
211
+ const name = pm ? pm[triPrim[t]] : '';
212
+ triMat[t] = matOf(name);
213
+ if (!vcol.has(name))
214
+ vcol.set(name, !!cdA && cdWhite.get(name) === false);
215
+ }
216
+ const al = g.findAttrib('Alpha', ['vertex', 'point', 'prim', 'detail']);
217
+ if (al && al.attr.type === 'float' && al.attr.data.some((x) => x < 1))
218
+ transparent.push('Alpha attribute below 1');
219
+ // MikkTSpace frames for normal-mapped triangles (computed once over every triangle: the frames do not depend on the
220
+ // material, and one call keeps the soup contiguous)
221
+ const anyNormal = [...mats.values()].some((m) => m.normalMap);
222
+ let tan = null;
223
+ if (anyNormal && uv) {
224
+ const r = cornerTangents(g, tris, N, uv);
225
+ tan = r.tangents;
226
+ if (r.diag.uvDegenerate || r.diag.uvNonFinite)
227
+ problems.push(`${r.diag.uvDegenerate + r.diag.uvNonFinite} triangles have collapsed or non-finite uvs: their normal map has no orientation (fallback frame)`);
228
+ }
229
+ if (!uv && [...mats.values()].some((m) => m.baseMap || m.normalMap || m.ormMap || m.roughMap))
230
+ problems.push('the geometry has no uv attribute: texture maps are not shown');
231
+ if (transparent.length)
232
+ notes.push(`pbr: transparency is not evaluated, shaded opaque (${[...new Set(transparent)].join('; ')})`);
233
+ for (const pr of new Set(problems))
234
+ notes.push(`pbr: ${pr}`);
235
+ let camL = RIG.map((l) => ({ d: l.d, c: l.c }));
236
+ const gain = 2 ** exposure;
237
+ const n = [0, 0, 0], f = new Float64Array(9), tx = [0, 0, 0, 0], base = [0, 0, 0], e = [0, 0, 0], c3 = [0, 0, 0];
238
+ const uvAt = (t, w0, w1, w2, out) => {
239
+ const a = tris[t * 3] * 2, b = tris[t * 3 + 1] * 2, c = tris[t * 3 + 2] * 2;
240
+ out[0] = uv[a] * w0 + uv[b] * w1 + uv[c] * w2;
241
+ out[1] = uv[a + 1] * w0 + uv[b + 1] * w1 + uv[c + 1] * w2;
242
+ };
243
+ const uvp = [0, 0];
244
+ const mapsUsed = new Set();
245
+ for (const m of mats.values()) {
246
+ if (m.baseMap)
247
+ mapsUsed.add('base colour');
248
+ if (m.normalMap)
249
+ mapsUsed.add('normal');
250
+ if (m.ormMap)
251
+ mapsUsed.add('orm');
252
+ if (m.roughMap)
253
+ mapsUsed.add('roughness');
254
+ }
255
+ const summary = `${mats.size} material${mats.size === 1 ? '' : 's'}${mapsUsed.size ? `, maps ${[...mapsUsed].join('/')}` : ''}`;
256
+ return {
257
+ summary, hasUV: !!uv, uvAt,
258
+ camera(r, u, fw) { camL = RIG.map((l) => ({ d: [0, 1, 2].map((k) => r[k] * l.d[0] + u[k] * l.d[1] - fw[k] * l.d[2]), c: l.c })); },
259
+ shade(t, w0, w1, w2, dudx, dvdx, dudy, dvdy, view, back, out) {
260
+ const m = triMat[t], a = tris[t * 3], b = tris[t * 3 + 1], c = tris[t * 3 + 2];
261
+ if (uv)
262
+ uvAt(t, w0, w1, w2, uvp);
263
+ const lod = (sz) => 0.5 * Math.log2(Math.max(1e-30, Math.max((dudx * sz[0].w) ** 2 + (dvdx * sz[0].h) ** 2, (dudy * sz[0].w) ** 2 + (dvdy * sz[0].h) ** 2)));
264
+ // base colour
265
+ if (vcol.get(pm ? pm[triPrim[t]] : '')) {
266
+ cdOf(a, triPrim[t], c3);
267
+ base[0] = c3[0] * w0;
268
+ base[1] = c3[1] * w0;
269
+ base[2] = c3[2] * w0;
270
+ cdOf(b, triPrim[t], c3);
271
+ base[0] += c3[0] * w1;
272
+ base[1] += c3[1] * w1;
273
+ base[2] += c3[2] * w1;
274
+ cdOf(c, triPrim[t], c3);
275
+ base[0] += c3[0] * w2;
276
+ base[1] += c3[1] * w2;
277
+ base[2] += c3[2] * w2;
278
+ for (let k = 0; k < 3; k++)
279
+ base[k] = srgbToLinear(Math.max(0, Math.min(1, base[k])));
280
+ }
281
+ else if (m.baseMap && uv) {
282
+ base[0] = base[1] = base[2] = 1;
283
+ }
284
+ else {
285
+ base[0] = m.base[0];
286
+ base[1] = m.base[1];
287
+ base[2] = m.base[2];
288
+ }
289
+ if (m.baseMap && uv) {
290
+ sampleTri(m.baseMap, uvp[0], uvp[1], lod(m.baseMap), tx);
291
+ base[0] *= tx[0];
292
+ base[1] *= tx[1];
293
+ base[2] *= tx[2];
294
+ }
295
+ if (m.unlit) {
296
+ out[0] = linearToSrgb(Math.min(1, base[0]));
297
+ out[1] = linearToSrgb(Math.min(1, base[1]));
298
+ out[2] = linearToSrgb(Math.min(1, base[2]));
299
+ return;
300
+ }
301
+ let rough = m.roughness, metal = m.metallic, ao = 1;
302
+ if (m.ormMap && uv) {
303
+ sampleTri(m.ormMap, uvp[0], uvp[1], lod(m.ormMap), tx);
304
+ ao = tx[0];
305
+ rough = tx[1];
306
+ metal = tx[2];
307
+ }
308
+ else if (m.roughMap && uv) {
309
+ sampleTri(m.roughMap, uvp[0], uvp[1], lod(m.roughMap), tx);
310
+ rough = m.roughMap[0].ch === 4 ? tx[1] : tx[0];
311
+ }
312
+ rough = Math.max(0.045, Math.min(1, rough));
313
+ metal = Math.max(0, Math.min(1, metal));
314
+ ao = Math.max(0, Math.min(1, ao));
315
+ // normal: interpolated vertex normal, then the tangent-space map in the MikkTSpace frame
316
+ n[0] = N[a * 3] * w0 + N[b * 3] * w1 + N[c * 3] * w2;
317
+ n[1] = N[a * 3 + 1] * w0 + N[b * 3 + 1] * w1 + N[c * 3 + 1] * w2;
318
+ n[2] = N[a * 3 + 2] * w0 + N[b * 3 + 2] * w1 + N[c * 3 + 2] * w2;
319
+ if (m.normalMap && tan) {
320
+ const o = t * 12;
321
+ const ttx = tan[o] * w0 + tan[o + 4] * w1 + tan[o + 8] * w2, tty = tan[o + 1] * w0 + tan[o + 5] * w1 + tan[o + 9] * w2;
322
+ const ttz = tan[o + 2] * w0 + tan[o + 6] * w1 + tan[o + 10] * w2, tw = tan[o + 3] * w0 + tan[o + 7] * w1 + tan[o + 11] * w2;
323
+ if (shadingFrame(n[0], n[1], n[2], ttx, tty, ttz, tw, f)) {
324
+ sampleTri(m.normalMap, uvp[0], uvp[1], lod(m.normalMap), tx);
325
+ const x = tx[0] * 2 - 1, y = tx[1] * 2 - 1, z = tx[2] * 2 - 1;
326
+ for (let k = 0; k < 3; k++)
327
+ n[k] = f[k] * x + f[3 + k] * y + f[6 + k] * z;
328
+ }
329
+ }
330
+ let l = Math.hypot(n[0], n[1], n[2]) || 1;
331
+ if (back)
332
+ l = -l;
333
+ n[0] /= l;
334
+ n[1] /= l;
335
+ n[2] /= l;
336
+ const NoV = Math.max(1e-4, n[0] * view[0] + n[1] * view[1] + n[2] * view[2]);
337
+ const alpha = rough * rough, a2 = alpha * alpha;
338
+ const F0 = [0, 1, 2].map((k) => 0.04 + (base[k] - 0.04) * metal);
339
+ const diff = [0, 1, 2].map((k) => (base[k] * (1 - metal)) / Math.PI);
340
+ let r = 0, gg = 0, bb = 0;
341
+ for (const L of camL) {
342
+ const NoL = n[0] * L.d[0] + n[1] * L.d[1] + n[2] * L.d[2];
343
+ if (NoL <= 0)
344
+ continue;
345
+ const hx = L.d[0] + view[0], hy = L.d[1] + view[1], hz = L.d[2] + view[2], hl = Math.hypot(hx, hy, hz) || 1;
346
+ const NoH = Math.max(0, (n[0] * hx + n[1] * hy + n[2] * hz) / hl), VoH = Math.max(0, (view[0] * hx + view[1] * hy + view[2] * hz) / hl);
347
+ const dd = NoH * NoH * (a2 - 1) + 1, D = a2 / (Math.PI * dd * dd);
348
+ const Vis = 0.5 / (NoL * Math.sqrt(NoV * NoV * (1 - a2) + a2) + NoV * Math.sqrt(NoL * NoL * (1 - a2) + a2));
349
+ const fw = (1 - VoH) ** 5;
350
+ for (let k = 0; k < 3; k++) {
351
+ const F = F0[k] + (1 - F0[k]) * fw;
352
+ const v = ((1 - F) * diff[k] + D * Vis * F) * L.c[k] * NoL;
353
+ if (k === 0)
354
+ r += v;
355
+ else if (k === 1)
356
+ gg += v;
357
+ else
358
+ bb += v;
359
+ }
360
+ }
361
+ // indirect: sky/ground irradiance (diffuse) and the environment along the reflection (specular), both occluded
362
+ env(n[1], 1, e);
363
+ const ir = [e[0], e[1], e[2]];
364
+ const RdotN = 2 * NoV, ry = RdotN * n[1] - view[1];
365
+ env(ry, rough, e);
366
+ // Karis' analytic environment BRDF
367
+ const c0 = [-1, -0.0275, -0.572, 0.022], c1 = [1, 0.0425, 1.04, -0.04];
368
+ const q = [rough * c0[0] + c1[0], rough * c0[1] + c1[1], rough * c0[2] + c1[2], rough * c0[3] + c1[3]];
369
+ const a004 = Math.min(q[0] * q[0], 2 ** (-9.28 * NoV)) * q[0] + q[1];
370
+ const A = a004 * -1.04 + q[2], B = a004 * 1.04 + q[3];
371
+ for (let k = 0; k < 3; k++) {
372
+ const ind = (base[k] * (1 - metal) * ir[k] + e[k] * (F0[k] * A + B)) * ao;
373
+ out[k] = ((k === 0 ? r : k === 1 ? gg : bb) + ind + m.emissive[k]) * gain;
374
+ }
375
+ tone(out);
376
+ },
377
+ };
378
+ }
@@ -0,0 +1,69 @@
1
+ import type { Geometry } from '../core/geometry.ts';
2
+ import type { GraphSpec } from '../graph/types.ts';
3
+ import type { ExportOptions } from '../io/common.ts';
4
+ /** Render options of a thumbnail: one persp view, `size` px (256), matcap, no view label, plus the graph's meta.thumbnail_render. */
5
+ export declare function thumbOptions(g: GraphSpec, size?: number): {
6
+ views?: import("./raster.ts").ViewName[];
7
+ size?: number | [number, number];
8
+ transparent?: boolean;
9
+ underlay?: string | null;
10
+ underlayImage?: import("./raster.ts").UnderlayImage | null;
11
+ underlayOpacity?: number;
12
+ underlayFit?: import("./raster.ts").UnderlayFit;
13
+ sockets?: boolean;
14
+ wireframe?: boolean | 'auto' | import("./raster.ts").WireMode;
15
+ colorBy?: string | null;
16
+ highlight?: {
17
+ cls: 'point' | 'prim';
18
+ mask: Uint8Array;
19
+ label?: string;
20
+ } | null;
21
+ points?: boolean | 'auto';
22
+ grid?: boolean;
23
+ azimuth?: number;
24
+ elevation?: number;
25
+ zoom?: number;
26
+ target?: import("../core/math.ts").Vec3 | null;
27
+ ssaa?: number;
28
+ maxTriangles?: number;
29
+ heightfieldRes?: number;
30
+ heightfieldLayer?: string;
31
+ title?: string;
32
+ checker?: boolean;
33
+ hardAngle?: number;
34
+ pointNumbers?: boolean;
35
+ primNumbers?: boolean;
36
+ maxLabels?: number;
37
+ sectionAxis?: import("./raster.ts").Axis;
38
+ sectionOffset?: number;
39
+ sectionAbsolute?: boolean;
40
+ clip?: import("./raster.ts").ClipOptions | null;
41
+ glyphs?: import("./raster.ts").GlyphMode;
42
+ glyphAttrib?: string | null;
43
+ glyphScale?: number;
44
+ maxGlyphs?: number;
45
+ labelGroups?: boolean;
46
+ labelPieces?: boolean;
47
+ labelAttrib?: string | null;
48
+ legend?: boolean;
49
+ shading?: import("./raster.ts").ShadingMode;
50
+ exposure?: number;
51
+ pbrTextures?: import("./pbr.ts").PBRTextures;
52
+ aoRadius?: number;
53
+ orthoScale?: number;
54
+ scale?: number;
55
+ annotate?: boolean;
56
+ viewLabels?: boolean;
57
+ textures?: boolean;
58
+ texture?: string;
59
+ };
60
+ /** A thumbnail PNG: the square view tile only, without the footer. */
61
+ export declare function thumbnailPNG(geo: Geometry, g: GraphSpec, deflate: (d: Uint8Array) => Uint8Array, size?: number): Uint8Array;
62
+ /**
63
+ * The GLB a viewer page shows: heightfields as meshes (with `heightfieldLayer` in red, default the mask), images as
64
+ * textured quads, a material output as spheres wearing its materials, lines as lines, no custom attributes. `compress: 'meshopt'` for files kept on disk (the page's
65
+ * loader decodes it).
66
+ */
67
+ export declare function previewGLB(g: Geometry, o?: Pick<ExportOptions, 'compress'> & {
68
+ heightfieldLayer?: string;
69
+ }): Promise<Uint8Array>;
@@ -0,0 +1,26 @@
1
+ import { exportGeometryAsync } from '../io/export.js';
2
+ import { withHeightfieldPreview } from '../core/heightfield.js';
3
+ import { withImagePreview, withMaterialPreview } from './texview.js';
4
+ import { renderGeometry } from './raster.js';
5
+ import { renderArgs } from './options.js';
6
+ import { encodePNG } from './png.js';
7
+ /** Render options of a thumbnail: one persp view, `size` px (256), matcap, no view label, plus the graph's meta.thumbnail_render. */
8
+ export function thumbOptions(g, size = 256) {
9
+ const extra = g.meta?.thumbnail_render ?? {};
10
+ return { ...renderArgs({ views: 'persp', size, shading: 'matcap', wireframe: false, annotate: false, view_labels: false, ...extra }) };
11
+ }
12
+ /** A thumbnail PNG: the square view tile only, without the footer. */
13
+ export function thumbnailPNG(geo, g, deflate, size = 256) {
14
+ const r = renderGeometry(geo, thumbOptions(g, size));
15
+ const w = r.width; // a single square view tile sits above the footer
16
+ return encodePNG(r.rgba.subarray(0, w * w * 4), w, w, deflate);
17
+ }
18
+ /**
19
+ * The GLB a viewer page shows: heightfields as meshes (with `heightfieldLayer` in red, default the mask), images as
20
+ * textured quads, a material output as spheres wearing its materials, lines as lines, no custom attributes. `compress: 'meshopt'` for files kept on disk (the page's
21
+ * loader decodes it).
22
+ */
23
+ export function previewGLB(g, o = {}) {
24
+ const { heightfieldLayer, ...rest } = o;
25
+ return exportGeometryAsync(withImagePreview(withMaterialPreview(withHeightfieldPreview(g, 256, heightfieldLayer))), 'glb', { splitByName: false, lineMode: 'lines', custom: false, ...rest });
26
+ }