Merge branch 'master' of github.com:FreeCAD/FreeCAD
This commit is contained in:
@@ -184,7 +184,7 @@
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
#include <App/Material.h>
|
||||
|
||||
#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<App::Color>& 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();
|
||||
|
||||
@@ -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<App::Color>&, std::ostream&) const;
|
||||
void exportLineSet(std::ostream&) const;
|
||||
//@}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ Sub-elements such as vertices, edges or faces are accessible as:
|
||||
<UserDocu>Read in an IGES, STEP or BREP file.</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="writeInventor" Const="true">
|
||||
<Methode Name="writeInventor" Const="true" Keyword="true">
|
||||
<Documentation>
|
||||
<UserDocu>Write the mesh in OpenInventor format to a string.</UserDocu>
|
||||
</Documentation>
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
#include <Base/MatrixPy.h>
|
||||
#include <Base/Vector3D.h>
|
||||
#include <Base/VectorPy.h>
|
||||
#include <App/PropertyStandard.h>
|
||||
#include <CXX/Extensions.hxx>
|
||||
|
||||
#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<App::Color> 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
|
||||
|
||||
Reference in New Issue
Block a user