Mesh: Mesh.createBox() now accepts a bounding box as argument
This commit is contained in:
@@ -308,19 +308,32 @@ private:
|
||||
}
|
||||
Py::Object createBox(const Py::Tuple& args)
|
||||
{
|
||||
float length = 10.0f;
|
||||
float width = 10.0f;
|
||||
float height = 10.0f;
|
||||
float edgelen = -1.0f;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "|ffff",&length,&width,&height,&edgelen))
|
||||
throw Py::Exception();
|
||||
MeshObject* mesh = nullptr;
|
||||
|
||||
MeshObject* mesh;
|
||||
if (edgelen < 0.0f)
|
||||
mesh = MeshObject::createCube(length, width, height);
|
||||
else
|
||||
mesh = MeshObject::createCube(length, width, height, edgelen);
|
||||
do {
|
||||
float length = 10.0f;
|
||||
float width = 10.0f;
|
||||
float height = 10.0f;
|
||||
float edgelen = -1.0f;
|
||||
if (PyArg_ParseTuple(args.ptr(), "|ffff",&length,&width,&height,&edgelen)) {
|
||||
if (edgelen < 0.0f)
|
||||
mesh = MeshObject::createCube(length, width, height);
|
||||
else
|
||||
mesh = MeshObject::createCube(length, width, height, edgelen);
|
||||
break;
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
PyObject* box;
|
||||
if (PyArg_ParseTuple(args.ptr(), "O!",&Base::BoundBoxPy::Type, &box)) {
|
||||
Py::BoundingBox bbox(box, false);
|
||||
mesh = MeshObject::createCube(bbox.getValue());
|
||||
break;
|
||||
}
|
||||
|
||||
throw Py::TypeError("Must be real numbers or BoundBox");
|
||||
}
|
||||
while (false);
|
||||
if (!mesh) {
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError, "Creation of box failed");
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <CXX/Objects.hxx>
|
||||
#include <Base/Builder3D.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Converter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Writer.h>
|
||||
#include <Base/Reader.h>
|
||||
@@ -1833,6 +1834,37 @@ MeshObject* MeshObject::createCube(float length, float width, float height, floa
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MeshObject* MeshObject::createCube(const Base::BoundBox3d& bbox)
|
||||
{
|
||||
std::vector<MeshCore::MeshGeomFacet> facets;
|
||||
auto createFacet = [&bbox](int i, int j, int k) {
|
||||
MeshCore::MeshGeomFacet facet;
|
||||
facet._aclPoints[0] = Base::convertTo<Base::Vector3f>(bbox.CalcPoint(i));
|
||||
facet._aclPoints[1] = Base::convertTo<Base::Vector3f>(bbox.CalcPoint(j));
|
||||
facet._aclPoints[2] = Base::convertTo<Base::Vector3f>(bbox.CalcPoint(k));
|
||||
facet.CalcNormal();
|
||||
return facet;
|
||||
};
|
||||
|
||||
facets.push_back(createFacet(0, 1, 2));
|
||||
facets.push_back(createFacet(0, 2, 3));
|
||||
facets.push_back(createFacet(0, 5, 1));
|
||||
facets.push_back(createFacet(0, 4, 5));
|
||||
facets.push_back(createFacet(0, 3, 7));
|
||||
facets.push_back(createFacet(0, 7, 4));
|
||||
facets.push_back(createFacet(4, 6, 5));
|
||||
facets.push_back(createFacet(4, 7, 6));
|
||||
facets.push_back(createFacet(1, 6, 2));
|
||||
facets.push_back(createFacet(1, 5, 6));
|
||||
facets.push_back(createFacet(2, 7, 3));
|
||||
facets.push_back(createFacet(2, 6, 7));
|
||||
|
||||
Base::EmptySequencer seq;
|
||||
std::unique_ptr<MeshObject> mesh(new MeshObject);
|
||||
mesh->getKernel() = facets;
|
||||
return mesh.release();
|
||||
}
|
||||
|
||||
void MeshObject::addSegment(const Segment& s)
|
||||
{
|
||||
addSegment(s.getIndices());
|
||||
|
||||
@@ -338,6 +338,7 @@ public:
|
||||
static MeshObject* createTorus(float, float, int);
|
||||
static MeshObject* createCube(float, float, float);
|
||||
static MeshObject* createCube(float, float, float, float);
|
||||
static MeshObject* createCube(const Base::BoundBox3d&);
|
||||
//@}
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user