babylon.quarks-editor 0.27.0 → 0.28.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 +71 -0
- package/README.md +31 -4
- package/dist/core/assetTree.d.ts +5 -0
- package/dist/core/assets.d.ts +7 -0
- package/dist/core/assets.js +11 -7
- package/dist/core/binding.d.ts +9 -0
- package/dist/core/binding.js +8 -0
- package/dist/core/collision.d.ts +4 -0
- package/dist/core/collision.js +4 -0
- package/dist/core/colors.d.ts +16 -0
- package/dist/core/colors.js +8 -0
- package/dist/core/defaultEffect.d.ts +3 -2
- package/dist/core/defaultEffect.js +1 -1
- package/dist/core/editorSession.d.ts +229 -0
- package/dist/core/editorSession.js +983 -0
- package/dist/core/effectTree.d.ts +5 -0
- package/dist/core/galleryPlayback.js +2 -1
- package/dist/core/history.d.ts +6 -0
- package/dist/core/history.js +4 -0
- package/dist/core/indexedDbProjectStore.d.ts +13 -0
- package/dist/core/indexedDbProjectStore.js +13 -0
- package/dist/core/material.d.ts +12 -2
- package/dist/core/playback.d.ts +6 -0
- package/dist/core/projectStore.d.ts +26 -0
- package/dist/core/projectStore.js +1 -0
- package/dist/core/sceneEntries.d.ts +3 -0
- package/dist/core/scrub.d.ts +1 -1
- package/dist/core/scrub.js +2 -2
- package/dist/core/shapes.d.ts +24 -0
- package/dist/core/shapes.js +5 -0
- package/dist/core/systems.d.ts +2 -0
- package/dist/core/systems.js +3 -1
- package/dist/core/timeline.d.ts +23 -3
- package/dist/core/values.d.ts +21 -4
- package/dist/core/values.js +5 -0
- package/dist/index.d.ts +5 -1
- package/dist/react/AssetsPanel.d.ts +7 -0
- package/dist/react/ChoiceDialog.d.ts +7 -0
- package/dist/react/ContextMenu.d.ts +10 -1
- package/dist/react/EditorWorkspace.d.ts +7 -0
- package/dist/react/EditorWorkspace.js +6 -3
- package/dist/react/EffectEditor.d.ts +8 -2
- package/dist/react/EffectEditorHost.d.ts +32 -28
- package/dist/react/EffectEditorHost.js +241 -1665
- package/dist/react/EffectTreeView.d.ts +3 -0
- package/dist/react/MessageDialog.d.ts +5 -0
- package/dist/react/ModuleSection.d.ts +10 -0
- package/dist/react/ModuleSection.js +4 -1
- package/dist/react/ProjectsPage.d.ts +6 -0
- package/dist/react/ProjectsPage.js +27 -11
- package/dist/react/PromptDialog.d.ts +7 -0
- package/dist/react/ScenePanel.d.ts +7 -0
- package/dist/react/ScenePanel.js +7 -5
- package/dist/react/TextureSelect.d.ts +5 -5
- package/dist/react/TimelinePanel.d.ts +13 -0
- package/dist/react/TimelinePanel.js +10 -6
- package/dist/react/TimelineTrackRow.d.ts +10 -0
- package/dist/react/TransportBar.d.ts +9 -0
- package/dist/react/ValueField.d.ts +32 -5
- package/dist/react/ValueField.js +20 -9
- package/dist/react/behaviorModules.d.ts +16 -5
- package/dist/react/behaviorModules.js +16 -1
- package/dist/react/fields.d.ts +8 -0
- package/dist/react/fields.js +3 -0
- package/dist/react/host/BottomDocks.d.ts +36 -0
- package/dist/react/host/BottomDocks.js +63 -0
- package/dist/react/host/HostDialogs.d.ts +50 -0
- package/dist/react/host/HostDialogs.js +113 -0
- package/dist/react/host/InspectorSidebar.d.ts +32 -0
- package/dist/react/host/InspectorSidebar.js +59 -0
- package/dist/react/host/SceneSidebar.d.ts +53 -0
- package/dist/react/host/SceneSidebar.js +62 -0
- package/dist/react/host/ViewportPane.d.ts +56 -0
- package/dist/react/host/ViewportPane.js +91 -0
- package/dist/react/host/hostHooks.d.ts +44 -0
- package/dist/react/host/hostHooks.js +164 -0
- package/dist/react/host/hostStyles.d.ts +21 -0
- package/dist/react/host/hostStyles.js +57 -0
- package/dist/react/index.d.ts +3 -1
- package/dist/react/modules.d.ts +17 -6
- package/dist/react/modules.js +38 -20
- package/dist/react/theme.d.ts +15 -0
- package/dist/react/theme.js +15 -0
- package/dist/session.d.ts +9 -0
- package/dist/session.js +8 -0
- package/package.json +17 -11
- package/src/core/assetTree.ts +14 -1
- package/src/core/assets.ts +25 -10
- package/src/core/binding.ts +9 -0
- package/src/core/collision.ts +4 -0
- package/src/core/colors.ts +21 -1
- package/src/core/defaultEffect.ts +4 -3
- package/src/core/editorSession.ts +1299 -0
- package/src/core/effectTree.ts +5 -0
- package/src/core/galleryPlayback.ts +2 -1
- package/src/core/history.ts +6 -0
- package/src/core/indexedDbProjectStore.ts +13 -0
- package/src/core/loadEffect.ts +1 -1
- package/src/core/material.ts +14 -4
- package/src/core/playback.ts +6 -0
- package/src/core/projectStore.ts +26 -0
- package/src/core/sceneEntries.ts +3 -0
- package/src/core/scrub.ts +2 -2
- package/src/core/shapes.ts +28 -1
- package/src/core/systems.ts +9 -2
- package/src/core/timeline.ts +40 -15
- package/src/core/values.ts +20 -4
- package/src/index.ts +5 -1
- package/src/react/AssetsPanel.tsx +7 -0
- package/src/react/ChoiceDialog.tsx +7 -0
- package/src/react/ContextMenu.tsx +10 -1
- package/src/react/EditorWorkspace.tsx +11 -5
- package/src/react/EffectEditor.tsx +7 -1
- package/src/react/EffectEditorHost.tsx +406 -2340
- package/src/react/EffectTreeView.tsx +3 -0
- package/src/react/MessageDialog.tsx +5 -0
- package/src/react/ModuleSection.tsx +11 -0
- package/src/react/ProjectsPage.tsx +38 -11
- package/src/react/PromptDialog.tsx +7 -0
- package/src/react/ScenePanel.tsx +14 -5
- package/src/react/TextureSelect.tsx +6 -6
- package/src/react/TimelinePanel.tsx +23 -6
- package/src/react/TimelineTrackRow.tsx +10 -0
- package/src/react/TransportBar.tsx +9 -0
- package/src/react/ValueField.tsx +58 -14
- package/src/react/behaviorModules.tsx +34 -32
- package/src/react/fields.tsx +12 -1
- package/src/react/host/BottomDocks.tsx +178 -0
- package/src/react/host/HostDialogs.tsx +228 -0
- package/src/react/host/InspectorSidebar.tsx +147 -0
- package/src/react/host/SceneSidebar.tsx +227 -0
- package/src/react/host/ViewportPane.tsx +300 -0
- package/src/react/host/hostHooks.ts +198 -0
- package/src/react/host/hostStyles.ts +65 -0
- package/src/react/index.ts +3 -1
- package/src/react/modules.tsx +70 -44
- package/src/react/theme.ts +15 -0
- package/src/session.ts +17 -0
package/src/core/effectTree.ts
CHANGED
|
@@ -4,12 +4,17 @@ import {ParticleEmitter, serializeEffect} from 'babylon.quarks';
|
|
|
4
4
|
import {isEditorSceneNode} from './editorScene.js';
|
|
5
5
|
|
|
6
6
|
/** A node in the editor's effect hierarchy: a Group (organizational) or a ParticleEmitter. */
|
|
7
|
+
/** One node of an effect's tree: a group, or an emitter with its system. */
|
|
7
8
|
export interface EffectTreeNode {
|
|
9
|
+
/** The node. */
|
|
8
10
|
node: TransformNode;
|
|
11
|
+
/** The node's name, or a readable stand-in when it has none. */
|
|
9
12
|
name: string;
|
|
10
13
|
/** Present when the node is a ParticleEmitter. */
|
|
11
14
|
system?: ParticleSystem;
|
|
15
|
+
/** How deep the node sits; the root is 0. */
|
|
12
16
|
depth: number;
|
|
17
|
+
/** The node's child groups and emitters. */
|
|
13
18
|
children: EffectTreeNode[];
|
|
14
19
|
}
|
|
15
20
|
|
package/src/core/history.ts
CHANGED
|
@@ -5,7 +5,9 @@ const MAX_DEPTH = 50;
|
|
|
5
5
|
|
|
6
6
|
/** Undo/redo stacks of one effect, kept by the host while another effect is focused. */
|
|
7
7
|
export interface HistoryStacks {
|
|
8
|
+
/** Snapshots to undo to, oldest first. */
|
|
8
9
|
undo: string[];
|
|
10
|
+
/** Snapshots to redo to, most recent undo last. */
|
|
9
11
|
redo: string[];
|
|
10
12
|
}
|
|
11
13
|
|
|
@@ -28,14 +30,17 @@ export class EffectHistory {
|
|
|
28
30
|
binding.onBeforeChange = () => this.capture();
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
/** There is a change to undo. */
|
|
31
34
|
get canUndo(): boolean {
|
|
32
35
|
return this.undoStack.length > 0;
|
|
33
36
|
}
|
|
34
37
|
|
|
38
|
+
/** There is an undone change to redo. */
|
|
35
39
|
get canRedo(): boolean {
|
|
36
40
|
return this.redoStack.length > 0;
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
/** Forgets every snapshot. */
|
|
39
44
|
clear(): void {
|
|
40
45
|
this.undoStack = [];
|
|
41
46
|
this.redoStack = [];
|
|
@@ -47,6 +52,7 @@ export class EffectHistory {
|
|
|
47
52
|
return {undo: this.undoStack, redo: this.redoStack};
|
|
48
53
|
}
|
|
49
54
|
|
|
55
|
+
/** Puts back stacks from `saveStacks`; undefined starts empty. */
|
|
50
56
|
restoreStacks(stacks: HistoryStacks | undefined): void {
|
|
51
57
|
this.undoStack = stacks?.undo ?? [];
|
|
52
58
|
this.redoStack = stacks?.redo ?? [];
|
|
@@ -119,12 +119,14 @@ export class IndexedDbProjectStore implements ProjectStore {
|
|
|
119
119
|
|
|
120
120
|
// ---- projects -------------------------------------------------------------------------
|
|
121
121
|
|
|
122
|
+
/** {@inheritDoc ProjectStore.listProjects} */
|
|
122
123
|
async listProjects(): Promise<ProjectMeta[]> {
|
|
123
124
|
const db = await this.db();
|
|
124
125
|
const all = await request<ProjectMeta[]>(db.transaction('projects').objectStore('projects').getAll());
|
|
125
126
|
return all.sort((a, b) => b.updatedAt - a.updatedAt);
|
|
126
127
|
}
|
|
127
128
|
|
|
129
|
+
/** {@inheritDoc ProjectStore.getProject} */
|
|
128
130
|
async getProject(id: string): Promise<ProjectMeta | null> {
|
|
129
131
|
const db = await this.db();
|
|
130
132
|
return (
|
|
@@ -132,6 +134,7 @@ export class IndexedDbProjectStore implements ProjectStore {
|
|
|
132
134
|
);
|
|
133
135
|
}
|
|
134
136
|
|
|
137
|
+
/** {@inheritDoc ProjectStore.createProject} */
|
|
135
138
|
async createProject(name: string): Promise<ProjectMeta> {
|
|
136
139
|
const now = Date.now();
|
|
137
140
|
const meta: ProjectMeta = {id: newId(), name, createdAt: now, updatedAt: now, assetCount: 0, sizeBytes: 0};
|
|
@@ -142,6 +145,7 @@ export class IndexedDbProjectStore implements ProjectStore {
|
|
|
142
145
|
return meta;
|
|
143
146
|
}
|
|
144
147
|
|
|
148
|
+
/** {@inheritDoc ProjectStore.renameProject} */
|
|
145
149
|
async renameProject(id: string, name: string): Promise<void> {
|
|
146
150
|
const meta = await this.getProject(id);
|
|
147
151
|
if (!meta) return;
|
|
@@ -151,6 +155,7 @@ export class IndexedDbProjectStore implements ProjectStore {
|
|
|
151
155
|
await done(tx);
|
|
152
156
|
}
|
|
153
157
|
|
|
158
|
+
/** {@inheritDoc ProjectStore.duplicateProject} */
|
|
154
159
|
async duplicateProject(id: string, name: string): Promise<ProjectMeta> {
|
|
155
160
|
const source = await this.getProject(id);
|
|
156
161
|
if (!source) throw new Error('Project not found.');
|
|
@@ -172,6 +177,7 @@ export class IndexedDbProjectStore implements ProjectStore {
|
|
|
172
177
|
return meta;
|
|
173
178
|
}
|
|
174
179
|
|
|
180
|
+
/** {@inheritDoc ProjectStore.deleteProject} */
|
|
175
181
|
async deleteProject(id: string): Promise<void> {
|
|
176
182
|
const db = await this.db();
|
|
177
183
|
const tx = db.transaction(['projects', 'assets', 'files', 'scenes'], 'readwrite');
|
|
@@ -189,6 +195,7 @@ export class IndexedDbProjectStore implements ProjectStore {
|
|
|
189
195
|
|
|
190
196
|
// ---- assets ---------------------------------------------------------------------------
|
|
191
197
|
|
|
198
|
+
/** {@inheritDoc ProjectStore.loadAssets} */
|
|
192
199
|
async loadAssets(projectId: string): Promise<StoredAsset[]> {
|
|
193
200
|
const db = await this.db();
|
|
194
201
|
const records = await request<AssetRecord[]>(
|
|
@@ -204,6 +211,7 @@ export class IndexedDbProjectStore implements ProjectStore {
|
|
|
204
211
|
);
|
|
205
212
|
}
|
|
206
213
|
|
|
214
|
+
/** {@inheritDoc ProjectStore.putAssets} */
|
|
207
215
|
async putAssets(projectId: string, assets: StoredAsset[]): Promise<void> {
|
|
208
216
|
const files = new Map<string, Blob>();
|
|
209
217
|
const packed = await Promise.all(
|
|
@@ -217,6 +225,7 @@ export class IndexedDbProjectStore implements ProjectStore {
|
|
|
217
225
|
await this.refresh(projectId);
|
|
218
226
|
}
|
|
219
227
|
|
|
228
|
+
/** {@inheritDoc ProjectStore.deleteAssets} */
|
|
220
229
|
async deleteAssets(projectId: string, paths: string[]): Promise<void> {
|
|
221
230
|
const db = await this.db();
|
|
222
231
|
const tx = db.transaction('assets', 'readwrite');
|
|
@@ -227,6 +236,7 @@ export class IndexedDbProjectStore implements ProjectStore {
|
|
|
227
236
|
|
|
228
237
|
// ---- scene ----------------------------------------------------------------------------
|
|
229
238
|
|
|
239
|
+
/** {@inheritDoc ProjectStore.loadScene} */
|
|
230
240
|
async loadScene(projectId: string): Promise<StoredScene | null> {
|
|
231
241
|
const db = await this.db();
|
|
232
242
|
const record = await request<SceneRecord | undefined>(
|
|
@@ -239,6 +249,7 @@ export class IndexedDbProjectStore implements ProjectStore {
|
|
|
239
249
|
return {entries, savedAt: record.savedAt};
|
|
240
250
|
}
|
|
241
251
|
|
|
252
|
+
/** {@inheritDoc ProjectStore.saveScene} */
|
|
242
253
|
async saveScene(projectId: string, scene: StoredScene): Promise<void> {
|
|
243
254
|
const files = new Map<string, Blob>();
|
|
244
255
|
const entries: StoredSceneEntry[] = await Promise.all(
|
|
@@ -254,6 +265,7 @@ export class IndexedDbProjectStore implements ProjectStore {
|
|
|
254
265
|
|
|
255
266
|
// ---- storage ----------------------------------------------------------------------------
|
|
256
267
|
|
|
268
|
+
/** {@inheritDoc ProjectStore.estimate} */
|
|
257
269
|
async estimate(): Promise<StorageEstimate> {
|
|
258
270
|
const storage = typeof navigator !== 'undefined' ? navigator.storage : undefined;
|
|
259
271
|
const estimate = storage?.estimate ? await storage.estimate() : undefined;
|
|
@@ -261,6 +273,7 @@ export class IndexedDbProjectStore implements ProjectStore {
|
|
|
261
273
|
return {usage: estimate?.usage ?? null, quota: estimate?.quota ?? null, persisted};
|
|
262
274
|
}
|
|
263
275
|
|
|
276
|
+
/** {@inheritDoc ProjectStore.requestPersistence} */
|
|
264
277
|
async requestPersistence(): Promise<boolean> {
|
|
265
278
|
const storage = typeof navigator !== 'undefined' ? navigator.storage : undefined;
|
|
266
279
|
return storage?.persist ? storage.persist() : false;
|
package/src/core/loadEffect.ts
CHANGED
|
@@ -103,7 +103,7 @@ export function parseEffectFromJson(
|
|
|
103
103
|
const autoplay = options.autoplay ?? registerRenderer;
|
|
104
104
|
|
|
105
105
|
const loader = new QuarksLoader(scene, {baseUrl});
|
|
106
|
-
let root = loader.parse(json
|
|
106
|
+
let root = loader.parse(json, baseUrl);
|
|
107
107
|
flattenRedundantGroups(root);
|
|
108
108
|
root = promoteIfSingleChildRoot(root);
|
|
109
109
|
|
package/src/core/material.ts
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
import type {BaseTexture} from '@babylonjs/core/Materials/Textures/baseTexture.js';
|
|
2
|
+
import type {Texture} from '@babylonjs/core/Materials/Textures/texture.js';
|
|
1
3
|
import type {ParticleSystem} from 'babylon.quarks';
|
|
2
4
|
|
|
5
|
+
/** Material settings the Renderer module changes; fields left out keep their value. */
|
|
3
6
|
export interface RendererMaterialPatch {
|
|
7
|
+
/** The blend mode, see `ParticleSystem.blending`. */
|
|
4
8
|
blendMode?: number;
|
|
9
|
+
/** Draws with alpha blending. */
|
|
5
10
|
transparent?: boolean;
|
|
11
|
+
/** Tests against the depth buffer. */
|
|
6
12
|
depthTest?: boolean;
|
|
13
|
+
/** Writes to the depth buffer. */
|
|
7
14
|
depthWrite?: boolean;
|
|
15
|
+
/** Discards pixels whose alpha is below this. */
|
|
8
16
|
alphaTest?: number;
|
|
9
|
-
texture
|
|
17
|
+
/** The main texture, or null for none. */
|
|
18
|
+
texture?: Texture | null;
|
|
10
19
|
/** A 3×2 cube-face atlas mesh particles reflect, or null for none. */
|
|
11
|
-
reflectionAtlas?:
|
|
20
|
+
reflectionAtlas?: BaseTexture | null;
|
|
21
|
+
/** How strongly mesh particles reflect the atlas, 0..1. */
|
|
12
22
|
reflectionLevel?: number;
|
|
13
23
|
}
|
|
14
24
|
|
|
@@ -36,10 +46,10 @@ export function applyRendererMaterial(system: ParticleSystem, patch: RendererMat
|
|
|
36
46
|
settings.materialAlphaTest = patch.alphaTest;
|
|
37
47
|
}
|
|
38
48
|
if (patch.texture !== undefined) {
|
|
39
|
-
system.texture = patch.texture
|
|
49
|
+
system.texture = patch.texture;
|
|
40
50
|
}
|
|
41
51
|
if (patch.reflectionAtlas !== undefined) {
|
|
42
|
-
settings.reflectionAtlas = patch.reflectionAtlas
|
|
52
|
+
settings.reflectionAtlas = patch.reflectionAtlas;
|
|
43
53
|
}
|
|
44
54
|
if (patch.reflectionLevel !== undefined) {
|
|
45
55
|
settings.reflectionLevel = patch.reflectionLevel;
|
package/src/core/playback.ts
CHANGED
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
export interface PlaybackState {
|
|
3
3
|
/** When true, all in-scene preview effects simulate. */
|
|
4
4
|
stagePlaying: boolean;
|
|
5
|
+
/** Root `uniqueId` of the focused effect, whose time the timeline shows. */
|
|
5
6
|
focusRootId: number | null;
|
|
7
|
+
/** Each effect's timeline time, in seconds, by root `uniqueId`. */
|
|
6
8
|
focusElapsedByRoot: Map<number, number>;
|
|
9
|
+
/** Effects parked at their end, by root `uniqueId`; Play restarts them. */
|
|
7
10
|
focusFinishedByRoot: Set<number>;
|
|
11
|
+
/** Playback speed, 1 for real time. */
|
|
8
12
|
speed: number;
|
|
13
|
+
/** While paused: advance one frame on the next render. */
|
|
9
14
|
stepQueued: boolean;
|
|
15
|
+
/** The timeline is being scrubbed; the render loop does not simulate. */
|
|
10
16
|
scrubbing: boolean;
|
|
11
17
|
}
|
|
12
18
|
|
package/src/core/projectStore.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/** One editor project: a library of effect assets plus the scene built from them. */
|
|
2
2
|
export interface ProjectMeta {
|
|
3
|
+
/** The project's key in its store. */
|
|
3
4
|
id: string;
|
|
5
|
+
/** The project's display name. */
|
|
4
6
|
name: string;
|
|
7
|
+
/** When the project was created, in milliseconds since the epoch. */
|
|
5
8
|
createdAt: number;
|
|
9
|
+
/** When the project last changed, in milliseconds since the epoch. */
|
|
6
10
|
updatedAt: number;
|
|
11
|
+
/** How many effect assets the project holds. */
|
|
7
12
|
assetCount: number;
|
|
8
13
|
/** Approximate bytes the project takes in storage (JSON + texture files). */
|
|
9
14
|
sizeBytes: number;
|
|
@@ -13,26 +18,35 @@ export interface ProjectMeta {
|
|
|
13
18
|
export interface StoredAsset {
|
|
14
19
|
/** Relative path inside the project (`Fire/Explosion.json`) — the asset's key. */
|
|
15
20
|
path: string;
|
|
21
|
+
/** The asset's display name, its file name without `.json`. */
|
|
16
22
|
name: string;
|
|
23
|
+
/** The effect, as quarks JSON with its textures inlined. */
|
|
17
24
|
json: unknown;
|
|
25
|
+
/** Files the effect referenced that were not imported with it. */
|
|
18
26
|
missingFiles: string[];
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
/** One effect instance in a saved scene. */
|
|
22
30
|
export interface StoredSceneEntry {
|
|
31
|
+
/** The instance's name in the Scene list. */
|
|
23
32
|
name: string;
|
|
24
33
|
/** Path of the asset it was made from, if any. */
|
|
25
34
|
assetPath: string | null;
|
|
26
35
|
/** The instance's own (possibly edited) effect, root transform included. */
|
|
27
36
|
json: unknown;
|
|
37
|
+
/** Whether the instance was shown. */
|
|
28
38
|
visible: boolean;
|
|
29
39
|
}
|
|
30
40
|
|
|
41
|
+
/** A project's saved scene: the effects placed in it, in Scene list order. */
|
|
31
42
|
export interface StoredScene {
|
|
43
|
+
/** The scene's effect instances. */
|
|
32
44
|
entries: StoredSceneEntry[];
|
|
45
|
+
/** When it was saved, in milliseconds since the epoch. */
|
|
33
46
|
savedAt: number;
|
|
34
47
|
}
|
|
35
48
|
|
|
49
|
+
/** How much storage projects use, as far as the browser tells. */
|
|
36
50
|
export interface StorageEstimate {
|
|
37
51
|
/** Bytes the whole site uses (all projects), when the browser reports it. */
|
|
38
52
|
usage: number | null;
|
|
@@ -47,26 +61,38 @@ export interface StorageEstimate {
|
|
|
47
61
|
* everything in the browser, and an embedding host can supply its own (e.g. on disk).
|
|
48
62
|
*/
|
|
49
63
|
export interface ProjectStore {
|
|
64
|
+
/** Every project, most recently changed first. */
|
|
50
65
|
listProjects(): Promise<ProjectMeta[]>;
|
|
66
|
+
/** One project, or null when there is none with that id. */
|
|
51
67
|
getProject(id: string): Promise<ProjectMeta | null>;
|
|
68
|
+
/** Creates an empty project. */
|
|
52
69
|
createProject(name: string): Promise<ProjectMeta>;
|
|
70
|
+
/** Renames a project. */
|
|
53
71
|
renameProject(id: string, name: string): Promise<void>;
|
|
72
|
+
/** Copies a project, its assets and its scene, under a new name. */
|
|
54
73
|
duplicateProject(id: string, name: string): Promise<ProjectMeta>;
|
|
74
|
+
/** Deletes a project, its assets and its scene. */
|
|
55
75
|
deleteProject(id: string): Promise<void>;
|
|
56
76
|
|
|
77
|
+
/** A project's assets. */
|
|
57
78
|
loadAssets(projectId: string): Promise<StoredAsset[]>;
|
|
58
79
|
/** Adds or replaces assets by path. */
|
|
59
80
|
putAssets(projectId: string, assets: StoredAsset[]): Promise<void>;
|
|
81
|
+
/** Deletes assets by path; paths it does not have are ignored. */
|
|
60
82
|
deleteAssets(projectId: string, paths: string[]): Promise<void>;
|
|
61
83
|
|
|
84
|
+
/** A project's saved scene, or null when it was never saved. */
|
|
62
85
|
loadScene(projectId: string): Promise<StoredScene | null>;
|
|
86
|
+
/** Replaces a project's saved scene. */
|
|
63
87
|
saveScene(projectId: string, scene: StoredScene): Promise<void>;
|
|
64
88
|
|
|
89
|
+
/** How much storage projects use. */
|
|
65
90
|
estimate(): Promise<StorageEstimate>;
|
|
66
91
|
/** Asks the browser to keep the data even under storage pressure; resolves to the result. */
|
|
67
92
|
requestPersistence(): Promise<boolean>;
|
|
68
93
|
}
|
|
69
94
|
|
|
95
|
+
/** A byte count for people: `512 B`, `1.5 KB`, `20 MB`; `—` when unknown. */
|
|
70
96
|
export function formatBytes(bytes: number | null | undefined): string {
|
|
71
97
|
if (bytes == null) return '—';
|
|
72
98
|
if (bytes < 1024) return `${bytes} B`;
|
package/src/core/sceneEntries.ts
CHANGED
|
@@ -12,12 +12,15 @@ import {disposeLoadedEffect, parseEffectFromJson} from './loadEffect.js';
|
|
|
12
12
|
* that are edited separately.
|
|
13
13
|
*/
|
|
14
14
|
export interface SceneEntry {
|
|
15
|
+
/** The instance's name in the Scene list, unique in the scene. */
|
|
15
16
|
name: string;
|
|
16
17
|
/** Path of the asset it came from, or a synthetic `_created/…` path for new effects. */
|
|
17
18
|
path: string;
|
|
18
19
|
/** Asset this instance was made from, if any. */
|
|
19
20
|
assetId: number | null;
|
|
21
|
+
/** The instance's root node. */
|
|
20
22
|
root: TransformNode;
|
|
23
|
+
/** Every particle system of the instance. */
|
|
21
24
|
systems: ParticleSystem[];
|
|
22
25
|
}
|
|
23
26
|
|
package/src/core/scrub.ts
CHANGED
|
@@ -7,10 +7,10 @@ function bindingSystems(binding: EffectBinding): ParticleSystem[] {
|
|
|
7
7
|
return [binding.system, ...binding.subSystems];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
/** Unpauses every system in the focused effect. */
|
|
10
|
+
/** Unpauses every system in the focused effect; one that has finished stays finished. */
|
|
11
11
|
export function playFocus(binding: EffectBinding): void {
|
|
12
12
|
for (const system of bindingSystems(binding)) {
|
|
13
|
-
system.
|
|
13
|
+
system.resume();
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
package/src/core/shapes.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
SphereEmitter,
|
|
18
18
|
} from 'babylon.quarks';
|
|
19
19
|
|
|
20
|
+
/** The emitter shapes the Shape module offers, by the `type` they serialise with. */
|
|
20
21
|
export type ShapeType =
|
|
21
22
|
| 'point'
|
|
22
23
|
| 'sphere'
|
|
@@ -30,7 +31,13 @@ export type ShapeType =
|
|
|
30
31
|
| 'edge'
|
|
31
32
|
| 'mesh_surface';
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
/** The Shape module's shape list, in menu order, with the label each shows. */
|
|
35
|
+
export const SHAPE_TYPES: Array<{
|
|
36
|
+
/** The shape's type. */
|
|
37
|
+
value: ShapeType;
|
|
38
|
+
/** Its label in the menu. */
|
|
39
|
+
label: string;
|
|
40
|
+
}> = [
|
|
34
41
|
{value: 'cone', label: 'Cone'},
|
|
35
42
|
{value: 'sphere', label: 'Sphere'},
|
|
36
43
|
{value: 'hemisphere', label: 'Hemisphere'},
|
|
@@ -44,17 +51,32 @@ export const SHAPE_TYPES: Array<{value: ShapeType; label: string}> = [
|
|
|
44
51
|
{value: 'point', label: 'Point'},
|
|
45
52
|
];
|
|
46
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Every shape's settings in one flat record, so switching shapes keeps what the shapes share
|
|
56
|
+
* (a cone's radius becomes the sphere's). Each shape reads the fields it has.
|
|
57
|
+
*/
|
|
47
58
|
export interface ShapeParams {
|
|
59
|
+
/** Radius of a sphere, hemisphere, cone, circle or donut. */
|
|
48
60
|
radius: number;
|
|
61
|
+
/** The part of the circle emitted from, in radians (2π: all of it). */
|
|
49
62
|
arc: number;
|
|
63
|
+
/** 0 emits from the surface only, 1 from the whole volume. */
|
|
50
64
|
thickness: number;
|
|
65
|
+
/** A cone's half angle, in radians. */
|
|
51
66
|
angle: number;
|
|
67
|
+
/** The radius of a donut's tube. */
|
|
52
68
|
donutRadius: number;
|
|
69
|
+
/** Width of a rectangle, grid or box (X). */
|
|
53
70
|
width: number;
|
|
71
|
+
/** Height of a rectangle, grid or box (Y). */
|
|
54
72
|
height: number;
|
|
73
|
+
/** How points around the arc are picked: at random, in a loop, back and forth or in bursts. */
|
|
55
74
|
mode: EmitterMode;
|
|
75
|
+
/** Snaps the arc position to steps of this fraction; 0 for none. */
|
|
56
76
|
spread: number;
|
|
77
|
+
/** A grid's column count. */
|
|
57
78
|
column: number;
|
|
79
|
+
/** A grid's row count. */
|
|
58
80
|
row: number;
|
|
59
81
|
/** Box depth (Z). */
|
|
60
82
|
depth: number;
|
|
@@ -62,9 +84,11 @@ export interface ShapeParams {
|
|
|
62
84
|
emitFrom: BoxEmitFrom;
|
|
63
85
|
/** How fast an edge emitter's loop / ping-pong point travels, in lengths per second. */
|
|
64
86
|
speed: number;
|
|
87
|
+
/** The mesh a mesh surface emitter emits from. */
|
|
65
88
|
mesh?: Mesh;
|
|
66
89
|
}
|
|
67
90
|
|
|
91
|
+
/** The settings a new shape starts from. */
|
|
68
92
|
export const DEFAULT_SHAPE_PARAMS: ShapeParams = {
|
|
69
93
|
radius: 0.3,
|
|
70
94
|
arc: Math.PI * 2,
|
|
@@ -83,11 +107,13 @@ export const DEFAULT_SHAPE_PARAMS: ShapeParams = {
|
|
|
83
107
|
mesh: undefined,
|
|
84
108
|
};
|
|
85
109
|
|
|
110
|
+
/** The type of a shape, as the Shape module lists it. */
|
|
86
111
|
export function getShapeType(shape: EmitterShape): ShapeType {
|
|
87
112
|
const type = (shape as {type?: string}).type ?? 'point';
|
|
88
113
|
return (SHAPE_TYPES.some((s) => s.value === type) ? type : 'point') as ShapeType;
|
|
89
114
|
}
|
|
90
115
|
|
|
116
|
+
/** A shape's settings, the fields it does not have taken from {@link DEFAULT_SHAPE_PARAMS}. */
|
|
91
117
|
export function readShapeParams(shape: EmitterShape): ShapeParams {
|
|
92
118
|
const anyShape = shape as unknown as {[key: string]: unknown};
|
|
93
119
|
const num = (key: string, fallback: number) =>
|
|
@@ -127,6 +153,7 @@ export const SHAPE_PARAM_KEYS: {[K in ShapeType]: Array<keyof ShapeParams>} = {
|
|
|
127
153
|
mesh_surface: [],
|
|
128
154
|
};
|
|
129
155
|
|
|
156
|
+
/** A new shape of `type`, built from the fields of `params` it has. */
|
|
130
157
|
export function createShape(type: ShapeType, params: ShapeParams): EmitterShape {
|
|
131
158
|
switch (type) {
|
|
132
159
|
case 'point':
|
package/src/core/systems.ts
CHANGED
|
@@ -7,10 +7,13 @@ import {
|
|
|
7
7
|
ParticleSystem,
|
|
8
8
|
RenderMode,
|
|
9
9
|
Vector4,
|
|
10
|
+
type ParticleEmitter,
|
|
10
11
|
} from 'babylon.quarks';
|
|
11
12
|
import type {EffectBinding} from './binding.js';
|
|
12
13
|
|
|
14
|
+
/** How {@link createChildSystem} builds a new system. */
|
|
13
15
|
export interface ChildSystemOptions {
|
|
16
|
+
/** The new emitter's name. */
|
|
14
17
|
name?: string;
|
|
15
18
|
/** One-shot burst (sub-emitter target) instead of a looping stream. */
|
|
16
19
|
oneShot?: boolean;
|
|
@@ -61,10 +64,14 @@ export function createChildSystem(parent: ParticleSystem, options: ChildSystemOp
|
|
|
61
64
|
export function unlinkSubEmitterReferences(systems: ParticleSystem[], removed: ParticleSystem[]): void {
|
|
62
65
|
const removedEmitters = new Set(removed.map((system) => system.emitter));
|
|
63
66
|
for (const system of systems) {
|
|
64
|
-
const behaviors = system.behaviors as Array<{type?: string; subParticleSystem?:
|
|
67
|
+
const behaviors = system.behaviors as Array<{type?: string; subParticleSystem?: ParticleEmitter}>;
|
|
65
68
|
for (let i = behaviors.length - 1; i >= 0; i--) {
|
|
66
69
|
const behavior = behaviors[i];
|
|
67
|
-
if (
|
|
70
|
+
if (
|
|
71
|
+
behavior.type === 'EmitSubParticleSystem' &&
|
|
72
|
+
behavior.subParticleSystem &&
|
|
73
|
+
removedEmitters.has(behavior.subParticleSystem)
|
|
74
|
+
) {
|
|
68
75
|
behaviors.splice(i, 1);
|
|
69
76
|
}
|
|
70
77
|
}
|
package/src/core/timeline.ts
CHANGED
|
@@ -7,21 +7,46 @@ import type {EffectTreeNode} from './effectTree.js';
|
|
|
7
7
|
/** Guards against a literally zero-width ruler (e.g. no tracks yet) — not a usability stretch. */
|
|
8
8
|
const MIN_TIMELINE_SPAN = 0.01;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
/** A timeline row for a group node: a heading over the tracks of the systems under it. */
|
|
11
|
+
export interface TimelineGroupRow {
|
|
12
|
+
/** Tells group rows from track rows. */
|
|
13
|
+
kind: 'group';
|
|
14
|
+
/** The group's node. */
|
|
15
|
+
node: TransformNode;
|
|
16
|
+
/** The group's name. */
|
|
17
|
+
name: string;
|
|
18
|
+
/** How deep the group sits in the effect tree; the root's children are 0. */
|
|
19
|
+
depth: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A timeline row for one particle system: a bar from its start delay over its duration. */
|
|
23
|
+
export interface TimelineSystemRow {
|
|
24
|
+
/** Tells group rows from track rows. */
|
|
25
|
+
kind: 'track';
|
|
26
|
+
/** The system's emitter node. */
|
|
27
|
+
node: TransformNode;
|
|
28
|
+
/** The system. */
|
|
29
|
+
system: ParticleSystem;
|
|
30
|
+
/** The emitter's name. */
|
|
31
|
+
name: string;
|
|
32
|
+
/** How deep the emitter sits in the effect tree. */
|
|
33
|
+
depth: number;
|
|
34
|
+
/** True for the effect's main system. */
|
|
35
|
+
isRoot: boolean;
|
|
36
|
+
/** False for the one system an effect cannot lose. */
|
|
37
|
+
removable: boolean;
|
|
38
|
+
/** Where the bar starts: the start delay, its lower end when random, in seconds. */
|
|
39
|
+
startOffset: number;
|
|
40
|
+
/** True when the start delay is a curve and the bar's start is only indicative. */
|
|
41
|
+
startOffsetVariable: boolean;
|
|
42
|
+
/** The bar's length, the system's duration in seconds. */
|
|
43
|
+
duration: number;
|
|
44
|
+
/** True when the system loops; its bar runs to the end of the ruler. */
|
|
45
|
+
looping: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** One row of the focused effect's timeline. */
|
|
49
|
+
export type TimelineRow = TimelineGroupRow | TimelineSystemRow;
|
|
25
50
|
|
|
26
51
|
/**
|
|
27
52
|
* Reads a representative start-delay value for display without invoking the generator's
|
package/src/core/values.ts
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
import type {FunctionValueGenerator, ValueGenerator} from 'babylon.quarks';
|
|
1
|
+
import type {FunctionValueGenerator, RotationGenerator, ValueGenerator, Vector3Generator} from 'babylon.quarks';
|
|
2
2
|
import {Bezier, ConstantValue, IntervalValue, PiecewiseBezier} from 'babylon.quarks';
|
|
3
3
|
|
|
4
|
+
/** A generator of one number: a constant or random value, or a curve over the particle's life. */
|
|
4
5
|
export type ScalarGenerator = ValueGenerator | FunctionValueGenerator;
|
|
6
|
+
/** Any generator a value field can be pointed at; ones that are not scalar read as the default. */
|
|
7
|
+
export type AnyGenerator = ScalarGenerator | Vector3Generator | RotationGenerator;
|
|
8
|
+
/** How a value field produces its number: Unity's Constant, Random Between Two Constants or Curve. */
|
|
5
9
|
export type ScalarMode = 'constant' | 'random' | 'curve';
|
|
6
10
|
|
|
7
11
|
/** Editable snapshot of a scalar value generator. */
|
|
8
12
|
export interface ScalarValueState {
|
|
13
|
+
/** Which of the fields below is the value. */
|
|
9
14
|
mode: ScalarMode;
|
|
10
15
|
/** Constant value (mode: constant). */
|
|
11
16
|
value: number;
|
|
12
|
-
/**
|
|
17
|
+
/** Lower end of the random range (mode: random). */
|
|
13
18
|
min: number;
|
|
19
|
+
/** Upper end of the random range (mode: random). */
|
|
14
20
|
max: number;
|
|
15
21
|
/** Cubic bezier control values over normalized lifetime (mode: curve). */
|
|
16
22
|
curve: [number, number, number, number];
|
|
17
23
|
}
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
/**
|
|
26
|
+
* What a value field shows for `generator`: its constant, its range or its first curve segment.
|
|
27
|
+
* Anything else, including a missing generator, reads as the constant 1.
|
|
28
|
+
*/
|
|
29
|
+
export function readScalar(generator: AnyGenerator | undefined): ScalarValueState {
|
|
20
30
|
const state: ScalarValueState = {mode: 'constant', value: 1, min: 0.5, max: 1.5, curve: [0, 1, 1, 0]};
|
|
21
31
|
if (generator instanceof ConstantValue) {
|
|
22
32
|
state.mode = 'constant';
|
|
@@ -39,6 +49,9 @@ export function readScalar(generator: ScalarGenerator | undefined): ScalarValueS
|
|
|
39
49
|
return state;
|
|
40
50
|
}
|
|
41
51
|
|
|
52
|
+
/** The generator a value field's state describes; a curve state builds a one-segment curve. */
|
|
53
|
+
export function buildScalar(state: ScalarValueState & {mode: 'curve'}): PiecewiseBezier;
|
|
54
|
+
export function buildScalar(state: ScalarValueState): ScalarGenerator;
|
|
42
55
|
export function buildScalar(state: ScalarValueState): ScalarGenerator {
|
|
43
56
|
switch (state.mode) {
|
|
44
57
|
case 'constant':
|
|
@@ -52,12 +65,14 @@ export function buildScalar(state: ScalarValueState): ScalarGenerator {
|
|
|
52
65
|
|
|
53
66
|
/** One segment of a piecewise bezier curve: start x (0..1) + four control values. */
|
|
54
67
|
export interface CurvePiece {
|
|
68
|
+
/** Where the segment starts, 0..1 over the particle's life. */
|
|
55
69
|
start: number;
|
|
70
|
+
/** The segment's four bezier control values. */
|
|
56
71
|
p: [number, number, number, number];
|
|
57
72
|
}
|
|
58
73
|
|
|
59
74
|
/** Reads pieces from a PiecewiseBezier (or synthesizes one segment for other generators). */
|
|
60
|
-
export function readPieces(generator:
|
|
75
|
+
export function readPieces(generator: AnyGenerator | undefined): CurvePiece[] {
|
|
61
76
|
if (generator instanceof PiecewiseBezier && generator.functions.length > 0) {
|
|
62
77
|
return generator.functions.map(([bezier, start]) => ({
|
|
63
78
|
start,
|
|
@@ -68,6 +83,7 @@ export function readPieces(generator: ScalarGenerator | undefined): CurvePiece[]
|
|
|
68
83
|
return [{start: 0, p: fallback.curve}];
|
|
69
84
|
}
|
|
70
85
|
|
|
86
|
+
/** A piecewise bezier from segments, sorted by their start. */
|
|
71
87
|
export function buildCurve(pieces: CurvePiece[]): PiecewiseBezier {
|
|
72
88
|
const sorted = [...pieces].sort((a, b) => a.start - b.start);
|
|
73
89
|
return new PiecewiseBezier(sorted.map((piece) => [new Bezier(...piece.p), piece.start] as [Bezier, number]));
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export type {AssetLoadProgress, EffectAsset} from './core/assets.js';
|
|
2
|
+
export type {AssetDragPayload} from './core/assetTree.js';
|
|
1
3
|
export {EffectBinding} from './core/binding.js';
|
|
2
4
|
export type {EditorListener} from './core/binding.js';
|
|
3
5
|
export {GroundPlaneResolver, ensureGroundResolver} from './core/collision.js';
|
|
@@ -29,6 +31,7 @@ export type {
|
|
|
29
31
|
StoredScene,
|
|
30
32
|
StoredSceneEntry,
|
|
31
33
|
} from './core/projectStore.js';
|
|
34
|
+
export type {SceneEntry} from './core/sceneEntries.js';
|
|
32
35
|
export {
|
|
33
36
|
DEFAULT_SHAPE_PARAMS,
|
|
34
37
|
SHAPE_PARAM_KEYS,
|
|
@@ -41,5 +44,6 @@ export type {ShapeParams, ShapeType} from './core/shapes.js';
|
|
|
41
44
|
export {createChildSystem} from './core/systems.js';
|
|
42
45
|
export type {ChildSystemOptions} from './core/systems.js';
|
|
43
46
|
export {ensurePortableTextureUrl} from './core/textureExport.js';
|
|
47
|
+
export type {TimelineGroupRow, TimelineRow, TimelineSystemRow} from './core/timeline.js';
|
|
44
48
|
export {buildCurve, buildScalar, mergePieces, readPieces, readScalar, sampleCurve, splitPieces} from './core/values.js';
|
|
45
|
-
export type {CurvePiece, ScalarGenerator, ScalarMode, ScalarValueState} from './core/values.js';
|
|
49
|
+
export type {AnyGenerator, CurvePiece, ScalarGenerator, ScalarMode, ScalarValueState} from './core/values.js';
|
|
@@ -26,16 +26,23 @@ import {buttonStyle, hiddenFileInputStyle, inputStyle, theme} from './theme.js';
|
|
|
26
26
|
const TREE_WIDTH = 200;
|
|
27
27
|
const TILE_WIDTH = 92;
|
|
28
28
|
|
|
29
|
+
/** Props of {@link AssetsPanel}. */
|
|
29
30
|
export interface AssetsPanelProps {
|
|
31
|
+
/** The assets, shown as a folder tree by their paths. */
|
|
30
32
|
assets: EffectAsset[];
|
|
31
33
|
/** Scene instance count per asset id. */
|
|
32
34
|
instanceCounts: ReadonlyMap<number, number>;
|
|
35
|
+
/** Import progress while importing; the import buttons are disabled meanwhile. */
|
|
33
36
|
loading: AssetLoadProgress | null;
|
|
37
|
+
/** The hidden folder input, clicked by hosts whose browser has no directory picker. */
|
|
34
38
|
folderInputRef: React.RefObject<HTMLInputElement | null>;
|
|
39
|
+
/** Imports picked files. */
|
|
35
40
|
onImportFiles: (files: FileList | File[]) => void;
|
|
41
|
+
/** Opens a folder to import. */
|
|
36
42
|
onImportFolder: () => void;
|
|
37
43
|
/** Adds a new instance of each asset in the payload to the scene. */
|
|
38
44
|
onAddToScene: (payload: AssetDragPayload) => void;
|
|
45
|
+
/** Deletes the assets in the payload. */
|
|
39
46
|
onDelete: (payload: AssetDragPayload) => void;
|
|
40
47
|
/** Opens the asset on its own to edit it (double-click). Without it, double-click adds to the scene. */
|
|
41
48
|
onOpenPrefab?: (asset: EffectAsset) => void;
|