trimesh.exchange.ply module

Functions

element_colors(element)

Given an element, try to extract RGBA color from properties and return them as an (n,3|4) array.

elements_to_kwargs(elements, fix_texture, image)

Given an elements data structure, extract the keyword arguments that a Trimesh object constructor will expect.

export_draco(mesh[, bits])

Export a mesh using Google’s Draco compressed format.

export_ply(mesh[, encoding, vertex_normal])

Export a mesh in the PLY format.

load_draco(file_obj, **kwargs)

Load a mesh from Google’s Draco format.

load_element_different(properties, data)

Load elements which include lists of different lengths based on the element’s property-definitions.

load_element_single(properties, data)

Load element data with lists of a single length based on the element’s property-definitions.

load_ply(file_obj[, resolver, fix_texture, …])

Load a PLY file from an open file object.

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.

ply_ascii(elements, file_obj)

Load data from an ASCII PLY file into an existing elements data structure.

ply_binary(elements, file_obj)

Load the data from a binary PLY file into the elements data structure.

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|4))

  • 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)

Export a mesh in the PLY format.

Parameters
  • mesh (Trimesh object) –

  • encoding (['ascii'|'binary_little_endian']) –

  • vertex_normal (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.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 object, 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)

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)