Last active
September 2, 2021 07:02
-
-
Save lukicdarkoo/7925a3eee3b83c9b04f6aac1b45bb1d7 to your computer and use it in GitHub Desktop.
Revisions
-
lukicdarkoo revised this gist
Sep 2, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ # sudo apt install xclip # # GNOME SHORTCUT # In GNOME, you can run the script as a keyboard shortcut. # Go to `Settings > Keyboard Shortcuts > +` import clipboard @@ -38,6 +38,8 @@ def vector_to_string_array(vector, decimals, zero_one_decimals=None): new_str.append('0') elif abs(value - 1) < 1 / (10**zero_one_decimals): new_str.append('1') elif abs(value + 1) < 1 / (10**zero_one_decimals): new_str.append('-1') else: new_str.append(str(round(value, decimals))) return new_str -
lukicdarkoo revised this gist
Sep 2, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ TRANSLATE_VECTOR = [-2, 0, 0] ROTATION = [np.pi/2, -np.pi/2, 0] # RUB # ROTATION = [np.pi/2, np.pi/2, 0] # RUB with x-inverted # ROTATION = [np.pi/2, 0, 0] if GEOMETRY: ROTATION = [-np.pi/2, 0, 0] # Plane for sure -
lukicdarkoo revised this gist
Sep 2, 2021 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,11 @@ # Converts rotation and translation VRML fields. # It takes the clipboard content, applies transforms, and pastes the transformed VRML to the clipboard. # # Dependencies: # # pip3 install clipboard numpy transforms3d # sudo apt install xclip # # GNOME SHORTCUT # In GNOME, you can set to run this script as a keyboard shortcut command. # Go to `Settings > Keyboard Shortcuts > +` @@ -16,9 +21,10 @@ TRANSLATE_VECTOR = [-2, 0, 0] ROTATION = [np.pi/2, -np.pi/2, 0] # RUB ROTATION = [np.pi/2, np.pi/2, 0] # RUB with x-inverted # ROTATION = [np.pi/2, 0, 0] if GEOMETRY: ROTATION = [-np.pi/2, 0, 0] # Plane for sure ROTATION_MATRIX = transforms3d.euler.euler2mat(ROTATION[0], ROTATION[1], ROTATION[2], 'rxyz') -
lukicdarkoo revised this gist
Sep 1, 2021 . 1 changed file with 14 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,23 +11,16 @@ import re GEOMETRY = False TRANSLATE_ONLY = False TRANSLATE_VECTOR = [-2, 0, 0] ROTATION = [np.pi/2, -np.pi/2, 0] # RUB # ROTATION = [0, 0, np.pi] if GEOMETRY: ROTATION = [np.pi/2, 0, 0] ROTATION_MATRIX = transforms3d.euler.euler2mat(ROTATION[0], ROTATION[1], ROTATION[2], 'rxyz') def vector_to_string_array(vector, decimals, zero_one_decimals=None): if zero_one_decimals is None: @@ -46,6 +39,8 @@ def vector_to_string_array(vector, decimals, zero_one_decimals=None): def convert_translation(translation): translation = [float(value) for value in translation] if TRANSLATE_ONLY: return (np.array(translation) + TRANSLATE_VECTOR).flatten() return (ROTATION_MATRIX @ np.array(translation)).flatten() @@ -59,7 +54,10 @@ def convert_mesh(geometry_points): def convert_orientation(rotation_angle_axis): rotation_angle_axis = [float(value) for value in rotation_angle_axis] orientation = transforms3d.axangles.axangle2mat(rotation_angle_axis[:3], rotation_angle_axis[3]) if GEOMETRY: new_rotation = orientation @ ROTATION_MATRIX else: new_rotation = ROTATION_MATRIX @ orientation new_rotation_axis, new_rotation_angle = transforms3d.axangles.mat2axangle(new_rotation) return ' '.join(vector_to_string_array(list(new_rotation_axis) + list([new_rotation_angle]), 6)) -
lukicdarkoo revised this gist
Aug 24, 2021 . 1 changed file with 72 additions and 38 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,53 +8,87 @@ import clipboard import numpy as np import transforms3d import re # ROTATION = [0.577351, -0.577351, 0.577351, 2.09439] # ROTATION = [0.577351, -0.577351, -0.577351, -2.09439] ROTATION = [-0.5773516025189619, 0.5773476025217157, 0.5773516025189619, -2.094405307179586] # From RUB to FLU ROTATION = [0, -0.707, 0.707, 3.140466] # Plane, from RUB to FLU # ROTATION = [1, 0, 0, -np.pi/2] # Plane, from RUB to FLU # ROTATION = [0, 1, 0, -np.pi/2] # Cylinder after conversion from RUB ROTATION_MATRIX = transforms3d.axangles.axangle2mat(ROTATION[:3], ROTATION[3]) ROTATION = [-np.pi/2, np.pi, 0] ROTATION_MATRIX = transforms3d.euler.euler2mat(ROTATION[0], ROTATION[1], ROTATION[2], 'rxyz') ROTATION_MATRIX = transforms3d.axangles.axangle2mat( [-0.5773516025189619, 0.5773476025217157, 0.5773516025189619], -2.094405307179586) def vector_to_string_array(vector, decimals, zero_one_decimals=None): if zero_one_decimals is None: # Zero and one are special cases and typically it is fine to be more agressive when rounding zero_one_decimals = int(0.7 * decimals) new_str = [] for value in vector: if abs(value) < 1 / (10**zero_one_decimals): new_str.append('0') elif abs(value - 1) < 1 / (10**zero_one_decimals): new_str.append('1') else: new_str.append(str(round(value, decimals))) return new_str def convert_translation(translation): translation = [float(value) for value in translation] return (ROTATION_MATRIX @ np.array(translation)).flatten() def convert_mesh(geometry_points): for i in range(0, len(geometry_points), 3): new_point = convert_translation(geometry_points[i:i+3]) geometry_points[i:i+3] = vector_to_string_array(new_point, 7) return ' '.join(geometry_points) def convert_orientation(rotation_angle_axis): rotation_angle_axis = [float(value) for value in rotation_angle_axis] orientation = transforms3d.axangles.axangle2mat(rotation_angle_axis[:3], rotation_angle_axis[3]) new_rotation = ROTATION_MATRIX @ orientation new_rotation_axis, new_rotation_angle = transforms3d.axangles.mat2axangle(new_rotation) return ' '.join(vector_to_string_array(list(new_rotation_axis) + list([new_rotation_angle]), 6)) def is_number(string): try: float(string) return True except ValueError: return False def main(): text = clipboard.paste() vector = [x for x in re.compile('\n|,| ').split(text) if is_number(x)] out = 'ERROR' if len(vector) == 0: new_rotation_axis, new_rotation_angle = transforms3d.axangles.mat2axangle(ROTATION_MATRIX) out = ' '.join(vector_to_string_array(list(new_rotation_axis) + list([new_rotation_angle]), 6)) elif len(vector) == 3: out = convert_translation(vector) out = ' '.join(vector_to_string_array(out, 4)) elif len(vector) == 4: out = convert_orientation(vector) else: out = convert_mesh(vector) clipboard.copy(out) if __name__ == '__main__': -
lukicdarkoo revised this gist
Aug 9, 2021 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import transforms3d EPSILON = 1e-4 ROTATION = [1, 0, 0, np.pi/2] ROTATION_MATRIX = transforms3d.axangles.axangle2mat(ROTATION[:3], ROTATION[3]) @@ -30,9 +32,9 @@ def main(): axis, angle = transforms3d.axangles.mat2axangle(rotated_matrix) for i in range(3): if abs(axis[i]) < EPSILON: axis[i] = int(0) if abs(angle) < EPSILON: angle = int(0) lines_out.append(f'{identation}rotation {axis[0]} {axis[1]} {axis[2]} {angle}') @@ -42,7 +44,7 @@ def main(): tranlsation_rotated = ROTATION_MATRIX @ translation for i in range(3): if abs(tranlsation_rotated[i]) < EPSILON: tranlsation_rotated[i] = int(0) lines_out.append( -
lukicdarkoo revised this gist
Aug 9, 2021 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,8 +10,6 @@ import transforms3d ROTATION = [1, 0, 0, np.pi/2] ROTATION_MATRIX = transforms3d.axangles.axangle2mat(ROTATION[:3], ROTATION[3]) -
lukicdarkoo renamed this gist
Aug 9, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
lukicdarkoo created this gist
Aug 9, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ # Converts rotation and translation VRML fields. # It takes the clipboard content, applies transforms, and pastes the transformed VRML to the clipboard. # # GNOME SHORTCUT # In GNOME, you can set to run this script as a keyboard shortcut command. # Go to `Settings > Keyboard Shortcuts > +` import clipboard import numpy as np import transforms3d # ROTATION = [0.577351, -0.577351, 0.577351, 2.09439] # ROTATION = [0.577351, -0.577351, -0.577351, -2.09439] ROTATION = [1, 0, 0, np.pi/2] ROTATION_MATRIX = transforms3d.axangles.axangle2mat(ROTATION[:3], ROTATION[3]) def main(): text = clipboard.paste() lines = text.split('\n') lines_out = [] for index, line in enumerate(lines): args = line.strip().split(' ') identation = ' ' * (len(line) - len(line.lstrip())) if args[0] == 'rotation': rotation_raw = [float(x) for x in args[1:]] rotation_matrix = transforms3d.axangles.axangle2mat(rotation_raw[:3], rotation_raw[3]) rotated_matrix = ROTATION_MATRIX @ rotation_matrix axis, angle = transforms3d.axangles.mat2axangle(rotated_matrix) for i in range(3): if abs(axis[i]) < 0.0001: axis[i] = int(0) if abs(angle) < 0.0001: angle = int(0) lines_out.append(f'{identation}rotation {axis[0]} {axis[1]} {axis[2]} {angle}') elif args[0] == 'translation': translation = np.array([float(x) for x in args[1:]]) tranlsation_rotated = ROTATION_MATRIX @ translation for i in range(3): if abs(tranlsation_rotated[i]) < 0.0001: tranlsation_rotated[i] = int(0) lines_out.append( f'{identation}translation {tranlsation_rotated[0]} {tranlsation_rotated[1]} {tranlsation_rotated[2]}') if 'rotation' not in lines[index + 1]: lines_out.append(f'{identation}rotation {ROTATION[0]} {ROTATION[1]} {ROTATION[2]} {ROTATION[3]}') else: lines_out.append(line) clipboard.copy('\n'.join(lines_out)) if __name__ == '__main__': main()