ldr 0.34.10 → 0.34.12
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/README.md +2 -1
- package/dist/cli.js +28 -11
- package/dist/index.d.ts +2 -1
- package/dist/index.js +414 -177
- package/dist/load-worker.gen.d.ts +1 -1
- package/dist/node/index.js +439 -185
- package/dist/parts-cdn.d.ts +2 -2
- package/dist/render.d.ts +12 -1
- package/dist/scene.d.ts +24 -5
- package/dist/stud-decal.d.ts +16 -0
- package/package.json +1 -1
package/dist/parts-cdn.d.ts
CHANGED
|
@@ -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
|
|
5
|
-
export declare const DEFAULT_PARTS_CDN = "https://ldr-
|
|
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'. */
|
|
@@ -36,6 +43,10 @@ export interface LdrObjectOptions {
|
|
|
36
43
|
scale?: number;
|
|
37
44
|
/** Initial step (inclusive, 0-based global sequence from `sequenceSteps`). Default: show all. */
|
|
38
45
|
step?: number;
|
|
46
|
+
/** Build the per-step tables up front, so the first `setStep` is as cheap as later ones. Default false (`loadModel`: true with
|
|
47
|
+
* `callouts`): a multi-step model loads as one plain all-steps scene (no step tables, culled slots dropped, ~15-20% faster on big
|
|
48
|
+
* models) and the first `setStep` that hides something builds step mode once (about one more build of the model). Implied by `step`. */
|
|
49
|
+
eagerSteps?: boolean;
|
|
39
50
|
/** Distance LOD, re-selected for each camera you render with. Default true. Batches are split into spatial clusters (so off-screen
|
|
40
51
|
* ones are frustum-culled); each cluster draws the coarsest simplified mesh (from `lod` packs, the `buildPack` default) whose error
|
|
41
52
|
* stays under `lodPx`, swaps closed studs to a 10-triangle square stud, then a flat disc, then drops them once under `lodPx`, and hides edge lines where a stud spans under
|
|
@@ -97,10 +108,18 @@ export interface LdrObject {
|
|
|
97
108
|
/** Per build step, the view rotation set by MLCad `0 ROTSTEP` (null = default view). Get the 3x3 (LDraw space, row-major) with
|
|
98
109
|
* `stepViewMatrix(view, yourDefaultView)`; in three.js terms rotate the model by it inside the object's -Y-up flip. */
|
|
99
110
|
stepViews: (StepView | null)[];
|
|
100
|
-
/** Show instances up to and including `step` (null = all).
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
|
|
111
|
+
/** Show instances up to and including `step` (null = all). Instance buffers are compacted, and culling is step-aware (a stud
|
|
112
|
+
* covered only by a later step's part stays visible). An object built showing every step (no `step` option) has no step tables
|
|
113
|
+
* yet (it builds faster, like a single-step model): the first call that hides something builds them, about one `createLdrObject`
|
|
114
|
+
* of work; later calls don't rebuild. `stats` reflect the shown step. With `mask` (per instance), only the
|
|
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;
|
|
104
123
|
setEdges(on: boolean): void;
|
|
105
124
|
/** Resolves when the pack's textures (if any) are decoded and ready to render. */
|
|
106
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.
|
|
3
|
+
"version": "0.34.12",
|
|
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",
|