| Home | Documentation | Download | Screenshots | Developer |
The X3D Toolkit library is used to load and display a x3d scene.
You need to install the X3D library in order to compile this file. See the Yannick Le Goc web site (or this page).
Once this is done, edit x3dViewer.pro, set LIBX3D_INSTALLED to
yes and set INCLUDEPATH and LIBS to the path where you
installed libX3D.
Press L (load) to load a new 3DS scene.
#include <qglviewer.h>
#include <X3D/simplex3dglscene.h>
class Viewer : public QGLViewer
{
protected :
void init();
void draw();
void keyPressEvent(QKeyEvent *e);
void loadFile();
QString helpString();
private:
X3D::SimpleX3DGLScene scene;
};
#include "x3dViewer.h"
#include <qfiledialog.h>
using namespace X3D;
using namespace std;
void Viewer::init()
{
#ifdef GL_RESCALE_NORMAL
glEnable(GL_RESCALE_NORMAL);
#endif
help();
loadFile();
}
void Viewer::keyPressEvent(QKeyEvent *e)
{
switch (e->key())
{
case Qt::Key_L : loadFile(); break;
default: QGLViewer::keyPressEvent(e);
}
}
void Viewer::loadFile()
{
QString name = QFileDialog::getOpenFileName("", "X3D files (*.x3d *.X3D);;All files (*)", this);
// In case of Cancel
if (name.isEmpty())
return;
/// Release previous scene.
scene.release();
/// Loads the scene.
scene.load(name);
/// QGLViewer scene settings.
setSceneBoundingBox(scene.getBboxMin().f_data(), scene.getBboxMax().f_data());
showEntireScene();
}
void Viewer::draw()
{
scene.draw();
}
QString Viewer::helpString()
{
QString text("<h2>x 3 d V i e w e r</h2>");
text += "This example uses the libX3D library to load an x3d object file. ";
text += "Press <b>L</b>(oad) to open an x3d file.";
return text;
}
#include "x3dViewer.h"
#include <qapplication.h>
int main(int argc, char** argv)
{
// Read command lines arguments.
QApplication application(argc,argv);
// Instantiate the viewer, show it on screen.
Viewer viewer;
viewer.show();
// Set the viewer as the application main widget.
application.setMainWidget(&viewer);
// Run main loop.
return application.exec();
}
Back to the main page