From 2a4626d27ad2c7e2a35e7001b65826a70fc2a6cb Mon Sep 17 00:00:00 2001 From: jriegel Date: Mon, 15 Sep 2014 19:50:55 +0200 Subject: [PATCH] FreeCAD-VR: Render the FreeCAD scene graph --- src/Gui/CoinRiftWidget.cpp | 5 +- src/Gui/CoinRiftWidget.h | 4 ++ src/Gui/View3DInventorRiftViewer.cpp | 77 ++++++++++++++++------------ src/Gui/View3DInventorViewer.cpp | 17 ++++-- 4 files changed, 64 insertions(+), 39 deletions(-) diff --git a/src/Gui/CoinRiftWidget.cpp b/src/Gui/CoinRiftWidget.cpp index fa4602406..ac3c1d8ef 100644 --- a/src/Gui/CoinRiftWidget.cpp +++ b/src/Gui/CoinRiftWidget.cpp @@ -84,7 +84,8 @@ CoinRiftWidget::CoinRiftWidget() : QGLWidget() renderer = new SoOffscreenRenderer(SbViewportRegion(std::max(recommenedTex0Size.w, recommenedTex0Size.w), std::max(recommenedTex1Size.h, recommenedTex1Size.h))); renderer->setComponents(SoOffscreenRenderer::RGB_TRANSPARENCY); - renderer->setBackgroundColor(SbColor(.0f, .0f, .8f)); + BackgroundColor = SbColor(.0f, .0f, .8f); + renderer->setBackgroundColor(BackgroundColor); #endif #ifdef USE_FRAMEBUFFER m_sceneManager = new SoSceneManager(); @@ -154,7 +155,7 @@ CoinRiftWidget::CoinRiftWidget() : QGLWidget() hmd->DefaultEyeFov,//eyes, eyeRenderDesc)) { qDebug() << "Could not configure OVR rendering."; - exit(3); + throw; } for (int eye = 0; eye < 2; eye++) { diff --git a/src/Gui/CoinRiftWidget.h b/src/Gui/CoinRiftWidget.h index ace577be9..a96e92802 100644 --- a/src/Gui/CoinRiftWidget.h +++ b/src/Gui/CoinRiftWidget.h @@ -96,6 +96,9 @@ public: explicit CoinRiftWidget(); ~CoinRiftWidget(); void setSceneGraph(SoNode *sceneGraph); + void setBase(const SbVec3f &pos){basePosition=pos;} + void setBackgoundColor(const SbColor &Col){BackgroundColor = Col;} + protected: void handlingSafetyWarning(void); void initializeGL(); @@ -103,6 +106,7 @@ protected: void resizeGL(int width, int height); SbVec3f basePosition; + SbColor BackgroundColor; }; diff --git a/src/Gui/View3DInventorRiftViewer.cpp b/src/Gui/View3DInventorRiftViewer.cpp index 18971b9e7..06a2cc9f4 100644 --- a/src/Gui/View3DInventorRiftViewer.cpp +++ b/src/Gui/View3DInventorRiftViewer.cpp @@ -34,40 +34,9 @@ using namespace Gui; static View3DInventorRiftViewer *window=0; - -void oculusStop() +void oculusSetTestScene(View3DInventorRiftViewer *window) { - //SoDB::finish(); - if(window){ - delete window; - window = 0; - } - - ovr_Shutdown(); -} - -bool oculusUp(void) -{ - return window!=0; -} - -int oculusStart(void) -{ - //SoDB::init(); - - //QApplication app(argc, argv); - //qAddPostRoutine(cleanup); - - // Moved here because of https://developer.oculusvr.com/forums/viewtopic.php?f=17&t=7915&p=108503#p108503 - // Init libovr. - if (!ovr_Initialize()) { - qDebug() << "Could not initialize Oculus SDK."; - return 0; - } - - window = new View3DInventorRiftViewer; - window->show(); - + assert(window); // An example scene. static const char * inlineSceneGraph[] = { "#Inventor V2.1 ascii\n", @@ -105,9 +74,49 @@ int oculusStart(void) in.setStringArray(inlineSceneGraph); window->setSceneGraph(SoDB::readAll(&in)); +} - return 1; + +void oculusStop() +{ + //SoDB::finish(); + if(window){ + delete window; + window = 0; + } + + ovr_Shutdown(); +} + +bool oculusUp(void) +{ + return window!=0; +} + +View3DInventorRiftViewer* oculusStart(void) +{ + //SoDB::init(); + + //QApplication app(argc, argv); + //qAddPostRoutine(cleanup); + + // Moved here because of https://developer.oculusvr.com/forums/viewtopic.php?f=17&t=7915&p=108503#p108503 + // Init libovr. + if (!ovr_Initialize()) { + qDebug() << "Could not initialize Oculus SDK."; + return 0; + } + if(window) + return window; + + window = new View3DInventorRiftViewer; + window->show(); + + + return window; //return app.exec(); } + + #endif //BUILD_VR \ No newline at end of file diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 8f78ea210..1a98287ed 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -103,6 +103,7 @@ #include "SoFCInteractiveElement.h" #include "SoFCBoundingBox.h" #include "SoAxisCrossKit.h" +#include "View3DInventorRiftViewer.h" #include "Selection.h" #include "SoFCSelectionAction.h" @@ -1637,9 +1638,10 @@ void View3DInventorViewer::animatedViewAll(int steps, int ms) } #if BUILD_VR -extern int oculusStart(void); +extern View3DInventorRiftViewer* oculusStart(void); extern bool oculusUp (void); extern void oculusStop (void); +void oculusSetTestScene(View3DInventorRiftViewer *window); #endif void View3DInventorViewer::viewVR(void) @@ -1647,8 +1649,17 @@ void View3DInventorViewer::viewVR(void) #if BUILD_VR if(oculusUp()) oculusStop(); - else - oculusStart(); + else{ +#if 0 + // start and load the simple test scene: + oculusSetTestScene(oculusStart()); +#else + View3DInventorRiftViewer* riftWin = oculusStart(); + riftWin->setSceneGraph(pcViewProviderRoot); + +#endif + + } #endif }