diff --git a/packages/engine/src/HedronEngine.ts b/packages/engine/src/HedronEngine.ts index 975084cd..49560e5d 100644 --- a/packages/engine/src/HedronEngine.ts +++ b/packages/engine/src/HedronEngine.ts @@ -36,7 +36,11 @@ export class HedronEngine { public async initiateSketchModules(moduleIds: string[]) { for (const moduleId of moduleIds) { - await this.addSketchModule(moduleId) + try { + await this.addSketchModule(moduleId) + } catch (error) { + console.error('Init error in: ' + moduleId, error) + } } this.store.setState({ isSketchModulesReady: true }) @@ -108,6 +112,7 @@ export class HedronEngine { if (instance.getPasses) { instance.getPasses(debugScene).forEach((pass) => { + pass.name = sketch.id debugScene.addPass(pass) }) } diff --git a/packages/engine/src/world/EngineScene.ts b/packages/engine/src/world/EngineScene.ts index 33da678a..0750f8a1 100644 --- a/packages/engine/src/world/EngineScene.ts +++ b/packages/engine/src/world/EngineScene.ts @@ -25,7 +25,15 @@ export class EngineScene { this.passes.push(pass) } + removePass(pass: Pass): void { + this.passes = this.passes.filter((p) => p !== pass) + } + clearPasses(): void { this.passes = [this.renderPass] } + + getPassesByName(name: string): Pass[] { + return this.passes.filter((pass) => pass.name === name) + } } diff --git a/packages/engine/src/world/SketchManager.ts b/packages/engine/src/world/SketchManager.ts index 6a7314c1..34677d76 100644 --- a/packages/engine/src/world/SketchManager.ts +++ b/packages/engine/src/world/SketchManager.ts @@ -35,14 +35,21 @@ export class SketchManager { } public removeSketchFromScene = (instanceId: string): void => { - const scene = getDebugScene().scene - const oldSketch = scene.getObjectByName(instanceId) + const engineScene = getDebugScene() + const threeScene = engineScene.scene + const oldSketch = threeScene.getObjectByName(instanceId) if (!oldSketch) { + const pass = engineScene.getPassesByName(instanceId) + if (pass?.length) { + pass.forEach((p) => engineScene.removePass(p)) + delete this.sketchInstances[instanceId] + return + } throw new Error(`couldn't find sketch to remove: ${instanceId}`) } - scene.remove(oldSketch) + threeScene.remove(oldSketch) delete this.sketchInstances[instanceId] }