The axis gizmo is usually used to move/rotate/scale normal scene objects, but you can also use it to manipulate custom object handles or other custom visual gizmos in the scene.
For this we provide an API that handles mouse events, transform and drawing of the axis gizmo.
Example of a simple sphere gizmo manipulated by the axis gizmo. This is implemented as an edit mode.
-- keep our helper transform here
local helperTransform = MatrixF(true)
-- called when the axis gizmo started to be dragged
local function myGizmoBeginDrag()
-- you can initialize some dragging variables here
-- or save the previous state of your edited object
end
local function myGizmoEndDrag()
-- you can add some undo action here after all dragging ended
-- comprised of previous and current state
end
local function myGizmoDragging()
-- update/save our gizmo matrix
helperTransform = editor.getAxisGizmoTransform()
end
local function drawMyHelper()
-- draw some sphere where my helper object is in the world
debugDrawer:drawSphere(helperTransform:getColumn(3), 2, ColorF(1, 0.5, 0.2, 1))
end
local function testEditModeActivate()
-- when our edit mode is activated, lets set some axis gizmo stuff
editor.setAxisGizmoMode(editor.AxisGizmoMode_Translate)
editor.setAxisGizmoAlignment(editor.AxisGizmoAlignment_World)
-- set the transform (default or previous)
-- only call once this here, not in the update of the edit mode
editor.setAxisGizmoTransform(helperTransform)
end
local function testEditModeDeactivate()
end
local function testEditModeUpdate()
editor.updateAxisGizmo(myGizmoBeginDrag, myGizmoEndDrag, myGizmoDragging)
drawMyHelper()
editor.drawAxisGizmo()
end
More, check the Gizmo API . Also, check the Edit Mode API .