Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt3d Sceneloader: Replace the material component of an Entity with my custom material at runtime
Forum Updated to NodeBB v4.3 + New Features

Qt3d Sceneloader: Replace the material component of an Entity with my custom material at runtime

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 333 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.
  • R Offline
    R Offline
    ruisebastiao
    wrote on last edited by
    #1

    i have the following code to load a collada scene using the SceneLoader:

    SceneLoader{
        id: sceneLoader
        source: "file:///home/rui/projects/cad/bodyplacement_lm36_v2.dae"
        
        
        MetalRoughMaterial {
            
            id:metal_mat
            objectName: "MetalRoughMaterial"
            
            metalness: 0
            roughness: 0.9
        }
        
        
        onStatusChanged: {
            console.log("SceneLoader status: " + status);
            if (status == SceneLoader.Ready) {
                console.log("Scene is ready");
                
                var entitynames=sceneLoader.entityNames();
                for (var i = 0; i < entitynames.length; ++i) {
                    
                    var entityname=entitynames[i];
                    var entityvar=sceneLoader.entity(entityname);
                    
                    for (var j = 0; j< entityvar.components.length; ++j) {
                        
                        
                        var cmp=entityvar.components[j]
                        if(cmp){
                            var cmp_class=cmp.toString();
                            if(cmp_class.indexOf("QPhongMaterial")>=0){
                                entityvar.components[j]=metal_mat;
                            }
                            
                        }
                        
                        
                        
                    }
                    
                    
                    
                }
                
                
                
            }
        }
        
        
        
        
    }
    

    as stated in docs (https://doc.qt.io/qt-5/qt3drender-qsceneloader.html#details):

    The loader will try to determine the best material to be used based on the properties of the model file. If you wish to use a custom material, you will have to traverse the tree and replace the default associated materials with yours.

    after i iterate all the entities i try to replace the material component wit the code:

    entityvar.components[j]=metal_mat;
    

    but isn't working. After debugging i can see that the loaded material isn't replaced.

    How can i replace the material component with my custom material at runtime?

    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