FreeCAD-VR: Render the FreeCAD scene graph

This commit is contained in:
jriegel 2014-09-15 19:50:55 +02:00
parent 0d2ce7073a
commit 2a4626d27a
4 changed files with 64 additions and 39 deletions

View File

@ -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++) {

View File

@ -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;
};

View File

@ -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

View File

@ -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
}