14#define ENQUEUE_VIEWER_METHOD( NAME, METHOD ) MR::getViewerInstance().emplaceEvent( NAME, [] { \
15 MR::getViewerInstance() . METHOD (); \
17#define ENQUEUE_VIEWER_METHOD_ARGS( NAME, METHOD, ... ) MR::getViewerInstance().emplaceEvent( NAME, [__VA_ARGS__] { \
18 MR::getViewerInstance() . METHOD ( __VA_ARGS__ ); \
20#define ENQUEUE_VIEWER_METHOD_ARGS_SKIPABLE( NAME, METHOD, ... ) MR::getViewerInstance().emplaceEvent( NAME, [__VA_ARGS__] { \
21 MR::getViewerInstance() . METHOD ( __VA_ARGS__ ); \
51 std::string
name{
"MRViewer" };
68class MRVIEWER_CLASS Viewer
98 template<
typename PluginType>
103 auto p =
dynamic_cast< PluginType*
>( plugin );
119 MRVIEWER_API
bool loadFiles(
const std::vector< std::filesystem::path>& filesList );
122 MRVIEWER_API
bool saveToFile(
const std::filesystem::path & mesh_file_name );
125 MRVIEWER_API
bool keyPressed(
unsigned int unicode_key,
int modifier );
126 MRVIEWER_API
bool keyDown(
int key,
int modifier );
127 MRVIEWER_API
bool keyUp(
int key,
int modifier );
131 MRVIEWER_API
bool mouseMove(
int mouse_x,
int mouse_y );
136 MRVIEWER_API
bool drag(
int mouse_x,
int mouse_y );
137 MRVIEWER_API
bool spaceMouseMove(
const Vector3f& translate,
const Vector3f& rotate );
141 MRVIEWER_API
bool dragDrop(
const std::vector<std::filesystem::path>& paths );
145 MRVIEWER_API
bool touchEnd(
int id,
int x,
int y );
160 MRVIEWER_API
void draw(
bool force =
false );
173 MRVIEWER_API
void resize(
int w,
int h );
332 const Vector2i& pos = Vector2i(),
const Vector2i&
size = Vector2i() );
416 MRVIEWER_API
void onSceneSaved(
const std::filesystem::path& savePath,
bool storeInRecent =
true );
426 template <
typename T>
553 void shutdownPlugins_();
556 void mainLoopFunc_();
557 static void emsMainInfiniteLoop();
560 bool draw_(
bool force );
563 int forceRedrawFrames_{ 0 };
565 int forceRedrawFramesWithoutSwap_{ 0 };
567 std::unique_ptr<ViewerEventQueue> eventQueue_;
570 std::shared_ptr<ImGuiMenu> menuPlugin_;
572 std::unique_ptr<TouchpadController> touchpadController_;
573 std::unique_ptr<SpaceMouse::Controller> spaceMouseController_;
574 std::unique_ptr<TouchesController> touchesController_;
575 std::unique_ptr<MouseController> mouseController_;
576 std::unique_ptr<IDragDropHandler> dragDropAdvancedHandler_;
578 std::unique_ptr<RecentFilesStore> recentFilesStore_;
579 std::unique_ptr<FrameCounter> frameCounter_;
581 mutable struct EventsCounter
587 mutable struct GLPrimitivesCounter
591 } glPrimitivesCounter_;
595 bool tryCreateWindow_(
bool fullscreen,
int&
width,
int&
height,
const std::string& name,
int major,
int minor );
597 bool needRedraw_()
const;
600 void initGlobalBasisAxesObject_();
601 void initBasisAxesObject_();
602 void initBasisViewControllerObject_();
603 void initClippingPlaneObject_();
604 void initRotationCenterObject_();
607 void initSpaceMouseHandler_();
610 void updatePixelRatio_();
615 int getRequiredMSAA_(
bool sceneTextureOn,
bool forSceneTexture )
const;
617 bool stopEventLoop_{
false };
619 bool isLaunched_{
false };
621 bool focusRedrawReady_{
false };
623 std::unique_ptr<SceneTextureGL> sceneTexture_;
624 std::unique_ptr<AlphaSortGL> alphaSorter_;
625 std::unique_ptr<DepthPeelingGL> depthPeeler_;
627 bool alphaSortEnabled_{
false };
629 bool glInitialized_{
false };
631 bool isInDraw_{
false };
632 bool dirtyScene_{
false };
634 bool hasScaledFramebuffer_{
false };
636 bool sortDroppedFiles_{
true };
638 LaunchParams launchParams_;
640 ViewportId getFirstAvailableViewportId_()
const;
641 ViewportMask presentViewportsMask_;
643 std::unique_ptr<IViewerSettingsManager> settingsMng_;
645 std::unique_ptr<HistoryStore> globalHistoryStore_;
647 std::shared_ptr<SpaceMouse::Handler> spaceMouseHandler_;
650 std::unique_ptr<Connections> connections_;
651 std::unique_ptr<ViewerSignals> signals_;
class for easier rendering in framebuffer texture
Definition MRRenderGLHelpers.h:217
This class stores history stack for undo/redo.
Definition MRHistoryStore.h:16
Definition MRMouseController.h:24
Definition MRRecentFilesStore.h:20
Object that is parent of all scene.
Definition MRSceneRoot.h:14
this class stores maps spacemouse event - program action
Definition MRSpaceMouseController.h:11
Definition MRTouchpadController.h:35
Definition MRSetupViewer.h:16
Definition MRViewportId.h:16
stores mask of viewport unique identifiers
Definition MRViewportId.h:42
static ViewportMask any()
Definition MRViewportId.h:50
static ViewportMask all()
mask meaning all or any viewports
Definition MRViewportId.h:49
Definition MRViewport.h:49
auto width(const Box< V > &box)
returns size along x axis
Definition MRBox.h:354
auto height(const Box< V > &box)
returns size along y axis
Definition MRBox.h:361
bool hasScaledFramebuffer() const
returns true if the system framebuffer is scaled (valid for macOS and Wayland)
Definition MRViewer.h:447
WindowMode
Definition MRViewer.h:39
void clearScene()
removes all objects from scene
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.
bool render3dSceneInTexture
Definition MRViewer.h:48
MouseMode
Standard mouse functions for camera control.
Definition MRMouse.h:22
bool console
If !startEventLoop close immediately after start, otherwise close on window close,...
Definition MRViewer.h:55
bool developerFeatures
If not set renders scene each frame.
Definition MRViewer.h:49
bool touchpadRotateGestureUpdate(float angle)
void drawFull(bool dirtyScene)
Draw 3d scene with UI.
size_t getStaticGLBufferSize() const
Returns memory amount used by shared GL memory buffer.
bool mouseScroll(float delta_y)
void postFocus(bool focused)
external set iconified due to user interaction
std::vector< std::reference_wrapper< Viewport > > getViewports(ViewportMask mask=ViewportMask::any())
Returns viewports satisfying given mask.
char ** argv
Pass argc.
Definition MRViewer.h:57
bool touchEnd(int id, int x, int y)
MouseButton
Definition MRMouse.h:12
bool startEventLoop
if true - resets config file on start of the application
Definition MRViewer.h:53
void setViewportSettingsManager(std::unique_ptr< IViewerSettingsManager > mng)
void popEventByName(const std::string &name)
pop all events from the queue while they have this name
int animationMaxFps
max fps if animating
Definition MRViewer.h:476
bool fullscreen
Definition MRViewer.h:35
bool keyRepeat(int key, int modifier)
MR::LaunchParams LaunchParams
Definition MRViewer.h:74
const MouseController & mouseController() const
Definition MRViewer.h:514
void emplaceEvent(std::string name, ViewerEventCallback cb, bool skipable=false)
std::shared_ptr< ViewerTitle > windowTitle
class that updates viewer title
Definition MRViewer.h:495
void draw(bool force=false)
Draw everything.
bool keyPressed(unsigned int unicode_key, int modifier)
Callbacks.
void setDepthPeelNumPasses(int numPasses)
Sets desired number of passes to depth peeler.
int animationMaxFps
if true - calls render without system events
Definition MRViewer.h:61
Viewport & viewport(ViewportId viewportId={})
Multi-viewport methods ///.
bool dragDrop(const std::vector< std::filesystem::path > &paths)
bool loadFiles(const std::vector< std::filesystem::path > &filesList, const FileLoadOptions &options)
uint16_t glPickRadius
opengl-based pick window radius in pixels
Definition MRViewer.h:481
bool isSupportedFormat(const std::filesystem::path &file_name)
void setupScene()
Setup viewports views.
int argc
If true - shows developers console.
Definition MRViewer.h:56
std::vector< ViewerPlugin * > plugins
List of registered plugins.
Definition MRViewer.h:464
bool swapOnLastPostEventsRedraw
if true only last frame of force redraw after events will be swapped, otherwise each will be swapped
Definition MRViewer.h:264
Vector3f viewportToScreen(const Vector3f &viewportPoint, ViewportId id) const
Vector2i windowSaveSize
pos to save
Definition MRViewer.h:469
void captureUIScreenShot(std::function< void(const Image &)> callback, const Vector2i &pos=Vector2i(), const Vector2i &size=Vector2i())
bool isCurrentFrameSwapping() const
Returns true if current frame will be shown on display.
bool touchpadZoomGestureEnd()
bool isDepthPeelingEnabled() const
Returns true if depth peeling is enabled, false otherwise.
EventType
types of counted events
Definition MRViewer.h:280
const SpaceMouse::Controller & spaceMouseController() const
Definition MRViewer.h:511
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
ViewportMask getPresentViewports() const
Returns mask of present viewports.
Definition MRViewer.h:313
const TouchpadController & touchpadController() const
Definition MRViewer.h:508
PointInAllSpaces getMousePointInfo() const
Finds point under mouse in all spaces and under mouse viewport id.
ViewportId getHoveredViewportId() const
const Viewport & viewport(ViewportId viewportId={}) const
std::shared_ptr< SplashWindow > splashWindow
unload all extended libraries right before program exit
Definition MRViewer.h:64
void incrementForceRedrawFrames(int i=1, bool swapOnLastOnly=false)
bool saveToFile(const std::filesystem::path &mesh_file_name)
Save first selected objects to file.
std::shared_ptr< T > getMenuPluginAs() const
Get the menu plugin casted in given type.
Definition MRViewer.h:427
bool isGLInitialized() const
Definition MRViewer.h:441
bool touchStart(int id, int x, int y)
Touch callbacks (now used in EMSCRIPTEN build only)
std::shared_ptr< ObjectMesh > rotationSphere
Definition MRViewer.h:490
Vector2i windowOldPos
size to save
Definition MRViewer.h:470
static void parseLaunchParams(LaunchParams ¶ms)
Accumulate launch params from cmd args.
std::vector< std::string > commandArgs
command arguments, each parsed arg should be erased from here not to affect other parsers
Definition MRViewer.h:485
bool enableAlphaSort(bool on)
HistoryStore * getGlobalHistoryStore() const
Definition MRViewer.h:410
const std::shared_ptr< ImGuiMenu > & getMenuPlugin() const
Get/Set menu plugin (which is separated from other plugins to be inited first before splash window st...
void clearFramebuffers()
Cleans framebuffers for all viewports (sets its background)
void fitBoxViewport(const Box3f &box, MR::ViewportMask vpList=MR::ViewportMask::all(), float fill=0.6f, bool snapView=true)
void drawScene(FramebufferData *framebuffer)
ViewportId append_viewport(const ViewportRectangle &viewportRect, bool append_empty=false)
bool spaceMouseDown(int key)
bool isAlphaSortAvailable() const
Returns true if can enable alpha sort.
std::array< size_t, size_t(GLPrimitivesType::Count)> counter
Definition MRViewer.h:589
const LaunchParams & getLaunchParams() const
get full parameters with witch viewer was launched
Definition MRViewer.h:89
std::function< void(Viewer *viewer)> resetSettingsFunction
Definition MRViewer.h:457
bool keyUp(int key, int modifier)
void bindSceneTexture(bool bind)
bool loadFiles(const std::vector< std::filesystem::path > &filesList)
ViewportId getHoveredViewportIdOrInvalid() const
Same, but returns an invalid ID if no viewport is hovered, instead of returning the last selected vie...
bool mouseDown(MouseButton button, int modifier)
void postRescale(float x, float y)
external focus handler due to user interaction
int launch(const LaunchParams ¶ms)
Launch viewer with given params.
bool windowMaximized
Definition MRViewer.h:471
bool unloadPluginsAtEnd
max fps if animating
Definition MRViewer.h:62
PointInAllSpaces getPixelPointInfo(const Vector3f &screenPoint) const
Finds point in all spaces from screen space pixel point.
void preciseFitDataViewport(MR::ViewportMask vpList, const FitDataParams ¶m)
bool isAlphaSortEnabled() const
Returns true if alpha sort is enabled, false otherwise.
Definition MRViewer.h:340
bool touchpadSwipeGestureBegin()
bool touchpadZoomGestureBegin()
bool touchpadSwipeGestureUpdate(float dx, float dy, bool kinetic)
void incrementThisFrameGLPrimitivesCount(GLPrimitivesType type, size_t num)
Increment number of gl primitives drawed in this frame.
const std::unique_ptr< IViewerSettingsManager > & getViewerSettingsManager() const
Definition MRViewer.h:370
bool experimentalFeatures
Experimental/developer features enabled.
Definition MRViewer.h:483
bool close
If false - does not start event loop.
Definition MRViewer.h:54
size_t selected_viewport_index
Definition MRViewer.h:461
bool multiViewport
If set shows some developer features useful for debugging.
Definition MRViewer.h:50
float pixelRatio
Definition MRViewer.h:466
bool isAnimating
if true - calls render without system events
Definition MRViewer.h:474
bool interruptWindowClose()
This function is called when window should close, if return value is true, window will stay open.
double getPrevFrameDrawTimeMillisec() const
static Viewer * instance()
provides non const access to viewer
Definition MRViewer.h:92
void launchShut()
Terminate window.
PluginType * getPluginInstance()
Definition MRViewer.h:99
Image captureSceneScreenShot(const Vector2i &resolution=Vector2i(), bool transparentBg=false)
bool spaceMouseMove(const Vector3f &translate, const Vector3f &rotate)
bool isLaunched() const
Definition MRViewer.h:86
void drawUiRenderObjects()
draw 2d (UI) part of objects in scene
void enableGlobalHistory(bool on)
Enables or disables global history (clears it on disable)
bool showMRVersionInTitle
Pass argv.
Definition MRViewer.h:59
static const Viewer * constInstance()
provide const access to viewer
Definition MRViewer.h:95
std::unique_ptr< ViewportGlobalBasis > globalBasis
Definition MRViewer.h:489
MR::MouseMode MouseMode
Definition MRViewer.h:72
void fitDataViewport(MR::ViewportMask vpList=MR::ViewportMask::all(), float fill=0.6f, bool snapView=true)
size_t getSwappedFrames() const
bool erase_viewport(ViewportId viewport_id)
Box2f getViewportsBounds() const
std::shared_ptr< ObjectMesh > clippingPlaneObject
Stores clipping plane mesh.
Definition MRViewer.h:492
void launchEventLoop()
Starts event loop.
void makeTitleFromSceneRootPath()
update the title of the main window and, if any scene was opened, show its filename
int getDepthPeelNumPasses() const
Returns number of passes performed by depth peeler.
bool touchMove(int id, int x, int y)
static const Viewer & constInstanceRef()
Definition MRViewer.h:96
void setSortDroppedFiles(bool value)
sets whether to sort the filenames received from Drag&Drop in lexicographical order before adding the...
Definition MRViewer.h:525
friend Viewer & getViewerInstance()
returns global instance of Viewer class
SpaceMouse::Controller & spaceMouseController()
Definition MRViewer.h:512
void requestChangeMSAA(int newMSAA)
Vector3f screenToViewport(const Vector3f &screenPoint, ViewportId id) const
size_t getLastFrameGLPrimitivesCount(GLPrimitivesType type) const
Returns number of events of given type.
bool mouseClick(MouseButton button, int modifier)
RecentFilesStore & recentFilesStore()
Definition MRViewer.h:519
bool enableTransparentBackground
Definition MRViewer.h:46
void resize(int w, int h)
OpenGL context resize.
int height
Definition MRViewer.h:37
bool isSceneTextureBound() const
Returns if scene texture is now bound.
static Viewer & instanceRef()
Definition MRViewer.h:93
void select_hovered_viewport()
Change selected_core_index to the viewport containing the mouse.
std::shared_ptr< ObjectMesh > basisAxes
Definition MRViewer.h:487
bool isSceneTextureEnabled() const
Returns true if 3d scene is rendering in scene texture instead of main framebuffer.
bool resetConfig
Window name.
Definition MRViewer.h:52
std::array< size_t, size_t(EventType::Count)> counter
Definition MRViewer.h:583
size_t getTotalFrames() const
bool mouseMove(int mouse_x, int mouse_y)
bool touchpadRotateGestureEnd()
void postSetMaximized(bool maximized)
external set position due to user interaction
void postSetPosition(int xPos, int yPos)
external resize due to user interaction
bool spaceMouseRepeat(int key)
void postClose()
external rescale due to user interaction
bool touchpadSwipeGestureEnd()
Vector2i framebufferSize
Definition MRViewer.h:467
ViewerSignals & signals()
return the structure with all viewer's signals
Definition MRViewer.h:498
bool getSortDroppedFiles() const
returns whether to sort the filenames received from Drag&Drop in lexicographical order before adding ...
Definition MRViewer.h:522
void preciseFitDataViewport(MR::ViewportMask vpList=MR::ViewportMask::all())
void setMenuPlugin(std::shared_ptr< ImGuiMenu > menu)
void forceSwapOnFrame(int i=0)
Forces redraw no later than the specified number of frames.
MR::MouseButton MouseButton
Definition MRViewer.h:71
int viewport_index(ViewportId viewport_id) const
void resetAllCounters()
Restes frames counter and events counter.
GLPrimitivesType
types of gl primitives counters
Definition MRViewer.h:296
Vector2i windowSavePos
Definition MRViewer.h:468
bool preferOpenGL3
Definition MRViewer.h:47
std::unique_ptr< CornerControllerObject > basisViewController
Definition MRViewer.h:488
int width
if true starts fullscreen
Definition MRViewer.h:36
bool mouseUp(MouseButton button, int modifier)
bool keyDown(int key, int modifier)
void appendHistoryAction(const std::shared_ptr< HistoryAction > &action)
bool erase_viewport(const size_t index)
bool touchpadZoomGestureUpdate(float scale, bool kinetic)
void postSetIconified(bool iconified)
external set maximized due to user interaction
int launchDefaultViewer(const Viewer::LaunchParams ¶ms, const ViewerSetup &setup)
starts default viewer with given params and setup
bool dragEnd(MouseButton button, int modifier)
GLFWwindow * window
Member variables ///.
Definition MRViewer.h:453
enum MR::LaunchParams::WindowMode HideInit
MR::PointInAllSpaces PointInAllSpaces
Definition MRViewer.h:372
std::string name
If set allows to move the imgui (tool) windows outside the main () window. (unavailable for Apple,...
Definition MRViewer.h:51
void stopEventLoop()
sets stop event loop flag (this flag is glfwShouldWindowClose equivalent)
int getRequestedMSAA() const
Returns MSAA level that have been requested (might be different from actual MSAA using,...
void setSceneDirty()
Call this function to force redraw scene into scene texture.
Definition MRViewer.h:167
void postResize(int w, int h)
explicitly set framebuffer size
Box2f ViewportRectangle
Viewport size.
Definition MRViewerFwd.h:17
bool isMultiViewportAvailable()
MouseController & mouseController()
Definition MRViewer.h:515
size_t getEventsCount(EventType type) const
Returns number of events of given type.
bool drag(int mouse_x, int mouse_y)
const RecentFilesStore & recentFilesStore() const
Store of recently opened files.
Definition MRViewer.h:518
TouchpadController & touchpadController()
Definition MRViewer.h:509
bool spaceMouseUp(int key)
std::shared_ptr< RibbonMenu > getRibbonMenu() const
get menu plugin casted in RibbonMenu
bool touchpadRotateGestureBegin()
Touchpad gesture callbacks.
std::function< void()> ViewerEventCallback
Definition MRViewerFwd.h:79
int forceRedrawMinimumIncrementAfterEvents
minimum auto increment force redraw frames after events
Definition MRViewer.h:266
bool isGlobalHistoryEnabled() const
Return true if global history is enabled, false otherwise.
Definition MRViewer.h:397
bool dragStart(MouseButton button, int modifier)
void set_root(SceneRootObject &newRoot)
called when close signal received
std::vector< Viewport > viewport_list
Stores all the viewing options.
Definition MRViewer.h:460
bool isAnimating
if true - print version info in window title
Definition MRViewer.h:60
const std::shared_ptr< SpaceMouse::Handler > & getSpaceMouseHandler() const
Return spacemouse handler.
Definition MRViewer.h:413
float scrollForce
Definition MRViewer.h:479
bool getStopEventLoopFlag() const
get stop event loop flag (this flag is glfwShouldWindowClose equivalent)
Definition MRViewer.h:432
@ NoWindow
Launches in "Hide" mode if OpenGL is present and "NoWindow" if it is not.
Definition MRViewer.h:44
@ TryHidden
Don't show window.
Definition MRViewer.h:43
@ Hide
Show window after init.
Definition MRViewer.h:42
@ Show
Definition MRViewer.h:40
@ angle
Direction, normally Vector3f.
Definition MRFeatureObject.h:26
@ KeyUp
Definition MRViewer.h:286
@ KeyRepeat
Definition MRViewer.h:287
@ MouseUp
Definition MRViewer.h:282
@ MouseScroll
Definition MRViewer.h:284
@ MouseDown
Definition MRViewer.h:281
@ KeyDown
Definition MRViewer.h:285
@ Count
Definition MRViewer.h:289
@ CharPressed
Definition MRViewer.h:288
@ MouseMove
Definition MRViewer.h:283
@ LineElementsNum
Definition MRViewer.h:302
@ LineArraySize
Definition MRViewer.h:299
@ TriangleElementsNum
Definition MRViewer.h:303
@ TriangleArraySize
Definition MRViewer.h:300
@ PointElementsNum
Definition MRViewer.h:301
@ PointArraySize
arrays and elements are different gl calls
Definition MRViewer.h:298
@ Count
Definition MRViewer.h:304
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRFileLoadOptions.h:14
Definition MRFitData.h:32
This struct contains rules for viewer launch.
Definition MRViewer.h:34
Definition MRPointInAllSpaces.h:16
Definition MRViewerSignals.h:13