ldr 0.0.0-alpha.1 → 0.2.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 +21 -0
- package/README.md +119 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +876 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +717 -0
- package/dist/model.d.ts +44 -0
- package/dist/node/build-pack.d.ts +29 -0
- package/dist/node/compile.d.ts +43 -0
- package/dist/node/index.d.ts +7 -0
- package/dist/node/index.js +1456 -0
- package/dist/node/library.d.ts +35 -0
- package/dist/node/resolver.d.ts +32 -0
- package/dist/pack-io.d.ts +2 -0
- package/dist/render.d.ts +43 -0
- package/dist/scene.d.ts +56 -0
- package/dist/spec.d.ts +73 -0
- package/package.json +56 -36
- package/lib/.DS_Store +0 -0
- package/lib/index.js +0 -1
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { parse, norm, type Doc, type M } from "./spec.js";
|
|
2
|
+
/** A placed part. `color` is an LDraw colour code (or direct colour 0x2RRGGBB); `m` is the 12-number LDraw matrix `x y z a b c d e f g h i`. */
|
|
3
|
+
export interface PartInstance {
|
|
4
|
+
part: string;
|
|
5
|
+
color: number;
|
|
6
|
+
m: M;
|
|
7
|
+
/** Build step of the top-level model this instance appears in (0-based). */
|
|
8
|
+
step: number;
|
|
9
|
+
/** Step path through nested submodels, e.g. [3, 1] = top step 3, submodel step 1. */
|
|
10
|
+
steps: number[];
|
|
11
|
+
/** Submodel path, e.g. "main.ldr/wheel.ldr". */
|
|
12
|
+
path: string;
|
|
13
|
+
}
|
|
14
|
+
export interface FlattenOptions {
|
|
15
|
+
/** Resolve an external reference that is not a submodel of this document (e.g. a model file you loaded separately). Return null to treat it as a part. */
|
|
16
|
+
resolveModel?: (name: string) => Doc | null;
|
|
17
|
+
/** Max submodel nesting (cycle guard). Default 64. */
|
|
18
|
+
maxDepth?: number;
|
|
19
|
+
}
|
|
20
|
+
/** Flatten a parsed LDraw document into part instances. Submodels (`0 FILE` blocks in an MPD) are expanded; everything else is treated as a part. */
|
|
21
|
+
export declare function flatten(doc: Doc, opts?: FlattenOptions): PartInstance[];
|
|
22
|
+
/** Parse LDraw text (.ldr/.mpd/.dat) and flatten it in one call. */
|
|
23
|
+
export declare function parseModel(text: string, name?: string, opts?: FlattenOptions): PartInstance[];
|
|
24
|
+
/**
|
|
25
|
+
* Assign each instance a global sequential build-step index, ordering by the full nested step path
|
|
26
|
+
* (so submodel steps become their own steps). Returns the number of steps.
|
|
27
|
+
*/
|
|
28
|
+
export declare function sequenceSteps<T extends {
|
|
29
|
+
steps: number[];
|
|
30
|
+
}>(insts: T[]): {
|
|
31
|
+
count: number;
|
|
32
|
+
stepOf: Int32Array;
|
|
33
|
+
};
|
|
34
|
+
/** Colour table entry. */
|
|
35
|
+
export interface LDrawColor {
|
|
36
|
+
code: number;
|
|
37
|
+
name: string;
|
|
38
|
+
hex: string;
|
|
39
|
+
edge: string;
|
|
40
|
+
alpha: number;
|
|
41
|
+
}
|
|
42
|
+
/** Parse LDConfig.ldr (or any file with `!COLOUR` lines) into a code → colour map. */
|
|
43
|
+
export declare function parseLDConfig(text: string): Map<number, LDrawColor>;
|
|
44
|
+
export { parse, norm };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface BuildPackOptions {
|
|
2
|
+
/** Root of an LDraw library (folder containing LDConfig.ldr, parts/, p/). Get it from https://library.ldraw.org (complete.zip). */
|
|
3
|
+
ldrawRoot: string;
|
|
4
|
+
/** Model files (.ldr/.mpd) or raw model text whose parts should be included. */
|
|
5
|
+
models?: (string | {
|
|
6
|
+
name: string;
|
|
7
|
+
text: string;
|
|
8
|
+
})[];
|
|
9
|
+
/** Extra part references to include, e.g. ["3001.dat"]. */
|
|
10
|
+
parts?: string[];
|
|
11
|
+
/** Include every part in parts/ (large: the full library is ~20k parts). */
|
|
12
|
+
allParts?: boolean;
|
|
13
|
+
/** Stud geometry: 'low' uses p/8 low-res primitives (default, ~visually lossless at distance); 'full' keeps full detail. */
|
|
14
|
+
studs?: "low" | "full";
|
|
15
|
+
/** Non-stud primitive detail. Default 'full'. */
|
|
16
|
+
primitives?: "low" | "full";
|
|
17
|
+
/** Weld + index vertices (smaller GPU buffers, faster). Default true. */
|
|
18
|
+
weld?: boolean;
|
|
19
|
+
/** Embed the LDConfig colour table (code → hex) in the pack header. Default true. */
|
|
20
|
+
colors?: boolean;
|
|
21
|
+
onProgress?: (done: number, total: number) => void;
|
|
22
|
+
}
|
|
23
|
+
export interface BuildPackResult {
|
|
24
|
+
data: Uint8Array;
|
|
25
|
+
parts: number;
|
|
26
|
+
studKinds: number;
|
|
27
|
+
missing: string[];
|
|
28
|
+
}
|
|
29
|
+
export declare function buildPack(o: BuildPackOptions): BuildPackResult;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Library } from './resolver.js';
|
|
2
|
+
export type Opts = {
|
|
3
|
+
studs: 'full' | 'low';
|
|
4
|
+
prims: 'full' | 'low';
|
|
5
|
+
weld: boolean;
|
|
6
|
+
separateStuds: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type Bucket = {
|
|
9
|
+
pos: number[];
|
|
10
|
+
col: number[];
|
|
11
|
+
};
|
|
12
|
+
export type Compiled = {
|
|
13
|
+
body: Bucket;
|
|
14
|
+
under: Bucket;
|
|
15
|
+
edges: number[];
|
|
16
|
+
condLines: number;
|
|
17
|
+
studs: {
|
|
18
|
+
kind: string;
|
|
19
|
+
color: string;
|
|
20
|
+
m: number[];
|
|
21
|
+
}[];
|
|
22
|
+
bbox: number[];
|
|
23
|
+
fullBottom: boolean;
|
|
24
|
+
uncertified?: boolean;
|
|
25
|
+
bottomMask?: {
|
|
26
|
+
nx: number;
|
|
27
|
+
nz: number;
|
|
28
|
+
bits: number[];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export declare function loadColors(root: string): Map<string, number[]>;
|
|
32
|
+
export declare class Compiler {
|
|
33
|
+
lib: Library;
|
|
34
|
+
opts: Opts;
|
|
35
|
+
colors: Map<string, number[]>;
|
|
36
|
+
cache: Map<string, Compiled>;
|
|
37
|
+
constructor(lib: Library, opts: Opts);
|
|
38
|
+
resolve(ref: string, isStud: boolean): string | null;
|
|
39
|
+
compile(key: string, separateStuds?: boolean): Compiled;
|
|
40
|
+
}
|
|
41
|
+
export declare function writePack(file: string, parts: Map<string, Compiled>, studKinds: Map<string, Compiled>, weld: boolean, extra?: Record<string, unknown>): void;
|
|
42
|
+
/** Serialize compiled parts into the binary pack format read by `decodePack`/`loadPack`. `extra` keys are merged into the JSON header (e.g. `colors`). */
|
|
43
|
+
export declare function encodePack(parts: Map<string, Compiled>, studKinds: Map<string, Compiled>, weld: boolean, extra?: Record<string, unknown>): Uint8Array;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "../index.js";
|
|
2
|
+
export { Library } from "./library.js";
|
|
3
|
+
export { buildPack } from "./build-pack.js";
|
|
4
|
+
export type { BuildPackOptions, BuildPackResult } from "./build-pack.js";
|
|
5
|
+
export { Compiler, encodePack, writePack, loadColors } from "./compile.js";
|
|
6
|
+
export type { Compiled, Opts as CompileOptions, Bucket } from "./compile.js";
|
|
7
|
+
export { Library as ResolverLibrary, splitModel, flatten as flattenWithLibrary, collectDeps } from "./resolver.js";
|