ldr 0.0.0-alpha.1 → 0.3.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 +121 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1472 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1239 -0
- package/dist/model.d.ts +44 -0
- package/dist/node/build-pack.d.ts +35 -0
- package/dist/node/compile.d.ts +70 -0
- package/dist/node/index.d.ts +7 -0
- package/dist/node/index.js +2354 -0
- package/dist/node/library.d.ts +42 -0
- package/dist/node/resolver.d.ts +33 -0
- package/dist/pack-io.d.ts +2 -0
- package/dist/render.d.ts +69 -0
- package/dist/scene.d.ts +74 -0
- package/dist/spec.d.ts +149 -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,35 @@
|
|
|
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
|
+
/** Keep type-5 conditional lines so the renderer can draw curved-surface silhouettes (pack v2). Off by default:
|
|
20
|
+
* Round 16 measured +7.5–13.6% zstd size and ~+25% build time on Datsville 10k/100k. Packs stay readable by ldr <= 0.2.0. */
|
|
21
|
+
cond?: boolean;
|
|
22
|
+
/** Keep textured (`!TEXMAP`) parts' TEXMAP-aware geometry + UVs and embed their PNGs (pack v2 "tex"). Off by default;
|
|
23
|
+
* packs without textured parts are byte-identical either way. Textures resolve from model `!DATA` blocks, then `textures/` in the library. */
|
|
24
|
+
textures?: boolean;
|
|
25
|
+
/** Embed the LDConfig colour table (code → hex) in the pack header. Default true. */
|
|
26
|
+
colors?: boolean;
|
|
27
|
+
onProgress?: (done: number, total: number) => void;
|
|
28
|
+
}
|
|
29
|
+
export interface BuildPackResult {
|
|
30
|
+
data: Uint8Array;
|
|
31
|
+
parts: number;
|
|
32
|
+
studKinds: number;
|
|
33
|
+
missing: string[];
|
|
34
|
+
}
|
|
35
|
+
export declare function buildPack(o: BuildPackOptions): BuildPackResult;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Library } from './resolver.js';
|
|
2
|
+
/** `cond`: keep type-5 conditional lines (endpoints + control points) so the pack can draw them (pack v2). Default off.
|
|
3
|
+
* `tex`: also compile the TEXMAP-aware view of parts that use `!TEXMAP` (textured triangles with UVs + PNGs; pack v2 "tex"). Default off. */
|
|
4
|
+
export type Opts = {
|
|
5
|
+
studs: 'full' | 'low';
|
|
6
|
+
prims: 'full' | 'low';
|
|
7
|
+
weld: boolean;
|
|
8
|
+
separateStuds: boolean;
|
|
9
|
+
cond?: boolean;
|
|
10
|
+
tex?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type Bucket = {
|
|
13
|
+
pos: number[];
|
|
14
|
+
col: number[];
|
|
15
|
+
};
|
|
16
|
+
/** Textured triangles for one PNG: `uv` = 2 floats per vertex (LDraw !TEXMAP projection, v = 0 at the image's top row). */
|
|
17
|
+
export type TexBucket = Bucket & {
|
|
18
|
+
uv: number[];
|
|
19
|
+
wrapU?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type Compiled = {
|
|
22
|
+
body: Bucket;
|
|
23
|
+
under: Bucket;
|
|
24
|
+
edges: number[];
|
|
25
|
+
condLines: number;
|
|
26
|
+
/** Type-5 lines in part space, stride 12 (p0, p1, control0, control1). Only filled when `opts.cond`.
|
|
27
|
+
* `cond` = lines of the body; `condUnder` = lines inside underside (tube / anti-stud) subfiles, drawn with the underside batch so they follow underside culling. */
|
|
28
|
+
cond?: number[];
|
|
29
|
+
condUnder?: number[];
|
|
30
|
+
studs: {
|
|
31
|
+
kind: string;
|
|
32
|
+
color: string;
|
|
33
|
+
m: number[];
|
|
34
|
+
}[];
|
|
35
|
+
bbox: number[];
|
|
36
|
+
fullBottom: boolean;
|
|
37
|
+
uncertified?: boolean;
|
|
38
|
+
bottomMask?: {
|
|
39
|
+
nx: number;
|
|
40
|
+
nz: number;
|
|
41
|
+
bits: number[];
|
|
42
|
+
};
|
|
43
|
+
/** Only with `opts.tex`, for parts whose tree uses !TEXMAP: the untextured body a TEXMAP-aware renderer draws instead of
|
|
44
|
+
* `body` (FALLBACK geometry dropped, `0 !:` geometry kept), plus textured triangles per texture name. Under/studs/edges are shared. */
|
|
45
|
+
tbody?: Bucket;
|
|
46
|
+
texb?: Map<string, TexBucket>;
|
|
47
|
+
};
|
|
48
|
+
export declare function loadColors(root: string): Map<string, number[]>;
|
|
49
|
+
export declare class Compiler {
|
|
50
|
+
lib: Library;
|
|
51
|
+
opts: Opts;
|
|
52
|
+
colors: Map<string, number[]>;
|
|
53
|
+
cache: Map<string, Compiled>;
|
|
54
|
+
constructor(lib: Library, opts: Opts);
|
|
55
|
+
resolve(ref: string, isStud: boolean): string | null;
|
|
56
|
+
compile(key: string, separateStuds?: boolean): Compiled;
|
|
57
|
+
private texMemo;
|
|
58
|
+
/** True if `key` or any file it references contains a `!TEXMAP` meta. */
|
|
59
|
+
hasTex(key: string): boolean;
|
|
60
|
+
/** Texture PNG bytes by !TEXMAP name: `textures/<name>` under parts/, p/, models/, then `<name>` (case-insensitive). */
|
|
61
|
+
texture(name: string): Uint8Array | null;
|
|
62
|
+
private texPass;
|
|
63
|
+
}
|
|
64
|
+
export declare function writePack(file: string, parts: Map<string, Compiled>, studKinds: Map<string, Compiled>, weld: boolean, extra?: Record<string, unknown>, options?: EncodeOptions): void;
|
|
65
|
+
/** `texture(name)`: PNG bytes for a !TEXMAP name used by a compiled part (e.g. `compiler.texture`, or an MPD `!DATA` block). */
|
|
66
|
+
export type EncodeOptions = {
|
|
67
|
+
texture?: (name: string) => Uint8Array | null;
|
|
68
|
+
};
|
|
69
|
+
/** Serialize compiled parts into the binary pack format read by `decodePack`/`loadPack`. `extra` keys are merged into the JSON header (e.g. `colors`). */
|
|
70
|
+
export declare function encodePack(parts: Map<string, Compiled>, studKinds: Map<string, Compiled>, weld: boolean, extra?: Record<string, unknown>, options?: EncodeOptions): 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";
|