Edit Modes

The edit modes are used for contextual separation of operations executed in the editor. A single edit mode can be active only in the editor. The current edit mode is updated by the editor main loop (by calling its onUpdate) every frame. There you can check for example ray scene intersections if you have some specific operation for that, you can also render various debug geometry and so on. To add a new edit mode to the editor, you create a new field in the editor.editModes table, check the available field names in selectEditMode.

The edit modes will appear (sorted by name) in the edit modes toolbar.

For example, selecting the object select edit mode: editor.selectEditMode(editor.editModes.objectSelect)

To add new icons in the editor icon atlas, read here

To add an edit mode to the editor it is recommended you do it in your extension onEditorInitialized function, like so:

Add edit mode
 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
42
43
44
45
46
47
local function myCustomEditModeActivate()
        -- here you prepare your edit mode variables
end

local function myCustomEditModeDeactivate()
        -- here you cleanup your edit mode caches or other things
end

local function myCustomEditModeUpdate()
        -- here you draw your debug edit mode geometry, check mouse clicks, etc.
end

local function myCustomEditModeToolbar()
        -- here you draw your custom mode vertical toolbar buttons
        -- example two buttons for translate and rotate
        if editor.uiIconImageButton(editor.icons.open_with, nil, imgui.ImColorByRGB(255,255,255,255).Value, nil, imgui.ImColorByRGB(128,128,128,128).Value) then
                worldEditorCppApi.setAxisGizmoMode(1)
        end
        if imgui.IsItemHovered() then imgui.BeginTooltip() imgui.Text("Translate") imgui.EndTooltip() end

        if editor.uiIconImageButton(editor.icons.refresh, nil, imgui.ImColorByRGB(255,255,255,255).Value, nil, imgui.ImColorByRGB(128,128,128,128).Value) then
                worldEditorCppApi.setAxisGizmoMode(2)
        end
        if imgui.IsItemHovered() then imgui.BeginTooltip() imgui.Text("Rotate") imgui.EndTooltip() end
end

local function onEditorInitialized()
        editor.editModes.myCustomEditMode =
        {
                displayName = "My Custom Edit Mode"
                onActivate = myCustomEditModeActivate,
                onDeactivate = myCustomEditModeDeactivate,
                onUpdate = myCustomEditModeUpdate,
                onToolbar = myCustomEditModeToolbar,
                actionMap = "myCustom", -- if available, not required
                icon = editor.icons.satellite,
                iconTooltip = "My Custom"
        }
end

M.onEditorInitialized = onEditorInitialized


.....

-- and for example somewhere in a menu or toolbar button, you activate your edit mode
editor.selectEditMode(editor.editModes.myCustomEditMode)