Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to set an object's color in Qt3D?
Forum Updated to NodeBB v4.3 + New Features

How to set an object's color in Qt3D?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 2.9k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    Linux777
    wrote on last edited by A Former User
    #1

    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;
    }
    
    G 1 Reply Last reply
    0
    • V Offline
      V Offline
      Vladimir Sazonov
      wrote on last edited by Vladimir Sazonov
      #2

      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.

      L 1 Reply Last reply
      0
      • V Vladimir Sazonov

        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.

        L Offline
        L Offline
        Linux777
        wrote on last edited by
        #3

        @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...

        1 Reply Last reply
        0
        • L Linux777

          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;
          }
          
          G Offline
          G Offline
          guy incognito
          wrote on last edited by
          #4

          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.

          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