@oeave/bakery3 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.
Files changed (46) hide show
  1. package/dist/bake/index.js +3 -3
  2. package/dist/catalog/index.js +1 -1
  3. package/dist/{chunk-KNUAOILG.js → chunk-3T3FJOSD.js} +4 -4
  4. package/dist/{chunk-KNUAOILG.js.map → chunk-3T3FJOSD.js.map} +1 -1
  5. package/dist/{chunk-6FYI6AJM.js → chunk-6FAMQZXB.js} +7 -7
  6. package/dist/{chunk-6FYI6AJM.js.map → chunk-6FAMQZXB.js.map} +1 -1
  7. package/dist/{chunk-QRCT5UGZ.js → chunk-CSSJRP5W.js} +9 -6
  8. package/dist/chunk-CSSJRP5W.js.map +1 -0
  9. package/dist/{chunk-APWUCEEB.js → chunk-EN4ROBYQ.js} +3 -3
  10. package/dist/{chunk-APWUCEEB.js.map → chunk-EN4ROBYQ.js.map} +1 -1
  11. package/dist/{chunk-JFYUDERE.js → chunk-NEK5TBEH.js} +2 -2
  12. package/dist/chunk-NEK5TBEH.js.map +1 -0
  13. package/dist/chunk-OPM2L63B.js +253 -0
  14. package/dist/chunk-OPM2L63B.js.map +1 -0
  15. package/dist/{chunk-UWBP7B54.js → chunk-R5IUPOWI.js} +3 -3
  16. package/dist/{chunk-UWBP7B54.js.map → chunk-R5IUPOWI.js.map} +1 -1
  17. package/dist/{chunk-HNMSWQU7.js → chunk-STRK4SZN.js} +3 -3
  18. package/dist/{chunk-HNMSWQU7.js.map → chunk-STRK4SZN.js.map} +1 -1
  19. package/dist/{chunk-Z7IYVH22.js → chunk-WLEFNUOH.js} +30 -279
  20. package/dist/chunk-WLEFNUOH.js.map +1 -0
  21. package/dist/{chunk-NXBAZGNB.js → chunk-X6GW43EX.js} +3 -3
  22. package/dist/{chunk-NXBAZGNB.js.map → chunk-X6GW43EX.js.map} +1 -1
  23. package/dist/devtools/index.js +7 -6
  24. package/dist/hotspots/index.d.ts +237 -31
  25. package/dist/hotspots/index.js +1013 -118
  26. package/dist/hotspots/index.js.map +1 -1
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +7 -6
  29. package/dist/node/index.cjs +1 -1
  30. package/dist/node/index.cjs.map +1 -1
  31. package/dist/node/index.js +2 -2
  32. package/dist/presets/index.js +2 -2
  33. package/dist/r3f/index.js +9 -8
  34. package/dist/r3f/index.js.map +1 -1
  35. package/dist/{room-FS26KAPQ.js → room-BM7Z7NKG.js} +4 -4
  36. package/dist/{room-FS26KAPQ.js.map → room-BM7Z7NKG.js.map} +1 -1
  37. package/dist/session-NPVBESWA.js +9 -0
  38. package/dist/{session-VCIQEO26.js.map → session-NPVBESWA.js.map} +1 -1
  39. package/dist/tsl/index.d.ts +14 -1
  40. package/dist/tsl/index.js +8 -2
  41. package/dist/tsl/index.js.map +1 -1
  42. package/package.json +1 -1
  43. package/dist/chunk-JFYUDERE.js.map +0 -1
  44. package/dist/chunk-QRCT5UGZ.js.map +0 -1
  45. package/dist/chunk-Z7IYVH22.js.map +0 -1
  46. package/dist/session-VCIQEO26.js +0 -9
@@ -1,32 +1,117 @@
1
- import { Group, Camera, Vector3, Object3D } from 'three';
1
+ import { Group, Vector3, Camera, Material, Color, Object3D, Intersection } from 'three';
2
+ import { T as Timeline } from '../timeline-ChwgD7bT.js';
3
+ import '../animation-B1h0Ryvj.js';
2
4
 
