Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSphereMesh Texture with PNG



  • Hello friends good afternoon I'm getting started migrating from my OpenGL projects to QT3D however, I'm having trouble understanding, and how to make solids texture like QSphereMesh presented in the qt example called basicshapes-cpp. Can anybody help me ?

       // Sphere shape data
       Qt3DExtras::QSphereMesh *sphereMesh = new Qt3DExtras::QSphereMesh();
       sphereMesh->setRings(32);
       sphereMesh->setSlices(32);
       sphereMesh->setRadius(4);
    
       // Sphere mesh transform
       Qt3DCore::QTransform *sphereTransform = new Qt3DCore::QTransform();
       sphereTransform->setScale(1.0f);
       sphereTransform->setTranslation(QVector3D(0.0f, 0.0f, 0.0f));
       sphereTransform->setRotation(QQuaternion(1.0f, 0.0f, 0.0f, 0.0f));
    
       Qt3DExtras::QPhongMaterial *sphereMaterial = new Qt3DExtras::QPhongMaterial();
       sphereMaterial->setDiffuse(QColor(QRgb(0xA69929)));
    
       // Sphere
       m_sphereEntity = new Qt3DCore::QEntity(m_rootEntity);
       m_sphereEntity->addComponent(sphereMesh);
       m_sphereEntity->addComponent(sphereMaterial);
       m_sphereEntity->addComponent(sphereTransform);
    


  • Solved =D

       // Sphere shape data
       Qt3DExtras::QSphereMesh *sphereMesh = new Qt3DExtras::QSphereMesh();
       sphereMesh->setRings(32);
       sphereMesh->setSlices(32);
       sphereMesh->setRadius(4);
    
       // Sphere mesh transform
       Qt3DCore::QTransform *sphereTransform = new Qt3DCore::QTransform();
       sphereTransform->setScale(1.0f);
       sphereTransform->setTranslation(QVector3D(0.0f, 0.0f, 0.0f));
       sphereTransform->setRotation(QQuaternion(1.0f, 0.0f, 0.0f, 0.0f));
    
       Qt3DRender::QTextureImage *diffuseTextureImage = new Qt3DRender::QTextureImage();
       diffuseTextureImage->setMirrored(false);
       diffuseTextureImage->setSource(QUrl(QStringLiteral("qrc:/resources/image.png")));
    
       Qt3DExtras::QDiffuseSpecularMapMaterial *diffuseSpecularMaterial = new Qt3DExtras::QDiffuseSpecularMapMaterial();
       diffuseSpecularMaterial->diffuse()->addTextureImage(diffuseTextureImage);
    
       // Sphere
       m_sphereEntity = new Qt3DCore::QEntity(m_rootEntity);
       m_sphereEntity->addComponent(sphereMesh);
       m_sphereEntity->addComponent(diffuseSpecularMaterial);
       m_sphereEntity->addComponent(sphereTransform);
    

Log in to reply