[ui] Viewer3D: add support for vertex-colored meshes

Use PerVertexColorMaterial if any vertex color data is available on a mesh without textures.
This commit is contained in:
Yann Lanthony 2019-07-10 16:35:44 +02:00
parent d30b2364eb
commit cee8d1b612
No known key found for this signature in database
GPG key ID: 519FAE6DF7A70642
2 changed files with 17 additions and 1 deletions

View file

@ -45,6 +45,13 @@ class Scene3DHelper(QObject):
count += sum([attr.count() for attr in geo.attributes() if attr.name() == "vertexPosition"])
return count / 3
@Slot(Qt3DCore.QEntity, result=int)
def vertexColorCount(self, entity):
count = 0
for geo in entity.findChildren(Qt3DRender.QGeometry):
count += sum([attr.count() for attr in geo.attributes() if attr.name() == "vertexColor"])
return count
class TrackballController(QObject):
"""

View file

@ -62,7 +62,11 @@ Entity {
},
State {
name: "Textured"
PropertyChanges { target: m; material: diffuseMap ? textured : solid }
PropertyChanges {
target: m;
// "textured" material resolution order: diffuse map > vertex color data > no color info
material: diffuseMap ? textured : (Scene3DHelper.vertexColorCount(root.parent) ? colored : solid)
}
}
]
}
@ -80,6 +84,11 @@ Entity {
diffuse: root.diffuseColor
}
PerVertexColorMaterial {
id: colored
objectName: "VertexColorMaterial"
}
DiffuseSpecularMaterial {
id: textured
objectName: "TexturedMaterial"