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_IS_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/qglviewer.h> #include <X3DTK/simplex3dglscene.h> class Viewer : public QGLViewer { protected : virtual void init(); virtual void draw(); virtual void keyPressEvent(QKeyEvent *e); virtual QString helpString() const; void loadFile(); private: X3DTK::SimpleX3DGLScene scene; };
#include "x3dViewer.h" #include <qfiledialog.h> using namespace X3DTK; using namespace std; void Viewer::init() { #ifdef GL_RESCALE_NORMAL glEnable(GL_RESCALE_NORMAL); #endif loadFile(); help(); } 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, with no xml validation. scene.load(name, false); /// QGLViewer scene settings. setSceneBoundingBox(scene.getBBoxMin().f_data(), scene.getBBoxMax().f_data()); showEntireScene(); } void Viewer::draw() { scene.draw(); } QString Viewer::helpString() const { 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.<br>"; text += "Press <b>L</b>(oad) to open an x3d file.<br><br>"; text += QGLViewer::helpString(); 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(); }
Go back to the examples main page