ldr 0.27.3 → 0.29.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.
@@ -1,13 +1,16 @@
1
1
  import type { Compiler, Compiled } from "./compile.js";
2
- /** [absolute error cap (LDU), target triangle fraction]; each is tried with free and with locked borders. 2 LDU = a quarter of a plate's height. */
3
- export declare const LOW_DETAIL_STEPS: readonly (readonly [err: number, ratio: number])[];
4
- /** Raster size of the see-through gate (per view). */
2
+ /** [absolute error cap (LDU), target triangle fraction]; each is tried with free and locked borders, as-is and seam-closed, and with
3
+ * and without vertex updates. 2 LDU = a quarter of a plate's height. The fine steps matter: the shape gate is a threshold, and the
4
+ * coarsest cap under it is what saves triangles (Round 57: with 6 caps instead of these 14, 42115 stays over the phone budget). */
5
+ export declare const LOW_DETAIL_CAPS: readonly (readonly [err: number, ratio: number])[];
6
+ /** Most shape error (shape-error.ts: fraction of pixels covered or shaded differently from full detail, 42 views) a phone-tier part may
7
+ * have. 0.3 is about where the Round 51 tier's 2 LDU Technic beams already sat (22-30%): coarse up close (holes go polygonal), still
8
+ * clearly the part. At 0.35-0.4 pins and axle pins turn into lumps (bench/results/r57-shots). */
9
+ export declare const LOW_DETAIL_MAX_ERR = 0.3;
10
+ /** Raster size of the see-through and shape gates (per view). */
5
11
  export declare const LOW_DETAIL_RES = 128;
6
12
  /** Seam closing tolerance (LDU) for `closeSeams`: well under a pixel at any phone zoom (1 LDU = 0.4 mm). */
7
13
  export declare const SEAM_EPS = 0.01;
