@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/dist/scene.js ADDED
@@ -0,0 +1,642 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+
4
+ import { a as e, i as t, n, r, t as i } from "./open-D1NQyRTk.js";
5
+ import { checkColor as a, checkPlacement as o } from "./index.js";
6
+ import { Material as s, createInstancedMesh as c } from "@margoengine/materials";
7
+ import { BatchedMesh as l } from "@margoengine/materials/batched";
8
+ //#region src/meshes.ts
9
+ var u = /^IFC(WALL|SLAB|ROOF|CURTAINWALL)/, d = /^IFC(COLUMN|BEAM|MEMBER|PLATE|WINDOW|DOOR|STAIR|RAMP|RAILING|COVERING|FOOTING|PILE|CHIMNEY|SHADINGDEVICE|BUILDINGELEMENTPART|BUILTELEMENT|BUILDINGELEMENT$)/, f = (e) => {
10
+ let t = [];
11
+ for (let n = 0; n < e.size(); n++) t.push(e.get(n));
12
+ return t;
13
+ };
14
+ function p(n, i) {
15
+ let { api: a, id: o } = n, s = i.order ?? "envelope";
16
+ s !== "envelope" && s !== "file" && t("range", "order must be 'envelope' or 'file'");
17
+ let c = (t) => e("reading the schema", () => a.GetLineIDsWithType(o, t, !0)), l = new Set(r(n));
18
+ for (let e of f(c(3588315303))) l.add(e);
19
+ if (!i.spaces) for (let e of f(c(3856911033))) l.add(e);
20
+ let p = new Set(f(c(4208778838))), m;
21
+ if (i.elements === void 0) m = [...p];
22
+ else {
23
+ m = [];
24
+ for (let e of new Set(i.elements)) Number.isSafeInteger(e) || t("range", "elements must be expressIDs; pass integers"), p.has(e) && m.push(e);
25
+ }
26
+ if (m = m.filter((e) => !l.has(e)).sort((e, t) => e - t), s === "file") return m;
27
+ let h = (t) => {
28
+ let n = e("reading a type", () => a.GetNameFromTypeCode(a.GetLineType(o, t))).toUpperCase();
29
+ return u.test(n) ? 0 : d.test(n) ? 1 : 2;
30
+ }, g = new Map(m.map((e) => [e, h(e)]));
31
+ return m.sort((e, t) => g.get(e) - g.get(t) || e - t);
32
+ }
33
+ function m(e) {
34
+ if (e === void 0) return [
35
+ 0,
36
+ 0,
37
+ 0
38
+ ];
39
+ if (e !== "auto") return Array.isArray(e) && e.length === 3 && e.every(Number.isFinite) || t("range", "origin must be 'auto' or three finite numbers"), [
40
+ e[0],
41
+ e[1],
42
+ e[2]
43
+ ];
44
+ }
45
+ function* h(r, s = {}) {
46
+ n(r);
47
+ let c = s.chunk ?? 256;
48
+ (!Number.isSafeInteger(c) || c < 1 || c > 1e6) && t("range", "chunk must be an integer from 1 to 1,000,000");
49
+ let l = m(s.origin);
50
+ i(s.signal);
51
+ let { api: u, id: d } = r, f = p(r, s), h = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set(), _ = f.length;
52
+ for (let t = 0; t < _ || t === 0; t += c) {
53
+ i(s.signal);
54
+ let n = f.slice(t, t + c), p = /* @__PURE__ */ new Map(), m = [];
55
+ for (let t of n) {
56
+ i(s.signal);
57
+ let n = e("reading meshes", () => u.GetFlatMesh(d, t, !0));
58
+ try {
59
+ for (let t = 0; t < n.geometries.size(); t++) {
60
+ let i = n.geometries.get(t), s = i.geometryExpressID, c = i.flatTransformation;
61
+ if (o(c), l ??= [
62
+ Math.round(c[12]),
63
+ Math.round(c[13]),
64
+ Math.round(c[14])
65
+ ], !h.has(s)) {
66
+ h.add(s);
67
+ let t = e("reading a mesh", () => v(r, s));
68
+ t && (p.set(s, t), g.add(s));
69
+ }
70
+ if (!g.has(s)) continue;
71
+ let u = Float64Array.from(c);
72
+ for (let e = 0; e < 3; e++) u[12 + e] -= l[e];
73
+ m.push({
74
+ element: n.expressID,
75
+ geometry: s,
76
+ matrix: u,
77
+ color: a(i.color)
78
+ });
79
+ }
80
+ } finally {
81
+ n.geometries.delete?.();
82
+ }
83
+ }
84
+ let y = Math.min(t + c, _);
85
+ (m.length || y === _) && (yield {
86
+ schema: r.schema,
87
+ origin: l ?? [
88
+ 0,
89
+ 0,
90
+ 0
91
+ ],
92
+ geometries: p,
93
+ placements: m,
94
+ loaded: y,
95
+ total: _
96
+ });
97
+ }
98
+ }
99
+ function g(e, t = {}) {
100
+ let n = {
101
+ schema: "",
102
+ origin: [
103
+ 0,
104
+ 0,
105
+ 0
106
+ ],
107
+ geometries: /* @__PURE__ */ new Map(),
108
+ placements: []
109
+ };
110
+ for (let r of h(e, {
111
+ ...t,
112
+ chunk: 1e6
113
+ })) {
114
+ n.schema = r.schema, n.origin = r.origin;
115
+ for (let [e, t] of r.geometries) n.geometries.set(e, t);
116
+ for (let e of r.placements) n.placements.push(e);
117
+ }
118
+ return n;
119
+ }
120
+ async function* _(e, t = {}) {
121
+ for (let n of h(e, t)) yield n, n.loaded < n.total && await new Promise((e) => setTimeout(e, 0));
122
+ }
123
+ function v(e, n) {
124
+ let { api: r, id: i } = e, a = r.GetGeometry(i, n);
125
+ try {
126
+ let e = r.GetVertexArray(a.GetVertexData(), a.GetVertexDataSize()), n = r.GetIndexArray(a.GetIndexData(), a.GetIndexDataSize());
127
+ (e.length % 6 || n.length % 3) && t("range", "invalid geometry layout; export the file again");
128
+ let i = e.length / 6;
129
+ if (!n.length) return;
130
+ let o = new Float32Array(i * 3), s = new Float32Array(i * 3);
131
+ for (let t = 0; t < i; t++) for (let n = 0; n < 3; n++) o[t * 3 + n] = e[t * 6 + n], s[t * 3 + n] = e[t * 6 + 3 + n];
132
+ (!o.every(Number.isFinite) || !s.every(Number.isFinite)) && t("range", "non-finite vertex; export the file again");
133
+ let c = Uint32Array.from(n);
134
+ for (let e of c) e >= i && t("range", "index outside geometry; export the file again");
135
+ return {
136
+ positions: o,
137
+ normals: s,
138
+ indices: c
139
+ };
140
+ } finally {
141
+ a.delete();
142
+ }
143
+ }
144
+ //#endregion
145
+ //#region src/scene.ts
146
+ var y = new Float32Array([
147
+ 0,
148
+ 0,
149
+ 0,
150
+ 0,
151
+ 0,
152
+ 0,
153
+ 0,
154
+ 0,
155
+ 0,
156
+ 0,
157
+ 0,
158
+ 0,
159
+ 0,
160
+ 0,
161
+ 0,
162
+ 1
163
+ ]), b = (e) => e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4;
164
+ function x(e, n, r) {
165
+ return e === void 0 ? r : ((!Array.isArray(e) || e.length < 3 || e.slice(0, 3).some((e) => !Number.isFinite(e) || e < 0 || e > 1)) && t("range", `${n} must be three sRGB components from 0 to 1`), [
166
+ e[0],
167
+ e[1],
168
+ e[2]
169
+ ]);
170
+ }
171
+ var S = (e, n, r) => e === void 0 ? r : Number.isFinite(e) && e >= 0 && e <= 1 ? e : t("range", `${n} must be a number from 0 to 1`), C = class {
172
+ constructor(e, t, n) {
173
+ this.engine = e, this.material = t, this.limit = n, this.list = [], this.owners = /* @__PURE__ */ new Map();
174
+ }
175
+ add(e, t, n, r) {
176
+ let i = e(), a = i.positions.length / 3, o = i.indices.length, s = this.list.find((e) => e.count < e.maxItems && e.usage.vertices + a <= e.maxVertices && e.usage.indices + o <= e.maxIndices) ?? this.grow(a, o, r);
177
+ if (!s) {
178
+ let e = Math.min(this.limit, Math.max(a, r.vertices, 3));
179
+ s = this.open(e, Math.max(o, Math.min(r.indices, e * 6)), Math.min(1e6, Math.max(1, r.items)));
180
+ }
181
+ let c = {
182
+ batch: s,
183
+ item: s.add(i, {
184
+ matrix: t,
185
+ color: n
186
+ }),
187
+ make: e,
188
+ vertices: a,
189
+ indices: o
190
+ };
191
+ return this.owners.get(s).add(c), c;
192
+ }
193
+ remove(e) {
194
+ e.batch.remove(e.item), this.owners.get(e.batch)?.delete(e);
195
+ }
196
+ dispose() {
197
+ for (let e of this.list.splice(0)) e.dispose();
198
+ this.owners.clear();
199
+ }
200
+ open(e, t, n) {
201
+ let r = l.attach(this.engine, this.material, {
202
+ maxVertices: e,
203
+ maxIndices: Math.max(3, Math.ceil(t / 3) * 3),
204
+ maxItems: n
205
+ });
206
+ return this.list.push(r), this.owners.set(r, /* @__PURE__ */ new Set()), r;
207
+ }
208
+ grow(e, t, n) {
209
+ let r = this.list.at(-1);
210
+ if (!r) return;
211
+ let i = this.owners.get(r), a = e, o = t;
212
+ for (let e of i) a += e.vertices, o += e.indices;
213
+ if (a > this.limit || i.size + 1 > 1e6) return;
214
+ let s = Math.min(this.limit, Math.max(a, r.maxVertices * 2, n.vertices));
215
+ this.list.pop();
216
+ let c = this.open(s, Math.max(o, Math.min(Math.max(r.maxIndices * 2, n.indices), s * 6)), Math.min(1e6, Math.max(i.size + 1, r.maxItems * 2, n.items)));
217
+ for (let e of i) {
218
+ let t = e.item;
219
+ e.item = c.add(e.make(), {
220
+ matrix: r.getMatrix(t),
221
+ color: Array.from(r.getColor(t)),
222
+ visible: r.isVisible(t)
223
+ }), e.batch = c, this.owners.get(c).add(e);
224
+ }
225
+ return this.owners.delete(r), r.dispose(), c;
226
+ }
227
+ }, w = class e {
228
+ constructor(e, n, r = {}) {
229
+ this.engine = e, this.slots = /* @__PURE__ */ new Map(), this.order = [], this.groups = [], this.known = /* @__PURE__ */ new Map(), this.uses = /* @__PURE__ */ new Map(), this.planes = [], this.disposed = !1;
230
+ let i = r.batchVertices ?? 1e6;
231
+ (!Number.isSafeInteger(i) || i < 3 || i > 1e6) && t("range", "batchVertices must be an integer from 3 to 1,000,000");
232
+ let a = r.instancing ?? 2;
233
+ (!Number.isSafeInteger(a) || a < 0) && t("range", "instancing must be a non-negative integer"), this.instancing = a, this.ghost = x(r.ghostColor, "ghostColor", [
234
+ .62,
235
+ .72,
236
+ .86
237
+ ]).map(b), this.ghostOpacity = S(r.ghostOpacity, "ghostOpacity", .15), this.selection = x(r.selectionColor, "selectionColor", [
238
+ .1,
239
+ .55,
240
+ 1
241
+ ]).map(b), this.data = r.data, this.origin = [
242
+ n[0],
243
+ n[1],
244
+ n[2]
245
+ ];
246
+ let o = r.doubleSided ?? !0;
247
+ this.materials = {
248
+ opaque: new s({
249
+ roughness: .8,
250
+ metalness: 0,
251
+ doubleSided: o
252
+ }),
253
+ translucent: new s({
254
+ roughness: .8,
255
+ metalness: 0,
256
+ doubleSided: o,
257
+ transparent: !0,
258
+ depthWrite: !1
259
+ })
260
+ }, this.opaque = new C(e, this.materials.opaque, i), this.translucent = new C(e, this.materials.translucent, i);
261
+ }
262
+ static attach(t, n, r = {}) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
263
+ return new e(t, n.origin, r).add(n);
264
+ }
265
+ get elements() {
266
+ return this.order.map((e) => e.id);
267
+ }
268
+ get meshes() {
269
+ return [...this.opaque.list, ...this.translucent.list].map((e) => e.mesh).concat(this.groups.map((e) => e.mesh));
270
+ }
271
+ add(e) {
272
+ this.live();
273
+ let n = this.opaque.limit, r = [];
274
+ for (let n of e.placements) r.push({
275
+ p: n,
276
+ g: e.geometries.get(n.geometry) ?? this.known.get(n.geometry) ?? t("range", `placement of #${n.element} names missing geometry ${n.geometry}`)
277
+ });
278
+ for (let [t, n] of e.geometries) this.known.get(t) !== n && this.uses.delete(t), this.known.set(t, n);
279
+ let i = (e) => {
280
+ let t = this.uses.get(e);
281
+ return t || this.uses.set(e, t = {
282
+ uses: 0,
283
+ batched: []
284
+ }), t;
285
+ };
286
+ for (let { p: e } of r) e.color[3] >= 1 && i(e.geometry).uses++;
287
+ let a = {
288
+ vertices: 0,
289
+ indices: 0,
290
+ items: 0
291
+ }, o = {
292
+ vertices: 0,
293
+ indices: 0,
294
+ items: 0
295
+ };
296
+ for (let { p: e, g: t } of r) {
297
+ let r = t.positions.length / 3, s = i(e.geometry);
298
+ if (e.color[3] >= 1 && (this.instancing > 0 && s.uses >= this.instancing || r > n)) {
299
+ if (s.group) this.reserve(s.group, s.uses);
300
+ else {
301
+ let e = {
302
+ positions: t.positions,
303
+ normals: t.normals,
304
+ indices: t.indices
305
+ }, n = {
306
+ mesh: c(this.engine, e, this.materials.opaque, s.uses),
307
+ slots: [],
308
+ white: e
309
+ };
310
+ n.mesh.instances.count = 0, this.groups.push(n), s.group = n;
311
+ for (let e of s.batched.splice(0)) this.opaque.remove(e.item), e.item = void 0, this.instance(n, e);
312
+ }
313
+ continue;
314
+ }
315
+ let l = e.color[3] < 1 ? o : a;
316
+ l.vertices += r, l.indices += t.indices.length, l.items++;
317
+ }
318
+ for (let { p: e, g: t } of r) {
319
+ let n = this.slot(e.element), r = [
320
+ b(e.color[0]),
321
+ b(e.color[1]),
322
+ b(e.color[2]),
323
+ e.color[3]
324
+ ], i = {
325
+ owner: n,
326
+ geometry: t,
327
+ matrix: Float32Array.from(e.matrix),
328
+ color: r
329
+ }, s = e.color[3] >= 1 ? this.uses.get(e.geometry).group : void 0;
330
+ if (s) this.instance(s, i);
331
+ else {
332
+ let s = e.color[3] < 1, c = s ? o : a, l = t.positions.length / 3, u = e.color[3];
333
+ i.item = (s ? this.translucent : this.opaque).add(() => this.copy(t, n, u), i.matrix, [
334
+ r[0],
335
+ r[1],
336
+ r[2]
337
+ ], c), s || this.uses.get(e.geometry).batched.push(i), c.vertices -= l, c.indices -= t.indices.length, c.items--;
338
+ }
339
+ n.parts.push(i), this.draw(n, i);
340
+ }
341
+ return this;
342
+ }
343
+ stateOf(e) {
344
+ let t = this.slots.get(e);
345
+ return t && {
346
+ hidden: t.hidden,
347
+ ghosted: t.ghosted,
348
+ selected: t.selected,
349
+ ...t.srgb && { color: [...t.srgb] },
350
+ ...t.opacity !== void 0 && { opacity: t.opacity }
351
+ };
352
+ }
353
+ setVisible(e, t) {
354
+ return this.each(e, (e) => e.hidden = !t);
355
+ }
356
+ hide(e) {
357
+ return this.setVisible(e, !1);
358
+ }
359
+ show(e) {
360
+ return this.setVisible(e, !0);
361
+ }
362
+ isolate(e, t = {}) {
363
+ let n = new Set(e);
364
+ return this.each(this.elements, (e) => {
365
+ let r = n.has(e.id);
366
+ t.ghost ? (e.hidden = !1, e.ghosted = !r) : (e.hidden = !r, r && (e.ghosted = !1));
367
+ });
368
+ }
369
+ showAll() {
370
+ return this.each(this.elements, (e) => {
371
+ e.hidden = !1, e.ghosted = !1;
372
+ });
373
+ }
374
+ setGhosted(e, t) {
375
+ return this.each(e, (e) => e.ghosted = t);
376
+ }
377
+ setColor(e, t) {
378
+ let n = t === null ? void 0 : x(t, "color", [
379
+ 1,
380
+ 1,
381
+ 1
382
+ ]);
383
+ return this.each(e, (e) => {
384
+ e.srgb = n, e.color = n?.map(b);
385
+ });
386
+ }
387
+ setOpacity(e, t) {
388
+ let n = t === null ? void 0 : S(t, "opacity", 1);
389
+ return this.each(e, (e) => e.opacity = n === void 0 || n >= 1 ? void 0 : n);
390
+ }
391
+ select(e) {
392
+ let t = new Set(e);
393
+ return this.each(this.elements, (e) => e.selected = t.has(e.id));
394
+ }
395
+ get selected() {
396
+ return this.order.filter((e) => e.selected).map((e) => e.id);
397
+ }
398
+ get hidden() {
399
+ return this.order.filter((e) => e.hidden).map((e) => e.id);
400
+ }
401
+ elementAt(e) {
402
+ if (!e) return;
403
+ let t = e.model ?? e.mesh, n = this.groups.find((e) => e.mesh === t || e.mesh.root === t);
404
+ if (n) return e.instanceId === void 0 ? void 0 : this.order[n.slots[e.instanceId]]?.id;
405
+ if ([...this.opaque.list, ...this.translucent.list].some((e) => e.mesh === t || e.mesh.root === t) && e.uv) return this.order[Math.round(e.uv[0])]?.id;
406
+ }
407
+ get clippingPlanes() {
408
+ return this.planes.map((e) => [...e]);
409
+ }
410
+ set clippingPlanes(e) {
411
+ this.live(), (!Array.isArray(e) || e.length > 16) && t("range", `clippingPlanes holds at most 16 planes (got ${Array.isArray(e) ? e.length : "none"}); pass fewer`), this.materials.opaque.clippingPlanes = e, this.materials.translucent.clippingPlanes = e, this.planes = e.map((e) => [...e]);
412
+ }
413
+ sectionBox(e, n) {
414
+ (![...e, ...n].every(Number.isFinite) || e.length !== 3 || n.length !== 3 || e.some((e, t) => e > n[t])) && t("range", "sectionBox takes finite min and max corners with min <= max");
415
+ let r = [
416
+ 0,
417
+ 1,
418
+ 2
419
+ ].flatMap((t) => {
420
+ let r = [
421
+ 0,
422
+ 0,
423
+ 0,
424
+ -e[t]
425
+ ], i = [
426
+ 0,
427
+ 0,
428
+ 0,
429
+ n[t]
430
+ ];
431
+ return r[t] = 1, i[t] = -1, [r, i];
432
+ });
433
+ return this.clippingPlanes = r, r;
434
+ }
435
+ placementsOf(e) {
436
+ return (this.slots.get(e)?.parts ?? []).map((e) => ({
437
+ geometry: e.geometry,
438
+ matrix: e.matrix,
439
+ color: e.color
440
+ }));
441
+ }
442
+ bounds(e) {
443
+ let t = new Float64Array([
444
+ Infinity,
445
+ Infinity,
446
+ Infinity,
447
+ -Infinity,
448
+ -Infinity,
449
+ -Infinity
450
+ ]);
451
+ for (let n of e ?? this.order.filter((e) => !e.hidden).map((e) => e.id)) for (let e of this.slots.get(n)?.parts ?? []) {
452
+ let n = e.geometry.positions, r = e.matrix;
453
+ for (let e = 0; e < n.length; e += 3) for (let i = 0; i < 3; i++) {
454
+ let a = r[i] * n[e] + r[4 + i] * n[e + 1] + r[8 + i] * n[e + 2] + r[12 + i];
455
+ a < t[i] && (t[i] = a), a > t[3 + i] && (t[3 + i] = a);
456
+ }
457
+ }
458
+ return t;
459
+ }
460
+ storeyPlan(e, n = {}) {
461
+ let r = this.data ?? t("range", "storeyPlan needs the model data; pass createIFCScene(engine, meshes, { data })"), i = r.elements.get(e);
462
+ (!i || i.type.toUpperCase() !== "IFCBUILDINGSTOREY") && t("range", `#${e} is not an IfcBuildingStorey of this model`);
463
+ let a = i.attributes.Elevation, o = r.units.byType.LENGTHUNIT?.scale ?? 1, s = n.elevation ?? (typeof a == "number" ? a * o - this.origin[1] : t("range", `storey #${e} has no Elevation; pass elevation`)), c = n.cutHeight ?? 1.2;
464
+ (!Number.isFinite(s) || !Number.isFinite(c)) && t("range", "elevation and cutHeight must be finite");
465
+ let l = [...r.elements.values()].filter((t) => t.storey === e).map((e) => e.id);
466
+ this.isolate(l);
467
+ let u = s + c, d = [[
468
+ 0,
469
+ -1,
470
+ 0,
471
+ u
472
+ ]];
473
+ this.clippingPlanes = d;
474
+ let f = this.bounds(l), p = !(f[0] <= f[3]), m = p ? 0 : (f[0] + f[3]) / 2, h = p ? 0 : (f[2] + f[5]) / 2, g = p ? 10 : Math.max(f[3] - f[0], f[5] - f[2]) * 1.1;
475
+ return {
476
+ elevation: s,
477
+ cut: u,
478
+ clippingPlanes: d,
479
+ camera: {
480
+ type: "orthogonal",
481
+ position: [
482
+ m,
483
+ u + 1,
484
+ h
485
+ ],
486
+ target: [
487
+ m,
488
+ s,
489
+ h
490
+ ],
491
+ up: [
492
+ 0,
493
+ 0,
494
+ -1
495
+ ],
496
+ height: Math.max(g, .001)
497
+ }
498
+ };
499
+ }
500
+ applyBCFView(e) {
501
+ this.live(), e.clippingPlanes.length > 16 && t("range", `the viewpoint has ${e.clippingPlanes.length} section planes; a scene clips with at most 16`);
502
+ let n = new Set(e.hidden), r = new Set(e.selected);
503
+ return this.each(this.elements, (t) => {
504
+ let i = e.colors.get(t.id);
505
+ t.hidden = n.has(t.id), t.ghosted = !1, t.selected = r.has(t.id), t.srgb = i && [
506
+ i[0],
507
+ i[1],
508
+ i[2]
509
+ ], t.color = t.srgb?.map(b), t.opacity = i && i[3] < 1 ? i[3] : void 0;
510
+ }), this.clippingPlanes = e.clippingPlanes, e.camera;
511
+ }
512
+ bcfView() {
513
+ let e = /* @__PURE__ */ new Map();
514
+ for (let t of this.order) (t.srgb || t.opacity !== void 0) && e.set(t.id, [...t.srgb ?? this.fileColor(t), t.opacity ?? 1]);
515
+ return {
516
+ hidden: this.hidden,
517
+ selected: this.selected,
518
+ colors: e,
519
+ clippingPlanes: this.clippingPlanes
520
+ };
521
+ }
522
+ dispose() {
523
+ if (!this.disposed) {
524
+ this.disposed = !0, this.opaque.dispose(), this.translucent.dispose();
525
+ for (let e of this.groups.splice(0)) e.mesh.dispose();
526
+ this.materials.opaque.dispose(), this.materials.translucent.dispose();
527
+ }
528
+ }
529
+ [Symbol.dispose]() {
530
+ this.dispose();
531
+ }
532
+ live() {
533
+ this.disposed && t("range", "the IFC scene is disposed; create a new one");
534
+ }
535
+ instance(e, t) {
536
+ this.reserve(e, e.mesh.instances.count + 1);
537
+ let n = e.mesh.instances.count++;
538
+ e.slots[n] = t.owner.index, t.instance = {
539
+ group: e,
540
+ index: n
541
+ }, this.draw(t.owner, t);
542
+ }
543
+ reserve(e, t) {
544
+ let n = e.mesh.instances;
545
+ if (t <= n.capacity) return;
546
+ let r = c(this.engine, e.white, this.materials.opaque, Math.min(1e6, Math.max(t, n.capacity * 2)));
547
+ r.instances.data.set(n.data.subarray(0, n.count * 24)), r.instances.count = n.count, r.instances.needsUpdate = !0, e.mesh.dispose(), e.mesh = r;
548
+ }
549
+ slot(e) {
550
+ let t = this.slots.get(e);
551
+ return t || (t = {
552
+ id: e,
553
+ index: this.order.length,
554
+ parts: [],
555
+ overlay: [],
556
+ hidden: !1,
557
+ ghosted: !1,
558
+ selected: !1
559
+ }, this.slots.set(e, t), this.order.push(t)), t;
560
+ }
561
+ fileColor(e) {
562
+ let t = e.parts[0]?.color ?? [
563
+ 1,
564
+ 1,
565
+ 1
566
+ ], n = (e) => e <= .0031308 ? e * 12.92 : 1.055 * e ** (1 / 2.4) - .055;
567
+ return [
568
+ n(t[0]),
569
+ n(t[1]),
570
+ n(t[2])
571
+ ];
572
+ }
573
+ copy(e, t, n) {
574
+ let r = e.positions.length / 3, i = t.index, a = new Float32Array(r * 2), o = new Float32Array(r * 4).fill(1);
575
+ for (let e = 0; e < r; e++) a[e * 2] = i, o[e * 4 + 3] = n;
576
+ return {
577
+ positions: e.positions,
578
+ normals: e.normals,
579
+ indices: e.indices,
580
+ uvs: a,
581
+ colors: o
582
+ };
583
+ }
584
+ each(e, t) {
585
+ this.live();
586
+ for (let n of e) {
587
+ let e = this.slots.get(n);
588
+ if (e) {
589
+ t(e);
590
+ for (let t of e.parts) this.draw(e, t);
591
+ this.overlay(e);
592
+ }
593
+ }
594
+ return this;
595
+ }
596
+ draw(e, t) {
597
+ let n = !e.hidden && !e.ghosted && e.opacity === void 0, r = e.selected ? this.selection : e.color ?? t.color;
598
+ if (t.item) t.item.batch.setVisible(t.item.item, n).setColor(t.item.item, [
599
+ r[0],
600
+ r[1],
601
+ r[2]
602
+ ]);
603
+ else if (t.instance) {
604
+ let { group: e, index: i } = t.instance;
605
+ e.mesh.instances.setMatrixAt(i, n ? t.matrix : y).setColorAt(i, [
606
+ r[0],
607
+ r[1],
608
+ r[2],
609
+ 1
610
+ ]);
611
+ }
612
+ }
613
+ overlay(e) {
614
+ let t = !e.hidden && (e.ghosted || e.opacity !== void 0), n = e.ghosted ? this.ghost : e.selected ? this.selection : e.color, r = e.ghosted ? this.ghostOpacity : e.opacity ?? 1, i = t ? `${n ?? "file"}/${r}` : void 0;
615
+ if (i === e.overlayKey) return;
616
+ for (let t of e.overlay.splice(0)) this.translucent.remove(t);
617
+ if (e.overlayKey = i, !t) return;
618
+ let a = {
619
+ vertices: 0,
620
+ indices: 0,
621
+ items: e.parts.length
622
+ };
623
+ for (let t of e.parts) a.vertices += t.geometry.positions.length / 3, a.indices += t.geometry.indices.length;
624
+ for (let t of e.parts) {
625
+ let i = n ?? [
626
+ t.color[0],
627
+ t.color[1],
628
+ t.color[2]
629
+ ];
630
+ e.overlay.push(this.translucent.add(() => this.copy(t.geometry, e, r), t.matrix, i, {
631
+ vertices: Math.max(a.vertices, 65536),
632
+ indices: Math.max(a.indices, 196608),
633
+ items: Math.max(a.items, 4096)
634
+ }));
635
+ }
636
+ }
637
+ };
638
+ function T(e, t, n = {}) {
639
+ return w.attach(e, t, n);
640
+ }
641
+ //#endregion
642
+ export { w as IFCScene, T as createIFCScene, g as readIFCMeshes, _ as streamIFCMeshes };