3
5
  /**
4
6
  * The implementation behind `@oeave/bakery3/hotspots`. `index.ts` lists what
5
- * is public; the orb's parts and the brand color are here for the SDK's own
6
- * pointer handling and the monorepo's tools (`internal.ts`).
7
+ * is public; the parts, the pose and the brand color are here for the SDK's
8
+ * own pointer handling and the monorepo's tools (`internal.ts`).
9
+ *
10
+ * One function decides how a hotspot looks: `poseOf` turns its state (how far
11
+ * it has appeared, how far it is open, the hover, the label, the pulse) into
12
+ * numbers on its parts. The live hotspot applies them every frame;
13
+ * `animateHotspots` samples them at every frame of a timeline and writes them
14
+ * as tracks, which is how the render plays the same motion the viewport
15
+ * showed. There is no second animation system to drift from the first.
7
16
  */
8
17
 
9
18
  /** `[x, y, z]`, in meters: the protocol's own vector shape. */
10
19
  type Vec3 = [number, number, number];
20
+ /**
21
+ * Where a hotspot is headed. `hidden` is not there at all, `closed` is the
22
+ * resting dot, `open` is the dot as it looks while its panel is showing.
23
+ */
24
+ type HotspotState = 'hidden' | 'closed' | 'open';
25
+ /** Where a hotspot is now, including the moves between states. */
26
+ type HotspotPhase = 'hidden' | 'entering' | 'closed' | 'opening' | 'open' | 'closing' | 'leaving';
27
+ /**
28
+ * The built-in looks.
29
+ *
30
+ * - `orb`: a glowing core in a soft halo that breathes.
31
+ * - `ring`: a small glowing core inside a ring.
32
+ * - `glass`: a clear glass bead with a glowing core inside.
33
+ * - `solid`: a glossy colored bead that barely glows.
34
+ */
35
+ type HotspotPreset = 'orb' | 'ring' | 'glass' | 'solid';
36
+ /** The meshes a hotspot can be made of; which exist depends on the preset. */
37
+ type HotspotPartName = 'core' | 'halo' | 'ring' | 'shell' | 'tether' | 'dot';
38
+ /**
39
+ * When the label beside a hotspot shows.
40
+ *
41
+ * - `never` (default): the hotspot draws no text.
42
+ * - `always`: whenever the hotspot is there.
43
+ * - `open`: while it is open.
44
+ * - `hover`: while the pointer is over it, and while it is open. A timeline
45
+ * hovers it with a `hover` event.
46
+ */
47
+ type HotspotLabelShow = 'never' | 'always' | 'open' | 'hover';
48
+ /** Which side of the orb the label is on. `auto` moves it off a screen edge. */
49
+ type HotspotLabelSide = 'auto' | 'left' | 'right';
50
+ /**
51
+ * A material of your own for a part, or a function asked once per part that
52
+ * returns one (or `undefined` to keep the preset's). A node material with an
53
+ * `emissiveNode` should multiply it by `bakeryEmissiveIntensity()` from
54
+ * `@oeave/bakery3/tsl`, so the glow the state animates reaches it in the
55
+ * viewport as it does in the render.
56
+ */
57
+ type HotspotMaterial = Material | ((part: {
58
+ name: HotspotPartName;
59
+ color: Color;
60
+ }) => Material | undefined);
11
61
  type HotspotOptions = {
12
62
  /** Stable identity: it names the group and travels with `hotspotSpecOf`. */
13
63
  id: string;
14
- /** A caption for the app to show; the orb itself draws no text. */
64
+ /** The hotspot's caption: the text of its label, and yours to show in your app. */
15
65
  label?: string;
16
- /** Where the orb is, in the parent's space (world space without a parent). */
17
- position: Vec3 | Vector3;
18
66
  /**
19
- * A surface point on the model, in the same space as `position`. When given
20
- * the hotspot is anchored: a thin line is drawn from here to the orb.
67
+ * Where the orb is, in the parent's space (world space without a parent).
68
+ * With an `anchor`, you can give `direction` and `distance` instead.
69
+ */
70
+ position?: Vec3 | Vector3;
71
+ /**
72
+ * A point on the model's surface, in the same space as `position`. When
73
+ * given, the hotspot is tied to it: a thin line runs from a small dot on
74
+ * the surface out to the orb.
21
75
  */
22
76
  anchor?: Vec3 | Vector3;
77
+ /**
78
+ * Which way the orb stands off the anchor, in the parent's space. Default:
79
+ * toward `position`, or straight up.
80
+ */
81
+ direction?: Vec3 | Vector3;
82
+ /** How far the orb stands off the anchor, in meters. Default: to `position`, or 0.1. */
83
+ distance?: number;
23
84
  /**
24
85
  * Attach to this object so the hotspot follows it. Without one the caller
25
86
  * adds `hotspot.object` to the scene themselves.
26
87
  */
27
88
  parent?: Object3D;
28
- /** CSS color of the orb, halo and line. Default the brand cyan, `#33d1ff`. */
89
+ /**
90
+ * Whether the hotspot shows up in renders. Default false: a hotspot is
91
+ * viewport UI and the capture walks past it. With true it is part of the
92
+ * scene, its glow lights the model in the render, and `animateHotspots`
93
+ * can play its states in a video.
94
+ */
95
+ render?: boolean;
96
+ /** The look. Default `orb`. */
97
+ style?: HotspotPreset;
98
+ /** Any CSS color. Default the brand cyan, `#33d1ff`. */
29
99
  color?: string;
100
+ /** The color it turns while open. Default: it keeps `color`. */
101
+ openColor?: string;
102
+ /**
103
+ * How bright the glowing parts are (emission strength). Default 3 for
104
+ * `orb` and `ring`, 6 for `glass`, 0.2 for `solid`; 1 for a hotspot that
105
+ * does not render, so the color on screen is exactly `color`.
106
+ */
107
+ intensity?: number;
108
+ /**
109
+ * How much the hotspot lights the model around it while open: a point light
110
+ * at the orb, in candela. A closed hotspot gives a third of it. Default 0.
111
+ */
112
+ glow?: number;
113
+ /** Your own material for some or all parts, a TSL node material included. */
114
+ material?: HotspotMaterial;
30
115
  /**
31
116
  * How the orb is sized. `screen` (default) keeps it the same size on screen
32
117
  * wherever it is: `size` is then a fraction of the viewport height, and
@@ -34,33 +119,86 @@ type HotspotOptions = {
34
119
  * `world` is a fixed radius in meters, which shrinks with distance.
35
120
  */
36
121
  sizing?: 'screen' | 'world';
37
- /** Orb radius: a fraction of viewport height (`screen`, default 0.012) or meters (`world`, default 0.03). */
122
+ /** Orb radius: a fraction of viewport height (`screen`, default 0.015) or meters (`world`, default 0.03). */
38
123
  size?: number;
39
- /** Whether the halo breathes. Default true. */
40
- pulse?: boolean;
124
+ /** Whether the closed hotspot breathes, or how fast, in cycles a second. Default true (0.7). */
125
+ pulse?: boolean | number;
126
+ /** Draw the line to the anchor. Default true when anchored. */
127
+ tether?: boolean;
128
+ /** Draw the small dot on the anchor. Default true when anchored. */
129
+ dot?: boolean;
130
+ /** When the label beside the orb shows. Default `never`. */
131
+ showLabel?: HotspotLabelShow;
132
+ /** Which side the label is on. Default `auto`: right, or left near the right edge. */
133
+ labelSide?: HotspotLabelSide;
134
+ /**
135
+ * The label's CSS font. Its pixel size is how sharp the label is, not how
136
+ * big: the label is sized to the orb. Default the platform's UI face at 40px.
137
+ */
138
+ labelFont?: string;
139
+ /** The label's text color. Default white. */
140
+ labelColor?: string;
141
+ /** The label's background color. Default near black. */
142
+ labelBackground?: string;
143
+ /** How opaque the shown label is. Default 0.9. */
144
+ labelOpacity?: number;
145
+ /** The label's height, as a multiple of its default. Default 1. */
146
+ labelSize?: number;
147
+ /** The state it starts in, already there. Default `closed`. */
148
+ state?: HotspotState;
149
+ /** Seconds each move takes. Default 0.8 to appear, 0.45 to open, 0.3 for the label. */
150
+ timing?: {
151
+ appear?: number;
152
+ open?: number;
153
+ label?: number;
154
+ };
41
155
  };
