Custom Axis Gizmo Usage

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.

Custom Axis Gizmo Example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- 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 APIs here: Gizmo API.

For edit modes check here: Edit Modes.