From c2428ca3ccdbcae03924b34fd71c2ad67081609d Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Sun, 19 Apr 2026 20:23:07 +0900 Subject: [PATCH] fix --- packages/frontend/src/world/room/engine.ts | 1 + packages/frontend/src/world/room/object.ts | 2 ++ .../src/world/room/objects/tabletopDigitalClock.ts | 5 +++-- .../frontend/src/world/room/objects/wallClock.ts | 5 +++-- packages/frontend/src/world/room/previewEngine.ts | 12 +++++++++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/frontend/src/world/room/engine.ts b/packages/frontend/src/world/room/engine.ts index 79c0655cc6..a17ddcfcdf 100644 --- a/packages/frontend/src/world/room/engine.ts +++ b/packages/frontend/src/world/room/engine.ts @@ -1090,6 +1090,7 @@ export class RoomEngine extends EventEmitter { options: args.options, model, id: args.id, + timer: this.timer, // TODO: 家具が撤去された後も動作し続けるのをどうにかする stickyMarkerMeshUpdated: (mesh) => { // TODO //// stickyな子の位置を更新 diff --git a/packages/frontend/src/world/room/object.ts b/packages/frontend/src/world/room/object.ts index 9f2717c7d5..466ae4b473 100644 --- a/packages/frontend/src/world/room/object.ts +++ b/packages/frontend/src/world/room/object.ts @@ -6,6 +6,7 @@ import * as BABYLON from '@babylonjs/core'; import type { RoomEngine } from './engine.js'; import type { ModelManager } from './utility.js'; +import type { Timer } from '../utility.js'; // babylonのドメイン知識は持たない export type RoomStateObject = { @@ -105,6 +106,7 @@ export type ObjectDef = { options: Readonly>; model: ModelManager; id: string; + timer: Timer; stickyMarkerMeshUpdated?: (mesh: BABYLON.Mesh) => void; }) => RoomObjectInstance> | Promise>>; // TODO: createInstanceをasyncにするのではなく、別にreadyみたいなものを返させる }; diff --git a/packages/frontend/src/world/room/objects/tabletopDigitalClock.ts b/packages/frontend/src/world/room/objects/tabletopDigitalClock.ts index 81403a7bd1..f6060ce838 100644 --- a/packages/frontend/src/world/room/objects/tabletopDigitalClock.ts +++ b/packages/frontend/src/world/room/objects/tabletopDigitalClock.ts @@ -34,7 +34,7 @@ export const tabletopDigitalClock = defineObject({ }, placement: 'top', hasCollisions: false, - createInstance: ({ root, room, options, model, scene }) => { + createInstance: ({ root, room, options, model, scene, timer }) => { const light = new BABYLON.SpotLight('', new BABYLON.Vector3(0, cm(3), cm(1)), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null); light.parent = root; light.intensity = 0.01 * WORLD_SCALE * WORLD_SCALE; @@ -100,7 +100,8 @@ export const tabletopDigitalClock = defineObject({ applyBodyColor(); applyLcdColor(); - room.timer.setInterval(() => { + // TODO: 家具が撤去された後も呼ばれ続けるのをどうにかする + timer.setInterval(() => { const onMeshes = get7segMeshesOfCurrentTime(segmentMeshes); for (const mesh of Object.values(segmentMeshes)) { diff --git a/packages/frontend/src/world/room/objects/wallClock.ts b/packages/frontend/src/world/room/objects/wallClock.ts index c367faebe5..b57a137004 100644 --- a/packages/frontend/src/world/room/objects/wallClock.ts +++ b/packages/frontend/src/world/room/objects/wallClock.ts @@ -22,7 +22,7 @@ export const wallClock = defineObject({ }, placement: 'side', hasCollisions: false, - createInstance: ({ room, root, options, model }) => { + createInstance: ({ room, timer, options, model }) => { const hourHand = model.findMesh('HandH'); const minuteHand = model.findMesh('HandM'); @@ -39,7 +39,8 @@ export const wallClock = defineObject({ return { onInited: () => { - room.timer.setInterval(() => { + // TODO: 家具が撤去された後も呼ばれ続けるのをどうにかする + timer.setInterval(() => { const now = new Date(); const hours = now.getHours() % 12; const minutes = now.getMinutes(); diff --git a/packages/frontend/src/world/room/previewEngine.ts b/packages/frontend/src/world/room/previewEngine.ts index b286213eb6..b351e26858 100644 --- a/packages/frontend/src/world/room/previewEngine.ts +++ b/packages/frontend/src/world/room/previewEngine.ts @@ -6,7 +6,7 @@ import * as BABYLON from '@babylonjs/core'; import { registerBuiltInLoaders } from '@babylonjs/loaders/dynamic.js'; import { GridMaterial } from '@babylonjs/materials'; -import { camelToKebab, WORLD_SCALE, cm, getMeshesBoundingBox } from '../utility.js'; +import { camelToKebab, WORLD_SCALE, cm, getMeshesBoundingBox, Timer } from '../utility.js'; import { getObjectDef } from './object-defs.js'; import { SYSTEM_MESH_NAMES, ModelManager } from './utility.js'; import type { RoomObjectInstance } from './object.js'; @@ -32,6 +32,7 @@ export class RoomObjectPreviewEngine { private envMapIndoor: BABYLON.CubeTexture; private roomLight: BABYLON.SpotLight; private zGridPreviewPlane: BABYLON.Mesh; + private timerForEachObject: Timer | null = null; private fps = 60; constructor(options: { @@ -219,6 +220,11 @@ export class RoomObjectPreviewEngine { } }); + if (this.timerForEachObject != null) { + this.timerForEachObject.dispose(); + } + this.timerForEachObject = new Timer(); + const objectInstance = await def.createInstance({ room: null, scene: this.scene, @@ -226,6 +232,7 @@ export class RoomObjectPreviewEngine { options: args.options, model, id: args.id, + timer: this.timerForEachObject, }); objectInstance.onInited?.(); @@ -245,6 +252,9 @@ export class RoomObjectPreviewEngine { } public destroy() { + if (this.timerForEachObject != null) { + this.timerForEachObject.dispose(); + } this.engine.dispose(); } }