Skip to content

Commit 7e2f215

Browse files
committed
fix: don't save animation groups from scene links
add node in workers when editing scene in separate window
1 parent 060a176 commit 7e2f215

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

editor/src/editor/nodes/scene-link.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join, dirname } from "path/posix";
22

3-
import { GetClass, Matrix, Node, Scene, SerializationHelper, serialize, Tools, TransformNode } from "babylonjs";
3+
import { GetClass, Matrix, Node, Scene, SerializationHelper, serialize, Tools, TransformNode, Tags } from "babylonjs";
44

55
import { UniqueNumber } from "../../tools/tools";
66

@@ -64,6 +64,10 @@ export class SceneLinkNode extends TransformNode {
6464
this._lastLoadResult?.cameras.forEach((camera) => !camera.parent && (camera.parent = this));
6565
this._lastLoadResult?.transformNodes.forEach((transformNode) => !transformNode.parent && (transformNode.parent = this));
6666

67+
this._lastLoadResult.animationGroups.forEach((animationGroup) => {
68+
Tags.AddTagsTo(animationGroup, "from-scene-link");
69+
});
70+
6771
return this._lastLoadResult;
6872
}
6973

editor/src/editor/window.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export async function createCustomWindow(indexPath: string, options: any): Promi
138138
height: 800,
139139
webPreferences: {
140140
nodeIntegration: true,
141+
nodeIntegrationInWorker: true,
141142
contextIsolation: process.env.DEBUG !== "true",
142143
preload: join(app.getAppPath(), "build/src/editor/windows/preload.js"),
143144
},

editor/src/project/save/scene.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import { Editor } from "../../editor/main";
99

1010
import { isSceneLinkNode } from "../../tools/guards/scene";
1111
import { applyAssetsCache } from "../../tools/assets/cache";
12-
import { isFromSceneLink } from "../../tools/scene/scene-link";
1312
import { isNodeVisibleInGraph } from "../../tools/node/metadata";
1413
import { getBufferSceneScreenshot } from "../../tools/scene/screenshot";
1514
import { createDirectoryIfNotExist, normalizedGlob } from "../../tools/fs";
1615
import { isSpriteManagerNode, isSpriteMapNode } from "../../tools/guards/sprites";
1716
import { isGPUParticleSystem, isParticleSystem } from "../../tools/guards/particles";
1817
import { serializePhysicsAggregate } from "../../tools/physics/serialization/aggregate";
19-
import { isCollisionMesh, isEditorCamera, isMesh, isTransformNode } from "../../tools/guards/nodes";
18+
import { isAnimationGroupFromSceneLink, isFromSceneLink } from "../../tools/scene/scene-link";
19+
import { isAnyTransformNode, isCollisionMesh, isEditorCamera, isMesh, isTransformNode } from "../../tools/guards/nodes";
2020

2121
import { vlsPostProcessCameraConfigurations } from "../../editor/rendering/vls";
2222
import { saveRenderingConfigurationForCamera } from "../../editor/rendering/tools";
@@ -308,7 +308,7 @@ export async function saveScene(editor: Editor, projectPath: string, scenePath:
308308
// Write transform nodes
309309
await Promise.all(
310310
scene.transformNodes.map(async (transformNode) => {
311-
if (!isTransformNode(transformNode)) {
311+
if (!isTransformNode(transformNode) || isFromSceneLink(transformNode)) {
312312
return;
313313
}
314314

@@ -513,6 +513,11 @@ export async function saveScene(editor: Editor, projectPath: string, scenePath:
513513
scene.particleSystems.map(async (particleSystem) => {
514514
const particleSystemPath = join(scenePath, "particleSystems", `${particleSystem.id}.json`);
515515

516+
const emitter = particleSystem.emitter;
517+
if (emitter && isAnyTransformNode(emitter) && isFromSceneLink(emitter)) {
518+
return;
519+
}
520+
516521
try {
517522
const data = particleSystem.serialize(true);
518523

@@ -537,6 +542,10 @@ export async function saveScene(editor: Editor, projectPath: string, scenePath:
537542
// Write animation groups
538543
await Promise.all(
539544
scene.animationGroups?.map(async (animationGroup) => {
545+
if (isAnimationGroupFromSceneLink(animationGroup)) {
546+
return;
547+
}
548+
540549
const animationGroupPath = join(scenePath, "animationGroups", `${filenamify(animationGroup.name)}_${animationGroup.uniqueId}.json`);
541550

542551
try {
@@ -555,7 +564,7 @@ export async function saveScene(editor: Editor, projectPath: string, scenePath:
555564
// Write sprite maps
556565
await Promise.all(
557566
scene.transformNodes.map(async (transformNode) => {
558-
if (!isSpriteMapNode(transformNode)) {
567+
if (!isSpriteMapNode(transformNode) || isFromSceneLink(transformNode)) {
559568
return;
560569
}
561570

@@ -583,7 +592,7 @@ export async function saveScene(editor: Editor, projectPath: string, scenePath:
583592
// Write sprite managers
584593
await Promise.all(
585594
scene.transformNodes.map(async (transformNode) => {
586-
if (!isSpriteManagerNode(transformNode)) {
595+
if (!isSpriteManagerNode(transformNode) || isFromSceneLink(transformNode)) {
587596
return;
588597
}
589598

editor/src/tools/scene/scene-link.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join, dirname, basename } from "path/posix";
22

3-
import { Node } from "babylonjs";
3+
import { Node, AnimationGroup, Tags } from "babylonjs";
44

55
import { Editor } from "../../editor/main";
66
import { SceneLinkNode } from "../../editor/nodes/scene-link";
@@ -41,6 +41,13 @@ export function isFromSceneLink(node: Node) {
4141
return false;
4242
}
4343

44+
/**
45+
* Returns whether or not the given animation group comes from a SceneLinkNode instance.
46+
*/
47+
export function isAnimationGroupFromSceneLink(animationGroup: AnimationGroup) {
48+
return Tags.MatchesQuery(animationGroup, "from-scene-link");
49+
}
50+
4451
/**
4552
* Returns the firt root SceneLinkNode found for the given node.
4653
* In case the node is not from a scene link, "null" is returned.

0 commit comments

Comments
 (0)