MeshLib C++ Docs
Loading...
Searching...
No Matches
MR::Viewer Class Reference

GLFW-based mesh viewer. More...

#include <MRViewer.h>

Public Types

enum class  EventType {
  EventType::MouseDown , EventType::MouseUp , EventType::MouseMove , EventType::MouseScroll ,
  EventType::KeyDown , EventType::KeyUp , EventType::KeyRepeat , EventType::CharPressed ,
  EventType::Count
}
 types of counted events More...
 
enum class  GLPrimitivesType {
  GLPrimitivesType::PointArraySize , GLPrimitivesType::LineArraySize , GLPrimitivesType::TriangleArraySize , GLPrimitivesType::PointElementsNum ,
  GLPrimitivesType::LineElementsNum , GLPrimitivesType::TriangleElementsNum , GLPrimitivesType::Count
}
 types of gl primitives counters More...
 
using MouseButton = MR::MouseButton
 
using MouseMode = MR::MouseMode
 
using LaunchParams = MR::LaunchParams
 
using PointInAllSpaces = MR::PointInAllSpaces
 

Public Member Functions

MRVIEWER_API int launch (const LaunchParams &params)
 Launch viewer with given params.
 
MRVIEWER_API void launchEventLoop ()
 Starts event loop.
 
MRVIEWER_API void launchShut ()
 Terminate window.
 
bool isLaunched () const
 
const LaunchParamsgetLaunchParams () const
 get full parameters with witch viewer was launched
 
template<typename PluginType >
PluginType * getPluginInstance ()
 
MRVIEWER_API bool isSupportedFormat (const std::filesystem::path &file_name)
 
MRVIEWER_API bool loadFiles (const std::vector< std::filesystem::path > &filesList, const FileLoadOptions &options)
 
MRVIEWER_API bool loadFiles (const std::vector< std::filesystem::path > &filesList)
 
MRVIEWER_API bool saveToFile (const std::filesystem::path &mesh_file_name)
 Save first selected objects to file.
 
MRVIEWER_API bool keyPressed (unsigned int unicode_key, int modifier)
 Callbacks.
 
MRVIEWER_API bool keyDown (int key, int modifier)
 
MRVIEWER_API bool keyUp (int key, int modifier)
 
MRVIEWER_API bool keyRepeat (int key, int modifier)
 
MRVIEWER_API bool mouseDown (MouseButton button, int modifier)
 
MRVIEWER_API bool mouseUp (MouseButton button, int modifier)
 
MRVIEWER_API bool mouseMove (int mouse_x, int mouse_y)
 
MRVIEWER_API bool mouseScroll (float delta_y)
 
MRVIEWER_API bool mouseClick (MouseButton button, int modifier)
 
MRVIEWER_API bool dragStart (MouseButton button, int modifier)
 
MRVIEWER_API bool dragEnd (MouseButton button, int modifier)
 
MRVIEWER_API bool drag (int mouse_x, int mouse_y)
 
MRVIEWER_API bool spaceMouseMove (const Vector3f &translate, const Vector3f &rotate)
 
MRVIEWER_API bool spaceMouseDown (int key)
 
MRVIEWER_API bool spaceMouseUp (int key)
 
MRVIEWER_API bool spaceMouseRepeat (int key)
 
MRVIEWER_API bool dragDrop (const std::vector< std::filesystem::path > &paths)
 
MRVIEWER_API bool touchStart (int id, int x, int y)
 Touch callbacks (now used in EMSCRIPTEN build only)
 
MRVIEWER_API bool touchMove (int id, int x, int y)
 
MRVIEWER_API bool touchEnd (int id, int x, int y)
 
MRVIEWER_API bool touchpadRotateGestureBegin ()
 Touchpad gesture callbacks.
 
MRVIEWER_API bool touchpadRotateGestureUpdate (float angle)
 
MRVIEWER_API bool touchpadRotateGestureEnd ()
 
MRVIEWER_API bool touchpadSwipeGestureBegin ()
 
MRVIEWER_API bool touchpadSwipeGestureUpdate (float dx, float dy, bool kinetic)
 
MRVIEWER_API bool touchpadSwipeGestureEnd ()
 
