This commit is contained in:
syuilo
2026-02-15 11:02:21 +09:00
parent 52a1b30503
commit 9f0fbb8531
4 changed files with 36 additions and 18 deletions

View File

@@ -10,13 +10,14 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkButton @click="toggleLight">Toggle Light</MkButton>
<MkButton :primary="engine.isEditMode.value" @click="toggleEditMode">Edit mode: {{ engine.isEditMode.value ? 'on' : 'off' }}</MkButton>
<template v-if="engine.isEditMode.value">
<MkButton @click="grab">Grab</MkButton>
<MkButton @click="grab">Grab (E)</MkButton>
<MkButton :primary="engine.enableGridSnapping.value" @click="toggleGridSnapping">Grid Snap: {{ engine.enableGridSnapping.value ? 'on' : 'off' }}</MkButton>
<MkButton v-if="engine.enableGridSnapping.value" :primary="engine.gridSnappingScale.value === 1" @click="engine.gridSnappingScale.value = 1">Snap: 1cm</MkButton>
<MkButton v-if="engine.enableGridSnapping.value" :primary="engine.gridSnappingScale.value === 2" @click="engine.gridSnappingScale.value = 2">Snap: 2cm</MkButton>
<MkButton v-if="engine.enableGridSnapping.value" :primary="engine.gridSnappingScale.value === 4" @click="engine.gridSnappingScale.value = 4">Snap: 4cm</MkButton>
<MkButton v-if="engine.enableGridSnapping.value" :primary="engine.gridSnappingScale.value === 8" @click="engine.gridSnappingScale.value = 8">Snap: 8cm</MkButton>
</template>
<MkButton v-if="engine.isSitting.value" @click="engine.standUp()">降りる (Q)</MkButton>
</div>
</div>
</template>
@@ -172,6 +173,11 @@ onMounted(() => {
type: 'wall-clock',
position: [-150, 200, 100],
rotation: [0, -Math.PI / 2, 0],
}, {
id: 's2',
type: 'wood-sound-absorbing-panel',
position: [-150, 140, 80],
rotation: [0, -Math.PI / 2, 0],
}, {
id: 't',
type: 'book',

View File

@@ -302,6 +302,9 @@ const OBJECTS = {
'round-rug': {
placement: 'floor',
},
'wood-sound-absorbing-panel': {
placement: 'side',
},
} as Record<string, ObjectDef>;
const _assumedFramesPerSecond = 60;
@@ -711,8 +714,8 @@ export class RoomEngine {
ev.stopPropagation();
if (this.isEditMode.value) {
this.toggleGrab();
} else {
this.interact();
} else if (this.selectedObjectId != null) {
this.interact(this.selectedObjectId);
}
} else if (ev.code === 'KeyR') {
ev.preventDefault();
@@ -720,6 +723,12 @@ export class RoomEngine {
if (this.grabbing != null) {
this.grabbing.rotation += Math.PI / 8;
}
} else if (ev.code === 'KeyQ') {
ev.preventDefault();
ev.stopPropagation();
if (this.isSitting.value) {
this.standUp();
}
}
});
@@ -1244,28 +1253,31 @@ export class RoomEngine {
});
}
private interact() {
if (this.selectedObjectId == null) return;
const o = this.def.objects.find(o => o.id === this.selectedObjectId)!;
private interact(oid: string) {
const o = this.def.objects.find(o => o.id === oid)!;
const mesh = this.objectMeshs.get(o.id)!;
const objDef = OBJECTS[o.type];
if (objDef.isChair) {
if (this.isSitting.value) {
this.isSitting.value = false;
this.scene.activeCamera = this.camera;
this.fixedCamera.parent = null;
} else {
this.isSitting.value = true;
this.fixedCamera.parent = this.objectMeshs.get(o.id);
this.fixedCamera.position = new BABYLON.Vector3(0, 120/*cm*/, 0);
this.fixedCamera.rotation = new BABYLON.Vector3(0, 0, 0);
this.scene.activeCamera = this.fixedCamera;
}
this.sitChair(o.id);
}
}
public sitChair(objectId: string) {
this.isSitting.value = true;
this.fixedCamera.parent = this.objectMeshs.get(objectId);
this.fixedCamera.position = new BABYLON.Vector3(0, 120/*cm*/, 0);
this.fixedCamera.rotation = new BABYLON.Vector3(0, 0, 0);
this.scene.activeCamera = this.fixedCamera;
this.selectObject(null);
}
public standUp() {
this.isSitting.value = false;
this.scene.activeCamera = this.camera;
this.fixedCamera.parent = null;
}
private turnOnRoomLight() {
this.roomLight.intensity = 300000;
this.envMapIndoor.level = 0.3;