From 67149d7500b02aed794c7d2d1d4ad386a467a3d8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 6 Jul 2020 12:17:15 +0200 Subject: [PATCH] Mesh: [skip ci] support of loading colored mesh segments --- src/Mod/Mesh/App/AppMeshPy.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Mod/Mesh/App/AppMeshPy.cpp b/src/Mod/Mesh/App/AppMeshPy.cpp index 4e5851c364..0143a72b81 100644 --- a/src/Mod/Mesh/App/AppMeshPy.cpp +++ b/src/Mod/Mesh/App/AppMeshPy.cpp @@ -192,6 +192,21 @@ private: (pcDoc->addObject("Mesh::Feature", groupName.c_str())); pcFeature->Label.setValue(groupName.c_str()); pcFeature->Mesh.swapMesh(*segm); + + // if colors are set per face + if (mat.binding == MeshCore::MeshIO::PER_FACE && + mat.diffuseColor.size() == mesh.countFacets()) { + App::PropertyColorList* prop = static_cast + (pcFeature->addDynamicProperty("App::PropertyColorList", "VertexColors")); + if (prop) { + std::vector diffuseColor; + diffuseColor.reserve(group.getIndices().size()); + for (const auto& it : group.getIndices()) { + diffuseColor.push_back(mat.diffuseColor[it]); + } + prop->setValues(diffuseColor); + } + } pcFeature->purgeTouched(); } } @@ -271,6 +286,21 @@ private: (pcDoc->addObject("Mesh::Feature", groupName.c_str())); pcFeature->Label.setValue(groupName.c_str()); pcFeature->Mesh.swapMesh(*segm); + + // if colors are set per face + if (mat.binding == MeshCore::MeshIO::PER_FACE && + mat.diffuseColor.size() == mesh.countFacets()) { + App::PropertyColorList* prop = static_cast + (pcFeature->addDynamicProperty("App::PropertyColorList", "VertexColors")); + if (prop) { + std::vector diffuseColor; + diffuseColor.reserve(group.getIndices().size()); + for (const auto& it : group.getIndices()) { + diffuseColor.push_back(mat.diffuseColor[it]); + } + prop->setValues(diffuseColor); + } + } pcFeature->purgeTouched(); } }