improve obj export of mesh with colors

This commit is contained in:
wmayer
2016-09-06 17:00:34 +02:00
parent da92d338b7
commit 2c226343cb
6 changed files with 241 additions and 63 deletions

View File

@@ -665,6 +665,35 @@ bool ViewProviderMesh::exportToVrml(const char* filename, const MeshCore::Materi
return false;
}
void ViewProviderMesh::exportMesh(const char* filename, const char* fmt) const
{
MeshCore::MeshIO::Format format = MeshCore::MeshIO::Undefined;
if (fmt) {
std::string dummy = "meshfile.";
dummy += fmt;
format = MeshCore::MeshOutput::GetFormat(dummy.c_str());
}
MeshCore::Material mat;
int numColors = pcShapeMaterial->diffuseColor.getNum();
const SbColor* colors = pcShapeMaterial->diffuseColor.getValues(0);
mat.diffuseColor.reserve(numColors);
for (int i=0; i<numColors; i++) {
const SbColor& c = colors[i];
mat.diffuseColor.push_back(App::Color(c[0], c[1], c[2]));
}
const Mesh::MeshObject& mesh = static_cast<Mesh::Feature*>(getObject())->Mesh.getValue();
if (mat.diffuseColor.size() == mesh.countPoints())
mat.binding = MeshCore::MeshIO::PER_VERTEX;
else if (mat.diffuseColor.size() == mesh.countFacets())
mat.binding = MeshCore::MeshIO::PER_FACE;
else
mat.binding = MeshCore::MeshIO::OVERALL;
mesh.save(filename, format, &mat, getObject()->Label.getValue());
}
void ViewProviderMesh::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
ViewProviderGeometryObject::setupContextMenu(menu, receiver, member);