42
156
  type Hotspot = {
43
157
  readonly id: string;
44
158
  readonly label: string | undefined;
45
159
  /**
46
- * The group holding everything (the orb, and the tether when anchored),
47
- * placed at the orb; excluded from capture, named `bakery3-hotspot-<id>`.
160
+ * The group holding everything, placed at the anchor (at the orb when
161
+ * there is none), named `bakery3-hotspot-<id>`.
48
162
  */
49
163
  readonly object: Group;
50
- /** Whether `setSelected(true)` is in effect. */
164
+ /** The state it is headed for. */
165
+ readonly state: HotspotState;
166
+ /** Where it is now, moves included. */
167
+ readonly phase: HotspotPhase;
168
+ /** Whether it is open, or opening. */
51
169
  readonly selected: boolean;
52
- /** Whether the cursor is over it; set by `attachHotspots`. */
170
+ /** Whether it is hovered, by the pointer or by `setHovered()`. */
53
171
  readonly hovered: boolean;
172
+ /** Meters from the anchor to the orb. */
173
+ readonly distance: number;
174
+ /** The side the label is on, or headed for. */
175
+ readonly labelSide: 'left' | 'right';
176
+ /** True while `animateHotspots` drives it: `update()` then leaves it to the timeline. */
177
+ readonly driven: boolean;
178
+ /** Move to a state, animated unless `instant`. */
179
+ setState(state: HotspotState, options?: {
180
+ instant?: boolean;
181
+ }): void;
182
+ /** `setState('open')` or `setState('closed')`. */
54
183
  setSelected(on: boolean): void;
55
- /** Advance the pulse; `seconds` is any monotonic clock. */
184
+ /** Hover it, or stop: what `attachHotspots` does as the pointer moves. */
185
+ setHovered(on: boolean): void;
186
+ /** Change the label's text. */
187
+ setLabel(text: string): void;
188
+ /** Stand the orb this far off the anchor, in meters. */
189
+ setDistance(meters: number): void;
190
+ /** Point the orb this way from the anchor (parent space). */
191
+ setDirection(direction: Vec3 | Vector3): void;
192
+ /** Advance the moves and the pulse; `seconds` is any monotonic clock. */
56
193
  update(seconds: number): void;
57
194
  /**
58
- * Scale the orb so it projects to its `size` for this camera. Called by
59
- * `attachHotspots.update()`; a host without pointer handling calls it
60
- * itself once per frame. No-op for `sizing: 'world'`.
195
+ * Turn the orb and its label to face this camera, put the label on the
196
+ * side with room, and, for a screen-sized orb, scale it to its `size`.
197
+ * Called by `attachHotspots.update()`; a host without pointer handling
198
+ * calls it itself once per frame, before `update()`.
61
199
  */
62
200
  fit(camera: Camera): void;
63
- /** Detach from its parent and free every geometry and material. */
201
+ /** Detach from its parent and free every geometry, material and texture. */
64
202
  dispose(): void;
65
203
  };
