Add furniture click events, OrbitControls toggle, and floor change event
- Export COLORS for external module access (themes) - Extend _onClick to detect furniture clicks before room clicks, dispatching 'furnitureclick' with catalog/room/mesh details - Add setControlsEnabled(enabled) to toggle OrbitControls - Dispatch 'floorchange' event from showFloor() - Wire up furnitureclick in index.html to show item info
This commit is contained in:
@@ -151,6 +151,11 @@
|
||||
viewer.addEventListener('roomclick', (e) => {
|
||||
selectRoom(e.detail.roomId);
|
||||
});
|
||||
|
||||
viewer.addEventListener('furnitureclick', (e) => {
|
||||
const d = e.detail;
|
||||
document.getElementById('info').textContent = `${d.itemName} — in ${renderer.getRooms().find(r => r.id === d.roomId)?.name || d.roomId}`;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as THREE from 'three';
|
||||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
||||
|
||||
const COLORS = {
|
||||
export const COLORS = {
|
||||
wall: {
|
||||
exterior: 0xe8e0d4,
|
||||
interior: 0xf5f0eb
|
||||
@@ -151,6 +151,14 @@ export class HouseRenderer {
|
||||
}
|
||||
|
||||
this._placeFurnitureForFloor();
|
||||
|
||||
this.container.dispatchEvent(new CustomEvent('floorchange', {
|
||||
detail: { index, floor }
|
||||
}));
|
||||
}
|
||||
|
||||
setControlsEnabled(enabled) {
|
||||
this.controls.enabled = enabled;
|
||||
}
|
||||
|
||||
_clearFloor() {
|
||||
@@ -506,9 +514,23 @@ export class HouseRenderer {
|
||||
|
||||
for (const hit of intersects) {
|
||||
let obj = hit.object;
|
||||
while (obj && !obj.userData.roomId) {
|
||||
// Walk up to find furniture or room group
|
||||
while (obj && !obj.userData.isFurniture && !obj.userData.roomId) {
|
||||
obj = obj.parent;
|
||||
}
|
||||
if (obj && obj.userData.isFurniture) {
|
||||
this.container.dispatchEvent(new CustomEvent('furnitureclick', {
|
||||
detail: {
|
||||
catalogId: obj.userData.catalogId,
|
||||
roomId: obj.userData.roomId,
|
||||
itemName: obj.userData.itemName,
|
||||
wallMounted: obj.userData.wallMounted,
|
||||
mesh: obj,
|
||||
point: hit.point
|
||||
}
|
||||
}));
|
||||
return;
|
||||
}
|
||||
if (obj && obj.userData.roomId) {
|
||||
this.highlightRoom(obj.userData.roomId);
|
||||
this.container.dispatchEvent(new CustomEvent('roomclick', {
|
||||
|
||||
Reference in New Issue
Block a user