import { Text } from '@react-three/drei'; import * as THREE from 'three'; import type { Room3D } from '../../lib/layoutApi'; import { PlantPosition, VisMode, COLORS } from './types'; import { SmartRack } from './SmartRack'; // Convert pixel coordinates to world units (same as SmartRack) const SCALE = 0.1; // Mock environment data const getMockRoomEnv = (roomName: string) => { const hash = roomName.split('').reduce((a, b) => a + b.charCodeAt(0), 0); return { temp: 68 + (hash % 15), humidity: 40 + (hash % 40), }; }; const lerpColor = (c1: string, c2: string, t: number) => { const c1c = new THREE.Color(c1); const c2c = new THREE.Color(c2); return '#' + c1c.lerp(c2c, Math.min(1, Math.max(0, t))).getHexString(); }; interface RoomObjectProps { room: Room3D; visMode: VisMode; onPlantClick: (plant: PlantPosition) => void; highlightedTags?: string[]; dimMode?: boolean; } export function RoomObject({ room, visMode, onPlantClick, highlightedTags, dimMode }: RoomObjectProps) { const env = getMockRoomEnv(room.name); // Scale room dimensions to world units const scaledRoom = { posX: room.posX * SCALE, posY: room.posY * SCALE, width: room.width * SCALE, height: room.height * SCALE, }; let floorColor: string = COLORS.ROOM_FLOOR; if (visMode === 'TEMP') { const t = (env.temp - 65) / 20; floorColor = t < 0.5 ? lerpColor(COLORS.TEMP_LOW, COLORS.TEMP_OPTIMAL, t * 2) : lerpColor(COLORS.TEMP_OPTIMAL, COLORS.TEMP_HIGH, (t - 0.5) * 2); } else if (visMode === 'HUMIDITY') { const t = (env.humidity - 40) / 40; floorColor = t < 0.5 ? lerpColor(COLORS.HUMIDITY_DRY, COLORS.HUMIDITY_OPTIMAL, t * 2) : lerpColor(COLORS.HUMIDITY_OPTIMAL, COLORS.HUMIDITY_WET, (t - 0.5) * 2); } return ( {room.name} {(visMode === 'TEMP' || visMode === 'HUMIDITY') && ( {visMode === 'TEMP' ? `${env.temp}°F` : `${env.humidity}%`} )} {room.sections.map(section => ( ))} ); }