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