MRVIEWER_API bool touchpadZoomGestureBegin ()
 
MRVIEWER_API bool touchpadZoomGestureUpdate (float scale, bool kinetic)
 
MRVIEWER_API bool touchpadZoomGestureEnd ()
 
MRVIEWER_API bool interruptWindowClose ()
 This function is called when window should close, if return value is true, window will stay open.
 
MRVIEWER_API void draw (bool force=false)
 Draw everything.
 
MRVIEWER_API void drawFull (bool dirtyScene)
 Draw 3d scene with UI.
 
MRVIEWER_API void drawScene (FramebufferData *framebuffer)
 
void setSceneDirty ()
 Call this function to force redraw scene into scene texture.
 
MRVIEWER_API void setupScene ()
 Setup viewports views.
 
MRVIEWER_API void clearFramebuffers ()
 Cleans framebuffers for all viewports (sets its background)
 
MRVIEWER_API void resize (int w, int h)
 OpenGL context resize.
 
MRVIEWER_API void postResize (int w, int h)
 explicitly set framebuffer size
 
MRVIEWER_API void postSetPosition (int xPos, int yPos)
 external resize due to user interaction
 
MRVIEWER_API void postSetMaximized (bool maximized)
 external set position due to user interaction
 
MRVIEWER_API void postSetIconified (bool iconified)
 external set maximized due to user interaction
 
MRVIEWER_API void postFocus (bool focused)
 external set iconified due to user interaction
 
MRVIEWER_API void postRescale (float x, float y)
 external focus handler due to user interaction
 
MRVIEWER_API void postClose ()
 external rescale due to user interaction
 
MRVIEWER_API void set_root (SceneRootObject &newRoot)
 called when close signal received
 
MRVIEWER_API void clearScene ()
 removes all objects from scene
 
MRVIEWER_API Viewportviewport (ViewportId viewportId={})
 Multi-viewport methods ///.
 
MRVIEWER_API const Viewportviewport (ViewportId viewportId={}) const
 
MRVIEWER_API ViewportId append_viewport (const ViewportRectangle &viewportRect, bool append_empty=false)
 
MRVIEWER_API Box2f getViewportsBounds () const
 
MRVIEWER_API bool erase_viewport (const size_t index)
 
MRVIEWER_API bool erase_viewport (ViewportId viewport_id)
 
MRVIEWER_API int viewport_index (ViewportId viewport_id) const
 
MRVIEWER_API ViewportId getHoveredViewportId () const
 
MRVIEWER_API ViewportId getHoveredViewportIdOrInvalid () const
 Same, but returns an invalid ID if no viewport is hovered, instead of returning the last selected viewport.
 
MRVIEWER_API void select_hovered_viewport ()
 Change selected_core_index to the viewport containing the mouse.
 
MRVIEWER_API void fitDataViewport (MR::ViewportMask vpList=MR::ViewportMask::all(), float fill=0.6f, bool snapView=true)
 
MRVIEWER_API void fitBoxViewport (const Box3f &box, MR::ViewportMask vpList=MR::ViewportMask::all(), float fill=0.6f, bool snapView=true)
 
MRVIEWER_API void preciseFitDataViewport (MR::ViewportMask vpList=MR::ViewportMask::all())
 
MRVIEWER_API void preciseFitDataViewport (MR::ViewportMask vpList, const FitDataParams &param)
 
MRVIEWER_API size_t getTotalFrames () const
 
MRVIEWER_API size_t getSwappedFrames () const
 
MRVIEWER_API size_t getFPS () const
 
MRVIEWER_API double getPrevFrameDrawTimeMillisec () const
 
MRVIEWER_API size_t getStaticGLBufferSize () const
 Returns memory amount used by shared GL memory buffer.
 
MRVIEWER_API void incrementForceRedrawFrames (int i=1, bool swapOnLastOnly=false)
 
MRVIEWER_API void forceSwapOnFrame (int i=0)
 Forces redraw no later than the specified number of frames.
 
MRVIEWER_API bool isCurrentFrameSwapping () const
 Returns true if current frame will be shown on display.
 
MRVIEWER_API size_t getEventsCount (EventType type) const
 Returns number of events of given type.
 
