How to set an object's color in Qt3D?



  • Hello!
    I'm new to Qt3D and got simple scene with one torus object. This object has black color. I'm using Qt3D C++ API (could not find more appropriate place to this question, so I choose QML & QQ).
    My task is to create simple math model schematic visualisation, without any lights shadows and so on.

    How to set just color? I want to see my object in red or any other color, instead of black color. My assumption that it's because I do not have lighting.

    If there any way to set different colors for objects in "shadow"? If one object will be light blue in shadow and other object of yellow color - I will be happy :)

    Qt3DCore::QEntity* gui::create_scene()
    {
    	Qt3DCore::QEntity *root = new Qt3DCore::QEntity;
    
    	Qt3DExtras::QDiffuseSpecularMapMaterial *material = new Qt3DExtras::QDiffuseSpecularMapMaterial(root);
    	// ??? how to set color of this material?
    
    	Qt3DCore::QEntity *torus = new Qt3DCore::QEntity(root);
    	Qt3DExtras::QTorusMesh *torus_mesh = new Qt3DExtras::QTorusMesh;
    	torus_mesh->setRadius(15);
    	torus_mesh->setMinorRadius(3);
    	torus_mesh->setRings(20);
    	torus_mesh->setSlices(5);
    	Qt3DCore::QTransform *torus_transform = new Qt3DCore::QTransform;
    	torus_transform->setScale3D(QVector3D(1.5, 1, 0.5));
    torus_transform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), 45.0f));
    	torus->addComponent(torus_mesh);
    	torus->addComponent(torus_transform);
    	torus->addComponent(material);
    	return root;
    }
    


  • To set the surface colors according to the Phong model, you should use slots of QDiffuseSpecularMapMaterial:

    void setAmbient (const QColor & ambient)
    void SetDiffus (Qt3DRender :: QAbstractTexture * diffuse)
    void setShininess (float shininess)

    And for set texture :
    void setSpecular (Qt3DRender :: QAbstractTexture * specular)
    voidSetTextureScale (float textureScale)

    And there is no light source in your scene. You must add at least one, otherwise everything will be too dark and will be illuminated only by the ambient light source.



  • @Vladimir-Sazonov said in Qt3D set object color:

    To set the surface colors according to the Phong model, you should use slots of QDiffuseSpecularMapMaterial:
    And for set texture :

    How to set texture? Which class is useful in this case? QAbstractTexture is not usable.

    And there is no light source in your scene. You must add at least one, otherwise everything will be too dark and will be illuminated only by the ambient light source.

    Is it possible to create self-glowing material? Or set ambient light source to maximum intensity? I will try to use Q3DLight...



  • Qt3DExtras::QDiffuseSpecularMapMaterial *material = new Qt3DExtras::QDiffuseSpecularMapMaterial(root);
    // ??? how to set color of this material?

    You could set the colour like this:

    material->setAmbient(Qt::red);

    there are different methods for different lighting.
    setAmbient();
    setDiffuse();
    setSpecular();

    Follow this link for a brief explanation.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.