Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. QtQuick3D - Colorize model imported from .obj file by the Runtimeloader
Qt 6.11 is out! See what's new in the release blog

QtQuick3D - Colorize model imported from .obj file by the Runtimeloader

Scheduled Pinned Locked Moved Unsolved Game Development
2 Posts 2 Posters 212 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.
  • K Offline
    K Offline
    kevin_d
    wrote last edited by kevin_d
    #1

    Hello Folks!
    I was upgrading to Qt 6.8/QML and tried to load my .obj - File with QML Syntax.
    The Mesh gets loaded, positioned and scaled properly, but it is white.
    I need to apply custom colors to the meshes.

    This is how i got so far: NOTE: This is not working. Any approach to colorize the Model fails:

          RuntimeLoader {
               id: loader
               source: "Resources/fem_3.obj"
               position: Qt.vector3d(0,1,0)
               scale: Qt.vector3d(5,5,5)
    
               function applyMaterialToAllModels(node, material) {
    
                   if (typeof node === "undefined") return;
    
                   if (node instanceof Model) {
                       node.material = material;
                   } else {
                       // console.log("node type: " + typeof node);
                   }
                   if (typeof node.children === "undefined") return;
                   for (var i = 0; i < node.children.length; i++) {
                       applyMaterialToAllModels(node.children[i], material)
                   }
               }
    
                onStatusChanged:  {
    
                    if (loader.status === RuntimeLoader.Success)
                    {
                        console.log("success loading asset file.")
    
                        var material3 = Qt.createQmlObject( "import QtQuick3D\n" +
                          "DefaultMaterial {\n" +
                           " diffuseColor: \"red\"\n" +
                           "}", loader);
                        material3.diffuseColor = "red";
    
                        applyMaterialToAllModels(loader, material3);
                    }
                }
            }
    

    Can you help me to apply a color?

    best regards, kevin_d

    1 Reply Last reply
    0
    • Nils SjobergN Offline
      Nils SjobergN Offline
      Nils Sjoberg
      wrote last edited by Nils Sjoberg
      #2

      Change node.material = material; to node.materials = [material]; because the Model in QtQuick3D has a property called materials (a list), not a single material.

      "What's up, Doc?"

      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
      • Unsolved