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. Define material indexes for triangles in QQuick3DGeometry
Qt 6.11 is out! See what's new in the release blog

Define material indexes for triangles in QQuick3DGeometry

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 396 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.
  • Dmitry87D Offline
    Dmitry87D Offline
    Dmitry87
    wrote on last edited by Dmitry87
    #1

    I'm trying to load a model to a Quick 3D scene using QQuick3DGeometry
    in the scene I can define (See Sub-mesh Example):

    Model {
        source: "qrc:/meshes/distortedcube.mesh"
        //geometry: MeshData
        
        PrincipledMaterial {
            id: frontTop_material
            baseColor: "red"
            cullMode: Material.NoCulling
            lighting: PrincipledMaterial.NoLighting
        }
    
        PrincipledMaterial {
            id: frontBottom_material
            baseColor: "green"
            cullMode: Material.NoCulling
            lighting: PrincipledMaterial.NoLighting
        }
    
        materials: [
            frontTop_material,
            frontBottom_material
        ]
    }
    

    One part of the model is painted with frontTop_material and for the other frontBottom_material is used.
    I created similar scene where mesh data is generated by QQuick3DGeometry and it is painted on the screen, but I can't see a way how to assing different materials to different triangles. How can I do that?
    There is a set of attributes, which i can set via QQuick3DGeometry::addAttribute to every vertex, but none of them is for defining texture id.

    1 Reply Last reply
    0
    • johngodJ Offline
      johngodJ Offline
      johngod
      wrote on last edited by
      #2

      I'm not sure if you want to apply diferente colors or different textures.
      If you're trying to use textures, for a simple model like a sphere, a texture would be applied like this:

      Model {
                      id: planetEarth
                      source: "#Sphere"
                      materials: [
                          PrincipledMaterial {
                              baseColorMap: Texture {
                                  source: "qrc:/images/earth.png"
                                  scaleU: 1.0
                                  scaleV: 1.0
                              }
                          }
                      ]
                  }
      

      The example you posted distortedcube, AFAIK the model is generated with the balsam tool, (from a obj file, or other similiar 3d format file), hence you can define diferente materials for each sub mesh, be either a texture or a color. See https://doc.qt.io/qt-5/qtquick3d-tool-balsam.html

      Note that I don´t think you can have submeshs with QQuick3DGeometry, so you can have only one texture for one model (but I maybe wrong). With QQuick3DGeometry, you should use QQuick3DGeometry::addAttribute with TexCoordSemantic to define your texture positions in your model. So if you want to load several textures I think you have to break your model a part.
      If you have one model and want to apply different colors to different triangles, I would try to use Quick3DGeometry::addAttribute with ColorSemantic.

      See also the custom geometry example https://doc-snapshots.qt.io/qt6-dev/qtquick3d-customgeometry-example.html

      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