MRVIEWER_API size_t getLastFrameGLPrimitivesCount (GLPrimitivesType type) const
 Returns number of events of given type.
 
MRVIEWER_API void incrementThisFrameGLPrimitivesCount (GLPrimitivesType type, size_t num)
 Increment number of gl primitives drawed in this frame.
 
ViewportMask getPresentViewports () const
 Returns mask of present viewports.
 
MRVIEWER_API void resetAllCounters ()
 Restes frames counter and events counter.
 
MRVIEWER_API Image captureSceneScreenShot (const Vector2i &resolution=Vector2i(), bool transparentBg=false)
 
MRVIEWER_API void captureUIScreenShot (std::function< void(const Image &)> callback, const Vector2i &pos=Vector2i(), const Vector2i &size=Vector2i())
 
MRVIEWER_API bool isAlphaSortAvailable () const
 Returns true if can enable alpha sort.
 
MRVIEWER_API bool enableAlphaSort (bool on)
 
bool isAlphaSortEnabled () const
 Returns true if alpha sort is enabled, false otherwise.
 
MRVIEWER_API int getDepthPeelNumPasses () const
 Returns number of passes performed by depth peeler.
 
MRVIEWER_API void setDepthPeelNumPasses (int numPasses)
 Sets desired number of passes to depth peeler.
 
MRVIEWER_API bool isDepthPeelingEnabled () const
 Returns true if depth peeling is enabled, false otherwise.
 
MRVIEWER_API bool isSceneTextureBound () const
 Returns if scene texture is now bound.
 
MRVIEWER_API void bindSceneTexture (bool bind)
 
MRVIEWER_API bool isSceneTextureEnabled () const
 Returns true if 3d scene is rendering in scene texture instead of main framebuffer.
 
MRVIEWER_API int getMSAA () const
 
MRVIEWER_API void requestChangeMSAA (int newMSAA)
 
MRVIEWER_API int getRequestedMSAA () const
 Returns MSAA level that have been requested (might be different from actual MSAA using, because of GPU limitations or need to restart app)
 
MRVIEWER_API void setViewportSettingsManager (std::unique_ptr< IViewerSettingsManager > mng)
 
MRVIEWER_API const std::unique_ptr< IViewerSettingsManager > & getViewerSettingsManager () const
 
MRVIEWER_API PointInAllSpaces getPixelPointInfo (const Vector3f &screenPoint) const
 Finds point in all spaces from screen space pixel point.
 
MRVIEWER_API PointInAllSpaces getMousePointInfo () const
 Finds point under mouse in all spaces and under mouse viewport id.
 
MRVIEWER_API Vector3f screenToViewport (const Vector3f &screenPoint, ViewportId id) const
 
MRVIEWER_API Vector3f viewportToScreen (const Vector3f &viewportPoint, ViewportId id) const
 
MRVIEWER_API std::vector< std::reference_wrapper< Viewport > > getViewports (ViewportMask mask=ViewportMask::any())
 Returns viewports satisfying given mask.
 
MRVIEWER_API void enableGlobalHistory (bool on)
 Enables or disables global history (clears it on disable)
 
bool isGlobalHistoryEnabled () const
 Return true if global history is enabled, false otherwise.
 
MRVIEWER_API void appendHistoryAction (const std::shared_ptr< HistoryAction > &action)
 
MRVIEWER_API bool globalHistoryUndo ()
 
MRVIEWER_API bool globalHistoryRedo ()
 
MRVIEWER_API HistoryStoregetGlobalHistoryStore () const
 
const std::shared_ptr< SpaceMouse::Handler > & getSpaceMouseHandler () const
 Return spacemouse handler.
 
MRVIEWER_API void onSceneSaved (const std::filesystem::path &savePath, bool storeInRecent=true)
 This method is called after successful scene saving to update scene root, window title and undo.
 
MRVIEWER_API const std::shared_ptr< ImGuiMenu > & getMenuPlugin () const
 Get/Set menu plugin (which is separated from other plugins to be inited first before splash window starts)
 
MRVIEWER_API void setMenuPlugin (std::shared_ptr< ImGuiMenu > menu)
 
MRVIEWER_API std::shared_ptr< RibbonMenugetRibbonMenu () const
 get menu plugin casted in RibbonMenu
 
