@volter/editor-model-play 0.5.189 → 0.5.191
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 +185 -0
- package/contributions/model-play.command.ts +37 -0
- package/contributions/model-play.service.tsx +108 -5
- package/package.json +3 -2
- package/src/camera-transition.ts +13 -3
- package/src/model-play.ts +253 -10
- package/src/play-log.ts +233 -0
- package/src/play-materials.ts +199 -0
- package/src/play-script.ts +357 -21
package/README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Volter Model Play
|
|
2
|
+
|
|
3
|
+
Play scripts on detached model documents. Play (the Game panel's, in Cyclotron) runs
|
|
4
|
+
`src/models/<name>.play.ts` beside `src/models/<name>.blend` on a detached copy
|
|
5
|
+
of the model; the model, its selection and its history stand as they were, and
|
|
6
|
+
Stop returns to them. The script's default export is called once with the play
|
|
7
|
+
context (`ModelPlayContext`, `src/play-script.ts`) and answers the game:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import type { ModelPlayContext, ModelPlayGame } from '@volter/editor-model-play/play-script';
|
|
11
|
+
|
|
12
|
+
export default (play: ModelPlayContext): ModelPlayGame => {
|
|
13
|
+
const player = play.find('Player')!;
|
|
14
|
+
let checkpoint = false;
|
|
15
|
+
return {
|
|
16
|
+
update(dt) {
|
|
17
|
+
player.position.y += dt;
|
|
18
|
+
if (!checkpoint && player.position.y > 10) {
|
|
19
|
+
checkpoint = true;
|
|
20
|
+
play.tint('Checkpoint.Pad', '#2bff6b');
|
|
21
|
+
play.log('checkpoint', { stage: 2, at: player.position });
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## The play log
|
|
29
|
+
|
|
30
|
+
`play.log(kind, facts?)` writes one entry, stamped with `simT` (seconds of
|
|
31
|
+
simulation since Play started, the sum of the `dt`s given to `update`) and
|
|
32
|
+
`tick` (the update in progress). Facts are snapshotted as JSON when logged. `simT` and `tick` are the Game panel's
|
|
33
|
+
clock: they stand still while paused and run at the speed (see Time below). The
|
|
34
|
+
runner adds `play-start`, `play-restart` (`{ speed }`, right after a Restart's
|
|
35
|
+
`play-start`), `script-reload` (`{ reason: 'saved' | 'dependency-deleted', path }`),
|
|
36
|
+
`script-error` (`{ phase, message }`), `tint-unsupported` (`{ object, material, why }`),
|
|
37
|
+
`tint-unknown-object` (`{ object, call }`, once per name: `tint` or `setOpacity` was given a
|
|
38
|
+
name the model has none of, and did nothing), `autoplay-on` / `autoplay-off`
|
|
39
|
+
(`{ by: 'panel' | 'cli' | 'takeover' | 'script' }`, see Autoplay below),
|
|
40
|
+
`autoplay-unavailable` (`{ why }`, when a script's first update has run and it registered no
|
|
41
|
+
bot; once per run, and again only if a bot came and went),
|
|
42
|
+
`pause`, `resume`, `step` (`{ dt }`, one per stepped update), `speed`
|
|
43
|
+
(`{ speed, from }` on a change; `{ speed }` at a start that is not 1×) and
|
|
44
|
+
`play-stop` (`{ reason }`). Log transitions rather than every frame. Logging
|
|
45
|
+
never throws and never changes timing or state; a script's `log`, `tint` and
|
|
46
|
+
`setOpacity` do nothing once it has been replaced or Play has stopped.
|
|
47
|
+
|
|
48
|
+
Each model document keeps its own log; a read takes the active Play's unless it
|
|
49
|
+
names a document. The newest 5000 entries are kept (older ones are counted as
|
|
50
|
+
`dropped`), each entry's facts up to 2048 characters of JSON. Play from a fresh
|
|
51
|
+
copy, and Restart, empty the document's log; a script reload does not, and the log stays readable after Stop until the
|
|
52
|
+
next Play. `console.log` does not reach the session's console feed (only
|
|
53
|
+
warnings and errors do); the play log does.
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
cyclotron play-log # every kept entry, one per line
|
|
57
|
+
cyclotron play-log --kind death # one kind
|
|
58
|
+
cyclotron play-log --since 12.5 --json # entries at or after simT 12.5, as JSON
|
|
59
|
+
cyclotron play-log --document <id> # another model document's log
|
|
60
|
+
cyclotron eval "(await editor.modelPlayLog({ kind: 'death' })).entries"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Recolouring the copy
|
|
64
|
+
|
|
65
|
+
`play.tint(object, color)` draws an object (a name, or what `find` answered)
|
|
66
|
+
and every mesh under it in `color`; an emitting surface glows in it, and an
|
|
67
|
+
image texture is multiplied by it. `play.setOpacity(object, opacity)` fades it.
|
|
68
|
+
`null` returns the authored look. Other objects wearing the same Blender
|
|
69
|
+
material are not affected.
|
|
70
|
+
|
|
71
|
+
Use these instead of editing materials directly: a presented mesh's `material`
|
|
72
|
+
is an array with one `MeshPhysicalMaterial` per Blender material slot, shared by
|
|
73
|
+
every object with that material; the presenter re-assigns those slots whenever
|
|
74
|
+
it re-applies shading; `clone()` drops its shader hooks; and a node graph that
|
|
75
|
+
drives Base Color or Alpha ignores `color` and `opacity`. A tinted or faded
|
|
76
|
+
object wears copies of its own slots that draw the material's constant inputs
|
|
77
|
+
(so a node graph's other inputs are not drawn while it does), and keeps them
|
|
78
|
+
across a script reload. An object with a material the document cannot copy
|
|
79
|
+
(one the script made itself) is left as it is, and the log says so once with
|
|
80
|
+
`tint-unsupported`.
|
|
81
|
+
|
|
82
|
+
## Autoplay
|
|
83
|
+
|
|
84
|
+
A game offers its bot; the editor decides whether it drives.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
play.autoplay(({ dt, simT, tick, keys }) => {
|
|
88
|
+
// the game's own decision, from its own state
|
|
89
|
+
return car.speed < 20 ? ['ArrowUp'] : [];
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The controller is a plain function. While autoplay is on it is called before each `update`
|
|
94
|
+
with that update's `dt`, `simT` and `tick` (the stamps that update's log entries carry) and
|
|
95
|
+
`keys`, the keys the person holds; it returns the `KeyboardEvent.code` keys the bot holds for
|
|
96
|
+
that update (any iterable, or nothing). The runner merges them into `play.keys`, so the bot
|
|
97
|
+
drives through the script's own input code exactly as a person does. One bot per script:
|
|
98
|
+
registering again replaces it, `play.autoplay(null)` withdraws it, and it goes with the script
|
|
99
|
+
on a reload or Stop. The bot is called only inside the editor's Play runner; a game run
|
|
100
|
+
anywhere else never drives itself.
|
|
101
|
+
|
|
102
|
+
Whether it drives is the editor's:
|
|
103
|
+
|
|
104
|
+
- Autoplay is **off** whenever Play starts or restarts.
|
|
105
|
+
- Only the Game panel's **Autoplay** toggle, `cyclotron play autoplay on|off` or
|
|
106
|
+
`await editor.command('volter.model-play.autoplay', { on: true })` turn it on (or off).
|
|
107
|
+
- **A bot exists only while the game runs**: `play.autoplay` is called by the play script, so
|
|
108
|
+
a stopped game (or one still starting) has none, and neither has a running script that never
|
|
109
|
+
registers one. The panel says which, in words beside the toggle — "Available once the game is
|
|
110
|
+
running" or "No autoplay — this game doesn't provide a bot" — and `on` is refused with the
|
|
111
|
+
same reason, which `play state` also gives as `autoplay.why`.
|
|
112
|
+
- **Arming.** Pressed while stopped, the panel's Autoplay arms the next start: autoplay turns
|
|
113
|
+
on (`by: 'panel'`) as soon as that run's script has run its first update with a bot, and the
|
|
114
|
+
arm is dropped if it offers none. A person's key or click in the game before then drops it
|
|
115
|
+
too (`autoplay-off` with `{ by: 'takeover', armed: true }`): the person always wins. Only an
|
|
116
|
+
explicit arm carries over; Stop, and closing the model, drop it.
|
|
117
|
+
- **The person always wins.** A new key press the game would hear, or a pointer pressed in the
|
|
118
|
+
game's area (the HUD included), turns autoplay off before that key reaches `play.keys`, and
|
|
119
|
+
the panel reads "You're driving" until someone switches the bot on again. Synthetic keys and
|
|
120
|
+
clicks (`editor.document.key`, `click`) count as a person's: they are how an agent plays by
|
|
121
|
+
hand. A key repeat is not a new press; keys typed in a text field, or while the game's surface
|
|
122
|
+
does not hold the keyboard, are not the game's and do not take over.
|
|
123
|
+
- A bot that throws turns autoplay off (`by: 'script'`, with a `script-error` of phase
|
|
124
|
+
`autoplay`), as does a reload whose script offers no bot.
|
|
125
|
+
|
|
126
|
+
Each change is a play-log entry, `autoplay-on` or `autoplay-off`, with `by`.
|
|
127
|
+
|
|
128
|
+
## Time
|
|
129
|
+
|
|
130
|
+
`update(dt)` is the only clock a play script is given, and the editor decides it:
|
|
131
|
+
|
|
132
|
+
| Control | What the script sees |
|
|
133
|
+
| --- | --- |
|
|
134
|
+
| Playing at 1× | One `update` per drawn frame, `dt` = the frame's seconds (at most 0.1). |
|
|
135
|
+
| Speed 0.25× – 4× | `dt` scaled by the speed. A scaled frame longer than 0.1 s is split into equal updates, so no single `dt` exceeds 0.1. |
|
|
136
|
+
| Pause | No `update` at all. The copy, the camera and the HUD hold the last frame. |
|
|
137
|
+
| Step (while paused) | One `update` with `dt` = 1/60. |
|
|
138
|
+
| Restart | The run begins again on a fresh detached copy, the clock at zero, without the camera's fly-in. |
|
|
139
|
+
|
|
140
|
+
A script that reads the page's own clock (`performance.now()`, `Date.now()`) instead of
|
|
141
|
+
summing `dt` is outside the reach of pause and speed.
|
|
142
|
+
|
|
143
|
+
The run's clock — simulation time (the sum of the `dt`s handed to the script) and tick (the
|
|
144
|
+
number of updates) — is kept per document beside whether it plays (`src/model-play.ts`).
|
|
145
|
+
Speed is kept for the page's life; pause and the clock reset on every Play.
|
|
146
|
+
When the run plays but no game runs — the script failed to start, or threw — the clock's
|
|
147
|
+
`failure` says why (the Game panel shows it in place of "Playing"); a save of the script
|
|
148
|
+
retries, and the next running game clears it.
|
|
149
|
+
|
|
150
|
+
## Controls
|
|
151
|
+
|
|
152
|
+
The tool registers the `model` document Play extension
|
|
153
|
+
(`@volter/editor-sdk/kit/document-play-extension`). Beside Play and Stop it offers:
|
|
154
|
+
|
|
155
|
+
- `transport` — `setPaused`, `step`, `setSpeed`, `restart`, the `clock` and its own
|
|
156
|
+
subscription, the offered `speeds`, and the restart `generation` the document keys its
|
|
157
|
+
detached copy on.
|
|
158
|
+
- `transport.autoplay(documentId)` and `transport.setAutoplay(documentId, on, by)` — the bot's
|
|
159
|
+
switch: `{ on, available, by, armed }`, announced through `subscribeClock`;
|
|
160
|
+
`transport.armAutoplay(documentId, armed)` arms it, while stopped, for the next start.
|
|
161
|
+
- `log` — `tail(documentId, last, kind?)` (the newest entries and every kind the run wrote) and
|
|
162
|
+
`subscribe`, which the Game panel draws live.
|
|
163
|
+
- `scriptPath(sourcePath)` and `hasScript(sourcePath)` — where a model's play script goes and
|
|
164
|
+
whether it exists, so a layout can open a model with a script as a game.
|
|
165
|
+
|
|
166
|
+
In Cyclotron these are drawn by the Game panel (`@volter/editor-blender`): the Game /
|
|
167
|
+
Movie switch at the left of the bottom area's header puts it there in place of the Timeline. The panel's controls
|
|
168
|
+
are also commands, `volter.model-play.<verb>`, so an agent drives the same run the person
|
|
169
|
+
sees:
|
|
170
|
+
|
|
171
|
+
| Command | Arguments |
|
|
172
|
+
| --- | --- |
|
|
173
|
+
| `volter.model-play.state` | — |
|
|
174
|
+
| `volter.model-play.play` / `stop` | — (`play` also switches the document to Game mode) |
|
|
175
|
+
| `volter.model-play.pause` / `resume` | — |
|
|
176
|
+
| `volter.model-play.step` | `{ count?: 1–600 }`, while paused |
|
|
177
|
+
| `volter.model-play.speed` | `{ speed: 0.25 \| 0.5 \| 1 \| 2 \| 4 }` |
|
|
178
|
+
| `volter.model-play.restart` | — |
|
|
179
|
+
| `volter.model-play.mode` | `{ mode?: 'game' \| 'movie' }` |
|
|
180
|
+
| `volter.model-play.autoplay` | `{ on: boolean }` — the game's bot drives, or the person does |
|
|
181
|
+
|
|
182
|
+
Each takes an optional `document` (the model document's id) and otherwise acts on the model
|
|
183
|
+
document on screen; each answers with the panel's state. From the shell:
|
|
184
|
+
`cyclotron play pause`; under `eval`:
|
|
185
|
+
`await editor.command('volter.model-play.speed', { speed: 0.5 })`.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE MODEL PLAY VERB of the session wire (`@volter/editor-sdk/commands`, a
|
|
3
|
+
* `workspace.command` contribution): `model-play-log`, the read behind
|
|
4
|
+
* `cyclotron play-log` and `editor.modelPlayLog()` in `eval`.
|
|
5
|
+
*
|
|
6
|
+
* It answers one model document's play log (`../src/play-log.ts`) — `documentId`'s, or the
|
|
7
|
+
* active Play's when omitted; the current run's, or the last one's after Stop — filtered by
|
|
8
|
+
* `since` (simulation seconds, inclusive) and `kind`. A read
|
|
9
|
+
* only: no play gate, since an empty log is the honest answer when nothing has played.
|
|
10
|
+
*/
|
|
11
|
+
import type { CommandContribution } from '@volter/editor-sdk/commands';
|
|
12
|
+
import { readModelPlayLog } from '../src/play-log';
|
|
13
|
+
|
|
14
|
+
export const point = 'workspace.command';
|
|
15
|
+
|
|
16
|
+
export const commands: CommandContribution['commands'] = {
|
|
17
|
+
'model-play-log': {
|
|
18
|
+
derivedRefresh: 'none',
|
|
19
|
+
handle: (command) => {
|
|
20
|
+
const since = command['since'];
|
|
21
|
+
const kind = command['kind'];
|
|
22
|
+
const documentId = command['documentId'];
|
|
23
|
+
if (documentId !== undefined && typeof documentId !== 'string')
|
|
24
|
+
return { ok: false, error: `model-play-log's documentId is a model document id, a string; it was given ${JSON.stringify(documentId)}.` };
|
|
25
|
+
if (since !== undefined && (typeof since !== 'number' || !Number.isFinite(since)))
|
|
26
|
+
return { ok: false, error: `model-play-log's since is simulation seconds, a number; it was given ${JSON.stringify(since)}.` };
|
|
27
|
+
if (kind !== undefined && typeof kind !== 'string')
|
|
28
|
+
return { ok: false, error: `model-play-log's kind is an entry kind, a string; it was given ${JSON.stringify(kind)}.` };
|
|
29
|
+
const reading = readModelPlayLog({
|
|
30
|
+
...(documentId === undefined ? {} : { documentId }),
|
|
31
|
+
...(since === undefined ? {} : { since }),
|
|
32
|
+
...(kind === undefined ? {} : { kind }),
|
|
33
|
+
});
|
|
34
|
+
return { ok: true, data: { ...reading } };
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
/** Model script tool, available to every product through project packages. */
|
|
2
2
|
import { useSyncExternalStore } from 'react';
|
|
3
3
|
import { Button, EditorIcon, editorIcons, MenuItem } from '@volter/editor-sdk/widgets';
|
|
4
|
+
import { editorHost } from '@volter/editor-sdk/host';
|
|
4
5
|
import { registerDocumentPlayExtension, type DocumentPlayControlProps } from '@volter/editor-sdk/kit/document-play-extension';
|
|
5
|
-
import {
|
|
6
|
-
|
|
6
|
+
import {
|
|
7
|
+
armModelPlayAutoplay,
|
|
8
|
+
escapeModelPlay,
|
|
9
|
+
MODEL_PLAY_SPEEDS,
|
|
10
|
+
modelPlayAutoplay,
|
|
11
|
+
modelPlayClock,
|
|
12
|
+
modelPlayGeneration,
|
|
13
|
+
modelPlaying,
|
|
14
|
+
restartModelPlay,
|
|
15
|
+
setModelPlayAutoplay,
|
|
16
|
+
setModelPlayFailure,
|
|
17
|
+
setModelPlayPaused,
|
|
18
|
+
setModelPlaying,
|
|
19
|
+
setModelPlaySpeed,
|
|
20
|
+
stepModelPlay,
|
|
21
|
+
subscribeModelPlay,
|
|
22
|
+
subscribeModelPlayClock,
|
|
23
|
+
} from '../src/model-play';
|
|
24
|
+
import { playScriptPath, runPlayScript } from '../src/play-script';
|
|
25
|
+
import { beginModelPlayLog, subscribeModelPlayLog, tailModelPlayLog } from '../src/play-log';
|
|
7
26
|
import type * as THREE from 'three';
|
|
8
27
|
import { getCurrentProject, onProjectChange } from '@volter/editor-sdk/kit/active-project';
|
|
9
28
|
|
|
@@ -11,6 +30,7 @@ export const point = 'workspace.service';
|
|
|
11
30
|
function usePlaying(documentId: string | undefined): boolean {
|
|
12
31
|
return useSyncExternalStore(subscribeModelPlay, () => documentId ? modelPlaying(documentId) : false, () => false);
|
|
13
32
|
}
|
|
33
|
+
// Kept because `DocumentPlayExtension` requires `Control` and `Menu` for a layout that draws Play in its header; Cyclotron's layout no longer does (its Play is the Game panel's).
|
|
14
34
|
function Control({ documentId, onClose }: DocumentPlayControlProps) {
|
|
15
35
|
const playing = usePlaying(documentId);
|
|
16
36
|
return <Button size="compact" data-testid="model-play-button" aria-pressed={playing}
|
|
@@ -27,12 +47,64 @@ function Menu({ documentId, onClose }: DocumentPlayControlProps) {
|
|
|
27
47
|
{playing ? 'Stop' : 'Play'}
|
|
28
48
|
</MenuItem>;
|
|
29
49
|
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* WHETHER A MODEL HAS A PLAY SCRIPT — `src/models/track.blend` has one when
|
|
53
|
+
* `src/models/track.play.ts` exists (`playScriptPath`), the same file Play imports. Asked once
|
|
54
|
+
* per path through the project's files door and then kept, corrected by that door's change
|
|
55
|
+
* events, so a layout can open a model with a script as a game and one without as a model. A
|
|
56
|
+
* project switch forgets every answer.
|
|
57
|
+
*/
|
|
58
|
+
const scripts = new Map<string, boolean>();
|
|
59
|
+
const looking = new Set<string>();
|
|
60
|
+
const scriptListeners = new Set<() => void>();
|
|
61
|
+
function publishScripts(): void {
|
|
62
|
+
for (const listener of [...scriptListeners]) listener();
|
|
63
|
+
}
|
|
64
|
+
function projectPath(path: string): string {
|
|
65
|
+
return path.replaceAll('\\', '/').replace(/^\.\//, '');
|
|
66
|
+
}
|
|
67
|
+
function hasScript(sourcePath: string): boolean | null {
|
|
68
|
+
const path = projectPath(playScriptPath(sourcePath));
|
|
69
|
+
const known = scripts.get(path);
|
|
70
|
+
if (known !== undefined) return known;
|
|
71
|
+
if (!looking.has(path)) {
|
|
72
|
+
looking.add(path);
|
|
73
|
+
const project = getCurrentProject()?.rootPath;
|
|
74
|
+
void editorHost().files.exists(path).then(exists => exists, () => false).then(exists => {
|
|
75
|
+
looking.delete(path);
|
|
76
|
+
// An answer about the previous project is no answer about this one.
|
|
77
|
+
if (getCurrentProject()?.rootPath !== project) return;
|
|
78
|
+
scripts.set(path, exists);
|
|
79
|
+
publishScripts();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
30
85
|
export function start(): () => void {
|
|
86
|
+
const stopWatching = (() => {
|
|
87
|
+
try {
|
|
88
|
+
return editorHost().files.watch((event) => {
|
|
89
|
+
const path = projectPath(event.path);
|
|
90
|
+
if (!scripts.has(path) && !path.endsWith('.play.ts')) return;
|
|
91
|
+
const exists = event.type !== 'remove';
|
|
92
|
+
if (scripts.get(path) === exists) return;
|
|
93
|
+
scripts.set(path, exists);
|
|
94
|
+
publishScripts();
|
|
95
|
+
});
|
|
96
|
+
} catch {
|
|
97
|
+
// A host without a files door still plays; the answer is then read once per path.
|
|
98
|
+
return () => {};
|
|
99
|
+
}
|
|
100
|
+
})();
|
|
101
|
+
const stopProject = onProjectChange(() => { scripts.clear(); publishScripts(); });
|
|
31
102
|
const unregister = registerDocumentPlayExtension('model', {
|
|
32
103
|
Control, Menu, playing: modelPlaying, setPlaying: setModelPlaying, escape: escapeModelPlay,
|
|
33
104
|
subscribe(listener) {
|
|
34
105
|
const stopPlay = subscribeModelPlay(listener), stopProject = onProjectChange(listener);
|
|
35
|
-
|
|
106
|
+
scriptListeners.add(listener);
|
|
107
|
+
return () => { stopPlay(); stopProject(); scriptListeners.delete(listener); };
|
|
36
108
|
},
|
|
37
109
|
aspectRatio() {
|
|
38
110
|
const size = getCurrentProject()?.config.resolution;
|
|
@@ -42,8 +114,39 @@ export function start(): () => void {
|
|
|
42
114
|
run(stage) {
|
|
43
115
|
// The document kind lends native scene objects; this tool owns their Three types.
|
|
44
116
|
return runPlayScript({ ...stage, blend: stage.sourcePath, root: stage.root as THREE.Object3D,
|
|
45
|
-
camera: stage.camera as () => THREE.Camera, editingCamera: stage.editingCamera as () => THREE.Camera
|
|
117
|
+
camera: stage.camera as () => THREE.Camera, editingCamera: stage.editingCamera as () => THREE.Camera,
|
|
118
|
+
ownMaterial: stage.ownMaterial as ((material: THREE.Material) => THREE.Material | null) | undefined });
|
|
119
|
+
},
|
|
120
|
+
// THE RUN'S TRANSPORT (`model-play.ts`): the runner reads all of it each frame.
|
|
121
|
+
transport: {
|
|
122
|
+
speeds: MODEL_PLAY_SPEEDS,
|
|
123
|
+
clock: modelPlayClock,
|
|
124
|
+
subscribeClock: subscribeModelPlayClock,
|
|
125
|
+
setPaused: setModelPlayPaused,
|
|
126
|
+
step: stepModelPlay,
|
|
127
|
+
setSpeed: setModelPlaySpeed,
|
|
128
|
+
restart: restartModelPlay,
|
|
129
|
+
generation: modelPlayGeneration,
|
|
130
|
+
autoplay: modelPlayAutoplay,
|
|
131
|
+
setAutoplay: setModelPlayAutoplay,
|
|
132
|
+
armAutoplay: armModelPlayAutoplay,
|
|
133
|
+
// NO STAGE, SO NO RUNNER, and until 2026-10-06 the document turned Play off and wrote the
|
|
134
|
+
// reason to the console: Play flicked on and off with nothing said where anyone looks.
|
|
135
|
+
// Now the run stands with its failure — the Game panel draws it, the log records it.
|
|
136
|
+
fail(documentId, sourcePath, failure) {
|
|
137
|
+
const run = beginModelPlayLog(documentId, playScriptPath(sourcePath));
|
|
138
|
+
run.append('play', 'script-error', { phase: 'stage', message: failure });
|
|
139
|
+
run.end({ reason: 'stage-failed' });
|
|
140
|
+
setModelPlayFailure(documentId, failure);
|
|
141
|
+
},
|
|
46
142
|
},
|
|
143
|
+
log: { tail: tailModelPlayLog, subscribe: subscribeModelPlayLog },
|
|
144
|
+
scriptPath: playScriptPath,
|
|
145
|
+
hasScript,
|
|
47
146
|
});
|
|
48
|
-
return
|
|
147
|
+
return () => {
|
|
148
|
+
unregister();
|
|
149
|
+
stopProject();
|
|
150
|
+
stopWatching();
|
|
151
|
+
};
|
|
49
152
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/editor-model-play",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.191",
|
|
4
4
|
"author": "Volter AI, Inc.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
|
@@ -23,11 +23,12 @@
|
|
|
23
23
|
},
|
|
24
24
|
"volter": {
|
|
25
25
|
"contributions": [
|
|
26
|
+
"./contributions/model-play.command.ts",
|
|
26
27
|
"./contributions/model-play.service.tsx"
|
|
27
28
|
]
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@volter/editor-sdk": "0.5.
|
|
31
|
+
"@volter/editor-sdk": "0.5.191"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
34
|
"react": "^19.0.0",
|
package/src/camera-transition.ts
CHANGED
|
@@ -14,10 +14,14 @@ type Pose = ReturnType<typeof pose>;
|
|
|
14
14
|
/** The tool blends AFTER the script has stated its complete camera pose.
|
|
15
15
|
* Projection matrices also interpolate, preserving an orthographic editing
|
|
16
16
|
* view exactly at the handoff to a perspective game. Neither editing camera
|
|
17
|
-
* nor its orbit target is ever written.
|
|
18
|
-
|
|
17
|
+
* nor its orbit target is ever written.
|
|
18
|
+
*
|
|
19
|
+
* `instant` enters already arrived: a Restart replaces a game that was on screen a frame ago,
|
|
20
|
+
* and flying in again from the editing pose would show the model between two games. The return
|
|
21
|
+
* on Stop still blends. */
|
|
22
|
+
export function cameraTransition(editingCamera: THREE.Camera, options?: { readonly instant?: boolean }) {
|
|
19
23
|
const editing = pose(editingCamera);
|
|
20
|
-
let phase: 'entering' | 'playing' | 'leaving' = 'entering';
|
|
24
|
+
let phase: 'entering' | 'playing' | 'leaving' = options?.instant ? 'playing' : 'entering';
|
|
21
25
|
let elapsed = 0;
|
|
22
26
|
let last = editing;
|
|
23
27
|
let leavingFrom = editing;
|
|
@@ -52,6 +56,12 @@ export function cameraTransition(editingCamera: THREE.Camera) {
|
|
|
52
56
|
? Math.min(1, elapsed / duration)
|
|
53
57
|
: Math.max(0, 1 - elapsed / (duration - 0.16)),
|
|
54
58
|
approachingEdit: () => phase === 'leaving' && elapsed >= duration - 0.16,
|
|
59
|
+
/** A PAUSED frame: put the camera back where the last drawn frame had it. Nothing else
|
|
60
|
+
* states the pose while the game's update is held, and the stage's navigation runs before
|
|
61
|
+
* this hook each frame; the blend's own clock stands still with the game's. */
|
|
62
|
+
hold(camera: THREE.Camera): void {
|
|
63
|
+
blend(camera, last, last, 1);
|
|
64
|
+
},
|
|
55
65
|
/** Escape completes an existing blend; otherwise begin the return. */
|
|
56
66
|
stop(escape: boolean): boolean {
|
|
57
67
|
if (escape && phase === 'entering') { phase = 'playing'; return false; }
|