Upload interiorgen3d/core/scene_graph.py
Browse files
interiorgen3d/core/scene_graph.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Core data structures for InteriorGen3D scene representation.
|
| 3 |
+
"""
|
| 4 |
+
from dataclasses import dataclass, field
|
| 5 |
+
from typing import List, Optional, Dict, Tuple
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@dataclass
|
| 10 |
+
class BoundingBox3D:
|
| 11 |
+
"""3D oriented bounding box for furniture objects."""
|
| 12 |
+
center: np.ndarray
|
| 13 |
+
dimensions: np.ndarray
|
| 14 |
+
rotation: np.ndarray
|
| 15 |
+
confidence: float = 1.0
|
| 16 |
+
|
| 17 |
+
@property
|
| 18 |
+
def corners(self) -> np.ndarray:
|
| 19 |
+
w, h, d = self.dimensions / 2
|
| 20 |
+
corners_local = np.array([
|
| 21 |
+
[-w, -h, -d], [w, -h, -d], [w, h, -d], [-w, h, -d],
|
| 22 |
+
[-w, -h, d], [w, -h, d], [w, h, d], [-w, h, d]
|
| 23 |
+
])
|
| 24 |
+
return (self.rotation @ corners_local.T).T + self.center
|
| 25 |
+
|
| 26 |
+
@property
|
| 27 |
+
def volume(self) -> float:
|
| 28 |
+
return float(np.prod(self.dimensions))
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
@dataclass
|
| 32 |
+
class WallPlane:
|
| 33 |
+
normal: np.ndarray
|
| 34 |
+
offset: float
|
| 35 |
+
height: float
|
| 36 |
+
start_point: np.ndarray
|
| 37 |
+
end_point: np.ndarray
|
| 38 |
+
has_window: bool = False
|
| 39 |
+
has_door: bool = False
|
| 40 |
+
material_id: Optional[str] = None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@dataclass
|
| 44 |
+
class RoomLayout:
|
| 45 |
+
walls: List[WallPlane] = field(default_factory=list)
|
| 46 |
+
floor_height: float = 0.0
|
| 47 |
+
ceiling_height: float = 2.7
|
| 48 |
+
floor_polygon: Optional[np.ndarray] = None
|
| 49 |
+
doors: List[Dict] = field(default_factory=list)
|
| 50 |
+
windows: List[Dict] = field(default_factory=list)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
@dataclass
|
| 54 |
+
class SceneObject:
|
| 55 |
+
object_id: str
|
| 56 |
+
category: str
|
| 57 |
+
bbox: BoundingBox3D
|
| 58 |
+
mesh_path: Optional[str] = None
|
| 59 |
+
texture_paths: Optional[Dict[str, str]] = None
|
| 60 |
+
gaussian_splat_path: Optional[str] = None
|
| 61 |
+
confidence: float = 1.0
|
| 62 |
+
material_type: Optional[str] = None
|
| 63 |
+
is_on_floor: bool = True
|
| 64 |
+
parent_object_id: Optional[str] = None
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@dataclass
|
| 68 |
+
class SpatialRelation:
|
| 69 |
+
subject_id: str
|
| 70 |
+
object_id: str
|
| 71 |
+
relation: str
|
| 72 |
+
confidence: float = 1.0
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
@dataclass
|
| 76 |
+
class SceneGraph:
|
| 77 |
+
room_layout: RoomLayout
|
| 78 |
+
objects: List[SceneObject] = field(default_factory=list)
|
| 79 |
+
relations: List[SpatialRelation] = field(default_factory=list)
|
| 80 |
+
camera_pose: Optional[np.ndarray] = None
|
| 81 |
+
camera_intrinsics: Optional[np.ndarray] = None
|
| 82 |
+
metric_scale: float = 1.0
|
| 83 |
+
|
| 84 |
+
def get_object(self, object_id: str) -> Optional[SceneObject]:
|
| 85 |
+
for obj in self.objects:
|
| 86 |
+
if obj.object_id == object_id:
|
| 87 |
+
return obj
|
| 88 |
+
return None
|
| 89 |
+
|
| 90 |
+
def get_objects_by_category(self, category: str) -> List[SceneObject]:
|
| 91 |
+
return [obj for obj in self.objects if obj.category == category]
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
@dataclass
|
| 95 |
+
class PBRMaterial:
|
| 96 |
+
albedo_map: Optional[np.ndarray] = None
|
| 97 |
+
metallic_map: Optional[np.ndarray] = None
|
| 98 |
+
roughness_map: Optional[np.ndarray] = None
|
| 99 |
+
normal_map: Optional[np.ndarray] = None
|
| 100 |
+
base_color: Tuple[float, float, float] = (0.8, 0.8, 0.8)
|
| 101 |
+
metallic: float = 0.0
|
| 102 |
+
roughness: float = 0.5
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
@dataclass
|
| 106 |
+
class GeneratedScene:
|
| 107 |
+
scene_graph: SceneGraph
|
| 108 |
+
room_mesh_path: str
|
| 109 |
+
object_meshes: Dict[str, str]
|
| 110 |
+
materials: Dict[str, PBRMaterial]
|
| 111 |
+
gaussian_splat_path: Optional[str] = None
|
| 112 |
+
export_paths: Dict[str, str] = field(default_factory=dict)
|
| 113 |
+
generation_time_seconds: float = 0.0
|
| 114 |
+
metadata: Dict = field(default_factory=dict)
|