trimesh.units

units.py

Deal with physical unit systems (i.e. inches, mm)

Very basic conversions, and no requirement for sympy.physics.units or pint.

trimesh.units.keys() set

Return a set containing all currently valid units.

Returns:

All units with conversions i.e. {‘in’, ‘m’, …}

Return type:

keys

trimesh.units.to_inch(unit: str) float

Calculate the conversion to an arbitrary common unit.

Parameters:

unit – Either a key in units_to_inches.json or in the simple {float} * {str} form, i.e. “1.2 * meters”. We don’t support arbitrary eval of any math string

Returns:

Factor to multiply by to get to an inch system.

Return type:

conversion

trimesh.units.unit_conversion(current: str, desired: str) float

Calculate the conversion from one set of units to another.

Parameters:
  • current (str) – Unit system values are in now (eg ‘millimeters’)

  • desired (str) – Unit system we’d like values in (eg ‘inches’)

Returns:

conversion – Number to multiply by to put values into desired units

Return type:

float

trimesh.units.units_from_metadata(obj: Geometry, guess: bool = True) str

Try to extract hints from metadata and if that fails guess based on the object scale.

Parameters:
  • obj – A geometry object.

  • guess – If metadata doesn’t have units make a “best guess”

Returns:

A guess of what the units might be

Return type:

units