I/O¶
Mesh loading and saving through Trimesh.
load_meshreads a mesh file (PLY, OBJ, STL and the other formats Trimesh supports).save_meshwrites a mesh; for PLY it switches to double-precision vertices when float32 would round the coordinates (georeferenced models far from the origin).validate_inputschecks that the files a preprocessing run needs exist (meshes, and the EPW for the modes that read one).load_meshesloads the maximum volume and the test surfaces, and reports coordinates that a float32 PLY file has rounded.
urbansolarcarver.io
¶
Mesh file input and output, and the preprocessing inputs.
load_mesh reads a mesh file (PLY, OBJ, STL...) into a trimesh mesh;
save_mesh writes one, switching PLY to double-precision vertices when
float32 would round georeferenced coordinates. validate_inputs checks
that the files a preprocessing run needs exist, and load_meshes loads
the maximum volume and the test surfaces, reporting coordinates that a
float32 file has rounded; load_optional_mesh loads the optional context
and terrain meshes.
load_mesh(path, fix_normals=True)
¶
Load a triangle mesh from file.
trimesh's default processing on load removes NaN/inf vertices and merges
duplicate vertices; it does not fix winding or remove degenerate faces.
fix_normals is then called: it makes the face winding consistent
across connected faces, and for watertight meshes it also turns each
closed body that is stored inside out so its normals point outward.
With fix_normals False that step is left out (for meshes whose face
orientation nothing reads, such as context and terrain: it takes seconds
on large meshes).
Raises:
| Type | Description |
|---|---|
InputError
|
If path is not a file, if trimesh cannot parse it, or if it has no triangles (empty, or only points or curves). Without the last check the problem would only show up later as an empty voxel grid. |
load_optional_mesh(path, name)
¶
Load an optional input mesh (context, terrain), or None when there is none.
No path gives None. A file without triangles counts as absent: it is
reported as a <name>_empty issue and gives None, so the run behaves as
without it. A missing or unreadable file raises InputError. The faces are
kept as stored: neither the column rule nor the ray test reads their
orientation, and fixing it takes seconds on large meshes.
float32_resolution(coords)
¶
Spacing between adjacent float32 values at the largest |coordinate|.
save_mesh(mesh, path)
¶
Save a mesh to disk, creating the output directory if needed, and return the absolute file path.
The format follows the file extension. PLY is written with float64
vertices when float32 spacing at the largest coordinate exceeds 1 mm
(as with georeferenced coordinates), and GLB with its offset in the node
(save_glb); otherwise trimesh's exporter is used. STL can only hold
float32 vertices, so a float32_coordinates issue is reported when that
rounds them by more than 1 mm.
save_glb(named_meshes, path)
¶
Write the (name, mesh) pairs as one GLB scene, one node each (a name of None lets trimesh name it).
glTF is Y-up, so the meshes are written turned by USC_TO_GLTF. glTF stores vertices as float32, which rounds georeferenced coordinates by up to half a metre; every mesh is therefore moved by the same whole-metre offset near the scene's lowest corner (chosen in USC coordinates), and each node's translation, that offset turned to glTF axes and a double in the file's JSON, moves it back, so readers place the vertices exactly.
validate_inputs(settings)
¶
Validate file paths and supported modes.
Raises:
| Type | Description |
|---|---|
InputError
|
If the max-volume or test-surface mesh is missing, a context or terrain path is given and its file is missing, or the EPW file is missing for a mode that needs one. |
ValueError
|
If |
load_meshes(settings)
¶
Load the maximum envelope mesh and the insolation sampling surface.
Warns when a PLY file stores large (georeferenced) coordinates as float32, because that rounding happened on disk and cannot be undone here.
Returns:
| Name | Type | Description |
|---|---|---|
envelope_mesh |
Trimesh
|
|
insolation_mesh |
Trimesh
|
|