66
204
  /** A hotspot as data, in world space: what to keep with a capture. */
@@ -71,29 +209,97 @@ type HotspotSpec = {
71
209
  anchor?: Vec3;
72
210
  };
73
211
  declare function createHotspot(options: HotspotOptions): Hotspot;
212
+ /**
213
+ * Where to put a hotspot for a click on a model: the surface point, and the
214
+ * way out of the surface there.
215
+ *
216
+ * `along: 'normal'` (default) stands the orb off the face that was hit;
217
+ * `'center'` stands it away from `center` (the model's middle) through the
218
+ * point, which keeps orbs on a curved or noisy surface from pointing every
219
+ * which way. Both are returned in `space`'s coordinates (world without one),
220
+ * ready to pass as `anchor` and `direction` with `parent: space`.
221
+ */
222
+ declare function hotspotFromHit(hit: Intersection, options?: {
223
+ along?: 'normal' | 'center';
224
+ center?: Vector3;
225
+ space?: Object3D;
226
+ }): {
227
+ anchor: Vector3;
228
+ direction: Vector3;
229
+ };
74
230
  /**
75
231
  * A hotspot as plain data, in world space, ready for `productState`.
76
232
  *
77
233
  * Reads through the parents so a hotspot riding on a product that has been
78
- * moved reports where it actually is, not where it was authored.
234
+ * moved reports where it actually is, not where it was authored. The
235
+ * position is where the orb stands once it is out, whatever it is doing.
79
236
  */
80
237
  declare function hotspotSpecOf(hotspot: Hotspot): HotspotSpec;
