trimesh.exchange.ply
- trimesh.exchange.ply.add_attributes_to_data_array(data_array, attributes)
Parses attribute data in to a custom array, assumes datatype has been defined appropriately
- Parameters
data_array (numpy array with custom datatype) – datatype reflects all the data to be stored for a given ply element
attributes (dict) – contains all the attributes to parse
- Returns
data_array
- Return type
numpy array with custom datatype
- trimesh.exchange.ply.add_attributes_to_dtype(dtype, attributes)
Parses attribute datatype to populate a numpy dtype list
- Parameters
dtype (list of numpy datatypes) – operated on in place
attributes (dict) – contains all the attributes to parse
- Returns
dtype
- Return type
list of numpy datatypes
- trimesh.exchange.ply.add_attributes_to_header(header, attributes)
Parses attributes in to ply header entries
- Parameters
header (list of ply header entries) – operated on in place
attributes (dict) – contains all the attributes to parse
- Returns
header – Contains ply header entries
- Return type
list
- trimesh.exchange.ply.assert_attributes_valid(attributes)
Asserts that a set of attributes is valid for PLY export.
- Parameters
attributes (dict) – Contains the attributes to validate
- Raises
ValueError – If passed attributes aren’t valid.
- trimesh.exchange.ply.element_colors(element)
Given an element, try to extract RGBA color from properties and return them as an (n,3|4) array.
- Parameters
element (dict) – Containing color keys
- Returns
colors ((n, 3) or (n, 4) float) – Colors extracted from the element
signal (float) – Estimate of range
- trimesh.exchange.ply.elements_to_kwargs(elements, fix_texture, image, prefer_color=None)
Given an elements data structure, extract the keyword arguments that a Trimesh object constructor will expect.
- Parameters
elements (OrderedDict object) – With fields and data loaded
fix_texture (bool) – If True, will re- index vertices and faces so vertices with different UV coordinates are disconnected.
image (PIL.Image) – Image to be viewed
prefer_color (None, 'vertex', or 'face') – Which kind of color to prefer if both defined
- Returns
kwargs – Keyword arguments for Trimesh constructor
- Return type
dict
- trimesh.exchange.ply.export_draco(mesh, bits=28)
Export a mesh using Google’s Draco compressed format.
Only works if draco_encoder is in your PATH: https://github.com/google/draco
- Parameters
mesh (Trimesh object) – Mesh to export
bits (int) – Bits of quantization for position tol.merge=1e-8 is roughly 25 bits
- Returns
data – DRC file bytes
- Return type
str or bytes
- trimesh.exchange.ply.export_ply(mesh, encoding='binary', vertex_normal=None, include_attributes=True)
Export a mesh in the PLY format.
- Parameters
mesh (trimesh.Trimesh) – Mesh to export.
encoding (str) – PLY encoding: ‘ascii’ or ‘binary_little_endian’
vertex_normal (None or include vertex normals) –
- Returns
export
- Return type
bytes of result
- trimesh.exchange.ply.load_draco(file_obj, **kwargs)
Load a mesh from Google’s Draco format.
- Parameters
file_obj (file- like object) – Contains data
- Returns
kwargs – Keyword arguments to construct a Trimesh object
- Return type
dict
- trimesh.exchange.ply.load_element_different(properties, data)
Load elements which include lists of different lengths based on the element’s property-definitions.
- Parameters
properties (dict) – Property definitions encoded in a dict where the property name is the key and the property data type the value.
data (array) – Data rows for this element.
- trimesh.exchange.ply.load_element_single(properties, data)
Load element data with lists of a single length based on the element’s property-definitions.
- Parameters
properties (dict) – Property definitions encoded in a dict where the property name is the key and the property data type the value.
data (array) – Data rows for this element. If the data contains list-properties, all lists belonging to one property must have the same length.
- trimesh.exchange.ply.load_ply(file_obj, resolver=None, fix_texture=True, prefer_color=None, *args, **kwargs)
Load a PLY file from an open file object.
- Parameters
file_obj (an open file- like object) – Source data, ASCII or binary PLY
resolver (trimesh.visual.resolvers.Resolver) – Object which can resolve assets
fix_texture (bool) – If True, will re- index vertices and faces so vertices with different UV coordinates are disconnected.
prefer_color (None, 'vertex', or 'face') – Which kind of color to prefer if both defined
- Returns
mesh_kwargs – Data which can be passed to Trimesh constructor, eg: a = Trimesh(**mesh_kwargs)
- Return type
dict
- trimesh.exchange.ply.numpy_type_to_ply_type(numpy_type)
Returns the closest ply equivalent of a numpy type
- Parameters
numpy_type (a numpy datatype) –
- Returns
ply_type
- Return type
string
- trimesh.exchange.ply.parse_header(file_obj)
Read the ASCII header of a PLY file, and leave the file object at the position of the start of data but past the header.
- Parameters
file_obj (open file object) – Positioned at the start of the file
- Returns
elements (collections.OrderedDict) – Fields and data types populated
is_ascii (bool) – Whether the data is ASCII or binary
image_name (None or str) – File name of TextureFile
- trimesh.exchange.ply.ply_ascii(elements, file_obj)
Load data from an ASCII PLY file into an existing elements data structure.
- Parameters
elements (OrderedDict) – Populated from the file header, data will be added in-place to this object
file_obj (file-like-object) – Current position at the start of the data section (past the header).
- trimesh.exchange.ply.ply_binary(elements, file_obj)
Load the data from a binary PLY file into the elements data structure.
- Parameters
elements (OrderedDict) – Populated from the file header. Object will be modified to add data by this function.
file_obj (open file object) – With current position at the start of the data section (past the header)