@margoengine/ifc 0.0.0-stage → 1.0.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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/NOTICE.md +16 -0
- package/README.md +365 -2
- package/dist/bcf-wKfMzfyy.js +871 -0
- package/dist/bcf.d.ts +274 -0
- package/dist/bcf.js +1 -0
- package/dist/data-CuTaQPFm.js +534 -0
- package/dist/data.d.ts +205 -0
- package/dist/data.js +1 -0
- package/dist/ids.d.ts +199 -0
- package/dist/ids.js +759 -0
- package/dist/ifc-stream.worker.d.ts +1 -0
- package/dist/ifc.worker.d.ts +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +116 -0
- package/dist/meshes.d.ts +75 -0
- package/dist/open-D1NQyRTk.js +181 -0
- package/dist/open.d.ts +39 -0
- package/dist/predefined-enums.d.ts +2 -0
- package/dist/query.d.ts +62 -0
- package/dist/query.js +92 -0
- package/dist/raw.d.ts +7 -0
- package/dist/scene.d.ts +187 -0
- package/dist/scene.js +642 -0
- package/dist/schema-B_VBQpdF.js +51 -0
- package/dist/schema-tree.d.ts +2 -0
- package/dist/schema.d.ts +16 -0
- package/dist/section.d.ts +95 -0
- package/dist/section.js +380 -0
- package/dist/step.d.ts +1 -0
- package/dist/tolerance-CAOnp3Mo.js +7 -0
- package/dist/tolerance.d.ts +2 -0
- package/dist/units-B32iYdmV.js +134 -0
- package/dist/units.d.ts +33 -0
- package/dist/worker.d.ts +38 -0
- package/dist/worker.js +108 -0
- package/dist/workers/ifc-stream.js +1 -0
- package/dist/workers/ifc.js +1 -0
- package/dist/write.d.ts +113 -0
- package/dist/write.js +546 -0
- package/package.json +100 -4
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
//#region src/raw.ts
|
|
2
|
+
var e = (e) => e && e.type === 5 && typeof e.value == "number" ? e.value : void 0, t = (t) => Array.isArray(t) ? t.map(e).filter((e) => e !== void 0) : e(t) === void 0 ? [] : [e(t)], n = (e) => e && typeof e.value == "string" && e.type !== 5 ? e.value : void 0, r = (e) => {
|
|
3
|
+
if (e == null) return null;
|
|
4
|
+
if (Array.isArray(e)) return e.map(r).filter((e) => e !== void 0);
|
|
5
|
+
if (typeof e != "object") return e;
|
|
6
|
+
if (e.type !== 5) return "_representationValue" in e ? e._representationValue : e.type === 3 && (e.name === "IFCBOOLEAN" || e.name === "IFCLOGICAL") ? e.value === !0 || e.value === "T" ? !0 : e.value === !1 || e.value === "F" ? !1 : null : Array.isArray(e.value) ? e.value : e.value ?? null;
|
|
7
|
+
}, i = {
|
|
8
|
+
EXA: 18,
|
|
9
|
+
PETA: 15,
|
|
10
|
+
TERA: 12,
|
|
11
|
+
GIGA: 9,
|
|
12
|
+
MEGA: 6,
|
|
13
|
+
KILO: 3,
|
|
14
|
+
HECTO: 2,
|
|
15
|
+
DECA: 1,
|
|
16
|
+
DECI: -1,
|
|
17
|
+
CENTI: -2,
|
|
18
|
+
MILLI: -3,
|
|
19
|
+
MICRO: -6,
|
|
20
|
+
NANO: -9,
|
|
21
|
+
PICO: -12,
|
|
22
|
+
FEMTO: -15,
|
|
23
|
+
ATTO: -18
|
|
24
|
+
}, a = {
|
|
25
|
+
LENGTHUNIT: "m",
|
|
26
|
+
AREAUNIT: "m2",
|
|
27
|
+
VOLUMEUNIT: "m3",
|
|
28
|
+
MASSUNIT: "kg",
|
|
29
|
+
TIMEUNIT: "s",
|
|
30
|
+
PLANEANGLEUNIT: "rad",
|
|
31
|
+
SOLIDANGLEUNIT: "sr",
|
|
32
|
+
THERMODYNAMICTEMPERATUREUNIT: "K",
|
|
33
|
+
ELECTRICCURRENTUNIT: "A",
|
|
34
|
+
AMOUNTOFSUBSTANCEUNIT: "mol",
|
|
35
|
+
LUMINOUSINTENSITYUNIT: "cd",
|
|
36
|
+
FORCEUNIT: "N",
|
|
37
|
+
PRESSUREUNIT: "Pa",
|
|
38
|
+
ENERGYUNIT: "J",
|
|
39
|
+
POWERUNIT: "W",
|
|
40
|
+
FREQUENCYUNIT: "Hz",
|
|
41
|
+
ELECTRICVOLTAGEUNIT: "V",
|
|
42
|
+
ILLUMINANCEUNIT: "lx",
|
|
43
|
+
LUMINOUSFLUXUNIT: "lm",
|
|
44
|
+
MASSDENSITYUNIT: "kg/m3",
|
|
45
|
+
THERMALTRANSMITTANCEUNIT: "W/(m2.K)",
|
|
46
|
+
THERMALCONDUCTANCEUNIT: "W/(m.K)",
|
|
47
|
+
VOLUMETRICFLOWRATEUNIT: "m3/s",
|
|
48
|
+
LINEARVELOCITYUNIT: "m/s",
|
|
49
|
+
MASSFLOWRATEUNIT: "kg/s"
|
|
50
|
+
}, o = {
|
|
51
|
+
SQUARE_METRE: 2,
|
|
52
|
+
CUBIC_METRE: 3
|
|
53
|
+
}, s = (e) => ({
|
|
54
|
+
scale: 1,
|
|
55
|
+
shift: 0,
|
|
56
|
+
symbol: a[e] ?? "",
|
|
57
|
+
name: "SI"
|
|
58
|
+
});
|
|
59
|
+
function c(e, t) {
|
|
60
|
+
let n = e ? i[e] ?? 0 : 0, r = o[t] ?? 1;
|
|
61
|
+
return t === "DEGREE_CELSIUS" ? {
|
|
62
|
+
scale: 10 ** n,
|
|
63
|
+
shift: 273.15
|
|
64
|
+
} : {
|
|
65
|
+
scale: (t === "GRAM" ? .001 : 1) * 10 ** (n * r),
|
|
66
|
+
shift: 0
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function l(e) {
|
|
70
|
+
let t = e && /^IFC(?:POSITIVE|NONNEGATIVE)?([A-Z]+)MEASURE$/.exec(e.toUpperCase());
|
|
71
|
+
if (!t) return;
|
|
72
|
+
let n = t[1];
|
|
73
|
+
if (!/^(COUNT|RATIO|NORMALISEDRATIO|PARAMETERVALUE|NUMERIC|COMPOUNDPLANEANGLE|CONTEXTDEPENDENT|DESCRIPTIVE)$/.test(n)) return `${n}UNIT`;
|
|
74
|
+
}
|
|
75
|
+
var u = {
|
|
76
|
+
IFCQUANTITYLENGTH: "LENGTHUNIT",
|
|
77
|
+
IFCQUANTITYAREA: "AREAUNIT",
|
|
78
|
+
IFCQUANTITYVOLUME: "VOLUMEUNIT",
|
|
79
|
+
IFCQUANTITYWEIGHT: "MASSUNIT",
|
|
80
|
+
IFCQUANTITYTIME: "TIMEUNIT"
|
|
81
|
+
};
|
|
82
|
+
function d(i, o, s, l = 0) {
|
|
83
|
+
if (!i || l > 8) return;
|
|
84
|
+
let u = s(i), f = typeof i.UnitType?.value == "string" ? i.UnitType.value : "", p = a[f] ?? "";
|
|
85
|
+
if (u === "IFCSIUNIT") {
|
|
86
|
+
let e = typeof i.Prefix?.value == "string" ? i.Prefix.value : null, t = String(i.Name?.value ?? "");
|
|
87
|
+
return {
|
|
88
|
+
...c(e, t),
|
|
89
|
+
symbol: p,
|
|
90
|
+
name: e ? `${e} ${t}` : t
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (u === "IFCCONVERSIONBASEDUNIT" || u === "IFCCONVERSIONBASEDUNITWITHOFFSET") {
|
|
94
|
+
let t = o(e(i.ConversionFactor)), a = r(t?.ValueComponent), c = d(o(e(t?.UnitComponent)), o, s, l + 1);
|
|
95
|
+
if (typeof a != "number" || !c) return;
|
|
96
|
+
let f = u === "IFCCONVERSIONBASEDUNITWITHOFFSET" ? Number(r(i.ConversionOffset) ?? 0) : 0;
|
|
97
|
+
return {
|
|
98
|
+
scale: c.scale * a,
|
|
99
|
+
shift: c.shift - c.scale * a * f,
|
|
100
|
+
symbol: p,
|
|
101
|
+
name: String(n(i.Name) ?? i.Name?.value ?? "")
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (u === "IFCDERIVEDUNIT") {
|
|
105
|
+
let r = 1;
|
|
106
|
+
for (let n of t(i.Elements)) {
|
|
107
|
+
let t = o(n), i = d(o(e(t?.Unit)), o, s, l + 1), a = Number(t?.Exponent?.value ?? t?.Exponent ?? 1);
|
|
108
|
+
if (!i) return;
|
|
109
|
+
r *= i.scale ** a;
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
scale: r,
|
|
113
|
+
shift: 0,
|
|
114
|
+
symbol: p,
|
|
115
|
+
name: n(i.Name) ?? f
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function f(r, i, a) {
|
|
120
|
+
let o = { byType: {} }, s = r(a("IFCPROJECT")[0]), c = s ? r(e(s.UnitsInContext)) : void 0;
|
|
121
|
+
for (let e of t(c?.Units)) {
|
|
122
|
+
let t = r(e);
|
|
123
|
+
if (!t) continue;
|
|
124
|
+
if (i(t) === "IFCMONETARYUNIT") {
|
|
125
|
+
o.currency = String(n(t.Currency) ?? t.Currency?.value ?? "");
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
let a = typeof t.UnitType?.value == "string" ? t.UnitType.value : void 0, s = d(t, r, i);
|
|
129
|
+
a && s && (o.byType[a] = s);
|
|
130
|
+
}
|
|
131
|
+
return o;
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
export { d as a, e as c, s as i, t as l, f as n, l as o, c as r, r as s, u as t, n as u };
|
package/dist/units.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Raw } from './raw.js';
|
|
2
|
+
/** A unit's conversion to SI: `si = value * scale + shift`, and the SI symbol the result is in. */
|
|
3
|
+
export interface IFCUnit {
|
|
4
|
+
scale: number;
|
|
5
|
+
shift: number;
|
|
6
|
+
/** SI symbol of the converted value, such as `m`, `m2`, `kg` or `K`; empty when the unit type has none here. */
|
|
7
|
+
symbol: string;
|
|
8
|
+
/** The unit as the file names it, such as `MILLI METRE` or `foot`. */
|
|
9
|
+
name: string;
|
|
10
|
+
}
|
|
11
|
+
/** The project's units by IFC unit type (`LENGTHUNIT`, `AREAUNIT`, ...), with `currency` for IfcMonetaryUnit. */
|
|
12
|
+
export interface IFCUnits {
|
|
13
|
+
byType: Record<string, IFCUnit>;
|
|
14
|
+
currency?: string;
|
|
15
|
+
}
|
|
16
|
+
/** SI symbol of each unit type this package converts; other types keep their scale but name no symbol. */
|
|
17
|
+
export declare const SI_SYMBOL: Record<string, string>;
|
|
18
|
+
/** The SI unit (scale 1) of a unit type. */
|
|
19
|
+
export declare const siUnit: (type: string) => IFCUnit;
|
|
20
|
+
/** Converts an IfcSIUnit's prefix and name to { scale, shift }. */
|
|
21
|
+
export declare function siScale(prefix: string | null | undefined, name: string): {
|
|
22
|
+
scale: number;
|
|
23
|
+
shift: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The unit type a value's IFC measure type belongs to: IFCLENGTHMEASURE and IFCPOSITIVELENGTHMEASURE to LENGTHUNIT,
|
|
27
|
+
* IFCTHERMALTRANSMITTANCEMEASURE to THERMALTRANSMITTANCEUNIT. Ratios, counts, labels and the like have none.
|
|
28
|
+
*/
|
|
29
|
+
export declare function unitTypeOfMeasure(measure: string | undefined): string | undefined;
|
|
30
|
+
/** Unit type of each IfcPhysicalSimpleQuantity subtype's value. */
|
|
31
|
+
export declare const QUANTITY_UNIT: Record<string, string | undefined>;
|
|
32
|
+
export declare function unitOf(l: Raw, line: (id: number | undefined) => Raw, upper: (l: Raw) => string, depth?: number): IFCUnit | undefined;
|
|
33
|
+
export declare function readUnits(line: (id: number | undefined) => Raw, upper: (l: Raw) => string, ids: (n: string) => number[]): IFCUnits;
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { IFCOptions, IFCResult } from './index.js';
|
|
2
|
+
import type { IFCMeshChunk, IFCStreamOptions } from './meshes.js';
|
|
3
|
+
import type { IFCOpenOptions } from './open.js';
|
|
4
|
+
/** Options of parseIFCInWorker: IFCOptions plus the web-ifc script and wasm locations and the worker time limit. */
|
|
5
|
+
export interface IFCWorkerOptions extends IFCOptions {
|
|
6
|
+
/** URL of web-ifc's classic-script build (`web-ifc/web-ifc-api-iife.js`), served by the app. */
|
|
7
|
+
webIfc: string | URL;
|
|
8
|
+
/** Folder of `web-ifc.wasm` (passed to `SetWasmPath(path, true)`); default: next to the script. */
|
|
9
|
+
wasmPath?: string;
|
|
10
|
+
/** The worker is terminated and the call rejects with `LoaderError` code `limit` after this. Default 60,000 ms. */
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* parseIFC in a fresh worker with a deadline. web-ifc 0.0.78 can loop forever inside its Wasm on schema-invalid
|
|
15
|
+
* models (a string where a list belongs, a missing attribute), which no check before it can rule out; on this thread
|
|
16
|
+
* that hangs the page. Here the worker is terminated after `timeoutMs` and the call rejects with a named error.
|
|
17
|
+
* A whole ArrayBuffer input moves to the worker (pass a copy to keep it).
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseIFCInWorker(data: Uint8Array | ArrayBuffer, { webIfc, wasmPath, timeoutMs, signal, ...options }: IFCWorkerOptions): Promise<IFCResult>;
|
|
20
|
+
/** Options of streamIFCInWorker: streamIFCMeshes' and openIFC's options plus the web-ifc locations and a time limit. */
|
|
21
|
+
export interface IFCStreamWorkerOptions extends IFCStreamOptions, IFCOpenOptions {
|
|
22
|
+
/** URL of web-ifc's classic-script build (`web-ifc/web-ifc-api-iife.js`), served by the app. */
|
|
23
|
+
webIfc: string | URL;
|
|
24
|
+
/** Folder of `web-ifc.wasm` (passed to `SetWasmPath(path, true)`); default: next to the script. */
|
|
25
|
+
wasmPath?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The worker is terminated and the stream rejects with `LoaderError` code `limit` when it sends nothing (no chunk,
|
|
28
|
+
* no end) for this long. Default 60,000 ms.
|
|
29
|
+
*/
|
|
30
|
+
timeoutMs?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* streamIFCMeshes in a fresh worker: the file is opened and its meshes read off this thread, and each chunk arrives
|
|
34
|
+
* as soon as the worker has read it (its buffers moved, not copied), so the page draws the first chunks while the
|
|
35
|
+
* worker reads the rest. Stopping the loop early (`break`), aborting `signal` or a worker that sends nothing for
|
|
36
|
+
* `timeoutMs` terminates the worker. The worker starts on the first `next()`. A whole ArrayBuffer input moves to it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function streamIFCInWorker(data: Uint8Array | ArrayBuffer, { webIfc, wasmPath, timeoutMs, signal, ...options }: IFCStreamWorkerOptions): AsyncGenerator<IFCMeshChunk, void, undefined>;
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { LoaderError as e } from "@margoengine/loaders/common";
|
|
2
|
+
//#region ../shared/worker.js
|
|
3
|
+
function t(e, t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set()) {
|
|
4
|
+
let r = [e];
|
|
5
|
+
for (; r.length;) {
|
|
6
|
+
let e = r.pop();
|
|
7
|
+
if (e && typeof e == "object" && !n.has(e)) {
|
|
8
|
+
if (n.add(e), ArrayBuffer.isView(e)) e.buffer instanceof ArrayBuffer && t.add(e.buffer);
|
|
9
|
+
else if (e instanceof ArrayBuffer) t.add(e);
|
|
10
|
+
else if (typeof ImageBitmap < "u" && e instanceof ImageBitmap) t.add(e);
|
|
11
|
+
else if (e instanceof Map) for (let [t, n] of e) r.push(t, n);
|
|
12
|
+
else for (let t in e) r.push(e[t]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return t;
|
|
16
|
+
}
|
|
17
|
+
function n(e) {
|
|
18
|
+
if (e instanceof ArrayBuffer) return e;
|
|
19
|
+
if (ArrayBuffer.isView(e)) return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
|
|
20
|
+
if (typeof e == "string") return e;
|
|
21
|
+
throw TypeError("Expected an ArrayBuffer, typed array or string");
|
|
22
|
+
}
|
|
23
|
+
var r = {
|
|
24
|
+
TypeError,
|
|
25
|
+
RangeError,
|
|
26
|
+
SyntaxError
|
|
27
|
+
}, i = ({ name: e, message: t }) => new (Object.hasOwn(r, e) ? r[e] : Error)(typeof t == "string" ? t : "Parser worker failed");
|
|
28
|
+
function a(e, n, r, a) {
|
|
29
|
+
return r?.throwIfAborted(), new Promise((o, s) => {
|
|
30
|
+
let c = new Worker(e, { name: "margoengine-parser" }), l = () => {
|
|
31
|
+
c.onmessage = c.onerror = c.onmessageerror = null, c.terminate(), r?.removeEventListener("abort", d);
|
|
32
|
+
}, u = (e) => {
|
|
33
|
+
l(), s(e);
|
|
34
|
+
}, d = () => u(r.reason ?? new DOMException("Aborted", "AbortError"));
|
|
35
|
+
r?.addEventListener("abort", d, { once: !0 }), c.onerror = (e) => {
|
|
36
|
+
e.preventDefault?.(), u(/* @__PURE__ */ Error("Parser worker failed: " + (e.message || "unknown error")));
|
|
37
|
+
}, c.onmessageerror = () => u(/* @__PURE__ */ Error("Parser worker reply could not be deserialized")), c.onmessage = ({ data: e }) => {
|
|
38
|
+
l(), !e || typeof e != "object" ? s(/* @__PURE__ */ TypeError("Parser worker sent an invalid reply")) : e.error ? s(a?.(e.error) ?? i(e.error)) : o(e.result);
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
c.postMessage(n, [...t(n)]);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
u(e);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/worker.ts
|
|
49
|
+
var o = () => new URL("./workers/ifc.js?no-inline",
|
|
50
|
+
import.meta.url
|
|
51
|
+
), s = (t) => t.name === "LoaderError" ? Object.assign(new e(t.format, t.code, ""), { message: t.message }) : void 0;
|
|
52
|
+
async function c(t, { webIfc: r, wasmPath: i, timeoutMs: c = 6e4, signal: l, ...u }) {
|
|
53
|
+
if (typeof Worker != "function") throw new e("IFC", "unsupported", "parseIFCInWorker needs Web Workers");
|
|
54
|
+
if (!(c > 0 && c <= 2 ** 31 - 1)) throw new e("IFC", "range", "timeoutMs must be positive");
|
|
55
|
+
let d = new AbortController(), f = () => d.abort(l.reason), p = setTimeout(() => d.abort(new e("IFC", "limit", `web-ifc did not finish within ${c} ms`)), c);
|
|
56
|
+
l?.throwIfAborted(), l?.addEventListener("abort", f, { once: !0 });
|
|
57
|
+
try {
|
|
58
|
+
return await a(o(), {
|
|
59
|
+
data: n(t),
|
|
60
|
+
webIfc: new URL(r, globalThis.location?.href).href,
|
|
61
|
+
wasmPath: i,
|
|
62
|
+
options: u
|
|
63
|
+
}, d.signal, s);
|
|
64
|
+
} finally {
|
|
65
|
+
clearTimeout(p), l?.removeEventListener("abort", f);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function* l(r, { webIfc: a, wasmPath: o, timeoutMs: c = 6e4, signal: l, ...u }) {
|
|
69
|
+
if (typeof Worker != "function") throw new e("IFC", "unsupported", "streamIFCInWorker needs Web Workers");
|
|
70
|
+
if (!(c > 0 && c <= 2 ** 31 - 1)) throw new e("IFC", "range", "timeoutMs must be positive");
|
|
71
|
+
l?.throwIfAborted();
|
|
72
|
+
let d = [], f, p, m, h = new Worker(new URL("./workers/ifc-stream.js?no-inline",
|
|
73
|
+
import.meta.url
|
|
74
|
+
), { name: "margoengine-parser" }), g = (e) => {
|
|
75
|
+
f || (f = e, clearTimeout(m), l?.removeEventListener("abort", _), h.onmessage = h.onerror = h.onmessageerror = null, h.terminate(), p?.());
|
|
76
|
+
}, _ = () => g({ error: l.reason }), v = () => {
|
|
77
|
+
clearTimeout(m), m = setTimeout(() => g({ error: new e("IFC", "limit", `the IFC worker sent nothing for ${c} ms`) }), c);
|
|
78
|
+
};
|
|
79
|
+
l?.addEventListener("abort", _, { once: !0 }), h.onerror = (e) => {
|
|
80
|
+
e.preventDefault?.(), g({ error: /* @__PURE__ */ Error("IFC worker failed: " + (e.message || "unknown error")) });
|
|
81
|
+
}, h.onmessageerror = () => g({ error: /* @__PURE__ */ Error("IFC worker reply could not be deserialized") }), h.onmessage = ({ data: e }) => {
|
|
82
|
+
e?.chunk ? (d.push(e.chunk), v(), p?.()) : e?.done ? g({}) : e?.error ? g({ error: s(e.error) ?? i(e.error) }) : g({ error: /* @__PURE__ */ TypeError("IFC worker sent an invalid reply") });
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
v();
|
|
86
|
+
let e = {
|
|
87
|
+
buffer: n(r),
|
|
88
|
+
webIfc: new URL(a, globalThis.location?.href).href,
|
|
89
|
+
wasmPath: o,
|
|
90
|
+
options: {
|
|
91
|
+
...u,
|
|
92
|
+
elements: u.elements && [...u.elements]
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
for (h.postMessage(e, [...t(e)]);;) {
|
|
96
|
+
if (f?.error !== void 0) throw f.error;
|
|
97
|
+
let e = d.shift();
|
|
98
|
+
if (e) yield e;
|
|
99
|
+
else if (f) return;
|
|
100
|
+
else await new Promise((e) => p = e);
|
|
101
|
+
p = void 0;
|
|
102
|
+
}
|
|
103
|
+
} finally {
|
|
104
|
+
g({});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { c as parseIFCInWorker, l as streamIFCInWorker };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){function e(e,t=new Set,n=new Set){let r=[e];for(;r.length;){let e=r.pop();if(e&&typeof e==`object`&&!n.has(e)){if(n.add(e),ArrayBuffer.isView(e))e.buffer instanceof ArrayBuffer&&t.add(e.buffer);else if(e instanceof ArrayBuffer)t.add(e);else if(typeof ImageBitmap<`u`&&e instanceof ImageBitmap)t.add(e);else if(e instanceof Map)for(let[t,n]of e)r.push(t,n);else for(let t in e)r.push(e[t])}}return t}var t=class extends Error{constructor(e,t,n,r){super(`${e}: ${n}; see https://margoengine.com/errors#loader-${t}`,r),this.name=`LoaderError`,this.format=e,this.code=t,r?.status!==void 0&&(this.status=r.status),r?.retryAfter!==void 0&&(this.retryAfter=r.retryAfter)}},n=64,r=e=>e===32||e===9||e===10||e===13,i=e=>e>=48&&e<=57,a=e=>e>=65&&e<=90||e>=97&&e<=122||e===95,o=e=>a(e)||i(e)||e===45,s=0,c=1,l=2,u=3,d=4,f=5,p=6,m=7,h=8;function g(e){let t=e.length,g=0,_=s,v=0,y=()=>{for(;;){for(;g<t&&r(e[g]);)g++;if(e[g]===47&&e[g+1]===42){let t=e.indexOf(42,g+2);for(;t>=0&&e[t+1]!==47;)t=e.indexOf(42,t+1);if(t<0)return!1;g=t+2}else break}if(v=g,g>=t)return _=s,!0;let n=e[g];if(n===40)_=d,g++;else if(n===41)_=f,g++;else if(n===44)_=p,g++;else if(n===59)_=m,g++;else if(n===61)_=h,g++;else if(n===36||n===42)_=u,g++;else if(n===35){if(!i(e[++g]))return!1;for(;i(e[g]);)g++;_=l}else if(n===39){for(g++;;g++){if(g>=t)return!1;if(e[g]===39){if(e[g+1]!==39)break;g++}}g++,_=u}else if(n===34){for(g++;g<t&&e[g]!==34;g++)if(!i(e[g])&&!((e[g]|32)>=97&&(e[g]|32)<=102))return!1;if(g++>=t)return!1;_=u}else if(n===46){if(!a(e[++g]))return!1;for(;a(e[g])||i(e[g]);)g++;if(e[g++]!==46)return!1;_=u}else if(i(n)||n===43||n===45){if(i(n)||g++,!i(e[g]))return!1;for(;i(e[g]);)g++;if(e[g]===46)for(;i(e[++g]););if(e[g]===69||e[g]===101){if((e[g+1]===43||e[g+1]===45)&&g++,!i(e[++g]))return!1;for(;i(e[g]);)g++}_=u}else if(a(n)||n===33){for(g++;o(e[g]);g++);_=c}else return!1;let y=e[g];return!(_!==d&&_!==f&&_!==p&&_!==m&&_!==h&&g<t&&!r(y)&&y!==40&&y!==41&&y!==44&&y!==59&&y!==61&&y!==47)},b=()=>_,x=e=>`${e} at byte ${v}`,S=e=>{let t=[e?2:1],r=!0,i=!0;for(;t.length;){if(!y())return x(`invalid token`);if(t[t.length-1]===2){if(b()===f){t.pop(),r=!1,i=!1;continue}if(b()!==c||!y()||b()!==d)return x(`expected a record in a complex entity`);if(t.push(1)>n)return x(`lists nest too deeply`);r=!0,i=!0}else if(r){if(b()===f&&i){t.pop(),r=!1,i=!1;continue}if(b()===u||b()===l)r=!1;else if(b()===d){if(t.push(1)>n)return x(`lists nest too deeply`);i=!0;continue}else if(b()===c){if(!y()||b()!==d)return x(`expected ( after a typed parameter`);if(t.push(1)>n)return x(`lists nest too deeply`);i=!0;continue}else return x(`expected a parameter`);i=!1}else if(b()===p)r=!0;else if(b()===f)t.pop(),r=!1,i=!1;else return x(`expected , or ) between parameters`)}return null};for(;;){if(!y())return x(`invalid token`);if(b()===s)return null;let e=null;if(b()===l){if(!y()||b()!==h)return x(`expected = after an instance name`);if(!y())return x(`invalid token`);if(b()===d)e=S(!0);else if(b()===c){if(!y()||b()!==d)return x(`expected ( after an entity name`);e=S(!1)}else return x(`expected an entity after =`)}else if(b()===c){if(!y())return x(`invalid token`);if(b()===d)e=S(!1);else if(b()===m)continue;else return x(`expected ( or ; after a keyword`)}else return x(`expected a statement`);if(e)return e;if(!y()||b()!==m)return x(`expected ; after a statement`)}}var _=(e,n)=>{throw new t(`IFC`,e,n)},v=e=>{e?.aborted&&_(`aborted`,`aborted; pass a signal that is not aborted to read the model`)};function y(e,n){try{return n()}catch(n){if(n instanceof t)throw n;let r=n instanceof WebAssembly.RuntimeError?`Wasm trap`:n?.name||`Error`;throw Object.assign(new t(`IFC`,`unsupported`,`web-ifc failed while ${e} (${r}: ${n?.message})`),{cause:n})}}var b=new WeakMap;function x(e){let t=b.get(e.api);t||b.set(e.api,t=new Map);let n=t.get(e.id);return n||t.set(e.id,n=new Set),n}function S(e){(!e||typeof e.id!=`number`||!e.api)&&_(`range`,`expected an IFCModel; call openIFC first`),e.closed&&_(`range`,`the IFC model is closed; open it again with openIFC`)}function C(e,t,n={}){let r=n.maxBytes??268435456;(!Number.isSafeInteger(r)||r<0)&&_(`range`,`limits must be non-negative integers`),v(n.signal),(!e||typeof e.OpenModel!=`function`)&&_(`range`,`expected an initialized web-ifc IfcAPI; call Init() first`),t instanceof Uint8Array||_(`range`,`expected Uint8Array; pass the file bytes`),t.byteLength>r&&_(`limit`,`input exceeds maxBytes; raise maxBytes or pass a smaller file`),/^\s*ISO-10303-21;/i.test(new TextDecoder().decode(t.subarray(0,128)))||_(`header`,`expected a STEP IFC file starting with ISO-10303-21;`);let i=g(t);i&&_(`syntax`,`malformed STEP: ${i}; export the file again`);let a=y(`opening the model`,()=>e.OpenModel(t,{ALLOW_INCOMPATIBLE_SCHEMA_ALIASES:!1,...n.settings}));(a<0||!y(`opening the model`,()=>e.IsModelOpen(a)))&&_(`unsupported`,`web-ifc could not open the model; check the schema is IFC2X3, IFC4 or IFC4X3`);let o;try{o=y(`reading the schema`,()=>e.GetModelSchema(a))}catch(t){try{e.CloseModel(a)}catch{}throw t}let s=!1,c=()=>{if(!s){s=!0,b.get(e)?.delete(a);try{e.CloseModel(a)}catch{}}},l={api:e,id:a,schema:o,get closed(){return s},close:c};return typeof Symbol.dispose==`symbol`&&Object.defineProperty(l,Symbol.dispose,{value:c}),l}function w(e){(e.length!==16||!Array.prototype.every.call(e,Number.isFinite)||e[3]!==0||e[7]!==0||e[11]!==0||e[15]!==1)&&_(`range`,`invalid affine placement; export the file again`);let t=e[0]*(e[5]*e[10]-e[6]*e[9])-e[4]*(e[1]*e[10]-e[2]*e[9])+e[8]*(e[1]*e[6]-e[2]*e[5]);return(!Number.isFinite(t)||t===0)&&_(`range`,`singular placement; export the file again`),t}function T({x:e,y:t,z:n,w:r}){let i=[e,t,n,r];return i.some(e=>!Number.isFinite(e)||e<0||e>1)&&_(`range`,`invalid surface color; export the file again`),i}var E=/^IFC(WALL|SLAB|ROOF|CURTAINWALL)/,D=/^IFC(COLUMN|BEAM|MEMBER|PLATE|WINDOW|DOOR|STAIR|RAMP|RAILING|COVERING|FOOTING|PILE|CHIMNEY|SHADINGDEVICE|BUILDINGELEMENTPART|BUILTELEMENT|BUILDINGELEMENT$)/,O=e=>{let t=[];for(let n=0;n<e.size();n++)t.push(e.get(n));return t};function k(e,t){let{api:n,id:r}=e,i=t.order??`envelope`;i!==`envelope`&&i!==`file`&&_(`range`,`order must be 'envelope' or 'file'`);let a=e=>y(`reading the schema`,()=>n.GetLineIDsWithType(r,e,!0)),o=new Set(x(e));for(let e of O(a(3588315303)))o.add(e);if(!t.spaces)for(let e of O(a(3856911033)))o.add(e);let s=new Set(O(a(4208778838))),c;if(t.elements===void 0)c=[...s];else{c=[];for(let e of new Set(t.elements))Number.isSafeInteger(e)||_(`range`,`elements must be expressIDs; pass integers`),s.has(e)&&c.push(e)}if(c=c.filter(e=>!o.has(e)).sort((e,t)=>e-t),i===`file`)return c;let l=e=>{let t=y(`reading a type`,()=>n.GetNameFromTypeCode(n.GetLineType(r,e))).toUpperCase();return E.test(t)?0:D.test(t)?1:2},u=new Map(c.map(e=>[e,l(e)]));return c.sort((e,t)=>u.get(e)-u.get(t)||e-t)}function A(e){if(e===void 0)return[0,0,0];if(e!==`auto`)return Array.isArray(e)&&e.length===3&&e.every(Number.isFinite)||_(`range`,`origin must be 'auto' or three finite numbers`),[e[0],e[1],e[2]]}function*j(e,t={}){S(e);let n=t.chunk??256;(!Number.isSafeInteger(n)||n<1||n>1e6)&&_(`range`,`chunk must be an integer from 1 to 1,000,000`);let r=A(t.origin);v(t.signal);let{api:i,id:a}=e,o=k(e,t),s=new Set,c=new Set,l=o.length;for(let u=0;u<l||u===0;u+=n){v(t.signal);let d=o.slice(u,u+n),f=new Map,p=[];for(let n of d){v(t.signal);let o=y(`reading meshes`,()=>i.GetFlatMesh(a,n,!0));try{for(let t=0;t<o.geometries.size();t++){let n=o.geometries.get(t),i=n.geometryExpressID,a=n.flatTransformation;if(w(a),r??=[Math.round(a[12]),Math.round(a[13]),Math.round(a[14])],!s.has(i)){s.add(i);let t=y(`reading a mesh`,()=>M(e,i));t&&(f.set(i,t),c.add(i))}if(!c.has(i))continue;let l=Float64Array.from(a);for(let e=0;e<3;e++)l[12+e]-=r[e];p.push({element:o.expressID,geometry:i,matrix:l,color:T(n.color)})}}finally{o.geometries.delete?.()}}let m=Math.min(u+n,l);(p.length||m===l)&&(yield{schema:e.schema,origin:r??[0,0,0],geometries:f,placements:p,loaded:m,total:l})}}function M(e,t){let{api:n,id:r}=e,i=n.GetGeometry(r,t);try{let e=n.GetVertexArray(i.GetVertexData(),i.GetVertexDataSize()),t=n.GetIndexArray(i.GetIndexData(),i.GetIndexDataSize());(e.length%6||t.length%3)&&_(`range`,`invalid geometry layout; export the file again`);let r=e.length/6;if(!t.length)return;let a=new Float32Array(r*3),o=new Float32Array(r*3);for(let t=0;t<r;t++)for(let n=0;n<3;n++)a[t*3+n]=e[t*6+n],o[t*3+n]=e[t*6+3+n];(!a.every(Number.isFinite)||!o.every(Number.isFinite))&&_(`range`,`non-finite vertex; export the file again`);let s=Uint32Array.from(t);for(let e of s)e>=r&&_(`range`,`index outside geometry; export the file again`);return{positions:a,normals:o,indices:s}}finally{i.delete()}}self.onmessage=async({data:t})=>{try{if(!t||typeof t!=`object`)throw TypeError(`Invalid IFC stream job; post an object`);let{buffer:n,webIfc:r,wasmPath:i,options:a}=t;self.importScripts(r);let o=new self.WebIFC.IfcAPI;i&&o.SetWasmPath(i,!0),await o.Init();let s=C(o,new Uint8Array(n),a);try{for(let t of j(s,a))self.postMessage({chunk:t},[...e(t)])}finally{s.close()}self.postMessage({done:!0})}catch(e){let t={name:e?.name??`Error`,message:e instanceof Error?e.message:String(e)};try{self.postMessage({error:{...e,...t}})}catch{self.postMessage({error:t})}}}})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){function e(e,t=new Set,n=new Set){let r=[e];for(;r.length;){let e=r.pop();if(e&&typeof e==`object`&&!n.has(e)){if(n.add(e),ArrayBuffer.isView(e))e.buffer instanceof ArrayBuffer&&t.add(e.buffer);else if(e instanceof ArrayBuffer)t.add(e);else if(typeof ImageBitmap<`u`&&e instanceof ImageBitmap)t.add(e);else if(e instanceof Map)for(let[t,n]of e)r.push(t,n);else for(let t in e)r.push(e[t])}}return t}function t(t){self.onmessage=async({data:n})=>{try{if(!n||typeof n!=`object`)throw TypeError(`Invalid parser worker job; post an object`);let r=await t(n);self.postMessage({result:r},[...e(r)])}catch(e){let t={name:e?.name??`Error`,message:e instanceof Error?e.message:String(e)};try{self.postMessage({error:{...e,...t}})}catch{self.postMessage({error:t})}}}}var n=class extends Error{constructor(e,t,n,r){super(`${e}: ${n}; see https://margoengine.com/errors#loader-${t}`,r),this.name=`LoaderError`,this.format=e,this.code=t,r?.status!==void 0&&(this.status=r.status),r?.retryAfter!==void 0&&(this.retryAfter=r.retryAfter)}};function r(e,t,n){for(let r=0;r+2<t.length;r+=3){let i=t[r]*3,a=t[r+1]*3,o=t[r+2]*3,s=e[a]-e[i],c=e[a+1]-e[i+1],l=e[a+2]-e[i+2],u=e[o]-e[i],d=e[o+1]-e[i+1],f=e[o+2]-e[i+2],p=c*f-l*d,m=l*u-s*f,h=s*d-c*u;for(let e of[i,a,o])n[e]+=p,n[e+1]+=m,n[e+2]+=h}return n}function i(e,t){let n=r(e,t,new Float64Array(e.length)),i=new Float32Array(e.length);for(let e=0;e<i.length;e+=3){let t=Math.hypot(n[e],n[e+1],n[e+2]);t>0&&Number.isFinite(t)?(i[e]=n[e]/t,i[e+1]=n[e+1]/t,i[e+2]=n[e+2]/t):i[e+2]=1}return i}var a=64,o=e=>e===32||e===9||e===10||e===13,s=e=>e>=48&&e<=57,c=e=>e>=65&&e<=90||e>=97&&e<=122||e===95,l=e=>c(e)||s(e)||e===45,u=0,d=1,f=2,p=3,m=4,h=5,g=6,_=7,v=8;function y(e){let t=e.length,n=0,r=u,i=0,y=()=>{for(;;){for(;n<t&&o(e[n]);)n++;if(e[n]===47&&e[n+1]===42){let t=e.indexOf(42,n+2);for(;t>=0&&e[t+1]!==47;)t=e.indexOf(42,t+1);if(t<0)return!1;n=t+2}else break}if(i=n,n>=t)return r=u,!0;let a=e[n];if(a===40)r=m,n++;else if(a===41)r=h,n++;else if(a===44)r=g,n++;else if(a===59)r=_,n++;else if(a===61)r=v,n++;else if(a===36||a===42)r=p,n++;else if(a===35){if(!s(e[++n]))return!1;for(;s(e[n]);)n++;r=f}else if(a===39){for(n++;;n++){if(n>=t)return!1;if(e[n]===39){if(e[n+1]!==39)break;n++}}n++,r=p}else if(a===34){for(n++;n<t&&e[n]!==34;n++)if(!s(e[n])&&!((e[n]|32)>=97&&(e[n]|32)<=102))return!1;if(n++>=t)return!1;r=p}else if(a===46){if(!c(e[++n]))return!1;for(;c(e[n])||s(e[n]);)n++;if(e[n++]!==46)return!1;r=p}else if(s(a)||a===43||a===45){if(s(a)||n++,!s(e[n]))return!1;for(;s(e[n]);)n++;if(e[n]===46)for(;s(e[++n]););if(e[n]===69||e[n]===101){if((e[n+1]===43||e[n+1]===45)&&n++,!s(e[++n]))return!1;for(;s(e[n]);)n++}r=p}else if(c(a)||a===33){for(n++;l(e[n]);n++);r=d}else return!1;let y=e[n];return!(r!==m&&r!==h&&r!==g&&r!==_&&r!==v&&n<t&&!o(y)&&y!==40&&y!==41&&y!==44&&y!==59&&y!==61&&y!==47)},b=()=>r,x=e=>`${e} at byte ${i}`,S=e=>{let t=[e?2:1],n=!0,r=!0;for(;t.length;){if(!y())return x(`invalid token`);if(t[t.length-1]===2){if(b()===h){t.pop(),n=!1,r=!1;continue}if(b()!==d||!y()||b()!==m)return x(`expected a record in a complex entity`);if(t.push(1)>a)return x(`lists nest too deeply`);n=!0,r=!0}else if(n){if(b()===h&&r){t.pop(),n=!1,r=!1;continue}if(b()===p||b()===f)n=!1;else if(b()===m){if(t.push(1)>a)return x(`lists nest too deeply`);r=!0;continue}else if(b()===d){if(!y()||b()!==m)return x(`expected ( after a typed parameter`);if(t.push(1)>a)return x(`lists nest too deeply`);r=!0;continue}else return x(`expected a parameter`);r=!1}else if(b()===g)n=!0;else if(b()===h)t.pop(),n=!1,r=!1;else return x(`expected , or ) between parameters`)}return null};for(;;){if(!y())return x(`invalid token`);if(b()===u)return null;let e=null;if(b()===f){if(!y()||b()!==v)return x(`expected = after an instance name`);if(!y())return x(`invalid token`);if(b()===m)e=S(!0);else if(b()===d){if(!y()||b()!==m)return x(`expected ( after an entity name`);e=S(!1)}else return x(`expected an entity after =`)}else if(b()===d){if(!y())return x(`invalid token`);if(b()===m)e=S(!1);else if(b()===_)continue;else return x(`expected ( or ; after a keyword`)}else return x(`expected a statement`);if(e)return e;if(!y()||b()!==_)return x(`expected ; after a statement`)}}var b=(e,t)=>{throw new n(`IFC`,e,t)},x=e=>{e?.aborted&&b(`aborted`,`aborted; pass a signal that is not aborted to read the model`)};function S(e,t){try{return t()}catch(t){if(t instanceof n)throw t;let r=t instanceof WebAssembly.RuntimeError?`Wasm trap`:t?.name||`Error`;throw Object.assign(new n(`IFC`,`unsupported`,`web-ifc failed while ${e} (${r}: ${t?.message})`),{cause:t})}}var C=new WeakMap;function w(e){(!e||typeof e.id!=`number`||!e.api)&&b(`range`,`expected an IFCModel; call openIFC first`),e.closed&&b(`range`,`the IFC model is closed; open it again with openIFC`)}function T(e,t,n={}){let r=n.maxBytes??268435456;(!Number.isSafeInteger(r)||r<0)&&b(`range`,`limits must be non-negative integers`),x(n.signal),(!e||typeof e.OpenModel!=`function`)&&b(`range`,`expected an initialized web-ifc IfcAPI; call Init() first`),t instanceof Uint8Array||b(`range`,`expected Uint8Array; pass the file bytes`),t.byteLength>r&&b(`limit`,`input exceeds maxBytes; raise maxBytes or pass a smaller file`),/^\s*ISO-10303-21;/i.test(new TextDecoder().decode(t.subarray(0,128)))||b(`header`,`expected a STEP IFC file starting with ISO-10303-21;`);let i=y(t);i&&b(`syntax`,`malformed STEP: ${i}; export the file again`);let a=S(`opening the model`,()=>e.OpenModel(t,{ALLOW_INCOMPATIBLE_SCHEMA_ALIASES:!1,...n.settings}));(a<0||!S(`opening the model`,()=>e.IsModelOpen(a)))&&b(`unsupported`,`web-ifc could not open the model; check the schema is IFC2X3, IFC4 or IFC4X3`);let o;try{o=S(`reading the schema`,()=>e.GetModelSchema(a))}catch(t){try{e.CloseModel(a)}catch{}throw t}let s=!1,c=()=>{if(!s){s=!0,C.get(e)?.delete(a);try{e.CloseModel(a)}catch{}}},l={api:e,id:a,schema:o,get closed(){return s},close:c};return typeof Symbol.dispose==`symbol`&&Object.defineProperty(l,Symbol.dispose,{value:c}),l}function E(e,t,n={}){D(n);let r=T(e,t,n);try{return O(r,n)}finally{r.close()}}function D(e){for(let t of[e.maxVertices??0,e.maxTriangles??0,e.maxBytes??0])(!Number.isSafeInteger(t)||t<0)&&b(`range`,`limits must be non-negative integers`);let t=e.origin;t!==void 0&&t!==`auto`&&!(Array.isArray(t)&&t.length===3&&t.every(Number.isFinite))&&b(`range`,`origin must be 'auto' or three finite numbers`)}function O(e,t={}){w(e),D(t);let{api:n,id:r}=e,a=t.maxVertices??8e6,o=t.maxTriangles??16e6;x(t.signal);let s=[],c=[],l=[],u=[],d=Array.isArray(t.origin)?[t.origin[0],t.origin[1],t.origin[2]]:t.origin===`auto`?void 0:[0,0,0],f;S(`reading meshes`,()=>n.StreamAllMeshes(r,e=>{if(!f)try{x(t.signal);let i=n.GetLine(r,e.expressID),f=n.GetNameFromTypeCode(n.GetLineType(r,e.expressID)),p={expressID:e.expressID,type:f};typeof i?.GlobalId?.value==`string`&&(p.globalId=i.GlobalId.value),typeof i?.Name?.value==`string`&&(p.name=i.Name.value),u.push(p);for(let t=0;t<e.geometries.size();t++){let i=e.geometries.get(t),u=n.GetGeometry(r,i.geometryExpressID);try{let t=n.GetVertexArray(u.GetVertexData(),u.GetVertexDataSize()),r=n.GetIndexArray(u.GetIndexData(),u.GetIndexDataSize());(t.length%6||r.length%3)&&b(`range`,`invalid geometry layout; export the file again`);let m=t.length/6,h=s.length/3,g=c.length,_=i.flatTransformation;(h+m>a||g/3+r.length/3>o)&&b(`limit`,`geometry exceeds vertex or triangle limit; raise maxVertices or maxTriangles`);let v=k(_);d??=[Math.round(_[12]),Math.round(_[13]),Math.round(_[14])];for(let e=0;e<m;e++){let n=t[e*6],r=t[e*6+1],i=t[e*6+2];for(let e=0;e<3;e++){let t=Math.fround(_[e]*n+_[4+e]*r+_[8+e]*i+_[12+e]-d[e]);Number.isFinite(t)||b(`range`,`non-finite vertex; export the file again`),s.push(t)}}for(let e=0;e<r.length;e+=3){let t=r[e],n=r[e+1],i=r[e+2];(t>=m||n>=m||i>=m)&&b(`range`,`index outside geometry; export the file again`),c.push(h+t,h+(v<0?i:n),h+(v<0?n:i))}let y=A(i.color);r.length&&l.push({start:g,count:r.length,objectId:String(e.expressID),name:p.name??`${f} #${e.expressID}`,color:y})}finally{u.delete()}}}catch(e){f=e}},!0)),f&&S(`reading a mesh`,()=>{throw f}),x(t.signal),c.length||b(`unsupported`,`model contains no renderable triangles; check it has body representations`);let p=new Float32Array(s),m=new Uint32Array(c);return{kind:`mesh`,positions:p,indices:m,normals:i(p,m),groups:l,products:u,schema:e.schema,origin:d??[0,0,0]}}function k(e){(e.length!==16||!Array.prototype.every.call(e,Number.isFinite)||e[3]!==0||e[7]!==0||e[11]!==0||e[15]!==1)&&b(`range`,`invalid affine placement; export the file again`);let t=e[0]*(e[5]*e[10]-e[6]*e[9])-e[4]*(e[1]*e[10]-e[2]*e[9])+e[8]*(e[1]*e[6]-e[2]*e[5]);return(!Number.isFinite(t)||t===0)&&b(`range`,`singular placement; export the file again`),t}function A({x:e,y:t,z:n,w:r}){let i=[e,t,n,r];return i.some(e=>!Number.isFinite(e)||e<0||e>1)&&b(`range`,`invalid surface color; export the file again`),i}t(async({data:e,webIfc:t,wasmPath:n,options:r})=>{self.importScripts(t);let i=new self.WebIFC.IfcAPI;return n&&i.SetWasmPath(n,!0),await i.Init(),E(i,new Uint8Array(e),r)})})();
|
package/dist/write.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { type IFCModel } from './open.js';
|
|
2
|
+
/** A scalar property value: a string (IfcLabel, or IfcText past 255 characters), a number (IfcReal) or a boolean. */
|
|
3
|
+
export type IFCScalarInput = string | number | boolean;
|
|
4
|
+
/**
|
|
5
|
+
* A value with its IFC type, such as `{ type: 'IfcLengthMeasure', value: 0.25 }`. `value` is in SI (m, m2, kg, K, ...)
|
|
6
|
+
* and is written in the project's unit for that measure, or in `unit` when given; `raw` is written as is instead.
|
|
7
|
+
*/
|
|
8
|
+
export interface IFCTypedValue {
|
|
9
|
+
/** The IFC defined type, in any case: `IfcLabel`, `IfcBoolean`, `IfcLengthMeasure`, `IfcThermalTransmittanceMeasure`. */
|
|
10
|
+
type: string;
|
|
11
|
+
value?: IFCScalarInput | null;
|
|
12
|
+
raw?: IFCScalarInput | null;
|
|
13
|
+
/**
|
|
14
|
+
* An SI unit symbol with an optional prefix, written as the property's own IfcSIUnit: `mm`, `m2`, `kg`, `kPa`, `degC`,
|
|
15
|
+
* `ms`. Its unit type must be the measure's.
|
|
16
|
+
*/
|
|
17
|
+
unit?: string;
|
|
18
|
+
}
|
|
19
|
+
/** What setProperty takes: a scalar, a typed value, or a list of either (an IfcPropertyListValue). */
|
|
20
|
+
export type IFCPropertyInput = IFCScalarInput | IFCTypedValue | readonly (IFCScalarInput | IFCTypedValue)[];
|
|
21
|
+
/** The IfcPhysicalSimpleQuantity subtypes. `number` (IfcQuantityNumber) is IFC4X3 only. */
|
|
22
|
+
export type IFCQuantityKind = 'length' | 'area' | 'volume' | 'count' | 'weight' | 'time' | 'number';
|
|
23
|
+
/** What setQuantity takes: a number in SI, or the quantity spelled out. */
|
|
24
|
+
export interface IFCQuantityInput {
|
|
25
|
+
/** Required for a new quantity; an existing one keeps its kind. */
|
|
26
|
+
kind?: IFCQuantityKind;
|
|
27
|
+
/** In SI (m, m2, m3, kg, s), written in the project's unit (or `unit`). */
|
|
28
|
+
value?: number;
|
|
29
|
+
/** Written as is instead of `value`. */
|
|
30
|
+
raw?: number;
|
|
31
|
+
unit?: string;
|
|
32
|
+
/** IfcPhysicalQuantity.Formula (IFC4 and later). */
|
|
33
|
+
formula?: string;
|
|
34
|
+
}
|
|
35
|
+
/** An IfcApplication to record as the editing application. */
|
|
36
|
+
export interface IFCApplicationInput {
|
|
37
|
+
name: string;
|
|
38
|
+
version: string;
|
|
39
|
+
/** A short identifier, such as `my-viewer`. */
|
|
40
|
+
identifier: string;
|
|
41
|
+
/** The developer organization's name. */
|
|
42
|
+
developer: string;
|
|
43
|
+
}
|
|
44
|
+
/** A person and organization to record as the editing user. */
|
|
45
|
+
export interface IFCUserInput {
|
|
46
|
+
givenName?: string;
|
|
47
|
+
familyName?: string;
|
|
48
|
+
organization: string;
|
|
49
|
+
}
|
|
50
|
+
/** Options of editIFC. */
|
|
51
|
+
export interface IFCEditOptions {
|
|
52
|
+
/** The editing application. Default: the model's first owner history's application, else `Margo Engine`. */
|
|
53
|
+
application?: IFCApplicationInput;
|
|
54
|
+
/** The editing user. Default: the model's first owner history's user, else an unnamed person of `Unknown`. */
|
|
55
|
+
user?: IFCUserInput;
|
|
56
|
+
/** The time stamp of new owner histories. Default: now. */
|
|
57
|
+
now?: Date;
|
|
58
|
+
}
|
|
59
|
+
/** Edits of one open model; every change is written into the model at once. Save with saveIFC. */
|
|
60
|
+
export interface IFCEditor {
|
|
61
|
+
/**
|
|
62
|
+
* Sets one property of an element's (or type object's) property set, creating the set when it has none of that
|
|
63
|
+
* name. An element's set overrides its type's, so setting a type's property on an occurrence adds an occurrence set;
|
|
64
|
+
* edit the type's ID to change every occurrence. Returns the property's expressID.
|
|
65
|
+
*/
|
|
66
|
+
setProperty(id: number, set: string, name: string, value: IFCPropertyInput): number;
|
|
67
|
+
/** Sets several properties of one set (null removes one). With `replace`, properties not listed are removed. */
|
|
68
|
+
setPropertySet(id: number, set: string, values: Record<string, IFCPropertyInput | null>, options?: {
|
|
69
|
+
replace?: boolean;
|
|
70
|
+
}): void;
|
|
71
|
+
/** Removes a property; a set left empty is removed. False when the element's own sets do not hold it. */
|
|
72
|
+
removeProperty(id: number, set: string, name: string): boolean;
|
|
73
|
+
/** Detaches a property set or quantity set from the element, deleting what nothing else uses. */
|
|
74
|
+
removePropertySet(id: number, set: string): boolean;
|
|
75
|
+
/** Sets one quantity of an IfcElementQuantity, creating the set when missing. Returns the quantity's expressID. */
|
|
76
|
+
setQuantity(id: number, set: string, name: string, value: number | IFCQuantityInput): number;
|
|
77
|
+
removeQuantity(id: number, set: string, name: string): boolean;
|
|
78
|
+
/** Sets the Name attribute. */
|
|
79
|
+
rename(id: number, name: string): void;
|
|
80
|
+
/**
|
|
81
|
+
* Sets a direct attribute that holds a value (not a reference), in the file's units as `IFCElement.attributes` reads
|
|
82
|
+
* it: text, numbers, booleans or an enumeration value such as `PARTITIONING`. null clears an optional IfcRoot text
|
|
83
|
+
* attribute (Name, Description, ObjectType, Tag, LongName, ElementType, ApplicableOccurrence).
|
|
84
|
+
*/
|
|
85
|
+
setAttribute(id: number, name: string, value: IFCScalarInput | null | {
|
|
86
|
+
type: string;
|
|
87
|
+
raw: IFCScalarInput;
|
|
88
|
+
}): void;
|
|
89
|
+
/** expressIDs of the lines this editor created, in order. */
|
|
90
|
+
readonly created: readonly number[];
|
|
91
|
+
/** expressIDs of the lines this editor deleted. */
|
|
92
|
+
readonly deleted: readonly number[];
|
|
93
|
+
}
|
|
94
|
+
/** Options of saveIFC. */
|
|
95
|
+
export interface IFCSaveOptions {
|
|
96
|
+
signal?: AbortSignal;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Compresses a UUID to the 22-character IfcGloballyUniqueId: the 128-bit number in base 64 with the digits
|
|
100
|
+
* `0-9A-Za-z_$`, most significant first, so the first character holds the top 2 bits (0 to 3).
|
|
101
|
+
*/
|
|
102
|
+
export declare function ifcGuidFromUUID(uuid: string): string;
|
|
103
|
+
/** Expands an IfcGloballyUniqueId to its lower-case UUID. */
|
|
104
|
+
export declare function uuidFromIFCGuid(guid: string): string;
|
|
105
|
+
/** A new random IfcGloballyUniqueId (a version 4 UUID, RFC 9562, compressed). */
|
|
106
|
+
export declare function newIFCGuid(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Saves the model to IFC bytes (ISO 10303-21). web-ifc 0.0.78 writes a real with an exponent and no decimal point
|
|
109
|
+
* (`1E-07`), which the ISO 10303-21 REAL grammar does not allow, so such reals get their point (`1.E-07`).
|
|
110
|
+
*/
|
|
111
|
+
export declare function saveIFC(model: IFCModel, options?: IFCSaveOptions): Uint8Array;
|
|
112
|
+
/** Starts editing an open model. The editor writes into the model at once; readIFCData reads the edits back. */
|
|
113
|
+
export declare function editIFC(model: IFCModel, options?: IFCEditOptions): IFCEditor;
|