MeshLib C++ Docs
Loading...
Searching...
No Matches
MRViewer.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRViewerInstance.h"
4#include "MRMouse.h"
5#include <MRMesh/MRVector2.h>
8#include <cstdint>
9#include <filesystem>
10#include <optional>
11
12struct GLFWwindow;
13
15#define ENQUEUE_VIEWER_METHOD( NAME, METHOD ) MR::getViewerInstance().emplaceEvent( NAME, [] { \
16 MR::getViewerInstance() . METHOD (); \
17} )
18#define ENQUEUE_VIEWER_METHOD_ARGS( NAME, METHOD, ... ) MR::getViewerInstance().emplaceEvent( NAME, [__VA_ARGS__] { \
19 MR::getViewerInstance() . METHOD ( __VA_ARGS__ ); \
20} )
21#define ENQUEUE_VIEWER_METHOD_ARGS_SKIPABLE( NAME, METHOD, ... ) MR::getViewerInstance().emplaceEvent( NAME, [__VA_ARGS__] { \
22 MR::getViewerInstance() . METHOD ( __VA_ARGS__ ); \
23}, true )
24
25namespace MR
26{
29
30
31class FramebufferData;
32
35{
36 bool fullscreen{ false };
37 int width{ 0 };
38 int height{ 0 };
48 bool preferOpenGL3{ false };
50 bool developerFeatures{ false };
51 bool multiViewport{ true };
52 std::string name{ "MRViewer" };
53 bool resetConfig{ false };
54 bool startEventLoop{ true };
55 bool close{ true };
56 bool console{ false };
57 int argc{ 0 };
58 char** argv{ nullptr };
59
60 bool showMRVersionInTitle{ false };
61 bool isAnimating{ false };
62 int animationMaxFps{ 30 };
63 bool unloadPluginsAtEnd{ false };
64 bool noMSAA{ false };
65
66 std::shared_ptr<SplashWindow> splashWindow;
67};
68
70class MRVIEWER_CLASS Viewer
71{
72public:
75
77
79 MRVIEWER_API static void parseLaunchParams( LaunchParams& params );
80
83 MRVIEWER_API int preLaunch( const LaunchParams& params );
86 MRVIEWER_API int launchShow( const LaunchParams& params );
88 MRVIEWER_API int launch( const LaunchParams& params );
90 MRVIEWER_API void launchEventLoop();
94 MRVIEWER_API void runEventLoopIteration( double maxWaitSec = -1 );
96 MRVIEWER_API void launchShut();
97
98 bool isPreLaunched() const { return isPreLaunched_; }
99 bool isLaunched() const { return isLaunched_; }
100
102 const LaunchParams& getLaunchParams() const { return launchParams_; }
103
105 static Viewer* instance() { return &getViewerInstance(); }
106 static Viewer& instanceRef() { return getViewerInstance(); }
108 static const Viewer* constInstance() { return &getViewerInstance(); }
109 static const Viewer& constInstanceRef() { return getViewerInstance(); }
110
111 template<typename PluginType>
112 PluginType* getPluginInstance()
113 {
114 for ( auto& plugin : plugins )
115 {
116 auto p = dynamic_cast< PluginType* >( plugin );
117 if ( p )
118 {
119 return p;
120 }
121 }
122 return nullptr;
123 }
124
127 MRVIEWER_API bool isSupportedFormat( const std::filesystem::path& file_name );
128
131 MRVIEWER_API bool loadFiles( const std::vector< std::filesystem::path>& filesList, const FileLoadOptions & options );
132 MRVIEWER_API bool loadFiles( const std::vector< std::filesystem::path>& filesList );
133
135 MRVIEWER_API bool saveToFile( const std::filesystem::path & mesh_file_name );
136
138 MRVIEWER_API bool keyPressed( unsigned int unicode_key, int modifier );
139 MRVIEWER_API bool keyDown( int key, int modifier );
140 MRVIEWER_API bool keyUp( int key, int modifier );
141 MRVIEWER_API bool keyRepeat( int key, int modifier );
142 MRVIEWER_API bool mouseDown( MouseButton button, int modifier );
143 MRVIEWER_API bool mouseUp( MouseButton button, int modifier );
144 MRVIEWER_API bool mouseMove( int mouse_x, int mouse_y );
145 MRVIEWER_API bool mouseScroll( float delta_y );
146 MRVIEWER_API bool mouseClick( MouseButton button, int modifier );
147 MRVIEWER_API bool dragStart( MouseButton button, int modifier );
148 MRVIEWER_API bool dragEnd( MouseButton button, int modifier );
149 MRVIEWER_API bool drag( int mouse_x, int mouse_y );
150 MRVIEWER_API bool spaceMouseMove( const Vector3f& translate, const Vector3f& rotate );
151 MRVIEWER_API bool spaceMouseDown( int key );
152 MRVIEWER_API bool spaceMouseUp( int key );
153 MRVIEWER_API bool spaceMouseRepeat( int key );
154 MRVIEWER_API bool dragDrop( const std::vector<std::filesystem::path>& paths );
156 MRVIEWER_API bool touchStart( int id, int x, int y );
157 MRVIEWER_API bool touchMove( int id, int x, int y );
158 MRVIEWER_API bool touchEnd( int id, int x, int y );
160 MRVIEWER_API bool touchpadRotateGestureBegin();
161 MRVIEWER_API bool touchpadRotateGestureUpdate( float angle );
162 MRVIEWER_API bool touchpadRotateGestureEnd();
163 MRVIEWER_API bool touchpadSwipeGestureBegin();
164 MRVIEWER_API bool touchpadSwipeGestureUpdate( float dx, float dy, bool kinetic );
165 MRVIEWER_API bool touchpadSwipeGestureEnd();
166 MRVIEWER_API bool touchpadZoomGestureBegin();
167 MRVIEWER_API bool touchpadZoomGestureUpdate( float scale, bool kinetic );
168 MRVIEWER_API bool touchpadZoomGestureEnd();
170 MRVIEWER_API bool interruptWindowClose();
171
173 MRVIEWER_API void draw( bool force = false );
175 MRVIEWER_API void drawFull( bool dirtyScene );
178 MRVIEWER_API void drawScene( FramebufferData* framebuffer );
180 void setSceneDirty() { dirtyScene_ = true; }
182 MRVIEWER_API void setupScene();
184 MRVIEWER_API void clearFramebuffers();
186 MRVIEWER_API void resize( int w, int h );
187 MRVIEWER_API void postResize( int w, int h );
188 MRVIEWER_API void postSetPosition( int xPos, int yPos );
189 MRVIEWER_API void postSetMaximized( bool maximized );
190 MRVIEWER_API void postSetIconified( bool iconified );
191 MRVIEWER_API void postFocus( bool focused );
192 MRVIEWER_API void postRescale( float x, float y );
193 MRVIEWER_API void postClose();
194
198
200 MRVIEWER_API void set_root( SceneRootObject& newRoot );
201
203 MRVIEWER_API void clearScene();
204
208
213 MRVIEWER_API Viewport& viewport( ViewportId viewportId = {} );
214 MRVIEWER_API const Viewport& viewport( ViewportId viewportId = {} ) const;
215
226 MRVIEWER_API ViewportId append_viewport( const ViewportRectangle & viewportRect, bool append_empty = false );
227
230 MRVIEWER_API Box2f getViewportsBounds() const;
231
236 MRVIEWER_API bool erase_viewport( const size_t index );
237 MRVIEWER_API bool erase_viewport( ViewportId viewport_id );
238
241 MRVIEWER_API int viewport_index( ViewportId viewport_id ) const;
242
245 MRVIEWER_API ViewportId getHoveredViewportId() const;
246
249
251 MRVIEWER_API void select_hovered_viewport();
252
256 MRVIEWER_API void fitDataViewport( MR::ViewportMask vpList = MR::ViewportMask::all(), float fill = 0.6f, bool snapView = true );
257
261 MRVIEWER_API void fitBoxViewport( const Box3f& box, MR::ViewportMask vpList = MR::ViewportMask::all(), float fill = 0.6f, bool snapView = true );
262
266 MRVIEWER_API void preciseFitDataViewport( MR::ViewportMask vpList, const FitDataParams& param );
267
268 MRVIEWER_API size_t getTotalFrames() const;
269 MRVIEWER_API size_t getSwappedFrames() const;
270 MRVIEWER_API size_t getFPS() const;
271 MRVIEWER_API double getPrevFrameDrawTimeMillisec() const;
272
274 MRVIEWER_API size_t getStaticGLBufferSize() const;
275
280
283 MRVIEWER_API void incrementForceRedrawFrames( int i = 1, bool swapOnLastOnly = false );
284
286 MRVIEWER_API void forceSwapOnFrame( int i = 0 );
287
289 MRVIEWER_API bool isCurrentFrameSwapping() const;
290
304
305 MRVIEWER_API size_t getEventsCount( EventType type )const;
306
319
320 MRVIEWER_API size_t getLastFrameGLPrimitivesCount( GLPrimitivesType type ) const;
322 MRVIEWER_API void incrementThisFrameGLPrimitivesCount( GLPrimitivesType type, size_t num );
323
324
326 ViewportMask getPresentViewports() const { return presentViewportsMask_; }
327
329 MRVIEWER_API void resetAllCounters();
330
336 MRVIEWER_API Image captureSceneScreenShot( const Vector2i& resolution = Vector2i(), bool transparentBg = false );
337
344 MRVIEWER_API void captureUIScreenShot( std::function<void( const Image& )> callback,
345 const Vector2i& pos = Vector2i(), const Vector2i& size = Vector2i() );
346
348 MRVIEWER_API bool isAlphaSortAvailable() const;
351 MRVIEWER_API bool enableAlphaSort( bool on );
353 bool isAlphaSortEnabled() const { return alphaSortEnabled_; }
354
356 MRVIEWER_API int getDepthPeelNumPasses() const;
358 MRVIEWER_API void setDepthPeelNumPasses( int numPasses );
360 MRVIEWER_API bool isDepthPeelingEnabled() const;
361
363 MRVIEWER_API bool isSceneTextureBound() const;
366 MRVIEWER_API void bindSceneTexture( bool bind );
368 MRVIEWER_API bool isSceneTextureEnabled() const;
369
372 MRVIEWER_API int getMSAA() const;
376 MRVIEWER_API void requestChangeMSAA( int newMSAA );
378 MRVIEWER_API int getRequestedMSAA() const;
379
382 MRVIEWER_API void setViewportSettingsManager( std::unique_ptr<IViewerSettingsManager> mng );
383 MRVIEWER_API const std::unique_ptr<IViewerSettingsManager>& getViewerSettingsManager() const { return settingsMng_; }
384
387 MRVIEWER_API PointInAllSpaces getPixelPointInfo( const Vector3f& screenPoint ) const;
390
396 MRVIEWER_API Vector3f screenToViewport( const Vector3f& screenPoint, ViewportId id ) const;
402 MRVIEWER_API Vector3f viewportToScreen( const Vector3f& viewportPoint, ViewportId id ) const;
403
405 MRVIEWER_API std::vector<std::reference_wrapper<Viewport>> getViewports( ViewportMask mask = ViewportMask::any() );
406
408 MRVIEWER_API void enableGlobalHistory( bool on );
410 bool isGlobalHistoryEnabled() const { return bool( globalHistoryStore_ ); };
413 MRVIEWER_API void appendHistoryAction( const std::shared_ptr<HistoryAction>& action );
416 MRVIEWER_API bool globalHistoryUndo();
419 MRVIEWER_API bool globalHistoryRedo();
420
423 MRVIEWER_API HistoryStore* getGlobalHistoryStore() const { return globalHistoryStore_.get(); }
424
426 const std::shared_ptr<SpaceMouse::Handler>& getSpaceMouseHandler() const { return spaceMouseHandler_; }
427
429 MRVIEWER_API void onSceneSaved( const std::filesystem::path& savePath, bool storeInRecent = true );
430
432 MRVIEWER_API const std::shared_ptr<ImGuiMenu>& getMenuPlugin() const;
433 MRVIEWER_API void setMenuPlugin( std::shared_ptr<ImGuiMenu> menu );
434
436 MRVIEWER_API std::shared_ptr<RibbonMenu> getRibbonMenu() const;
437
439 template <typename T>
440 std::shared_ptr<T> getMenuPluginAs() const { return std::dynamic_pointer_cast<T>( getMenuPlugin() ); }
441
445 MRVIEWER_API void stopEventLoop( int exitCode = 0, bool interruptible = true );
447 bool getStopEventLoopFlag() const { return stopEventLoopRequest_.has_value(); }
448
451 MRVIEWER_API bool windowShouldClose();
452
456 bool isGLInitialized() const { return glInitialized_; }
457
459 MRVIEWER_API void makeTitleFromSceneRootPath();
460
462 bool hasScaledFramebuffer() const { return hasScaledFramebuffer_; }
463
464public:
468 GLFWwindow* window;
469
472 std::function<void( Viewer* viewer )> resetSettingsFunction;
473
475 std::vector<Viewport> viewport_list;
477
479 std::vector<ViewerPlugin*> plugins;
480
481 float pixelRatio{ 1.0f };
483 Vector2i windowSavePos;
484 Vector2i windowSaveSize;
485 Vector2i windowOldPos;
486 bool windowMaximized{ false };
487
489 bool isAnimating{ false };
494 float scrollForce{ };
496 uint16_t glPickRadius{ };
500 std::vector<std::string> commandArgs;
501
502 std::shared_ptr<ObjectMesh> basisAxes;
503 std::unique_ptr<CornerControllerObject> basisViewController;
504 std::unique_ptr<ViewportGlobalBasis> globalBasis;
505 std::shared_ptr<ObjectMesh> rotationSphere;
507 std::shared_ptr<ObjectMesh> clippingPlaneObject;
508
510 std::shared_ptr<ViewerTitle> windowTitle;
511
513 ViewerSignals & signals() { return *signals_; }
514
517 MRVIEWER_API void emplaceEvent( std::string name, ViewerEventCallback cb, bool skipable = false );
519 MRVIEWER_API void popEventByName( const std::string& name );
520
521 MRVIEWER_API void postEmptyEvent();
522
523 [[nodiscard]] const TouchpadController &touchpadController() const { return *touchpadController_; }
524 [[nodiscard]] TouchpadController& touchpadController() { return *touchpadController_; }
525
526 [[nodiscard]] const SpaceMouse::Controller &spaceMouseController() const { return *spaceMouseController_; }
527 [[nodiscard]] SpaceMouse::Controller& spaceMouseController() { return *spaceMouseController_; }
528
529 [[nodiscard]] const MouseController &mouseController() const { return *mouseController_; }
530 [[nodiscard]] MouseController &mouseController() { return *mouseController_; }
531
533 [[nodiscard]] const RecentFilesStore &recentFilesStore() const { return *recentFilesStore_; }
534 [[nodiscard]] RecentFilesStore &recentFilesStore() { return *recentFilesStore_; }
535
537 [[nodiscard]] bool getSortDroppedFiles() const { return sortDroppedFiles_; }
538
540 void setSortDroppedFiles( bool value ) { sortDroppedFiles_ = value; }
541
543 MRVIEWER_API void drawUiRenderObjects();
544
547 MRVIEWER_API bool isMultiViewportAvailable();
548private:
549 Viewer();
550 ~Viewer();
551
553 int launchInit_( const LaunchParams& params );
554
556 bool setupWindow_( const LaunchParams& params );
557
559 bool checkOpenGL_(const LaunchParams& params );
560
562 void init_();
563
565 void initPlugins_();
566
568 void shutdownPlugins_();
569
570#ifdef __EMSCRIPTEN__
571 void mainLoopFunc_();
572 static void emsMainInfiniteLoop();
573#endif
575 bool draw_( bool force );
576
578 int forceRedrawFrames_{ 0 };
580 int forceRedrawFramesWithoutSwap_{ 0 };
581
582 std::unique_ptr<ViewerEventQueue> eventQueue_;
583
585 std::shared_ptr<ImGuiMenu> menuPlugin_;
586
587 std::unique_ptr<TouchpadController> touchpadController_;
588 std::unique_ptr<SpaceMouse::Controller> spaceMouseController_;
589 std::unique_ptr<TouchesController> touchesController_;
590 std::unique_ptr<MouseController> mouseController_;
591 std::unique_ptr<IDragDropHandler> dragDropAdvancedHandler_;
592
593 std::unique_ptr<RecentFilesStore> recentFilesStore_;
594 std::unique_ptr<FrameCounter> frameCounter_;
595
596 mutable struct EventsCounter
597 {
598 std::array<size_t, size_t( EventType::Count )> counter{};
599 void reset();
600 } eventsCounter_;
601
602 mutable struct GLPrimitivesCounter
603 {
604 std::array<size_t, size_t( GLPrimitivesType::Count )> counter{};
605 void reset();
606 } glPrimitivesCounter_;
607
608
610 bool tryCreateWindow_( bool fullscreen, int& width, int& height, const std::string& name, int major, int minor );
611
612 bool needRedraw_() const;
613 void resetRedraw_();
614
615 void initGlobalBasisAxesObject_();
616 void initBasisAxesObject_();
617 void initBasisViewControllerObject_();
618 void initClippingPlaneObject_();
619 void initRotationCenterObject_();
620
622 void initSpaceMouseHandler_();
623
625 void updatePixelRatio_();
626
630 int getRequiredMSAA_( bool sceneTextureOn, bool forSceneTexture ) const;
631
633 struct StopEventLoopRequest
634 {
635 int exitCode = 0;
636 bool interruptible = true;
637 };
638 std::optional<StopEventLoopRequest> stopEventLoopRequest_;
639
640 bool isPreLaunched_{ false };
641 bool isLaunched_{ false };
643 bool focusRedrawReady_{ false };
644
645 std::unique_ptr<SceneTextureGL> sceneTexture_;
646 std::unique_ptr<AlphaSortGL> alphaSorter_;
647 std::unique_ptr<DepthPeelingGL> depthPeeler_;
648
649 bool alphaSortEnabled_{ false };
650
651 bool glInitialized_{ false };
652
653 bool isInDraw_{ false };
654 bool dirtyScene_{ false };
655
656 bool hasScaledFramebuffer_{ false };
657
658 bool sortDroppedFiles_{ true };
659
660 LaunchParams launchParams_;
661
662 ViewportId getFirstAvailableViewportId_() const;
663 ViewportMask presentViewportsMask_;
664
665 std::unique_ptr<IViewerSettingsManager> settingsMng_;
666
667 std::unique_ptr<HistoryStore> globalHistoryStore_;
668
669 std::shared_ptr<SpaceMouse::Handler> spaceMouseHandler_;
670
671 struct Connections;
672 std::unique_ptr<Connections> connections_;
673 std::unique_ptr<ViewerSignals> signals_;
674
675 friend MRVIEWER_API Viewer& getViewerInstance();
676};
677
680MRVIEWER_API int protectedLaunchPhase( const std::function<int()>& phase );
683MRVIEWER_API int preLaunchDefaultViewer( const Viewer::LaunchParams& params, const ViewerSetup& setup );
686MRVIEWER_API void postLaunchDefaultViewer( const Viewer::LaunchParams& params, const ViewerSetup& setup );
688MRVIEWER_API int launchDefaultViewer( const Viewer::LaunchParams& params, const ViewerSetup& setup );
689
690}
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:12
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:76
auto width(const Box< V > &box)
returns size along x axis
Definition MRBox.h:386
auto height(const Box< V > &box)
returns size along y axis
Definition MRBox.h:393
bool hasScaledFramebuffer() const
returns true if the system framebuffer is scaled (valid for macOS and Wayland)
Definition MRViewer.h:462
WindowMode
Definition MRViewer.h:40
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:49
MouseMode
Standard mouse functions for camera control.
Definition MRMouse.h:23
bool console
If !startEventLoop close immediately after start, otherwise close on window close,...
Definition MRViewer.h:56
bool developerFeatures
If not set renders scene each frame.
Definition MRViewer.h:50
bool touchpadRotateGestureUpdate(float angle)
void drawFull(bool dirtyScene)
Draw 3d scene with UI.
bool windowShouldClose()
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:58
bool touchEnd(int id, int x, int y)
MouseButton
Definition MRMouse.h:13
bool startEventLoop
if true - resets config file on start of the application
Definition MRViewer.h:54
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:491
bool fullscreen
Definition MRViewer.h:36
bool keyRepeat(int key, int modifier)
MR::LaunchParams LaunchParams
Definition MRViewer.h:76
const MouseController & mouseController() const
Definition MRViewer.h:529
void emplaceEvent(std::string name, ViewerEventCallback cb, bool skipable=false)
std::shared_ptr< ViewerTitle > windowTitle
class that updates viewer title
Definition MRViewer.h:510
void draw(bool force=false)
Draw everything.
int exitCode
Definition MRViewer.h:635
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:62
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:496
bool isSupportedFormat(const std::filesystem::path &file_name)
void setupScene()
Setup viewports views.
int argc
If true - shows developers console.
Definition MRViewer.h:57
std::vector< ViewerPlugin * > plugins
List of registered plugins.
Definition MRViewer.h:479
bool swapOnLastPostEventsRedraw
if true only last frame of force redraw after events will be swapped, otherwise each will be swapped
Definition MRViewer.h:277
Vector3f viewportToScreen(const Vector3f &viewportPoint, ViewportId id) const
Vector2i windowSaveSize
pos to save
Definition MRViewer.h:484
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:293
const SpaceMouse::Controller & spaceMouseController() const
Definition MRViewer.h:526
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:59
ViewportMask getPresentViewports() const
Returns mask of present viewports.
Definition MRViewer.h:326
const TouchpadController & touchpadController() const
Definition MRViewer.h:523
PointInAllSpaces getMousePointInfo() const
Finds point under mouse in all spaces and under mouse viewport id.
ViewportId getHoveredViewportId() const
bool noMSAA
unload all extended libraries right before program exit
Definition MRViewer.h:64
const Viewport & viewport(ViewportId viewportId={}) const
std::shared_ptr< SplashWindow > splashWindow
render without multisample anti-aliasing regardless of the saved setting
Definition MRViewer.h:66
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:440
bool isGLInitialized() const
Definition MRViewer.h:456
bool touchStart(int id, int x, int y)
Touch callbacks (now used in EMSCRIPTEN build only)
std::shared_ptr< ObjectMesh > rotationSphere
Definition MRViewer.h:505
Vector2i windowOldPos
size to save
Definition MRViewer.h:485
static void parseLaunchParams(LaunchParams &params)
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:500
bool enableAlphaSort(bool on)
HistoryStore * getGlobalHistoryStore() const
Definition MRViewer.h:423
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:604
const LaunchParams & getLaunchParams() const
get full parameters with witch viewer was launched
Definition MRViewer.h:102
std::function< void(Viewer *viewer)> resetSettingsFunction
Definition MRViewer.h:472
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 &params)
Launch viewer with given params.
bool windowMaximized
Definition MRViewer.h:486
bool unloadPluginsAtEnd
max fps if animating
Definition MRViewer.h:63
PointInAllSpaces getPixelPointInfo(const Vector3f &screenPoint) const
Finds point in all spaces from screen space pixel point.
void preciseFitDataViewport(MR::ViewportMask vpList, const FitDataParams &param)
bool isAlphaSortEnabled() const
Returns true if alpha sort is enabled, false otherwise.
Definition MRViewer.h:353
bool touchpadSwipeGestureBegin()
bool touchpadZoomGestureBegin()
bool interruptible
Definition MRViewer.h:636
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:383
bool experimentalFeatures
Experimental/developer features enabled.
Definition MRViewer.h:498
bool close
If false - does not start event loop.
Definition MRViewer.h:55
size_t selected_viewport_index
Definition MRViewer.h:476
bool multiViewport
If set shows some developer features useful for debugging.
Definition MRViewer.h:51
float pixelRatio
Definition MRViewer.h:481
bool isAnimating
if true - calls render without system events
Definition MRViewer.h:489
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:105
void launchShut()
Terminate window.
PluginType * getPluginInstance()
Definition MRViewer.h:112
Image captureSceneScreenShot(const Vector2i &resolution=Vector2i(), bool transparentBg=false)
bool spaceMouseMove(const Vector3f &translate, const Vector3f &rotate)
bool isLaunched() const
Definition MRViewer.h:99
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:60
static const Viewer * constInstance()
provide const access to viewer
Definition MRViewer.h:108
std::unique_ptr< ViewportGlobalBasis > globalBasis
Definition MRViewer.h:504
MR::MouseMode MouseMode
Definition MRViewer.h:74
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:507
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:109
int launchShow(const LaunchParams &params)
void setSortDroppedFiles(bool value)
sets whether to sort the filenames received from Drag&Drop in lexicographical order before adding the...
Definition MRViewer.h:540
friend Viewer & getViewerInstance()
returns global instance of Viewer class
SpaceMouse::Controller & spaceMouseController()
Definition MRViewer.h:527
int preLaunch(const LaunchParams &params)
void requestChangeMSAA(int newMSAA)
void postLaunchDefaultViewer(const Viewer::LaunchParams &params, const ViewerSetup &setup)
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:534
bool enableTransparentBackground
Definition MRViewer.h:47
void resize(int w, int h)
OpenGL context resize.
int height
Definition MRViewer.h:38
bool isSceneTextureBound() const
Returns if scene texture is now bound.
static Viewer & instanceRef()
Definition MRViewer.h:106
void select_hovered_viewport()
Change selected_core_index to the viewport containing the mouse.
void runEventLoopIteration(double maxWaitSec=-1)
std::shared_ptr< ObjectMesh > basisAxes
Definition MRViewer.h:502
bool isSceneTextureEnabled() const
Returns true if 3d scene is rendering in scene texture instead of main framebuffer.
void postEmptyEvent()
bool resetConfig
Window name.
Definition MRViewer.h:53
std::array< size_t, size_t(EventType::Count)> counter
Definition MRViewer.h:598
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:482
ViewerSignals & signals()
return the structure with all viewer's signals
Definition MRViewer.h:513
bool getSortDroppedFiles() const
returns whether to sort the filenames received from Drag&Drop in lexicographical order before adding ...
Definition MRViewer.h:537
void preciseFitDataViewport(MR::ViewportMask vpList=MR::ViewportMask::all())
void stopEventLoop(int exitCode=0, bool interruptible=true)
void setMenuPlugin(std::shared_ptr< ImGuiMenu > menu)
void forceSwapOnFrame(int i=0)
Forces redraw no later than the specified number of frames.
size_t getFPS() const
MR::MouseButton MouseButton
Definition MRViewer.h:73
int viewport_index(ViewportId viewport_id) const
void resetAllCounters()
Restes frames counter and events counter.
GLPrimitivesType
types of gl primitives counters
Definition MRViewer.h:309
Vector2i windowSavePos
Definition MRViewer.h:483
bool preferOpenGL3
Definition MRViewer.h:48
int protectedLaunchPhase(const std::function< int()> &phase)
std::unique_ptr< CornerControllerObject > basisViewController
Definition MRViewer.h:503
int width
if true starts fullscreen
Definition MRViewer.h:37
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)
bool globalHistoryRedo()
void postSetIconified(bool iconified)
external set maximized due to user interaction
int launchDefaultViewer(const Viewer::LaunchParams &params, const ViewerSetup &setup)
starts default viewer with given params and setup
bool dragEnd(MouseButton button, int modifier)
GLFWwindow * window
Member variables ///.
Definition MRViewer.h:468
enum MR::LaunchParams::WindowMode HideInit
bool isPreLaunched() const
Definition MRViewer.h:98
MR::PointInAllSpaces PointInAllSpaces
Definition MRViewer.h:385
std::string name
If set allows to move the imgui (tool) windows outside the main () window. (unavailable for Apple,...
Definition MRViewer.h:52
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:180
void postResize(int w, int h)
explicitly set framebuffer size
Box2f ViewportRectangle
Viewport size.
Definition MRViewerFwd.h:17
bool isMultiViewportAvailable()
int preLaunchDefaultViewer(const Viewer::LaunchParams &params, const ViewerSetup &setup)
MouseController & mouseController()
Definition MRViewer.h:530
bool globalHistoryUndo()
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:533
int getMSAA() const
TouchpadController & touchpadController()
Definition MRViewer.h:524
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:80
int forceRedrawMinimumIncrementAfterEvents
minimum auto increment force redraw frames after events
Definition MRViewer.h:279
bool isGlobalHistoryEnabled() const
Return true if global history is enabled, false otherwise.
Definition MRViewer.h:410
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:475
bool isAnimating
if true - print version info in window title
Definition MRViewer.h:61
const std::shared_ptr< SpaceMouse::Handler > & getSpaceMouseHandler() const
Return spacemouse handler.
Definition MRViewer.h:426
float scrollForce
Definition MRViewer.h:494
bool getStopEventLoopFlag() const
get stop event loop flag (this flag is glfwShouldWindowClose equivalent)
Definition MRViewer.h:447
@ NoWindow
Launches in "Hide" mode if OpenGL is present and "NoWindow" if it is not.
Definition MRViewer.h:45
@ TryHidden
Don't show window.
Definition MRViewer.h:44
@ Hide
Show window after init.
Definition MRViewer.h:43
@ Show
Definition MRViewer.h:41
@ angle
Direction, normally Vector3f.
Definition MRFeatureObject.h:26
@ KeyUp
Definition MRViewer.h:299
@ KeyRepeat
Definition MRViewer.h:300
@ MouseUp
Definition MRViewer.h:295
@ MouseScroll
Definition MRViewer.h:297
@ MouseDown
Definition MRViewer.h:294
@ KeyDown
Definition MRViewer.h:298
@ Count
Definition MRViewer.h:302
@ CharPressed
Definition MRViewer.h:301
@ MouseMove
Definition MRViewer.h:296
@ LineElementsNum
Definition MRViewer.h:315
@ LineArraySize
Definition MRViewer.h:312
@ TriangleElementsNum
Definition MRViewer.h:316
@ TriangleArraySize
Definition MRViewer.h:313
@ PointElementsNum
Definition MRViewer.h:314
@ PointArraySize
arrays and elements are different gl calls
Definition MRViewer.h:311
@ Count
Definition MRViewer.h:317
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
Definition MRFileLoadOptions.h:14
Definition MRFitData.h:32
Definition MRImage.h:19
This struct contains rules for viewer launch.
Definition MRViewer.h:35
Definition MRPointInAllSpaces.h:16
Definition MRViewerSignals.h:13