14#define ENQUEUE_VIEWER_METHOD( NAME, METHOD ) MR::getViewerInstance().emplaceEvent( NAME, [] { \
15 MR::getViewerInstance() . METHOD (); \
17#define ENQUEUE_VIEWER_METHOD_ARGS( NAME, METHOD, ... ) MR::getViewerInstance().emplaceEvent( NAME, [__VA_ARGS__] { \
18 MR::getViewerInstance() . METHOD ( __VA_ARGS__ ); \
20#define ENQUEUE_VIEWER_METHOD_ARGS_SKIPABLE( NAME, METHOD, ... ) MR::getViewerInstance().emplaceEvent( NAME, [__VA_ARGS__] { \
21 MR::getViewerInstance() . METHOD ( __VA_ARGS__ ); \
45 std::string
name{
"MRViewer" };
92 template<
typename PluginType>
95 for (
auto& plugin : plugins )
97 auto p =
dynamic_cast< PluginType*
>( plugin );
113 MRVIEWER_API
bool loadFiles(
const std::vector< std::filesystem::path>& filesList );
116 MRVIEWER_API
bool saveToFile(
const std::filesystem::path & mesh_file_name );
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 );
125 MRVIEWER_API
bool mouseMove(
int mouse_x,
int mouse_y );
130 MRVIEWER_API
bool drag(
int mouse_x,
int mouse_y );
131 MRVIEWER_API
bool spaceMouseMove(
const Vector3f& translate,
const Vector3f& rotate );
135 MRVIEWER_API
bool dragDrop(
const std::vector<std::filesystem::path>& paths );
139 MRVIEWER_API
bool touchEnd(
int id,
int x,
int y );
154 MRVIEWER_API
void draw(
bool force =
false );
166 MRVIEWER_API
void resize(
int w,
int h );
257 bool swapOnLastPostEventsRedraw{
true };
259 int forceRedrawMinimumIncrementAfterEvents{ 4 };
322 const Vector2i& pos = Vector2i(),
const Vector2i& size = Vector2i() );
396 MRVIEWER_API
void onSceneSaved(
const std::filesystem::path& savePath,
bool storeInRecent =
true );
406 template <
typename T>
407 std::shared_ptr<T>
getMenuPluginAs()
const {
return std::dynamic_pointer_cast<T>( getMenuPlugin() ); }
446 float pixelRatio{ 1.0f };
451 bool windowMaximized{
false };
454 bool isAnimating{
false };
456 int animationMaxFps{ 30 };
459 float scrollForce{ };
461 uint16_t glPickRadius{ };
463 bool experimentalFeatures{ };
533 void shutdownPlugins_();
536 void mainLoopFunc_();
537 static void emsMainInfiniteLoop();
540 bool draw_(
bool force );
543 int forceRedrawFrames_{ 0 };
545 int forceRedrawFramesWithoutSwap_{ 0 };
548 bool enableDeveloperFeatures_{
false };
550 std::unique_ptr<ViewerEventQueue> eventQueue_;
553 std::shared_ptr<ImGuiMenu> menuPlugin_;
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_;
561 std::unique_ptr<RecentFilesStore> recentFilesStore_;
562 std::unique_ptr<FrameCounter> frameCounter_;
564 mutable struct EventsCounter
566 std::array<size_t, size_t( EventType::Count )> counter{};
570 mutable struct GLPrimitivesCounter
572 std::array<size_t, size_t( GLPrimitivesType::Count )> counter{};
574 } glPrimitivesCounter_;
578 bool tryCreateWindow_(
bool fullscreen,
int& width,
int& height,
const std::string& name,
int major,
int minor );
580 bool needRedraw_()
const;
583 void recursiveDraw_(
const Viewport& vp,
const Object& obj,
const AffineXf3f& parentXf, RenderModelPassMask renderType,
int* numDraws =
nullptr )
const;
585 void initGlobalBasisAxesObject_();
586 void initBasisAxesObject_();
587 void initBasisViewControllerObject_();
588 void initClippingPlaneObject_();
589 void initRotationCenterObject_();
592 void updatePixelRatio_();
597 int getRequiredMSAA_(
bool sceneTextureOn,
bool forSceneTexture )
const;
599 bool stopEventLoop_{
false };
601 bool isLaunched_{
false };
603 bool focusRedrawReady_{
false };
605 std::unique_ptr<SceneTextureGL> sceneTexture_;
606 std::unique_ptr<AlphaSortGL> alphaSorter_;
608 bool alphaSortEnabled_{
false};
610 bool glInitialized_{
false };
612 bool isInDraw_{
false };
613 bool dirtyScene_{
false };
615 bool hasScaledFramebuffer_{
false };
617 bool sortDroppedFiles_{
true };
619 LaunchParams launchParams_;
621 ViewportId getFirstAvailableViewportId_()
const;
622 ViewportMask presentViewportsMask_;
624 std::unique_ptr<IViewerSettingsManager> settingsMng_;
626 std::shared_ptr<HistoryStore> globalHistoryStore_;
628 std::shared_ptr<SpaceMouseHandler> spaceMouseHandler_;
631 std::unique_ptr<Connections> connections_;
632 std::unique_ptr<ViewerSignals> signals_;
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
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)
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 ¶ms)
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 ¶ms)
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 ¶m)
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 ¶ms, 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
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