io

Module Contents

Classes

FileEncoding

Create a collection of name/value pairs.

LoadOptions

SaveOptions

Functions

load_mesh(filename[, triangulate, load_normals, ...])

Load mesh from a file.

load_scene(filename[, options])

Load a scene.

load_simple_scene(filename[, triangulate, search_path])

Load a simple scene from file.

mesh_to_string(mesh[, format, binary, exact_match, ...])

Convert a mesh to a binary string based on specified format.

save_mesh(filename, mesh[, binary, exact_match, ...])

Save mesh to file.

save_scene(filename, scene[, options])

Save a scene.

save_simple_scene(filename, scene[, binary])

Save a simple scene to file.

scene_to_string(scene, format[, binary, exact_match, ...])

Convert a scene to a binary string based on specified format.

string_to_mesh(data[, triangulate])

Convert a binary string to a mesh.

string_to_scene(data[, triangulate])

Convert a binary string to a scene.

class io.FileEncoding(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

Ascii = 1
Binary = 0
class io.LoadOptions
property load_materials: bool
Return type:

bool

property load_normals: bool
Return type:

bool

property load_object_ids: bool
Return type:

bool

property load_tangents: bool
Return type:

bool

property load_uvs: bool
Return type:

bool

property load_vertex_colors: bool
Return type:

bool

property load_weights: bool
Return type:

bool

property search_path: pathlib.Path
Return type:

pathlib.Path

property triangulate: bool
Return type:

bool

class io.SaveOptions
class AttributeConversionPolicy(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

ConvertAsNeeded = 1
ExactMatchOnly = 0
class OutputAttributes(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

All = 0
SelectedOnly = 1
property attribute_conversion_policy: SaveOptions
Return type:

SaveOptions

property embed_images: bool
Return type:

bool

property encoding: FileEncoding
Return type:

FileEncoding

property output_attributes: SaveOptions
Return type:

SaveOptions

property selected_attributes: list[int]
Return type:

list[int]

io.load_mesh(filename, triangulate=False, load_normals=True, load_tangents=True, load_uvs=True, load_weights=True, load_materials=True, load_vertex_colors=True, load_object_ids=True, load_images=True, stitch_vertices=False, search_path=...)

Load mesh from a file.

Parameters:
  • filename (str | os.PathLike) – The input file name.

  • triangulate (bool) – Whether to triangulate the mesh if it is not already triangulated. Defaults to False.

  • load_normals (bool) – Whether to load vertex normals from mesh if available. Defaults to True.

  • load_tangents (bool) – Whether to load tangents and bitangents from mesh if available. Defaults to True.

  • load_uvs (bool) – Whether to load texture coordinates from mesh if available. Defaults to True.

  • load_weights (bool) – Whether to load skinning weights attributes from mesh if available. Defaults to True.

  • load_materials (bool) – Whether to load material ids from mesh if available. Defaults to True.

  • load_vertex_colors (bool) – Whether to load vertex colors from mesh if available. Defaults to True.

  • load_object_id – Whether to load object ids from mesh if available. Defaults to True.

  • load_images (bool) – Whether to load external images if available. Defaults to True.

  • stitch_vertices (bool) – Whether to stitch vertices based on position. Defaults to False.

  • search_path (str | os.PathLike) – Optional search path for external references (e.g. .mtl, .bin, etc.). Defaults to None.

  • load_object_ids (bool)

Return SurfaceMesh:

The mesh object extracted from the input string.

Return type:

lagrange.core.SurfaceMesh

io.load_scene(filename, options=...)

Load a scene.

Parameters:
  • filename (str | os.PathLike) – The input file name.

  • options (LoadOptions) – Load scene options. Check the class for more details.

Return Scene:

The loaded scene object.

Return type:

lagrange.scene.Scene

io.load_simple_scene(filename, triangulate=False, search_path=None)

Load a simple scene from file.

Parameters:
  • filename (str | os.PathLike) – The input file name.

  • triangulate (bool) – Whether to triangulate the scene if it is not already triangulated. Defaults to False.

  • search_path (str | os.PathLike | None) – Optional search path for external references (e.g. .mtl, .bin, etc.). Defaults to None.

Return SimpleScene:

The scene object extracted from the input string.

Return type:

lagrange.scene.SimpleScene3D

io.mesh_to_string(mesh, format='ply', binary=True, exact_match=True, selected_attributes=None)

Convert a mesh to a binary string based on specified format.

Parameters:
  • mesh (lagrange.core.SurfaceMesh) – The input mesh.

  • format (str) – Format to use. Supported formats are “obj”, “ply”, “gltf” and “msh”.

  • binary (bool) – Whether to save the mesh in binary format if supported. Defaults to True. Only msh, ply and glb support binary format.

  • exact_match (bool) – Whether to save attributes in their exact form. Some mesh formats may not support all the attribute types. If set to False, attributes will be converted to the closest supported attribute type. Defaults to True.

  • selected_attributes (collections.abc.Sequence[int] | None) – A list of attribute ids to save. If not specified, all attributes will be saved. Defaults to None.

Return str:

The string representing the input mesh.

Return type:

bytes

io.save_mesh(filename, mesh, binary=True, exact_match=True, selected_attributes=None)

Save mesh to file.

Filename extension determines the file format. Supported formats are: obj, ply, msh, glb and gltf.

Parameters:
  • filename (str | os.PathLike) – The output file name.

  • mesh (lagrange.core.SurfaceMesh) – The input mesh.

  • binary (bool) – Whether to save the mesh in binary format if supported. Defaults to True. Only msh, ply and glb support binary format.

  • exact_match (bool) – Whether to save attributes in their exact form. Some mesh formats may not support all the attribute types. If set to False, attributes will be converted to the closest supported attribute type. Defaults to True.

  • selected_attributes (collections.abc.Sequence[int] | None) – A list of attribute ids to save. If not specified, all attributes will be saved. Defaults to None.

Return type:

None

io.save_scene(filename, scene, options=...)

Save a scene.

Parameters:
  • filename (str | os.PathLike) – The output file name.

  • scene (lagrange.scene.Scene) – The scene to save.

  • options (SaveOptions) – Save options. Check the class for more details.

Return type:

None

io.save_simple_scene(filename, scene, binary=True)

Save a simple scene to file.

Parameters:
  • filename (str | os.PathLike) – The output file name.

  • scene (lagrange.scene.SimpleScene3D) – The input scene.

  • binary (bool) – Whether to save the scene in binary format if supported. Defaults to True. Only glb supports binary format.

Return type:

None

io.scene_to_string(scene, format, binary=True, exact_match=True, embed_images=False, selected_attributes=None)

Convert a scene to a binary string based on specified format.

Parameters:
  • scene (lagrange.scene.Scene) – The input scene.

  • format (str) – Format to use. Supported formats are “gltf” and “glb”.

  • binary (bool) – Whether to save the scene in binary format if supported. Defaults to True. Only glb supports binary format.

  • exact_match (bool) – Whether to save attributes in their exact form. Some mesh formats may not support all the attribute types. If set to False, attributes will be converted to the closest supported attribute type. Defaults to True.

  • selected_attributes (collections.abc.Sequence[int] | None) – A list of attribute ids to save. If not specified, all attributes will be saved. Defaults to None.

  • embed_images (bool)

Return str:

The string representing the input scene.

Return type:

bytes

io.string_to_mesh(data, triangulate=False)

Convert a binary string to a mesh.

The binary string should use one of the supported formats. Supported formats include obj, ply, gltf, glb, fbx and msh. Format is automatically detected.

Parameters:
  • data (bytes) – A binary string representing the mesh data in a supported format.

  • triangulate (bool) – Whether to triangulate the mesh if it is not already triangulated. Defaults to False.

Return SurfaceMesh:

The mesh object extracted from the input string.

Return type:

lagrange.core.SurfaceMesh

io.string_to_scene(data, triangulate=False)

Convert a binary string to a scene.

The binary string should use one of the supported formats (i.e. gltf, glb and fbx).

Parameters:
  • data (bytes) – A binary string representing the scene data in a supported format.

  • triangulate (bool) – Whether to triangulate the scene if it is not already triangulated. Defaults to False.

Return Scene:

The scene object extracted from the input string.

Return type:

lagrange.scene.Scene