Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions editor/src/editor/layout/inspector/script/field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) {

registerUndoRedo({
executeRedo: true,
action: () => props.editor.layout.preview.play.hotReloadScript(props.script.key, false),
undo: () => (props.script[scriptValues][value.propertyKey].value = oldValue),
redo: () => (props.script[scriptValues][value.propertyKey].value = v?.id),
});
Expand All @@ -209,7 +208,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) {
property="value"
label={value.label ?? value.propertyKey}
tooltip={value.configuration.description}
onChange={() => props.editor.layout.preview.play.hotReloadScript(props.script.key, false)}
items={props.editor.layout.preview.scene.animationGroups.map((animationGroup) => ({
text: animationGroup.name,
value: animationGroup.name,
Expand Down Expand Up @@ -255,7 +253,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) {

registerUndoRedo({
executeRedo: true,
action: () => props.editor.layout.preview.play.hotReloadScript(props.script.key, false),
undo: () => (props.script[scriptValues][value.propertyKey].value = oldSerializedTexture),
redo: () => (props.script[scriptValues][value.propertyKey].value = v?.serialize() ?? null),
});
Expand Down Expand Up @@ -310,7 +307,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) {
property="value"
label={value.label ?? value.propertyKey}
tooltip={value.configuration.description}
onChange={() => props.editor.layout.preview.play.hotReloadScript(props.script.key, false)}
/>
);

Expand All @@ -325,7 +321,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) {
max={value.configuration.max}
step={value.configuration.step}
tooltip={value.configuration.description}
onChange={() => props.editor.layout.preview.play.hotReloadScript(props.script.key, false)}
/>
);

Expand All @@ -338,7 +333,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) {
label={value.label ?? value.propertyKey}
tooltip={value.configuration.description}
multiline={(value.configuration as VisibleInInspectorDecoratorStringConfiguration).multiline}
onChange={() => props.editor.layout.preview.play.hotReloadScript(props.script.key, false)}
/>
);

Expand All @@ -363,7 +357,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) {
const scriptCopy = cloneJSObject(props.script);

props.script[scriptValues][value.propertyKey].value = tempVector.value.asArray();
props.editor.layout.preview.play.hotReloadScript(props.script.key, false);
props.script[scriptValues][value.propertyKey].value = scriptCopy[scriptValues][value.propertyKey].value;
}}
onFinishChange={() => {
Expand Down Expand Up @@ -401,7 +394,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) {
const scriptCopy = cloneJSObject(props.script);

props.script[scriptValues][value.propertyKey].value = tempColor.value.asArray();
props.editor.layout.preview.play.hotReloadScript(props.script.key, false);
props.script[scriptValues][value.propertyKey].value = scriptCopy[scriptValues][value.propertyKey].value;
}}
onFinishChange={() => {
Expand All @@ -425,7 +417,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) {
label={value.label ?? value.propertyKey}
onChange={(v) => {
props.script[scriptValues][value.propertyKey].value = v;
props.editor.layout.preview.play.hotReloadScript(props.script.key, false);
}}
/>
);
Expand All @@ -446,7 +437,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) {
label={value.label ?? value.propertyKey}
tooltip={value.configuration.description}
typeRestriction={(value.configuration as VisibleInspectorDecoratorAssetConfiguration).typeRestriction}
onChange={() => props.editor.layout.preview.play.hotReloadScript(props.script.key, false)}
/>
);

Expand Down
89 changes: 3 additions & 86 deletions editor/src/editor/layout/preview/play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ import { Grid } from "react-loader-spinner";

import { IoPlay, IoStop, IoRefresh } from "react-icons/io5";

import { IRegisteredScript } from "babylonjs-editor-tools";
import { Node, Scene, Vector3, HavokPlugin, Sprite } from "babylonjs";
import { Scene, Vector3, HavokPlugin } from "babylonjs";

import { ensureTemporaryDirectoryExists } from "../../../tools/project";

import { isNode } from "../../../tools/guards/nodes";
import { isScene } from "../../../tools/guards/scene";
import { isSprite } from "../../../tools/guards/sprites";
import { wait, waitNextAnimationFrame } from "../../../tools/tools";
import { compilePlayScript } from "../../../tools/scene/play/compile";
import { forceCompileAllSceneMaterials } from "../../../tools/scene/materials";
import { cloneJSObject, wait, waitNextAnimationFrame } from "../../../tools/tools";
import { applyOverrides, restorePlayOverrides } from "../../../tools/scene/play/override";

import { exportProject } from "../../../project/export/export";
Expand Down Expand Up @@ -397,13 +393,7 @@ export class EditorPreviewPlayComponent extends Component<IEditorPreviewPlayComp
if (this.canPlayScene) {
this.props.editor.layout.console.log(`Detected change in ${path}, restarting play...`);
await this._compileScripts();

if (this.props.editor.state.enableExperimentalFeatures) {
const scriptKey = path.replace(nativeJoin(srcPath, "/"), "").replace(/\\/g, "/");
this.hotReloadScript(scriptKey, true);
} else {
await this.restart();
}
await this.restart();
}
});
}
Expand All @@ -412,77 +402,4 @@ export class EditorPreviewPlayComponent extends Component<IEditorPreviewPlayComp
this._srcWatcher?.close();
this._srcWatcher = null;
}

