+ 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,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()));