improve obj export of mesh with colors
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user