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
11struct GLFWwindow;
12
14#define ENQUEUE_VIEWER_METHOD( NAME, METHOD ) MR::getViewerInstance().emplaceEvent( NAME, [] { \
15 MR::getViewerInstance() . METHOD (); \
16} )
17#define ENQUEUE_VIEWER_METHOD_ARGS( NAME, METHOD, ... ) MR::getViewerInstance().emplaceEvent( NAME, [__VA_ARGS__] { \
18 MR::getViewerInstance() . METHOD ( __VA_ARGS__ ); \
19} )
20#define ENQUEUE_VIEWER_METHOD_ARGS_SKIPABLE( NAME, METHOD, ... ) MR::getViewerInstance().emplaceEvent( NAME, [__VA_ARGS__] { \
21 MR::getViewerInstance() . METHOD ( __VA_ARGS__ ); \
22}, true )
23
24namespace MR
25{
26
27// This struct contains rules for viewer launch
29{
30 bool fullscreen{ false }; // if true starts fullscreen
31 int width{ 0 };
32 int height{ 0 };
34 {
35 Show, // Show window immediately
36 HideInit, // Show window after init
37 Hide, // Don't show window
38 TryHidden, // Launches in "Hide" mode if OpenGL is present and "NoWindow" if it is not
39 NoWindow // Don't initialize GL window (don't call GL functions)(force `isAnimating`)
40 } windowMode{ HideInit };
42 bool preferOpenGL3{ false };
43 bool render3dSceneInTexture{ true }; // If not set renders scene each frame
44 bool developerFeatures{ false }; // If set shows some developer features useful for debugging
45 std::string name{ "MRViewer" }; // Window name
46 bool resetConfig{ false }; // if true - resets config file on start of the application
47 bool startEventLoop{ true }; // If false - does not start event loop
48 bool close{ true }; // If !startEventLoop close immediately after start, otherwise close on window close, make sure you call `launchShut` manually if this flag is false
49 bool console{ false }; // If true - shows developers console
50 int argc{ 0 }; // Pass argc
51 char** argv{ nullptr }; // Pass argv
52
53 bool showMRVersionInTitle{ false }; // if true - print version info in window title
54 bool isAnimating{ false }; // if true - calls render without system events
55 int animationMaxFps{ 30 }; // max fps if animating
56 bool unloadPluginsAtEnd{ false }; // unload all extended libraries right before program exit
57
58 std::shared_ptr<SplashWindow> splashWindow; // if present will show this window while initializing plugins (after menu initialization)
59};
60
61// GLFW-based mesh viewer
62class MRVIEWER_CLASS Viewer
63{
64public:
67
69
70 // Accumulate launch params from cmd args
71 MRVIEWER_API static void parseLaunchParams( LaunchParams& params );
72
73 // Launch viewer with given params
74 MRVIEWER_API int launch( const LaunchParams& params );
75 // Starts event loop
76 MRVIEWER_API void launchEventLoop();
77 // Terminate window
78 MRVIEWER_API void launchShut();
79
80 bool isLaunched() const { return isLaunched_; }
81
82 // get full parameters with witch viewer was launched
83 const LaunchParams& getLaunchParams() const { return launchParams_; }
84
85 // provides non const access to viewer
86 static Viewer* instance() { return &getViewerInstance(); }
87 static Viewer& instanceRef() { return getViewerInstance(); }
88 // provide const access to viewer
89 static const Viewer* constInstance() { return &getViewerInstance(); }
90 static const Viewer& constInstanceRef() { return getViewerInstance(); }
91
92 template<typename PluginType>
93 PluginType* getPluginInstance()
94 {
95 for ( auto& plugin : plugins )
96 {
97 auto p = dynamic_cast< PluginType* >( plugin );
98 if ( p )
99 {
100 return p;
101 }
102 }
103 return nullptr;
104 }
105
106 // Mesh IO
107 // Check the supported file format
108 MRVIEWER_API bool isSupportedFormat( const std::filesystem::path& file_name );
109
110 // Load objects / scenes from files
111 // Note! load files with progress bar in next frame if it possible, otherwise load directly inside this function
112 MRVIEWER_API bool loadFiles( const std::vector< std::filesystem::path>& filesList, const FileLoadOptions & options );
113 MRVIEWER_API bool loadFiles( const std::vector< std::filesystem::path>& filesList );
114
115 // Save first selected objects to file
116 MRVIEWER_API bool saveToFile( const std::filesystem::path & mesh_file_name );
117
118 // Callbacks
119 MRVIEWER_API bool keyPressed( unsigned int unicode_key, int modifier );
120 MRVIEWER_API bool keyDown( int key, int modifier );
121 MRVIEWER_API bool keyUp( int key, int modifier );
122 MRVIEWER_API bool keyRepeat( int key, int modifier );
123 MRVIEWER_API bool mouseDown( MouseButton button, int modifier );
124 MRVIEWER_API bool mouseUp( MouseButton button, int modifier );
125 MRVIEWER_API bool mouseMove( int mouse_x, int mouse_y );
126 MRVIEWER_API bool mouseScroll( float delta_y );
127 MRVIEWER_API bool mouseClick( MouseButton button, int modifier );
128 MRVIEWER_API bool dragStart( MouseButton button, int modifier );
129 MRVIEWER_API bool dragEnd( MouseButton button, int modifier );
130 MRVIEWER_API bool drag( int mouse_x, int mouse_y );
131 MRVIEWER_API bool spaceMouseMove( const Vector3f& translate, const Vector3f& rotate );
132 MRVIEWER_API bool spaceMouseDown( int key );
133 MRVIEWER_API bool spaceMouseUp( int key );
134 MRVIEWER_API bool spaceMouseRepeat( int key );
135 MRVIEWER_API bool dragDrop( const std::vector<std::filesystem::path>& paths );
136 // Touch callbacks (now used in EMSCRIPTEN build only)
137 MRVIEWER_API bool touchStart( int id, int x, int y );
138 MRVIEWER_API bool touchMove( int id, int x, int y );
139 MRVIEWER_API bool touchEnd( int id, int x, int y );
140 // Touchpad gesture callbacks
141 MRVIEWER_API bool touchpadRotateGestureBegin();
142 MRVIEWER_API bool touchpadRotateGestureUpdate( float angle );
143 MRVIEWER_API bool touchpadRotateGestureEnd();
144 MRVIEWER_API bool touchpadSwipeGestureBegin();
145 MRVIEWER_API bool touchpadSwipeGestureUpdate( float dx, float dy, bool kinetic );
146 MRVIEWER_API bool touchpadSwipeGestureEnd();
147 MRVIEWER_API bool touchpadZoomGestureBegin();
148 MRVIEWER_API bool touchpadZoomGestureUpdate( float scale, bool kinetic );
149 MRVIEWER_API bool touchpadZoomGestureEnd();
150 // This function is called when window should close, if return value is true, window will stay open
151 MRVIEWER_API bool interruptWindowClose();
152
153 // Draw everything
154 MRVIEWER_API void draw( bool force = false );
155 // Draw 3d scene with UI
156 MRVIEWER_API void drawFull( bool dirtyScene );
157 // Draw 3d scene without UI
158 MRVIEWER_API void drawScene();
159 // Call this function to force redraw scene into scene texture
160 void setSceneDirty() { dirtyScene_ = true; }
161 // Setup viewports views
162 MRVIEWER_API void setupScene();
163 // Cleans framebuffers for all viewports (sets its background)
164 MRVIEWER_API void clearFramebuffers();
165 // OpenGL context resize
166 MRVIEWER_API void resize( int w, int h ); // explicitly set framebuffer size
167 MRVIEWER_API void postResize( int w, int h ); // external resize due to user interaction
168 MRVIEWER_API void postSetPosition( int xPos, int yPos ); // external set position due to user interaction
169 MRVIEWER_API void postSetMaximized( bool maximized ); // external set maximized due to user interaction
170 MRVIEWER_API void postSetIconified( bool iconified ); // external set iconified due to user interaction
171 MRVIEWER_API void postFocus( bool focused ); // external focus handler due to user interaction
172 MRVIEWER_API void postRescale( float x, float y ); // external rescale due to user interaction
173 MRVIEWER_API void postClose(); // called when close signal received
174
176 // Multi-mesh methods //
178
179 // reset objectRoot with newRoot, append all RenderObjects and basis objects
180 MRVIEWER_API void set_root( SceneRootObject& newRoot );
181
182 // removes all objects from scene
183 MRVIEWER_API void clearScene();
184
186 // Multi-viewport methods //
188
189 // Return the current viewport, or the viewport corresponding to a given unique identifier
190 //
191 // Inputs:
192 // viewportId unique identifier corresponding to the desired viewport (current viewport if 0)
193 MRVIEWER_API Viewport& viewport( ViewportId viewportId = {} );
194 MRVIEWER_API const Viewport& viewport( ViewportId viewportId = {} ) const;
195
196 // Append a new "slot" for a viewport (i.e., copy properties of the current viewport, only
197 // changing the viewport size/position)
198 //
199 // Inputs:
200 // viewport Vector specifying the viewport origin and size in screen coordinates.
201 // append_empty If true, existing meshes are hidden on the new viewport.
202 //
203 // Returns the unique id of the newly inserted viewport. There can be a maximum of 31
204 // viewports created in the same viewport. Erasing a viewport does not change the id of
205 // other existing viewports
206 MRVIEWER_API ViewportId append_viewport( const ViewportRectangle & viewportRect, bool append_empty = false );
207
208 // Calculates and returns viewports bounds in gl space:
209 // (0,0) - lower left angle
210 MRVIEWER_API Box2f getViewportsBounds() const;
211
212 // Erase a viewport
213 //
214 // Inputs:
215 // index index of the viewport to erase
216 MRVIEWER_API bool erase_viewport( const size_t index );
217 MRVIEWER_API bool erase_viewport( ViewportId viewport_id );
218
219 // Retrieve viewport index from its unique identifier
220 // Returns -1 if not found
221 MRVIEWER_API int viewport_index( ViewportId viewport_id ) const;
222
223 // Get unique id of the vieport containing the mouse
224 // if mouse is out of any viewport returns index of last selected viewport
225 MRVIEWER_API ViewportId getHoveredViewportId() const;
226
227 // Same, but returns an invalid ID if no viewport is hovered, instead of returning the last selected viewport.
229
230 // Change selected_core_index to the viewport containing the mouse
231 MRVIEWER_API void select_hovered_viewport();
232
233 // Calls fitData for single/each viewport in viewer
234 // fill = 0.6 parameter means that scene will 0.6 of screen,
235 // snapView - to snap camera angle to closest canonical quaternion
236 MRVIEWER_API void fitDataViewport( MR::ViewportMask vpList = MR::ViewportMask::all(), float fill = 0.6f, bool snapView = true );
237
238 // Calls fitBox for single/each viewport in viewer
239 // fill = 0.6 parameter means that scene will 0.6 of screen,
240 // snapView - to snap camera angle to closest canonical quaternion
241 MRVIEWER_API void fitBoxViewport( const Box3f& box, MR::ViewportMask vpList = MR::ViewportMask::all(), float fill = 0.6f, bool snapView = true );
242
243 // Calls fitData and change FOV to match the screen size then
244 // params - params fit data
246 MRVIEWER_API void preciseFitDataViewport( MR::ViewportMask vpList, const FitDataParams& param );
247
248 MRVIEWER_API size_t getTotalFrames() const;
249 MRVIEWER_API size_t getSwappedFrames() const;
250 MRVIEWER_API size_t getFPS() const;
251 MRVIEWER_API double getPrevFrameDrawTimeMillisec() const;
252
253 // Returns memory amount used by shared GL memory buffer
254 MRVIEWER_API size_t getStaticGLBufferSize() const;
255
256 // if true only last frame of force redraw after events will be swapped, otherwise each will be swapped
257 bool swapOnLastPostEventsRedraw{ true };
258 // minimum auto increment force redraw frames after events
259 int forceRedrawMinimumIncrementAfterEvents{ 4 };
260
261 // Increment number of forced frames to redraw in event loop
262 // if `swapOnLastOnly` only last forced frame will be present on screen and all previous will not
263 MRVIEWER_API void incrementForceRedrawFrames( int i = 1, bool swapOnLastOnly = false );
264
265 // Returns true if current frame will be shown on display
266 MRVIEWER_API bool isCurrentFrameSwapping() const;
267
268 // types of counted events
269 enum class EventType
270 {
271 MouseDown,
272 MouseUp,
273 MouseMove,
274 MouseScroll,
275 KeyDown,
276 KeyUp,
277 KeyRepeat,
278 CharPressed,
279 Count
280 };
281 // Returns number of events of given type
282 MRVIEWER_API size_t getEventsCount( EventType type )const;
283
284 // types of gl primitives counters
286 {
287 // arrays and elements are different gl calls
288 PointArraySize,
289 LineArraySize,
290 TriangleArraySize,
291 PointElementsNum,
292 LineElementsNum,
293 TriangleElementsNum,
294 Count
295 };
296 // Returns number of events of given type
297 MRVIEWER_API size_t getLastFrameGLPrimitivesCount( GLPrimitivesType type ) const;
298 // Increment number of gl primitives drawed in this frame
299 MRVIEWER_API void incrementThisFrameGLPrimitivesCount( GLPrimitivesType type, size_t num );
300
301
302 // Returns mask of present viewports
303 ViewportMask getPresentViewports() const { return presentViewportsMask_; }
304
305 // Restes frames counter and events counter
306 MRVIEWER_API void resetAllCounters();
307
313 MRVIEWER_API Image captureSceneScreenShot( const Vector2i& resolution = Vector2i(), bool transparentBg = false );
314
321 MRVIEWER_API void captureUIScreenShot( std::function<void( const Image& )> callback,
322 const Vector2i& pos = Vector2i(), const Vector2i& size = Vector2i() );
323
324 // Returns true if can enable alpha sort
325 MRVIEWER_API bool isAlphaSortAvailable() const;
326 // Tries to enable alpha sort,
327 // returns true if value was changed, return false otherwise
328 MRVIEWER_API bool enableAlphaSort( bool on );
329 // Returns true if alpha sort is enabled, false otherwise
330 bool isAlphaSortEnabled() const { return alphaSortEnabled_; }
331
332 // Returns if scene texture is now bound
333 MRVIEWER_API bool isSceneTextureBound() const;
334 // Binds or unbinds scene texture (should be called only with valid window)
335 // note that it does not clear framebuffer
336 MRVIEWER_API void bindSceneTexture( bool bind );
337 // Returns true if 3d scene is rendering in scene texture instead of main framebuffer
338 MRVIEWER_API bool isSceneTextureEnabled() const;
339
340 // Returns actual msaa level of:
341 // scene texture if it is present, or main framebuffer
342 MRVIEWER_API int getMSAA() const;
343 // Requests changing MSAA level
344 // if scene texture is using, request should be executed in the beginig of next frame
345 // otherwise restart of the app is required to apply change to main framebuffer
346 MRVIEWER_API void requestChangeMSAA( int newMSAA );
347 // Returns MSAA level that have been requested (might be different from actual MSAA using, because of GPU limitations or need to restart app)
348 MRVIEWER_API int getRequestedMSAA() const;
349
350 // Sets manager of viewer settings which loads user personal settings on beginning of app
351 // and saves it in app's ending
352 MRVIEWER_API void setViewportSettingsManager( std::unique_ptr<IViewerSettingsManager> mng );
353 MRVIEWER_API const std::unique_ptr<IViewerSettingsManager>& getViewerSettingsManager() const { return settingsMng_; }
354
356 // Finds point in all spaces from screen space pixel point
357 MRVIEWER_API PointInAllSpaces getPixelPointInfo( const Vector3f& screenPoint ) const;
358 // Finds point under mouse in all spaces and under mouse viewport id
360
361 // Converts screen space coordinate to viewport space coordinate
362 // (0,0) if viewport does not exist
363 // screen space: X [0,framebufferSize.x], Y [0,framebufferSize.y] - (0,0) is upper left of window
364 // viewport space: X [0,viewport_width], Y [0,viewport_height] - (0,0) is upper left of viewport
365 // Z [0,1] - 0 is Dnear, 1 is Dfar
366 MRVIEWER_API Vector3f screenToViewport( const Vector3f& screenPoint, ViewportId id ) const;
367 // Converts viewport space coordinate to screen space coordinate
368 // (0,0) if viewport does not exist
369 // screen space: X [0,framebufferSize.x], Y [0,framebufferSize.y] - (0,0) is upper left of window
370 // viewport space: X [0,viewport_width], Y [0,viewport_height] - (0,0) is upper left of viewport
371 // Z [0,1] - 0 is Dnear, 1 is Dfar
372 MRVIEWER_API Vector3f viewportToScreen( const Vector3f& viewportPoint, ViewportId id ) const;
373
374 // Returns viewports satisfying given mask
375 MRVIEWER_API std::vector<std::reference_wrapper<Viewport>> getViewports( ViewportMask mask = ViewportMask::any() );
376
377 // Enables or disables global history (clears it on disable)
378 MRVIEWER_API void enableGlobalHistory( bool on );
379 // Return true if global history is enabled, false otherwise
380 bool isGlobalHistoryEnabled() const { return bool( globalHistoryStore_ ); };
381 // Appends history action to current stack position (clearing redo)
382 // if global history is disabled do nothing
383 MRVIEWER_API void appendHistoryAction( const std::shared_ptr<HistoryAction>& action );
384 // Applies undo if global history is enabled
385 // return true if undo was applied
386 MRVIEWER_API bool globalHistoryUndo();
387 // Applies redo if global history is enabled
388 // return true if redo was applied
389 MRVIEWER_API bool globalHistoryRedo();
390 // Returns global history store
391 const std::shared_ptr<HistoryStore>& getGlobalHistoryStore() const { return globalHistoryStore_; }
392 // Return spacemouse handler
393 const std::shared_ptr<SpaceMouseHandler>& getSpaceMouseHandler() const { return spaceMouseHandler_; }
394
395 // This method is called after successful scene saving to update scene root, window title and undo
396 MRVIEWER_API void onSceneSaved( const std::filesystem::path& savePath, bool storeInRecent = true );
397
398 // Get/Set menu plugin (which is separated from other plugins to be inited first before splash window starts)
399 MRVIEWER_API const std::shared_ptr<ImGuiMenu>& getMenuPlugin() const;
400 MRVIEWER_API void setMenuPlugin( std::shared_ptr<ImGuiMenu> menu );
401
402 // get menu plugin casted in RibbonMenu
403 MRVIEWER_API std::shared_ptr<RibbonMenu> getRibbonMenu() const;
404
405 // Get the menu plugin casted in given type
406 template <typename T>
407 std::shared_ptr<T> getMenuPluginAs() const { return std::dynamic_pointer_cast<T>( getMenuPlugin() ); }
408
409 // sets stop event loop flag (this flag is glfwShouldWindowClose equivalent)
410 MRVIEWER_API void stopEventLoop();
411 // get stop event loop flag (this flag is glfwShouldWindowClose equivalent)
412 bool getStopEventLoopFlag() const { return stopEventLoop_; }
413
414 // return true if window should close
415 // calls interrupt signal and if no slot interrupts return true, otherwise return false
417
418 // returns true if viewer has valid GL context
419 // note that sometimes it is not enough, for example to free GL memory in destructor,
420 // glInitialized_ can be already reset and it requires `loadGL()` check too
421 bool isGLInitialized() const { return glInitialized_; }
422
423 // update the title of the main window and, if any scene was opened, show its filename
424 MRVIEWER_API void makeTitleFromSceneRootPath();
425
426 // returns true if the system framebuffer is scaled (valid for macOS and Wayland)
427 bool hasScaledFramebuffer() const { return hasScaledFramebuffer_; }
428
429public:
431 // Member variables //
433 GLFWwindow* window;
434
435 // A function to reset setting to initial state
436 // Overrides should call previous function
437 std::function<void( Viewer* viewer )> resetSettingsFunction;
438
439 // Stores all the viewing options
440 std::vector<Viewport> viewport_list;
442
443 // List of registered plugins
444 std::vector<ViewerPlugin*> plugins;
445
446 float pixelRatio{ 1.0f };
448 Vector2i windowSavePos; // pos to save
449 Vector2i windowSaveSize; // size to save
450 Vector2i windowOldPos;
451 bool windowMaximized{ false };
452
453 // if true - calls render without system events
454 bool isAnimating{ false };
455 // max fps if animating
456 int animationMaxFps{ 30 };
457 // this parameter can force up/down mouse scroll
458 // useful for WebAssembler version because it has too powerful scroll
459 float scrollForce{ }; // init in resetSettingsFunction()
460 // opengl-based pick window radius in pixels
461 uint16_t glPickRadius{ }; // init in resetSettingsFunction()
462 // Experimental/developer features enabled
463 bool experimentalFeatures{ };
464 // command arguments, each parsed arg should be erased from here not to affect other parsers
465 std::vector<std::string> commandArgs;
466
467 std::shared_ptr<ObjectMesh> basisAxes;
468 std::unique_ptr<CornerControllerObject> basisViewController;
469 std::unique_ptr<ViewportGlobalBasis> globalBasis;
470 std::shared_ptr<ObjectMesh> rotationSphere;
471 // Stores clipping plane mesh
472 std::shared_ptr<ObjectMesh> clippingPlaneObject;
473
474 // class that updates viewer title
475 std::shared_ptr<ViewerTitle> windowTitle;
476
478 ViewerSignals & signals() { return *signals_; }
479
482 MRVIEWER_API void emplaceEvent( std::string name, ViewerEventCallback cb, bool skipable = false );
483 // pop all events from the queue while they have this name
484 MRVIEWER_API void popEventByName( const std::string& name );
485
486 MRVIEWER_API void postEmptyEvent();
487
488 [[nodiscard]] MRVIEWER_API const TouchpadParameters & getTouchpadParameters() const;
489 MRVIEWER_API void setTouchpadParameters( const TouchpadParameters & );
490
491 [[nodiscard]] MRVIEWER_API SpaceMouseParameters getSpaceMouseParameters() const;
492 MRVIEWER_API void setSpaceMouseParameters( const SpaceMouseParameters & );
493
494 [[nodiscard]] const MouseController &mouseController() const { return *mouseController_; }
495 [[nodiscard]] MouseController &mouseController() { return *mouseController_; }
496
497 // Store of recently opened files
498 [[nodiscard]] const RecentFilesStore &recentFilesStore() const { return *recentFilesStore_; }
499 [[nodiscard]] RecentFilesStore &recentFilesStore() { return *recentFilesStore_; }
500
502 [[nodiscard]] bool getSortDroppedFiles() const { return sortDroppedFiles_; }
503
505 void setSortDroppedFiles( bool value ) { sortDroppedFiles_ = value; }
506
509 MRVIEWER_API void initSpaceMouseHandler( std::function<void(const std::string&)> deviceSignal = {} );
510
512 MRVIEWER_API void drawUiRenderObjects();
513private:
514 Viewer();
515 ~Viewer();
516
517 // Init window
518 int launchInit_( const LaunchParams& params );
519
520 // Called from launchInit_ after window creating to configure it properly
521 bool setupWindow_( const LaunchParams& params );
522
523 // Return true if OpenGL loaded successfully
524 bool checkOpenGL_(const LaunchParams& params );
525
526 // Init base objects
527 void init_();
528
529 // Init all plugins on start
530 void initPlugins_();
531
532 // Shut all plugins at the end
533 void shutdownPlugins_();
534
535#ifdef __EMSCRIPTEN__
536 void mainLoopFunc_();
537 static void emsMainInfiniteLoop();
538#endif
539 // returns true if was swapped
540 bool draw_( bool force );
541
542 // the minimum number of frames to be rendered even if the scene is unchanged
543 int forceRedrawFrames_{ 0 };
544 // Should be `<= forceRedrawFrames_`. The next N frames will not be shown on screen.
545 int forceRedrawFramesWithoutSwap_{ 0 };
546
547 // if this flag is set shows some developer features useful for debugging
548 bool enableDeveloperFeatures_{ false };
549
550 std::unique_ptr<ViewerEventQueue> eventQueue_;
551
552 // special plugin for menu (initialized before splash window starts)
553 std::shared_ptr<ImGuiMenu> menuPlugin_;
554
555 std::unique_ptr<TouchpadController> touchpadController_;
556 std::unique_ptr<SpaceMouseController> spaceMouseController_;
557 std::unique_ptr<TouchesController> touchesController_;
558 std::unique_ptr<MouseController> mouseController_;
559 std::unique_ptr<IDragDropHandler> dragDropAdvancedHandler_;
560
561 std::unique_ptr<RecentFilesStore> recentFilesStore_;
562 std::unique_ptr<FrameCounter> frameCounter_;
563
564 mutable struct EventsCounter
565 {
566 std::array<size_t, size_t( EventType::Count )> counter{};
567 void reset();
568 } eventsCounter_;
569
570 mutable struct GLPrimitivesCounter
571 {
572 std::array<size_t, size_t( GLPrimitivesType::Count )> counter{};
573 void reset();
574 } glPrimitivesCounter_;
575
576
577 // creates glfw window with gl version major.minor, false if failed;
578 bool tryCreateWindow_( bool fullscreen, int& width, int& height, const std::string& name, int major, int minor );
579
580 bool needRedraw_() const;
581 void resetRedraw_();
582
583 void recursiveDraw_( const Viewport& vp, const Object& obj, const AffineXf3f& parentXf, RenderModelPassMask renderType, int* numDraws = nullptr ) const;
584
585 void initGlobalBasisAxesObject_();
586 void initBasisAxesObject_();
587 void initBasisViewControllerObject_();
588 void initClippingPlaneObject_();
589 void initRotationCenterObject_();
590
591 // recalculate pixel ratio
592 void updatePixelRatio_();
593
594 // return MSAA that is required for framebuffer
595 // sceneTextureOn - true means that app is using scene texture for rendering (false means that scene is rendered directly in main framebuffer)
596 // forSceneTexture - true request MSAA required for scene texture (calling with !sceneTextureOn is invalid), false - request MSAA for main framebuffer
597 int getRequiredMSAA_( bool sceneTextureOn, bool forSceneTexture ) const;
598
599 bool stopEventLoop_{ false };
600
601 bool isLaunched_{ false };
602 // this flag is needed to know if all viewer setup was already done, and we can call draw
603 bool focusRedrawReady_{ false };
604
605 std::unique_ptr<SceneTextureGL> sceneTexture_;
606 std::unique_ptr<AlphaSortGL> alphaSorter_;
607
608 bool alphaSortEnabled_{false};
609
610 bool glInitialized_{ false };
611
612 bool isInDraw_{ false };
613 bool dirtyScene_{ false };
614
615 bool hasScaledFramebuffer_{ false };
616
617 bool sortDroppedFiles_{ true };
618
619 LaunchParams launchParams_;
620
621 ViewportId getFirstAvailableViewportId_() const;
622 ViewportMask presentViewportsMask_;
623
624 std::unique_ptr<IViewerSettingsManager> settingsMng_;
625
626 std::shared_ptr<HistoryStore> globalHistoryStore_;
627
628 std::shared_ptr<SpaceMouseHandler> spaceMouseHandler_;
629
630 struct Connections;
631 std::unique_ptr<Connections> connections_;
632 std::unique_ptr<ViewerSignals> signals_;
633
634 friend MRVIEWER_API Viewer& getViewerInstance();
635};
636
637// starts default viewer with given params and setup
638MRVIEWER_API int launchDefaultViewer( const Viewer::LaunchParams& params, const ViewerSetup& setup );
639
640} // end namespace
angle
Definition MRObjectDimensionsEnum.h:13
Definition MRMouseController.h:21
Definition MRRecentFilesStore.h:17
Object that is parent of all scene.
Definition MRSceneRoot.h:11
Definition MRSetupViewer.h:13
Definition MRViewer.h:63
bool hasScaledFramebuffer() const
Definition MRViewer.h:427
MRVIEWER_API bool saveToFile(const std::filesystem::path &mesh_file_name)
MRVIEWER_API bool keyUp(int key, int modifier)
bool windowShouldClose()
MRVIEWER_API void fitDataViewport(MR::ViewportMask vpList=MR::ViewportMask::all(), float fill=0.6f, bool snapView=true)
MRVIEWER_API bool isAlphaSortAvailable() const
MRVIEWER_API ViewportId getHoveredViewportId() const
MRVIEWER_API void setViewportSettingsManager(std::unique_ptr< IViewerSettingsManager > mng)
MRVIEWER_API bool keyRepeat(int key, int modifier)
MRVIEWER_API std::vector< std::reference_wrapper< Viewport > > getViewports(ViewportMask mask=ViewportMask::any())
const MouseController & mouseController() const
Definition MRViewer.h:494
MRVIEWER_API void appendHistoryAction(const std::shared_ptr< HistoryAction > &action)
std::shared_ptr< ViewerTitle > windowTitle
Definition MRViewer.h:475
MRVIEWER_API PointInAllSpaces getMousePointInfo() const
MRVIEWER_API const std::shared_ptr< ImGuiMenu > & getMenuPlugin() const
MRVIEWER_API void resize(int w, int h)
MRVIEWER_API bool mouseClick(MouseButton button, int modifier)
std::vector< ViewerPlugin * > plugins
Definition MRViewer.h:444
static MRVIEWER_API void parseLaunchParams(LaunchParams &params)
MRVIEWER_API Box2f getViewportsBounds() const
Vector2i windowSaveSize
Definition MRViewer.h:449
EventType
Definition MRViewer.h:270
ViewportMask getPresentViewports() const
Definition MRViewer.h:303
MRVIEWER_API bool touchpadSwipeGestureEnd()
MRVIEWER_API bool erase_viewport(ViewportId viewport_id)
MRVIEWER_API SpaceMouseParameters getSpaceMouseParameters() const
MRVIEWER_API void fitBoxViewport(const Box3f &box, MR::ViewportMask vpList=MR::ViewportMask::all(), float fill=0.6f, bool snapView=true)
MRVIEWER_API void setSpaceMouseParameters(const SpaceMouseParameters &)
MRVIEWER_API size_t getEventsCount(EventType type) const
std::shared_ptr< T > getMenuPluginAs() const
Definition MRViewer.h:407
const std::shared_ptr< HistoryStore > & getGlobalHistoryStore() const
Definition MRViewer.h:391
bool isGLInitialized() const
Definition MRViewer.h:421
MRVIEWER_API void onSceneSaved(const std::filesystem::path &savePath, bool storeInRecent=true)
MRVIEWER_API bool touchStart(int id, int x, int y)
MRVIEWER_API void drawUiRenderObjects()
draw 2d (UI) part of objects in scene
MRVIEWER_API bool mouseMove(int mouse_x, int mouse_y)
std::shared_ptr< ObjectMesh > rotationSphere
Definition MRViewer.h:470
MRVIEWER_API void clearFramebuffers()
Vector2i windowOldPos
Definition MRViewer.h:450
std::vector< std::string > commandArgs
Definition MRViewer.h:465
MRVIEWER_API Vector3f viewportToScreen(const Vector3f &viewportPoint, ViewportId id) const
MRVIEWER_API Image captureSceneScreenShot(const Vector2i &resolution=Vector2i(), bool transparentBg=false)
MRVIEWER_API bool isCurrentFrameSwapping() const
MRVIEWER_API double getPrevFrameDrawTimeMillisec() const
MRVIEWER_API void enableGlobalHistory(bool on)
MRVIEWER_API int launch(const LaunchParams &params)
MRVIEWER_API size_t getSwappedFrames() const
MRVIEWER_API void popEventByName(const std::string &name)
const LaunchParams & getLaunchParams() const
Definition MRViewer.h:83
std::function< void(Viewer *viewer)> resetSettingsFunction
Definition MRViewer.h:437
MRVIEWER_API bool touchMove(int id, int x, int y)
MRVIEWER_API bool erase_viewport(const size_t index)
MRVIEWER_API bool touchpadSwipeGestureBegin()
MRVIEWER_API bool dragDrop(const std::vector< std::filesystem::path > &paths)
MRVIEWER_API bool spaceMouseDown(int key)
MRVIEWER_API bool touchpadSwipeGestureUpdate(float dx, float dy, bool kinetic)
friend MRVIEWER_API Viewer & getViewerInstance()
returns global instance of Viewer class
MRVIEWER_API PointInAllSpaces getPixelPointInfo(const Vector3f &screenPoint) const
bool isAlphaSortEnabled() const
Definition MRViewer.h:330
MRVIEWER_API void emplaceEvent(std::string name, ViewerEventCallback cb, bool skipable=false)
MRVIEWER_API int getMSAA() const
MRVIEWER_API bool spaceMouseUp(int key)
MRVIEWER_API void incrementForceRedrawFrames(int i=1, bool swapOnLastOnly=false)
size_t selected_viewport_index
Definition MRViewer.h:441
MRVIEWER_API const TouchpadParameters & getTouchpadParameters() const
MRVIEWER_API void postSetMaximized(bool maximized)
const std::shared_ptr< SpaceMouseHandler > & getSpaceMouseHandler() const
Definition MRViewer.h:393
MRVIEWER_API int getRequestedMSAA() const
static Viewer * instance()
Definition MRViewer.h:86
MRVIEWER_API bool mouseUp(MouseButton button, int modifier)
MRVIEWER_API bool enableAlphaSort(bool on)
PluginType * getPluginInstance()
Definition MRViewer.h:93
MRVIEWER_API bool mouseScroll(float delta_y)
bool isLaunched() const
Definition MRViewer.h:80
MRVIEWER_API void postEmptyEvent()
static const Viewer * constInstance()
Definition MRViewer.h:89
std::unique_ptr< ViewportGlobalBasis > globalBasis
Definition MRViewer.h:469
MRVIEWER_API size_t getFPS() const
MRVIEWER_API Vector3f screenToViewport(const Vector3f &screenPoint, ViewportId id) const
MRVIEWER_API bool dragEnd(MouseButton button, int modifier)
std::shared_ptr< ObjectMesh > clippingPlaneObject
Definition MRViewer.h:472
MRVIEWER_API const Viewport & viewport(ViewportId viewportId={}) const
static const Viewer & constInstanceRef()
Definition MRViewer.h:90
MRVIEWER_API bool touchpadZoomGestureEnd()
void setSortDroppedFiles(bool value)
sets whether to sort the filenames received from Drag&Drop in lexicographical order before adding the...
Definition MRViewer.h:505
MRVIEWER_API bool touchpadRotateGestureBegin()
MRVIEWER_API bool mouseDown(MouseButton button, int modifier)
RecentFilesStore & recentFilesStore()
Definition MRViewer.h:499
MRVIEWER_API void select_hovered_viewport()
MRVIEWER_API ViewportId append_viewport(const ViewportRectangle &viewportRect, bool append_empty=false)
MRVIEWER_API bool touchpadRotateGestureUpdate(float angle)
MRVIEWER_API bool spaceMouseRepeat(int key)
MRVIEWER_API void incrementThisFrameGLPrimitivesCount(GLPrimitivesType type, size_t num)
MRVIEWER_API void postRescale(float x, float y)
static Viewer & instanceRef()
Definition MRViewer.h:87
std::shared_ptr< ObjectMesh > basisAxes
Definition MRViewer.h:467
MRVIEWER_API bool touchpadZoomGestureBegin()
MRVIEWER_API void bindSceneTexture(bool bind)
MRVIEWER_API bool touchpadZoomGestureUpdate(float scale, bool kinetic)
MRVIEWER_API void set_root(SceneRootObject &newRoot)
MRVIEWER_API void stopEventLoop()
MRVIEWER_API void launchEventLoop()
MRVIEWER_API void captureUIScreenShot(std::function< void(const Image &)> callback, const Vector2i &pos=Vector2i(), const Vector2i &size=Vector2i())
MRVIEWER_API void launchShut()
MRVIEWER_API bool globalHistoryUndo()
MRVIEWER_API std::shared_ptr< RibbonMenu > getRibbonMenu() const
MRVIEWER_API const std::unique_ptr< IViewerSettingsManager > & getViewerSettingsManager() const
Definition MRViewer.h:353
MRVIEWER_API void preciseFitDataViewport(MR::ViewportMask vpList=MR::ViewportMask::all())
Vector2i framebufferSize
Definition MRViewer.h:447
ViewerSignals & signals()
return the structure with all viewer's signals
Definition MRViewer.h:478
MRVIEWER_API bool keyDown(int key, int modifier)
bool getSortDroppedFiles() const
returns whether to sort the filenames received from Drag&Drop in lexicographical order before adding ...
Definition MRViewer.h:502
MRVIEWER_API void setupScene()
MRVIEWER_API void setMenuPlugin(std::shared_ptr< ImGuiMenu > menu)
MRVIEWER_API Viewport & viewport(ViewportId viewportId={})
MRVIEWER_API size_t getStaticGLBufferSize() const
GLPrimitivesType
Definition MRViewer.h:286
Vector2i windowSavePos
Definition MRViewer.h:448
MRVIEWER_API size_t getLastFrameGLPrimitivesCount(GLPrimitivesType type) const
MRVIEWER_API bool dragStart(MouseButton button, int modifier)
MRVIEWER_API ViewportId getHoveredViewportIdOrInvalid() const
MRVIEWER_API void drawFull(bool dirtyScene)
std::unique_ptr< CornerControllerObject > basisViewController
Definition MRViewer.h:468
MRVIEWER_API bool loadFiles(const std::vector< std::filesystem::path > &filesList)
MRVIEWER_API bool loadFiles(const std::vector< std::filesystem::path > &filesList, const FileLoadOptions &options)
MRVIEWER_API void drawScene()
MRVIEWER_API void requestChangeMSAA(int newMSAA)
GLFWwindow * window
Definition MRViewer.h:433
MRVIEWER_API bool drag(int mouse_x, int mouse_y)
MRVIEWER_API void postSetIconified(bool iconified)
MRVIEWER_API bool globalHistoryRedo()
MRVIEWER_API void makeTitleFromSceneRootPath()
MRVIEWER_API size_t getTotalFrames() const
MRVIEWER_API void postFocus(bool focused)
void setSceneDirty()
Definition MRViewer.h:160
MRVIEWER_API void resetAllCounters()
MRVIEWER_API bool isSupportedFormat(const std::filesystem::path &file_name)
MRVIEWER_API void draw(bool force=false)
MRVIEWER_API int viewport_index(ViewportId viewport_id) const
MRVIEWER_API bool touchpadRotateGestureEnd()
MouseController & mouseController()
Definition MRViewer.h:495
MRVIEWER_API bool isSceneTextureBound() const
MRVIEWER_API void initSpaceMouseHandler(std::function< void(const std::string &)> deviceSignal={})
MRVIEWER_API bool touchEnd(int id, int x, int y)
const RecentFilesStore & recentFilesStore() const
Definition MRViewer.h:498
MRVIEWER_API bool interruptWindowClose()
MRVIEWER_API bool spaceMouseMove(const Vector3f &translate, const Vector3f &rotate)
MRVIEWER_API void setTouchpadParameters(const TouchpadParameters &)
MRVIEWER_API void preciseFitDataViewport(MR::ViewportMask vpList, const FitDataParams &param)
bool isGlobalHistoryEnabled() const
Definition MRViewer.h:380
MRVIEWER_API void postResize(int w, int h)
MRVIEWER_API bool keyPressed(unsigned int unicode_key, int modifier)
MRVIEWER_API bool isSceneTextureEnabled() const
MRVIEWER_API void postSetPosition(int xPos, int yPos)
MRVIEWER_API void clearScene()
std::vector< Viewport > viewport_list
Definition MRViewer.h:440
MRVIEWER_API void postClose()
bool getStopEventLoopFlag() const
Definition MRViewer.h:412
Definition MRViewportId.h:16
stores mask of viewport unique identifiers
Definition MRViewportId.h:42
static ViewportMask all()
mask meaning all or any viewports
Definition MRViewportId.h:49
Definition MRViewport.h:46
Definition MRCameraOrientationPlugin.h:8
MouseMode
Definition MRMouse.h:19
MouseButton
Definition MRMouse.h:9
MRVIEWER_API Viewer & getViewerInstance()
returns global instance of Viewer class
MRVIEWER_API int launchDefaultViewer(const Viewer::LaunchParams &params, const ViewerSetup &setup)
Box2f ViewportRectangle
Viewport size.
Definition MRViewerFwd.h:14
std::function< void()> ViewerEventCallback
Definition MRViewerFwd.h:78
Definition MRFileLoadOptions.h:11
Definition MRFitData.h:29
Definition MRImage.h:16
Definition MRViewer.h:29
WindowMode
Definition MRViewer.h:34
@ HideInit
Definition MRViewer.h:36
@ NoWindow
Definition MRViewer.h:39
@ TryHidden
Definition MRViewer.h:38
@ Hide
Definition MRViewer.h:37
@ Show
Definition MRViewer.h:35
bool render3dSceneInTexture
Definition MRViewer.h:43
bool console
Definition MRViewer.h:49
bool developerFeatures
Definition MRViewer.h:44
char ** argv
Definition MRViewer.h:51
bool startEventLoop
Definition MRViewer.h:47
bool fullscreen
Definition MRViewer.h:30
int animationMaxFps
Definition MRViewer.h:55
int argc
Definition MRViewer.h:50
std::shared_ptr< SplashWindow > splashWindow
Definition MRViewer.h:58
bool unloadPluginsAtEnd
Definition MRViewer.h:56
bool close
Definition MRViewer.h:48
bool showMRVersionInTitle
Definition MRViewer.h:53
bool enableTransparentBackground
Definition MRViewer.h:41
int height
Definition MRViewer.h:32
bool resetConfig
Definition MRViewer.h:46
bool preferOpenGL3
Definition MRViewer.h:42
int width
Definition MRViewer.h:31
enum MR::LaunchParams::WindowMode HideInit
std::string name
Definition MRViewer.h:45
bool isAnimating
Definition MRViewer.h:54
Definition MRPointInAllSpaces.h:13
Definition MRSpaceMouseParameters.h:10
Definition MRTouchpadParameters.h:9
Definition MRViewerSignals.h:10