Please contact us if you have any trouble resetting your password.
I hope you’re all doing well.
So I’ve been developing this application that renders a textured cube and rotates using quaternions. [I’m working with Qt6 and I’m using QOpenGL].
Then I wanted to chnage the cube with another textured 3D model that I loaded using QT3D. this means I didn’t draw the cube then add the texture, I loaded the full model.
I’ve looked for several solutions to do that, I found a tutorial that has 21 episodes and followed every steps but the application kept crashing and I felt really exhasuted because I couldn’t rewatch 21 episodes that last about 1 hour.
So I kept searching for an easier way to load the 3D model and found an example with QT3D. It finally worked ( I created a new project and followed the same steps). I tried to draw some other objects ( not load them) using opengl but that didn’t work.
Now I want to integrate this part in the main project however I’m not sure about mising QT3D and QOpenGL together.
So I’m wondering if there is a way to do that.
Load the model using QT3D then continue to work on it ( apply transformations and add other objects) using QOpenGL.
The example I worked with uses QT3D and QTransform class to apply transformation on the model and the fix the position of the camera.
Here is how I loaded the model with QT3D: (sorry for the long code)
int main(int argc, char* argv)
QApplication app(argc, argv);
Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();
QWidget *container = QWidget::createWindowContainer(view);
QSize screenSize = view->screen()->size();
QWidget *widget = new QWidget;
QHBoxLayout *hLayout = new QHBoxLayout(widget);
Qt3DInput::QInputAspect *input = new Qt3DInput::QInputAspect;
// Root entity
Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity();
Qt3DRender::QCamera *cameraEntity = view->camera();
cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 100000.0f);
cameraEntity->setPosition(QVector3D(-40000, 40000, 40000.0f));
cameraEntity->setUpVector(QVector3D(0, 0, 1));
//cameraEntity->setViewCenter(QVector3D(0, 0, 10000));
cameraEntity->setViewCenter(QVector3D(0, 0, 100000));
Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);
//Loading .ply data
const QUrl data = QUrl::fromLocalFile("C:/Users/nahra/3DModel_qt3d/Model3D/challengeone.PLY");
qDebug() << data << data.isValid() << data.toLocalFile() << QFileInfo(data.toLocalFile()).exists() << data.fileName();
qDebug() << QDir::currentPath();
Qt3DRender::QMesh *bodyMesh = new Qt3DRender::QMesh();
Qt3DCore::QTransform *bodyTransform = new Qt3DCore::QTransform;
bodyTransform->setScale3D(QVector3D(90.0, 90.0, 90.0));
bodyTransform->setTranslation(QVector3D(0.0,0.0,5.0)); //translation doesn't work
Qt3DExtras::QPhongMaterial *bodyMaterial = new Qt3DExtras::QPhongMaterial();
Qt3DCore::QEntity *plyEntity = new Qt3DCore::QEntity(rootEntity);
// Set root object of the scene
// Show window
I think that camera entity here is the equivalent of gluLookAt in opengl or lookAt in QOpenGL.
And bodyTransform is the equivalent of the model matrix.
I just want to load the model and keep working on it using QOpenGL functions.
I want to do something like this:
I want to load the modelview and projection matrices into the opengl pipeline.
I can’t do that because cameraEntity→lens() is a QCamera and bodyTransform is a QTransform. These are not matrices.
EDIT: What I did is that I store the projection and model matrices values like this:
then I calculated the modelview matrix ( product of viewmatrix and model)
// draw coordinate system
I loaded them in the OpenGL pipeline and tried to draw a coordinate system but that didn’t work.
Thank you all.