BobTheHunted

PreciseTranslateRotateEden.sqf

Nov 16th, 2021 (edited)
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 9.60 KB | None | 0 0
  1. // Script that enables "nudging" objects in the 3den editor for precision alignment/adjustment.  Execute script from 3den debug menu. (Ctrl + D to open) - execVM "PreciseTranslateRotateEden.sqf"
  2. // Select 1 or more objects in 3den and you can adjust their position(s).
  3. // Created by Rylan
  4. //
  5. //  Controls:
  6. //      Shift + Numpad 5 = Nudge "forward" (Global coordinates so it probably won't be forward for the object if it has changed rotation.)
  7. //      Shift + Numpad 1 = Nudge "left"
  8. //      Shift + Numpad 2 = Nudge "backward"
  9. //      Shift + Numpad 3 = Nudge "right"
  10. //      Alt + Numpad 5 = Nudge "up" (vertical)
  11. //      Alt + Numpad 2 = Nudge "down" (vertical)
  12. //      Ctrl + Numpad 5 or 2 = Increase or decrease the nudge increment by 0.0025 - For high precision
  13. //      Ctrl + Numpad 1 or 3 = Increase or decrease the nudge increment by 0.01 --- For lower precision
  14. //      Shift + Numpad 0 = Toggle rotate or translate mode (rotate mode has same controls, including separate increment values)
  15. //      Numpad 0 = Cycle through rotation axis (yaw, pitch, roll)
  16. //
  17. // The default value and the amount the increment can be increased or decreased can be changed by editing the first 3 variables of this script.
  18. // These variables can also be changed on the fly from the editor via the debug menu.  Simply redefine any of the variables with the values you want (or just edit them here)
  19.  
  20.  
  21. A3EM_nudgeIncrement = 0.01; // Default nudge value
  22. A3EM_ni_inc1 = 0.0025; // ---- High precision adjustment
  23. A3EM_ni_inc2 = 0.1; // ------- Low precision adjustment
  24.  
  25. A3EM_rotateIncrement = 0.1; // Default rotate value
  26. A3EM_ri_inc1 = 0.05; // ---- High precision adjustment
  27. A3EM_ri_inc2 = 0.15; // ------- Low precision adjustment
  28.  
  29. A3EM_nudgeMode = "translate"; // "rotate"
  30. A3EM_rotateAxis = "yaw"; // "pitch" "roll"
  31.  
  32. A3EM_fnc_nudgeTranslate =
  33. {
  34.     collect3DENHistory
  35.     {
  36.         private ["_keypress", "_EditorObjects"];
  37.    
  38.         _keypress = _this select 0;
  39.         _EditorObjects = get3DENSelected "object";
  40.         if (count _EditorObjects < 1) exitWith {systemChat "No object(s) selected!"};
  41.    
  42.         {
  43.             if (_keypress == "NudgeUp") then {
  44.                 private _oldPos = (_x get3DENAttribute "Position") select 0;
  45.                 set3DENAttributes [[[_x],"Position",[(_oldPos select 0),(_oldPos select 1) + A3EM_nudgeincrement,(_oldPos select 2)]]];
  46.             };
  47.             if (_keypress == "NudgeDown") then {
  48.                 private _oldPos = (_x get3DENAttribute "Position") select 0;
  49.                 set3DENAttributes [[[_x],"Position",[(_oldPos select 0),(_oldPos select 1) - A3EM_nudgeincrement,(_oldPos select 2)]]];
  50.             };
  51.             if (_keypress == "NudgeRight") then {
  52.                 private _oldPos = (_x get3DENAttribute "Position") select 0;
  53.                 set3DENAttributes [[[_x],"Position",[(_oldPos select 0) + A3EM_nudgeincrement,(_oldPos select 1),(_oldPos select 2)]]];
  54.             };
  55.             if (_keypress == "NudgeLeft") then {
  56.                 private _oldPos = (_x get3DENAttribute "Position") select 0;
  57.                 set3DENAttributes [[[_x],"Position",[(_oldPos select 0) - A3EM_nudgeincrement,(_oldPos select 1),(_oldPos select 2)]]];
  58.             };
  59.             if (_keypress == "AltNudgeUp") then {
  60.                 private _oldPos = (_x get3DENAttribute "Position") select 0;
  61.                 set3DENAttributes [[[_x],"Position",[(_oldPos select 0),(_oldPos select 1),(_oldPos select 2) + A3EM_nudgeincrement]]];
  62.             };
  63.             if (_keypress == "AltNudgeDown") then {
  64.                 private _oldPos = (_x get3DENAttribute "Position") select 0;
  65.                 set3DENAttributes [[[_x],"Position",[(_oldPos select 0),(_oldPos select 1),(_oldPos select 2) - A3EM_nudgeincrement]]];
  66.             };
  67.         } forEach _EditorObjects;
  68.     };
  69. };
  70.  
  71. A3EM_fnc_nudgeRotate =
  72. {
  73.     collect3DENHistory
  74.     {
  75.         private ["_keypress", "_axis", "_EditorObjects"];
  76.    
  77.         _keypress = _this select 0;
  78.         _axis = _this select 1;
  79.         _EditorObjects = get3DENSelected "object";
  80.         if (count _EditorObjects < 1) exitWith {systemChat "No object(s) selected!"};
  81.        
  82.         if (_axis == "yaw") then {
  83.             {
  84.                 if ((_keypress == "RotateUp") OR (_keypress == "RotateRight")) then {
  85.                     private _oldPos = (_x get3DENAttribute "Rotation") select 0;
  86.                     set3DENAttributes [[[_x],"Rotation",[(_oldPos select 0),(_oldPos select 1),(_oldPos select 2) - A3EM_rotateIncrement]]];
  87.                 };
  88.                 if ((_keypress == "RotateDown") OR (_keypress == "RotateLeft")) then {
  89.                     private _oldPos = (_x get3DENAttribute "Rotation") select 0;
  90.                     set3DENAttributes [[[_x],"Rotation",[(_oldPos select 0),(_oldPos select 1),(_oldPos select 2) + A3EM_rotateIncrement]]];
  91.                 };
  92.             } forEach _EditorObjects;
  93.         };
  94.         if (_axis == "pitch") then {
  95.             {
  96.                 if ((_keypress == "RotateUp") OR (_keypress == "RotateRight")) then {
  97.                     private _oldPos = (_x get3DENAttribute "Rotation") select 0;
  98.                     set3DENAttributes [[[_x],"Rotation",[(_oldPos select 0) - A3EM_rotateIncrement,(_oldPos select 1),(_oldPos select 2)]]];
  99.                 };
  100.                 if ((_keypress == "RotateDown") OR (_keypress == "RotateLeft")) then {
  101.                     private _oldPos = (_x get3DENAttribute "Rotation") select 0;
  102.                     set3DENAttributes [[[_x],"Rotation",[(_oldPos select 0) + A3EM_rotateIncrement,(_oldPos select 1),(_oldPos select 2)]]];
  103.                 };
  104.  
  105.             } forEach _EditorObjects;
  106.         };
  107.         if (_axis == "roll") then {
  108.             {
  109.                 if ((_keypress == "RotateUp") OR (_keypress == "RotateRight")) then {
  110.                     private _oldPos = (_x get3DENAttribute "Rotation") select 0;
  111.                     set3DENAttributes [[[_x],"Rotation",[(_oldPos select 0),(_oldPos select 1) - A3EM_rotateIncrement,(_oldPos select 2)]]];
  112.                 };
  113.                 if ((_keypress == "RotateDown") OR (_keypress == "RotateLeft")) then {
  114.                     private _oldPos = (_x get3DENAttribute "Rotation") select 0;
  115.                     set3DENAttributes [[[_x],"Rotation",[(_oldPos select 0),(_oldPos select 1) + A3EM_rotateIncrement,(_oldPos select 2)]]];
  116.                 };
  117.             } forEach _EditorObjects;
  118.         };
  119.     };
  120. };
  121.  
  122. waitUntil {!isNull (findDisplay 313)};
  123.  
  124. #include "\a3\ui_f\hpp\definedikcodes.inc"
  125.  
  126. _display = findDisplay 313;
  127. if (_display getVariable ["A3EM_eh_nudgecontrols", -1] != -1) exitWith {};
  128. _EventHandler = _display displayAddEventHandler [ "KeyDown", {
  129.     params[
  130.         "_display",
  131.         "_keyCode",
  132.         "_shft",
  133.         "_ctr",
  134.         "_alt"
  135.     ];
  136.    
  137.     call {
  138.         if ( _shft && { _keyCode isEqualTo DIK_NUMPAD0 } ) exitWith { // translate or rotate mode
  139.             if (A3EM_nudgeMode == "translate") then {A3EM_nudgeMode = "rotate"; systemChat "Rotate mode"} else {A3EM_nudgeMode = "translate"; systemChat "Translate mode"};
  140.             true
  141.         };
  142.        
  143.         if ( _keyCode isEqualTo DIK_NUMPAD0 ) exitWith { // rotation axis
  144.             if (A3EM_rotateAxis == "yaw") exitWith {A3EM_rotateAxis = "pitch"; systemChat "Rotation axis set to 'pitch'"};
  145.             if (A3EM_rotateAxis == "pitch") exitWith {A3EM_rotateAxis = "roll"; systemChat "Rotation axis set to 'roll'"};
  146.             if (A3EM_rotateAxis == "roll") exitWith {A3EM_rotateAxis = "yaw"; systemChat "Rotation axis set to 'yaw'"};
  147.             true
  148.         };
  149.        
  150.         if ( _shft && { _keyCode isEqualTo DIK_NUMPAD5 } ) exitWith { // up
  151.             if (A3EM_nudgeMode == "translate") then {["NudgeUp"] call A3EM_fnc_nudgeTranslate} else {["RotateUp", A3EM_rotateAxis] call A3EM_fnc_nudgeRotate};
  152.             true
  153.         };
  154.        
  155.         if ( _shft && { _keyCode isEqualTo DIK_NUMPAD2 } ) exitWith { // down
  156.             if (A3EM_nudgeMode == "translate") then {["NudgeDown"] call A3EM_fnc_nudgeTranslate} else {["RotateDown", A3EM_rotateAxis] call A3EM_fnc_nudgeRotate};
  157.             true
  158.         };
  159.        
  160.         if ( _shft && { _keyCode isEqualTo DIK_NUMPAD3 } ) exitWith { // right
  161.             if (A3EM_nudgeMode == "translate") then {["NudgeRight"] call A3EM_fnc_nudgeTranslate} else {["RotateRight", A3EM_rotateAxis] call A3EM_fnc_nudgeRotate};
  162.             true
  163.         };
  164.        
  165.         if ( _shft && { _keyCode isEqualTo DIK_NUMPAD1 } ) exitWith { // left
  166.             if (A3EM_nudgeMode == "translate") then {["NudgeLeft"] call A3EM_fnc_nudgeTranslate} else {["RotateLeft", A3EM_rotateAxis] call A3EM_fnc_nudgeRotate};
  167.             true
  168.         };
  169.        
  170.         if ( _alt && { _keyCode isEqualTo DIK_NUMPAD5 } ) exitWith { // up - vertical
  171.             ["AltNudgeUp"] call A3EM_fnc_nudgeTranslate;
  172.             true
  173.         };
  174.        
  175.         if ( _alt && { _keyCode isEqualTo DIK_NUMPAD2 } ) exitWith { // down - vertical
  176.             ["AltNudgeDown"] call A3EM_fnc_nudgeTranslate;
  177.             true
  178.         };
  179.        
  180.         if ( _ctr && { _keyCode isEqualTo DIK_NUMPAD5 } ) exitWith { // adjust increment, precise
  181.             if (A3EM_nudgeMode == "translate") then {A3EM_nudgeIncrement = A3EM_nudgeIncrement + A3EM_ni_inc1; systemChat format ["Translate increment: %1", A3EM_nudgeIncrement]} else {A3EM_rotateIncrement = A3EM_rotateIncrement + A3EM_ri_inc1; systemChat format ["Rotate increment: %1", A3EM_rotateIncrement]};
  182.             true
  183.         };
  184.        
  185.         if ( _ctr && { _keyCode isEqualTo DIK_NUMPAD2 } ) exitWith { // adjust increment, precise
  186.             if (A3EM_nudgeMode == "translate") then {A3EM_nudgeIncrement = A3EM_nudgeIncrement - A3EM_ni_inc1; systemChat format ["Translate increment: %1", A3EM_nudgeIncrement]} else {A3EM_rotateIncrement = A3EM_rotateIncrement - A3EM_ri_inc1; systemChat format ["Rotate increment: %1", A3EM_rotateIncrement]};
  187.             true
  188.         };
  189.        
  190.         if ( _ctr && { _keyCode isEqualTo DIK_NUMPAD3 } ) exitWith { // adjust increment, less precise
  191.             if (A3EM_nudgeMode == "translate") then {A3EM_nudgeIncrement = A3EM_nudgeIncrement + A3EM_ni_inc2; systemChat format ["Translate increment: %1", A3EM_nudgeIncrement]} else {A3EM_rotateIncrement = A3EM_rotateIncrement + A3EM_ri_inc2; systemChat format ["Rotate increment: %1", A3EM_rotateIncrement]};
  192.             true
  193.         };
  194.        
  195.         if ( _ctr && { _keyCode isEqualTo DIK_NUMPAD1 } ) exitWith { // adjust increment, less precise
  196.             if (A3EM_nudgeMode == "translate") then {A3EM_nudgeIncrement = A3EM_nudgeIncrement - A3EM_ni_inc2; systemChat format ["Translate increment: %1", A3EM_nudgeIncrement]} else {A3EM_rotateIncrement = A3EM_rotateIncrement - A3EM_ri_inc2; systemChat format ["Rotate increment: %1", A3EM_rotateIncrement]};
  197.             true
  198.         };
  199.         false
  200.     };
  201. }];
  202. _display setVariable ["A3EM_eh_nudgecontrols", _EventHandler]
  203.  
Add Comment
Please, Sign In to add comment