@margoengine/loaders 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/README.md +1665 -2
- package/dist/3dm.d.ts +161 -0
- package/dist/3dm.js +289 -0
- package/dist/3ds.d.ts +124 -0
- package/dist/3ds.js +392 -0
- package/dist/acclaim.d.ts +90 -0
- package/dist/acclaim.js +312 -0
- package/dist/amf.d.ts +45 -0
- package/dist/amf.js +256 -0
- package/dist/babylon.d.ts +197 -0
- package/dist/babylon.js +701 -0
- package/dist/common.d.ts +7 -0
- package/dist/common.js +6 -0
- package/dist/crease.d.ts +7 -0
- package/dist/crease.js +67 -0
- package/dist/dae-animation.d.ts +66 -0
- package/dist/dae-animation.js +266 -0
- package/dist/dae-common.d.ts +95 -0
- package/dist/dae-common.js +226 -0
- package/dist/dae-controllers.d.ts +57 -0
- package/dist/dae-controllers.js +164 -0
- package/dist/dae-kinematics.d.ts +65 -0
- package/dist/dae-kinematics.js +461 -0
- package/dist/dae-pose.d.ts +131 -0
- package/dist/dae-pose.js +381 -0
- package/dist/dae-scene.d.ts +203 -0
- package/dist/dae-scene.js +279 -0
- package/dist/dae.d.ts +166 -0
- package/dist/dae.js +644 -0
- package/dist/detect.d.ts +20 -0
- package/dist/detect.js +72 -0
- package/dist/dxf-hatch.d.ts +8 -0
- package/dist/dxf-hatch.js +346 -0
- package/dist/dxf-leaders.d.ts +59 -0
- package/dist/dxf-leaders.js +258 -0
- package/dist/dxf.d.ts +122 -0
- package/dist/dxf.js +985 -0
- package/dist/engine.d.ts +41 -0
- package/dist/engine.js +120 -0
- package/dist/font-opentype.d.ts +14 -0
- package/dist/font-opentype.js +33 -0
- package/dist/font-woff.d.ts +23 -0
- package/dist/font-woff.js +293 -0
- package/dist/font.d.ts +41 -0
- package/dist/font.js +26 -0
- package/dist/gcode.d.ts +92 -0
- package/dist/gcode.js +369 -0
- package/dist/geo-model.d.ts +84 -0
- package/dist/geo-model.js +220 -0
- package/dist/geo-mvt.d.ts +15 -0
- package/dist/geo-mvt.js +302 -0
- package/dist/geo-shp.d.ts +15 -0
- package/dist/geo-shp.js +234 -0
- package/dist/geo-xml.d.ts +6 -0
- package/dist/geo-xml.js +165 -0
- package/dist/geo.d.ts +8 -0
- package/dist/geo.js +59 -0
- package/dist/geometry.d.ts +60 -0
- package/dist/geometry.js +273 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +28 -0
- package/dist/kmz.d.ts +78 -0
- package/dist/kmz.js +173 -0
- package/dist/las.d.ts +92 -0
- package/dist/las.js +110 -0
- package/dist/ldraw.d.ts +118 -0
- package/dist/ldraw.js +474 -0
- package/dist/load.d.ts +72 -0
- package/dist/load.js +205 -0
- package/dist/lottie.d.ts +154 -0
- package/dist/lottie.js +893 -0
- package/dist/lwo.d.ts +81 -0
- package/dist/lwo.js +454 -0
- package/dist/lzf.d.ts +13 -0
- package/dist/lzf.js +56 -0
- package/dist/materialx.d.ts +120 -0
- package/dist/materialx.js +563 -0
- package/dist/md2.d.ts +52 -0
- package/dist/md2.js +112 -0
- package/dist/mmcif.d.ts +14 -0
- package/dist/mmcif.js +246 -0
- package/dist/mmd.d.ts +244 -0
- package/dist/mmd.js +958 -0
- package/dist/mocap.d.ts +71 -0
- package/dist/mocap.js +178 -0
- package/dist/molecule-common.d.ts +4 -0
- package/dist/molecule-common.js +54 -0
- package/dist/mtl.d.ts +125 -0
- package/dist/mtl.js +550 -0
- package/dist/normals.d.ts +7 -0
- package/dist/normals.js +31 -0
- package/dist/nrrd.d.ts +70 -0
- package/dist/nrrd.js +785 -0
- package/dist/nurbs.d.ts +118 -0
- package/dist/nurbs.js +265 -0
- package/dist/obj.d.ts +145 -0
- package/dist/obj.js +462 -0
- package/dist/off.d.ts +10 -0
- package/dist/off.js +155 -0
- package/dist/outline-font.d.ts +87 -0
- package/dist/outline-font.js +110 -0
- package/dist/outline.d.ts +20 -0
- package/dist/outline.js +215 -0
- package/dist/pcd.d.ts +34 -0
- package/dist/pcd.js +258 -0
- package/dist/pdb.d.ts +67 -0
- package/dist/pdb.js +126 -0
- package/dist/ply.d.ts +35 -0
- package/dist/ply.js +392 -0
- package/dist/polygon.d.ts +9 -0
- package/dist/polygon.js +49 -0
- package/dist/prwm.d.ts +24 -0
- package/dist/prwm.js +114 -0
- package/dist/render.d.ts +32 -0
- package/dist/render.js +181 -0
- package/dist/sfnt-cff.d.ts +37 -0
- package/dist/sfnt-cff.js +749 -0
- package/dist/sfnt-layout.d.ts +24 -0
- package/dist/sfnt-layout.js +266 -0
- package/dist/sfnt-reader.d.ts +28 -0
- package/dist/sfnt-reader.js +87 -0
- package/dist/sfnt-variation.d.ts +40 -0
- package/dist/sfnt-variation.js +318 -0
- package/dist/shared/asset-url.js +82 -0
- package/dist/shared/crc32.d.ts +2 -0
- package/dist/shared/crc32.js +47 -0
- package/dist/shared/errors.js +36 -0
- package/dist/shared/inflate.js +284 -0
- package/dist/shared/normals.js +26 -0
- package/dist/shared/scene-scope.js +56 -0
- package/dist/shared/trailing-data.js +45 -0
- package/dist/stl.d.ts +64 -0
- package/dist/stl.js +309 -0
- package/dist/svg.d.ts +90 -0
- package/dist/svg.js +1007 -0
- package/dist/tds.d.ts +2 -0
- package/dist/tds.js +2 -0
- package/dist/textures.d.ts +42 -0
- package/dist/textures.js +53 -0
- package/dist/threemf-beam-reader.d.ts +19 -0
- package/dist/threemf-beam-reader.js +165 -0
- package/dist/threemf-beams.d.ts +52 -0
- package/dist/threemf-beams.js +268 -0
- package/dist/threemf-boolean-read.d.ts +10 -0
- package/dist/threemf-boolean-read.js +113 -0
- package/dist/threemf-boolean.d.ts +59 -0
- package/dist/threemf-boolean.js +20 -0
- package/dist/threemf-csg.d.ts +14 -0
- package/dist/threemf-csg.js +193 -0
- package/dist/threemf-displacement-read.d.ts +8 -0
- package/dist/threemf-displacement-read.js +213 -0
- package/dist/threemf-displacement.d.ts +71 -0
- package/dist/threemf-displacement.js +18 -0
- package/dist/threemf-evaluate.d.ts +36 -0
- package/dist/threemf-evaluate.js +86 -0
- package/dist/threemf-functions.d.ts +33 -0
- package/dist/threemf-functions.js +359 -0
- package/dist/threemf-lattice-mesh.d.ts +9 -0
- package/dist/threemf-lattice-mesh.js +115 -0
- package/dist/threemf-lattice.d.ts +139 -0
- package/dist/threemf-lattice.js +379 -0
- package/dist/threemf-levelset.d.ts +23 -0
- package/dist/threemf-levelset.js +105 -0
- package/dist/threemf-materials.d.ts +162 -0
- package/dist/threemf-materials.js +497 -0
- package/dist/threemf-mesh.d.ts +75 -0
- package/dist/threemf-mesh.js +422 -0
- package/dist/threemf-secure.d.ts +50 -0
- package/dist/threemf-secure.js +153 -0
- package/dist/threemf-tessellate.d.ts +37 -0
- package/dist/threemf-tessellate.js +277 -0
- package/dist/threemf-volume-colour.d.ts +25 -0
- package/dist/threemf-volume-colour.js +233 -0
- package/dist/threemf-volume-sample.d.ts +8 -0
- package/dist/threemf-volume-sample.js +65 -0
- package/dist/threemf-volumetric-read.d.ts +15 -0
- package/dist/threemf-volumetric-read.js +539 -0
- package/dist/threemf-volumetric.d.ts +177 -0
- package/dist/threemf-volumetric.js +28 -0
- package/dist/threemf.d.ts +170 -0
- package/dist/threemf.js +609 -0
- package/dist/tilt.d.ts +62 -0
- package/dist/tilt.js +186 -0
- package/dist/tmx.d.ts +151 -0
- package/dist/tmx.js +394 -0
- package/dist/ttf.d.ts +78 -0
- package/dist/ttf.js +568 -0
- package/dist/types.d.ts +108 -0
- package/dist/types.js +35 -0
- package/dist/usd.d.ts +2 -0
- package/dist/usd.js +2 -0
- package/dist/usd.worker.d.ts +1 -0
- package/dist/usdz.d.ts +50 -0
- package/dist/usdz.js +646 -0
- package/dist/util.d.ts +75 -0
- package/dist/util.js +241 -0
- package/dist/vdb.d.ts +111 -0
- package/dist/vdb.js +663 -0
- package/dist/vrml.d.ts +53 -0
- package/dist/vrml.js +532 -0
- package/dist/vtk-cells.d.ts +29 -0
- package/dist/vtk-cells.js +211 -0
- package/dist/vtk-legacy.d.ts +57 -0
- package/dist/vtk-legacy.js +439 -0
- package/dist/vtk-reader.d.ts +19 -0
- package/dist/vtk-reader.js +134 -0
- package/dist/vtk-xml.d.ts +96 -0
- package/dist/vtk-xml.js +578 -0
- package/dist/vtk.d.ts +13 -0
- package/dist/vtk.js +234 -0
- package/dist/woff-glyf.d.ts +17 -0
- package/dist/woff-glyf.js +215 -0
- package/dist/worker.d.ts +10 -0
- package/dist/worker.js +93 -0
- package/dist/workers/usd.js +3 -0
- package/dist/xfile.d.ts +99 -0
- package/dist/xfile.js +706 -0
- package/dist/xml.d.ts +107 -0
- package/dist/xml.js +843 -0
- package/dist/xyz.d.ts +16 -0
- package/dist/xyz.js +110 -0
- package/dist/zip.d.ts +38 -0
- package/dist/zip.js +150 -0
- package/package.json +289 -4
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Adds a 3MF beam lattice's triangles to its mesh object, for `parse3MFEvaluated`: the shells of
|
|
2
|
+
// `mesh3MFBeamLattice`, cut by the clipping mesh when the lattice names one, with the properties the beam lattice
|
|
3
|
+
// extension gives them (https://github.com/3MFConsortium/spec_beamlattice, chapter 2: a beam's property runs along its
|
|
4
|
+
// axis, a surface takes that of the nearest point of the axis, and a clipped surface takes the clipping mesh's).
|
|
5
|
+
import { mesh3MFBeamLattice } from './threemf-beams.js';
|
|
6
|
+
import { booleanMesh } from './threemf-csg.js';
|
|
7
|
+
import { cornerProperty, } from './threemf.js';
|
|
8
|
+
import { LoaderError } from './types.js';
|
|
9
|
+
import { floats, limits, uints } from './util.js';
|
|
10
|
+
const F = '3MF';
|
|
11
|
+
const NONE = 0xffffffff;
|
|
12
|
+
const IDENTITY = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
|
|
13
|
+
/** A lattice's shells as a mesh with the properties of their beams and balls. */
|
|
14
|
+
function shells(model, object, lattice, vertices, gradients, options) {
|
|
15
|
+
const made = mesh3MFBeamLattice(vertices, lattice, options), out = { vertices: floats(), triangles: uints(), pid: uints(), p: uints(), flat: [] }, blended = [];
|
|
16
|
+
let blendedAt = -1;
|
|
17
|
+
for (let v = 0; v < made.positions.length; v += 3)
|
|
18
|
+
out.vertices.push3(made.positions[v], made.positions[v + 1], made.positions[v + 2]);
|
|
19
|
+
for (const { kind, index, triangleStart, triangleCount } of made.parts) {
|
|
20
|
+
const beam = kind === 'beam' ? lattice.beams[index] : undefined, ball = kind === 'ball' ? lattice.effectiveBalls[index] : undefined, pid = (beam ?? ball).pid, first = beam ? beam.p1 : ball.property, second = beam ? (beam.p2 ?? first) : first, group = pid === undefined ? undefined : model.properties.get(pid), a = first === undefined ? undefined : group?.[first], b = second === undefined ? undefined : group?.[second], at = pid === undefined ? NONE : model.propertyIds.indexOf(pid),
|
|
21
|
+
// Only a colour group blends; a base material holds for the whole beam.
|
|
22
|
+
blend = a && b && gradients.has(pid) && String(a) !== String(b);
|
|
23
|
+
for (let t = triangleStart; t < triangleStart + triangleCount; t++) {
|
|
24
|
+
const corners = [made.indices[t * 3], made.indices[t * 3 + 1], made.indices[t * 3 + 2]];
|
|
25
|
+
out.triangles.push3(corners[0], corners[1], corners[2]);
|
|
26
|
+
out.flat.push(a);
|
|
27
|
+
if (blend) {
|
|
28
|
+
if (blendedAt < 0) {
|
|
29
|
+
blendedAt = model.propertyIds.length;
|
|
30
|
+
const id = `\0lattice ${object.id}`;
|
|
31
|
+
model.propertyIds.push(id);
|
|
32
|
+
model.properties.set(id, blended);
|
|
33
|
+
}
|
|
34
|
+
for (const v of corners) {
|
|
35
|
+
const s = made.along[v];
|
|
36
|
+
blended.push([0, 1, 2, 3].map((k) => a[k] + (b[k] - a[k]) * s));
|
|
37
|
+
}
|
|
38
|
+
out.pid.push(blendedAt);
|
|
39
|
+
out.p.push3(blended.length - 3, blended.length - 2, blended.length - 1);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// A property the colour groups do not hold, such as a texture's, gives the surface none here.
|
|
43
|
+
out.pid.push(at < 0 ? NONE - 1 : at);
|
|
44
|
+
const index = first ?? NONE;
|
|
45
|
+
out.p.push3(index, index, index);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/** One mesh of two, each triangle keeping its group colour. */
|
|
52
|
+
function appended(model, object, meshes) {
|
|
53
|
+
const out = { vertices: floats(), triangles: uints(), pid: uints(), p: uints(), flat: [] };
|
|
54
|
+
for (const mesh of meshes) {
|
|
55
|
+
const base = out.vertices.length / 3, count = mesh.vertices.length / 3, source = mesh.vertices.array;
|
|
56
|
+
for (let v = 0; v < count; v++)
|
|
57
|
+
out.vertices.push3(source[v * 3], source[v * 3 + 1], source[v * 3 + 2]);
|
|
58
|
+
for (let t = 0; t < mesh.triangles.length / 3; t++) {
|
|
59
|
+
const [a, b, c] = mesh.triangles.array.subarray(t * 3, t * 3 + 3),
|
|
60
|
+
// An index past its own mesh stays past the joined one, for the reader to refuse.
|
|
61
|
+
at = (v) => (v < count ? base + v : NONE);
|
|
62
|
+
out.triangles.push3(at(a), at(b), at(c));
|
|
63
|
+
out.pid.push(mesh.pid.array[t]);
|
|
64
|
+
out.p.push3(mesh.p.array[t * 3], mesh.p.array[t * 3 + 1], mesh.p.array[t * 3 + 2]);
|
|
65
|
+
const property = cornerProperty(model, object, mesh, t, 0);
|
|
66
|
+
out.flat.push(mesh.flat ? mesh.flat[t] : property && model.properties.get(property.id)?.[property.index]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
/** The lattice step of the evaluating reader. */
|
|
72
|
+
export function lattices(options) {
|
|
73
|
+
/** The colour groups of each model part, whose properties blend along a beam. */
|
|
74
|
+
const gradients = new Map(), found = [];
|
|
75
|
+
const hooks = {
|
|
76
|
+
element(model, name, a) {
|
|
77
|
+
if (name !== 'colorgroup' || !a.id)
|
|
78
|
+
return;
|
|
79
|
+
let ids = gradients.get(model);
|
|
80
|
+
if (!ids)
|
|
81
|
+
gradients.set(model, (ids = new Set()));
|
|
82
|
+
ids.add(a.id);
|
|
83
|
+
},
|
|
84
|
+
bucket: () => '',
|
|
85
|
+
corner() { },
|
|
86
|
+
group() { },
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
hooks,
|
|
90
|
+
async add(model, own, surfaces, modelPath) {
|
|
91
|
+
const { maxTriangles } = limits(options, F);
|
|
92
|
+
for (const [objectId, lattice] of own) {
|
|
93
|
+
const object = model.objects.get(objectId);
|
|
94
|
+
found.push({ objectId, ...(modelPath === undefined ? {} : { modelPath }), lattice });
|
|
95
|
+
let made = shells(model, object, lattice, object.mesh.vertices.result(), gradients.get(model) ?? new Set(), {
|
|
96
|
+
segments: options.beamSegments,
|
|
97
|
+
maxTriangles,
|
|
98
|
+
});
|
|
99
|
+
if (!made.triangles.length)
|
|
100
|
+
continue;
|
|
101
|
+
if (lattice.clippingMode !== 'none') {
|
|
102
|
+
const clip = model.objects.get(lattice.clippingMesh), surface = surfaces.get(lattice.clippingMesh);
|
|
103
|
+
if (!clip || !surface || clip === object)
|
|
104
|
+
throw new LoaderError(F, 'range', `the lattice of object ${objectId.slice(0, 32)} names no clipping mesh`);
|
|
105
|
+
made = await booleanMesh(model, `${objectId} lattice`, lattice.clippingMode === 'inside' ? 'intersection' : 'difference', [
|
|
106
|
+
{ model, object: { ...object, mesh: made }, transform: IDENTITY },
|
|
107
|
+
{ model, object: { ...clip, mesh: surface }, transform: IDENTITY },
|
|
108
|
+
], maxTriangles);
|
|
109
|
+
}
|
|
110
|
+
object.mesh = appended(model, object, [object.mesh, made]);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
result: () => found,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { type BinaryInput } from './util.js';
|
|
2
|
+
import { type ThreeMFMaterials } from './threemf-materials.js';
|
|
3
|
+
import type { ThreeMFOptions } from './threemf.js';
|
|
4
|
+
/** One beam's native tapered-frustum geometry and endpoint properties, in file units. */
|
|
5
|
+
export interface ThreeMFBeam {
|
|
6
|
+
v1: number;
|
|
7
|
+
v2: number;
|
|
8
|
+
r1: number;
|
|
9
|
+
r2: number;
|
|
10
|
+
cap1: 'sphere' | 'hemisphere' | 'butt';
|
|
11
|
+
cap2: 'sphere' | 'hemisphere' | 'butt';
|
|
12
|
+
pid?: string;
|
|
13
|
+
p1?: number;
|
|
14
|
+
p2?: number;
|
|
15
|
+
}
|
|
16
|
+
/** One explicit or effective ball at a lattice vertex. */
|
|
17
|
+
export interface ThreeMFBall {
|
|
18
|
+
vertex: number;
|
|
19
|
+
radius: number;
|
|
20
|
+
pid?: string;
|
|
21
|
+
property?: number;
|
|
22
|
+
}
|
|
23
|
+
/** Named beam/ball subsets, retaining original source indices. */
|
|
24
|
+
export interface ThreeMFBeamSet {
|
|
25
|
+
name?: string;
|
|
26
|
+
identifier?: string;
|
|
27
|
+
beams: Uint32Array;
|
|
28
|
+
balls: Uint32Array;
|
|
29
|
+
}
|
|
30
|
+
/** Native lattice semantics, including clipping/representation references without flattening into a preview. */
|
|
31
|
+
export interface ThreeMFBeamLattice {
|
|
32
|
+
radius: number;
|
|
33
|
+
minLength: number;
|
|
34
|
+
cap: 'sphere' | 'hemisphere' | 'butt';
|
|
35
|
+
ballMode: 'none' | 'mixed' | 'all';
|
|
36
|
+
ballRadius?: number;
|
|
37
|
+
clippingMode: 'none' | 'inside' | 'outside';
|
|
38
|
+
clippingMesh?: string;
|
|
39
|
+
representationMesh?: string;
|
|
40
|
+
pid?: string;
|
|
41
|
+
property?: number;
|
|
42
|
+
beams: ThreeMFBeam[];
|
|
43
|
+
balls: ThreeMFBall[];
|
|
44
|
+
sets: ThreeMFBeamSet[];
|
|
45
|
+
/** Indices of beams satisfying minlength; ignored beams retain their original metadata indices. */
|
|
46
|
+
activeBeams: Uint32Array;
|
|
47
|
+
/** Effective balls after ballmode and beam-end membership, including implicit balls in all mode. */
|
|
48
|
+
effectiveBalls: ThreeMFBall[];
|
|
49
|
+
}
|
|
50
|
+
/** A property-gradient segment of a slice contour. */
|
|
51
|
+
export interface ThreeMFSliceSegment {
|
|
52
|
+
vertex: number;
|
|
53
|
+
pid?: string;
|
|
54
|
+
p1?: number;
|
|
55
|
+
p2?: number;
|
|
56
|
+
}
|
|
57
|
+
/** Source slice contour. Closure is explicit in the final segment. */
|
|
58
|
+
export interface ThreeMFSlicePolygon {
|
|
59
|
+
start: number;
|
|
60
|
+
segments: ThreeMFSliceSegment[];
|
|
61
|
+
}
|
|
62
|
+
/** One layer in source units, including void layers. */
|
|
63
|
+
export interface ThreeMFSlice {
|
|
64
|
+
top: number;
|
|
65
|
+
vertices: Float64Array;
|
|
66
|
+
polygons: ThreeMFSlicePolygon[];
|
|
67
|
+
}
|
|
68
|
+
/** Slice resources with resolved external references and unmodified source layers. */
|
|
69
|
+
export interface ThreeMFSliceStack {
|
|
70
|
+
part: string;
|
|
71
|
+
id: string;
|
|
72
|
+
bottom: number;
|
|
73
|
+
slices: ThreeMFSlice[];
|
|
74
|
+
references: {
|
|
75
|
+
part: string;
|
|
76
|
+
id: string;
|
|
77
|
+
}[];
|
|
78
|
+
/** Resolved, monotonically increasing layers; the stack's bottom supplies the first slab boundary. */
|
|
79
|
+
layers: ThreeMFSlice[];
|
|
80
|
+
}
|
|
81
|
+
/** Original property resources, with typed composite/multi rows and resolved color tables. */
|
|
82
|
+
export interface ThreeMFNativeProperty {
|
|
83
|
+
part: string;
|
|
84
|
+
id: string;
|
|
85
|
+
kind: string;
|
|
86
|
+
attributes: Record<string, string>;
|
|
87
|
+
entries: Record<string, string>[];
|
|
88
|
+
colors?: Float64Array;
|
|
89
|
+
materialId?: string;
|
|
90
|
+
materialIndices?: Uint32Array;
|
|
91
|
+
weights?: Float64Array[];
|
|
92
|
+
propertyIds?: string[];
|
|
93
|
+
rows?: Uint32Array[];
|
|
94
|
+
blendMethods?: ('mix' | 'multiply')[];
|
|
95
|
+
}
|
|
96
|
+
/** A source object, distinct from each occurrence in the build. */
|
|
97
|
+
export interface ThreeMFNativeObject {
|
|
98
|
+
part: string;
|
|
99
|
+
id: string;
|
|
100
|
+
type: string;
|
|
101
|
+
pid?: string;
|
|
102
|
+
property?: number;
|
|
103
|
+
/** Source-double xyz, before unit conversion and affine instances. */
|
|
104
|
+
vertices: Float64Array;
|
|
105
|
+
triangles: Uint32Array;
|
|
106
|
+
lattice?: ThreeMFBeamLattice;
|
|
107
|
+
slices?: {
|
|
108
|
+
part: string;
|
|
109
|
+
id: string;
|
|
110
|
+
resolution: 'fullres' | 'lowres';
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** Built native geometry with an exact affine matrix; source radii remain valid under nonuniform scale. */
|
|
114
|
+
export interface ThreeMFNativeInstance {
|
|
115
|
+
object: ThreeMFNativeObject;
|
|
116
|
+
/** Row-vector 4x3 matrix, applied before unitScale. */
|
|
117
|
+
transform: Float64Array;
|
|
118
|
+
unitScale: number;
|
|
119
|
+
}
|
|
120
|
+
/** Materials/fallback mesh plus native lattice, slices, properties and build occurrences. */
|
|
121
|
+
export interface ThreeMFLatticeResult extends ThreeMFMaterials {
|
|
122
|
+
objects: ThreeMFNativeObject[];
|
|
123
|
+
instances: ThreeMFNativeInstance[];
|
|
124
|
+
sliceStacks: ThreeMFSliceStack[];
|
|
125
|
+
/** Top-level slice representations; component-level stacks override stacks on their descendants. */
|
|
126
|
+
sliceInstances: (ThreeMFNativeInstance & {
|
|
127
|
+
stack: ThreeMFSliceStack;
|
|
128
|
+
})[];
|
|
129
|
+
propertyResources: ThreeMFNativeProperty[];
|
|
130
|
+
}
|
|
131
|
+
/** 3MF bounds extended to native primitives and slice data. */
|
|
132
|
+
export interface ThreeMFLatticeOptions extends ThreeMFOptions {
|
|
133
|
+
/** Maximum source beams and explicit balls each. Default 1,000,000. */
|
|
134
|
+
maxBeams?: number;
|
|
135
|
+
/** Maximum layers and slice references combined. Default 100,000. */
|
|
136
|
+
maxSlices?: number;
|
|
137
|
+
}
|
|
138
|
+
/** Reads exact native beam/ball and slice resources alongside the existing textured/composite/multi material mesh. */
|
|
139
|
+
export declare function parse3MFLattice(input: BinaryInput, options?: ThreeMFLatticeOptions): Promise<ThreeMFLatticeResult>;
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { LoaderError } from './types.js';
|
|
2
|
+
import { limits, resolvePath, throwIfAborted } from './util.js';
|
|
3
|
+
import { read3MFMaterials } from './threemf-materials.js';
|
|
4
|
+
import { readXMLTree, decodeXML } from './xml.js';
|
|
5
|
+
import { attribute, beamReader, choice, finishLattice, index, number } from './threemf-beam-reader.js';
|
|
6
|
+
const F = '3MF';
|
|
7
|
+
const own = (a) => Object.assign(Object.create(null), a);
|
|
8
|
+
const normalize = (path) => path.replaceAll('\\', '/').replace(/^\/+/, '').toLowerCase();
|
|
9
|
+
const list = (value, name) => {
|
|
10
|
+
if (!value?.trim())
|
|
11
|
+
throw new LoaderError(F, 'syntax', `${name} needs values`);
|
|
12
|
+
return value
|
|
13
|
+
.trim()
|
|
14
|
+
.split(/\s+/)
|
|
15
|
+
.map((v) => number(v, name));
|
|
16
|
+
};
|
|
17
|
+
/** Reads exact native beam/ball and slice resources alongside the existing textured/composite/multi material mesh. */
|
|
18
|
+
export async function parse3MFLattice(input, options = {}) {
|
|
19
|
+
const limit = limits(options, F), maxBeams = options.maxBeams ?? 1000000, maxSlices = options.maxSlices ?? 100000;
|
|
20
|
+
if (!Number.isSafeInteger(maxBeams) || maxBeams < 1 || !Number.isSafeInteger(maxSlices) || maxSlices < 1)
|
|
21
|
+
throw new LoaderError(F, 'limit', 'maxBeams and maxSlices must be positive safe integers');
|
|
22
|
+
throwIfAborted(options.signal, F);
|
|
23
|
+
const states = new Map(), instances = [], sliceInstances = [];
|
|
24
|
+
const ancestors = [];
|
|
25
|
+
let objectCount = 0, expandedLayers = 0;
|
|
26
|
+
const lattices = beamReader(maxBeams);
|
|
27
|
+
let slices = 0, vertices = 0, segments = 0;
|
|
28
|
+
const state = (m) => {
|
|
29
|
+
let s = states.get(m);
|
|
30
|
+
if (!s) {
|
|
31
|
+
s = { part: '', objects: new Map(), stacks: new Map(), properties: new Map(), xyz: [], xy: [] };
|
|
32
|
+
states.set(m, s);
|
|
33
|
+
}
|
|
34
|
+
return s;
|
|
35
|
+
};
|
|
36
|
+
const hooks = {
|
|
37
|
+
element(m, name, a) {
|
|
38
|
+
const s = state(m), obj = s.object;
|
|
39
|
+
if (name === 'model') {
|
|
40
|
+
const required = (a.requiredextensions ?? '').trim().split(/\s+/);
|
|
41
|
+
s.requiredSlice = Object.entries(a).some(([key, value]) => key.startsWith('xmlns:') &&
|
|
42
|
+
value === 'http://schemas.microsoft.com/3dmanufacturing/slice/2015/07' &&
|
|
43
|
+
required.includes(key.slice(6)));
|
|
44
|
+
}
|
|
45
|
+
else if (name === 'object') {
|
|
46
|
+
if (++objectCount > 100000)
|
|
47
|
+
throw new LoaderError(F, 'limit', 'native objects exceed 100000');
|
|
48
|
+
const id = a.id;
|
|
49
|
+
if (!id || s.objects.has(id))
|
|
50
|
+
throw new LoaderError(F, 'syntax', 'native object id is missing or duplicated');
|
|
51
|
+
s.object = {
|
|
52
|
+
part: '',
|
|
53
|
+
id,
|
|
54
|
+
type: a.type ?? 'model',
|
|
55
|
+
pid: a.pid,
|
|
56
|
+
property: a.pindex === undefined ? undefined : index(a.pindex, 'pindex'),
|
|
57
|
+
vertices: new Float64Array(),
|
|
58
|
+
triangles: new Uint32Array(),
|
|
59
|
+
};
|
|
60
|
+
s.objects.set(id, s.object);
|
|
61
|
+
s.xyz = [];
|
|
62
|
+
const stack = attribute(a, 'slicestackid');
|
|
63
|
+
if (stack)
|
|
64
|
+
s.object.slices = {
|
|
65
|
+
part: attribute(a, 'slicepath') ?? '',
|
|
66
|
+
id: stack,
|
|
67
|
+
resolution: choice(attribute(a, 'meshresolution'), ['fullres', 'lowres'], 'fullres'),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
else if (name === 'vertex') {
|
|
71
|
+
if (++vertices > limit.maxVertices)
|
|
72
|
+
throw new LoaderError(F, 'limit', 'native/slice vertices exceed maxVertices');
|
|
73
|
+
if (s.slice) {
|
|
74
|
+
s.xy.push(number(a.x, 'slice x'), number(a.y, 'slice y'));
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (obj)
|
|
78
|
+
s.xyz.push(number(a.x, 'vertex x'), number(a.y, 'vertex y'), number(a.z, 'vertex z'));
|
|
79
|
+
}
|
|
80
|
+
else if (name === 'beamlattice') {
|
|
81
|
+
if (!obj || obj.lattice)
|
|
82
|
+
throw new LoaderError(F, 'syntax', 'beamlattice needs a distinct mesh object');
|
|
83
|
+
const core = m.objects.get(obj.id);
|
|
84
|
+
obj.lattice = lattices.begin(s, a, core?.pid, core?.pindex);
|
|
85
|
+
}
|
|
86
|
+
else if (['beam', 'ball', 'beamset', 'ref', 'ballref'].includes(name)) {
|
|
87
|
+
lattices.element(s, name, a);
|
|
88
|
+
}
|
|
89
|
+
else if (name === 'slicestack') {
|
|
90
|
+
if (s.stack || !a.id || s.stacks.has(a.id))
|
|
91
|
+
throw new LoaderError(F, 'syntax', 'invalid slicestack id or nesting');
|
|
92
|
+
s.stack = {
|
|
93
|
+
part: '',
|
|
94
|
+
id: a.id,
|
|
95
|
+
bottom: number(a.zbottom, 'zbottom', 0),
|
|
96
|
+
slices: [],
|
|
97
|
+
references: [],
|
|
98
|
+
layers: [],
|
|
99
|
+
};
|
|
100
|
+
s.stacks.set(a.id, s.stack);
|
|
101
|
+
}
|
|
102
|
+
else if (name === 'sliceref') {
|
|
103
|
+
if (!s.stack || !a.slicepath || !a.slicestackid)
|
|
104
|
+
throw new LoaderError(F, 'syntax', 'sliceref requires a stack, path and id');
|
|
105
|
+
if (++slices > maxSlices)
|
|
106
|
+
throw new LoaderError(F, 'limit', 'slice references exceed maxSlices');
|
|
107
|
+
s.stack.references.push({ part: a.slicepath, id: a.slicestackid });
|
|
108
|
+
}
|
|
109
|
+
else if (name === 'slice') {
|
|
110
|
+
if (!s.stack || s.slice)
|
|
111
|
+
throw new LoaderError(F, 'syntax', 'slice outside stack or nested');
|
|
112
|
+
if (++slices > maxSlices)
|
|
113
|
+
throw new LoaderError(F, 'limit', 'layers exceed maxSlices');
|
|
114
|
+
s.slice = { top: number(a.ztop, 'ztop'), vertices: new Float64Array(), polygons: [] };
|
|
115
|
+
s.stack.slices.push(s.slice);
|
|
116
|
+
s.xy = [];
|
|
117
|
+
}
|
|
118
|
+
else if (name === 'polygon' && s.slice) {
|
|
119
|
+
if (s.polygon)
|
|
120
|
+
throw new LoaderError(F, 'syntax', 'nested slice polygon');
|
|
121
|
+
s.polygon = { start: index(a.startv, 'startv'), segments: [] };
|
|
122
|
+
s.slice.polygons.push(s.polygon);
|
|
123
|
+
}
|
|
124
|
+
else if (name === 'segment' && s.polygon) {
|
|
125
|
+
if (++segments > limit.maxTriangles * 3)
|
|
126
|
+
throw new LoaderError(F, 'limit', 'slice segments exceed triangle-derived limit');
|
|
127
|
+
const p1 = a.p1 === undefined ? undefined : index(a.p1, 'p1');
|
|
128
|
+
s.polygon.segments.push({
|
|
129
|
+
vertex: index(a.v2, 'v2'),
|
|
130
|
+
pid: a.pid,
|
|
131
|
+
p1,
|
|
132
|
+
p2: a.p2 === undefined ? p1 : index(a.p2, 'p2'),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (['basematerials', 'colorgroup', 'texture2dgroup', 'compositematerials', 'multiproperties'].includes(name)) {
|
|
136
|
+
if (!a.id || s.properties.has(a.id))
|
|
137
|
+
throw new LoaderError(F, 'syntax', 'missing or duplicate property resource id');
|
|
138
|
+
s.property = { part: '', id: a.id, kind: name, attributes: own(a), entries: [] };
|
|
139
|
+
s.properties.set(a.id, s.property);
|
|
140
|
+
}
|
|
141
|
+
else if (['base', 'color', 'tex2coord', 'composite', 'multi'].includes(name) && s.property)
|
|
142
|
+
s.property.entries.push(own(a));
|
|
143
|
+
},
|
|
144
|
+
close(m, name) {
|
|
145
|
+
const s = state(m);
|
|
146
|
+
lattices.close(s, name);
|
|
147
|
+
if (name === 'object') {
|
|
148
|
+
if (s.object)
|
|
149
|
+
s.object.vertices = Float64Array.from(s.xyz);
|
|
150
|
+
s.object = undefined;
|
|
151
|
+
s.xyz = [];
|
|
152
|
+
}
|
|
153
|
+
else if (name === 'slice' && s.slice) {
|
|
154
|
+
s.slice.vertices = Float64Array.from(s.xy);
|
|
155
|
+
s.slice = undefined;
|
|
156
|
+
s.xy = [];
|
|
157
|
+
}
|
|
158
|
+
else if (name === 'polygon')
|
|
159
|
+
s.polygon = undefined;
|
|
160
|
+
else if (name === 'slicestack')
|
|
161
|
+
s.stack = undefined;
|
|
162
|
+
if (name === s.property?.kind)
|
|
163
|
+
s.property = undefined;
|
|
164
|
+
},
|
|
165
|
+
async ready(read, context) {
|
|
166
|
+
const relationships = new Map();
|
|
167
|
+
const related = async (part, path) => {
|
|
168
|
+
const target = normalize(resolvePath(part, path));
|
|
169
|
+
if (target === part)
|
|
170
|
+
return;
|
|
171
|
+
let targets = relationships.get(part);
|
|
172
|
+
if (!targets) {
|
|
173
|
+
const at = part.lastIndexOf('/'), name = part.slice(at + 1), folder = part.slice(0, at + 1);
|
|
174
|
+
const tree = readXMLTree(decodeXML(await read(folder + '_rels/' + name + '.rels')), F);
|
|
175
|
+
targets = new Set();
|
|
176
|
+
for (const root of tree.children)
|
|
177
|
+
for (const rel of root.children)
|
|
178
|
+
if (rel.name === 'Relationship' &&
|
|
179
|
+
rel.attributes.Type?.endsWith('/3dmodel') &&
|
|
180
|
+
rel.attributes.TargetMode !== 'External' &&
|
|
181
|
+
rel.attributes.Target)
|
|
182
|
+
targets.add(normalize(resolvePath(part, rel.attributes.Target)));
|
|
183
|
+
relationships.set(part, targets);
|
|
184
|
+
}
|
|
185
|
+
if (!targets.has(target))
|
|
186
|
+
throw new LoaderError(F, 'syntax', 'external slice model has no OPC model relationship');
|
|
187
|
+
};
|
|
188
|
+
// Model parts loaded here use the same reader and material hooks as the root, including 2D vertices.
|
|
189
|
+
for (const [part, m] of context.models) {
|
|
190
|
+
const s = state(m);
|
|
191
|
+
s.part = part;
|
|
192
|
+
const paths = [
|
|
193
|
+
...[...s.objects.values()].flatMap((o) => (o.slices?.part ? [o.slices.part] : [])),
|
|
194
|
+
...[...s.stacks.values()].flatMap((stack) => stack.references.map((r) => r.part)),
|
|
195
|
+
];
|
|
196
|
+
for (const path of paths) {
|
|
197
|
+
await related(part, path);
|
|
198
|
+
await context.loadModelPart(resolvePath(part, path));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const checkProperty = (s, id, p) => {
|
|
202
|
+
if (p === undefined)
|
|
203
|
+
return;
|
|
204
|
+
const resource = id && s.properties.get(id);
|
|
205
|
+
if (!resource || p >= resource.entries.length)
|
|
206
|
+
throw new LoaderError(F, 'range', 'native property index is outside its resource');
|
|
207
|
+
};
|
|
208
|
+
for (const [m, s] of states) {
|
|
209
|
+
throwIfAborted(options.signal, F);
|
|
210
|
+
for (const resource of s.properties.values()) {
|
|
211
|
+
resource.part = s.part;
|
|
212
|
+
const colors = m.properties.get(resource.id);
|
|
213
|
+
if (colors)
|
|
214
|
+
resource.colors = Float64Array.from(colors.flat());
|
|
215
|
+
if (resource.kind === 'compositematerials') {
|
|
216
|
+
const indices = list(resource.attributes.matindices, 'matindices').map((n) => index(String(n), 'matindex')), base = s.properties.get(resource.attributes.matid);
|
|
217
|
+
if (!base || base.kind !== 'basematerials' || indices.some((n) => n >= base.entries.length))
|
|
218
|
+
throw new LoaderError(F, 'range', 'composite materials reference invalid base materials');
|
|
219
|
+
resource.materialId = base.id;
|
|
220
|
+
resource.materialIndices = Uint32Array.from(indices);
|
|
221
|
+
resource.weights = resource.entries.map((e) => {
|
|
222
|
+
const source = list(e.values, 'composite weights'), weights = indices.map((_, i) => source[i] ?? 0);
|
|
223
|
+
if (weights.some((w) => w < 0))
|
|
224
|
+
throw new LoaderError(F, 'range', 'invalid composite weight row');
|
|
225
|
+
const sum = weights.reduce((a, b) => a + b, 0);
|
|
226
|
+
return Float64Array.from(weights, (w) => (sum ? w / sum : 1 / indices.length));
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
else if (resource.kind === 'multiproperties') {
|
|
230
|
+
const pids = resource.attributes.pids?.trim().split(/\s+/);
|
|
231
|
+
if (!pids?.length ||
|
|
232
|
+
pids.some((id) => !s.properties.has(id) || s.properties.get(id).kind === 'multiproperties'))
|
|
233
|
+
throw new LoaderError(F, 'range', 'invalid multi-property resource references');
|
|
234
|
+
resource.propertyIds = pids;
|
|
235
|
+
const blends = resource.attributes.blendmethods?.trim().split(/\s+/) ?? [];
|
|
236
|
+
if (blends.length >= pids.length || blends.some((b) => b !== 'mix' && b !== 'multiply'))
|
|
237
|
+
throw new LoaderError(F, 'range', 'invalid multi-property blend methods');
|
|
238
|
+
resource.blendMethods = Array.from({ length: pids.length - 1 }, (_, i) => (blends[i] ?? 'mix'));
|
|
239
|
+
resource.rows = resource.entries.map((e) => {
|
|
240
|
+
const source = list(e.pindices, 'pindices');
|
|
241
|
+
const row = pids.map((_, i) => index(String(source[i] ?? 0), 'property index'));
|
|
242
|
+
row.forEach((n, i) => checkProperty(s, pids[i], n));
|
|
243
|
+
return Uint32Array.from(row);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
for (const o of s.objects.values()) {
|
|
248
|
+
o.part = s.part;
|
|
249
|
+
o.triangles = m.objects.get(o.id)?.mesh?.triangles.result() ?? new Uint32Array();
|
|
250
|
+
if (o.slices)
|
|
251
|
+
o.slices.part = o.slices.part ? normalize(resolvePath(s.part, o.slices.part)) : s.part;
|
|
252
|
+
if (o.slices?.resolution === 'lowres' && !s.requiredSlice)
|
|
253
|
+
throw new LoaderError(F, 'syntax', 'lowres slice objects require the slice namespace in requiredextensions');
|
|
254
|
+
const l = o.lattice;
|
|
255
|
+
if (!l)
|
|
256
|
+
continue;
|
|
257
|
+
if (!m.objects.get(o.id)?.mesh || m.objects.get(o.id).components.length)
|
|
258
|
+
throw new LoaderError(F, 'syntax', 'lattice object requires a mesh');
|
|
259
|
+
finishLattice(l, o.vertices, (pid, p) => checkProperty(s, pid, p));
|
|
260
|
+
for (const set of l.sets)
|
|
261
|
+
if (set.beams.some((i) => i >= l.beams.length) || set.balls.some((i) => i >= l.balls.length))
|
|
262
|
+
throw new LoaderError(F, 'range', 'beamset index outside source arrays');
|
|
263
|
+
for (const id of [l.clippingMesh, l.representationMesh])
|
|
264
|
+
if (id !== undefined) {
|
|
265
|
+
const target = s.objects.get(id);
|
|
266
|
+
const ids = [...s.objects.keys()];
|
|
267
|
+
if (!target ||
|
|
268
|
+
target === o ||
|
|
269
|
+
target.type !== 'model' ||
|
|
270
|
+
target.lattice ||
|
|
271
|
+
!target.triangles.length ||
|
|
272
|
+
ids.indexOf(id) >= ids.indexOf(o.id))
|
|
273
|
+
throw new LoaderError(F, 'range', 'clipping/representation mesh must be an earlier non-lattice model mesh');
|
|
274
|
+
}
|
|
275
|
+
if (l.clippingMode !== 'none' && !l.clippingMesh)
|
|
276
|
+
throw new LoaderError(F, 'syntax', 'clippingmode requires clippingmesh');
|
|
277
|
+
}
|
|
278
|
+
for (const stack of s.stacks.values()) {
|
|
279
|
+
stack.part = s.part;
|
|
280
|
+
if (stack.slices.length && stack.references.length)
|
|
281
|
+
throw new LoaderError(F, 'syntax', 'slice stack cannot mix inline slices and references');
|
|
282
|
+
let previous = stack.bottom;
|
|
283
|
+
for (const slice of stack.slices) {
|
|
284
|
+
if (slice.top <= previous)
|
|
285
|
+
throw new LoaderError(F, 'range', 'slice tops must strictly increase above zbottom');
|
|
286
|
+
previous = slice.top;
|
|
287
|
+
if ((slice.vertices.length && !slice.polygons.length) || (!slice.vertices.length && slice.polygons.length))
|
|
288
|
+
throw new LoaderError(F, 'syntax', 'nonvoid slice needs vertices and polygons');
|
|
289
|
+
for (const polygon of slice.polygons) {
|
|
290
|
+
if (polygon.start >= slice.vertices.length / 2 || !polygon.segments.length)
|
|
291
|
+
throw new LoaderError(F, 'range', 'invalid slice polygon start or empty segments');
|
|
292
|
+
let v = polygon.start;
|
|
293
|
+
for (const segment of polygon.segments) {
|
|
294
|
+
if (segment.vertex >= slice.vertices.length / 2 || segment.vertex === v)
|
|
295
|
+
throw new LoaderError(F, 'range', 'invalid slice segment vertex');
|
|
296
|
+
if (segment.pid !== undefined) {
|
|
297
|
+
checkProperty(s, segment.pid, segment.p1);
|
|
298
|
+
checkProperty(s, segment.pid, segment.p2);
|
|
299
|
+
if (s.properties.get(segment.pid)?.kind === 'texture2dgroup')
|
|
300
|
+
throw new LoaderError(F, 'range', 'slice segments cannot reference image properties');
|
|
301
|
+
}
|
|
302
|
+
v = segment.vertex;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
const byPart = new Map([...states.values()].map((s) => [s.part, s]));
|
|
309
|
+
for (const s of states.values())
|
|
310
|
+
for (const stack of s.stacks.values()) {
|
|
311
|
+
stack.layers = [...stack.slices];
|
|
312
|
+
let previous = stack.bottom;
|
|
313
|
+
for (const ref of stack.references) {
|
|
314
|
+
ref.part = normalize(resolvePath(s.part, ref.part));
|
|
315
|
+
const target = byPart.get(ref.part)?.stacks.get(ref.id);
|
|
316
|
+
if (!target || target.part === stack.part || target.references.length)
|
|
317
|
+
throw new LoaderError(F, 'range', 'slice reference must target an external stack without references');
|
|
318
|
+
for (const layer of target.slices) {
|
|
319
|
+
if (++expandedLayers > maxSlices)
|
|
320
|
+
throw new LoaderError(F, 'limit', 'expanded slice references exceed maxSlices');
|
|
321
|
+
if (layer.top <= previous)
|
|
322
|
+
throw new LoaderError(F, 'range', 'referenced slice heights do not increase');
|
|
323
|
+
stack.layers.push(layer);
|
|
324
|
+
previous = layer.top;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
for (const s of states.values())
|
|
329
|
+
for (const o of s.objects.values())
|
|
330
|
+
if (o.slices) {
|
|
331
|
+
const stack = byPart.get(o.slices.part)?.stacks.get(o.slices.id);
|
|
332
|
+
if (!stack)
|
|
333
|
+
throw new LoaderError(F, 'range', 'object references a missing slice stack');
|
|
334
|
+
for (const layer of stack.layers)
|
|
335
|
+
for (const polygon of layer.polygons) {
|
|
336
|
+
if ((o.type === 'model' || o.type === 'solidsupport') &&
|
|
337
|
+
polygon.segments.at(-1)?.vertex !== polygon.start)
|
|
338
|
+
throw new LoaderError(F, 'range', 'solid slice contour is not closed');
|
|
339
|
+
for (const segment of polygon.segments)
|
|
340
|
+
if (segment.pid === undefined) {
|
|
341
|
+
checkProperty(s, o.pid, segment.p1);
|
|
342
|
+
checkProperty(s, o.pid, segment.p2);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
instance(m, obj, transform, unitScale, depth) {
|
|
348
|
+
const s = state(m), o = s.objects.get(obj.id);
|
|
349
|
+
const instance = { object: o, transform: new Float64Array(transform), unitScale };
|
|
350
|
+
instances.push(instance);
|
|
351
|
+
ancestors.length = depth;
|
|
352
|
+
const inherited = ancestors.some(Boolean);
|
|
353
|
+
ancestors[depth] = inherited || !!o.slices;
|
|
354
|
+
if (o.slices && !inherited) {
|
|
355
|
+
if (transform[2] !== 0 || transform[5] !== 0 || transform[6] !== 0 || transform[7] !== 0 || transform[8] !== 1)
|
|
356
|
+
throw new LoaderError(F, 'range', 'slice build transform must preserve the slicing plane');
|
|
357
|
+
const owner = [...states.values()].find((s) => s.part === o.slices.part);
|
|
358
|
+
sliceInstances.push({ ...instance, stack: owner.stacks.get(o.slices.id) });
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
hasGeometry() {
|
|
362
|
+
return instances.some((i) => i.object.lattice?.activeBeams.length);
|
|
363
|
+
},
|
|
364
|
+
bucket() {
|
|
365
|
+
return '';
|
|
366
|
+
},
|
|
367
|
+
corner() { },
|
|
368
|
+
group() { },
|
|
369
|
+
};
|
|
370
|
+
const mesh = await read3MFMaterials(input, options, hooks);
|
|
371
|
+
return {
|
|
372
|
+
...mesh,
|
|
373
|
+
objects: [...states.values()].flatMap((s) => [...s.objects.values()]),
|
|
374
|
+
instances,
|
|
375
|
+
sliceStacks: [...states.values()].flatMap((s) => [...s.stacks.values()]),
|
|
376
|
+
sliceInstances,
|
|
377
|
+
propertyResources: [...states.values()].flatMap((s) => [...s.properties.values()]),
|
|
378
|
+
};
|
|
379
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type FieldScope } from './threemf-functions.js';
|
|
2
|
+
import type { ThreeMFSampledField } from './threemf-volumetric.js';
|
|
3
|
+
import type { ThreeMFMesh } from './threemf.js';
|
|
4
|
+
/** The most cells along the longest side. */
|
|
5
|
+
export declare const MAX_CELLS = 512;
|
|
6
|
+
export interface LevelSetOptions {
|
|
7
|
+
/** Cells wanted along the longest side of the domain. */
|
|
8
|
+
resolution: number;
|
|
9
|
+
maxTriangles: number;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The triangles of a level set in its object's coordinates, and whether its grid is too coarse for the
|
|
14
|
+
* `minfeaturesize` the file asks for (two cells to a feature).
|
|
15
|
+
*/
|
|
16
|
+
export declare function meshLevelSet(scope: FieldScope, levelSet: ThreeMFSampledField & {
|
|
17
|
+
meshId: string;
|
|
18
|
+
boundingBoxOnly: boolean;
|
|
19
|
+
}, domain: ArrayLike<number>, { resolution, maxTriangles, signal }: LevelSetOptions): Promise<{
|
|
20
|
+
mesh: ThreeMFMesh;
|
|
21
|
+
cell: number;
|
|
22
|
+
coarse: boolean;
|
|
23
|
+
}>;
|