pyblenderSDIC.meshes.TriangleMesh3D.from_dict#

classmethod TriangleMesh3D.from_dict(data: Dict[str, Any]) TriangleMesh3D[source]#

Create a TriangleMesh3D instance from a dictionary.

The dictionary should contain the following keys:

  • “vertices”: A list of lists representing the coordinates of the mesh vertices.

  • “triangles”: A list of lists representing the indices of the vertices that form each triangle.

  • “uvmap”: Optional; A list of lists representing the UV coordinates for each triangle in the mesh.

  • “vertex_normals”: Optional; A list of lists representing the normals of the vertices in the mesh.

  • “triangle_normals”: Optional; A list of lists representing the normals of the triangles in the mesh.

  • “triangle_centroids”: Optional; A list of lists representing the centroids of the triangles in the mesh.

  • “triangle_areas”: Optional; A list representing the areas of the triangles in the mesh.

  • “bounding_box”: Optional; A list of two lists representing the bounding box of the mesh, where the first list contains the minimum coordinates and the second list contains the maximum coordinates in each dimension.

  • “volume”: Optional; A float representing the volume of the mesh.

from pyblenderSDIC.mesh import TriangleMesh3D

# Create a TriangleMesh3D instance from a dictionary
data = {
    "vertices": [[0, 0, 0], [1, 0, 0], [0, 1, 0]],
    "triangles": [[0, 1, 2]],
    "uvmap": [[0, 0, 1, 0, 0, 1]],
    "vertex_normals": [[0, 0, 1], [0, 0, 1], [0, 0, 1]],
    "triangle_normals": [[0, 0, 1]],
    "triangle_centroids": [[0.333, 0.333, 0]],
    "triangle_areas": [0.5],
    "bounding_box": [[0, 0, 0], [1, 1, 0]],
    "volume": None
}
mesh = TriangleMesh3D.from_dict(data)

If a key is not present in the dictionary, the corresponding attribute will be set to None. All other keys are ignored.

Note

The values of the dictionary should be convertible to NumPy arrays. They are expected by default to be lists of lists in order to be readable from JSON or similar formats.

Parameters:

data (Dict[str, Any]) – A dictionary containing the mesh data.

Returns:

A TriangleMesh3D instance created from the dictionary.

Return type:

TriangleMesh3D