Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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"
- // Select 1 or more objects in 3den and you can adjust their position(s).
- // Created by Rylan
- //
- // Controls:
- // Shift + Numpad 5 = Nudge "forward" (Global coordinates so it probably won't be forward for the object if it has changed rotation.)
- // Shift + Numpad 1 = Nudge "left"
- // Shift + Numpad 2 = Nudge "backward"
- // Shift + Numpad 3 = Nudge "right"
- // Alt + Numpad 5 = Nudge "up" (vertical)
- // Alt + Numpad 2 = Nudge "down" (vertical)
- // Ctrl + Numpad 5 or 2 = Increase or decrease the nudge increment by 0.0025 - For high precision
- // Ctrl + Numpad 1 or 3 = Increase or decrease the nudge increment by 0.01 --- For lower precision
- // Shift + Numpad 0 = Toggle rotate or translate mode (rotate mode has same controls, including separate increment values)
- // Numpad 0 = Cycle through rotation axis (yaw, pitch, roll)
- //
- // 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.
- // 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)
- A3EM_nudgeIncrement = 0.01; // Default nudge value
- A3EM_ni_inc1 = 0.0025; // ---- High precision adjustment
- A3EM_ni_inc2 = 0.1; // ------- Low precision adjustment
- A3EM_rotateIncrement = 0.1; // Default rotate value
- A3EM_ri_inc1 = 0.05; // ---- High precision adjustment
- A3EM_ri_inc2 = 0.15; // ------- Low precision adjustment
- A3EM_nudgeMode = "translate"; // "rotate"
- A3EM_rotateAxis = "yaw"; // "pitch" "roll"
- A3EM_fnc_nudgeTranslate =
- {
- collect3DENHistory
- {
- private ["_keypress", "_EditorObjects"];
- _keypress = _this select 0;
- _EditorObjects = get3DENSelected "object";
- if (count _EditorObjects < 1) exitWith {systemChat "No object(s) selected!"};
- {
- if (_keypress == "NudgeUp") then {
- private _oldPos = (_x get3DENAttribute "Position") select 0;
- set3DENAttributes [[[_x],"Position",[(_oldPos select 0),(_oldPos select 1) + A3EM_nudgeincrement,(_oldPos select 2)]]];
- };
- if (_keypress == "NudgeDown") then {
- private _oldPos = (_x get3DENAttribute "Position") select 0;
- set3DENAttributes [[[_x],"Position",[(_oldPos select 0),(_oldPos select 1) - A3EM_nudgeincrement,(_oldPos select 2)]]];
- };
- if (_keypress == "NudgeRight") then {
- private _oldPos = (_x get3DENAttribute "Position") select 0;
- set3DENAttributes [[[_x],"Position",[(_oldPos select 0) + A3EM_nudgeincrement,(_oldPos select 1),(_oldPos select 2)]]];
- };
- if (_keypress == "NudgeLeft") then {
- private _oldPos = (_x get3DENAttribute "Position") select 0;
- set3DENAttributes [[[_x],"Position",[(_oldPos select 0) - A3EM_nudgeincrement,(_oldPos select 1),(_oldPos select 2)]]];
- };
- if (_keypress == "AltNudgeUp") then {
- private _oldPos = (_x get3DENAttribute "Position") select 0;
- set3DENAttributes [[[_x],"Position",[(_oldPos select 0),(_oldPos select 1),(_oldPos select 2) + A3EM_nudgeincrement]]];
- };
- if (_keypress == "AltNudgeDown") then {
- private _oldPos = (_x get3DENAttribute "Position") select 0;
- set3DENAttributes [[[_x],"Position",[(_oldPos select 0),(_oldPos select 1),(_oldPos select 2) - A3EM_nudgeincrement]]];
- };
- } forEach _EditorObjects;
- };
- };
- A3EM_fnc_nudgeRotate =
- {
- collect3DENHistory
- {
- private ["_keypress", "_axis", "_EditorObjects"];
- _keypress = _this select 0;
- _axis = _this select 1;
- _EditorObjects = get3DENSelected "object";
- if (count _EditorObjects < 1) exitWith {systemChat "No object(s) selected!"};
- if (_axis == "yaw") then {
- {
- if ((_keypress == "RotateUp") OR (_keypress == "RotateRight")) then {
- private _oldPos = (_x get3DENAttribute "Rotation") select 0;
- set3DENAttributes [[[_x],"Rotation",[(_oldPos select 0),(_oldPos select 1),(_oldPos select 2) - A3EM_rotateIncrement]]];
- };
- if ((_keypress == "RotateDown") OR (_keypress == "RotateLeft")) then {
- private _oldPos = (_x get3DENAttribute "Rotation") select 0;
- set3DENAttributes [[[_x],"Rotation",[(_oldPos select 0),(_oldPos select 1),(_oldPos select 2) + A3EM_rotateIncrement]]];
- };
- } forEach _EditorObjects;
- };
- if (_axis == "pitch") then {
- {
- if ((_keypress == "RotateUp") OR (_keypress == "RotateRight")) then {
- private _oldPos = (_x get3DENAttribute "Rotation") select 0;
- set3DENAttributes [[[_x],"Rotation",[(_oldPos select 0) - A3EM_rotateIncrement,(_oldPos select 1),(_oldPos select 2)]]];
- };
- if ((_keypress == "RotateDown") OR (_keypress == "RotateLeft")) then {
- private _oldPos = (_x get3DENAttribute "Rotation") select 0;
- set3DENAttributes [[[_x],"Rotation",[(_oldPos select 0) + A3EM_rotateIncrement,(_oldPos select 1),(_oldPos select 2)]]];
- };
- } forEach _EditorObjects;
- };
- if (_axis == "roll") then {
- {
- if ((_keypress == "RotateUp") OR (_keypress == "RotateRight")) then {
- private _oldPos = (_x get3DENAttribute "Rotation") select 0;
- set3DENAttributes [[[_x],"Rotation",[(_oldPos select 0),(_oldPos select 1) - A3EM_rotateIncrement,(_oldPos select 2)]]];
- };
- if ((_keypress == "RotateDown") OR (_keypress == "RotateLeft")) then {
- private _oldPos = (_x get3DENAttribute "Rotation") select 0;
- set3DENAttributes [[[_x],"Rotation",[(_oldPos select 0),(_oldPos select 1) + A3EM_rotateIncrement,(_oldPos select 2)]]];
- };
- } forEach _EditorObjects;
- };
- };
- };
- waitUntil {!isNull (findDisplay 313)};
- #include "\a3\ui_f\hpp\definedikcodes.inc"
- _display = findDisplay 313;
- if (_display getVariable ["A3EM_eh_nudgecontrols", -1] != -1) exitWith {};
- _EventHandler = _display displayAddEventHandler [ "KeyDown", {
- params[
- "_display",
- "_keyCode",
- "_shft",
- "_ctr",
- "_alt"
- ];
- call {
- if ( _shft && { _keyCode isEqualTo DIK_NUMPAD0 } ) exitWith { // translate or rotate mode
- if (A3EM_nudgeMode == "translate") then {A3EM_nudgeMode = "rotate"; systemChat "Rotate mode"} else {A3EM_nudgeMode = "translate"; systemChat "Translate mode"};
- true
- };
- if ( _keyCode isEqualTo DIK_NUMPAD0 ) exitWith { // rotation axis
- if (A3EM_rotateAxis == "yaw") exitWith {A3EM_rotateAxis = "pitch"; systemChat "Rotation axis set to 'pitch'"};
- if (A3EM_rotateAxis == "pitch") exitWith {A3EM_rotateAxis = "roll"; systemChat "Rotation axis set to 'roll'"};
- if (A3EM_rotateAxis == "roll") exitWith {A3EM_rotateAxis = "yaw"; systemChat "Rotation axis set to 'yaw'"};
- true
- };
- if ( _shft && { _keyCode isEqualTo DIK_NUMPAD5 } ) exitWith { // up
- if (A3EM_nudgeMode == "translate") then {["NudgeUp"] call A3EM_fnc_nudgeTranslate} else {["RotateUp", A3EM_rotateAxis] call A3EM_fnc_nudgeRotate};
- true
- };
- if ( _shft && { _keyCode isEqualTo DIK_NUMPAD2 } ) exitWith { // down
- if (A3EM_nudgeMode == "translate") then {["NudgeDown"] call A3EM_fnc_nudgeTranslate} else {["RotateDown", A3EM_rotateAxis] call A3EM_fnc_nudgeRotate};
- true
- };
- if ( _shft && { _keyCode isEqualTo DIK_NUMPAD3 } ) exitWith { // right
- if (A3EM_nudgeMode == "translate") then {["NudgeRight"] call A3EM_fnc_nudgeTranslate} else {["RotateRight", A3EM_rotateAxis] call A3EM_fnc_nudgeRotate};
- true
- };
- if ( _shft && { _keyCode isEqualTo DIK_NUMPAD1 } ) exitWith { // left
- if (A3EM_nudgeMode == "translate") then {["NudgeLeft"] call A3EM_fnc_nudgeTranslate} else {["RotateLeft", A3EM_rotateAxis] call A3EM_fnc_nudgeRotate};
- true
- };
- if ( _alt && { _keyCode isEqualTo DIK_NUMPAD5 } ) exitWith { // up - vertical
- ["AltNudgeUp"] call A3EM_fnc_nudgeTranslate;
- true
- };
- if ( _alt && { _keyCode isEqualTo DIK_NUMPAD2 } ) exitWith { // down - vertical
- ["AltNudgeDown"] call A3EM_fnc_nudgeTranslate;
- true
- };
- if ( _ctr && { _keyCode isEqualTo DIK_NUMPAD5 } ) exitWith { // adjust increment, precise
- 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]};
- true
- };
- if ( _ctr && { _keyCode isEqualTo DIK_NUMPAD2 } ) exitWith { // adjust increment, precise
- 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]};
- true
- };
- if ( _ctr && { _keyCode isEqualTo DIK_NUMPAD3 } ) exitWith { // adjust increment, less precise
- 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]};
- true
- };
- if ( _ctr && { _keyCode isEqualTo DIK_NUMPAD1 } ) exitWith { // adjust increment, less precise
- 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]};
- true
- };
- false
- };
- }];
- _display setVariable ["A3EM_eh_nudgecontrols", _EventHandler]
Add Comment
Please, Sign In to add comment