""" All inertial objects are captured in this class. """
from typing import Union
import numpy as np
import bpy
from mathutils import Matrix
from blenderproc.python.types.EntityUtility import Entity
# as all attributes are accessed via the __getattr__ and __setattr__ in this module, we need to remove the member
# init check
# pylint: disable=no-member
[docs]
class Inertial(Entity):
"""
Every instance of this class is an inertial object which is usually part of an URDFObject.
"""
def __init__(self, bpy_object: bpy.types.Object):
super().__init__(bpy_object=bpy_object)
object.__setattr__(self, "inertia", None)
object.__setattr__(self, "mass", None)
object.__setattr__(self, "origin", None)
[docs]
def set_inertia(self, inertia: np.ndarray):
""" Sets inertia value.
:param inertia: 3x3 symmetric rotational inertia matrix.
"""
assert inertia.shape == (3, 3)
object.__setattr__(self, "inertia", inertia)
[docs]
def get_inertia(self) -> np.ndarray:
""" Returns the inertia.
:return: The inertia matrix.
"""
return self.inertia
[docs]
def set_mass(self, mass: float):
""" Sets the mass.
:param mass: Mass of the link in kilograms.
"""
object.__setattr__(self, "mass", mass)
[docs]
def get_mass(self) -> float:
""" Returns the mass of the link.
:return: The mass.
"""
return self.mass
[docs]
def set_origin(self, origin: Union[np.ndarray, Matrix]):
""" Sets the origin and the world matrix of the inertia.
:param origin: 4x4 matrix of the inertials relative to the link frame.
"""
object.__setattr__(self, "origin", Matrix(origin))
self.blender_obj.matrix_world = Matrix(origin)
[docs]
def get_origin(self) -> Matrix:
""" Returns the origin of the inertia.
:return: The pose relative to the link frame.
"""
return self.origin
[docs]
def hide(self, hide_object: bool = True):
""" Sets the visibility of the object.
:param hide_object: Determines whether the object should be hidden in rendering.
"""
self.blender_obj.hide_render = hide_object
# pylint: enable=no-member