ldr 0.34.11 → 0.34.13

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,8 +1,8 @@
1
1
  import { type Pack } from "./pack-io.js";
2
2
  import { type PartInstance } from "./model.js";
3
3
  import { type CullResult } from "./cull.js";
4
- /** Default parts CDN (LDraw library parts, CC BY 2.0 / 4.0, compiled by ldr; hosted with the demo site). */
5
- export declare const DEFAULT_PARTS_CDN = "https://ldr-demo.vercel.app/cdn/v1/";
4
+ /** Default parts CDN (LDraw library parts, CC BY 2.0 / 4.0, compiled by ldr; hosted on the ldr-parts-cdn Worker in front of R2; not the demo's /cdn/v1/* proxy, whose edge cache answers Range requests with the wrong bytes). */
5
+ export declare const DEFAULT_PARTS_CDN = "https://ldr-parts-cdn.baconbrix.workers.dev/v1/";
6
6
  export interface PartsCdnIndex {
7
7
  format: string;
8
8
  release?: string;
package/dist/render.d.ts CHANGED
@@ -2,6 +2,13 @@ import * as THREE from 'three';
2
2
  import { decodePack, type Pack } from './pack-io.js';
3
3
  import { type ColourSurface, type LDrawColor } from './model.js';
4
4
  export { decodePack, type Pack };
5
+ import { type StudDecalUniforms } from './stud-decal';
6
+ /** which studs stay real geometry (setStudMask): per instance, or those whose stud cell centre is within `r` of (x, z) in model space */
7
+ export type StudMask = ArrayLike<number | boolean> | {
8
+ x: number;
9
+ z: number;
10
+ r: number;
11
+ };
5
12
  /** `edges`: LDraw edge lines, welded + indexed and sharing each batch's instance matrices (`'idx'` is the same as `true`).
6
13
  * `cond`: draw type-5 conditional lines when the pack carries them (pack v2, built with `cond: true`) and edges are on. Default true.
7
14
  * `condStuds`: also draw them on stud batches (stud silhouettes). Default true. Uncertified (no BFC) parts are always double-sided. */
@@ -10,13 +17,16 @@ export type LdrParams = {
10
17
  /** Colours of instance colour keys that aren't table codes: model-level `0 !COLOUR` definitions (see `sceneInstances`). */
11
18
  localColours?: Map<string, LDrawColor>;
12
19
  cullStuds: boolean;
13
- cullUnder: boolean;
20
+ cullUnder: boolean; /** see LdrObjectOptions.studGrid */
21
+ studGrid?: number;
14
22
  edges?: boolean | 'idx';
15
23
  side: 'double' | 'front';
16
24
  cond?: boolean;
17
25
  condStuds?: boolean;
18
26
  /** Draw textured (!TEXMAP) parts with their PNGs when the pack carries them (pack v2 "tex", `ldr pack --textures`). Default true. */
19
27
  tex?: boolean;
28
+ /** Step mode: also draw every stud as a flat decal quad (stud-decal.ts), shown where `setStudMask` takes the real studs away. */
29
+ studDecal?: StudDecalUniforms;
20
30
  /** Distance LOD: spatial clusters per part, simplified meshes from `lod` packs, studs as full → square stud → flat disc → dropped, edges hidden once sub-pixel. Default true. */
21
31
  lod?: boolean;
22
32
  /** LOD: max screen-space error in pixels (default 0.5). */
@@ -121,6 +131,7 @@ export declare function studSquareLines(E: ArrayLike<number>, w: number, hole?:
121
131
  /** Box-level outline (Round 67): the 12 edges of a body's bounding-box LOD level (`lod.ts` boxMesh: an axis-aligned box in part
122
132
  * space), drawn with that level in place of the part's own edge lines. Null unless `pos` is exactly such a box's corners. */
123
133
  export declare function boxLevelLines(pos: ArrayLike<number>): Float32Array | null;
134
+ export declare function studGridGeom(g: THREE.BufferGeometry, n: number): THREE.BufferGeometry;
124
135
  /**
125
136
  * Builds (and caches on the pack) the shared BufferGeometries `buildLdrScene` will use, in time slices of about `sliceMs` that yield
126
137
  * to the event loop, until done or `stop()` returns true. Lets the main thread do this useful work while the load worker culls.
package/dist/scene.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as THREE from "three";
2
- import { type Pack } from "./render.js";
2
+ import { type Pack, type StudMask } from "./render.js";
3
3
  import { type CullResult } from "./cull.js";
4
4
  import { type PartInstance, type LDrawColor } from "./model.js";
5
5
  import type { StepView } from "./spec.js";
6
+ import type { StudDecalUniforms } from "./stud-decal.js";
6
7
  export type ColorSource = Map<number, string | LDrawColor> | Record<number | string, string | LDrawColor> | ((code: number) => THREE.ColorRepresentation | undefined);
7
8
  export interface LdrObjectOptions {
8
9
  /** Culling computed ahead (e.g. by `prepareModel({ cull: true })` in a worker) for these same instances and `textures` setting. */
@@ -20,6 +21,12 @@ export interface LdrObjectOptions {
20
21
  textures?: boolean;
21
22
  /** Hide studs fully covered by a part above. Default true. */
22
23
  cullStuds?: boolean;
24
+ /** Draw each stud as an n x n grid of studs 1/n its size on the same 20-LDU cell (the city's bricks are a stud per metre, its
25
+ * minifigs a third of LDraw size: `studGrid: 3` gives the ground and buildings minifig-scale studs). Same instances and culling;
26
+ * stud LOD thresholds shrink by n. No stud edge lines with n > 1. Default 1. Only read when the object is built. */
27
+ studGrid?: number;
28
+ /** Step mode: flat stud decals (stud-decal.ts) where `setStudMask` takes the real studs away; these uniforms move their near hole. */
29
+ studDecal?: StudDecalUniforms;
23
30
  /** Hide undersides (tubes) sitting fully on studs below. Default true. */
24
31
  cullUndersides?: boolean;
25
32
  /** 'front' = single-sided BFC faces (fast); 'double' = render both sides. Uncertified parts are always double-sided. Default 'front'. */
@@ -105,8 +112,14 @@ export interface LdrObject {
105
112
  * covered only by a later step's part stays visible). An object built showing every step (no `step` option) has no step tables
106
113
  * yet (it builds faster, like a single-step model): the first call that hides something builds them, about one `createLdrObject`
107
114
  * of work; later calls don't rebuild. `stats` reflect the shown step. With `mask` (per instance), only the
108
- * instances whose entry is truthy are shown, e.g. a sub-assembly on its own (an instruction callout; see `planStepViews`). */
109
- setStep(step: number | null, mask?: ArrayLike<number | boolean> | null): void;
115
+ * instances whose entry is truthy are shown, e.g. a sub-assembly on its own (an instruction callout; see `planStepViews`).
116
+ * `ghostAfter`: the ghost (`setGhost`) shows the steps after this one instead of after `step` (default `step`). A step animated in
117
+ * shows the step before while its new parts are drawn in flight elsewhere: `setStep(s - 1, mask, s)` keeps those parts out of the
118
+ * ghost too, so no part is ever drawn as a ghost and a solid in the same place (they z-fight, a flickery doubled brick). */
119
+ setStep(step: number | null, mask?: ArrayLike<number | boolean> | null, ghostAfter?: number | null): void;
120
+ /** Step mode only (false otherwise): real studs only on the instances whose `mask` entry is truthy, `studDecal` decals on the
121
+ * rest, or (`{ x, z, r }`, model space) only the stud cells within `r` of a point; null: every stud real, no decals. Cheap (only the stud batches are rewritten). */
122
+ setStudMask(mask: StudMask | null): boolean;
110
123
  setEdges(on: boolean): void;
111
124
  /** Resolves when the pack's textures (if any) are decoded and ready to render. */
112
125
  texturesReady: Promise<void>;
@@ -0,0 +1,16 @@
1
+ import * as THREE from 'three';
2
+ /** shared uniforms: the app moves `center` (world space) and sets `near` (world units) once */
3
+ export type StudDecalUniforms = {
4
+ center: {
5
+ value: THREE.Vector3;
6
+ };
7
+ near: {
8
+ value: number;
9
+ };
10
+ };
11
+ export declare function studDecalUniforms(near?: number): StudDecalUniforms;
12
+ /** the 20 x 20 LDU footprint of a stud at the height of its studs' tops (stud space: y = 0 is the part's top, -y up), facing up: the
13
+ * shader marches down from there, and a quad that high wins the depth test over the plate under it at any distance */
14
+ export declare function studDecalGeom(grid?: number): THREE.BufferGeometry<THREE.NormalBufferAttributes, THREE.BufferGeometryEventMap>;
15
+ /** `base` (a stud batch's plastic) with the decal shading on top of whatever it already patches; one per base material and grid */
16
+ export declare function studDecalMaterial(base: THREE.Material, U: StudDecalUniforms, grid: number): THREE.Material;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldr",
3
- "version": "0.34.11",
3
+ "version": "0.34.13",
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",