From f2be8a21695d8052786e83976dec83a655e4052f Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Sat, 4 Apr 2026 16:57:52 +0900 Subject: [PATCH] Update engine.ts --- packages/frontend/src/utility/room/engine.ts | 32 +++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/frontend/src/utility/room/engine.ts b/packages/frontend/src/utility/room/engine.ts index c1c954bcef..dac1d6dc97 100644 --- a/packages/frontend/src/utility/room/engine.ts +++ b/packages/frontend/src/utility/room/engine.ts @@ -637,17 +637,9 @@ export class RoomEngine { watch(this.isEditMode, (v) => { if (v) { - // 選択した後選択解除して再度選択しようとするとエラーになる - //this.selectionOutlineLayer = new BABYLON.SelectionOutlineLayer('outliner', this.scene); - for (const entity of this.objectEntities.values()) { entity.instance.resetTemporaryState?.(); } - } else { - if (this.selectionOutlineLayer != null) { - this.selectionOutlineLayer.dispose(); - this.selectionOutlineLayer = null; - } } }); @@ -726,7 +718,7 @@ export class RoomEngine { public selectObject(objectId: string | null) { if (this.selected.value != null) { - if (this.selectionOutlineLayer != null) this.selectionOutlineLayer.clearSelection(); + this.clearHighlight(); this.selected.value.objectEntity.model.bakeMesh(); this.selected.value = null; } @@ -735,7 +727,7 @@ export class RoomEngine { const entity = this.objectEntities.get(objectId); if (entity != null) { if (this.isEditMode.value) entity.model.unbakeMesh(); - if (this.selectionOutlineLayer != null) this.selectionOutlineLayer.addSelection(entity.rootMesh.getChildMeshes()); + this.highlightMeshes(entity.rootMesh.getChildMeshes()); const state = this.roomState.installedObjects.find(o => o.id === objectId)!; this.selected.value = { objectId, @@ -1039,10 +1031,7 @@ export class RoomEngine { const model = new ModelManager(subRoot, loaderResult.meshes.filter(m => m !== subRoot), (meshes) => { if (this.selected.value?.objectId === args.id) { - if (this.selectionOutlineLayer != null) { - this.selectionOutlineLayer.clearSelection(); - this.selectionOutlineLayer.addSelection(meshes); - } + this.highlightMeshes(meshes); } for (const m of meshes) { @@ -1102,11 +1091,24 @@ export class RoomEngine { return { root, objectInstance }; } + private highlightMeshes(meshes: BABYLON.AbstractMesh[]) { + this.clearHighlight(); + this.selectionOutlineLayer = new BABYLON.SelectionOutlineLayer('outliner', this.scene); + this.selectionOutlineLayer.addSelection(meshes); + } + + private clearHighlight() { + if (this.selectionOutlineLayer != null) { + this.selectionOutlineLayer.dispose(); + this.selectionOutlineLayer = null; + } + } + public beginSelectedInstalledObjectGrabbing() { if (this.selected.value == null) return; const selectedObject = this.selected.value.objectEntity.rootMesh; - if (this.selectionOutlineLayer != null) this.selectionOutlineLayer.clearSelection(); + this.clearHighlight(); // 子から先に適用していく const setStickyParentRecursively = (mesh: BABYLON.AbstractMesh) => {