@volter/play 0.0.0-stage → 0.5.204
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/LICENSE +202 -0
- package/NOTICE +12 -0
- package/README.md +184 -2
- package/contributions/model-play.command.ts +37 -0
- package/contributions/model-play.service.tsx +152 -0
- package/package.json +39 -4
- package/src/camera-transition.ts +87 -0
- package/src/model-play.ts +376 -0
- package/src/play-log.ts +233 -0
- package/src/play-materials.ts +199 -0
- package/src/play-script.ts +841 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Volter AI, Inc.
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Copyright 2026 Volter AI, Inc.
|
|
2
|
+
|
|
3
|
+
This package is developed in the public volter-ai/editor repository and is
|
|
4
|
+
Volter AI, Inc.'s own work. It was first published under AGPL-3.0-only and is
|
|
5
|
+
licensed under Apache-2.0 from this notice on. The owner's words are "the
|
|
6
|
+
runtime should be apache, the editor is agpl"; that this package is runtime
|
|
7
|
+
(the play-script API a game's gameplay is written against) is the reading
|
|
8
|
+
recorded as ruling D336 on board task t_b315eb39 and in COMMERCIAL.md at the
|
|
9
|
+
repository root. LICENSE contains the Apache-2.0 text.
|
|
10
|
+
|
|
11
|
+
A play script is written against `src/play-script.ts`. The package imports
|
|
12
|
+
`@volter/sdk` (Apache-2.0), three and React, and nothing of Blender.
|
package/README.md
CHANGED
|
@@ -1,3 +1,185 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Play
|
|
2
2
|
|
|
3
|
-
|
|
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/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/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
|
+
Animation 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' \| 'animation' }` |
|
|
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/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/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
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/** Model script tool, available to every product through project packages. */
|
|
2
|
+
import { useSyncExternalStore } from 'react';
|
|
3
|
+
import { Button, EditorIcon, editorIcons, MenuItem } from '@volter/sdk/widgets';
|
|
4
|
+
import { editorHost } from '@volter/sdk/host';
|
|
5
|
+
import { registerDocumentPlayExtension, type DocumentPlayControlProps } from '@volter/sdk/kit/document-play-extension';
|
|
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';
|
|
26
|
+
import type * as THREE from 'three';
|
|
27
|
+
import { getCurrentProject, onProjectChange } from '@volter/sdk/kit/active-project';
|
|
28
|
+
|
|
29
|
+
export const point = 'workspace.service';
|
|
30
|
+
function usePlaying(documentId: string | undefined): boolean {
|
|
31
|
+
return useSyncExternalStore(subscribeModelPlay, () => documentId ? modelPlaying(documentId) : false, () => false);
|
|
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).
|
|
34
|
+
function Control({ documentId, onClose }: DocumentPlayControlProps) {
|
|
35
|
+
const playing = usePlaying(documentId);
|
|
36
|
+
return <Button size="compact" data-testid="model-play-button" aria-pressed={playing}
|
|
37
|
+
disabled={!documentId} title={playing ? 'Stop playing (Escape)' : 'Play this model’s script'}
|
|
38
|
+
onClick={() => { onClose(); if (documentId) setModelPlaying(documentId, !playing); }}>
|
|
39
|
+
<EditorIcon icon={playing ? editorIcons.transport.stop : editorIcons.transport.play} />
|
|
40
|
+
{playing ? 'Stop' : 'Play'}
|
|
41
|
+
</Button>;
|
|
42
|
+
}
|
|
43
|
+
function Menu({ documentId, onClose }: DocumentPlayControlProps) {
|
|
44
|
+
const playing = usePlaying(documentId);
|
|
45
|
+
return <MenuItem data-testid="model-play" disabled={!documentId}
|
|
46
|
+
onSelect={() => { onClose(); if (documentId) setModelPlaying(documentId, !playing); }}>
|
|
47
|
+
{playing ? 'Stop' : 'Play'}
|
|
48
|
+
</MenuItem>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* WHETHER A MODEL HAS A PLAY SCRIPT — `src/models/canyon.blend` has one when
|
|
53
|
+
* `src/models/canyon.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
|
+
|
|
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(); });
|
|
102
|
+
const unregister = registerDocumentPlayExtension('model', {
|
|
103
|
+
Control, Menu, playing: modelPlaying, setPlaying: setModelPlaying, escape: escapeModelPlay,
|
|
104
|
+
subscribe(listener) {
|
|
105
|
+
const stopPlay = subscribeModelPlay(listener), stopProject = onProjectChange(listener);
|
|
106
|
+
scriptListeners.add(listener);
|
|
107
|
+
return () => { stopPlay(); stopProject(); scriptListeners.delete(listener); };
|
|
108
|
+
},
|
|
109
|
+
aspectRatio() {
|
|
110
|
+
const size = getCurrentProject()?.config.resolution;
|
|
111
|
+
const ratio = size ? size.width / size.height : null;
|
|
112
|
+
return ratio !== null && Number.isFinite(ratio) && ratio > 0 ? ratio : null;
|
|
113
|
+
},
|
|
114
|
+
run(stage) {
|
|
115
|
+
// The document kind lends native scene objects; this tool owns their Three types.
|
|
116
|
+
return runPlayScript({ ...stage, blend: stage.sourcePath, root: stage.root as THREE.Object3D,
|
|
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
|
+
},
|
|
142
|
+
},
|
|
143
|
+
log: { tail: tailModelPlayLog, subscribe: subscribeModelPlayLog },
|
|
144
|
+
scriptPath: playScriptPath,
|
|
145
|
+
hasScript,
|
|
146
|
+
});
|
|
147
|
+
return () => {
|
|
148
|
+
unregister();
|
|
149
|
+
stopProject();
|
|
150
|
+
stopWatching();
|
|
151
|
+
};
|
|
152
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/play",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.204",
|
|
4
|
+
"author": "Volter AI, Inc.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"description": "Play scripts on detached model documents.",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/volter-ai/editor.git",
|
|
11
|
+
"directory": "packages/play"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"contributions",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"NOTICE"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
"./contributions/*": "./contributions/*",
|
|
21
|
+
"./package.json": "./package.json",
|
|
22
|
+
"./play-script": "./src/play-script.ts"
|
|
23
|
+
},
|
|
24
|
+
"volter": {
|
|
25
|
+
"contributions": [
|
|
26
|
+
"./contributions/model-play.command.ts",
|
|
27
|
+
"./contributions/model-play.service.tsx"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@volter/sdk": "0.5.204"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": "^19.0.0",
|
|
35
|
+
"react-dom": "^19.0.0",
|
|
36
|
+
"three": "^0.180.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
}
|
|
41
|
+
}
|