def rotateline_callback(event=None): obj, direction, move = handle_clickline_event(event, Mode.ROTATE) if not obj and not direction: return rotated = rot = obj.rotation inc = float(USERS[event.source].target_style) rot = arblib.rotation_quat2euler(rot) rot = (round(rot[0]), round(rot[1]), round(rot[2])) if direction == "xp": rotated = (incr_pos(rot[0], inc), rot[1], rot[2]) elif direction == "xn": rotated = (incr_neg(rot[0], inc), rot[1], rot[2]) elif direction == "yp": rotated = (rot[0], incr_pos(rot[1], inc), rot[2]) elif direction == "yn": rotated = (rot[0], incr_neg(rot[1], inc), rot[2]) elif direction == "zp": rotated = (rot[0], rot[1], incr_pos(rot[2], inc)) elif direction == "zn": rotated = (rot[0], rot[1], incr_neg(rot[2], inc)) if abs(rotated[0]) > 180 or abs(rotated[1]) > 180 or abs(rotated[2]) > 180: return rotated = arblib.rotation_euler2quat(rotated) arblib.rotate_obj(REALM, SCENE, obj.object_id, rotated) print(str(obj.rotation) + " to " + str(rotated)) do_rotate_select(event.source, obj.object_id, rotation=rotated)
def rotateline_callback(_scene, event, msg): obj, direction, move = handle_clickline_event(event, Mode.ROTATE) if not obj or not direction or "rotation" not in obj.data: return rotated = rot = obj.data.rotation inc = float(USERS[event.data.source].target_style) try: rot = arblib.rotation_quat2euler((rot.x, rot.y, rot.z, rot.w)) except ValueError as error: print(f"Rotation error: {error}") return rot = (round(rot[0]), round(rot[1]), round(rot[2])) if direction == "xp": rotated = (incr_pos(rot[0], inc), rot[1], rot[2]) elif direction == "xn": rotated = (incr_neg(rot[0], inc), rot[1], rot[2]) elif direction == "yp": rotated = (rot[0], incr_pos(rot[1], inc), rot[2]) elif direction == "yn": rotated = (rot[0], incr_neg(rot[1], inc), rot[2]) elif direction == "zp": rotated = (rot[0], rot[1], incr_pos(rot[2], inc)) elif direction == "zn": rotated = (rot[0], rot[1], incr_neg(rot[2], inc)) if abs(rotated[0]) > 180 or abs(rotated[1]) > 180 or abs(rotated[2]) > 180: return try: rotated = arblib.rotation_euler2quat(rotated) except ValueError as error: print(f"Rotation error: {error}") return rotated = Rotation(x=rotated[0], y=rotated[1], z=rotated[2], w=rotated[3]) arblib.rotate_obj(scene, obj.object_id, rotated) print(f"{str(obj.data.rotation)} to {str(rotated)}") do_rotate_select(event.data.source, obj.object_id, rotation=rotated)
def do_rotate_select(camname, objid, rotation=None): color = arblib.CLR_ROTATE delim = f"_{Mode.ROTATE.value}_" callback = rotateline_callback obj = scene.get_persisted_obj(objid) position = Position() if "position" in obj.data: position = obj.data.position if not rotation: rotation = Rotation() if "rotation" in obj.data: rotation = obj.data.rotation xl, yl, zl = get_clicklines_len(obj) # rotate object + or - on 3 axis, plus show original axis as after # effect root = make_clickroot(objid, position, delim) ghost = make_clickroot(objid, position, delim, rotation=rotation, move=True) make_clickline("x", xl, objid, position, delim, color, callback, ghost=ghost, parent=root) make_clickline("y", yl, objid, position, delim, color, callback, ghost=ghost, parent=root) make_clickline("z", zl, objid, position, delim, color, callback, ghost=ghost, parent=root) # TODO: restore make_followspot(objid, position, delim, color) try: rote = arblib.rotation_quat2euler( (rotation.x, rotation.y, rotation.z, rotation.w)) except ValueError as error: print(f"Rotation error: {error}") return euler = (round(rote[0], 1), round(rote[1], 1), round(rote[2], 1)) USERS[camname].set_textright( f"{USERS[camname].target_style}d r({euler[0]},{euler[1]},{euler[2]})")
def do_rotate_select(camname, objid, rotation=None): color = arblib.CLR_ROTATE delim = "_" + Mode.ROTATE.value + "_" callback = rotateline_callback if not rotation: pobjs = arena.get_network_persisted_obj(objid, BROKER, SCENE) if not pobjs: return obj = arblib.ObjectPersistence(pobjs[0]) position = obj.position rotation = obj.rotation # rotate object + or - on 3 axis, plus show original axis as after # effect make_clickline("x", 1, objid, position, delim, color, callback, True) make_clickline("y", 1, objid, position, delim, color, callback, True) make_clickline("z", 1, objid, position, delim, color, callback, True) make_followspot(objid, position, delim, color) rote = arblib.rotation_quat2euler(rotation) euler = (round(rote[0], 1), round(rote[1], 1), round(rote[2], 1)) USERS[camname].set_textright(USERS[camname].target_style + "d r" + str(euler))