@margoengine/loaders 0.1.0 → 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 -201
- package/NOTICE +4 -4
- package/README.md +1666 -1198
- package/dist/crease.d.ts +7 -0
- package/dist/crease.js +67 -0
- package/dist/dae-common.js +1 -1
- package/dist/dae-kinematics.d.ts +65 -0
- package/dist/dae-kinematics.js +461 -0
- package/dist/dae.d.ts +9 -4
- package/dist/dae.js +16 -5
- 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 +42 -1
- package/dist/dxf.js +226 -15
- package/dist/engine.d.ts +5 -0
- package/dist/engine.js +3 -0
- package/dist/gcode.d.ts +37 -0
- package/dist/gcode.js +91 -0
- package/dist/geometry.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/mtl.d.ts +8 -3
- package/dist/mtl.js +91 -10
- package/dist/nrrd.d.ts +12 -5
- package/dist/nrrd.js +68 -26
- package/dist/obj.d.ts +3 -1
- package/dist/obj.js +7 -1
- package/dist/render.d.ts +9 -4
- package/dist/render.js +31 -3
- package/dist/shared/asset-url.js +82 -82
- package/dist/shared/crc32.d.ts +2 -2
- package/dist/shared/crc32.js +47 -47
- package/dist/shared/errors.js +36 -36
- package/dist/shared/inflate.js +284 -284
- package/dist/shared/normals.js +26 -26
- package/dist/shared/scene-scope.js +54 -54
- package/dist/shared/trailing-data.js +45 -42
- 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.js +10 -145
- package/dist/threemf-levelset.d.ts +23 -0
- package/dist/threemf-levelset.js +105 -0
- package/dist/threemf-materials.d.ts +89 -2
- package/dist/threemf-materials.js +194 -11
- package/dist/threemf-mesh.d.ts +21 -6
- package/dist/threemf-mesh.js +266 -45
- 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 +73 -4
- package/dist/threemf.js +235 -41
- package/dist/types.d.ts +18 -0
- package/dist/workers/usd.js +1 -1
- package/package.json +291 -246
|
@@ -1,9 +1,37 @@
|
|
|
1
|
-
// 3MF materials extension on top of parse3MF: texture2d, texture2dgroup, compositematerials and
|
|
1
|
+
// 3MF materials extension on top of parse3MF: texture2d, texture2dgroup, compositematerials, multiproperties and the
|
|
2
|
+
// display properties (metallic, specular and translucent).
|
|
2
3
|
import { LoaderError } from './types.js';
|
|
3
4
|
import { floats } from './util.js';
|
|
4
|
-
import { SRGBToLinear, LinearToSRGB } from '@margoengine/math/color';
|
|
5
|
-
import { cornerProperty, read3MF, } from './threemf.js';
|
|
5
|
+
import { SRGBToLinear, LinearToSRGB, hexColor } from '@margoengine/math/color';
|
|
6
|
+
import { THREEMF_UNITS, cornerProperty, read3MF, } from './threemf.js';
|
|
6
7
|
const F = '3MF';
|
|
8
|
+
/** A display property number: `fallback` when absent, refused below 0 or above `max`. */
|
|
9
|
+
function amount(value, fallback, max, what) {
|
|
10
|
+
if (value === undefined)
|
|
11
|
+
return fallback;
|
|
12
|
+
const number = value.trim() ? Number(value) : Number.NaN;
|
|
13
|
+
if (!(Number.isFinite(number) && number >= 0 && number <= max))
|
|
14
|
+
throw new LoaderError(F, 'range', `invalid ${what} "${value.slice(0, 32)}"`);
|
|
15
|
+
return number;
|
|
16
|
+
}
|
|
17
|
+
/** An sRGB colour attribute, `fallback` when absent. */
|
|
18
|
+
function colorOf(value, fallback) {
|
|
19
|
+
if (value === undefined)
|
|
20
|
+
return fallback;
|
|
21
|
+
const color = hexColor(value.trim());
|
|
22
|
+
if (!color)
|
|
23
|
+
throw new LoaderError(F, 'syntax', `invalid color "${value.slice(0, 16)}"`);
|
|
24
|
+
return color;
|
|
25
|
+
}
|
|
26
|
+
/** Three numbers of 0 or more, above 0 with `positive`. */
|
|
27
|
+
function triplet(value, what, positive) {
|
|
28
|
+
const out = list(value, what);
|
|
29
|
+
if (out.length !== 3)
|
|
30
|
+
throw new LoaderError(F, 'syntax', `${what} needs three numbers, not "${value.slice(0, 64)}"`);
|
|
31
|
+
if (out.some((v) => v < 0 || (positive && v === 0)))
|
|
32
|
+
throw new LoaderError(F, 'range', `invalid ${what} "${value.slice(0, 64)}"`);
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
7
35
|
function list(value, what) {
|
|
8
36
|
const parts = (value ?? '').trim().split(/\s+/).map(Number);
|
|
9
37
|
if (!value?.trim() || !parts.every(Number.isFinite))
|
|
@@ -17,7 +45,9 @@ function required(value, element, attribute) {
|
|
|
17
45
|
}
|
|
18
46
|
/**
|
|
19
47
|
* Reads a 3MF package like `parse3MF` and adds the materials extension: `texture2d` images, `texture2dgroup`
|
|
20
|
-
* coordinates, `compositematerials` as mixed colours,
|
|
48
|
+
* coordinates, `compositematerials` as mixed colours, `multiproperties` layers, and the display properties as each
|
|
49
|
+
* group's `metallic` (`pbmetallic` and `pbmetallictexturedisplayproperties`), `specular` (`pbspecular` and
|
|
50
|
+
* `pbspeculartexturedisplayproperties`) or `translucent`. Every triangle corner gets its own
|
|
21
51
|
* vertex, so `uvs` and `colors` can differ across a seam; `uvs` use Margo's convention, v = 1 - the file's v. `colors` is
|
|
22
52
|
* present when corners of a triangle differ or a layer sets them. A group's `texture` indexes `textures`. In
|
|
23
53
|
* `multiproperties` colour layers mix by their alpha, and the first texture layer sets the group's texture: draw
|
|
@@ -26,7 +56,10 @@ function required(value, element, attribute) {
|
|
|
26
56
|
* @param input The package's bytes.
|
|
27
57
|
* @param options The same options as `parse3MF`.
|
|
28
58
|
* @returns The merged mesh with its coordinates, colours and images.
|
|
29
|
-
* @throws LoaderError with the codes of `parse3MF`, with `range` for a property index outside its group
|
|
59
|
+
* @throws LoaderError with the codes of `parse3MF`, with `range` for a property index outside its group or its display
|
|
60
|
+
* properties, for a metalness, roughness or glossiness outside 0 to 1 (a texture's factor: below 0), a negative
|
|
61
|
+
* attenuation or a refractive index of 0 or less, and `syntax` for display properties that are not defined or are of a
|
|
62
|
+
* kind their group cannot take, and for a colour or a number triplet that is not one.
|
|
30
63
|
*
|
|
31
64
|
* @example
|
|
32
65
|
* ```ts
|
|
@@ -46,13 +79,61 @@ export async function read3MFMaterials(input, options, extra) {
|
|
|
46
79
|
const stores = new Map(), textures = [], uvs = floats(), colors = floats(), opacity = floats(),
|
|
47
80
|
/** Each layer attribute's values by vertex, written at each corner. */
|
|
48
81
|
layerData = new Map();
|
|
49
|
-
let group, multi, composite,
|
|
82
|
+
let group, multi, composite,
|
|
83
|
+
/** The open container of display properties, and the open `basematerials` with the `<base>` elements seen in it. */
|
|
84
|
+
entries, materialGroup, textured = false, varied = false, translucent = false;
|
|
50
85
|
const store = (model) => {
|
|
51
86
|
let found = stores.get(model);
|
|
52
|
-
if (!found)
|
|
53
|
-
|
|
87
|
+
if (!found) {
|
|
88
|
+
found = {
|
|
89
|
+
textures: new Map(),
|
|
90
|
+
groups: new Map(),
|
|
91
|
+
multis: new Map(),
|
|
92
|
+
materials: new Set(),
|
|
93
|
+
displays: new Map(),
|
|
94
|
+
shown: new Map(),
|
|
95
|
+
bases: new Map(),
|
|
96
|
+
};
|
|
97
|
+
stores.set(model, found);
|
|
98
|
+
}
|
|
54
99
|
return found;
|
|
55
100
|
};
|
|
101
|
+
/** The display properties of entry `index` of a property group. Read after parsing, so a later resource counts. */
|
|
102
|
+
const finish = (model, id, index) => {
|
|
103
|
+
const { displays, shown, bases, groups, multis, textures: known } = store(model), layers = multis.get(id);
|
|
104
|
+
if (layers) {
|
|
105
|
+
for (let layer = 0; layer < layers.pids.length; layer++) {
|
|
106
|
+
const found = finish(model, layers.pids[layer], layers.rows[index]?.[layer] ?? 0);
|
|
107
|
+
if (found)
|
|
108
|
+
return [found[0], { ...found[1], layer }];
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
const reference = shown.get(id) ?? bases.get(id)?.get(index);
|
|
113
|
+
if (reference === undefined)
|
|
114
|
+
return undefined;
|
|
115
|
+
const display = displays.get(reference), refuse = (code, what) => {
|
|
116
|
+
throw new LoaderError(F, code, what);
|
|
117
|
+
}, short = reference.slice(0, 32);
|
|
118
|
+
if (!display)
|
|
119
|
+
return refuse('syntax', `display properties ${short} are not defined`);
|
|
120
|
+
if ('maps' in display !== groups.has(id))
|
|
121
|
+
return refuse('syntax', `property group ${id.slice(0, 32)} cannot take the kind of display properties ${short}`);
|
|
122
|
+
if (!('maps' in display))
|
|
123
|
+
return [
|
|
124
|
+
display.kind,
|
|
125
|
+
display.entries[index] ?? refuse('range', `property index ${index} is outside display properties ${short}`),
|
|
126
|
+
];
|
|
127
|
+
const [first, second] = display.maps.map((texture) => known.get(texture) ?? refuse('syntax', `texture ${texture.slice(0, 32)} is not defined`)), named = display.kind === 'metallic'
|
|
128
|
+
? { metalnessTexture: first, roughnessTexture: second }
|
|
129
|
+
: { specularTexture: first, glossinessTexture: second };
|
|
130
|
+
return [display.kind, { ...display.entry, ...named }];
|
|
131
|
+
};
|
|
132
|
+
/** A triangle's display properties: its first corner's. */
|
|
133
|
+
const finishAt = (...[model, object, mesh, t]) => {
|
|
134
|
+
const property = cornerProperty(model, object, mesh, t, 0);
|
|
135
|
+
return property && finish(model, property.id, property.index);
|
|
136
|
+
};
|
|
56
137
|
/** What one corner samples: a texture and uv, a colour, or both through layers. */
|
|
57
138
|
const sample = (model, id, index, layered) => {
|
|
58
139
|
const { groups, multis, textures: known } = store(model), coords = groups.get(id);
|
|
@@ -102,8 +183,24 @@ export async function read3MFMaterials(input, options, extra) {
|
|
|
102
183
|
};
|
|
103
184
|
const extension = {
|
|
104
185
|
element(model, name, a) {
|
|
105
|
-
if (name === 'basematerials'
|
|
106
|
-
|
|
186
|
+
if (name === 'basematerials' || name === 'colorgroup') {
|
|
187
|
+
if (a.id && a.displaypropertiesid)
|
|
188
|
+
store(model).shown.set(a.id, a.displaypropertiesid);
|
|
189
|
+
if (name === 'basematerials' && a.id) {
|
|
190
|
+
store(model).materials.add(a.id);
|
|
191
|
+
materialGroup = { id: a.id, count: 0 };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else if (name === 'base' && materialGroup) {
|
|
195
|
+
const index = materialGroup.count++;
|
|
196
|
+
if (a.displaypropertiesid) {
|
|
197
|
+
const { bases } = store(model);
|
|
198
|
+
let own = bases.get(materialGroup.id);
|
|
199
|
+
if (!own)
|
|
200
|
+
bases.set(materialGroup.id, (own = new Map()));
|
|
201
|
+
own.set(index, a.displaypropertiesid);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
107
204
|
},
|
|
108
205
|
open(model, name, a) {
|
|
109
206
|
switch (name) {
|
|
@@ -124,9 +221,82 @@ export async function read3MFMaterials(input, options, extra) {
|
|
|
124
221
|
const id = required(a.id, name, 'id');
|
|
125
222
|
group = { texture: required(a.texid, name, 'texid'), coords: [] };
|
|
126
223
|
store(model).groups.set(id, group);
|
|
224
|
+
if (a.displaypropertiesid)
|
|
225
|
+
store(model).shown.set(id, a.displaypropertiesid);
|
|
127
226
|
model.propertyIds.push(id);
|
|
128
227
|
break;
|
|
129
228
|
}
|
|
229
|
+
case 'pbmetallicdisplayproperties':
|
|
230
|
+
case 'pbspeculardisplayproperties':
|
|
231
|
+
case 'translucentdisplayproperties': {
|
|
232
|
+
const kind = name === 'translucentdisplayproperties'
|
|
233
|
+
? 'translucent'
|
|
234
|
+
: name === 'pbspeculardisplayproperties'
|
|
235
|
+
? 'specular'
|
|
236
|
+
: 'metallic';
|
|
237
|
+
entries = [];
|
|
238
|
+
store(model).displays.set(required(a.id, name, 'id'), { kind, entries });
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case 'pbmetallic':
|
|
242
|
+
entries?.push({
|
|
243
|
+
name: a.name ?? '',
|
|
244
|
+
metalness: amount(a.metallicness, 0, 1, 'metallicness'),
|
|
245
|
+
roughness: amount(a.roughness, 1, 1, 'roughness'),
|
|
246
|
+
});
|
|
247
|
+
break;
|
|
248
|
+
case 'pbspecular': {
|
|
249
|
+
const [r, g, b] = colorOf(a.specularcolor, [56 / 255, 56 / 255, 56 / 255, 1]);
|
|
250
|
+
entries?.push({
|
|
251
|
+
name: a.name ?? '',
|
|
252
|
+
specularColor: [r, g, b],
|
|
253
|
+
glossiness: amount(a.glossiness, 0, 1, 'glossiness'),
|
|
254
|
+
});
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
case 'translucent':
|
|
258
|
+
entries?.push({
|
|
259
|
+
name: a.name ?? '',
|
|
260
|
+
attenuation: triplet(required(a.attenuation, name, 'attenuation'), 'attenuation', false),
|
|
261
|
+
refractiveIndex: triplet(a.refractiveindex ?? '1 1 1', 'refractiveindex', true),
|
|
262
|
+
roughness: amount(a.roughness, 0, 1, 'roughness'),
|
|
263
|
+
});
|
|
264
|
+
break;
|
|
265
|
+
case 'pbmetallictexturedisplayproperties': {
|
|
266
|
+
const factor = colorOf(a.basecolorfactor, [1, 1, 1, 1]);
|
|
267
|
+
store(model).displays.set(required(a.id, name, 'id'), {
|
|
268
|
+
kind: 'metallic',
|
|
269
|
+
maps: [
|
|
270
|
+
required(a.metallictextureid, name, 'metallictextureid'),
|
|
271
|
+
required(a.roughnesstextureid, name, 'roughnesstextureid'),
|
|
272
|
+
],
|
|
273
|
+
entry: {
|
|
274
|
+
name: a.name ?? '',
|
|
275
|
+
// A factor above 1 brightens the sampled value, which stays at most 1.
|
|
276
|
+
metalness: amount(a.metallicfactor, 1, Number.MAX_VALUE, 'metallicfactor'),
|
|
277
|
+
roughness: amount(a.roughnessfactor, 1, Number.MAX_VALUE, 'roughnessfactor'),
|
|
278
|
+
...(factor.some((value) => value !== 1) ? { baseColorFactor: factor } : {}),
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case 'pbspeculartexturedisplayproperties': {
|
|
284
|
+
const [r, g, b] = colorOf(a.specularfactor, [1, 1, 1, 1]), diffuse = colorOf(a.diffusefactor, [1, 1, 1, 1]);
|
|
285
|
+
store(model).displays.set(required(a.id, name, 'id'), {
|
|
286
|
+
kind: 'specular',
|
|
287
|
+
maps: [
|
|
288
|
+
required(a.speculartextureid, name, 'speculartextureid'),
|
|
289
|
+
required(a.glossinesstextureid, name, 'glossinesstextureid'),
|
|
290
|
+
],
|
|
291
|
+
entry: {
|
|
292
|
+
name: a.name ?? '',
|
|
293
|
+
specularColor: [r, g, b],
|
|
294
|
+
glossiness: amount(a.glossinessfactor, 1, Number.MAX_VALUE, 'glossinessfactor'),
|
|
295
|
+
...(diffuse.some((value) => value !== 1) ? { diffuseFactor: diffuse } : {}),
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
130
300
|
case 'tex2coord': {
|
|
131
301
|
const u = Number(a.u), v = Number(a.v);
|
|
132
302
|
if (!Number.isFinite(u) || !Number.isFinite(v))
|
|
@@ -166,6 +336,8 @@ export async function read3MFMaterials(input, options, extra) {
|
|
|
166
336
|
throw new LoaderError(F, 'syntax', `material group ${a.matid.slice(0, 32)} is not defined`);
|
|
167
337
|
composite = { base, indices: list(a.matindices, 'matindices'), colors: [] };
|
|
168
338
|
store(model).materials.add(id);
|
|
339
|
+
if (a.displaypropertiesid)
|
|
340
|
+
store(model).shown.set(id, a.displaypropertiesid);
|
|
169
341
|
model.properties.set(id, composite.colors);
|
|
170
342
|
model.propertyIds.push(id);
|
|
171
343
|
break;
|
|
@@ -203,6 +375,10 @@ export async function read3MFMaterials(input, options, extra) {
|
|
|
203
375
|
multi = undefined;
|
|
204
376
|
else if (name === 'compositematerials')
|
|
205
377
|
composite = undefined;
|
|
378
|
+
else if (name.endsWith('displayproperties'))
|
|
379
|
+
entries = undefined;
|
|
380
|
+
else if (name === 'basematerials')
|
|
381
|
+
materialGroup = undefined;
|
|
206
382
|
},
|
|
207
383
|
async ready(read) {
|
|
208
384
|
for (const texture of textures)
|
|
@@ -210,7 +386,10 @@ export async function read3MFMaterials(input, options, extra) {
|
|
|
210
386
|
},
|
|
211
387
|
bucket(model, object, mesh, t) {
|
|
212
388
|
const property = cornerProperty(model, object, mesh, t, 0), layered = property && store(model).multis.has(property.id) ? `|m${property.id}` : '';
|
|
213
|
-
|
|
389
|
+
const found = finishAt(model, object, mesh, t),
|
|
390
|
+
// The name does not change how a triangle looks, so it does not split a group.
|
|
391
|
+
shown = found ? `|${found[0]}${JSON.stringify({ ...found[1], name: undefined })}` : '';
|
|
392
|
+
return String(at(model, model, object, mesh, t, 0).texture ?? '') + layered + shown;
|
|
214
393
|
},
|
|
215
394
|
corner(model, object, mesh, t, k) {
|
|
216
395
|
const property = cornerProperty(model, object, mesh, t, k), layers = property && store(model).multis.get(property.id);
|
|
@@ -247,6 +426,9 @@ export async function read3MFMaterials(input, options, extra) {
|
|
|
247
426
|
const { texture } = at(model, model, object, mesh, t, 0);
|
|
248
427
|
if (texture !== undefined)
|
|
249
428
|
target.texture = texture;
|
|
429
|
+
const found = finishAt(model, object, mesh, t);
|
|
430
|
+
if (found)
|
|
431
|
+
Object.assign(target, { [found[0]]: found[1] });
|
|
250
432
|
const property = cornerProperty(model, object, mesh, t, 0), { multis, groups, textures: known } = store(model), layers = property && multis.get(property.id);
|
|
251
433
|
if (layers)
|
|
252
434
|
target.layers = layers.pids.map((pid, k) => {
|
|
@@ -295,6 +477,7 @@ export async function read3MFMaterials(input, options, extra) {
|
|
|
295
477
|
: extension;
|
|
296
478
|
const result = (await read3MF(input, options, hooks));
|
|
297
479
|
result.textures = textures;
|
|
480
|
+
result.metresPerUnit = options.units === 'file' ? THREEMF_UNITS[result.unit] : 1;
|
|
298
481
|
if (textured)
|
|
299
482
|
result.uvs = uvs.result();
|
|
300
483
|
if (varied)
|
package/dist/threemf-mesh.d.ts
CHANGED
|
@@ -5,13 +5,19 @@ import type { ThreeMFMaterials } from './threemf-materials.js';
|
|
|
5
5
|
/** Options of {@link create3MFMesh}. */
|
|
6
6
|
export interface ThreeMFMeshOptions {
|
|
7
7
|
/**
|
|
8
|
-
* `'smooth'` (default) shares one
|
|
9
|
-
* `
|
|
8
|
+
* `'smooth'` (default) shares one angle-weighted normal where corners meet at the same position and their faces are
|
|
9
|
+
* within `creaseAngle` of each other, so edges sharper than that stay sharp; `'flat'` gives every triangle its face
|
|
10
|
+
* normal.
|
|
10
11
|
*/
|
|
11
12
|
normals?: 'smooth' | 'flat';
|
|
12
|
-
/**
|
|
13
|
+
/** The largest angle between faces that `'smooth'` normals blend across, in degrees, 0 to 180. Default 40. */
|
|
14
|
+
creaseAngle?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Every material's roughness, 0 to 1, in place of the file's value and map. Default: that of the group's `metallic` or
|
|
17
|
+
* `translucent`, 1 - the glossiness of its `specular`, else 0.6.
|
|
18
|
+
*/
|
|
13
19
|
roughness?: number;
|
|
14
|
-
/** Every material's metalness, 0 to 1. Default 0. */
|
|
20
|
+
/** Every material's metalness, 0 to 1, in place of the file's value and map. Default: the group's `metallic`, else 0. */
|
|
15
21
|
metalness?: number;
|
|
16
22
|
/** Draw both faces. Default true: printed parts are often open or inside out. */
|
|
17
23
|
doubleSided?: boolean;
|
|
@@ -25,7 +31,10 @@ export interface ThreeMFMeshOptions {
|
|
|
25
31
|
/** What {@link create3MFMesh} made. The textures and materials are its own: `dispose()` releases them with the mesh. */
|
|
26
32
|
export interface ThreeMFMesh {
|
|
27
33
|
mesh: MaterialMesh<Material[]>;
|
|
28
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* One per group, in `groups` order, empty groups left out. Groups that look alike (a scan has one per vertex colour)
|
|
36
|
+
* share one `Material`, so changing it changes them all.
|
|
37
|
+
*/
|
|
29
38
|
materials: Material[];
|
|
30
39
|
/** The decoded textures, by their index in `textures`. */
|
|
31
40
|
textures: Map<number, Texture>;
|
|
@@ -36,7 +45,13 @@ export interface ThreeMFMesh {
|
|
|
36
45
|
* Draws a `parse3MFMaterials` result as one materials mesh with a material per group: colour groups, composites and
|
|
37
46
|
* per-corner colours as vertex colours, a texture group's image as the colour map, and a `multiproperties` stack as its
|
|
38
47
|
* layers (`layered()`), blended as the 3MF Materials and Properties Extension 1.2.1 specifies (mix and multiply, in
|
|
39
|
-
* linear light).
|
|
48
|
+
* linear light). A group's `metallic` sets its material's metalness and roughness, with their maps. Its `specular` is
|
|
49
|
+
* drawn as an index of refraction of 0 with that specular colour (`KHR_materials_ior`), and roughness 1 - glossiness.
|
|
50
|
+
* Its `translucent` is drawn as transmission through a volume: the thickness is the object's mean chord, 4 V / S, and the
|
|
51
|
+
* attenuation is converted with `metresPerUnit`; draw it with `@margoengine/materials/transmission` to refract the scene
|
|
52
|
+
* behind it, without which the background shows through tinted. `unlit` draws neither. Colour images decode with
|
|
53
|
+
* `createImageBitmap`; roughness, metalness and glossiness maps need the optional `@margoengine/decoders` peer, which
|
|
54
|
+
* reads their texels exactly.
|
|
40
55
|
*
|
|
41
56
|
* @param engine The engine to draw in.
|
|
42
57
|
* @param loaded What `parse3MFMaterials` returned.
|