@chanmeng666/archlang-3d 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.
- package/CHANGELOG.md +23 -0
- package/dist/browser.d.ts +90 -5
- package/dist/browser.js +257 -23
- package/dist/camera-CLNYQ1Xv.d.ts +211 -0
- package/dist/{chunk-VUSBWX7N.js → chunk-PRZXP6FP.js} +6 -2
- package/dist/{chunk-4AF5Q7M3.js → chunk-QUSG4UCO.js} +2 -2
- package/dist/{chunk-EYEEIS4R.js → chunk-VPYTRKMK.js} +41 -1
- package/dist/chunk-WBA4LABI.js +137 -0
- package/dist/{chunk-KUK6ARJC.js → chunk-ZE4PL6KP.js} +12 -4
- package/dist/cli.js +5 -5
- package/dist/{facts-DHuCDilh.d.ts → facts-B47HOKOh.d.ts} +1 -1
- package/dist/index.d.ts +5 -122
- package/dist/index.js +21 -3
- package/dist/node.d.ts +3 -3
- package/dist/node.js +4 -4
- package/dist/replay.d.ts +1 -1
- package/dist/{strip-CdTeMoHA.d.ts → strip-CN_dTKqy.d.ts} +93 -93
- package/dist/viewer.iife.js +177 -177
- package/package.json +1 -1
- package/dist/chunk-2ZINQMUB.js +0 -66
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { w as ReplayEvent, x as ReplayState } from './strip-CN_dTKqy.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The replay's end camera as plain maths (card A3, look notes round 1): the viewer and the tests
|
|
5
|
+
* read the same functions, so "the end frame fills the canvas" is a property a test can check
|
|
6
|
+
* without a browser. Millimetres, the exporters' axes (X plan x, Y up, Z plan y). No three.js here:
|
|
7
|
+
* the conventions copy three.js's `lookAt` for a camera (it looks down its local −Z; right =
|
|
8
|
+
* up × back, true up = back × right, world up +Y).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
type Vec3 = [number, number, number];
|
|
12
|
+
interface Box {
|
|
13
|
+
lo: Vec3;
|
|
14
|
+
hi: Vec3;
|
|
15
|
+
}
|
|
16
|
+
/** Where the end camera looks from: elevation and azimuth in degrees, vertical field of view. */
|
|
17
|
+
interface Orbit {
|
|
18
|
+
elevation: number;
|
|
19
|
+
azimuth: number;
|
|
20
|
+
fov: number;
|
|
21
|
+
/** Canvas width / height. */
|
|
22
|
+
aspect: number;
|
|
23
|
+
}
|
|
24
|
+
interface EndCamera {
|
|
25
|
+
target: Vec3;
|
|
26
|
+
/** Distance from the target to the camera (mm). */
|
|
27
|
+
dist: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The fraction of each half-axis the building may use: a margin of 6 % of the frame on each side
|
|
31
|
+
* of the binding axis.
|
|
32
|
+
*/
|
|
33
|
+
declare const FILL = 0.88;
|
|
34
|
+
declare function corners(b: Box): Vec3[];
|
|
35
|
+
/**
|
|
36
|
+
* The projected extent of `box` in normalised device coordinates (−1…1 on each axis) for a camera
|
|
37
|
+
* at `cam` with orbit `o`.
|
|
38
|
+
*/
|
|
39
|
+
declare function projectBox(box: Box, cam: EndCamera, o: Orbit): {
|
|
40
|
+
x: [number, number];
|
|
41
|
+
y: [number, number];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The end camera that fills the frame with `box`: the 8 corners are projected through the end
|
|
45
|
+
* orbit and the distance is solved so the binding corner sits at `FILL` of the half-frame; the
|
|
46
|
+
* target is then re-centred on the projected box (perspective makes the near half larger) and the
|
|
47
|
+
* distance solved again. A fixed number of rounds, so the result is a pure function of its input.
|
|
48
|
+
*/
|
|
49
|
+
declare function fitEndCamera(box: Box, o: Orbit): EndCamera;
|
|
50
|
+
/** The share of the binding axis the projected box fills (1 = edge to edge). */
|
|
51
|
+
declare function coverage(box: Box, cam: EndCamera, o: Orbit): number;
|
|
52
|
+
/** The end camera's lens and bearing. */
|
|
53
|
+
declare const END_FOV = 30;
|
|
54
|
+
declare const END_AZIMUTH = -32;
|
|
55
|
+
/**
|
|
56
|
+
* The end camera's elevation: 45° for every view. The combined view of a taller building needs it so
|
|
57
|
+
* the exploded gaps show the floors below (see `timeline.ts`'s header); a one-storey view took it
|
|
58
|
+
* too (card A9, by delegation, the owner may veto on a look): at 30° the near walls hid the floor,
|
|
59
|
+
* the inner doors and most furniture of `studio`. The storey count stays a parameter so a later
|
|
60
|
+
* look can split the two again without a signature change.
|
|
61
|
+
*/
|
|
62
|
+
declare const endElevation: (_storeys: number) => number;
|
|
63
|
+
/**
|
|
64
|
+
* The scene's box (mm) from the payload's nodes: positions in micrometres, each node lifted by its
|
|
65
|
+
* `lift` (the combined view's exploded storeys). A demolished wall's ghost (`part` "demolish") is not
|
|
66
|
+
* the building and is left out of a fit (`timeline.ts`'s header), unless nothing else is there;
|
|
67
|
+
* `ghosts: true` keeps it, for a box that must hold everything drawn (the viewer's clip range).
|
|
68
|
+
*/
|
|
69
|
+
declare function boxOfNodes(nodes: ReadonlyArray<{
|
|
70
|
+
positions: readonly number[];
|
|
71
|
+
lift?: number;
|
|
72
|
+
part?: string;
|
|
73
|
+
}>, opts?: {
|
|
74
|
+
ghosts?: boolean;
|
|
75
|
+
}): Box;
|
|
76
|
+
/** The perspective camera's lens at the start of the dolly (a near-orthographic top-down view). */
|
|
77
|
+
declare const START_FOV = 1.5;
|
|
78
|
+
/**
|
|
79
|
+
* One fitted camera per stop: stop k fills the frame with storeys 0…k (the combined view; a node's
|
|
80
|
+
* storey is its event's), the last stop with the whole building. One storey: one stop. Each stop is
|
|
81
|
+
* fitted for the end orbit, which `stateAt` has reached by the time of the first stop.
|
|
82
|
+
*/
|
|
83
|
+
declare function cameraStops(nodes: ReadonlyArray<{
|
|
84
|
+
key: string;
|
|
85
|
+
positions: readonly number[];
|
|
86
|
+
lift?: number;
|
|
87
|
+
part?: string;
|
|
88
|
+
}>, events: readonly ReplayEvent[], o: Orbit): EndCamera[];
|
|
89
|
+
/** The fitted camera at a (fractional) stop: between two stops, a straight blend of the two. */
|
|
90
|
+
declare function cameraAtStop(fits: readonly EndCamera[], stop: number): EndCamera;
|
|
91
|
+
/** The perspective camera of one frame: where it aims, from how far, with which lens and bearing. */
|
|
92
|
+
interface FrameCamera {
|
|
93
|
+
target: Vec3;
|
|
94
|
+
dist: number;
|
|
95
|
+
fov: number;
|
|
96
|
+
elevation: number;
|
|
97
|
+
azimuth: number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The perspective camera at state `s` (the viewer's `seek`): from straight down over the drawing's
|
|
101
|
+
* centre (`cx`, `cz`; `oh` the drawing's height in the frame) it tilts to the end orbit and dollies
|
|
102
|
+
* to the fitted camera of the current stop.
|
|
103
|
+
*/
|
|
104
|
+
declare function frameCamera(s: Pick<ReplayState, "tilt" | "dolly" | "stop">, fits: readonly EndCamera[], view: {
|
|
105
|
+
cx: number;
|
|
106
|
+
cz: number;
|
|
107
|
+
oh: number;
|
|
108
|
+
elevation: number;
|
|
109
|
+
}): FrameCamera;
|
|
110
|
+
/**
|
|
111
|
+
* The first frame frames the core drawing's viewBox exactly, letterboxed as the image is: its
|
|
112
|
+
* centre (`cx`, `cz`) and the height (`oh`) and width (`ow`) it spans in the frame, in plan mm.
|
|
113
|
+
*/
|
|
114
|
+
declare function drawingFrame(viewBox: readonly [number, number, number, number], aspect: number): {
|
|
115
|
+
cx: number;
|
|
116
|
+
cz: number;
|
|
117
|
+
ow: number;
|
|
118
|
+
oh: number;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* The free camera (card CR4, decision CR-D2): the views a viewer offers beside the replay's own
|
|
122
|
+
* camera, as plain maths like the end camera's, so a test reads them without a browser. Each preset
|
|
123
|
+
* is a pure function of the scene (`ViewScene`); the viewer draws it through the same placement as
|
|
124
|
+
* the replay's frames (`cameraPosition`, then three.js's `lookAt`).
|
|
125
|
+
*/
|
|
126
|
+
type PresetName = "iso" | "top" | "north" | "east" | "south" | "west";
|
|
127
|
+
declare const PRESET_NAMES: readonly PresetName[];
|
|
128
|
+
/** What a preset reads: the replay's event table and fitted stops, the drawing's frame, the box. */
|
|
129
|
+
interface ViewScene {
|
|
130
|
+
events: readonly ReplayEvent[];
|
|
131
|
+
fits: readonly EndCamera[];
|
|
132
|
+
/** The first frame's framing (`drawingFrame`) and the end elevation, as `frameCamera` takes them. */
|
|
133
|
+
frame: {
|
|
134
|
+
cx: number;
|
|
135
|
+
cz: number;
|
|
136
|
+
oh: number;
|
|
137
|
+
elevation: number;
|
|
138
|
+
};
|
|
139
|
+
/** The standing building (`boxOfNodes`, ghosts left out): the box the last stop is fitted to. */
|
|
140
|
+
box: Box;
|
|
141
|
+
/** Canvas width / height. */
|
|
142
|
+
aspect: number;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The bearing each elevation looks from, relative to the plan's axes (not its `north`): north is the
|
|
146
|
+
* plan's top edge (plan −y, the exporters' −Z), east its right edge (+X). `backOf` puts the camera at
|
|
147
|
+
* (sin az, ·, cos az) from the target, so azimuth 0 stands south of the plan.
|
|
148
|
+
*/
|
|
149
|
+
declare const ELEVATION_AZIMUTH: {
|
|
150
|
+
readonly north: 180;
|
|
151
|
+
readonly east: 90;
|
|
152
|
+
readonly south: 0;
|
|
153
|
+
readonly west: -90;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* The free camera's elevation range, degrees: from the horizon through its target (an elevation
|
|
157
|
+
* view) to straight down (the top view). The orbit's pivot is never below the building's lowest
|
|
158
|
+
* point (`pivotAbove`) and never drops (panning keeps to its horizontal plane), so the camera never
|
|
159
|
+
* goes below the building.
|
|
160
|
+
*/
|
|
161
|
+
declare const ELEVATION_RANGE: {
|
|
162
|
+
readonly min: 0;
|
|
163
|
+
readonly max: 90;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* The point the orbit turns about when it takes a camera at `position` aimed at `target`: the target
|
|
167
|
+
* itself, or, where the target lies below `minY` (a fitted target is re-centred across the view and
|
|
168
|
+
* can sink under the slab: the end camera of a deep plan does), the point of the same line of sight
|
|
169
|
+
* at height `minY`. The view does not move (the aim is the same ray), only the pivot.
|
|
170
|
+
*/
|
|
171
|
+
declare function pivotAbove(position: Vec3, target: Vec3, minY: number): Vec3;
|
|
172
|
+
/**
|
|
173
|
+
* A preset camera. `iso` IS the replay's end camera (`frameCamera` at t = 1, the very numbers the
|
|
174
|
+
* end frame is drawn from), so returning to it draws the end frame byte for byte; the other presets
|
|
175
|
+
* are fitted to the standing building like the stops (`fitEndCamera`, the end lens): `top` from
|
|
176
|
+
* straight down with the plan's top edge up, each elevation level with the target.
|
|
177
|
+
*/
|
|
178
|
+
declare function presetCamera(name: PresetName, v: ViewScene): FrameCamera;
|
|
179
|
+
/**
|
|
180
|
+
* The camera the orbit takes from a replay frame: the frame's aim and bearing, and its framing at the
|
|
181
|
+
* target (the view height there), through the end lens. So a take in the top-down phase (a 1.5°,
|
|
182
|
+
* near-orthographic lens under the core's drawing) turns a top view at the end lens over the same
|
|
183
|
+
* area, and a take mid-dolly keeps what the frame showed. A frame already at the end lens (the end
|
|
184
|
+
* frame, every stop) is returned as it is.
|
|
185
|
+
*/
|
|
186
|
+
declare function takenLens(f: FrameCamera): FrameCamera;
|
|
187
|
+
/**
|
|
188
|
+
* How far the free camera may dolly, as multiples of the whole building's fitted distance (the
|
|
189
|
+
* last stop): in until an eighth of the building's span fills the frame (a corner, one room), out
|
|
190
|
+
* until it stands at a third of its fitted size.
|
|
191
|
+
*/
|
|
192
|
+
declare const ZOOM: {
|
|
193
|
+
readonly in: 8;
|
|
194
|
+
readonly out: 3;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* The free camera's distance limits for lens `fov`: the view heights at the target that the end
|
|
198
|
+
* lens has at `ZOOM`'s distances, so a camera taken mid-dolly (a narrower lens) zooms over the same
|
|
199
|
+
* framings.
|
|
200
|
+
*/
|
|
201
|
+
declare function distanceLimits(fits: readonly EndCamera[], fov: number): {
|
|
202
|
+
min: number;
|
|
203
|
+
max: number;
|
|
204
|
+
};
|
|
205
|
+
/** Where the free camera's target may pan: the sphere round everything drawn (the clip box). */
|
|
206
|
+
declare function targetBounds(box: Box): {
|
|
207
|
+
centre: Vec3;
|
|
208
|
+
radius: number;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export { type Box as B, ELEVATION_AZIMUTH as E, FILL as F, type Orbit as O, type PresetName as P, START_FOV as S, type Vec3 as V, ZOOM as Z, ELEVATION_RANGE as a, END_AZIMUTH as b, END_FOV as c, type EndCamera as d, type FrameCamera as e, PRESET_NAMES as f, type ViewScene as g, boxOfNodes as h, cameraAtStop as i, cameraStops as j, corners as k, coverage as l, distanceLimits as m, drawingFrame as n, endElevation as o, fitEndCamera as p, frameCamera as q, pivotAbove as r, presetCamera as s, projectBox as t, takenLens as u, targetBounds as v };
|
|
@@ -3571,7 +3571,7 @@ function floorLifts(floors, overlaps) {
|
|
|
3571
3571
|
}
|
|
3572
3572
|
|
|
3573
3573
|
// package.json
|
|
3574
|
-
var version = "0.
|
|
3574
|
+
var version = "0.3.0";
|
|
3575
3575
|
|
|
3576
3576
|
// src/scene3d/build.ts
|
|
3577
3577
|
import {
|
|
@@ -3843,7 +3843,11 @@ function levelOf(s, ledger, tol, mirrored) {
|
|
|
3843
3843
|
openings,
|
|
3844
3844
|
furniture: of("furniture").map((f) => furnitureOf(f, mirrored, ledger)),
|
|
3845
3845
|
stairs: of("stair").map(stairOf),
|
|
3846
|
-
|
|
3846
|
+
// A core `void … polygon` (an L) carries the rectangles its hole is made of (`parts`): each is
|
|
3847
|
+
// one box, ids `<id>#<k>` (unique per collection), `source` still naming the void.
|
|
3848
|
+
voids: of("void").flatMap(
|
|
3849
|
+
(v) => v.parts ? v.parts.map((p, k) => ({ ...box({ ...v, at: p.at, size: p.size }), id: `${v.id}#${k}` })) : [box(v)]
|
|
3850
|
+
),
|
|
3847
3851
|
columns: of("column").map(box),
|
|
3848
3852
|
outdoor: of("outdoor").map(outdoorOf),
|
|
3849
3853
|
fences: of("fence").map(fenceOf),
|
|
@@ -19,10 +19,10 @@ import {
|
|
|
19
19
|
t0Shells,
|
|
20
20
|
wallOwnership,
|
|
21
21
|
where
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-PRZXP6FP.js";
|
|
23
23
|
import {
|
|
24
24
|
floorFinish
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-VPYTRKMK.js";
|
|
26
26
|
|
|
27
27
|
// src/adapter/adapt.ts
|
|
28
28
|
import * as core from "@chanmeng666/archlang";
|
|
@@ -516,6 +516,37 @@ function drawingFrame(viewBox, aspect) {
|
|
|
516
516
|
const ow = Math.max(vw, vh * aspect);
|
|
517
517
|
return { cx: vx + vw / 2, cz: vy + vh / 2, ow, oh: ow / aspect };
|
|
518
518
|
}
|
|
519
|
+
var PRESET_NAMES = ["iso", "top", "north", "east", "south", "west"];
|
|
520
|
+
var ELEVATION_AZIMUTH = { north: 180, east: 90, south: 0, west: -90 };
|
|
521
|
+
var ELEVATION_RANGE = { min: 0, max: 90 };
|
|
522
|
+
function pivotAbove(position, target, minY) {
|
|
523
|
+
if (target[1] >= minY || position[1] <= minY) return target;
|
|
524
|
+
const s = (position[1] - minY) / (position[1] - target[1]);
|
|
525
|
+
return [position[0] + (target[0] - position[0]) * s, minY, position[2] + (target[2] - position[2]) * s];
|
|
526
|
+
}
|
|
527
|
+
function presetCamera(name, v) {
|
|
528
|
+
if (name === "iso") return frameCamera(stateAt(v.events, 1), v.fits, v.frame);
|
|
529
|
+
const bearing = name === "top" ? { elevation: ELEVATION_RANGE.max, azimuth: ELEVATION_AZIMUTH.south } : { elevation: ELEVATION_RANGE.min, azimuth: ELEVATION_AZIMUTH[name] };
|
|
530
|
+
const fit = fitEndCamera(v.box, { ...bearing, fov: END_FOV, aspect: v.aspect });
|
|
531
|
+
return { target: fit.target, dist: fit.dist, fov: END_FOV, ...bearing };
|
|
532
|
+
}
|
|
533
|
+
function takenLens(f) {
|
|
534
|
+
if (f.fov === END_FOV) return f;
|
|
535
|
+
return { ...f, fov: END_FOV, dist: f.dist * Math.tan(rad(f.fov) / 2) / Math.tan(rad(END_FOV) / 2) };
|
|
536
|
+
}
|
|
537
|
+
var ZOOM = { in: 8, out: 3 };
|
|
538
|
+
function distanceLimits(fits, fov) {
|
|
539
|
+
const whole = fits[fits.length - 1].dist;
|
|
540
|
+
const k = Math.tan(rad(END_FOV) / 2) / Math.tan(rad(fov) / 2);
|
|
541
|
+
return { min: whole * k / ZOOM.in, max: whole * k * ZOOM.out };
|
|
542
|
+
}
|
|
543
|
+
function targetBounds(box) {
|
|
544
|
+
const d = [box.hi[0] - box.lo[0], box.hi[1] - box.lo[1], box.hi[2] - box.lo[2]];
|
|
545
|
+
return {
|
|
546
|
+
centre: [(box.lo[0] + box.hi[0]) / 2, (box.lo[1] + box.hi[1]) / 2, (box.lo[2] + box.hi[2]) / 2],
|
|
547
|
+
radius: Math.hypot(d[0], d[1], d[2]) / 2
|
|
548
|
+
};
|
|
549
|
+
}
|
|
519
550
|
|
|
520
551
|
export {
|
|
521
552
|
MATERIAL_SLOTS,
|
|
@@ -558,5 +589,14 @@ export {
|
|
|
558
589
|
cameraStops,
|
|
559
590
|
cameraAtStop,
|
|
560
591
|
frameCamera,
|
|
561
|
-
drawingFrame
|
|
592
|
+
drawingFrame,
|
|
593
|
+
PRESET_NAMES,
|
|
594
|
+
ELEVATION_AZIMUTH,
|
|
595
|
+
ELEVATION_RANGE,
|
|
596
|
+
pivotAbove,
|
|
597
|
+
presetCamera,
|
|
598
|
+
takenLens,
|
|
599
|
+
ZOOM,
|
|
600
|
+
distanceLimits,
|
|
601
|
+
targetBounds
|
|
562
602
|
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FLOOR_FINISHES,
|
|
3
|
+
endElevation,
|
|
4
|
+
explodeLifts,
|
|
5
|
+
slotGroups,
|
|
6
|
+
storeysOf,
|
|
7
|
+
timeline
|
|
8
|
+
} from "./chunk-VPYTRKMK.js";
|
|
9
|
+
|
|
10
|
+
// src/replay/view-dom.ts
|
|
11
|
+
var PRESET_LABELS = [
|
|
12
|
+
["iso", "Iso", "Iso view: the replay's end view"],
|
|
13
|
+
["top", "Top", "Top view, the plan's top edge up"],
|
|
14
|
+
["north", "N", "North elevation: from the plan's top edge"],
|
|
15
|
+
["east", "E", "East elevation: from the plan's right edge"],
|
|
16
|
+
["south", "S", "South elevation: from the plan's bottom edge"],
|
|
17
|
+
["west", "W", "West elevation: from the plan's left edge"]
|
|
18
|
+
];
|
|
19
|
+
var VIEW_HINT = "Drag to turn, right-drag to pan, scroll to zoom; on the focused view, arrow keys turn and + / \u2212 zoom.";
|
|
20
|
+
var VIEW_CONTROLS_LABEL = "an interactive 3D view: drag or use the arrow keys to turn it, scroll or + and \u2212 to zoom";
|
|
21
|
+
function viewToolbar(view, opts = {}) {
|
|
22
|
+
const bar = document.createElement("div");
|
|
23
|
+
bar.className = "archlang-views";
|
|
24
|
+
bar.setAttribute("role", "toolbar");
|
|
25
|
+
bar.setAttribute("aria-label", "3D view");
|
|
26
|
+
const button = (text, label, onClick) => {
|
|
27
|
+
const b = document.createElement("button");
|
|
28
|
+
b.type = "button";
|
|
29
|
+
if (opts.buttonClass) b.className = opts.buttonClass;
|
|
30
|
+
b.textContent = text;
|
|
31
|
+
b.setAttribute("aria-label", label);
|
|
32
|
+
b.addEventListener("click", onClick);
|
|
33
|
+
return b;
|
|
34
|
+
};
|
|
35
|
+
const presetButtons = [];
|
|
36
|
+
const storeyButtons = [];
|
|
37
|
+
const press = () => {
|
|
38
|
+
for (const [name, b] of presetButtons) b.setAttribute("aria-pressed", String(view.camera === name));
|
|
39
|
+
for (const [i, b] of storeyButtons.entries()) b.setAttribute("aria-pressed", String(i + 1 === view.shown));
|
|
40
|
+
};
|
|
41
|
+
for (const [name, text, label] of PRESET_LABELS) {
|
|
42
|
+
const b = button(text, label, () => view.preset(name));
|
|
43
|
+
b.dataset.preset = name;
|
|
44
|
+
presetButtons.push([name, b]);
|
|
45
|
+
bar.append(b);
|
|
46
|
+
}
|
|
47
|
+
bar.append(button("Reset", "Reset the view: the replay's own camera, every storey shown", () => view.reset()));
|
|
48
|
+
if (view.storeys > 1) {
|
|
49
|
+
const group = document.createElement("span");
|
|
50
|
+
group.className = "archlang-views-storeys";
|
|
51
|
+
group.setAttribute("role", "group");
|
|
52
|
+
group.setAttribute("aria-label", "Storeys shown");
|
|
53
|
+
group.append("Storeys ");
|
|
54
|
+
for (let k = 1; k <= view.storeys; k++) {
|
|
55
|
+
const all = k === view.storeys;
|
|
56
|
+
const b = button(
|
|
57
|
+
all ? "All" : k === 1 ? "1" : `1\u2013${k}`,
|
|
58
|
+
all ? "Show every storey" : `Show storeys 1 to ${k}, hide the ones above`,
|
|
59
|
+
() => view.showStoreys(k)
|
|
60
|
+
);
|
|
61
|
+
b.dataset.storeys = String(k);
|
|
62
|
+
storeyButtons.push(b);
|
|
63
|
+
group.append(b);
|
|
64
|
+
}
|
|
65
|
+
bar.append(group);
|
|
66
|
+
}
|
|
67
|
+
view.onChange(press);
|
|
68
|
+
press();
|
|
69
|
+
const hint = document.createElement("span");
|
|
70
|
+
hint.className = "archlang-views-hint";
|
|
71
|
+
if (opts.hintId) hint.id = opts.hintId;
|
|
72
|
+
hint.textContent = VIEW_HINT;
|
|
73
|
+
bar.append(hint);
|
|
74
|
+
return bar;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/replay/payload.ts
|
|
78
|
+
var PREVIEW_LABEL = "Preview \u2014 from the separate archlang-3d package. ArchLang itself draws plans.";
|
|
79
|
+
function viewBoxOf(svg) {
|
|
80
|
+
const m = /viewBox="([-\d.\s]+)"/.exec(svg);
|
|
81
|
+
const v = (m?.[1] ?? "").trim().split(/\s+/).map(Number);
|
|
82
|
+
if (v.length !== 4 || v.some((x) => !Number.isFinite(x))) throw new Error("the drawing has no numeric viewBox");
|
|
83
|
+
return v;
|
|
84
|
+
}
|
|
85
|
+
function replayPayload(mesh, opts) {
|
|
86
|
+
const lifts = explodeLifts(mesh);
|
|
87
|
+
return {
|
|
88
|
+
title: opts.title,
|
|
89
|
+
theme: opts.theme ?? "light",
|
|
90
|
+
width: opts.width ?? 1920,
|
|
91
|
+
height: opts.height ?? 1080,
|
|
92
|
+
seconds: opts.seconds ?? 15,
|
|
93
|
+
svg: opts.svg,
|
|
94
|
+
viewBox: viewBoxOf(opts.svg),
|
|
95
|
+
elevation: endElevation(storeysOf(mesh).length),
|
|
96
|
+
...opts.facts ? { facts: opts.facts } : {},
|
|
97
|
+
nodes: mesh.nodes.filter((n) => !n.hidden).map((n) => {
|
|
98
|
+
const positions = [];
|
|
99
|
+
const indices = [];
|
|
100
|
+
const slotted = n.shells.some((s) => s.slot !== void 0);
|
|
101
|
+
const groups = slotted ? slotGroups(n.shells) : [{ slot: "body", shells: n.shells }];
|
|
102
|
+
const runs = [];
|
|
103
|
+
for (const g of groups) {
|
|
104
|
+
const start = indices.length;
|
|
105
|
+
for (const s of g.shells) {
|
|
106
|
+
const base = positions.length / 3;
|
|
107
|
+
positions.push(...s.positions);
|
|
108
|
+
for (const i of s.indices) indices.push(base + i);
|
|
109
|
+
}
|
|
110
|
+
runs.push({ slot: g.slot, count: indices.length - start });
|
|
111
|
+
}
|
|
112
|
+
const lift = lifts.get(n.level) ?? 0;
|
|
113
|
+
const finish = FLOOR_FINISHES.find((f) => f === n.extras.finish);
|
|
114
|
+
return {
|
|
115
|
+
key: n.key,
|
|
116
|
+
kind: n.kind,
|
|
117
|
+
...n.part ? { part: n.part } : {},
|
|
118
|
+
...lift !== 0 ? { lift } : {},
|
|
119
|
+
positions,
|
|
120
|
+
indices,
|
|
121
|
+
...slotted ? { groups: runs } : {},
|
|
122
|
+
...n.kind === "floor" && finish ? { finish } : {}
|
|
123
|
+
};
|
|
124
|
+
}),
|
|
125
|
+
events: timeline(mesh)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export {
|
|
130
|
+
PRESET_LABELS,
|
|
131
|
+
VIEW_HINT,
|
|
132
|
+
VIEW_CONTROLS_LABEL,
|
|
133
|
+
viewToolbar,
|
|
134
|
+
PREVIEW_LABEL,
|
|
135
|
+
viewBoxOf,
|
|
136
|
+
replayPayload
|
|
137
|
+
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ARCHLANG_3D_VERSION,
|
|
3
3
|
validateScene3D
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-PRZXP6FP.js";
|
|
5
5
|
import {
|
|
6
6
|
PREVIEW_LABEL,
|
|
7
|
+
VIEW_CONTROLS_LABEL,
|
|
7
8
|
replayPayload
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-WBA4LABI.js";
|
|
9
10
|
import {
|
|
10
11
|
FINISH_PALETTE,
|
|
11
12
|
FLOOR_FINISHES,
|
|
@@ -14,7 +15,7 @@ import {
|
|
|
14
15
|
keyFrames,
|
|
15
16
|
linearRgb,
|
|
16
17
|
slotGroups
|
|
17
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-VPYTRKMK.js";
|
|
18
19
|
|
|
19
20
|
// src/node.ts
|
|
20
21
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
@@ -79,15 +80,22 @@ canvas{max-width:100%;height:auto;display:block}
|
|
|
79
80
|
#archlang-replay-strip[hidden]{display:none}
|
|
80
81
|
input[type=range]{width:min(720px,90vw)}
|
|
81
82
|
p{margin:0;font-size:12px;opacity:.8}
|
|
83
|
+
canvas:focus-visible{outline:2px solid ${fg};outline-offset:2px}
|
|
84
|
+
.archlang-views{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:6px;max-width:min(720px,90vw)}
|
|
85
|
+
.archlang-views button{font:inherit;font-size:13px;padding:2px 10px;border:1px solid ${fg};border-radius:4px;background:transparent;color:${fg};cursor:pointer}
|
|
86
|
+
.archlang-views button[aria-pressed=true]{background:${fg};color:${bg}}
|
|
87
|
+
.archlang-views-storeys{display:inline-flex;align-items:center;gap:4px;margin-left:8px}
|
|
88
|
+
.archlang-views-hint{flex-basis:100%;text-align:center;font-size:12px;opacity:.8}
|
|
82
89
|
</style>
|
|
83
90
|
</head>
|
|
84
91
|
<body>
|
|
85
92
|
<main>
|
|
86
93
|
<div id="archlang-replay-stage" style="width:${payload.width}px">
|
|
87
|
-
<canvas id="archlang-replay" role="
|
|
94
|
+
<canvas id="archlang-replay" role="application" aria-label="${escapeHtml(`${opts.title}: the plan drawing itself in its authoring order, then rising; ${VIEW_CONTROLS_LABEL}`)}"></canvas>${payload.facts ? `
|
|
88
95
|
<div id="archlang-replay-strip" role="group" aria-label="Plan facts" hidden></div>` : ""}
|
|
89
96
|
</div>
|
|
90
97
|
<input id="archlang-replay-t" type="range" min="0" max="1" step="0.001" value="0" aria-label="Replay position">
|
|
98
|
+
<div id="archlang-replay-views"></div>
|
|
91
99
|
<p>${escapeHtml(PREVIEW_LABEL)}</p>
|
|
92
100
|
</main>
|
|
93
101
|
<script type="application/json" id="archlang-replay-payload">${json}</script>
|
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
DOOR_POSES,
|
|
4
4
|
adaptPlan,
|
|
5
5
|
buildMesh
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-QUSG4UCO.js";
|
|
7
7
|
import {
|
|
8
8
|
SWIFTSHADER_ARGS,
|
|
9
9
|
checkGlb,
|
|
@@ -13,18 +13,18 @@ import {
|
|
|
13
13
|
renderReplay,
|
|
14
14
|
replayHtml,
|
|
15
15
|
writeGlb
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-ZE4PL6KP.js";
|
|
17
17
|
import {
|
|
18
18
|
ARCHLANG_3D_VERSION,
|
|
19
19
|
replayFacts
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
import "./chunk-
|
|
20
|
+
} from "./chunk-PRZXP6FP.js";
|
|
21
|
+
import "./chunk-WBA4LABI.js";
|
|
22
22
|
import {
|
|
23
23
|
storeysOf,
|
|
24
24
|
timeline,
|
|
25
25
|
viewLabel,
|
|
26
26
|
viewMesh
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-VPYTRKMK.js";
|
|
28
28
|
|
|
29
29
|
// src/cli/run.ts
|
|
30
30
|
import { readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { World } from '@chanmeng666/archlang';
|
|
2
|
-
import { y as ReplayView, R as ReplayFacts } from './strip-
|
|
2
|
+
import { y as ReplayView, R as ReplayFacts } from './strip-CN_dTKqy.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The metrics strip's numbers (card G4), read from the core's public `describe()` and `lint()` for
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ResolvedPlan, RWall, Point, JoinedCut, loopsToPolygons, World, Diagnostic } from '@chanmeng666/archlang';
|
|
2
2
|
export { Point } from '@chanmeng666/archlang';
|
|
3
|
-
import { a as Scene3D, F as Floor, P as Polygon, M as Mesh3D, b as Pt, c as Shell, d as Ring3, A as Assumption, e as MaterialSlot, f as Furniture
|
|
4
|
-
export { D as DoorKind, E as EXPLODE_GAP_MM,
|
|
5
|
-
export { F as FactsOptions, r as replayFacts } from './facts-
|
|
3
|
+
import { a as Scene3D, F as Floor, P as Polygon, M as Mesh3D, b as Pt, c as Shell, d as Ring3, A as Assumption, e as MaterialSlot, f as Furniture } from './strip-CN_dTKqy.js';
|
|
4
|
+
export { D as DoorKind, E as EXPLODE_GAP_MM, g as FINISH_PALETTE, h as FIXTURE_FAMILIES, i as FLOOR_FINISHES, j as FLOOR_FINISH_RULES, k as Fence, l as FloorFinish, K as KIND_PALETTE, m as KindMaterial, L as Level, n as MATERIAL_SLOTS, o as MeshNode, p as Meta, N as NodeKind, q as NodeState, O as Opening, r as Outdoor, t as PALETTE, u as PHASE, v as Provenance, w as ReplayEvent, R as ReplayFacts, x as ReplayState, y as ReplayView, z as Roof, B as STOP_LEAD, C as SlotMaterial, G as Source, H as Stage, I as Stair, S as StripItem, U as Um, W as WALL_CAP_SRGB, J as Wall, Q as authoringOrder, T as ease, V as explodeLifts, X as finishColour, Y as floorFinish, Z as keyFrames, _ as linearRgb, $ as slotColour, a0 as slotGroups, a1 as stateAt, a2 as storeysOf, s as stripAt, a3 as timeline, a4 as viewLabel, a5 as viewMesh } from './strip-CN_dTKqy.js';
|
|
5
|
+
export { F as FactsOptions, r as replayFacts } from './facts-B47HOKOh.js';
|
|
6
|
+
export { B as Box, E as ELEVATION_AZIMUTH, a as ELEVATION_RANGE, b as END_AZIMUTH, c as END_FOV, d as EndCamera, F as FILL, e as FrameCamera, O as Orbit, f as PRESET_NAMES, P as PresetName, S as START_FOV, V as Vec3, g as ViewScene, Z as ZOOM, h as boxOfNodes, i as cameraAtStop, j as cameraStops, k as corners, l as coverage, m as distanceLimits, n as drawingFrame, o as endElevation, p as fitEndCamera, q as frameCamera, r as pivotAbove, s as presetCamera, t as projectBox, u as takenLens, v as targetBounds } from './camera-CLNYQ1Xv.js';
|
|
6
7
|
|
|
7
8
|
/** The package's own version, stamped into `meta.tool`. */
|
|
8
9
|
declare const ARCHLANG_3D_VERSION: string;
|
|
@@ -456,122 +457,4 @@ declare function t0Shells(f: Furniture, floor: number): {
|
|
|
456
457
|
holesDropped: number;
|
|
457
458
|
} | null;
|
|
458
459
|
|
|
459
|
-
|
|
460
|
-
* The replay's end camera as plain maths (card A3, look notes round 1): the viewer and the tests
|
|
461
|
-
* read the same functions, so "the end frame fills the canvas" is a property a test can check
|
|
462
|
-
* without a browser. Millimetres, the exporters' axes (X plan x, Y up, Z plan y). No three.js here:
|
|
463
|
-
* the conventions copy three.js's `lookAt` for a camera (it looks down its local −Z; right =
|
|
464
|
-
* up × back, true up = back × right, world up +Y).
|
|
465
|
-
*/
|
|
466
|
-
|
|
467
|
-
type Vec3 = [number, number, number];
|
|
468
|
-
interface Box {
|
|
469
|
-
lo: Vec3;
|
|
470
|
-
hi: Vec3;
|
|
471
|
-
}
|
|
472
|
-
/** Where the end camera looks from: elevation and azimuth in degrees, vertical field of view. */
|
|
473
|
-
interface Orbit {
|
|
474
|
-
elevation: number;
|
|
475
|
-
azimuth: number;
|
|
476
|
-
fov: number;
|
|
477
|
-
/** Canvas width / height. */
|
|
478
|
-
aspect: number;
|
|
479
|
-
}
|
|
480
|
-
interface EndCamera {
|
|
481
|
-
target: Vec3;
|
|
482
|
-
/** Distance from the target to the camera (mm). */
|
|
483
|
-
dist: number;
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* The fraction of each half-axis the building may use: a margin of 6 % of the frame on each side
|
|
487
|
-
* of the binding axis.
|
|
488
|
-
*/
|
|
489
|
-
declare const FILL = 0.88;
|
|
490
|
-
declare function corners(b: Box): Vec3[];
|
|
491
|
-
/**
|
|
492
|
-
* The projected extent of `box` in normalised device coordinates (−1…1 on each axis) for a camera
|
|
493
|
-
* at `cam` with orbit `o`.
|
|
494
|
-
*/
|
|
495
|
-
declare function projectBox(box: Box, cam: EndCamera, o: Orbit): {
|
|
496
|
-
x: [number, number];
|
|
497
|
-
y: [number, number];
|
|
498
|
-
};
|
|
499
|
-
/**
|
|
500
|
-
* The end camera that fills the frame with `box`: the 8 corners are projected through the end
|
|
501
|
-
* orbit and the distance is solved so the binding corner sits at `FILL` of the half-frame; the
|
|
502
|
-
* target is then re-centred on the projected box (perspective makes the near half larger) and the
|
|
503
|
-
* distance solved again. A fixed number of rounds, so the result is a pure function of its input.
|
|
504
|
-
*/
|
|
505
|
-
declare function fitEndCamera(box: Box, o: Orbit): EndCamera;
|
|
506
|
-
/** The share of the binding axis the projected box fills (1 = edge to edge). */
|
|
507
|
-
declare function coverage(box: Box, cam: EndCamera, o: Orbit): number;
|
|
508
|
-
/** The end camera's lens and bearing. */
|
|
509
|
-
declare const END_FOV = 30;
|
|
510
|
-
declare const END_AZIMUTH = -32;
|
|
511
|
-
/**
|
|
512
|
-
* The end camera's elevation: 45° for every view. The combined view of a taller building needs it so
|
|
513
|
-
* the exploded gaps show the floors below (see `timeline.ts`'s header); a one-storey view took it
|
|
514
|
-
* too (card A9, by delegation, the owner may veto on a look): at 30° the near walls hid the floor,
|
|
515
|
-
* the inner doors and most furniture of `studio`. The storey count stays a parameter so a later
|
|
516
|
-
* look can split the two again without a signature change.
|
|
517
|
-
*/
|
|
518
|
-
declare const endElevation: (_storeys: number) => number;
|
|
519
|
-
/**
|
|
520
|
-
* The scene's box (mm) from the payload's nodes: positions in micrometres, each node lifted by its
|
|
521
|
-
* `lift` (the combined view's exploded storeys). A demolished wall's ghost (`part` "demolish") is not
|
|
522
|
-
* the building and is left out of a fit (`timeline.ts`'s header), unless nothing else is there;
|
|
523
|
-
* `ghosts: true` keeps it, for a box that must hold everything drawn (the viewer's clip range).
|
|
524
|
-
*/
|
|
525
|
-
declare function boxOfNodes(nodes: ReadonlyArray<{
|
|
526
|
-
positions: readonly number[];
|
|
527
|
-
lift?: number;
|
|
528
|
-
part?: string;
|
|
529
|
-
}>, opts?: {
|
|
530
|
-
ghosts?: boolean;
|
|
531
|
-
}): Box;
|
|
532
|
-
/** The perspective camera's lens at the start of the dolly (a near-orthographic top-down view). */
|
|
533
|
-
declare const START_FOV = 1.5;
|
|
534
|
-
/**
|
|
535
|
-
* One fitted camera per stop: stop k fills the frame with storeys 0…k (the combined view; a node's
|
|
536
|
-
* storey is its event's), the last stop with the whole building. One storey: one stop. Each stop is
|
|
537
|
-
* fitted for the end orbit, which `stateAt` has reached by the time of the first stop.
|
|
538
|
-
*/
|
|
539
|
-
declare function cameraStops(nodes: ReadonlyArray<{
|
|
540
|
-
key: string;
|
|
541
|
-
positions: readonly number[];
|
|
542
|
-
lift?: number;
|
|
543
|
-
part?: string;
|
|
544
|
-
}>, events: readonly ReplayEvent[], o: Orbit): EndCamera[];
|
|
545
|
-
/** The fitted camera at a (fractional) stop: between two stops, a straight blend of the two. */
|
|
546
|
-
declare function cameraAtStop(fits: readonly EndCamera[], stop: number): EndCamera;
|
|
547
|
-
/** The perspective camera of one frame: where it aims, from how far, with which lens and bearing. */
|
|
548
|
-
interface FrameCamera {
|
|
549
|
-
target: Vec3;
|
|
550
|
-
dist: number;
|
|
551
|
-
fov: number;
|
|
552
|
-
elevation: number;
|
|
553
|
-
azimuth: number;
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* The perspective camera at state `s` (the viewer's `seek`): from straight down over the drawing's
|
|
557
|
-
* centre (`cx`, `cz`; `oh` the drawing's height in the frame) it tilts to the end orbit and dollies
|
|
558
|
-
* to the fitted camera of the current stop.
|
|
559
|
-
*/
|
|
560
|
-
declare function frameCamera(s: Pick<ReplayState, "tilt" | "dolly" | "stop">, fits: readonly EndCamera[], view: {
|
|
561
|
-
cx: number;
|
|
562
|
-
cz: number;
|
|
563
|
-
oh: number;
|
|
564
|
-
elevation: number;
|
|
565
|
-
}): FrameCamera;
|
|
566
|
-
/**
|
|
567
|
-
* The first frame frames the core drawing's viewBox exactly, letterboxed as the image is: its
|
|
568
|
-
* centre (`cx`, `cz`) and the height (`oh`) and width (`ow`) it spans in the frame, in plan mm.
|
|
569
|
-
*/
|
|
570
|
-
declare function drawingFrame(viewBox: readonly [number, number, number, number], aspect: number): {
|
|
571
|
-
cx: number;
|
|
572
|
-
cz: number;
|
|
573
|
-
ow: number;
|
|
574
|
-
oh: number;
|
|
575
|
-
};
|
|
576
|
-
|
|
577
|
-
export { ARCHLANG_3D_VERSION, type AdaptOptions, type AdaptResult, Assumption, type Box, type BuildOptions, type CutSector, DOOR_POSES, type DoorPose, END_AZIMUTH, END_FOV, type EndCamera, FILL, FLOOR_LIFT_UM, FLOOR_OVERLAP_MIN_UM2, FURNITURE_HEIGHT_MM, Floor, type FloorOverlap, type FrameCamera, Furniture, MIN_CORE, MaterialSlot, Mesh3D, type MeshOptions, type MixedHeightJoint, type Orbit, type OwnedWall, type Ownership, type Part, type Piece, Polygon, Pt, type Refusal, type RefusalCode, ReplayEvent, ReplayState, type Ring, Ring3, START_FOV, Scene3D, type SectionShape, Shell, type Storey, T0_FAMILIES, T0_HANDED, T0_HEIGHT_MM, T0_HUNG_FROM_TOP, T0_MATERIALS, T0_MOUNT_MM, type ValidationIssue, type Vec3, type Warning3D, adaptPlan, assetFor, boxOfNodes, buildMesh, buildScene3D, cameraAtStop, cameraStops, clipToConvex, corners, coverage, cutSector, drawingFrame, endElevation, fitEndCamera, floorLifts, floorOverlaps, frameCamera, handedAt, insideCut, mixedHeightJoints, openLeaf, overlapArea, partShell, piecesOf, piecesTouch, prism, projectBox, rectsOf, sectionRing, sectorBand, slab2d, slabRegion, t0LocalParts, t0Shells, um, umPoint, validateScene3D, wallOwnership };
|
|
460
|
+
export { ARCHLANG_3D_VERSION, type AdaptOptions, type AdaptResult, Assumption, type BuildOptions, type CutSector, DOOR_POSES, type DoorPose, FLOOR_LIFT_UM, FLOOR_OVERLAP_MIN_UM2, FURNITURE_HEIGHT_MM, Floor, type FloorOverlap, Furniture, MIN_CORE, MaterialSlot, Mesh3D, type MeshOptions, type MixedHeightJoint, type OwnedWall, type Ownership, type Part, type Piece, Polygon, Pt, type Refusal, type RefusalCode, type Ring, Ring3, Scene3D, type SectionShape, Shell, type Storey, T0_FAMILIES, T0_HANDED, T0_HEIGHT_MM, T0_HUNG_FROM_TOP, T0_MATERIALS, T0_MOUNT_MM, type ValidationIssue, type Warning3D, adaptPlan, assetFor, buildMesh, buildScene3D, clipToConvex, cutSector, floorLifts, floorOverlaps, handedAt, insideCut, mixedHeightJoints, openLeaf, overlapArea, partShell, piecesOf, piecesTouch, prism, rectsOf, sectionRing, sectorBand, slab2d, slabRegion, t0LocalParts, t0Shells, um, umPoint, validateScene3D, wallOwnership };
|