voxcity.importer.rhino_objΒΆ
Public entry point: add buildings from an OBJ file to a VoxCity model.
FunctionsΒΆ
|
Voxelize buildings from an OBJ file and stamp them into a VoxCity model. |
Module ContentsΒΆ
- voxcity.importer.rhino_obj.add_buildings_from_obj(voxcity, obj_path, anchor_lonlat, anchor_elevation, anchor_model_point=(0.0, 0.0, 0.0), rotation=0.0, move=(0.0, 0.0, 0.0), units='m', roles=None, backend='trimesh', z_up=True, swap_yz=False, overwrite=True, auto_window=True, window_keywords=None, window_value=-16, gridvis=False)[source]ΒΆ
Voxelize buildings from an OBJ file and stamp them into a VoxCity model.
Loads geometry groups from obj_path, selects the groups whose resolved role is
"building", places them into the VoxCity domain using an anchor lon/lat + elevation (plus optional rotation/translation/unit scaling), voxelizes each building group, and stamps the resulting cells into a copy of voxcity. The input voxcity is never mutated; this function always returns a new object. See docs/rhino_obj_import.md for the Rhino export guide and conventions.- Parameters:
voxcity β source VoxCity object. Read for its grid geometry (
extras['rectangle_vertices']), voxel shape, DEM, and existing building grids; never mutated. A deep copy is made internally and returned (with buildings stamped in), or returned unmodified (still a deep copy) if no in-domain geometry is found.obj_path β path to the OBJ file to import. Must exist on disk; checked before any other validation.
anchor_lonlat β
(lon, lat)pair giving the geographic position thatanchor_model_pointis placed at. Must have exactly 2 elements.anchor_elevation β elevation (metres) of
anchor_model_pointin the real world. Combined with the VoxCity DEM minimum to fix the vertical (Z) placement of the model.anchor_model_point β
(x, y, z)point in OBJ model coordinates (in units, pre-scale) that is pinned toanchor_lonlat/anchor_elevation. Defaults to the model origin(0.0, 0.0, 0.0).rotation β rotation in degrees applied to the model in the horizontal (east/north) plane before placement. Positive values rotate the model counter-clockwise; e.g. at
rotation=90, model +X ends up pointing north. Defaults to0.0(no rotation).move β
(east, north, up)offset in metres applied after anchoring, e.g. for fine-tuning placement without changing the anchor. Defaults to(0.0, 0.0, 0.0)(no offset).units β model length unit, used to scale OBJ coordinates to metres. One of
"m","cm","mm","ft","in"(case-insensitive). Defaults to"m".roles β optional
{group_name: role}mapping overriding the auto-detected role of a group. Recognized roles:"building"(voxelized solid as-3),"window"(surface-voxelized and stamped as glass-16on the building facade it touches), and"skip"(excluded). Matching is exact-string only. Groups absent from this mapping are auto-classified (seeauto_window).backend β voxelization backend.
"trimesh"(default) usesvoxelize_mesh()(column z-ray casting)."meshlib"uses the optionalvoxelize_mesh_meshlib()SDF backend, which requires the optionalmeshlibpackage to be installed (see Raises below); this backend is best-effort and not empirically verified against a real MeshLib install (see that functionβs docstring for details).z_up β whether the OBJβs vertical axis is already Z-up (Rhinoβs convention), the default (
True). WhenFalse, the loaded mesh is treated as Y-up and axes 1/2 (Y/Z) are swapped before placement, equivalent to settingswap_yz=True.swap_yz β if
True, force an explicit Y/Z axis swap on the loaded geometry regardless ofz_up. Defaults toFalse. The effective swap applied isswap_yz or (not z_up).overwrite β if
True(default), newly stamped building voxels overwrite any existing non-empty voxel at that cell (and the collision is counted/logged). IfFalse, only cells that are currently empty are stamped; already-occupied cells are left untouched.auto_window β if
True(default), groups whose name or assigned OBJ material name contains a window keyword (seewindow_keywords) are auto-classified as"window". An explicitrolesentry always overrides this.window_keywords β optional iterable of case-insensitive substrings used for window auto-detection.
None(default) uses("window", "glass", "glazing").window_value β voxel code written for window cells. Defaults to
-16(the standard glass code).gridvis β if
True, after stamping, display a quick-look 2D visualization of the post-import building height grid. Purely a debugging aid; failures in the visualization step (including a missing/broken plotting backend) are swallowed silently. Defaults toFalse.
- Returns:
A new VoxCity object with the imported buildings stamped in (or an unmodified deep copy of voxcity if no building-role geometry was found, or none of it voxelized to cells inside the domain). The voxcity argument passed in is never mutated.
- Raises:
FileNotFoundError β if obj_path does not exist.
ValueError β if units is not one of the recognized unit strings, if backend is not
"trimesh"or"meshlib", or if anchor_lonlat does not have exactly 2 elements.ImportError β if
backend="meshlib"is requested but the optionalmeshlibpackage is not installed.