Qt 6.11 is out! See what's new in the release
blog
QtQuick3D - Colorize model imported from .obj file by the Runtimeloader
-
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
-
Change
node.material = material;tonode.materials = [material];because the Model in QtQuick3D has a property calledmaterials(a list), not a singlematerial.