def set_LRS(self, context, obj, LRS, rotation_mode='QUATERNION'): L, R, S = LRS L_mode, R_mode, S_mode, to_m, persp = self.calc_matrix(context, obj) mL = (L is not None) and (L_mode != 'BASIS') mR = (R is not None) and (R_mode != 'BASIS') mS = (S is not None) and (S_mode != 'BASIS') if mL or mR or mS: in_m = matrix_inverted_safe(to_m) * BlUtil.Object.matrix_world(obj) if not mL: in_L = in_m.to_translation() else: L = Vector(L) # make sure it's a Vector if L_mode in ('CAMERA', 'VIEW'): L = Vector((L.x / persp.x, L.y / persp.y, -L.z)).lerp( Vector( (L.x * L.z / persp.x, L.y * L.z / persp.y, -L.z)), persp.z) in_L = L L = None if not mR: in_R = in_m.to_quaternion() if not R: rotation_mode = obj.rotation_mode else: if rotation_mode == 'QUATERNION': in_R = Quaternion(R) elif rotation_mode == 'AXIS_ANGLE': in_R = Quaternion(R[1:], R[0]) else: if (len(R) == 4): R = R[1:] in_R = Euler(R).to_quaternion() R = None if not mS: in_S = in_m.to_scale() else: in_S = Vector(S) S = None x, y, z = in_R.normalized().to_matrix().col in_m = matrix_compose(x * in_S.x, y * in_S.y, z * in_S.z, in_L) BlUtil.Object.matrix_world_set(obj, to_m * in_m) if (not mL) and (not L): L = Vector(obj.location) if (not mR) and (not R): R = BlUtil.Object.rotation_convert(obj.rotation_mode, obj.rotation_quaternion, obj.rotation_axis_angle, obj.rotation_euler, rotation_mode) if (not mS) and (not S): S = Vector(obj.scale) if L: obj.location = Vector(L) if R: BlUtil.Object.rotation_apply(obj, R, rotation_mode) if S: obj.scale = Vector(S)
def set_LRS(self, context, obj, LRS, rotation_mode='QUATERNION'): L, R, S = LRS L_mode, R_mode, S_mode, to_m, persp = self.calc_matrix(context, obj) mL = (L is not None) and (L_mode != 'BASIS') mR = (R is not None) and (R_mode != 'BASIS') mS = (S is not None) and (S_mode != 'BASIS') if mL or mR or mS: in_m = matrix_inverted_safe(to_m) * BlUtil.Object.matrix_world(obj) if not mL: in_L = in_m.to_translation() else: L = Vector(L) # make sure it's a Vector if L_mode in ('CAMERA', 'VIEW'): L = Vector((L.x / persp.x, L.y / persp.y, -L.z)).lerp( Vector((L.x * L.z / persp.x, L.y * L.z / persp.y, -L.z)), persp.z) in_L = L L = None if not mR: in_R = in_m.to_quaternion() if not R: rotation_mode = obj.rotation_mode else: if rotation_mode == 'QUATERNION': in_R = Quaternion(R) elif rotation_mode == 'AXIS_ANGLE': in_R = Quaternion(R[1:], R[0]) else: if (len(R) == 4): R = R[1:] in_R = Euler(R).to_quaternion() R = None if not mS: in_S = in_m.to_scale() else: in_S = Vector(S) S = None x, y, z = in_R.normalized().to_matrix().col in_m = matrix_compose(x*in_S.x, y*in_S.y, z*in_S.z, in_L) BlUtil.Object.matrix_world_set(obj, to_m * in_m) if (not mL) and (not L): L = Vector(obj.location) if (not mR) and (not R): R = BlUtil.Object.rotation_convert(obj.rotation_mode, obj.rotation_quaternion, obj.rotation_axis_angle, obj.rotation_euler, rotation_mode) if (not mS) and (not S): S = Vector(obj.scale) if L: obj.location = Vector(L) if R: BlUtil.Object.rotation_apply(obj, R, rotation_mode) if S: obj.scale = Vector(S)
def quaternionToImEuler(quaternion: mathutils.Quaternion): assert type(quaternion) is mathutils.Quaternion qrot = quaternion.normalized() return eulerToImEuler(qrot.to_euler(kImEulerOrder), kImEulerOrder)