formacad 0.1.0 → 0.2.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/README.md +32 -21
- package/build/cli/src/forma.js +276 -15
- package/build/cli/src/forma.js.map +1 -1
- package/build/cli/src/mcp.d.ts +1 -0
- package/build/cli/src/mcp.js +495 -0
- package/build/cli/src/mcp.js.map +1 -0
- package/build/cli/src/preview.d.ts +31 -3
- package/build/cli/src/preview.js +235 -76
- package/build/cli/src/preview.js.map +1 -1
- package/build/core/src/export2d.d.ts +3 -0
- package/build/core/src/export2d.js +48 -0
- package/build/core/src/export2d.js.map +1 -1
- package/build/core/src/geometry.d.ts +1 -0
- package/build/core/src/geometry.js +1 -1
- package/build/core/src/geometry.js.map +1 -1
- package/build/core/src/gltf.d.ts +6 -0
- package/build/core/src/gltf.js +154 -0
- package/build/core/src/gltf.js.map +1 -0
- package/build/core/src/importers.d.ts +1 -0
- package/build/core/src/importers.js +314 -0
- package/build/core/src/importers.js.map +1 -1
- package/build/core/src/index.d.ts +17 -6
- package/build/core/src/index.js +79 -7
- package/build/core/src/index.js.map +1 -1
- package/build/core/src/interp.d.ts +37 -1
- package/build/core/src/interp.js +1048 -62
- package/build/core/src/interp.js.map +1 -1
- package/build/core/src/lexer.js +1 -1
- package/build/core/src/lexer.js.map +1 -1
- package/build/core/src/modeling.d.ts +18 -0
- package/build/core/src/modeling.js +483 -0
- package/build/core/src/modeling.js.map +1 -0
- package/build/core/src/parser.js +82 -12
- package/build/core/src/parser.js.map +1 -1
- package/build/core/src/scad/colors.d.ts +1 -0
- package/build/core/src/scad/colors.js +37 -0
- package/build/core/src/scad/colors.js.map +1 -0
- package/build/core/src/scad/convert.d.ts +33 -0
- package/build/core/src/scad/convert.js +2842 -0
- package/build/core/src/scad/convert.js.map +1 -0
- package/build/core/src/scad/parser.d.ts +239 -0
- package/build/core/src/scad/parser.js +578 -0
- package/build/core/src/scad/parser.js.map +1 -0
- package/build/core/src/scad/sources.d.ts +39 -0
- package/build/core/src/scad/sources.js +171 -0
- package/build/core/src/scad/sources.js.map +1 -0
- package/build/core/src/surface.d.ts +21 -0
- package/build/core/src/surface.js +253 -0
- package/build/core/src/surface.js.map +1 -0
- package/build/core/src/values.d.ts +31 -1
- package/build/core/src/values.js +72 -1
- package/build/core/src/values.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Where OpenSCAD files come from: links the user pastes, include/use paths, and libraries.
|
|
2
|
+
// Pure functions (no network, no DOM) so the website, the CLI and the tests share them.
|
|
3
|
+
/** Model sites that don't let other websites download their files (no CORS, sign-in, or terms of use). */
|
|
4
|
+
const MODEL_SITES = [
|
|
5
|
+
[/(^|\.)thingiverse\.com$/, 'Thingiverse'],
|
|
6
|
+
[/(^|\.)printables\.com$/, 'Printables'],
|
|
7
|
+
[/(^|\.)makerworld\.com$/, 'MakerWorld'],
|
|
8
|
+
[/(^|\.)cults3d\.com$/, 'Cults3D'],
|
|
9
|
+
[/(^|\.)myminifactory\.com$/, 'MyMiniFactory'],
|
|
10
|
+
[/(^|\.)thangs\.com$/, 'Thangs'],
|
|
11
|
+
[/(^|\.)grabcad\.com$/, 'GrabCAD'],
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* Turns a pasted link into a downloadable raw-file URL, or explains why it can't be downloaded from the browser.
|
|
15
|
+
* GitHub "blob" pages, GitHub "raw" redirects, Gists and GitLab blob pages are rewritten to their raw files.
|
|
16
|
+
*/
|
|
17
|
+
export function normalizeModelLink(input) {
|
|
18
|
+
const text = input.trim();
|
|
19
|
+
if (!text)
|
|
20
|
+
return { ok: false, reason: 'Paste a link to a .scad file first.' };
|
|
21
|
+
let u;
|
|
22
|
+
try {
|
|
23
|
+
u = new URL(text);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return { ok: false, reason: "This doesn't look like a link. It should start with https://" };
|
|
27
|
+
}
|
|
28
|
+
if (u.protocol === 'http:')
|
|
29
|
+
return { ok: false, reason: 'Only secure https:// links are supported.' };
|
|
30
|
+
if (u.protocol !== 'https:')
|
|
31
|
+
return { ok: false, reason: 'Only https:// links are supported.' };
|
|
32
|
+
if (u.username || u.password)
|
|
33
|
+
return { ok: false, reason: 'Links with a user name or password are not supported.' };
|
|
34
|
+
const host = u.hostname.toLowerCase();
|
|
35
|
+
for (const [re, site] of MODEL_SITES) {
|
|
36
|
+
if (re.test(host)) {
|
|
37
|
+
return {
|
|
38
|
+
ok: false,
|
|
39
|
+
reason: `${site} doesn't allow other websites to download its files. Open the model page, download the .scad file `
|
|
40
|
+
+ '(or the whole .zip), and drop it here.',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const parts = u.pathname.split('/').filter(Boolean);
|
|
45
|
+
if (host === 'github.com') {
|
|
46
|
+
// /owner/repo/blob/ref/path or /owner/repo/raw/ref/path
|
|
47
|
+
if (parts.length >= 5 && (parts[2] === 'blob' || parts[2] === 'raw')) {
|
|
48
|
+
return { ok: true, url: `https://raw.githubusercontent.com/${parts[0]}/${parts[1]}/${parts.slice(3).join('/')}` };
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
reason: 'This GitHub link is not a file. Open the .scad file on GitHub and copy the link from the address bar.',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (host === 'gist.github.com') {
|
|
56
|
+
if (parts.length >= 2)
|
|
57
|
+
return { ok: true, url: `https://gist.githubusercontent.com/${parts[0]}/${parts[1]}/raw` };
|
|
58
|
+
if (parts.length === 1)
|
|
59
|
+
return { ok: false, reason: 'This Gist link has no user name. Use the full link, like https://gist.github.com/user/id' };
|
|
60
|
+
}
|
|
61
|
+
if (host === 'gitlab.com') {
|
|
62
|
+
const i = parts.indexOf('-');
|
|
63
|
+
if (i > 0 && parts[i + 1] === 'blob') {
|
|
64
|
+
const p = [...parts];
|
|
65
|
+
p[i + 1] = 'raw';
|
|
66
|
+
return { ok: true, url: `https://gitlab.com/${p.join('/')}` };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { ok: true, url: u.href };
|
|
70
|
+
}
|
|
71
|
+
/** Explanation shown when a download fails in the browser (usually CORS). */
|
|
72
|
+
export function fetchFailureReason(url, status) {
|
|
73
|
+
let host = url;
|
|
74
|
+
try {
|
|
75
|
+
host = new URL(url).hostname;
|
|
76
|
+
}
|
|
77
|
+
catch { /* keep the text */ }
|
|
78
|
+
if (status === 404)
|
|
79
|
+
return `The file was not found (404) at ${host}. Check that the link opens the .scad file itself.`;
|
|
80
|
+
if (status === 401 || status === 403)
|
|
81
|
+
return `${host} refused the download (${status}). The file may be private.`;
|
|
82
|
+
if (status !== null)
|
|
83
|
+
return `${host} answered with an error (${status}).`;
|
|
84
|
+
return `${host} doesn't allow other websites to read its files (CORS), or it can't be reached. `
|
|
85
|
+
+ 'Download the .scad file and drop it here instead. Links to GitHub, GitHub Gist and raw.githubusercontent.com work directly.';
|
|
86
|
+
}
|
|
87
|
+
/** True when downloaded text looks like a web page instead of OpenSCAD code. */
|
|
88
|
+
export function looksLikeHtml(text) {
|
|
89
|
+
const head = text.slice(0, 512).trimStart().toLowerCase();
|
|
90
|
+
return head.startsWith('<!doctype html') || head.startsWith('<html') || (head.startsWith('<') && head.includes('<head'));
|
|
91
|
+
}
|
|
92
|
+
/** Libraries people include by path (<BOSL2/std.scad>), resolved from OpenSCAD's library folder. */
|
|
93
|
+
export const KNOWN_LIBRARIES = {
|
|
94
|
+
BOSL2: {
|
|
95
|
+
name: 'BOSL2', base: null,
|
|
96
|
+
why: 'BOSL2 is a very large library built on OpenSCAD features that Forma does not have '
|
|
97
|
+
+ '(function literals, undef, special $-variables and attachments)',
|
|
98
|
+
alternative: 'Forma\'s built-in std/ libraries cover threads, fasteners, joints, enclosures and patterns',
|
|
99
|
+
},
|
|
100
|
+
BOSL: {
|
|
101
|
+
name: 'BOSL', base: null,
|
|
102
|
+
why: 'BOSL relies on undef, special $-variables and other OpenSCAD features that Forma does not have',
|
|
103
|
+
alternative: 'Forma\'s built-in std/ libraries cover threads, fasteners, joints, enclosures and patterns',
|
|
104
|
+
},
|
|
105
|
+
NopSCADlib: {
|
|
106
|
+
name: 'NopSCADlib', base: null,
|
|
107
|
+
why: 'NopSCADlib is a very large library that relies on undef, special $-variables and OpenSCAD-only functions',
|
|
108
|
+
},
|
|
109
|
+
dotSCAD: {
|
|
110
|
+
name: 'dotSCAD', base: null,
|
|
111
|
+
why: 'dotSCAD relies on function literals and other OpenSCAD features that Forma does not have',
|
|
112
|
+
},
|
|
113
|
+
MCAD: { name: 'MCAD', base: 'https://raw.githubusercontent.com/openscad/MCAD/master/' },
|
|
114
|
+
};
|
|
115
|
+
/** The library a path like "BOSL2/std.scad" belongs to, if any. */
|
|
116
|
+
export function libraryOf(path) {
|
|
117
|
+
const first = path.replace(/\\/g, '/').split('/')[0];
|
|
118
|
+
return Object.prototype.hasOwnProperty.call(KNOWN_LIBRARIES, first) ? KNOWN_LIBRARIES[first] : null;
|
|
119
|
+
}
|
|
120
|
+
function joinKey(fromKey, path) {
|
|
121
|
+
const p = path.replace(/\\/g, '/');
|
|
122
|
+
if (/^https:\/\//.test(fromKey)) {
|
|
123
|
+
try {
|
|
124
|
+
return new URL(p, fromKey).href;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return p;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (p.startsWith('/'))
|
|
131
|
+
return p.slice(1);
|
|
132
|
+
const dir = fromKey.includes('/') ? fromKey.slice(0, fromKey.lastIndexOf('/') + 1) : '';
|
|
133
|
+
const out = [];
|
|
134
|
+
for (const seg of (dir + p).split('/')) {
|
|
135
|
+
if (seg === '' || seg === '.')
|
|
136
|
+
continue;
|
|
137
|
+
if (seg === '..')
|
|
138
|
+
out.pop();
|
|
139
|
+
else
|
|
140
|
+
out.push(seg);
|
|
141
|
+
}
|
|
142
|
+
return out.join('/');
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Where an include/use path may be found, in OpenSCAD's order: next to the including file first, then the
|
|
146
|
+
* library folder (for known downloadable libraries, as a raw GitHub URL).
|
|
147
|
+
* Keys are URLs (for downloaded files) or relative paths (for dropped files).
|
|
148
|
+
*/
|
|
149
|
+
export function includeCandidates(fromKey, path) {
|
|
150
|
+
const out = [joinKey(fromKey, path)];
|
|
151
|
+
const lib = libraryOf(path);
|
|
152
|
+
if (lib && lib.base) {
|
|
153
|
+
const rest = path.replace(/\\/g, '/').split('/').slice(1).join('/');
|
|
154
|
+
out.push(lib.base + rest);
|
|
155
|
+
}
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
/** All include/use paths in a source (a quick scan, so the website can download them before converting). */
|
|
159
|
+
export function scanIncludes(source) {
|
|
160
|
+
const out = [];
|
|
161
|
+
const noComments = source.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, ' ')).replace(/\/\/[^\n]*/g, '');
|
|
162
|
+
const lines = noComments.split('\n');
|
|
163
|
+
lines.forEach((l, i) => {
|
|
164
|
+
const re = /\b(include|use)\s*<([^>\n]+)>/g;
|
|
165
|
+
let m;
|
|
166
|
+
while ((m = re.exec(l)))
|
|
167
|
+
out.push({ kind: m[1], path: m[2].trim(), line: i + 1 });
|
|
168
|
+
});
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=sources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources.js","sourceRoot":"","sources":["../../../../packages/core/src/scad/sources.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,wFAAwF;AAUxF,0GAA0G;AAC1G,MAAM,WAAW,GAAuB;IACtC,CAAC,yBAAyB,EAAE,aAAa,CAAC;IAC1C,CAAC,wBAAwB,EAAE,YAAY,CAAC;IACxC,CAAC,wBAAwB,EAAE,YAAY,CAAC;IACxC,CAAC,qBAAqB,EAAE,SAAS,CAAC;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CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,4GAA4G;AAC5G,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,MAAM,GAAG,GAA8D,EAAE,CAAC;IAC1E,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;IACnH,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACrB,MAAM,EAAE,GAAG,gCAAgC,CAAC;QAC5C,IAAI,CAAyB,CAAC;QAC9B,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAAE,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAsB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACzG,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Pos } from './errors.js';
|
|
2
|
+
import { Poly } from './geometry.js';
|
|
3
|
+
export declare const MAX_SURFACE_PNG_DIM = 4096;
|
|
4
|
+
export declare const MAX_SURFACE_PNG_PIXELS: number;
|
|
5
|
+
export declare const MAX_SURFACE_GRID_CELLS = 1000000;
|
|
6
|
+
export declare const MAX_SURFACE_MESH_RES = 400;
|
|
7
|
+
export declare const MAX_SURFACE_MESH_CELLS = 160000;
|
|
8
|
+
export interface HeightGrid {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
/** Normalized 0..1 (for PNG) or raw numeric heights (for DAT/CSV), row-major top-to-bottom. */
|
|
12
|
+
data: Float32Array;
|
|
13
|
+
}
|
|
14
|
+
/** Decode an 8-bit or 16-bit non-interlaced PNG into a 0..1 grayscale HeightGrid. */
|
|
15
|
+
export declare function decodePngGray(bytes: Uint8Array, pos?: Pos | null): HeightGrid;
|
|
16
|
+
/** Parse whitespace- or comma-separated numeric height grid (.dat / .csv / .txt). */
|
|
17
|
+
export declare function parseHeightText(text: string, pos?: Pos | null): HeightGrid;
|
|
18
|
+
/** Downsample a HeightGrid so max(width, height) <= maxRes using bilinear sampling. */
|
|
19
|
+
export declare function downsampleGrid(grid: HeightGrid, maxRes: number): HeightGrid;
|
|
20
|
+
/** Build a closed, watertight heightmap solid with flat base at z = 0. */
|
|
21
|
+
export declare function buildSurfaceMesh(cols: number, rows: number, zAt: (c: number, r: number) => number, width: number, depth: number, center: boolean): Poly[];
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// Surface heightmap builder & zero-dependency PNG/DAT decoder (reuses inflate.ts).
|
|
2
|
+
// Produces a guaranteed-watertight closed solid with flat base at z = 0.
|
|
3
|
+
import { FormaError } from './errors.js';
|
|
4
|
+
import { makePoly } from './geometry.js';
|
|
5
|
+
import { inflateRaw } from './inflate.js';
|
|
6
|
+
export const MAX_SURFACE_PNG_DIM = 4096;
|
|
7
|
+
export const MAX_SURFACE_PNG_PIXELS = 4096 * 4096;
|
|
8
|
+
export const MAX_SURFACE_GRID_CELLS = 1_000_000;
|
|
9
|
+
export const MAX_SURFACE_MESH_RES = 400;
|
|
10
|
+
export const MAX_SURFACE_MESH_CELLS = 160_000;
|
|
11
|
+
function paeth(a, b, c) {
|
|
12
|
+
const p = a + b - c;
|
|
13
|
+
const pa = Math.abs(p - a), pb = Math.abs(p - b), pc = Math.abs(p - c);
|
|
14
|
+
return pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
|
|
15
|
+
}
|
|
16
|
+
/** Decode an 8-bit or 16-bit non-interlaced PNG into a 0..1 grayscale HeightGrid. */
|
|
17
|
+
export function decodePngGray(bytes, pos = null) {
|
|
18
|
+
const sig = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
19
|
+
if (bytes.length < 33 || sig.some((b, i) => bytes[i] !== b)) {
|
|
20
|
+
throw new FormaError('Surface: not a valid PNG image', pos);
|
|
21
|
+
}
|
|
22
|
+
const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
23
|
+
let width = 0, height = 0, bitDepth = 0, colorType = 0, interlace = 0;
|
|
24
|
+
let palette = null;
|
|
25
|
+
const idats = [];
|
|
26
|
+
let p = 8;
|
|
27
|
+
while (p + 8 <= bytes.length) {
|
|
28
|
+
const len = dv.getUint32(p, false);
|
|
29
|
+
const type = String.fromCharCode(bytes[p + 4], bytes[p + 5], bytes[p + 6], bytes[p + 7]);
|
|
30
|
+
const bodyStart = p + 8;
|
|
31
|
+
const bodyEnd = bodyStart + len;
|
|
32
|
+
if (bodyEnd > bytes.length)
|
|
33
|
+
break;
|
|
34
|
+
if (type === 'IHDR') {
|
|
35
|
+
width = dv.getUint32(bodyStart, false);
|
|
36
|
+
height = dv.getUint32(bodyStart + 4, false);
|
|
37
|
+
bitDepth = bytes[bodyStart + 8];
|
|
38
|
+
colorType = bytes[bodyStart + 9];
|
|
39
|
+
interlace = bytes[bodyStart + 12];
|
|
40
|
+
}
|
|
41
|
+
else if (type === 'PLTE') {
|
|
42
|
+
palette = bytes.subarray(bodyStart, bodyEnd);
|
|
43
|
+
}
|
|
44
|
+
else if (type === 'IDAT') {
|
|
45
|
+
idats.push(bytes.subarray(bodyStart, bodyEnd));
|
|
46
|
+
}
|
|
47
|
+
else if (type === 'IEND') {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
p = bodyEnd + 4; // skip CRC
|
|
51
|
+
}
|
|
52
|
+
if (!width || !height)
|
|
53
|
+
throw new FormaError('Surface: PNG is missing image header', pos);
|
|
54
|
+
if (width < 2 || height < 2) {
|
|
55
|
+
throw new FormaError(`Surface: PNG must be at least 2x2 pixels (got ${width}x${height})`, pos);
|
|
56
|
+
}
|
|
57
|
+
if (width > MAX_SURFACE_PNG_DIM || height > MAX_SURFACE_PNG_DIM || width * height > MAX_SURFACE_PNG_PIXELS) {
|
|
58
|
+
throw new FormaError(`Surface: PNG resolution ${width}x${height} exceeds the ${MAX_SURFACE_PNG_DIM}px limit — resize the image first`, pos);
|
|
59
|
+
}
|
|
60
|
+
if (!idats.length)
|
|
61
|
+
throw new FormaError('Surface: PNG is missing image data', pos);
|
|
62
|
+
if (interlace !== 0)
|
|
63
|
+
throw new FormaError('Surface: interlaced PNGs are not supported — re-save as non-interlaced PNG', pos);
|
|
64
|
+
if (bitDepth !== 8 && bitDepth !== 16)
|
|
65
|
+
throw new FormaError(`Surface: unsupported PNG bit depth ${bitDepth} (use 8-bit or 16-bit PNG)`, pos);
|
|
66
|
+
const channels = colorType === 0 ? 1 : colorType === 2 ? 3 : colorType === 3 ? 1 : colorType === 4 ? 2 : colorType === 6 ? 4 : 0;
|
|
67
|
+
if (!channels)
|
|
68
|
+
throw new FormaError(`Surface: unsupported PNG color type ${colorType}`, pos);
|
|
69
|
+
const bpp = channels * (bitDepth / 8);
|
|
70
|
+
const stride = width * bpp;
|
|
71
|
+
const totalLen = idats.reduce((s, c) => s + c.length, 0);
|
|
72
|
+
const zlib = new Uint8Array(totalLen);
|
|
73
|
+
let off = 0;
|
|
74
|
+
for (const c of idats) {
|
|
75
|
+
zlib.set(c, off);
|
|
76
|
+
off += c.length;
|
|
77
|
+
}
|
|
78
|
+
if (zlib.length < 6)
|
|
79
|
+
throw new FormaError('Surface: PNG compressed stream is truncated', pos);
|
|
80
|
+
const hdrLen = (zlib[1] & 0x20) ? 6 : 2;
|
|
81
|
+
let raw;
|
|
82
|
+
try {
|
|
83
|
+
raw = inflateRaw(zlib.subarray(hdrLen), height * (stride + 1));
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
throw new FormaError(`Surface: failed to decompress PNG (${e?.message ?? e})`, pos);
|
|
87
|
+
}
|
|
88
|
+
const recon = new Uint8Array(height * stride);
|
|
89
|
+
for (let y = 0; y < height; y++) {
|
|
90
|
+
const f = raw[y * (stride + 1)];
|
|
91
|
+
const srcOff = y * (stride + 1) + 1;
|
|
92
|
+
const dstOff = y * stride;
|
|
93
|
+
const prevOff = (y - 1) * stride;
|
|
94
|
+
for (let x = 0; x < stride; x++) {
|
|
95
|
+
const v = raw[srcOff + x];
|
|
96
|
+
const a = x >= bpp ? recon[dstOff + x - bpp] : 0;
|
|
97
|
+
const b = y > 0 ? recon[prevOff + x] : 0;
|
|
98
|
+
const c = x >= bpp && y > 0 ? recon[prevOff + x - bpp] : 0;
|
|
99
|
+
let r = v;
|
|
100
|
+
if (f === 1)
|
|
101
|
+
r = (v + a) & 0xff;
|
|
102
|
+
else if (f === 2)
|
|
103
|
+
r = (v + b) & 0xff;
|
|
104
|
+
else if (f === 3)
|
|
105
|
+
r = (v + ((a + b) >> 1)) & 0xff;
|
|
106
|
+
else if (f === 4)
|
|
107
|
+
r = (v + paeth(a, b, c)) & 0xff;
|
|
108
|
+
else if (f !== 0)
|
|
109
|
+
throw new FormaError(`Surface: unknown PNG scanline filter ${f}`, pos);
|
|
110
|
+
recon[dstOff + x] = r;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const data = new Float32Array(width * height);
|
|
114
|
+
const is16 = bitDepth === 16;
|
|
115
|
+
const maxV = is16 ? 65535 : 255;
|
|
116
|
+
const sample = (idx) => (is16 ? ((recon[idx] << 8) | recon[idx + 1]) / maxV : recon[idx] / maxV);
|
|
117
|
+
const step = is16 ? 2 : 1;
|
|
118
|
+
for (let y = 0; y < height; y++) {
|
|
119
|
+
for (let x = 0; x < width; x++) {
|
|
120
|
+
const idx = y * stride + x * bpp;
|
|
121
|
+
let lum = 0;
|
|
122
|
+
if (colorType === 0 || colorType === 4) {
|
|
123
|
+
lum = sample(idx);
|
|
124
|
+
}
|
|
125
|
+
else if (colorType === 2 || colorType === 6) {
|
|
126
|
+
lum = 0.299 * sample(idx) + 0.587 * sample(idx + step) + 0.114 * sample(idx + 2 * step);
|
|
127
|
+
}
|
|
128
|
+
else if (colorType === 3) {
|
|
129
|
+
if (!palette)
|
|
130
|
+
throw new FormaError('Surface: indexed PNG is missing PLTE palette', pos);
|
|
131
|
+
const pi = recon[idx] * 3;
|
|
132
|
+
lum = (0.299 * palette[pi] + 0.587 * palette[pi + 1] + 0.114 * palette[pi + 2]) / 255;
|
|
133
|
+
}
|
|
134
|
+
data[y * width + x] = lum;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { width, height, data };
|
|
138
|
+
}
|
|
139
|
+
/** Parse whitespace- or comma-separated numeric height grid (.dat / .csv / .txt). */
|
|
140
|
+
export function parseHeightText(text, pos = null) {
|
|
141
|
+
const rows = [];
|
|
142
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
143
|
+
const line = rawLine.replace(/(#|\/\/).*$/, '').trim();
|
|
144
|
+
if (!line)
|
|
145
|
+
continue;
|
|
146
|
+
const nums = line.split(/[\s,;]+/).map(Number);
|
|
147
|
+
if (nums.some((n) => !Number.isFinite(n))) {
|
|
148
|
+
throw new FormaError(`Surface: non-numeric value in height file line '${line.slice(0, 40)}'`, pos);
|
|
149
|
+
}
|
|
150
|
+
rows.push(nums);
|
|
151
|
+
}
|
|
152
|
+
if (rows.length < 2 || rows[0].length < 2) {
|
|
153
|
+
throw new FormaError('Surface: height file needs at least a 2x2 grid of numbers', pos);
|
|
154
|
+
}
|
|
155
|
+
const width = rows[0].length;
|
|
156
|
+
const height = rows.length;
|
|
157
|
+
if (width * height > MAX_SURFACE_GRID_CELLS) {
|
|
158
|
+
throw new FormaError(`Surface: height grid ${width}x${height} exceeds the ${MAX_SURFACE_GRID_CELLS.toLocaleString('en')} cell limit`, pos);
|
|
159
|
+
}
|
|
160
|
+
const data = new Float32Array(width * height);
|
|
161
|
+
for (let r = 0; r < height; r++) {
|
|
162
|
+
if (rows[r].length !== width) {
|
|
163
|
+
throw new FormaError(`Surface: row ${r + 1} has ${rows[r].length} columns, expected ${width}`, pos);
|
|
164
|
+
}
|
|
165
|
+
for (let c = 0; c < width; c++)
|
|
166
|
+
data[r * width + c] = rows[r][c];
|
|
167
|
+
}
|
|
168
|
+
return { width, height, data };
|
|
169
|
+
}
|
|
170
|
+
/** Downsample a HeightGrid so max(width, height) <= maxRes using bilinear sampling. */
|
|
171
|
+
export function downsampleGrid(grid, maxRes) {
|
|
172
|
+
const { width, height, data } = grid;
|
|
173
|
+
if (Math.max(width, height) <= maxRes)
|
|
174
|
+
return grid;
|
|
175
|
+
const scale = maxRes / Math.max(width, height);
|
|
176
|
+
const nw = Math.max(2, Math.round(width * scale));
|
|
177
|
+
const nh = Math.max(2, Math.round(height * scale));
|
|
178
|
+
const out = new Float32Array(nw * nh);
|
|
179
|
+
for (let y = 0; y < nh; y++) {
|
|
180
|
+
const fy = (y / (nh - 1)) * (height - 1);
|
|
181
|
+
const y0 = Math.floor(fy), y1 = Math.min(height - 1, y0 + 1), ty = fy - y0;
|
|
182
|
+
for (let x = 0; x < nw; x++) {
|
|
183
|
+
const fx = (x / (nw - 1)) * (width - 1);
|
|
184
|
+
const x0 = Math.floor(fx), x1 = Math.min(width - 1, x0 + 1), tx = fx - x0;
|
|
185
|
+
const v00 = data[y0 * width + x0], v10 = data[y0 * width + x1];
|
|
186
|
+
const v01 = data[y1 * width + x0], v11 = data[y1 * width + x1];
|
|
187
|
+
out[y * nw + x] = (v00 * (1 - tx) + v10 * tx) * (1 - ty) + (v01 * (1 - tx) + v11 * tx) * ty;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return { width: nw, height: nh, data: out };
|
|
191
|
+
}
|
|
192
|
+
/** Build a closed, watertight heightmap solid with flat base at z = 0. */
|
|
193
|
+
export function buildSurfaceMesh(cols, rows, zAt, width, depth, center) {
|
|
194
|
+
const x0 = center ? -width / 2 : 0;
|
|
195
|
+
const y0 = center ? -depth / 2 : 0;
|
|
196
|
+
const xs = new Float64Array(cols);
|
|
197
|
+
const ys = new Float64Array(rows);
|
|
198
|
+
for (let c = 0; c < cols; c++)
|
|
199
|
+
xs[c] = x0 + (c / (cols - 1)) * width;
|
|
200
|
+
for (let r = 0; r < rows; r++)
|
|
201
|
+
ys[r] = y0 + (r / (rows - 1)) * depth;
|
|
202
|
+
const top = new Array(cols * rows);
|
|
203
|
+
for (let r = 0; r < rows; r++) {
|
|
204
|
+
for (let c = 0; c < cols; c++) {
|
|
205
|
+
const z = Math.max(0.05, zAt(c, r));
|
|
206
|
+
top[r * cols + c] = [xs[c], ys[r], z];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const T = (c, r) => top[r * cols + c];
|
|
210
|
+
const B = (c, r) => [xs[c], ys[r], 0];
|
|
211
|
+
const out = [];
|
|
212
|
+
const push = (a, b, c) => {
|
|
213
|
+
const p = makePoly([a, b, c]);
|
|
214
|
+
if (p)
|
|
215
|
+
out.push(p);
|
|
216
|
+
};
|
|
217
|
+
// Top surface (+Z)
|
|
218
|
+
for (let r = 0; r < rows - 1; r++) {
|
|
219
|
+
for (let c = 0; c < cols - 1; c++) {
|
|
220
|
+
const a = T(c, r), b = T(c + 1, r), d = T(c + 1, r + 1), e = T(c, r + 1);
|
|
221
|
+
push(a, b, d);
|
|
222
|
+
push(a, d, e);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Front wall (r = 0, -Y) & Back wall (r = rows - 1, +Y)
|
|
226
|
+
for (let c = 0; c < cols - 1; c++) {
|
|
227
|
+
push(B(c, 0), B(c + 1, 0), T(c + 1, 0));
|
|
228
|
+
push(B(c, 0), T(c + 1, 0), T(c, 0));
|
|
229
|
+
const rm = rows - 1;
|
|
230
|
+
push(B(c, rm), T(c + 1, rm), B(c + 1, rm));
|
|
231
|
+
push(B(c, rm), T(c, rm), T(c + 1, rm));
|
|
232
|
+
}
|
|
233
|
+
// Left wall (c = 0, -X) & Right wall (c = cols - 1, +X)
|
|
234
|
+
for (let r = 0; r < rows - 1; r++) {
|
|
235
|
+
push(B(0, r), T(0, r + 1), B(0, r + 1));
|
|
236
|
+
push(B(0, r), T(0, r), T(0, r + 1));
|
|
237
|
+
const cm = cols - 1;
|
|
238
|
+
push(B(cm, r), B(cm, r + 1), T(cm, r + 1));
|
|
239
|
+
push(B(cm, r), T(cm, r + 1), T(cm, r));
|
|
240
|
+
}
|
|
241
|
+
// Flat bottom fan at z = 0 (-Z) sharing all perimeter vertices (zero T-junctions)
|
|
242
|
+
const bc = [x0 + width / 2, y0 + depth / 2, 0];
|
|
243
|
+
for (let c = 0; c < cols - 1; c++) {
|
|
244
|
+
push(bc, B(c + 1, 0), B(c, 0));
|
|
245
|
+
push(bc, B(c, rows - 1), B(c + 1, rows - 1));
|
|
246
|
+
}
|
|
247
|
+
for (let r = 0; r < rows - 1; r++) {
|
|
248
|
+
push(bc, B(0, r), B(0, r + 1));
|
|
249
|
+
push(bc, B(cols - 1, r + 1), B(cols - 1, r));
|
|
250
|
+
}
|
|
251
|
+
return out;
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=surface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surface.js","sourceRoot":"","sources":["../../../packages/core/src/surface.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,yEAAyE;AAEzE,OAAO,EAAE,UAAU,EAAO,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAc,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACxC,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,GAAG,IAAI,CAAC;AAClD,MAAM,CAAC,MAAM,sB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,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -100,7 +100,37 @@ export declare class FontValue {
|
|
|
100
100
|
constructor(file?: string | null, size?: number, weight?: 'regular' | 'bold', spacing?: number, lineHeight?: number, align?: 'left' | 'center' | 'right', valign?: 'baseline' | 'bottom' | 'center' | 'top', ttf?: TtfFont | null);
|
|
101
101
|
toString(): string;
|
|
102
102
|
}
|
|
103
|
-
export
|
|
103
|
+
export declare class RangeValue {
|
|
104
|
+
lo: Q;
|
|
105
|
+
hi: Q;
|
|
106
|
+
inclusive: boolean;
|
|
107
|
+
constructor(lo: Q, hi: Q, inclusive?: boolean);
|
|
108
|
+
toString(): string;
|
|
109
|
+
}
|
|
110
|
+
export declare class RandomValue {
|
|
111
|
+
private state;
|
|
112
|
+
readonly seed: number;
|
|
113
|
+
constructor(seed?: number);
|
|
114
|
+
/** Next uniform float in [0, 1) using deterministic Mulberry32. */
|
|
115
|
+
nextUnit(): number;
|
|
116
|
+
toString(): string;
|
|
117
|
+
}
|
|
118
|
+
export declare class StructType {
|
|
119
|
+
name: string;
|
|
120
|
+
fields: [string, any, Pos][];
|
|
121
|
+
methods: Map<string, FunctionValue>;
|
|
122
|
+
env: Env;
|
|
123
|
+
pos: Pos;
|
|
124
|
+
constructor(name: string, fields: [string, any, Pos][], methods: Map<string, FunctionValue>, env: Env, pos: Pos);
|
|
125
|
+
toString(): string;
|
|
126
|
+
}
|
|
127
|
+
export declare class StructInstance {
|
|
128
|
+
type: StructType;
|
|
129
|
+
fields: Map<string, Value>;
|
|
130
|
+
constructor(type: StructType, fields: Map<string, Value>);
|
|
131
|
+
toString(): string;
|
|
132
|
+
}
|
|
133
|
+
export type Value = Q | boolean | string | Value[] | Shape | FontValue | LayerValue | RangeValue | RandomValue | StructType | StructInstance | Enum | Closure | Component | Builtin | BBox | Module | null;
|
|
104
134
|
export type Arg = [string | null, Value, Pos];
|
|
105
135
|
export declare class Env {
|
|
106
136
|
parent: Env | null;
|
package/build/core/src/values.js
CHANGED
|
@@ -204,6 +204,69 @@ export class FontValue {
|
|
|
204
204
|
return `Font(${name}, ${new Q(this.size, 'len')})`;
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
+
export class RangeValue {
|
|
208
|
+
lo;
|
|
209
|
+
hi;
|
|
210
|
+
inclusive;
|
|
211
|
+
constructor(lo, hi, inclusive = true) {
|
|
212
|
+
this.lo = lo;
|
|
213
|
+
this.hi = hi;
|
|
214
|
+
this.inclusive = inclusive;
|
|
215
|
+
}
|
|
216
|
+
toString() {
|
|
217
|
+
return `${this.lo}${this.inclusive ? '...' : '..<'}${this.hi}`;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
export class RandomValue {
|
|
221
|
+
state;
|
|
222
|
+
seed;
|
|
223
|
+
constructor(seed = 0) {
|
|
224
|
+
this.seed = seed;
|
|
225
|
+
let s = (Math.imul(Math.trunc(seed), 0x9e3779b1) ^ 0x6d2b79f5) >>> 0;
|
|
226
|
+
if (s === 0)
|
|
227
|
+
s = 0x6d2b79f5;
|
|
228
|
+
this.state = s;
|
|
229
|
+
}
|
|
230
|
+
/** Next uniform float in [0, 1) using deterministic Mulberry32. */
|
|
231
|
+
nextUnit() {
|
|
232
|
+
this.state = (this.state + 0x6d2b79f5) >>> 0;
|
|
233
|
+
let t = Math.imul(this.state ^ (this.state >>> 15), 1 | this.state);
|
|
234
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
235
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
236
|
+
}
|
|
237
|
+
toString() {
|
|
238
|
+
return `Random(seed: ${this.seed})`;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
export class StructType {
|
|
242
|
+
name;
|
|
243
|
+
fields;
|
|
244
|
+
methods;
|
|
245
|
+
env;
|
|
246
|
+
pos;
|
|
247
|
+
constructor(name, fields, methods, env, pos) {
|
|
248
|
+
this.name = name;
|
|
249
|
+
this.fields = fields;
|
|
250
|
+
this.methods = methods;
|
|
251
|
+
this.env = env;
|
|
252
|
+
this.pos = pos;
|
|
253
|
+
}
|
|
254
|
+
toString() {
|
|
255
|
+
return `<struct ${this.name}>`;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
export class StructInstance {
|
|
259
|
+
type;
|
|
260
|
+
fields;
|
|
261
|
+
constructor(type, fields) {
|
|
262
|
+
this.type = type;
|
|
263
|
+
this.fields = fields;
|
|
264
|
+
}
|
|
265
|
+
toString() {
|
|
266
|
+
const parts = [...this.fields.entries()].map(([k, v]) => `${k}: ${show(v)}`);
|
|
267
|
+
return `${this.type.name}(${parts.join(', ')})`;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
207
270
|
export class Env {
|
|
208
271
|
parent;
|
|
209
272
|
vars = new Map();
|
|
@@ -251,6 +314,14 @@ export function typename(v) {
|
|
|
251
314
|
return 'a font';
|
|
252
315
|
if (v instanceof LayerValue)
|
|
253
316
|
return 'a layer';
|
|
317
|
+
if (v instanceof RangeValue)
|
|
318
|
+
return 'a range';
|
|
319
|
+
if (v instanceof RandomValue)
|
|
320
|
+
return 'a random generator';
|
|
321
|
+
if (v instanceof StructType)
|
|
322
|
+
return `struct '${v.name}'`;
|
|
323
|
+
if (v instanceof StructInstance)
|
|
324
|
+
return `${v.type.name}`;
|
|
254
325
|
if (v instanceof Enum)
|
|
255
326
|
return `the option '${v}'`;
|
|
256
327
|
if (v instanceof Component || v instanceof Builtin || v instanceof Closure)
|
|
@@ -278,7 +349,7 @@ export function show(v) {
|
|
|
278
349
|
}
|
|
279
350
|
if (v === null || v === undefined)
|
|
280
351
|
return 'None';
|
|
281
|
-
if (v instanceof Q || v instanceof Enum || v instanceof FontValue || v instanceof LayerValue)
|
|
352
|
+
if (v instanceof Q || v instanceof Enum || v instanceof FontValue || v instanceof LayerValue || v instanceof RangeValue || v instanceof RandomValue || v instanceof StructType || v instanceof StructInstance)
|
|
282
353
|
return v.toString();
|
|
283
354
|
if (v instanceof Module)
|
|
284
355
|
return `<module ${v.name}>`;
|