+ support reading mesh files with colors

This commit is contained in:
wmayer
2015-12-31 21:07:04 +01:00
parent e2369996e2
commit 342198ea87
7 changed files with 129 additions and 7 deletions

View File

@@ -83,6 +83,7 @@ void MeshExport initMesh()
Mesh::MeshObject ::init();
Mesh::Feature ::init();
Mesh::FeatureCustom ::init();
Mesh::FeaturePython ::init();
Mesh::Import ::init();
Mesh::Export ::init();

View File

@@ -83,7 +83,8 @@ static PyObject * open(PyObject *self, PyObject *args)
PY_TRY {
MeshObject mesh;
if (mesh.load(EncodedName.c_str())) {
MeshCore::Material mat;
if (mesh.load(EncodedName.c_str(), &mat)) {
Base::FileInfo file(EncodedName.c_str());
// create new document and add Import feature
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
@@ -98,6 +99,20 @@ static PyObject * open(PyObject *self, PyObject *args)
pcFeature->purgeTouched();
}
}
else if (mat.binding == MeshCore::MeshIO::PER_VERTEX &&
mat.diffuseColor.size() == mesh.countPoints()) {
FeatureCustom *pcFeature = new FeatureCustom();
pcFeature->Label.setValue(file.fileNamePure().c_str());
pcFeature->Mesh.swapMesh(mesh);
App::PropertyColorList* prop = static_cast<App::PropertyColorList*>
(pcFeature->addDynamicProperty("App::PropertyColorList", "VertexColors"));
if (prop) {
prop->setValues(mat.diffuseColor);
}
pcFeature->purgeTouched();
pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
}
else {
Mesh::Feature *pcFeature = static_cast<Mesh::Feature *>
(pcDoc->addObject("Mesh::Feature", file.fileNamePure().c_str()));
@@ -132,6 +147,7 @@ static PyObject * importer(PyObject *self, PyObject *args)
}
MeshObject mesh;
MeshCore::Material mat;
if (mesh.load(EncodedName.c_str())) {
Base::FileInfo file(EncodedName.c_str());
unsigned long segmct = mesh.countSegments();
@@ -145,6 +161,20 @@ static PyObject * importer(PyObject *self, PyObject *args)
pcFeature->purgeTouched();
}
}
else if (mat.binding == MeshCore::MeshIO::PER_VERTEX &&
mat.diffuseColor.size() == mesh.countPoints()) {
FeatureCustom *pcFeature = new FeatureCustom();
pcFeature->Label.setValue(file.fileNamePure().c_str());
pcFeature->Mesh.swapMesh(mesh);
App::PropertyColorList* prop = static_cast<App::PropertyColorList*>
(pcFeature->addDynamicProperty("App::PropertyColorList", "VertexColors"));
if (prop) {
prop->setValues(mat.diffuseColor);
}
pcFeature->purgeTouched();
pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
}
else {
Mesh::Feature *pcFeature = static_cast<Mesh::Feature *>
(pcDoc->addObject("Mesh::Feature", file.fileNamePure().c_str()));

View File

@@ -720,6 +720,16 @@ bool MeshInput::LoadPLY (std::istream &inp)
if (num_z != 1)
return false;
for (std::vector<std::pair<std::string, Ply::Number> >::iterator it =
vertex_props.begin(); it != vertex_props.end(); ++it) {
if (it->first == "diffuse_red")
it->first = "red";
else if (it->first == "diffuse_green")
it->first = "green";
else if (it->first == "diffuse_blue")
it->first = "blue";
}
// check if valid colors are set
std::size_t num_r = std::count_if(vertex_props.begin(), vertex_props.end(),
std::bind2nd(property, "red"));

View File

@@ -97,6 +97,17 @@ void Feature::onChanged(const App::Property* prop)
// ---------------------------------------------------------
namespace App {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(Mesh::FeatureCustom, Mesh::Feature)
/// @endcond
// explicit template instantiation
template class MeshExport FeatureCustomT<Mesh::Feature>;
}
// ---------------------------------------------------------
namespace App {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(Mesh::FeaturePython, Mesh::Feature)

View File

@@ -25,6 +25,7 @@
#define MESH_FEATURE_H
#include <App/GeoFeature.h>
#include <App/FeatureCustom.h>
#include <App/FeaturePython.h>
#include "Core/MeshKernel.h"
@@ -81,6 +82,7 @@ public:
virtual PyObject* getPyObject(void);
};
typedef App::FeatureCustomT<Feature> FeatureCustom;
typedef App::FeaturePythonT<Feature> FeaturePython;
} //namespace Mesh