public hotReloadScript(scriptKey: string, compile: boolean): void {
if (!this.scene || !this.state.playing || !this.props.editor.state.enableExperimentalFeatures) {
return;
}

const oldScriptExports = this._compiledScriptExports;
const originalScene = this.props.editor.layout.preview.scene;

const projectDir = dirname(projectConfiguration.path!);
const rootUrl = join(projectDir, "public", "scene", "/");

if (compile) {
this._requireCompiledScripts();
}

if (oldScriptExports) {
Object.assign(this._compiledScriptExports.scriptAssetsCache, oldScriptExports.scriptAssetsCache);
}

const allNodes = [this.scene, ...this.scene.meshes, ...this.scene.transformNodes, ...this.scene.lights, ...this.scene.cameras] as (Node | Scene | Sprite)[];

this.scene.spriteManagers?.forEach((manager) => {
allNodes.push(...manager.sprites);
});

allNodes.forEach((n) => {
const runningScripts = oldScriptExports.scriptsDictionary.get(n) as IRegisteredScript[] | undefined;
if (!runningScripts) {
return;
}

const runningScriptsCopy = runningScripts.slice();

runningScriptsCopy.forEach(async (script) => {
if (script.key !== scriptKey) {
return;
}

oldScriptExports._removeRegisteredScriptInstance(n, script);

let sourceObject: Node | Scene | Sprite | null | undefined;
if (isScene(n)) {
sourceObject = originalScene;
} else if (isNode(n)) {
sourceObject = originalScene.getNodeById(n.id);
} else if (isSprite(n)) {
spriteLoop: for (const manager of originalScene.spriteManagers ?? []) {
for (const sprite of manager.sprites) {
if (sprite.uniqueId === n.uniqueId) {
sourceObject = sprite;
break spriteLoop;
}
}
}
}

const sourceMetadata = sourceObject?.metadata?.scripts?.find((sourceScript) => sourceScript.key === script.key);

if (sourceMetadata) {
n.metadata ??= {};
n.metadata.scripts ??= [];
n.metadata.scripts.push(cloneJSObject(sourceMetadata));
}
});
});

this._compiledScriptExports._preloadScriptsAssets(this.scene, rootUrl).then(() => {
allNodes.forEach((n) => {
this._compiledScriptExports._applyScriptsForObject(this.scene!, n, this._compiledScriptExports.scriptsMap, rootUrl);
});
});
}
}
10 changes: 4 additions & 6 deletions editor/src/project/export/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ export async function processAssetFile(editor: Editor, file: string, options: Pr

let isNewFile = false;

if (options.optimize) {
const fileStat = await stat(file);
const hash = fileStat.mtimeMs.toString();
const fileStat = await stat(file);
const hash = fileStat.mtimeMs.toString();

isNewFile = !options.cache[relativePath] || options.cache[relativePath] !== hash;
isNewFile = !options.cache[relativePath] || options.cache[relativePath] !== hash;

options.cache[relativePath] = hash;
}
options.cache[relativePath] = hash;

const finalPath = join(options.scenePath, relativePath);
const finalPathExists = await pathExists(finalPath);
Expand Down
2 changes: 1 addition & 1 deletion tools/src/loading/script/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function _preloadScriptsAssets(rootUrl: string, scene: Scene, scrip
}

const obj = script.values[key];
if (obj.type === "asset" && obj.value) {
if (obj.type === "asset" && obj.value && !scriptAssetsCache.get(obj.value)) {
scriptAssetsCache.set(obj.value, null);
}
}
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3949,8 +3949,9 @@ babylonjs-editor-tools@latest:
resolved "https://registry.yarnpkg.com/babylonjs-editor-tools/-/babylonjs-editor-tools-5.0.0.tgz#d2e1919cc5d4defbcbcf60259a1eb73a589cf643"
integrity sha512-AREjL0WjtjyOvud0EMG/II3zH73KlSif/u0HV965tPWmUZHrxr+g/4iX6eU0mIYlIjOuepfRAopaF04IYJOaHA==

"babylonjs-editor-tools@link:../../AppData/Local/Yarn/Cache/v6/npm-babylonjs-editor-5.2.4-3cce3a704dc0c4572a85041a993264060376230a-integrity/node_modules/tools":
"babylonjs-editor-tools@link:../../../Library/Caches/Yarn/v6/npm-babylonjs-editor-5.2.4-3cce3a704dc0c4572a85041a993264060376230a-integrity/node_modules/tools":
version "0.0.0"
uid ""

"babylonjs-editor-tools@link:tools":
version "5.2.4"
Expand Down