ldr 0.2.0 → 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.
@@ -16,6 +16,12 @@ export interface BuildPackOptions {
16
16
  primitives?: "low" | "full";
17
17
  /** Weld + index vertices (smaller GPU buffers, faster). Default true. */
18
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;
19
25
  /** Embed the LDConfig colour table (code → hex) in the pack header. Default true. */
20
26
  colors?: boolean;
21
27
  onProgress?: (done: number, total: number) => void;
@@ -1,19 +1,32 @@
1
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. */
2
4
  export type Opts = {
3
5
  studs: 'full' | 'low';
4
6
  prims: 'full' | 'low';
5
7
  weld: boolean;
6
8
  separateStuds: boolean;
9
+ cond?: boolean;
10
+ tex?: boolean;
7
11
  };
8
12
  export type Bucket = {
9
13
  pos: number[];
10
14
  col: number[];
11
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
+ };
12
21
  export type Compiled = {
13
22
  body: Bucket;
14
23
  under: Bucket;
15
24
  edges: number[];
16
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[];
17
30
  studs: {
18
31
  kind: string;
19
32
  color: string;
@@ -27,6 +40,10 @@ export type Compiled = {
27
40
  nz: number;
28
41
  bits: number[];
29
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>;
30
47
  };
31
48
  export declare function loadColors(root: string): Map<string, number[]>;
32
49
  export declare class Compiler {
@@ -37,7 +54,17 @@ export declare class Compiler {
37
54
  constructor(lib: Library, opts: Opts);
38
55
  resolve(ref: string, isStud: boolean): string | null;
39
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;
40
63
  }
41
- export declare function writePack(file: string, parts: Map<string, Compiled>, studKinds: Map<string, Compiled>, weld: boolean, extra?: Record<string, unknown>): void;
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
+ };
42
69
  /** 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;
70
+ export declare function encodePack(parts: Map<string, Compiled>, studKinds: Map<string, Compiled>, weld: boolean, extra?: Record<string, unknown>, options?: EncodeOptions): Uint8Array;