Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can I reload/refresh 3d model on mouse click?
QtWS25 Last Chance

Can I reload/refresh 3d model on mouse click?

Scheduled Pinned Locked Moved Solved General and Desktop
qt5.7qt3dwindowqt3drender
4 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PoortiP Offline
    PoortiP Offline
    Poorti
    wrote on last edited by Poorti
    #1

    Hi All,

    I am developing a 3d model loader in Qt 5.7 on Windows.
    I have been successful in loading the model. The model has jpg textures.
    I want to be able to reload the model (say, on a button click), whenever I replace the texture image on disk.

    Here is the code that loads the model,

    ASErr RenderView()
    {
    	view->setVisible(false);
    	view->defaultFramegraph()->setClearColor(Qt::black);
    
    	// Root entity
    	Qt3DCore::QEntity *sceneRoot = new Qt3DCore::QEntity();
    
    	// Scene Camera
    	Qt3DRender::QCamera *camera = view->camera();
    	camera->setProjectionType(Qt3DRender::QCameraLens::PerspectiveProjection);
    	camera->setAspectRatio(view->width() / view->height());
    	camera->setUpVector(QVector3D(0.0f, 1.0f, 0.0f));
    	camera->setViewCenter(QVector3D(0.0f, 1.1f, 0.0f));
    	camera->setPosition(QVector3D(0.0f, 2.5f, 2.0f));
    	camera->setNearPlane(0.001f);
    	camera->setFarPlane(100.0f);
    
    	// For camera controls
    	Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(sceneRoot);
    	camController->setCamera(camera);
    
    	// Scene loader
    	Qt3DCore::QEntity *sceneLoaderEntity = new Qt3DCore::QEntity(sceneRoot);
    	Qt3DRender::QSceneLoader *sceneLoader = new Qt3DRender::QSceneLoader(sceneLoaderEntity);
    
    	sceneWalker = new SceneWalker(sceneLoader);
    	QObject::connect(sceneLoader, &Qt3DRender::QSceneLoader::statusChanged, sceneWalker, &SceneWalker::onStatusChanged);
    	sceneLoaderEntity->addComponent(sceneLoader);
    
    	std::string url = GetUrl();
    	QUrl sourceFileName(url.c_str());
    
    	if (sourceFileName.isEmpty())
    		return 0;
    
    	sceneLoader->setSource(sourceFileName);
    	view->setRootEntity(sceneRoot);
    	view->show();
    
    	return 0;
    }
    

    Here, view is a pointer to Qt3DExtras::Qt3DWindow.
    I have followed the assimp-cpp sample from Qt.

    How can I refresh my model on button click so that it refreshes the textures?

    1 Reply Last reply
    0
    • PoortiP Offline
      PoortiP Offline
      Poorti
      wrote on last edited by
      #2

      Update:
      When I try to call the above method after the texture jpg image is changed, I get the following exception,

      ASSERT: "!is Visible()" in file defaults\qt3d window.cpp
      on this line,

      view->setRootEntity(sceneRoot);
      

      How can I refresh the model view?

      1 Reply Last reply
      0
      • PoortiP Offline
        PoortiP Offline
        Poorti
        wrote on last edited by
        #3

        Anyone?
        Please guide.
        I really need to understand this.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jimfar
          wrote on last edited by
          #4

          hi did u fix it ,i also encout this problem when delete or add a 3DObject to QT3DWindow.. it seems have no convnient api to do this

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved