Skip to content

Custom plugins best practices

Fedr edited this page Jul 4, 2022 · 1 revision

Overview

Custom plugins is simple objects to work with MeshLib scene and/or objects. It has base functions:

Available function - plugin will be blocked in UI if this function return false

    // this function id called in each frame for each custom plugin, 
    // so its better to have selectedObjects as param, not to traverse them each time
    MRVIEWER_API virtual bool isAvailable( const std::vector<std::shared_ptr<const Object>>& selectedObjects );

On Enable function - will be called if user enables plugin (only possible if isAvailable has returned true), if onEnable_ function returns false plugin will not be enabled (useful for some expensive checks, not to do them in each frame available function)

    MRVIEWER_API virtual bool onEnable_();

On Disable function - will be called if user disable plugin, it is necessary to clear all plugin data

    MRVIEWER_API virtual void onDisable_();

Draw Dialog function - this function is called in each frame, only if plugin is enabled (will not be called after onDisable_ function). It is necessary to show plugin custom UI.

    MRVIEWER_API virtual void drawDialog( float menuScaling, ImGuiContext* ctx );

Some practices

Use

    ImGui::SetCurrentContext( ctx );

in drawDialog to setup valid ImGui context

If viewport lines or points are needed, make sure to clear them in onDisable_ function (don't forget, that active viewport can be changed during plugin work, so it is better to store viewportId and be careful with adding and removing lines and points). Also do not add and/or remove same lines and points in each frame, it can be done once.