def m44Decompose(m=('Matrix44Pin', pyrr.Matrix44()), t=("Reference", ('FloatVector3Pin', pyrr.Vector3())), r=("Reference", ('QuatPin', pyrr.Quaternion())), s=("Reference", ('FloatVector3Pin', pyrr.Vector3()))): '''Decomposes an affine transformation matrix into its scale, rotation and translation components.''' _s, _r, _t = pyrr.matrix44.decompose(m) t(pyrr.Vector3(_t)) r(pyrr.Quaternion(_r)) s(pyrr.Vector3(_s))
def m44Decompose(m=(DataTypes.Matrix44, pyrr.Matrix44()), t=(DataTypes.Reference, (DataTypes.FloatVector3, pyrr.Vector3())), r=(DataTypes.Reference, (DataTypes.Quaternion, pyrr.Quaternion())), s=(DataTypes.Reference, (DataTypes.FloatVector3, pyrr.Vector3()))): '''Decomposes an affine transformation matrix into its scale, rotation and translation components.''' _s, _r, _t = pyrr.matrix44.decompose(m) t(pyrr.Vector3(_t)) r(pyrr.Quaternion(_r)) s(pyrr.Vector3(_s))
def asDataTypeClass(self): return pyrr.Quaternion([ self.dsbX.value(), self.dsbY.value(), self.dsbZ.value(), self.dsbW.value() ])
def __init__(self, dataset_settings, obj_class='', name=''): super(AnnotatedObjectInfo, self).__init__() self.name = name self.obj_class = obj_class self.object_settings = dataset_settings.get_object_settings( obj_class) if not (dataset_settings is None) else None self.location = pyrr.Vector3() self.cuboid_center = None self.quaternion = pyrr.Quaternion([0.0, 0.0, 0.0, 1.0]) # self.bb2d = BoundingBox() self.cuboid2d = None self.keypoints = [] if not (self.object_settings is None): self.dimension = self.object_settings.cuboid_dimension self.cuboid3d = copy.deepcopy(self.object_settings.cuboid3d) if ( not self.object_settings is None) else None self.mesh = Mesh(self.object_settings.mesh_file_path) self.mesh.set_initial_matrix(self.object_settings.initial_matrix) self.pivot_axis = self.object_settings.pivot_axis else: self.dimension = None self.cuboid3d = None self.mesh = None self.pivot_axis = None self.is_modified = False self.relative_transform = transform3d()
def quatPower(q=('QuatPin', pyrr.Quaternion()), exp=('FloatPin', 0.0), result=("Reference", ('BoolPin', False))): '''Returns a new Quaternion representing this Quaternion to the power of the exponent. Checks for identify quaternion''' try: powered = q.power(exp) result(True) return powered except: result(False)
def quatPower(q=(DataTypes.Quaternion, pyrr.Quaternion()), exp=(DataTypes.Float, 0.0), result=(DataTypes.Reference, (DataTypes.Bool, False))): '''Returns a new Quaternion representing this Quaternion to the power of the exponent. Checks for identify quaternion''' try: powered = q.power(exp) result(True) return powered except: result(False)
def test_imports(self): import pyrr pyrr.Quaternion() pyrr.quaternion.Quaternion() pyrr.objects.quaternion.Quaternion() from pyrr import Quaternion from pyrr.objects import Quaternion from pyrr.objects.quaternion import Quaternion
def rotation(self, value): value = np.asanyarray(value, dtype='f4') if isinstance(value, pyrr.Quaternion): self._rotation = value.astype('f4') elif isinstance(value, (np.ndarray, collections.Iterable)): value = np.asanyarray(value, dtype='f4') if value.shape in ((3, 3), (4, 4)): self._rotation = pyrr.Quaternion.from_matrix(value, dtype='f4') elif value.shape == (3,): self._rotation = pyrr.Quaternion.from_eulers(pyrr.euler.create(*value, dtype='f4')) elif value.shape == (4,): self._rotation = pyrr.Quaternion(value, dtype='f4') else: raise ValueError(f"unexpected shape {value.shape} for rotation") else: raise ValueError(f"unexpected type {type(value)} for rotation") self._rotation.flags.writeable = False self.dirty = True
class QuatLib(FunctionLibraryBase): '''doc string for QuatLib''' def __init__(self): super(QuatLib, self).__init__() @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion()), nodeType=NodeTypes.Pure, meta={'Category': 'Math|Quaternion', 'Keywords': []}) def zeroQuat(): '''Returns zero quaternion.''' return pyrr.Quaternion() @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion.from_x_rotation(0.0)), nodeType=NodeTypes.Pure, meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatFromXRotation(theta=(DataTypes.Float, 0.0)): '''Creates a new Quaternion with a rotation around the X-axis.''' return pyrr.Quaternion.from_x_rotation(theta) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion.from_y_rotation(0.0)), nodeType=NodeTypes.Pure, meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatFromYRotation(theta=(DataTypes.Float, 0.0)): '''Creates a new Quaternion with a rotation around the Y-axis.''' return pyrr.Quaternion.from_y_rotation(theta) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion.from_z_rotation(0.0)), nodeType=NodeTypes.Pure, meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatFromZRotation(theta=(DataTypes.Float, 0.0)): '''Creates a new Quaternion with a rotation around the Z-axis.''' return pyrr.Quaternion.from_z_rotation(theta) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion.from_matrix(pyrr.Matrix33())), nodeType=NodeTypes.Pure, meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatFromMatrix33(m=(DataTypes.Matrix33, pyrr.Matrix33())): '''Creates a Quaternion from the specified Matrix33.''' return pyrr.Quaternion.from_matrix(m) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion.from_matrix(pyrr.Matrix44())), nodeType=NodeTypes.Pure, meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatFromMatrix44(m=(DataTypes.Matrix44, pyrr.Matrix44())): '''Creates a Quaternion from the specified Matrix44.''' return pyrr.Quaternion.from_matrix(m) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion()), nodeType=NodeTypes.Pure, meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatFromEulers(a=(DataTypes.Float, 0.0), b=(DataTypes.Float, 0.0), c=(DataTypes.Float, 0.0)): '''Creates a Quaternion from the specified Euler angles.''' return pyrr.Quaternion.from_eulers([a, b, c]) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion()), nodeType=NodeTypes.Pure, meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatFromInverseOfEulers(a=(DataTypes.Float, 0.0), b=(DataTypes.Float, 0.0), c=(DataTypes.Float, 0.0)): '''Creates a Quaternion from the specified Euler angles.''' return pyrr.Quaternion.from_inverse_of_eulers([a, b, c]) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion()), nodeType=NodeTypes.Pure, meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatFromAxisRotation(a=(DataTypes.Float, 0.0), b=(DataTypes.Float, 0.0), c=(DataTypes.Float, 0.0), theta=(DataTypes.Float, 0.0)): '''Creates a new Quaternion with a rotation around the specified axis.''' return pyrr.Quaternion.from_axis_rotation([a, b, c], theta) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.FloatVector3, pyrr.Vector3()), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatApplyToVector(q=(DataTypes.Quaternion, pyrr.Quaternion()), v=(DataTypes.FloatVector3, pyrr.Vector3())): '''Rotates a vector by a quaternion.''' return pyrr.Vector3(pyrr.quaternion.apply_to_vector(quat=q, vec=v)) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Float, 0.0), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatX(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the x component of the quat.''' return q.x @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Float, 0.0), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatY(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the y component of the quat.''' return q.y @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Float, 0.0), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatZ(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the z component of the quat.''' return q.z @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Float, 0.0), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatW(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the w component of the quat.''' return q.w @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Float, 0.0), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatAngle(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the angle around the axis of rotation of this Quaternion as a float.''' return q.angle @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.FloatVector3, pyrr.Vector3()), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatAxis(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the axis of rotation of this Quaternion as a Vector3.''' return q.axis @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion()), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatConjugate(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the conjugate of this Quaternion.\nThis is a Quaternion with the opposite rotation.''' return q.conjugate @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion()), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatCross(q=(DataTypes.Quaternion, pyrr.Quaternion()), other=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the cross of this Quaternion and another.\nThis is the equivalent of combining Quaternion rotations (like Matrix multiplication).''' return q.cross(other) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion()), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatInverse(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the inverse of this quaternion.''' return q.inverse @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Bool, False), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatIsIdentity(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns True if the Quaternion has no rotation (0.,0.,0.,1.).''' return q.is_identity @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Float, False), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatLength(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the length of this Quaternion.''' return q.length @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Float, False), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatSquaredLength(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Calculates the squared length of a quaternion.\nUseful for avoiding the performanc penalty of the square root function.''' return pyrr.quaternion.squared_length(q) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion()), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatLerp(q1=(DataTypes.Quaternion, pyrr.Quaternion()), q2=(DataTypes.Quaternion, pyrr.Quaternion()), t=(DataTypes.Float, 0.0)): '''Interpolates between q1 and q2 by t. The parameter t is clamped to the range [0, 1].''' return q1.lerp(q2, t) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Matrix33, pyrr.Matrix33()), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatAsMatrix33(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns a Matrix33 representation of this Quaternion.''' return q.matrix33 @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Matrix44, pyrr.Matrix44()), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatAsMatrix44(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns a Matrix44 representation of this Quaternion.''' return q.matrix44 @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion()), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatNegative(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the negative of the Quaternion.''' return q.negative @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion()), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatNormalize(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns a normalized version of this Quaternion as a new Quaternion.''' return q.normalized @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion()), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatPower(q=(DataTypes.Quaternion, pyrr.Quaternion()), exp=(DataTypes.Float, 0.0), result=(DataTypes.Reference, (DataTypes.Bool, False))): '''Returns a new Quaternion representing this Quaternion to the power of the exponent. Checks for identify quaternion''' try: powered = q.power(exp) result(True) return powered except: result(False) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Quaternion, pyrr.Quaternion()), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatSlerp(q1=(DataTypes.Quaternion, pyrr.Quaternion()), q2=(DataTypes.Quaternion, pyrr.Quaternion()), t=(DataTypes.Float, 0.0)): '''Spherically interpolates between quat1 and quat2 by t. The parameter t is clamped to the range [0, 1].''' return q1.slerp(q2, t) @staticmethod @IMPLEMENT_NODE(returns=(DataTypes.Bool, False), meta={'Category': 'Math|Quaternion', 'Keywords': []}) def quatIsZeroLength(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Checks if a quaternion is zero length.''' return pyrr.quaternion.is_zero_length(q)
def quatSlerp(q1=(DataTypes.Quaternion, pyrr.Quaternion()), q2=(DataTypes.Quaternion, pyrr.Quaternion()), t=(DataTypes.Float, 0.0)): '''Spherically interpolates between quat1 and quat2 by t. The parameter t is clamped to the range [0, 1].''' return q1.slerp(q2, t)
def quatIsZeroLength(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Checks if a quaternion is zero length.''' return pyrr.quaternion.is_zero_length(q)
def quatNormalize(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns a normalized version of this Quaternion as a new Quaternion.''' return q.normalized
def quatMult(q1=(DataTypes.Quaternion, pyrr.Quaternion()), q2=(DataTypes.Quaternion, pyrr.Quaternion())): '''"*" operator for quaternions.''' return q1 * q2
def quatConjugate(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the conjugate of this Quaternion.\nThis is a Quaternion with the opposite rotation.''' return q.conjugate
def quatNegative(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the negative of the Quaternion.''' return q.negative
def quatAngle(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the angle around the axis of rotation of this Quaternion as a float.''' return q.angle
def isQuatInList(List=(DataTypes.Array, []), Value=(DataTypes.Quaternion, pyrr.Quaternion())): return Value in List
def quatIsIdentity(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns True if the Quaternion has no rotation (0.,0.,0.,1.).''' return q.is_identity
def quatLength(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the length of this Quaternion.''' return q.length
def quatInverse(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the inverse of this quaternion.''' return q.inverse
def zeroQuat(): '''Returns zero quaternion.''' return pyrr.Quaternion()
def quatCross(q=(DataTypes.Quaternion, pyrr.Quaternion()), other=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the cross of this Quaternion and another.\nThis is the equivalent of combining Quaternion rotations (like Matrix multiplication).''' return q.cross(other)
def quatApplyToVector(q=(DataTypes.Quaternion, pyrr.Quaternion()), v=(DataTypes.FloatVector3, pyrr.Vector3())): '''Rotates a vector by a quaternion.''' return pyrr.Vector3(pyrr.quaternion.apply_to_vector(quat=q, vec=v))
def quatToString(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Convert to quat to str''' return str(q)
def quatW(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the w component of the quat.''' return q.w
def quatAxis(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the axis of rotation of this Quaternion as a Vector3.''' return q.axis
def quatLerp(q1=(DataTypes.Quaternion, pyrr.Quaternion()), q2=(DataTypes.Quaternion, pyrr.Quaternion()), t=(DataTypes.Float, 0.0)): '''Interpolates between q1 and q2 by t. The parameter t is clamped to the range [0, 1].''' return q1.lerp(q2, t)
def quatAsMatrix44(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns a Matrix44 representation of this Quaternion.''' return q.matrix44
def quatSquaredLength(q=(DataTypes.Quaternion, pyrr.Quaternion())): '''Calculates the squared length of a quaternion.\nUseful for avoiding the performanc penalty of the square root function.''' return pyrr.quaternion.squared_length(q)
def quatDot(q=(DataTypes.Quaternion, pyrr.Quaternion()), other=(DataTypes.Quaternion, pyrr.Quaternion())): '''Returns the dot of this Quaternion and another.''' return q.dot(other)