8
- /** Steps for the seam-closed candidates: caps up to 0.5 LDU only, more finely spaced. Coarser, with the borders closed the simplifier
9
- * collapses across thin walls (pin slits, beam ends) and folds them: still closed, so the see-through gate passes it, but visibly crumpled. */
10
- export declare const SEAM_STEPS: readonly (readonly [err: number, ratio: number])[];
11
14
  type Group = {
12
15
  c: number[];
13
16
  idx: Uint32Array;
@@ -15,8 +18,10 @@ type Group = {
15
18
  };
16
19
  /** A stride-9 triangle soup with rgba-per-vertex colours, welded per colour (one indexed mesh each), optionally with `closeSeams` applied. */
17
20
  export declare function weldBody(pos: ArrayLike<number>, col: ArrayLike<number>, seams?: boolean): Group[];
18
- /** Simplify welded colour groups (`weldBody`) at absolute error cap `err` (LDU) and target triangle fraction `ratio`; back to a stride-9 soup. */
19
- export declare function simplifyGroups(groups: Group[], err: number, ratio: number, lockBorder?: boolean): {
21
+ /** Simplify welded colour groups (`weldBody`) at absolute error cap `err` (LDU) and target triangle fraction `ratio`; back to a stride-9 soup.
22
+ * `update` (Round 57): `simplifyWithUpdate`, which also moves the kept vertices to fit the original surface (on a copy).
23
+ * `regularize` (Round 57): meshoptimizer's `Regularize`, which favours even-sized triangles over slivers. */
24
+ export declare function simplifyGroups(groups: Group[], err: number, ratio: number, lockBorder?: boolean, update?: boolean, regularize?: boolean): {
20
25
  pos: number[];
21
26
  col: number[];
22
27
  };
@@ -25,8 +30,8 @@ export declare function simplifyBody(pos: ArrayLike<number>, col: ArrayLike<numb
25
30
  pos: number[];
26
31
  col: number[];
27
32
  };
28
- /** Candidate name: `s<cap>`, `L` = locked borders, `S` = seams closed first (`closeSeams`, Round 54). */
29
- export type LowDetailLevel = `s${number}` | `s${number}L` | `s${number}S` | `s${number}LS`;
33
+ /** Candidate name: `s<cap>`, `L` = locked borders, `S` = seams closed first (`closeSeams`, Round 54), `U` = vertices updated, `R` = regularized (Round 57). */
34
+ export type LowDetailLevel = `s${number}${"" | "L"}${"" | "S"}${"" | "U"}${"" | "R"}`;
30
35
  export interface LowDetailResult {
31
36
  compiled: Compiled;
32
37
  level: "full" | LowDetailLevel;
@@ -34,10 +39,17 @@ export interface LowDetailResult {
34
39
  tris: number;
35
40
  fullSee: number;
36
41
  see: number;
42
+ shapeErr: number;
37
43
  }
38
- /** The phone-tier version of compiled part `c`. `comp` compiles (or looks up) its stud kinds, placed for the gate. Textured bodies stay full. */
44
+ /** The phone-tier version of compiled part `c`. `comp` compiles (or looks up) its stud kinds, placed for the gates. Textured bodies stay
45
+ * full. For comparisons, `{ seams: false, update: false, regularize: false, maxErr: Infinity, caps: [[2, 0.05], [1, 0.1], [0.5, 0.2], [0.25, 0.3], [0.1, 0.5],
46
+ * [0.05, 0.6]] }` is the Round 51 tier exactly. */
39
47
  export declare function lowDetail(comp: Compiler | ((kind: string) => Compiled), c: Compiled, o?: {
40
48
  seams?: boolean;
49
+ update?: boolean;
50
+ regularize?: boolean;
51
+ maxErr?: number;
52
+ caps?: readonly (readonly [number, number])[];
41
53
  }): LowDetailResult;
42
54
  /** Round 54: close the cracks LDraw leaves between sub-files before simplifying (one colour's welded mesh, indexed). LDraw parts join
43
55
  * primitives to hand-placed geometry with coordinates a few thousandths of an LDU apart (pins: 3.061 vs 3.062) and with T-junctions
@@ -4,6 +4,8 @@ export declare function partTris(c: Compiler, key: string): number[];
4
4
  /** `partTris` of an already compiled part, optionally with `body` (stride-9 positions) drawn instead of its own body. `c` compiles the
5
5
  * stud kinds (or is a lookup of already compiled ones). */
6
6
  export declare function placedTris(c: Compiler | ((kind: string) => Compiled), out: Compiled, body?: ArrayLike<number>): number[];
7
+ /** The 42 view directions of the see-through gate (and shape-error.ts). */
8
+ export declare const DIRS: number[][];
7
9
  /** { see, cover }: pixels covered by triangles of one orientation only (see-through when back faces are culled), and covered pixels,
8
10
  * summed over 42 orthographic views at `res`² each, the part's bounding sphere filling the view. With `limit`, stops after the first
9
11
  * view that takes `see` past it (`see` is then only known to exceed `limit`; `cover` is partial). */
@@ -0,0 +1,14 @@
1
+ /** Shade difference (0..1, |cos| of the face normal to the view direction) that counts a pixel as wrong: ~8.6 degrees of facet tilt at normal incidence. */
2
+ export declare const SHADE_TOL = 0.15;
3
+ export interface ShapeRef {
4
+ c: number[];
5
+ r: number;
6
+ res: number;
7
+ views: Float32Array[];
8
+ cover: number[];
9
+ }
10
+ /** Flat-shaded views of a part (stride-9 triangles), the reference the candidates are compared to. */
11
+ export declare function shapeRef(tris: ArrayLike<number>, res?: number): ShapeRef;
12
+ /** Fraction of pixels (over all views) where `tris` looks different from `ref`. With `limit`, stops as soon as the error is known to exceed
13
+ * it (the result is then only a lower bound above `limit`). */
14
+ export declare function shapeError(ref: ShapeRef, tris: ArrayLike<number>, limit?: number): number;
package/dist/spec.d.ts CHANGED
@@ -209,9 +209,10 @@ export declare const colorToken: (c: number) => string;
209
209
  /** Name of the synthetic part holding a model file's own geometry in local step `step`: `<file>#<step>`. */
210
210
  export declare const loosePartName: (file: string, step: number) => string;
211
211
  /**
212
- * The synthetic part for a model file's own type 2-5 lines in local step `step`, as a file: every `0 BFC` line of the file
213
- * (winding / certification state, in order), the step's `!TEXMAP` and `0 !:` lines, and the step's type 2-5 lines. Type-1 lines
214
- * are dropped (they are instances), together with a `!TEXMAP NEXT` that applied to one. Commands are shared with `f`.
212
+ * The synthetic part for a model file's own type 2-5 lines in local step `step`, as a file: every `0 BFC` and `0 !COLOUR` line of
213
+ * the file (winding / certification state and the file's own colour definitions, in order), the step's `!TEXMAP` and `0 !:` lines,
214
+ * and the step's type 2-5 lines. Type-1 lines are dropped (they are instances), together with a `!TEXMAP NEXT` that applied to one.
215
+ * Commands are shared with `f`.
215
216
  */
216
217
  export declare function looseFile(f: LFile, step: number): LFile;
217
218
  /** LDraw source text of `looseFile(f, step)`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldr",
3
- "version": "0.27.3",
3
+ "version": "0.29.0",
4
4
  "description": "High-performance LEGO (LDraw) rendering for three.js: instanced parts packs, hidden stud/tube culling, low-detail studs, indexed edges, build steps.",
5
5
  "license": "MIT",
6
6
  "author": "Evan Bacon",