diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp
index 6a4b22d391..72566eac3b 100644
--- a/src/Mod/Part/App/TopoShape.cpp
+++ b/src/Mod/Part/App/TopoShape.cpp
@@ -184,7 +184,7 @@
#include
#include
#include
-
+#include
#include "TopoShape.h"
#include "CrossSection.h"
@@ -826,13 +826,22 @@ void TopoShape::exportStl(const char *filename, double deflection) const
writer.Write(this->_Shape,encodeFilename(filename).c_str());
}
-void TopoShape::exportFaceSet(double dev, double ca, std::ostream& str) const
+void TopoShape::exportFaceSet(double dev, double ca,
+ const std::vector& colors,
+ std::ostream& str) const
{
Base::InventorBuilder builder(str);
TopExp_Explorer ex;
-
- BRepMesh_IncrementalMesh MESH(this->_Shape,dev);
+ std::size_t numFaces = 0;
for (ex.Init(this->_Shape, TopAbs_FACE); ex.More(); ex.Next()) {
+ numFaces++;
+ }
+
+ bool supportFaceColors = (numFaces == colors.size());
+
+ std::size_t index=0;
+ BRepMesh_IncrementalMesh MESH(this->_Shape,dev);
+ for (ex.Init(this->_Shape, TopAbs_FACE); ex.More(); ex.Next(), index++) {
// get the shape and mesh it
const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
Standard_Integer nbNodesInFace,nbTriInFace;
@@ -898,6 +907,11 @@ void TopoShape::exportFaceSet(double dev, double ca, std::ostream& str) const
builder.beginSeparator();
builder.addShapeHints((float)ca);
+ if (supportFaceColors) {
+ App::Color c = colors[index];
+ builder.addMaterial(c.r, c.g, c.b, c.a);
+ }
+
builder.beginPoints();
builder.addPoints(vertices);
builder.endPoints();
diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h
index 1738cb8bd0..abb72591a4 100644
--- a/src/Mod/Part/App/TopoShape.h
+++ b/src/Mod/Part/App/TopoShape.h
@@ -35,6 +35,10 @@ class gp_Ax1;
class gp_Ax2;
class gp_Vec;
+namespace App {
+class Color;
+}
+
namespace Part
{
@@ -175,7 +179,7 @@ public:
void exportBrep(std::ostream&) const;
void exportBinary(std::ostream&);
void exportStl (const char *FileName, double deflection) const;
- void exportFaceSet(double, double, std::ostream&) const;
+ void exportFaceSet(double, double, const std::vector&, std::ostream&) const;
void exportLineSet(std::ostream&) const;
//@}
diff --git a/src/Mod/Part/App/TopoShapePy.xml b/src/Mod/Part/App/TopoShapePy.xml
index 798a99f02d..4399528d10 100644
--- a/src/Mod/Part/App/TopoShapePy.xml
+++ b/src/Mod/Part/App/TopoShapePy.xml
@@ -33,7 +33,7 @@ Sub-elements such as vertices, edges or faces are accessible as:
Read in an IGES, STEP or BREP file.
-
+
Write the mesh in OpenInventor format to a string.
diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp
index 22c5ff3d3d..5255b92fb8 100644
--- a/src/Mod/Part/App/TopoShapePyImp.cpp
+++ b/src/Mod/Part/App/TopoShapePyImp.cpp
@@ -74,6 +74,7 @@
#include
#include
#include
+#include
#include
#include "TopoShape.h"
@@ -286,21 +287,32 @@ PyObject* TopoShapePy::read(PyObject *args)
Py_Return;
}
-PyObject* TopoShapePy::writeInventor(PyObject * args)
+PyObject* TopoShapePy::writeInventor(PyObject * args, PyObject * keywds)
{
+ static char *kwlist[] = {"Mode", "Deviation", "Angle", "FaceColors", NULL};
+
double dev=0.3, angle=0.4;
int mode=2;
- if (!PyArg_ParseTuple(args, "|idd", &mode,&dev,&angle))
+ PyObject* pylist=nullptr;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "|iddO", kwlist,
+ &mode,&dev,&angle,&pylist))
return NULL;
+ std::vector faceColors;
+ if (pylist) {
+ App::PropertyColorList prop;
+ prop.setPyObject(pylist);
+ faceColors = prop.getValues();
+ }
+
std::stringstream result;
BRepMesh_IncrementalMesh(getTopoShapePtr()->getShape(),dev);
if (mode == 0)
- getTopoShapePtr()->exportFaceSet(dev, angle, result);
+ getTopoShapePtr()->exportFaceSet(dev, angle, faceColors, result);
else if (mode == 1)
getTopoShapePtr()->exportLineSet(result);
else {
- getTopoShapePtr()->exportFaceSet(dev, angle, result);
+ getTopoShapePtr()->exportFaceSet(dev, angle, faceColors, result);
getTopoShapePtr()->exportLineSet(result);
}
// NOTE: Cleaning the triangulation may cause problems on some algorithms like BOP