diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index 17f7af8a5..dda001601 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -834,6 +834,26 @@ Base::Vector3d MeshObject::getPointNormal(unsigned long index) const return normal; } +std::vector MeshObject::getPointNormals() const +{ + std::vector temp = _kernel.CalcVertexNormals(); + + std::vector normals; + normals.reserve(temp.size()); + for (std::vector::iterator it = temp.begin(); it != temp.end(); ++it) { + Base::Vector3d normal = transformToOutside(*it); + // the normal is a vector, hence we must not apply the translation part + // of the transformation to the vector + normal.x -= _Mtrx[0][3]; + normal.y -= _Mtrx[1][3]; + normal.z -= _Mtrx[2][3]; + normal.Normalize(); + normals.push_back(normal); + } + + return normals; +} + void MeshObject::crossSections(const std::vector& planes, std::vector §ions, float fMinEps, bool bConnectPolygons) const { diff --git a/src/Mod/Mesh/App/Mesh.h b/src/Mod/Mesh/App/Mesh.h index d55d56711..74d224382 100644 --- a/src/Mod/Mesh/App/Mesh.h +++ b/src/Mod/Mesh/App/Mesh.h @@ -205,6 +205,7 @@ public: void setPoint(unsigned long, const Base::Vector3d& v); void smooth(int iterations, float d_max); Base::Vector3d getPointNormal(unsigned long) const; + std::vector getPointNormals() const; void crossSections(const std::vector&, std::vector §ions, float fMinEps = 1.0e-2f, bool bConnectPolygons = false) const; void cut(const Base::Polygon2D& polygon, const Base::ViewProjMethod& proj, CutType); diff --git a/src/Mod/Mesh/App/MeshPy.xml b/src/Mod/Mesh/App/MeshPy.xml index fd9949777..05d483f3e 100644 --- a/src/Mod/Mesh/App/MeshPy.xml +++ b/src/Mod/Mesh/App/MeshPy.xml @@ -155,6 +155,14 @@ Example: + + + + getPointNormals() + Get the normals of the points. + + + Get the number of segments which may also be 0 diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index 85ca92a02..f46eb00db 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -685,6 +685,22 @@ PyObject* MeshPy::setPoint(PyObject *args) Py_Return; } +PyObject* MeshPy::getPointNormals(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + PY_TRY { + std::vector normals = getMeshObjectPtr()->getPointNormals(); + Py::Tuple ary(normals.size()); + std::size_t numNormals = normals.size(); + for (std::size_t i=0; i