238
+ /** One change, at a time on the timeline: a state, a hover, or both. */
239
+ type HotspotEvent = {
240
+ /** The hotspot, or its id. */
241
+ hotspot: Hotspot | string;
242
+ /** Seconds from the start of the timeline. */
243
+ at: number;
244
+ state?: HotspotState;
245
+ /**
246
+ * The pointer moves onto it (true) or off (false): the hover look, and the
247
+ * label of a hotspot that shows it on hover.
248
+ */
249
+ hover?: boolean;
250
+ };
251
+ type AnimateHotspotsOptions = {
252
+ /** The changes, in any order. */
253
+ events?: HotspotEvent[];
254
+ /**
255
+ * Where each hotspot is at time zero, already there: one state for all, or
256
+ * one per id. Default `hidden`, so a clip opens on the model alone.
257
+ */
258
+ initial?: HotspotState | Record<string, HotspotState>;
259
+ /**
260
+ * Round each pulse to whole breaths over the timeline, so a clip that loops
261
+ * does not hitch at the seam. Default true.
262
+ */
263
+ loop?: boolean;
264
+ };
265
+ type AnimatedHotspots = {
266
+ /** How many tracks were written. */
267
+ readonly tracks: number;
268
+ /** Remove the tracks and hand the hotspots back to their own `update()`. */
269
+ release(): void;
270
+ };
271
+ /**
272
+ * Play hotspot states on a timeline, so a video renders them.
273
+ *
274
+ * Every frame of the timeline is posed by the same function the live hotspot
275
+ * uses, and written as ordinary tracks (position, rotation, scale, emission,
276
+ * opacity, the glow light's intensity), so `seek()` previews exactly what the
277
+ * render traces. The camera at each frame decides what a live camera would:
278
+ * the size of a screen-sized orb, which way the rig faces, and which side the
279
+ * label is on. Author the camera first. Calling it again on the same timeline
280
+ * replaces what it wrote. Hotspots must be made with `render: true`.
281
+ *
282
+ * While animated, a hotspot's `update()` and `fit()` stand aside.
283
+ */
284
+ declare function animateHotspots(timeline: Timeline, hotspots: Hotspot[], options?: AnimateHotspotsOptions): AnimatedHotspots;
285
+ /** Undo `animateHotspots` on a timeline: its tracks go, the hotspots are live again. */
286
+ declare function releaseHotspots(timeline: Timeline): void;
81
287
  type AttachHotspotsOptions = {
82
288
  hotspots: Hotspot[];
83
289
  camera: Camera;
84
290
  /** The renderer's canvas, or whatever element receives the pointer. */
85
291
  domElement: HTMLElement;
86
- /** Selection changed: the hotspot now selected, or null when cleared. */
292
+ /** Selection changed: the hotspot now open, or null when cleared. */
87
293
  onSelect?(hotspot: Hotspot | null): void;
88
294
  /** The pointer moved onto (or off) a hotspot. */
89
295
  onHover?(hotspot: Hotspot | null): void;
90
296
  };
91
297
  type AttachedHotspots = {
92
- /** Advance every hotspot's pulse. Call once per frame. */
298
+ /** Fit and advance every hotspot. Call once per frame. */
93
299
  update(seconds: number): void;
94
- /** The hotspot currently selected, if any. */
300
+ /** The hotspot currently open, if any. */
95
301
  readonly selected: Hotspot | null;
96
- /** Select (or clear) programmatically; fires `onSelect` like a click would. */
302
+ /** Open one (or close all) programmatically; fires `onSelect` like a click would. */
97
303
  select(hotspot: Hotspot | null): void;
98
304
  /** Remove the listeners. Does not dispose the hotspots. */
99
305
  dispose(): void;
@@ -101,11 +307,11 @@ type AttachedHotspots = {
101
307
  /**
102
308
  * Wire hover and click for a set of hotspots on one canvas.
103
309
  *
104
- * Raycasts the orbs (core and halo, so the target is a little generous) from
105
- * the pointer through `camera`; sets `cursor: pointer` over one; toggles
106
- * selection on click, one at a time. Nothing here is a render loop: call
107
- * `update()` from yours.
310
+ * Raycasts the heads (core and halo, ring or glass, and the label, so the
311
+ * target is a little generous) from the pointer through `camera`; sets
312
+ * `cursor: pointer` over one; opens it on click and closes the one that was
313
+ * open. Nothing here is a render loop: call `update()` from yours.
108
314
  */
109
315
  declare function attachHotspots(options: AttachHotspotsOptions): AttachedHotspots;
110
316
 
111
- export { type AttachHotspotsOptions, type AttachedHotspots, type Hotspot, type HotspotOptions, type HotspotSpec, type Vec3, attachHotspots, createHotspot, hotspotSpecOf };
317
+ export { type AnimateHotspotsOptions, type AnimatedHotspots, type AttachHotspotsOptions, type AttachedHotspots, type Hotspot, type HotspotEvent, type HotspotLabelShow, type HotspotLabelSide, type HotspotMaterial, type HotspotOptions, type HotspotPartName, type HotspotPhase, type HotspotPreset, type HotspotSpec, type HotspotState, type Vec3, animateHotspots, attachHotspots, createHotspot, hotspotFromHit, hotspotSpecOf, releaseHotspots };