def add_object_align_init(context, operator): """ Return a matrix using the operator settings and view context. :arg context: The context to use. :type context: :class:`bpy.types.Context` :arg operator: The operator, checked for location and rotation properties. :type operator: :class:`bpy.types.Operator` :return: the matrix from the context and settings. :rtype: :class:`mathutils.Matrix` """ from mathutils import Matrix, Vector, Euler properties = operator.properties if operator is not None else None space_data = context.space_data if space_data and space_data.type != 'VIEW_3D': space_data = None # location if operator and properties.is_property_set("location"): location = Matrix.Translation(Vector(properties.location)) else: location = Matrix.Translation(context.scene.cursor_location) if operator: properties.location = location.to_translation() # rotation view_align = (context.preferences.edit.object_align == 'VIEW') view_align_force = False if operator: if properties.is_property_set("view_align"): view_align = view_align_force = operator.view_align else: if properties.is_property_set("rotation"): # ugh, 'view_align' callback resets value = properties.rotation[:] properties.view_align = view_align properties.rotation = value del value else: properties.view_align = view_align if operator and (properties.is_property_set("rotation") and not view_align_force): rotation = Euler(properties.rotation).to_matrix().to_4x4() else: if view_align and space_data: rotation = space_data.region_3d.view_matrix.to_3x3().inverted() rotation.resize_4x4() else: rotation = Matrix() # set the operator properties if operator: properties.rotation = rotation.to_euler() return location @ rotation
def add_object_align_init(context, operator): """ Return a matrix using the operator settings and view context. :arg context: The context to use. :type context: :class:`bpy.types.Context` :arg operator: The operator, checked for location and rotation properties. :type operator: :class:`bpy.types.Operator` :return: the matrix from the context and settings. :rtype: :class:`mathutils.Matrix` """ from mathutils import Matrix, Vector, Euler properties = operator.properties if operator is not None else None space_data = context.space_data if space_data and space_data.type != 'VIEW_3D': space_data = None # location if operator and properties.is_property_set("location"): location = Matrix.Translation(Vector(properties.location)) else: location = Matrix.Translation(context.scene.cursor.location) if operator: properties.location = location.to_translation() # rotation view_align = (context.preferences.edit.object_align == 'VIEW') view_align_force = False if operator: if properties.is_property_set("view_align"): view_align = view_align_force = operator.view_align else: if properties.is_property_set("rotation"): # ugh, 'view_align' callback resets value = properties.rotation[:] properties.view_align = view_align properties.rotation = value del value else: properties.view_align = view_align if operator and (properties.is_property_set("rotation") and not view_align_force): rotation = Euler(properties.rotation).to_matrix().to_4x4() else: if view_align and space_data: rotation = space_data.region_3d.view_matrix.to_3x3().inverted() rotation.resize_4x4() else: rotation = Matrix() # set the operator properties if operator: properties.rotation = rotation.to_euler() return location @ rotation
def getTransformFromParent(self): rot = Euler((radians(self.alpha.value), radians(self.beta.value), radians(self.gamma.value)), 'XYZ').to_matrix() rot.resize_4x4() transl = Matrix.Translation((self.x.value, self.y.value, self.z.value)) # print("here",transl * rot) return transl * rot
def getTransformFromParent(self): alphaMatrix = Euler((radians(self.alpha.value), 0, 0), 'XYZ').to_matrix() alphaMatrix.resize_4x4() thetaMatrix = Euler((0, 0, radians(self.theta.value)), 'XYZ').to_matrix() thetaMatrix.resize_4x4() translation = Matrix.Translation((self.a.value, 0, self.d.value, 1)) return translation * alphaMatrix * thetaMatrix
def getTransformFromParent(self): rot = Euler( ( radians(self.alpha.value), radians(self.beta.value), radians(self.gamma.value), ), "XYZ", ).to_matrix() rot.resize_4x4() transl = Matrix.Translation((self.x.value, self.y.value, self.z.value)) return transl @ rot
def getTransform(self): """ returned transform matrix is of the form translation*parentMatrix*rotation parent is dependent of parent mode, that is either Euler or DH either translation or rotation is I_4 dependent of the joint type, whereas a revolute joints contributes a rotation only and a prismatic joint contributes a translation only """ translation = Matrix() # initialize as I_4 matrix rotation = Matrix() # initialize as I_4 matrix axis_matrix = ( Matrix() ) # contains axis information which should be applied to parentMatrix if self.axis_revert: inverted = -1 else: inverted = 1 if self.parentMode == "EULER": parentMatrix = self.Euler.getTransformFromParent() else: # self.parentMode == 'DH' parentMatrix = self.DH.getTransformFromParent() if self.jointMode == "REVOLUTE": if self.axis == "X": rotation = Euler( (radians(self.theta.value + self.theta.offset), 0, 0), "XYZ").to_matrix() rotation.resize_4x4() axis_matrix = Euler((radians(180 * (1 - inverted) / 2), 0, 0), "XYZ").to_matrix() axis_matrix.resize_4x4() elif self.axis == "Y": rotation = Euler( (0, radians(self.theta.value + self.theta.offset), 0), "XYZ").to_matrix() rotation.resize_4x4() axis_matrix = Euler((0, radians(180 * (1 - inverted) / 2), 0), "XYZ").to_matrix() axis_matrix.resize_4x4() elif self.axis == "Z": rotation = Euler( (0, 0, radians(self.theta.value + self.theta.offset)), "XYZ").to_matrix() rotation.resize_4x4() axis_matrix = Euler((0, 0, radians(180 * (1 - inverted) / 2)), "XYZ").to_matrix() axis_matrix.resize_4x4() if self.jointMode == "PRISMATIC": if self.axis == "X": translation = Matrix.Translation( (inverted * (self.d.value + self.d.offset), 0, 0, 1)) elif self.axis == "Y": translation = Matrix.Translation( (0, inverted * (self.d.value + self.d.offset), 0, 1)) elif self.axis == "Z": translation = Matrix.Translation( (0, 0, inverted * (self.d.value + self.d.offset), 1)) if (self.jointMode == "FIXED" or self.jointMode == "REVOLUTE2" or self.jointMode == "UNIVERSAL" or self.jointMode == "BALL" ): # todo: check if this is right for fixed joint type translation = Matrix.Translation((0, 0, 0, 1)) return parentMatrix @ axis_matrix, translation @ rotation