@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,105 @@
|
|
|
1
|
+
// Meshes a 3MF level set (volumetric extension chapter 4): the part of the domain mesh, or of its box, where the
|
|
2
|
+
// function is below zero, polygonized by `@margoengine/procedural`'s Marching Cubes on max(function, domain distance).
|
|
3
|
+
// The grid's points are multiples of a power of two, so blocks of it meshed one after another meet in the same
|
|
4
|
+
// vertices.
|
|
5
|
+
import { compileField } from './threemf-functions.js';
|
|
6
|
+
import { LoaderError } from './types.js';
|
|
7
|
+
import { floats, throwIfAborted, uints } from './util.js';
|
|
8
|
+
const F = '3MF';
|
|
9
|
+
/** Cells along the side of a block: the most points `marchingCubes` takes on one axis is 128. */
|
|
10
|
+
const BLOCK = 32;
|
|
11
|
+
/** The most cells along the longest side. */
|
|
12
|
+
export const MAX_CELLS = 512;
|
|
13
|
+
const NONE = 0xffffffff;
|
|
14
|
+
/** The signed distance to an axis-aligned box, negative inside. */
|
|
15
|
+
const boxDistance = (low, high) => (x, y, z) => {
|
|
16
|
+
const a = Math.max(low[0] - x, x - high[0]), b = Math.max(low[1] - y, y - high[1]), c = Math.max(low[2] - z, z - high[2]), inner = Math.max(a, b, c);
|
|
17
|
+
return inner <= 0 ? inner : Math.hypot(Math.max(a, 0), Math.max(b, 0), Math.max(c, 0));
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The triangles of a level set in its object's coordinates, and whether its grid is too coarse for the
|
|
21
|
+
* `minfeaturesize` the file asks for (two cells to a feature).
|
|
22
|
+
*/
|
|
23
|
+
export async function meshLevelSet(scope, levelSet, domain, { resolution, maxTriangles, signal }) {
|
|
24
|
+
const { marchingCubes } = await import('@margoengine/procedural/marching-cubes');
|
|
25
|
+
const low = [Infinity, Infinity, Infinity], high = [-Infinity, -Infinity, -Infinity];
|
|
26
|
+
for (let i = 0; i < domain.length; i++) {
|
|
27
|
+
low[i % 3] = Math.min(low[i % 3], domain[i]);
|
|
28
|
+
high[i % 3] = Math.max(high[i % 3], domain[i]);
|
|
29
|
+
}
|
|
30
|
+
const longest = Math.max(...high.map((v, k) => v - low[k]));
|
|
31
|
+
if (!(longest > 0))
|
|
32
|
+
throw new LoaderError(F, 'syntax', `the domain mesh ${levelSet.meshId.slice(0, 32)} is empty`);
|
|
33
|
+
const { minFeatureSize, fallback, transform } = levelSet, wanted = Math.max(longest / MAX_CELLS, Math.min(longest / resolution, minFeatureSize > 0 ? minFeatureSize / 2 : Infinity)), cell = 2 ** Math.floor(Math.log2(wanted));
|
|
34
|
+
const inside = levelSet.boundingBoxOnly ? boxDistance(low, high) : scope.distance(levelSet.meshId, true);
|
|
35
|
+
const pos = new Float64Array(3), program = compileField(scope, levelSet.functionId, new Map([['pos', pos]])), output = program.outputs.get(levelSet.channel);
|
|
36
|
+
const m = transform ?? [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
|
|
37
|
+
const first = low.map((v) => Math.floor(v / cell) - 1), last = high.map((v) => Math.ceil(v / cell) + 1);
|
|
38
|
+
// The domain distance at the centres of cubes of 8 cells: a distance changes no faster than its point moves, so a
|
|
39
|
+
// cube whose centre is farther from the domain's surface than its corners lies wholly inside or outside it.
|
|
40
|
+
const coarseCell = 8 * cell, corner = (Math.sqrt(3) / 2) * coarseCell, centres = new Map();
|
|
41
|
+
const bound = (x, y, z) => {
|
|
42
|
+
const i = Math.floor(x / coarseCell), j = Math.floor(y / coarseCell), k = Math.floor(z / coarseCell), key = `${i} ${j} ${k}`;
|
|
43
|
+
let centre = centres.get(key);
|
|
44
|
+
if (centre === undefined)
|
|
45
|
+
centres.set(key, (centre = inside((i + 0.5) * coarseCell, (j + 0.5) * coarseCell, (k + 0.5) * coarseCell)));
|
|
46
|
+
return centre < -corner ? -Infinity : centre > corner ? centre - corner : inside(x, y, z);
|
|
47
|
+
};
|
|
48
|
+
// max(function, domain distance) in sign; the domain is asked only where the function is not already outside.
|
|
49
|
+
const field = (x, y, z) => {
|
|
50
|
+
for (let k = 0; k < 3; k++)
|
|
51
|
+
pos[k] = x * m[k] + y * m[3 + k] + z * m[6 + k] + m[9 + k];
|
|
52
|
+
program.run();
|
|
53
|
+
const value = Number.isFinite(output[0]) ? output[0] : fallback;
|
|
54
|
+
return value > 0 ? value : Math.max(value, bound(x, y, z));
|
|
55
|
+
};
|
|
56
|
+
const vertices = floats(), triangles = uints(), welded = new Map();
|
|
57
|
+
for (let z = first[2]; z < last[2]; z += BLOCK)
|
|
58
|
+
for (let y = first[1]; y < last[1]; y += BLOCK)
|
|
59
|
+
for (let x = first[0]; x < last[0]; x += BLOCK) {
|
|
60
|
+
throwIfAborted(signal, F);
|
|
61
|
+
const from = [x, y, z], cells = from.map((v, k) => Math.max(2, Math.min(BLOCK, last[k] - v))), centre = from.map((v, k) => (v + cells[k] / 2) * cell), reach = (Math.hypot(...cells) / 2) * cell;
|
|
62
|
+
// A distance changes no faster than its point moves: a block this far outside the domain holds no surface.
|
|
63
|
+
if (inside(centre[0], centre[1], centre[2]) > reach)
|
|
64
|
+
continue;
|
|
65
|
+
const surface = marchingCubes(field, {
|
|
66
|
+
resolution: [cells[0] + 1, cells[1] + 1, cells[2] + 1],
|
|
67
|
+
bounds: [
|
|
68
|
+
[from[0] * cell, from[1] * cell, from[2] * cell],
|
|
69
|
+
[(from[0] + cells[0]) * cell, (from[1] + cells[1]) * cell, (from[2] + cells[2]) * cell],
|
|
70
|
+
],
|
|
71
|
+
});
|
|
72
|
+
if (!surface)
|
|
73
|
+
continue;
|
|
74
|
+
const points = surface.vertices, stride = 6, ids = [];
|
|
75
|
+
for (let i = 0; i < points.length; i += stride) {
|
|
76
|
+
const key = `${points[i]},${points[i + 1]},${points[i + 2]}`;
|
|
77
|
+
let id = welded.get(key);
|
|
78
|
+
if (id === undefined) {
|
|
79
|
+
id = vertices.length / 3;
|
|
80
|
+
welded.set(key, id);
|
|
81
|
+
vertices.push3(points[i], points[i + 1], points[i + 2]);
|
|
82
|
+
}
|
|
83
|
+
ids.push(id);
|
|
84
|
+
}
|
|
85
|
+
const index = surface.indices;
|
|
86
|
+
for (let t = 0; t < index.length; t += 3) {
|
|
87
|
+
const a = ids[index[t]], b = ids[index[t + 1]], c = ids[index[t + 2]];
|
|
88
|
+
if (a === b || b === c || c === a)
|
|
89
|
+
continue;
|
|
90
|
+
if (triangles.length / 3 >= maxTriangles)
|
|
91
|
+
throw new LoaderError(F, 'limit', `a level set exceeds ${maxTriangles} triangles; lower levelSetResolution or raise maxTriangles`);
|
|
92
|
+
triangles.push3(a, b, c);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const count = triangles.length / 3, pid = uints(), p = uints();
|
|
96
|
+
for (let t = 0; t < count; t++) {
|
|
97
|
+
pid.push(NONE);
|
|
98
|
+
p.push3(NONE, NONE, NONE);
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
mesh: { vertices, triangles, pid, p },
|
|
102
|
+
cell,
|
|
103
|
+
coarse: minFeatureSize > 0 && cell > minFeatureSize / 2,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { type LoadedGroup } from './types.js';
|
|
2
|
+
import type { BinaryInput } from './util.js';
|
|
3
|
+
import { type ThreeMFExtension, type ThreeMFOptions, type ThreeMFResult } from './threemf.js';
|
|
4
|
+
/** One `<texture2d>` of a package with the bytes of its image. */
|
|
5
|
+
export interface ThreeMFTexture {
|
|
6
|
+
/** The part's path in the package. */
|
|
7
|
+
path: string;
|
|
8
|
+
/** `image/png` or `image/jpeg`, as the file declares. */
|
|
9
|
+
contentType: string;
|
|
10
|
+
/** The image file, ready for `createImageBitmap`. */
|
|
11
|
+
data: Uint8Array;
|
|
12
|
+
/** How u and v repeat: `wrap` (the default), `mirror`, `clamp` or `none`. */
|
|
13
|
+
tileStyleU: string;
|
|
14
|
+
tileStyleV: string;
|
|
15
|
+
/** `auto` (the default), `linear` or `nearest`. */
|
|
16
|
+
filter: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* One layer of a `multiproperties` stack, in the order its `pids` list them (bottom first). Its per-vertex values are in
|
|
20
|
+
* `attributes[attribute]`: four numbers per vertex for a colour layer (sRGB red, green, blue and linear alpha), two for a
|
|
21
|
+
* texture layer (u and v, v = 1 - the file's v as in `uvs`). Vertices outside the group hold zeros.
|
|
22
|
+
*/
|
|
23
|
+
export interface ThreeMFLayer {
|
|
24
|
+
/** `'color'` for a base material, composite or colour group layer, `'texture'` for a texture group layer. */
|
|
25
|
+
kind: 'color' | 'texture';
|
|
26
|
+
/** A texture layer's index into `textures`. */
|
|
27
|
+
texture?: number;
|
|
28
|
+
/** `layerColor<k>` or `layerUV<k>`, k the layer's place in the stack. */
|
|
29
|
+
attribute: string;
|
|
30
|
+
/**
|
|
31
|
+
* How the layer goes over the result of the layers below (`blendmethods`): `'mix'` (the default) or `'multiply'`. The
|
|
32
|
+
* spec blends in linear light: mix is `rgb = new.rgb * new.a + below.rgb * (1 - new.a)`, `a = new.a + below.a * (1 -
|
|
33
|
+
* new.a)`; multiply is `rgb = new.rgb * below.rgb`, `a = new.a * below.a`. The first layer starts the stack, opaque.
|
|
34
|
+
*/
|
|
35
|
+
blend: 'mix' | 'multiply';
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The metalness and roughness a group's triangles are shown with: the materials extension's `pbmetallic`, or its
|
|
39
|
+
* `pbmetallictexturedisplayproperties` (chapter 7 of the extension).
|
|
40
|
+
*/
|
|
41
|
+
export interface ThreeMFMetallic {
|
|
42
|
+
/** The element's `name`, usually the material's. */
|
|
43
|
+
name: string;
|
|
44
|
+
/** The metalness, 0 to 1. With `metalnessTexture` it is the factor over the sampled value (default 1). */
|
|
45
|
+
metalness: number;
|
|
46
|
+
/** The roughness, 0 to 1. With `roughnessTexture` it is the factor over the sampled value (default 1). */
|
|
47
|
+
roughness: number;
|
|
48
|
+
/**
|
|
49
|
+
* Index into `textures` of the linear map metalness is sampled from, at the group's own coordinates and with the tile
|
|
50
|
+
* style and filter of its colour texture: the red channel, or the green one when `roughnessTexture` is the same
|
|
51
|
+
* resource.
|
|
52
|
+
*/
|
|
53
|
+
metalnessTexture?: number;
|
|
54
|
+
/** Index into `textures` of the linear map roughness is sampled from, in its red channel. */
|
|
55
|
+
roughnessTexture?: number;
|
|
56
|
+
/** `basecolorfactor`, sRGB red, green, blue and linear alpha over the colour texture, when it is not white. */
|
|
57
|
+
baseColorFactor?: [number, number, number, number];
|
|
58
|
+
/** In a `multiproperties` stack, the index of the layer these properties come from. */
|
|
59
|
+
layer?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The specular colour and glossiness a group's triangles are shown with: the materials extension's `pbspecular`, or its
|
|
63
|
+
* `pbspeculartexturedisplayproperties` (chapter 7 of the extension). The diffuse colour is the group's own colour or
|
|
64
|
+
* colour texture.
|
|
65
|
+
*/
|
|
66
|
+
export interface ThreeMFSpecular {
|
|
67
|
+
/** The element's `name`, usually the material's. */
|
|
68
|
+
name: string;
|
|
69
|
+
/**
|
|
70
|
+
* Reflectance at normal incidence, sRGB red, green and blue (default `#383838`, 4 % in linear light, as plastics have).
|
|
71
|
+
* With `specularTexture` it is the factor over the sampled colour (default white).
|
|
72
|
+
*/
|
|
73
|
+
specularColor: [number, number, number];
|
|
74
|
+
/** Smoothness, 0 (rough, the default) to 1 (mirror). With `glossinessTexture` it is the factor (default 1). */
|
|
75
|
+
glossiness: number;
|
|
76
|
+
/** Index into `textures` of the sRGB map the specular colour is sampled from, at the group's own coordinates. */
|
|
77
|
+
specularTexture?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Index into `textures` of the linear map glossiness is sampled from: the alpha channel when it is the same resource
|
|
80
|
+
* as `specularTexture`, else the red one.
|
|
81
|
+
*/
|
|
82
|
+
glossinessTexture?: number;
|
|
83
|
+
/** `diffusefactor`, sRGB red, green, blue and linear alpha over the colour texture, when it is not white. */
|
|
84
|
+
diffuseFactor?: [number, number, number, number];
|
|
85
|
+
/** In a `multiproperties` stack, the index of the layer these properties come from. */
|
|
86
|
+
layer?: number;
|
|
87
|
+
}
|
|
88
|
+
/** The volume a translucent group's triangles enclose: the materials extension's `translucent` (section 7.5). */
|
|
89
|
+
export interface ThreeMFTranslucent {
|
|
90
|
+
/** The element's `name`, usually the print material's. */
|
|
91
|
+
name: string;
|
|
92
|
+
/**
|
|
93
|
+
* Linear attenuation of red, green and blue per metre, whatever the model's unit: light keeps `exp(-a * t)` of itself
|
|
94
|
+
* after `t` metres inside (Beer-Lambert). 0 is clear.
|
|
95
|
+
*/
|
|
96
|
+
attenuation: [number, number, number];
|
|
97
|
+
/** Index of refraction of red, green and blue. Default 1, 1, 1: light passes straight through. */
|
|
98
|
+
refractiveIndex: [number, number, number];
|
|
99
|
+
/** Roughness of the surface, 0 (the default) to 1. */
|
|
100
|
+
roughness: number;
|
|
101
|
+
/** In a `multiproperties` stack, the index of the layer these properties come from. */
|
|
102
|
+
layer?: number;
|
|
103
|
+
}
|
|
104
|
+
/** A group of {@link ThreeMFMaterials}: {@link LoadedGroup} with the texture its triangles sample. */
|
|
105
|
+
export interface ThreeMFMaterialGroup extends LoadedGroup {
|
|
106
|
+
/** Index into `textures`: the group's only texture, or the first texture layer of its `layers`. */
|
|
107
|
+
texture?: number;
|
|
108
|
+
/** The whole layer stack, when the group's triangles use a `multiproperties`; `create3MFMesh` draws it. */
|
|
109
|
+
layers?: ThreeMFLayer[];
|
|
110
|
+
/**
|
|
111
|
+
* The metallic display properties of the group's triangles (their first corner's, as the spec says). A group has at
|
|
112
|
+
* most one of `metallic`, `specular` and `translucent`, and none when the file gives no display properties. In a stack
|
|
113
|
+
* they are those of the lowest layer that has any. `create3MFMesh` draws them.
|
|
114
|
+
*/
|
|
115
|
+
metallic?: ThreeMFMetallic;
|
|
116
|
+
/** The specular display properties of the group's triangles, chosen as `metallic` is. */
|
|
117
|
+
specular?: ThreeMFSpecular;
|
|
118
|
+
/** The translucent display properties of the group's triangles, chosen as `metallic` is. */
|
|
119
|
+
translucent?: ThreeMFTranslucent;
|
|
120
|
+
}
|
|
121
|
+
/** What {@link parse3MFMaterials} returns: {@link ThreeMFResult} with textures, and one vertex per triangle corner. */
|
|
122
|
+
export interface ThreeMFMaterials extends ThreeMFResult {
|
|
123
|
+
groups: ThreeMFMaterialGroup[];
|
|
124
|
+
/** Every texture the package declares. */
|
|
125
|
+
textures: ThreeMFTexture[];
|
|
126
|
+
/**
|
|
127
|
+
* Metres in one unit of `positions`, which the reader sets: 1, or the length of the model's unit with
|
|
128
|
+
* `units: 'file'`. Default 1.
|
|
129
|
+
*/
|
|
130
|
+
metresPerUnit?: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Reads a 3MF package like `parse3MF` and adds the materials extension: `texture2d` images, `texture2dgroup`
|
|
134
|
+
* coordinates, `compositematerials` as mixed colours, `multiproperties` layers, and the display properties as each
|
|
135
|
+
* group's `metallic` (`pbmetallic` and `pbmetallictexturedisplayproperties`), `specular` (`pbspecular` and
|
|
136
|
+
* `pbspeculartexturedisplayproperties`) or `translucent`. Every triangle corner gets its own
|
|
137
|
+
* vertex, so `uvs` and `colors` can differ across a seam; `uvs` use Margo's convention, v = 1 - the file's v. `colors` is
|
|
138
|
+
* present when corners of a triangle differ or a layer sets them. A group's `texture` indexes `textures`. In
|
|
139
|
+
* `multiproperties` colour layers mix by their alpha, and the first texture layer sets the group's texture: draw
|
|
140
|
+
* `colors` as a tint over it.
|
|
141
|
+
*
|
|
142
|
+
* @param input The package's bytes.
|
|
143
|
+
* @param options The same options as `parse3MF`.
|
|
144
|
+
* @returns The merged mesh with its coordinates, colours and images.
|
|
145
|
+
* @throws LoaderError with the codes of `parse3MF`, with `range` for a property index outside its group or its display
|
|
146
|
+
* properties, for a metalness, roughness or glossiness outside 0 to 1 (a texture's factor: below 0), a negative
|
|
147
|
+
* attenuation or a refractive index of 0 or less, and `syntax` for display properties that are not defined or are of a
|
|
148
|
+
* kind their group cannot take, and for a colour or a number triplet that is not one.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* import { parse3MFMaterials } from '@margoengine/loaders/threemf-materials';
|
|
153
|
+
*
|
|
154
|
+
* const bytes = await (await fetch('/prints/lithophane.3mf')).arrayBuffer();
|
|
155
|
+
* const { groups, textures, uvs } = await parse3MFMaterials(bytes);
|
|
156
|
+
* const image = await createImageBitmap(new Blob([textures[groups[0].texture ?? 0].data]));
|
|
157
|
+
* console.log(image.width, uvs?.length);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function parse3MFMaterials(input: BinaryInput, options?: ThreeMFOptions): Promise<ThreeMFMaterials>;
|
|
161
|
+
/** Shared materials reader with optional additional format hooks, used by the lattice/slice entry. */
|
|
162
|
+
export declare function read3MFMaterials(input: BinaryInput, options: ThreeMFOptions, extra?: ThreeMFExtension): Promise<ThreeMFMaterials>;
|