@margoengine/loaders 0.0.0-stage → 0.1.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 +1198 -3
- 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/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-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 +161 -0
- package/dist/dae.js +633 -0
- package/dist/detect.d.ts +20 -0
- package/dist/detect.js +72 -0
- package/dist/dxf.d.ts +81 -0
- package/dist/dxf.js +774 -0
- package/dist/engine.d.ts +36 -0
- package/dist/engine.js +117 -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 +55 -0
- package/dist/gcode.js +278 -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 +120 -0
- package/dist/mtl.js +469 -0
- package/dist/normals.d.ts +7 -0
- package/dist/normals.js +31 -0
- package/dist/nrrd.d.ts +63 -0
- package/dist/nrrd.js +743 -0
- package/dist/nurbs.d.ts +118 -0
- package/dist/nurbs.js +265 -0
- package/dist/obj.d.ts +143 -0
- package/dist/obj.js +456 -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 +27 -0
- package/dist/render.js +153 -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 +42 -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-lattice.d.ts +139 -0
- package/dist/threemf-lattice.js +514 -0
- package/dist/threemf-materials.d.ts +75 -0
- package/dist/threemf-materials.js +314 -0
- package/dist/threemf-mesh.d.ts +60 -0
- package/dist/threemf-mesh.js +201 -0
- package/dist/threemf.d.ts +101 -0
- package/dist/threemf.js +415 -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 +90 -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 +246 -6
package/dist/tds.d.ts
ADDED
package/dist/tds.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AssetResolver } from './types.js';
|
|
2
|
+
/** Options of {@link loadTextures}. */
|
|
3
|
+
export interface LoadTexturesOptions {
|
|
4
|
+
/** Stops the reads; the promise then rejects with a `LoaderError` code `aborted`. */
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
}
|
|
7
|
+
/** What {@link loadTextures} returns. */
|
|
8
|
+
export interface LoadedTextures {
|
|
9
|
+
/** Each file's bytes, by the path as the model wrote it. */
|
|
10
|
+
textures: Map<string, Uint8Array>;
|
|
11
|
+
/** The paths no spelling of which could be read, with the resolver's last error. */
|
|
12
|
+
missing: {
|
|
13
|
+
path: string;
|
|
14
|
+
error: unknown;
|
|
15
|
+
}[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reads the texture files a model names (`materials[i].texture` of `parse3DS`, `images` of `parseLWO`, `skins` of
|
|
19
|
+
* `parseMD2`) through `resolve`, asking for each path as written, then with forward slashes, in lower case, and by its
|
|
20
|
+
* base name. A file that cannot be read is listed in `missing`, so one lost skin does not lose the model.
|
|
21
|
+
*
|
|
22
|
+
* Decode the bytes with what fits: `createImageBitmap` for PNG, JPEG and BMP, `parseTGA` from
|
|
23
|
+
* `@margoengine/decoders/tga`, and `parsePCX` from `@margoengine/decoders/pcx` for Quake skins.
|
|
24
|
+
*
|
|
25
|
+
* @param paths The paths, each read once.
|
|
26
|
+
* @param resolve Reads one path; `resolveFromURL` from `@margoengine/loaders/ldraw` makes one for a hosted folder.
|
|
27
|
+
* @param options An AbortSignal.
|
|
28
|
+
* @returns The bytes by path, and what is missing.
|
|
29
|
+
* @throws LoaderError with code `aborted`.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { resolveFromURL } from '@margoengine/loaders/ldraw';
|
|
34
|
+
* import { parseMD2 } from '@margoengine/loaders/md2';
|
|
35
|
+
* import { loadTextures } from '@margoengine/loaders/textures';
|
|
36
|
+
*
|
|
37
|
+
* const model = parseMD2(await (await fetch('/models/tank.md2')).arrayBuffer());
|
|
38
|
+
* const { textures, missing } = await loadTextures(model.skins, resolveFromURL('/models/'));
|
|
39
|
+
* console.log(textures.size, missing);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function loadTextures(paths: Iterable<string>, resolve: AssetResolver, { signal }?: LoadTexturesOptions): Promise<LoadedTextures>;
|
package/dist/textures.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { throwIfAborted } from './util.js';
|
|
2
|
+
/** Old tools wrote upper-case 8.3 names, folders of their own PC and `Images:wall.jpg` volumes: the spellings to ask for, in order. */
|
|
3
|
+
function spellings(path) {
|
|
4
|
+
const clean = path.replaceAll('\\', '/'), base = clean.slice(Math.max(clean.lastIndexOf('/'), clean.lastIndexOf(':')) + 1);
|
|
5
|
+
return [...new Set([path, clean, clean.toLowerCase(), base, base.toLowerCase()])];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Reads the texture files a model names (`materials[i].texture` of `parse3DS`, `images` of `parseLWO`, `skins` of
|
|
9
|
+
* `parseMD2`) through `resolve`, asking for each path as written, then with forward slashes, in lower case, and by its
|
|
10
|
+
* base name. A file that cannot be read is listed in `missing`, so one lost skin does not lose the model.
|
|
11
|
+
*
|
|
12
|
+
* Decode the bytes with what fits: `createImageBitmap` for PNG, JPEG and BMP, `parseTGA` from
|
|
13
|
+
* `@margoengine/decoders/tga`, and `parsePCX` from `@margoengine/decoders/pcx` for Quake skins.
|
|
14
|
+
*
|
|
15
|
+
* @param paths The paths, each read once.
|
|
16
|
+
* @param resolve Reads one path; `resolveFromURL` from `@margoengine/loaders/ldraw` makes one for a hosted folder.
|
|
17
|
+
* @param options An AbortSignal.
|
|
18
|
+
* @returns The bytes by path, and what is missing.
|
|
19
|
+
* @throws LoaderError with code `aborted`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { resolveFromURL } from '@margoengine/loaders/ldraw';
|
|
24
|
+
* import { parseMD2 } from '@margoengine/loaders/md2';
|
|
25
|
+
* import { loadTextures } from '@margoengine/loaders/textures';
|
|
26
|
+
*
|
|
27
|
+
* const model = parseMD2(await (await fetch('/models/tank.md2')).arrayBuffer());
|
|
28
|
+
* const { textures, missing } = await loadTextures(model.skins, resolveFromURL('/models/'));
|
|
29
|
+
* console.log(textures.size, missing);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export async function loadTextures(paths, resolve, { signal } = {}) {
|
|
33
|
+
const textures = new Map(), missing = [];
|
|
34
|
+
for (const path of new Set(paths)) {
|
|
35
|
+
let error;
|
|
36
|
+
for (const name of spellings(path)) {
|
|
37
|
+
throwIfAborted(signal, 'textures');
|
|
38
|
+
try {
|
|
39
|
+
const read = await resolve(name);
|
|
40
|
+
textures.set(path, typeof read === 'string' ? new TextEncoder().encode(read) : read);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
catch (failure) {
|
|
44
|
+
// The next spelling may be the one the folder holds; the last failure is reported in `missing`.
|
|
45
|
+
error = failure;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
throwIfAborted(signal, 'textures');
|
|
49
|
+
if (!textures.has(path))
|
|
50
|
+
missing.push({ path, error });
|
|
51
|
+
}
|
|
52
|
+
return { textures, missing };
|
|
53
|
+
}
|
|
@@ -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>;
|