babylon.quarks-editor 0.18.1 → 0.20.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 +28 -0
- package/README.md +6 -6
- package/dist/core/assetDragSession.d.ts +4 -0
- package/dist/core/assetDragSession.js +8 -0
- package/dist/core/assetTree.d.ts +39 -0
- package/dist/core/assetTree.js +112 -0
- package/dist/core/assets.d.ts +56 -0
- package/dist/core/assets.js +207 -0
- package/dist/core/binding.d.ts +6 -1
- package/dist/core/binding.js +7 -0
- package/dist/core/collision.d.ts +4 -5
- package/dist/core/collision.js +4 -5
- package/dist/core/colors.d.ts +1 -1
- package/dist/core/defaultEffect.d.ts +4 -5
- package/dist/core/defaultEffect.js +5 -14
- package/dist/core/effectTree.d.ts +1 -1
- package/dist/core/effectTree.js +18 -4
- package/dist/core/emitterShapeWireframe.d.ts +2 -1
- package/dist/core/emitterShapeWireframe.js +2 -1
- package/dist/core/galleryDropMarker.js +1 -1
- package/dist/core/galleryPlayback.d.ts +7 -7
- package/dist/core/galleryPlayback.js +2 -2
- package/dist/core/galleryScene.d.ts +8 -13
- package/dist/core/galleryScene.js +14 -42
- package/dist/core/gallerySelectionMarker.d.ts +1 -0
- package/dist/core/gallerySelectionMarker.js +1 -0
- package/dist/core/history.d.ts +12 -1
- package/dist/core/history.js +16 -3
- package/dist/core/indexedDbProjectStore.d.ts +35 -0
- package/dist/core/indexedDbProjectStore.js +299 -0
- package/dist/core/lineShaders.d.ts +2 -0
- package/dist/core/lineShaders.js +7 -0
- package/dist/core/loadEffect.d.ts +2 -2
- package/dist/core/loadEffect.js +1 -1
- package/dist/core/pickAssetFiles.d.ts +6 -0
- package/dist/core/{pickGalleryFiles.js → pickAssetFiles.js} +13 -8
- package/dist/core/projectStore.d.ts +61 -0
- package/dist/core/projectStore.js +14 -0
- package/dist/core/sceneEntries.d.ts +35 -0
- package/dist/core/sceneEntries.js +62 -0
- package/dist/core/shapes.d.ts +1 -1
- package/dist/core/shapes.js +35 -8
- package/dist/core/systems.d.ts +1 -1
- package/dist/core/systems.js +3 -1
- package/dist/core/timeline.d.ts +1 -2
- package/dist/core/transport.d.ts +12 -0
- package/dist/core/transport.js +36 -0
- package/dist/core/values.d.ts +1 -1
- package/dist/core/viewportPicker.d.ts +4 -4
- package/dist/core/viewportPicker.js +3 -3
- package/dist/index.d.ts +15 -11
- package/dist/index.js +8 -6
- package/dist/react/AssetsPanel.d.ts +22 -0
- package/dist/react/AssetsPanel.js +252 -0
- package/dist/react/ChoiceDialog.d.ts +18 -0
- package/dist/react/ChoiceDialog.js +48 -0
- package/dist/react/ContextMenu.d.ts +16 -0
- package/dist/react/ContextMenu.js +70 -0
- package/dist/react/CurveEditor.d.ts +1 -2
- package/dist/react/CurveEditor.js +14 -3
- package/dist/react/EditorWorkspace.d.ts +21 -0
- package/dist/react/EditorWorkspace.js +63 -0
- package/dist/react/EffectEditor.d.ts +3 -3
- package/dist/react/EffectEditor.js +9 -6
- package/dist/react/EffectEditorHost.d.ts +20 -3
- package/dist/react/EffectEditorHost.js +1426 -558
- package/dist/react/EffectTreeView.d.ts +17 -0
- package/dist/react/EffectTreeView.js +52 -0
- package/dist/react/GradientEditor.d.ts +1 -2
- package/dist/react/GradientEditor.js +8 -1
- package/dist/react/MessageDialog.js +7 -1
- package/dist/react/ModuleSection.js +10 -3
- package/dist/react/ObjectModule.d.ts +5 -2
- package/dist/react/ObjectModule.js +8 -11
- package/dist/react/ProjectsPage.d.ts +9 -0
- package/dist/react/ProjectsPage.js +140 -0
- package/dist/react/ScenePanel.d.ts +26 -0
- package/dist/react/ScenePanel.js +134 -0
- package/dist/react/SubEmittersModule.d.ts +1 -2
- package/dist/react/TimelinePanel.d.ts +11 -4
- package/dist/react/TimelinePanel.js +65 -40
- package/dist/react/TimelineTrackRow.d.ts +1 -1
- package/dist/react/TimelineTrackRow.js +20 -6
- package/dist/react/TransportBar.d.ts +24 -0
- package/dist/react/TransportBar.js +43 -0
- package/dist/react/ValueField.d.ts +1 -2
- package/dist/react/behaviorModules.js +24 -12
- package/dist/react/index.d.ts +31 -17
- package/dist/react/index.js +18 -11
- package/dist/react/inspectorHints.js +1 -2
- package/dist/react/modules.js +55 -25
- package/package.json +68 -68
- package/src/core/assetDragSession.ts +12 -0
- package/src/core/assetTree.ts +148 -0
- package/src/core/assets.ts +262 -0
- package/src/core/binding.ts +10 -2
- package/src/core/collision.ts +4 -5
- package/src/core/colors.ts +1 -1
- package/src/core/defaultEffect.ts +10 -23
- package/src/core/effectTree.ts +22 -7
- package/src/core/emitterShapeWireframe.ts +9 -4
- package/src/core/galleryDropMarker.ts +6 -2
- package/src/core/galleryPlayback.ts +9 -9
- package/src/core/galleryScene.ts +15 -63
- package/src/core/gallerySelectionMarker.ts +6 -1
- package/src/core/history.ts +24 -3
- package/src/core/indexedDbProjectStore.ts +357 -0
- package/src/core/lineShaders.ts +7 -0
- package/src/core/loadEffect.ts +3 -3
- package/src/core/{pickGalleryFiles.ts → pickAssetFiles.ts} +16 -8
- package/src/core/projectStore.ts +81 -0
- package/src/core/sceneEntries.ts +96 -0
- package/src/core/shapes.ts +48 -10
- package/src/core/systems.ts +9 -3
- package/src/core/timeline.ts +8 -8
- package/src/core/transport.ts +53 -0
- package/src/core/values.ts +1 -1
- package/src/core/viewportPicker.ts +5 -5
- package/src/index.ts +29 -18
- package/src/react/AssetsPanel.tsx +559 -0
- package/src/react/ChoiceDialog.tsx +93 -0
- package/src/react/ContextMenu.tsx +107 -0
- package/src/react/CurveEditor.tsx +40 -10
- package/src/react/EditorWorkspace.tsx +95 -0
- package/src/react/EffectEditor.tsx +28 -16
- package/src/react/EffectEditorHost.tsx +2005 -721
- package/src/react/EffectTreeView.tsx +117 -0
- package/src/react/GradientEditor.tsx +21 -4
- package/src/react/InspectorInfoIcon.tsx +6 -2
- package/src/react/MessageDialog.tsx +9 -1
- package/src/react/ModuleSection.tsx +12 -3
- package/src/react/ObjectModule.tsx +41 -16
- package/src/react/ProjectsPage.tsx +306 -0
- package/src/react/PromptDialog.tsx +5 -1
- package/src/react/ScenePanel.tsx +318 -0
- package/src/react/SubEmittersModule.tsx +1 -2
- package/src/react/TimelinePanel.tsx +171 -99
- package/src/react/TimelineTrackRow.tsx +71 -18
- package/src/react/TransportBar.tsx +114 -0
- package/src/react/ValueField.tsx +0 -1
- package/src/react/behaviorModules.tsx +148 -42
- package/src/react/index.ts +47 -33
- package/src/react/inspectorHints.ts +1 -2
- package/src/react/modules.tsx +173 -57
- package/dist/core/galleryDragSession.d.ts +0 -4
- package/dist/core/galleryDragSession.js +0 -8
- package/dist/core/galleryTree.d.ts +0 -49
- package/dist/core/galleryTree.js +0 -138
- package/dist/core/loadEffectGallery.d.ts +0 -36
- package/dist/core/loadEffectGallery.js +0 -97
- package/dist/core/pickGalleryFiles.d.ts +0 -5
- package/dist/react/GalleryPanel.d.ts +0 -20
- package/dist/react/GalleryPanel.js +0 -246
- package/src/core/galleryDragSession.ts +0 -12
- package/src/core/galleryTree.ts +0 -187
- package/src/core/loadEffectGallery.ts +0 -146
- package/src/react/GalleryPanel.tsx +0 -517
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import {QuarksLoader} from 'babylon.quarks';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One effect file in the Assets panel. Holds the source JSON only — nothing is live in the
|
|
5
|
+
* Babylon scene until the asset is dropped into the viewport, and every drop instantiates a
|
|
6
|
+
* fresh, independent copy (see `instantiateSceneEntry`).
|
|
7
|
+
*/
|
|
8
|
+
export interface EffectAsset {
|
|
9
|
+
id: number;
|
|
10
|
+
name: string;
|
|
11
|
+
/** Relative path inside the imported folder (preserves subfolders). */
|
|
12
|
+
path: string;
|
|
13
|
+
/** Quarks JSON with every external file reference already inlined. */
|
|
14
|
+
json: unknown;
|
|
15
|
+
/** Texture/geometry files the effect references that were not among the imported files. */
|
|
16
|
+
missingFiles: string[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AssetLoadProgress {
|
|
20
|
+
done: number;
|
|
21
|
+
total: number;
|
|
22
|
+
loaded: number;
|
|
23
|
+
failed: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const YIELD_EVERY = 8;
|
|
27
|
+
const IMAGE_FILE = /\.(png|jpe?g|webp|gif|bmp)$/i;
|
|
28
|
+
|
|
29
|
+
let nextAssetId = 1;
|
|
30
|
+
|
|
31
|
+
function yieldToBrowser(): Promise<void> {
|
|
32
|
+
return new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function relativePathOf(file: File): string {
|
|
36
|
+
return ((file as File & {webkitRelativePath?: string}).webkitRelativePath || file.name).replace(/\\/g, '/');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Files an asset import reads: effect `.json` files plus the images/geometries they may reference. */
|
|
40
|
+
export function isAssetImportFile(name: string): boolean {
|
|
41
|
+
return /\.json$/i.test(name) || IMAGE_FILE.test(name);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Collects `.json` files from a picker result, sorted by relative path. */
|
|
45
|
+
export function collectJsonFiles(files: FileList | File[]): File[] {
|
|
46
|
+
return Array.from(files)
|
|
47
|
+
.filter((file) => file.name.toLowerCase().endsWith('.json'))
|
|
48
|
+
.sort((a, b) => relativePathOf(a).localeCompare(relativePathOf(b)));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Resolves `url` against the folder of `fromPath` (`a/b/fx.json` + `../t.png` → `a/t.png`). */
|
|
52
|
+
export function resolveRelativePath(fromPath: string, url: string): string {
|
|
53
|
+
const segments = fromPath.split('/').slice(0, -1);
|
|
54
|
+
for (const part of url.split('/')) {
|
|
55
|
+
if (part === '..') {
|
|
56
|
+
segments.pop();
|
|
57
|
+
} else if (part !== '.' && part !== '') {
|
|
58
|
+
segments.push(part);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return segments.join('/');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function isExternalUrl(url: string): boolean {
|
|
65
|
+
return /^(data|blob):/i.test(url) || /^[a-z][a-z0-9+.-]*:\/\//i.test(url) || url.startsWith('/');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function readAsDataUrl(file: File): Promise<string> {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
const reader = new FileReader();
|
|
71
|
+
reader.onload = () => resolve(reader.result as string);
|
|
72
|
+
reader.onerror = () => reject(reader.error);
|
|
73
|
+
reader.readAsDataURL(file);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** True for a Quarks effect envelope with at least one particle emitter. */
|
|
78
|
+
export function isEffectJson(json: unknown): boolean {
|
|
79
|
+
const object = (json as {object?: unknown} | null)?.object;
|
|
80
|
+
const walk = (node: unknown): boolean => {
|
|
81
|
+
if (!node || typeof node !== 'object') return false;
|
|
82
|
+
const typed = node as {type?: unknown; children?: unknown};
|
|
83
|
+
if (typed.type === 'ParticleEmitter') return true;
|
|
84
|
+
return Array.isArray(typed.children) && typed.children.some(walk);
|
|
85
|
+
};
|
|
86
|
+
return walk(object);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Looks files up by path relative to the import root, falling back to the bare file name — a
|
|
91
|
+
* multi-file "Import effect" pick has no folder structure, only names.
|
|
92
|
+
*/
|
|
93
|
+
class ImportedFileIndex {
|
|
94
|
+
private readonly byPath = new Map<string, File>();
|
|
95
|
+
private readonly byName = new Map<string, File>();
|
|
96
|
+
private readonly cache = new Map<File, Promise<unknown>>();
|
|
97
|
+
|
|
98
|
+
constructor(files: File[]) {
|
|
99
|
+
for (const file of files) {
|
|
100
|
+
this.byPath.set(relativePathOf(file).toLowerCase(), file);
|
|
101
|
+
if (!this.byName.has(file.name.toLowerCase())) {
|
|
102
|
+
this.byName.set(file.name.toLowerCase(), file);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
find(fromPath: string, url: string): File | undefined {
|
|
108
|
+
const clean = decodeURIComponent(url.split(/[?#]/)[0]);
|
|
109
|
+
return (
|
|
110
|
+
this.byPath.get(resolveRelativePath(fromPath, clean).toLowerCase()) ??
|
|
111
|
+
this.byName.get((clean.split('/').pop() ?? clean).toLowerCase())
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Reads each file once, however many effects reference it. */
|
|
116
|
+
read<T>(file: File, read: (file: File) => Promise<T>): Promise<T> {
|
|
117
|
+
let pending = this.cache.get(file);
|
|
118
|
+
if (!pending) {
|
|
119
|
+
pending = read(file);
|
|
120
|
+
this.cache.set(file, pending);
|
|
121
|
+
}
|
|
122
|
+
return pending as Promise<T>;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Inlines what an "assets as files" export put in separate files: image urls become data URIs
|
|
128
|
+
* and external geometries are read into the JSON, so the effect loads (and later exports) as a
|
|
129
|
+
* self-contained effect. Returns the references that could not be found among the files.
|
|
130
|
+
*/
|
|
131
|
+
async function inlineExternalFiles(json: any, effectPath: string, index: ImportedFileIndex): Promise<string[]> {
|
|
132
|
+
const missing: string[] = [];
|
|
133
|
+
|
|
134
|
+
for (const image of Array.isArray(json.images) ? json.images : []) {
|
|
135
|
+
const url = image?.url;
|
|
136
|
+
if (typeof url !== 'string' || isExternalUrl(url)) continue;
|
|
137
|
+
const file = index.find(effectPath, url);
|
|
138
|
+
if (file) {
|
|
139
|
+
image.url = await index.read(file, readAsDataUrl);
|
|
140
|
+
} else {
|
|
141
|
+
missing.push(url);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
await QuarksLoader.resolveExternalGeometries(json, async (url) => {
|
|
146
|
+
const file = index.find(effectPath, url);
|
|
147
|
+
if (!file) {
|
|
148
|
+
missing.push(url);
|
|
149
|
+
throw new Error('not among the imported files');
|
|
150
|
+
}
|
|
151
|
+
return index.read(file, async (f) => JSON.parse(await f.text()));
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return missing;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Reads every effect JSON among `files` into an asset. Files that are not effects (geometry
|
|
159
|
+
* files, unrelated JSON, images) are skipped silently; unreadable JSON is skipped with a warning.
|
|
160
|
+
*/
|
|
161
|
+
export async function loadEffectAssets(
|
|
162
|
+
files: FileList | File[],
|
|
163
|
+
onProgress: (progress: AssetLoadProgress) => void
|
|
164
|
+
): Promise<EffectAsset[]> {
|
|
165
|
+
const all = Array.from(files).filter((file) => isAssetImportFile(file.name));
|
|
166
|
+
const jsonFiles = collectJsonFiles(all);
|
|
167
|
+
const index = new ImportedFileIndex(all);
|
|
168
|
+
const assets: EffectAsset[] = [];
|
|
169
|
+
let failed = 0;
|
|
170
|
+
|
|
171
|
+
onProgress({done: 0, total: jsonFiles.length, loaded: 0, failed: 0});
|
|
172
|
+
|
|
173
|
+
for (let i = 0; i < jsonFiles.length; i++) {
|
|
174
|
+
const file = jsonFiles[i];
|
|
175
|
+
const path = relativePathOf(file);
|
|
176
|
+
try {
|
|
177
|
+
const json = JSON.parse(await file.text());
|
|
178
|
+
if (isEffectJson(json)) {
|
|
179
|
+
const missingFiles = await inlineExternalFiles(json, path, index);
|
|
180
|
+
if (missingFiles.length > 0) {
|
|
181
|
+
console.warn(`[Quarks editor] "${path}" references files that were not imported:`, missingFiles);
|
|
182
|
+
}
|
|
183
|
+
assets.push({id: nextAssetId++, name: file.name.replace(/\.json$/i, ''), path, json, missingFiles});
|
|
184
|
+
}
|
|
185
|
+
} catch (err) {
|
|
186
|
+
failed++;
|
|
187
|
+
console.warn(`[Quarks editor] Skipped "${path}":`, err);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
onProgress({done: i + 1, total: jsonFiles.length, loaded: assets.length, failed});
|
|
191
|
+
|
|
192
|
+
if ((i + 1) % YIELD_EVERY === 0) {
|
|
193
|
+
await yieldToBrowser();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return assets;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Wraps an in-memory effect JSON (e.g. the host's `effectJson`) as an asset. */
|
|
201
|
+
export function createEffectAsset(name: string, path: string, json: unknown): EffectAsset {
|
|
202
|
+
return {id: nextAssetId++, name, path, json, missingFiles: []};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Merges newly imported assets, skipping paths already in the list. */
|
|
206
|
+
export function mergeAssets(
|
|
207
|
+
existing: EffectAsset[],
|
|
208
|
+
incoming: EffectAsset[]
|
|
209
|
+
): {merged: EffectAsset[]; added: EffectAsset[]; skipped: number} {
|
|
210
|
+
const paths = new Set(existing.map((asset) => asset.path));
|
|
211
|
+
const added: EffectAsset[] = [];
|
|
212
|
+
for (const asset of incoming) {
|
|
213
|
+
if (paths.has(asset.path)) continue;
|
|
214
|
+
paths.add(asset.path);
|
|
215
|
+
added.push(asset);
|
|
216
|
+
}
|
|
217
|
+
return {merged: [...existing, ...added], added, skipped: incoming.length - added.length};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Removes one asset, or every asset under a folder path. */
|
|
221
|
+
export function removeAssets(
|
|
222
|
+
assets: EffectAsset[],
|
|
223
|
+
target: {kind: 'asset'; id: number} | {kind: 'folder'; path: string}
|
|
224
|
+
): EffectAsset[] {
|
|
225
|
+
if (target.kind === 'asset') {
|
|
226
|
+
return assets.filter((asset) => asset.id !== target.id);
|
|
227
|
+
}
|
|
228
|
+
const prefix = `${target.path}/`;
|
|
229
|
+
return assets.filter((asset) => !asset.path.startsWith(prefix));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const iconCache = new WeakMap<EffectAsset, string | null>();
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Url of the effect's main texture — the first emitter's material map — used as its icon in
|
|
236
|
+
* the Assets panel. Falls back to the first image; null when the effect has no texture.
|
|
237
|
+
*/
|
|
238
|
+
export function assetIconUrl(asset: EffectAsset): string | null {
|
|
239
|
+
const cached = iconCache.get(asset);
|
|
240
|
+
if (cached !== undefined) {
|
|
241
|
+
return cached;
|
|
242
|
+
}
|
|
243
|
+
const json = asset.json as any;
|
|
244
|
+
const findMaterial = (node: any): string | undefined => {
|
|
245
|
+
if (!node || typeof node !== 'object') return undefined;
|
|
246
|
+
if (node.type === 'ParticleEmitter' && node.ps?.material) return node.ps.material;
|
|
247
|
+
for (const child of Array.isArray(node.children) ? node.children : []) {
|
|
248
|
+
const found = findMaterial(child);
|
|
249
|
+
if (found) return found;
|
|
250
|
+
}
|
|
251
|
+
return undefined;
|
|
252
|
+
};
|
|
253
|
+
const byUuid = (list: unknown, uuid: unknown) =>
|
|
254
|
+
(Array.isArray(list) ? list : []).find((item: any) => item?.uuid === uuid) as any;
|
|
255
|
+
|
|
256
|
+
const material = byUuid(json?.materials, findMaterial(json?.object));
|
|
257
|
+
const texture = byUuid(json?.textures, material?.map ?? material?.texture);
|
|
258
|
+
const image = byUuid(json?.images, texture?.image) ?? (Array.isArray(json?.images) ? json.images[0] : undefined);
|
|
259
|
+
const url = typeof image?.url === 'string' && image.url ? image.url : null;
|
|
260
|
+
iconCache.set(asset, url);
|
|
261
|
+
return url;
|
|
262
|
+
}
|
package/src/core/binding.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {ParticleSystem} from 'babylon.quarks';
|
|
2
1
|
import type {TransformNode} from '@babylonjs/core/Meshes/transformNode';
|
|
3
|
-
import {
|
|
2
|
+
import type {ParticleSystem} from 'babylon.quarks';
|
|
4
3
|
import type {EffectTreeNode} from './effectTree';
|
|
4
|
+
import {buildEffectTree, serializeEffectTree} from './effectTree';
|
|
5
5
|
|
|
6
6
|
export type EditorListener = () => void;
|
|
7
7
|
|
|
@@ -77,6 +77,14 @@ export class EffectBinding {
|
|
|
77
77
|
this.notify();
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Notifies subscribers of a change made outside `apply()` — e.g. a transform edited by the
|
|
82
|
+
* gizmo, or a sub-system edited through its own nested binding.
|
|
83
|
+
*/
|
|
84
|
+
markChanged(): void {
|
|
85
|
+
this.notify();
|
|
86
|
+
}
|
|
87
|
+
|
|
80
88
|
private notify(): void {
|
|
81
89
|
this.revision++;
|
|
82
90
|
for (const listener of this.listeners) {
|
package/src/core/collision.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {Vector3, getPhysicsResolver, setPhysicsResolver} from 'babylon.quarks';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* A horizontal ground plane collider
|
|
5
|
-
*
|
|
6
|
-
* own, so the editor supplies this — the common "particles bounce off the floor" case.
|
|
4
|
+
* A horizontal ground plane collider for hosts/demos that opt in via ensureGroundResolver /
|
|
5
|
+
* setPhysicsResolver. The editor never registers this automatically.
|
|
7
6
|
*
|
|
8
7
|
* `resolve` returns true and fills the surface normal when the point is at or below the plane,
|
|
9
8
|
* which is exactly what ApplyCollision.update reflects the velocity against.
|
|
@@ -21,8 +20,8 @@ export class GroundPlaneResolver {
|
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* Opt-in helper for hosts/demos that want a simple floor collider.
|
|
24
|
+
* The editor does not call this — like Unity, collision needs an explicit host-provided resolver.
|
|
26
25
|
* Idempotent: an already-registered resolver is left untouched and returned.
|
|
27
26
|
*/
|
|
28
27
|
export function ensureGroundResolver(): GroundPlaneResolver {
|
package/src/core/colors.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {ColorOverLife, Gradient, Vector3, Vector4} from 'babylon.quarks';
|
|
2
1
|
import type {Behavior} from 'babylon.quarks';
|
|
2
|
+
import {ColorOverLife, Gradient, Vector3, Vector4} from 'babylon.quarks';
|
|
3
3
|
|
|
4
4
|
/** One RGBA stop of the editable gradient (all channels 0..1, pos 0..1). */
|
|
5
5
|
export interface GradientStop {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {Scene} from '@babylonjs/core/scene';
|
|
2
1
|
import {TransformNode} from '@babylonjs/core/Meshes/transformNode';
|
|
2
|
+
import type {Scene} from '@babylonjs/core/scene';
|
|
3
3
|
import {
|
|
4
4
|
ColorOverLife,
|
|
5
5
|
ConeEmitter,
|
|
@@ -11,9 +11,9 @@ import {
|
|
|
11
11
|
Vector4,
|
|
12
12
|
} from 'babylon.quarks';
|
|
13
13
|
import {DEFAULT_GRADIENT_STOPS, buildGradient} from './colors';
|
|
14
|
-
import type
|
|
14
|
+
import {uniqueEntryName, type SceneEntry} from './sceneEntries';
|
|
15
15
|
|
|
16
|
-
export interface
|
|
16
|
+
export interface CreateSceneDefaultOptions {
|
|
17
17
|
resolveTexture?: (url: string, scene: Scene) => unknown;
|
|
18
18
|
textureUrl?: string;
|
|
19
19
|
}
|
|
@@ -44,31 +44,18 @@ export function createDefaultEffect(
|
|
|
44
44
|
return system;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
/**
|
|
48
|
-
export function
|
|
47
|
+
/** Creates a preset effect as a new scene entry (systems not registered with the renderer yet). */
|
|
48
|
+
export function createSceneDefaultEntry(
|
|
49
49
|
scene: Scene,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const takenNames = new Set(existing.map((entry) => entry.name));
|
|
55
|
-
const takenPaths = new Set(existing.map((entry) => entry.path));
|
|
56
|
-
|
|
57
|
-
let name = existing.length === 0 ? 'Effect' : 'New Effect';
|
|
58
|
-
let suffix = 2;
|
|
59
|
-
while (takenNames.has(name) || takenPaths.has(`_created/${name}.json`)) {
|
|
60
|
-
name = `New Effect ${suffix}`;
|
|
61
|
-
suffix++;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const path = `_created/${name}.json`;
|
|
50
|
+
existing: SceneEntry[],
|
|
51
|
+
options: CreateSceneDefaultOptions = {}
|
|
52
|
+
): SceneEntry {
|
|
53
|
+
const name = uniqueEntryName(existing.length === 0 ? 'Effect' : 'New Effect', existing);
|
|
65
54
|
const system = createDefaultEffect(scene, options.resolveTexture, options.textureUrl);
|
|
66
55
|
system.pause();
|
|
67
56
|
|
|
68
57
|
const root = new TransformNode(name, scene);
|
|
69
58
|
system.emitter.parent = root;
|
|
70
|
-
root.parent = catalogRoot;
|
|
71
|
-
root.setEnabled(false);
|
|
72
59
|
|
|
73
|
-
return {name, path, root, systems: [system]
|
|
60
|
+
return {name, path: `_created/${name}.json`, assetId: null, root, systems: [system]};
|
|
74
61
|
}
|
package/src/core/effectTree.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {ParticleEmitter} from 'babylon.quarks';
|
|
2
|
-
import type {ParticleSystem} from 'babylon.quarks';
|
|
3
|
-
import {TransformNode} from '@babylonjs/core/Meshes/transformNode';
|
|
4
1
|
import {Matrix, Quaternion} from '@babylonjs/core/Maths/math.vector';
|
|
2
|
+
import {TransformNode} from '@babylonjs/core/Meshes/transformNode';
|
|
3
|
+
import type {ParticleSystem} from 'babylon.quarks';
|
|
4
|
+
import {ParticleEmitter} from 'babylon.quarks';
|
|
5
5
|
import {isEditorSceneNode} from './editorScene';
|
|
6
6
|
|
|
7
7
|
/** A node in the editor's effect hierarchy: a Group (organizational) or a ParticleEmitter. */
|
|
@@ -46,7 +46,7 @@ export function collectSystems(tree: EffectTreeNode): ParticleSystem[] {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
interface SerializeMeta {
|
|
49
|
-
textures: {[k: string]: {url?: string; name?: string}};
|
|
49
|
+
textures: {[k: string]: {url?: string; name?: string; invertY?: boolean}};
|
|
50
50
|
materials: {[k: string]: {[key: string]: unknown}};
|
|
51
51
|
geometries: {[k: string]: unknown};
|
|
52
52
|
}
|
|
@@ -72,7 +72,11 @@ function serializeNode(tree: EffectTreeNode, meta: SerializeMeta, fallbackUuid:
|
|
|
72
72
|
children: children.length > 0 ? children : undefined,
|
|
73
73
|
};
|
|
74
74
|
if (tree.system) {
|
|
75
|
-
return {
|
|
75
|
+
return {
|
|
76
|
+
...base,
|
|
77
|
+
type: 'ParticleEmitter',
|
|
78
|
+
ps: tree.system.toJSON(meta as never, {useUrlForImage: true} as never),
|
|
79
|
+
};
|
|
76
80
|
}
|
|
77
81
|
return {...base, type: 'Group'};
|
|
78
82
|
}
|
|
@@ -113,13 +117,24 @@ function finishEnvelope(object: Record<string, unknown>, meta: SerializeMeta): s
|
|
|
113
117
|
// toJSON stashes live Texture instances and material records in meta; flatten them into
|
|
114
118
|
// the serializable images/textures/materials arrays QuarksLoader expects.
|
|
115
119
|
const images: Array<{uuid: string; url: string}> = [];
|
|
116
|
-
const textures: Array<{uuid: string; image?: string}> = [];
|
|
120
|
+
const textures: Array<{uuid: string; image?: string; invertY?: boolean; noMipmap?: boolean}> = [];
|
|
117
121
|
for (const [uuid, tex] of Object.entries(meta.textures)) {
|
|
118
122
|
const url = tex?.url ?? tex?.name;
|
|
123
|
+
const invertY = typeof tex?.invertY === 'boolean' ? tex.invertY : undefined;
|
|
124
|
+
const isEnvAtlas =
|
|
125
|
+
tex?.name === 'quarksEnvAtlas' || (typeof tex?.name === 'string' && tex.name.endsWith('_envAtlas'));
|
|
119
126
|
if (url) {
|
|
120
127
|
const imageUuid = `${uuid}-image`;
|
|
121
128
|
images.push({uuid: imageUuid, url});
|
|
122
|
-
|
|
129
|
+
const entry: {uuid: string; image?: string; invertY?: boolean; noMipmap?: boolean} = {
|
|
130
|
+
uuid,
|
|
131
|
+
image: imageUuid,
|
|
132
|
+
};
|
|
133
|
+
if (invertY === false || isEnvAtlas) {
|
|
134
|
+
entry.invertY = false;
|
|
135
|
+
entry.noMipmap = true;
|
|
136
|
+
}
|
|
137
|
+
textures.push(entry);
|
|
123
138
|
} else {
|
|
124
139
|
textures.push({uuid});
|
|
125
140
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import type {ParticleSystem} from 'babylon.quarks';
|
|
2
1
|
import {Color3} from '@babylonjs/core/Maths/math.color';
|
|
3
2
|
import {Vector3} from '@babylonjs/core/Maths/math.vector';
|
|
4
|
-
import {Mesh} from '@babylonjs/core/Meshes/mesh';
|
|
5
3
|
import {LinesMesh} from '@babylonjs/core/Meshes/linesMesh';
|
|
4
|
+
import {Mesh} from '@babylonjs/core/Meshes/mesh';
|
|
6
5
|
import {MeshBuilder} from '@babylonjs/core/Meshes/meshBuilder';
|
|
7
6
|
import {TransformNode} from '@babylonjs/core/Meshes/transformNode';
|
|
8
7
|
import type {Scene} from '@babylonjs/core/scene';
|
|
9
|
-
import {
|
|
8
|
+
import type {ParticleSystem} from 'babylon.quarks';
|
|
10
9
|
import {EDITOR_SCENE_NODE_METADATA} from './editorScene';
|
|
10
|
+
import './lineShaders';
|
|
11
|
+
import {getShapeType, readShapeParams} from './shapes';
|
|
11
12
|
|
|
12
13
|
const LINE_COLOR = new Color3(0.45, 0.82, 1);
|
|
13
14
|
const DIRECTION_COLOR = new Color3(0.75, 0.92, 1);
|
|
@@ -125,7 +126,11 @@ function buildEmitterWireframe(system: ParticleSystem, scene: Scene): Mesh[] {
|
|
|
125
126
|
for (let i = 0; i <= spokeCount; i++) {
|
|
126
127
|
const theta = (i / spokeCount) * arc;
|
|
127
128
|
const rim = arcPoint(radius, theta);
|
|
128
|
-
const dir = new Vector3(
|
|
129
|
+
const dir = new Vector3(
|
|
130
|
+
Math.sin(angle) * Math.cos(theta),
|
|
131
|
+
Math.sin(angle) * Math.sin(theta),
|
|
132
|
+
Math.cos(angle)
|
|
133
|
+
);
|
|
129
134
|
const travel = preview / Math.max(Math.cos(angle), 0.05);
|
|
130
135
|
lines(`wf-cone-ray-${i}`, [rim, rim.add(dir.scale(travel))], DIRECTION_COLOR);
|
|
131
136
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {StandardMaterial} from '@babylonjs/core/Materials/standardMaterial';
|
|
1
2
|
import {Color3} from '@babylonjs/core/Maths/math.color';
|
|
2
3
|
import {Vector3} from '@babylonjs/core/Maths/math.vector';
|
|
3
|
-
import {StandardMaterial} from '@babylonjs/core/Materials/standardMaterial';
|
|
4
4
|
import {Mesh} from '@babylonjs/core/Meshes/mesh';
|
|
5
5
|
import {MeshBuilder} from '@babylonjs/core/Meshes/meshBuilder';
|
|
6
6
|
import {TransformNode} from '@babylonjs/core/Meshes/transformNode';
|
|
@@ -15,7 +15,11 @@ export class GalleryDropMarker {
|
|
|
15
15
|
|
|
16
16
|
constructor(scene: Scene) {
|
|
17
17
|
this.root = new TransformNode('gallery-drop-root', scene);
|
|
18
|
-
this.disc = MeshBuilder.CreateDisc(
|
|
18
|
+
this.disc = MeshBuilder.CreateDisc(
|
|
19
|
+
'gallery-drop-fill',
|
|
20
|
+
{radius: 1, tessellation: 48, sideOrientation: Mesh.DOUBLESIDE},
|
|
21
|
+
scene
|
|
22
|
+
);
|
|
19
23
|
this.disc.parent = this.root;
|
|
20
24
|
this.disc.rotation.x = Math.PI / 2;
|
|
21
25
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {GalleryEntry} from './loadEffectGallery';
|
|
2
1
|
import {QuarksUtil} from 'babylon.quarks';
|
|
2
|
+
import type {SceneEntry} from './sceneEntries';
|
|
3
3
|
|
|
4
|
-
function isPreviewEntry(entry:
|
|
5
|
-
return
|
|
4
|
+
function isPreviewEntry(entry: SceneEntry, previewRootIds: ReadonlySet<number>): boolean {
|
|
5
|
+
return previewRootIds.has(entry.root.uniqueId);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
/** Freezes every
|
|
8
|
+
/** Freezes every scene entry; unpauses the visible ones (the preview set) when transport is playing. */
|
|
9
9
|
export function applyGalleryPlayback(
|
|
10
|
-
entries:
|
|
10
|
+
entries: SceneEntry[],
|
|
11
11
|
previewRootIds: ReadonlySet<number>,
|
|
12
12
|
transportPlaying: boolean,
|
|
13
13
|
focusFinishedRootIds: ReadonlySet<number> = new Set()
|
|
@@ -36,17 +36,17 @@ export function applyGalleryPlayback(
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/** Whether any preview effect on stage should keep simulating. */
|
|
39
|
-
export function hasActivePreview(entries:
|
|
39
|
+
export function hasActivePreview(entries: SceneEntry[], previewRootIds: ReadonlySet<number>): boolean {
|
|
40
40
|
return entries.some((entry) => isPreviewEntry(entry, previewRootIds));
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/** In-scene preview effects currently in the preview set. */
|
|
44
|
-
export function countActivePreviews(entries:
|
|
44
|
+
export function countActivePreviews(entries: SceneEntry[], previewRootIds: ReadonlySet<number>): number {
|
|
45
45
|
return entries.filter((entry) => isPreviewEntry(entry, previewRootIds)).length;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/** Particle count across all active preview effects. */
|
|
49
|
-
export function countGalleryParticles(entries:
|
|
49
|
+
export function countGalleryParticles(entries: SceneEntry[], previewRootIds: ReadonlySet<number>): number {
|
|
50
50
|
let count = 0;
|
|
51
51
|
for (const entry of entries) {
|
|
52
52
|
if (!isPreviewEntry(entry, previewRootIds)) {
|
|
@@ -64,7 +64,7 @@ export function countGalleryParticles(entries: GalleryEntry[], previewRootIds: R
|
|
|
64
64
|
* Returns true when any entry was paused (caller should refresh renderer batches).
|
|
65
65
|
*/
|
|
66
66
|
export function pauseFinishedPreviews(
|
|
67
|
-
entries:
|
|
67
|
+
entries: SceneEntry[],
|
|
68
68
|
previewRootIds: ReadonlySet<number>,
|
|
69
69
|
focusFinishedRootIds: ReadonlySet<number> = new Set()
|
|
70
70
|
): boolean {
|
package/src/core/galleryScene.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import {Vector3} from '@babylonjs/core/Maths/math.vector';
|
|
2
2
|
import type {Scene} from '@babylonjs/core/scene';
|
|
3
|
-
import type {TransformNode} from '@babylonjs/core/Meshes/transformNode';
|
|
4
3
|
import type {BatchedRenderer} from 'babylon.quarks';
|
|
5
|
-
import type {GalleryEntry} from './loadEffectGallery';
|
|
6
4
|
import {DEFAULT_GALLERY_SPACING, galleryGridPosition} from './galleryLayout';
|
|
5
|
+
import type {SceneEntry} from './sceneEntries';
|
|
7
6
|
|
|
8
|
-
/** Clears live particles and freezes simulation for one
|
|
9
|
-
export function
|
|
7
|
+
/** Clears live particles and freezes simulation for one scene entry. */
|
|
8
|
+
export function clearSceneEntrySimulation(entry: SceneEntry, renderer: BatchedRenderer): void {
|
|
10
9
|
for (const system of entry.systems) {
|
|
11
10
|
system.restart();
|
|
12
11
|
system.pause();
|
|
@@ -14,63 +13,25 @@ export function clearGalleryEntrySimulation(entry: GalleryEntry, renderer: Batch
|
|
|
14
13
|
renderer.refreshBatches();
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
entry.root.parent = null;
|
|
25
|
-
entry.root.position.copyFrom(worldPosition);
|
|
26
|
-
|
|
27
|
-
if (!entry.inScene) {
|
|
28
|
-
for (const system of entry.systems) {
|
|
29
|
-
renderer.addSystem(system);
|
|
30
|
-
system.pause();
|
|
31
|
-
}
|
|
32
|
-
entry.inScene = true;
|
|
16
|
+
/**
|
|
17
|
+
* Shows or hides a scene entry. A hidden entry keeps its place in the scene and stays editable,
|
|
18
|
+
* but has no particles, is not simulated and can't be picked in the viewport.
|
|
19
|
+
*/
|
|
20
|
+
export function setSceneEntryVisible(entry: SceneEntry, renderer: BatchedRenderer, visible: boolean): void {
|
|
21
|
+
if (!visible) {
|
|
22
|
+
clearSceneEntrySimulation(entry, renderer);
|
|
33
23
|
}
|
|
24
|
+
entry.root.setEnabled(visible);
|
|
34
25
|
}
|
|
35
26
|
|
|
36
|
-
/**
|
|
37
|
-
export function
|
|
38
|
-
entries: GalleryEntry[],
|
|
39
|
-
renderer: BatchedRenderer,
|
|
40
|
-
center: Vector3,
|
|
41
|
-
spacing = DEFAULT_GALLERY_SPACING
|
|
42
|
-
): void {
|
|
27
|
+
/** Lays out a batch of new entries in a square grid centered on `center`. */
|
|
28
|
+
export function placeSceneEntriesAt(entries: SceneEntry[], center: Vector3, spacing = DEFAULT_GALLERY_SPACING): void {
|
|
43
29
|
entries.forEach((entry, index) => {
|
|
44
|
-
const offset = galleryGridPosition(index, entries.length, spacing);
|
|
45
|
-
|
|
46
|
-
placeGalleryEntryInScene(entry, renderer, position);
|
|
30
|
+
const offset = entries.length === 1 ? {x: 0, z: 0} : galleryGridPosition(index, entries.length, spacing);
|
|
31
|
+
entry.root.position.copyFrom(center.add(new Vector3(offset.x, 0, offset.z)));
|
|
47
32
|
});
|
|
48
33
|
}
|
|
49
34
|
|
|
50
|
-
/**
|
|
51
|
-
* Unregisters a placed effect from the renderer and returns it to the hidden catalog.
|
|
52
|
-
* Systems stay alive for inspector editing; drag into the viewport to place again.
|
|
53
|
-
*/
|
|
54
|
-
export function removeGalleryEntryFromScene(
|
|
55
|
-
entry: GalleryEntry,
|
|
56
|
-
renderer: BatchedRenderer,
|
|
57
|
-
catalogRoot: TransformNode
|
|
58
|
-
): void {
|
|
59
|
-
if (!entry.inScene) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
clearGalleryEntrySimulation(entry, renderer);
|
|
64
|
-
|
|
65
|
-
for (const system of entry.systems) {
|
|
66
|
-
renderer.deleteSystem(system);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
entry.root.parent = catalogRoot;
|
|
70
|
-
entry.root.setEnabled(false);
|
|
71
|
-
entry.inScene = false;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
35
|
/** Raycasts the editor ground plane from canvas/client coordinates. */
|
|
75
36
|
export function pickGroundPosition(scene: Scene, clientX: number, clientY: number): Vector3 {
|
|
76
37
|
const canvas = scene.getEngine().getRenderingCanvas();
|
|
@@ -81,12 +42,3 @@ export function pickGroundPosition(scene: Scene, clientX: number, clientY: numbe
|
|
|
81
42
|
const pick = scene.pick(clientX - rect.left, clientY - rect.top, (mesh) => mesh.name === 'ground');
|
|
82
43
|
return pick?.pickedPoint?.clone() ?? Vector3.Zero();
|
|
83
44
|
}
|
|
84
|
-
|
|
85
|
-
/** Finds a gallery entry by Babylon node id from a drag payload. */
|
|
86
|
-
export function findGalleryEntryById(entries: GalleryEntry[], id: string): GalleryEntry | undefined {
|
|
87
|
-
const numericId = Number(id);
|
|
88
|
-
if (!Number.isFinite(numericId)) {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
return entries.find((entry) => entry.root.uniqueId === numericId);
|
|
92
|
-
}
|
|
@@ -4,6 +4,7 @@ import {LinesMesh} from '@babylonjs/core/Meshes/linesMesh';
|
|
|
4
4
|
import {MeshBuilder} from '@babylonjs/core/Meshes/meshBuilder';
|
|
5
5
|
import {TransformNode} from '@babylonjs/core/Meshes/transformNode';
|
|
6
6
|
import type {Scene} from '@babylonjs/core/scene';
|
|
7
|
+
import './lineShaders';
|
|
7
8
|
|
|
8
9
|
export const GROUND_RING_RADIUS = 1.2;
|
|
9
10
|
const RING_SEGMENTS = 64;
|
|
@@ -28,7 +29,11 @@ class GroundRingMarker {
|
|
|
28
29
|
|
|
29
30
|
constructor(scene: Scene, name: string, color: Color3) {
|
|
30
31
|
this.anchor = new TransformNode(`${name}-root`, scene);
|
|
31
|
-
this.ring = MeshBuilder.CreateLines(
|
|
32
|
+
this.ring = MeshBuilder.CreateLines(
|
|
33
|
+
`${name}-ring`,
|
|
34
|
+
{points: buildGroundRingPoints(GROUND_RING_RADIUS)},
|
|
35
|
+
scene
|
|
36
|
+
) as LinesMesh;
|
|
32
37
|
this.ring.color = color;
|
|
33
38
|
this.ring.parent = this.anchor;
|
|
34
39
|
this.ring.isPickable = false;
|