template<typename T >
std::shared_ptr< T > getMenuPluginAs () const
 Get the menu plugin casted in given type.
 
MRVIEWER_API void stopEventLoop ()
 sets stop event loop flag (this flag is glfwShouldWindowClose equivalent)
 
bool getStopEventLoopFlag () const
 get stop event loop flag (this flag is glfwShouldWindowClose equivalent)
 
bool windowShouldClose ()
 
bool isGLInitialized () const
 
MRVIEWER_API void makeTitleFromSceneRootPath ()
 update the title of the main window and, if any scene was opened, show its filename
 
bool hasScaledFramebuffer () const
 returns true if the system framebuffer is scaled (valid for macOS and Wayland)
 
ViewerSignalssignals ()
 return the structure with all viewer's signals
 
MRVIEWER_API void emplaceEvent (std::string name, ViewerEventCallback cb, bool skipable=false)
 
MRVIEWER_API void popEventByName (const std::string &name)
 pop all events from the queue while they have this name
 
MRVIEWER_API void postEmptyEvent ()
 
const TouchpadControllertouchpadController () const
 
TouchpadControllertouchpadController ()
 
const SpaceMouse::ControllerspaceMouseController () const
 
SpaceMouse::ControllerspaceMouseController ()
 
const MouseControllermouseController () const
 
MouseControllermouseController ()
 
const RecentFilesStorerecentFilesStore () const
 Store of recently opened files.
 
RecentFilesStorerecentFilesStore ()
 
bool getSortDroppedFiles () const
 returns whether to sort the filenames received from Drag&Drop in lexicographical order before adding them in scene
 
void setSortDroppedFiles (bool value)
 sets whether to sort the filenames received from Drag&Drop in lexicographical order before adding them in scene
 
MRVIEWER_API void drawUiRenderObjects ()
 draw 2d (UI) part of objects in scene
 
MRVIEWER_API bool isMultiViewportAvailable ()
 

Static Public Member Functions

static MRVIEWER_API void parseLaunchParams (LaunchParams &params)
 Accumulate launch params from cmd args.
 
static Viewerinstance ()
 provides non const access to viewer
 
static ViewerinstanceRef ()
 
static const ViewerconstInstance ()
 provide const access to viewer
 
static const ViewerconstInstanceRef ()
 

Public Attributes

bool swapOnLastPostEventsRedraw { true }
 if true only last frame of force redraw after events will be swapped, otherwise each will be swapped
 
int forceRedrawMinimumIncrementAfterEvents { 4 }
 minimum auto increment force redraw frames after events
 
GLFWwindow * window
 Member variables ///.
 
std::function< void(Viewer *viewer)> resetSettingsFunction
 
std::vector< Viewportviewport_list
 Stores all the viewing options.
 
size_t selected_viewport_index
 
std::vector< ViewerPlugin * > plugins
 List of registered plugins.
 
float pixelRatio { 1.0f }
 
Vector2i framebufferSize
 
Vector2i windowSavePos
 
Vector2i windowSaveSize
 pos to save
 
Vector2i windowOldPos
 size to save
 
bool windowMaximized { false }
 
bool isAnimating { false }
 if true - calls render without system events
 
int animationMaxFps { 30 }
 max fps if animating
 
float scrollForce { }
 
uint16_t glPickRadius { }
 opengl-based pick window radius in pixels
 
bool experimentalFeatures { }
 Experimental/developer features enabled.
 
std::vector< std::string > commandArgs
 command arguments, each parsed arg should be erased from here not to affect other parsers
 
std::shared_ptr< ObjectMeshbasisAxes
 
std::unique_ptr< CornerControllerObjectbasisViewController
 
std::unique_ptr< ViewportGlobalBasisglobalBasis
 
std::shared_ptr< ObjectMeshrotationSphere
 
std::shared_ptr< ObjectMeshclippingPlaneObject
 Stores clipping plane mesh.
 
std::shared_ptr< ViewerTitlewindowTitle
 class that updates viewer title
 

Friends

MRVIEWER_API ViewergetViewerInstance ()
 returns global instance of Viewer class
 

Detailed Description

GLFW-based mesh viewer.


The documentation for this class was generated from the following file: