CAM: apply precommit
This commit is contained in:
@@ -29,16 +29,19 @@
|
||||
#include "PathSimPy.h"
|
||||
|
||||
|
||||
namespace PathSimulator {
|
||||
class Module : public Py::ExtensionModule<Module>
|
||||
namespace PathSimulator
|
||||
{
|
||||
class Module: public Py::ExtensionModule<Module>
|
||||
{
|
||||
public:
|
||||
Module() : Py::ExtensionModule<Module>("PathSimulator")
|
||||
Module()
|
||||
: Py::ExtensionModule<Module>("PathSimulator")
|
||||
{
|
||||
initialize("This module is the PathSimulator module."); // register with Python
|
||||
initialize("This module is the PathSimulator module."); // register with Python
|
||||
}
|
||||
|
||||
~Module() override {}
|
||||
~Module() override
|
||||
{}
|
||||
|
||||
private:
|
||||
};
|
||||
@@ -49,34 +52,34 @@ PyObject* initModule()
|
||||
}
|
||||
|
||||
|
||||
} // namespace PathSimulator
|
||||
} // namespace PathSimulator
|
||||
|
||||
|
||||
/* Python entry */
|
||||
PyMOD_INIT_FUNC(PathSimulator)
|
||||
{
|
||||
// load dependent module
|
||||
try {
|
||||
Base::Interpreter().runString("import Part");
|
||||
Base::Interpreter().runString("import Path");
|
||||
Base::Interpreter().runString("import Mesh");
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_SetString(PyExc_ImportError, e.what());
|
||||
PyMOD_Return(nullptr);
|
||||
}
|
||||
// load dependent module
|
||||
try {
|
||||
Base::Interpreter().runString("import Part");
|
||||
Base::Interpreter().runString("import Path");
|
||||
Base::Interpreter().runString("import Mesh");
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_SetString(PyExc_ImportError, e.what());
|
||||
PyMOD_Return(nullptr);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
PyObject* mod = PathSimulator::initModule();
|
||||
Base::Console().Log("Loading PathSimulator module.... done\n");
|
||||
|
||||
// Add Types to module
|
||||
Base::Interpreter().addType(&PathSimulator::PathSimPy::Type, mod, "PathSim");
|
||||
// Add Types to module
|
||||
Base::Interpreter().addType(&PathSimulator::PathSimPy::Type, mod, "PathSim");
|
||||
|
||||
// NOTE: To finish the initialization of our own type objects we must
|
||||
// call PyType_Ready, otherwise we run into a segmentation fault, later on.
|
||||
// This function is responsible for adding inherited slots from a type's base class.
|
||||
PathSimulator::PathSim::init();
|
||||
// NOTE: To finish the initialization of our own type objects we must
|
||||
// call PyType_Ready, otherwise we run into a segmentation fault, later on.
|
||||
// This function is responsible for adding inherited slots from a type's base class.
|
||||
PathSimulator::PathSim::init();
|
||||
|
||||
PyMOD_Return(mod);
|
||||
PyMOD_Return(mod);
|
||||
}
|
||||
|
||||
@@ -28,60 +28,54 @@
|
||||
using namespace Base;
|
||||
using namespace PathSimulator;
|
||||
|
||||
TYPESYSTEM_SOURCE(PathSimulator::PathSim , Base::BaseClass);
|
||||
TYPESYSTEM_SOURCE(PathSimulator::PathSim, Base::BaseClass);
|
||||
|
||||
PathSim::PathSim()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
PathSim::~PathSim()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
void PathSim::BeginSimulation(Part::TopoShape * stock, float resolution)
|
||||
void PathSim::BeginSimulation(Part::TopoShape* stock, float resolution)
|
||||
{
|
||||
Base::BoundBox3d bbox = stock->getBoundBox();
|
||||
m_stock = std::make_unique<cStock>(bbox.MinX, bbox.MinY, bbox.MinZ, bbox.LengthX(), bbox.LengthY(), bbox.LengthZ(), resolution);
|
||||
Base::BoundBox3d bbox = stock->getBoundBox();
|
||||
m_stock = std::make_unique<cStock>(bbox.MinX,
|
||||
bbox.MinY,
|
||||
bbox.MinZ,
|
||||
bbox.LengthX(),
|
||||
bbox.LengthY(),
|
||||
bbox.LengthZ(),
|
||||
resolution);
|
||||
}
|
||||
|
||||
void PathSim::SetToolShape(const TopoDS_Shape& toolShape, float resolution)
|
||||
{
|
||||
m_tool = std::make_unique<cSimTool>(toolShape, resolution);
|
||||
m_tool = std::make_unique<cSimTool>(toolShape, resolution);
|
||||
}
|
||||
|
||||
Base::Placement * PathSim::ApplyCommand(Base::Placement * pos, Command * cmd)
|
||||
Base::Placement* PathSim::ApplyCommand(Base::Placement* pos, Command* cmd)
|
||||
{
|
||||
Point3D fromPos(*pos);
|
||||
Point3D toPos(*pos);
|
||||
toPos.UpdateCmd(*cmd);
|
||||
if (m_tool)
|
||||
{
|
||||
if (cmd->Name == "G0" || cmd->Name == "G1")
|
||||
{
|
||||
m_stock->ApplyLinearTool(fromPos, toPos, *m_tool);
|
||||
}
|
||||
else if (cmd->Name == "G2")
|
||||
{
|
||||
Vector3d vcent = cmd->getCenter();
|
||||
Point3D cent(vcent);
|
||||
m_stock->ApplyCircularTool(fromPos, toPos, cent, *m_tool, false);
|
||||
}
|
||||
else if (cmd->Name == "G3")
|
||||
{
|
||||
Vector3d vcent = cmd->getCenter();
|
||||
Point3D cent(vcent);
|
||||
m_stock->ApplyCircularTool(fromPos, toPos, cent, *m_tool, true);
|
||||
}
|
||||
}
|
||||
Point3D fromPos(*pos);
|
||||
Point3D toPos(*pos);
|
||||
toPos.UpdateCmd(*cmd);
|
||||
if (m_tool) {
|
||||
if (cmd->Name == "G0" || cmd->Name == "G1") {
|
||||
m_stock->ApplyLinearTool(fromPos, toPos, *m_tool);
|
||||
}
|
||||
else if (cmd->Name == "G2") {
|
||||
Vector3d vcent = cmd->getCenter();
|
||||
Point3D cent(vcent);
|
||||
m_stock->ApplyCircularTool(fromPos, toPos, cent, *m_tool, false);
|
||||
}
|
||||
else if (cmd->Name == "G3") {
|
||||
Vector3d vcent = cmd->getCenter();
|
||||
Point3D cent(vcent);
|
||||
m_stock->ApplyCircularTool(fromPos, toPos, cent, *m_tool, true);
|
||||
}
|
||||
}
|
||||
|
||||
Base::Placement *plc = new Base::Placement();
|
||||
Vector3d vec(toPos.x, toPos.y, toPos.z);
|
||||
plc->setPosition(vec);
|
||||
return plc;
|
||||
Base::Placement* plc = new Base::Placement();
|
||||
Vector3d vec(toPos.x, toPos.y, toPos.z);
|
||||
plc->setPosition(vec);
|
||||
return plc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -38,26 +38,26 @@ using namespace Path;
|
||||
namespace PathSimulator
|
||||
{
|
||||
|
||||
/** The representation of a CNC Toolpath Simulator */
|
||||
/** The representation of a CNC Toolpath Simulator */
|
||||
|
||||
class PathSimulatorExport PathSim : public Base::BaseClass
|
||||
{
|
||||
TYPESYSTEM_HEADER();
|
||||
class PathSimulatorExport PathSim: public Base::BaseClass
|
||||
{
|
||||
TYPESYSTEM_HEADER();
|
||||
|
||||
public:
|
||||
PathSim();
|
||||
~PathSim();
|
||||
public:
|
||||
PathSim();
|
||||
~PathSim();
|
||||
|
||||
void BeginSimulation(Part::TopoShape * stock, float resolution);
|
||||
void SetToolShape(const TopoDS_Shape& toolShape, float resolution);
|
||||
Base::Placement * ApplyCommand(Base::Placement * pos, Command * cmd);
|
||||
void BeginSimulation(Part::TopoShape* stock, float resolution);
|
||||
void SetToolShape(const TopoDS_Shape& toolShape, float resolution);
|
||||
Base::Placement* ApplyCommand(Base::Placement* pos, Command* cmd);
|
||||
|
||||
public:
|
||||
std::unique_ptr<cStock> m_stock;
|
||||
std::unique_ptr<cSimTool> m_tool;
|
||||
};
|
||||
public:
|
||||
std::unique_ptr<cStock> m_stock;
|
||||
std::unique_ptr<cSimTool> m_tool;
|
||||
};
|
||||
|
||||
} //namespace Path
|
||||
} // namespace PathSimulator
|
||||
|
||||
|
||||
#endif // PATHSIMULATOR_PathSim_H
|
||||
#endif // PATHSIMULATOR_PathSim_H
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
/**************************************************************************
|
||||
* Copyright (c) 2017 Shai Seger <shaise at gmail> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
* Copyright (c) 2017 Shai Seger <shaise at gmail> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
@@ -43,7 +43,7 @@ std::string PathSimPy::representation() const
|
||||
return std::string("<PathSim object>");
|
||||
}
|
||||
|
||||
PyObject *PathSimPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
PyObject* PathSimPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper
|
||||
{
|
||||
// create a new instance of PathSimPy and the Twin object
|
||||
return new PathSimPy(new PathSim);
|
||||
@@ -56,82 +56,97 @@ int PathSimPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
|
||||
}
|
||||
|
||||
|
||||
PyObject* PathSimPy::BeginSimulation(PyObject * args, PyObject * kwds)
|
||||
PyObject* PathSimPy::BeginSimulation(PyObject* args, PyObject* kwds)
|
||||
{
|
||||
static const std::array<const char *, 3> kwlist { "stock", "resolution", nullptr };
|
||||
PyObject *pObjStock;
|
||||
float resolution;
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!f", kwlist, &(Part::TopoShapePy::Type), &pObjStock, &resolution))
|
||||
return nullptr;
|
||||
PathSim *sim = getPathSimPtr();
|
||||
Part::TopoShape *stock = static_cast<Part::TopoShapePy*>(pObjStock)->getTopoShapePtr();
|
||||
sim->BeginSimulation(stock, resolution);
|
||||
Py_IncRef(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject* PathSimPy::SetToolShape(PyObject * args)
|
||||
{
|
||||
PyObject *pObjToolShape;
|
||||
float resolution;
|
||||
if (!PyArg_ParseTuple(args, "O!f", &(Part::TopoShapePy::Type), &pObjToolShape, &resolution))
|
||||
return nullptr;
|
||||
PathSim *sim = getPathSimPtr();
|
||||
const TopoDS_Shape& toolShape = static_cast<Part::TopoShapePy*>(pObjToolShape)->getTopoShapePtr()->getShape();
|
||||
sim->SetToolShape(toolShape, resolution);
|
||||
Py_IncRef(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject* PathSimPy::GetResultMesh(PyObject * args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
cStock *stock = getPathSimPtr()->m_stock.get();
|
||||
if (!stock)
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, "Simulation has stock object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Mesh::MeshObject *meshOuter = new Mesh::MeshObject();
|
||||
Mesh::MeshPy *meshOuterpy = new Mesh::MeshPy(meshOuter);
|
||||
Mesh::MeshObject *meshInner = new Mesh::MeshObject();
|
||||
Mesh::MeshPy *meshInnerpy = new Mesh::MeshPy(meshInner);
|
||||
stock->Tessellate(*meshOuter, *meshInner);
|
||||
PyObject *tuple = PyTuple_New(2);
|
||||
PyTuple_SetItem(tuple, 0, meshOuterpy);
|
||||
PyTuple_SetItem(tuple, 1, meshInnerpy);
|
||||
return tuple;
|
||||
}
|
||||
|
||||
|
||||
PyObject* PathSimPy::ApplyCommand(PyObject * args, PyObject * kwds)
|
||||
{
|
||||
static const std::array<const char *, 3> kwlist { "position", "command", nullptr };
|
||||
PyObject *pObjPlace;
|
||||
PyObject *pObjCmd;
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!O!", kwlist, &(Base::PlacementPy::Type), &pObjPlace,
|
||||
&(Path::CommandPy::Type), &pObjCmd)) {
|
||||
static const std::array<const char*, 3> kwlist {"stock", "resolution", nullptr};
|
||||
PyObject* pObjStock;
|
||||
float resolution;
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args,
|
||||
kwds,
|
||||
"O!f",
|
||||
kwlist,
|
||||
&(Part::TopoShapePy::Type),
|
||||
&pObjStock,
|
||||
&resolution)) {
|
||||
return nullptr;
|
||||
}
|
||||
PathSim *sim = getPathSimPtr();
|
||||
Base::Placement *pos = static_cast<Base::PlacementPy*>(pObjPlace)->getPlacementPtr();
|
||||
Path::Command *cmd = static_cast<Path::CommandPy*>(pObjCmd)->getCommandPtr();
|
||||
Base::Placement *newpos = sim->ApplyCommand(pos, cmd);
|
||||
//Base::Console().Log("Done...\n");
|
||||
//Base::Console().Refresh();
|
||||
Base::PlacementPy *newposPy = new Base::PlacementPy(newpos);
|
||||
return newposPy;
|
||||
PathSim* sim = getPathSimPtr();
|
||||
Part::TopoShape* stock = static_cast<Part::TopoShapePy*>(pObjStock)->getTopoShapePtr();
|
||||
sim->BeginSimulation(stock, resolution);
|
||||
Py_IncRef(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject* PathSimPy::SetToolShape(PyObject* args)
|
||||
{
|
||||
PyObject* pObjToolShape;
|
||||
float resolution;
|
||||
if (!PyArg_ParseTuple(args, "O!f", &(Part::TopoShapePy::Type), &pObjToolShape, &resolution)) {
|
||||
return nullptr;
|
||||
}
|
||||
PathSim* sim = getPathSimPtr();
|
||||
const TopoDS_Shape& toolShape =
|
||||
static_cast<Part::TopoShapePy*>(pObjToolShape)->getTopoShapePtr()->getShape();
|
||||
sim->SetToolShape(toolShape, resolution);
|
||||
Py_IncRef(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject* PathSimPy::GetResultMesh(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
cStock* stock = getPathSimPtr()->m_stock.get();
|
||||
if (!stock) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Simulation has stock object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Mesh::MeshObject* meshOuter = new Mesh::MeshObject();
|
||||
Mesh::MeshPy* meshOuterpy = new Mesh::MeshPy(meshOuter);
|
||||
Mesh::MeshObject* meshInner = new Mesh::MeshObject();
|
||||
Mesh::MeshPy* meshInnerpy = new Mesh::MeshPy(meshInner);
|
||||
stock->Tessellate(*meshOuter, *meshInner);
|
||||
PyObject* tuple = PyTuple_New(2);
|
||||
PyTuple_SetItem(tuple, 0, meshOuterpy);
|
||||
PyTuple_SetItem(tuple, 1, meshInnerpy);
|
||||
return tuple;
|
||||
}
|
||||
|
||||
|
||||
PyObject* PathSimPy::ApplyCommand(PyObject* args, PyObject* kwds)
|
||||
{
|
||||
static const std::array<const char*, 3> kwlist {"position", "command", nullptr};
|
||||
PyObject* pObjPlace;
|
||||
PyObject* pObjCmd;
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args,
|
||||
kwds,
|
||||
"O!O!",
|
||||
kwlist,
|
||||
&(Base::PlacementPy::Type),
|
||||
&pObjPlace,
|
||||
&(Path::CommandPy::Type),
|
||||
&pObjCmd)) {
|
||||
return nullptr;
|
||||
}
|
||||
PathSim* sim = getPathSimPtr();
|
||||
Base::Placement* pos = static_cast<Base::PlacementPy*>(pObjPlace)->getPlacementPtr();
|
||||
Path::Command* cmd = static_cast<Path::CommandPy*>(pObjCmd)->getCommandPtr();
|
||||
Base::Placement* newpos = sim->ApplyCommand(pos, cmd);
|
||||
// Base::Console().Log("Done...\n");
|
||||
// Base::Console().Refresh();
|
||||
Base::PlacementPy* newposPy = new Base::PlacementPy(newpos);
|
||||
return newposPy;
|
||||
}
|
||||
|
||||
Py::Object PathSimPy::getTool() const
|
||||
{
|
||||
//return Py::Object();
|
||||
// return Py::Object();
|
||||
throw Py::AttributeError("Not yet implemented");
|
||||
}
|
||||
|
||||
PyObject *PathSimPy::getCustomAttributes(const char* /*attr*/) const
|
||||
PyObject* PathSimPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@@ -140,5 +155,3 @@ int PathSimPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
// Xerces
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
|
||||
#endif //_PreComp_
|
||||
#endif //_PreComp_
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,26 +1,26 @@
|
||||
/**************************************************************************
|
||||
* Copyright (c) 2017 Shai Seger <shaise at gmail> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************
|
||||
* Volumetric Path simulation engine *
|
||||
***************************************************************************/
|
||||
* Copyright (c) 2017 Shai Seger <shaise at gmail> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************
|
||||
* Volumetric Path simulation engine *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef PATHSIMULATOR_VolSim_H
|
||||
#define PATHSIMULATOR_VolSim_H
|
||||
@@ -32,155 +32,239 @@
|
||||
|
||||
|
||||
#define SIM_EPSILON 0.00001
|
||||
#define SIM_TESSEL_TOP 1
|
||||
#define SIM_TESSEL_BOT 2
|
||||
#define SIM_WALK_RES 0.6 // step size in pixel units (to make sure all pixels in the path are visited)
|
||||
#define SIM_TESSEL_TOP 1
|
||||
#define SIM_TESSEL_BOT 2
|
||||
#define SIM_WALK_RES \
|
||||
0.6 // step size in pixel units (to make sure all pixels in the path are visited)
|
||||
|
||||
struct toolShapePoint {
|
||||
float radiusPos;
|
||||
float heightPos;
|
||||
struct toolShapePoint
|
||||
{
|
||||
float radiusPos;
|
||||
float heightPos;
|
||||
|
||||
struct less_than{
|
||||
bool operator()(const toolShapePoint &a, const toolShapePoint &b){
|
||||
return a.radiusPos < b.radiusPos;
|
||||
}
|
||||
};
|
||||
struct less_than
|
||||
{
|
||||
bool operator()(const toolShapePoint& a, const toolShapePoint& b)
|
||||
{
|
||||
return a.radiusPos < b.radiusPos;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct Point3D
|
||||
{
|
||||
Point3D() : x(0), y(0), z(0), sina(0), cosa(0) {}
|
||||
Point3D(float x, float y, float z) : x(x), y(y), z(z), sina(0), cosa(0) {}
|
||||
explicit Point3D(Base::Vector3d & vec) : x(vec[0]), y(vec[1]), z(vec[2]), sina(0), cosa(0) {}
|
||||
explicit Point3D(Base::Placement & pl) : x(pl.getPosition()[0]), y(pl.getPosition()[1]), z(pl.getPosition()[2]), sina(0), cosa(0) {}
|
||||
inline void set(float px, float py, float pz) { x = px; y = py; z = pz; }
|
||||
inline void Add(Point3D & p) { x += p.x; y += p.y; z += p.z; }
|
||||
inline void Rotate() { float tx = x; x = x * cosa - y * sina; y = tx * sina + y * cosa; }
|
||||
void UpdateCmd(Path::Command & cmd);
|
||||
void SetRotationAngle(float angle);
|
||||
void SetRotationAngleRad(float angle);
|
||||
float x, y, z;
|
||||
float sina, cosa;
|
||||
Point3D()
|
||||
: x(0)
|
||||
, y(0)
|
||||
, z(0)
|
||||
, sina(0)
|
||||
, cosa(0)
|
||||
{}
|
||||
Point3D(float x, float y, float z)
|
||||
: x(x)
|
||||
, y(y)
|
||||
, z(z)
|
||||
, sina(0)
|
||||
, cosa(0)
|
||||
{}
|
||||
explicit Point3D(Base::Vector3d& vec)
|
||||
: x(vec[0])
|
||||
, y(vec[1])
|
||||
, z(vec[2])
|
||||
, sina(0)
|
||||
, cosa(0)
|
||||
{}
|
||||
explicit Point3D(Base::Placement& pl)
|
||||
: x(pl.getPosition()[0])
|
||||
, y(pl.getPosition()[1])
|
||||
, z(pl.getPosition()[2])
|
||||
, sina(0)
|
||||
, cosa(0)
|
||||
{}
|
||||
inline void set(float px, float py, float pz)
|
||||
{
|
||||
x = px;
|
||||
y = py;
|
||||
z = pz;
|
||||
}
|
||||
inline void Add(Point3D& p)
|
||||
{
|
||||
x += p.x;
|
||||
y += p.y;
|
||||
z += p.z;
|
||||
}
|
||||
inline void Rotate()
|
||||
{
|
||||
float tx = x;
|
||||
x = x * cosa - y * sina;
|
||||
y = tx * sina + y * cosa;
|
||||
}
|
||||
void UpdateCmd(Path::Command& cmd);
|
||||
void SetRotationAngle(float angle);
|
||||
void SetRotationAngleRad(float angle);
|
||||
float x, y, z;
|
||||
float sina, cosa;
|
||||
};
|
||||
|
||||
// some vector manipulations
|
||||
inline static Point3D operator + (const Point3D & a, const Point3D & b) { return Point3D(a.x + b.x, a.y + b.y, a.z + b.z); }
|
||||
inline static Point3D operator - (const Point3D & a, const Point3D & b) { return Point3D(a.x - b.x, a.y - b.y, a.z - b.z); }
|
||||
inline static Point3D operator * (const Point3D & a, double b) { return Point3D(a.x * b, a.y * b, a.z * b); }
|
||||
inline static Point3D operator / (const Point3D & a, double b) { return a * (1.0f / b); }
|
||||
inline static double dot(const Point3D & a, const Point3D & b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
|
||||
inline static double length(const Point3D & a) { return sqrtf(dot(a, a)); }
|
||||
inline static Point3D unit(const Point3D & a) { return a / length(a); }
|
||||
inline static Point3D operator+(const Point3D& a, const Point3D& b)
|
||||
{
|
||||
return Point3D(a.x + b.x, a.y + b.y, a.z + b.z);
|
||||
}
|
||||
inline static Point3D operator-(const Point3D& a, const Point3D& b)
|
||||
{
|
||||
return Point3D(a.x - b.x, a.y - b.y, a.z - b.z);
|
||||
}
|
||||
inline static Point3D operator*(const Point3D& a, double b)
|
||||
{
|
||||
return Point3D(a.x * b, a.y * b, a.z * b);
|
||||
}
|
||||
inline static Point3D operator/(const Point3D& a, double b)
|
||||
{
|
||||
return a * (1.0f / b);
|
||||
}
|
||||
inline static double dot(const Point3D& a, const Point3D& b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||
}
|
||||
inline static double length(const Point3D& a)
|
||||
{
|
||||
return sqrtf(dot(a, a));
|
||||
}
|
||||
inline static Point3D unit(const Point3D& a)
|
||||
{
|
||||
return a / length(a);
|
||||
}
|
||||
|
||||
|
||||
struct Triangle3D
|
||||
{
|
||||
Triangle3D() {}
|
||||
Triangle3D(Point3D & p1, Point3D & p2, Point3D & p3)
|
||||
{
|
||||
points[0] = p1;
|
||||
points[1] = p2;
|
||||
points[2] = p3;
|
||||
}
|
||||
Point3D points[3];
|
||||
Triangle3D()
|
||||
{}
|
||||
Triangle3D(Point3D& p1, Point3D& p2, Point3D& p3)
|
||||
{
|
||||
points[0] = p1;
|
||||
points[1] = p2;
|
||||
points[2] = p3;
|
||||
}
|
||||
Point3D points[3];
|
||||
};
|
||||
|
||||
struct cLineSegment
|
||||
{
|
||||
cLineSegment() : len(0), lenXY(0) {}
|
||||
cLineSegment(Point3D & p1, Point3D & p2) { SetPoints(p1, p2); }
|
||||
void SetPoints(Point3D & p1, Point3D & p2);
|
||||
void PointAt(float dist, Point3D & retp);
|
||||
Point3D pStart;
|
||||
Point3D pDir;
|
||||
Point3D pDirXY;
|
||||
float len;
|
||||
float lenXY;
|
||||
cLineSegment()
|
||||
: len(0)
|
||||
, lenXY(0)
|
||||
{}
|
||||
cLineSegment(Point3D& p1, Point3D& p2)
|
||||
{
|
||||
SetPoints(p1, p2);
|
||||
}
|
||||
void SetPoints(Point3D& p1, Point3D& p2);
|
||||
void PointAt(float dist, Point3D& retp);
|
||||
Point3D pStart;
|
||||
Point3D pDir;
|
||||
Point3D pDirXY;
|
||||
float len;
|
||||
float lenXY;
|
||||
};
|
||||
|
||||
class cSimTool
|
||||
{
|
||||
public:
|
||||
cSimTool(const TopoDS_Shape& toolShape, float res);
|
||||
~cSimTool() {}
|
||||
~cSimTool()
|
||||
{}
|
||||
|
||||
float GetToolProfileAt(float pos);
|
||||
bool isInside(const TopoDS_Shape& toolShape, Base::Vector3d pnt, float res);
|
||||
float GetToolProfileAt(float pos);
|
||||
bool isInside(const TopoDS_Shape& toolShape, Base::Vector3d pnt, float res);
|
||||
|
||||
/* m_toolShape has to be populated with linearly increased
|
||||
radiusPos to get the tool profile at given position */
|
||||
std::vector <toolShapePoint> m_toolShape;
|
||||
/* m_toolShape has to be populated with linearly increased
|
||||
radiusPos to get the tool profile at given position */
|
||||
std::vector<toolShapePoint> m_toolShape;
|
||||
float radius;
|
||||
float length;
|
||||
float length;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
template<class T>
|
||||
class Array2D
|
||||
{
|
||||
public:
|
||||
Array2D() : data(nullptr), height(0) {}
|
||||
Array2D()
|
||||
: data(nullptr)
|
||||
, height(0)
|
||||
{}
|
||||
|
||||
~Array2D()
|
||||
{
|
||||
if (data)
|
||||
delete[] data;
|
||||
}
|
||||
~Array2D()
|
||||
{
|
||||
if (data) {
|
||||
delete[] data;
|
||||
}
|
||||
}
|
||||
|
||||
void Init(int x, int y)
|
||||
{
|
||||
data = new T[x * y];
|
||||
height = y;
|
||||
}
|
||||
void Init(int x, int y)
|
||||
{
|
||||
data = new T[x * y];
|
||||
height = y;
|
||||
}
|
||||
|
||||
T *operator [] (int i) { return data + i * height; }
|
||||
T* operator[](int i)
|
||||
{
|
||||
return data + i * height;
|
||||
}
|
||||
|
||||
private:
|
||||
T *data;
|
||||
int height;
|
||||
T* data;
|
||||
int height;
|
||||
};
|
||||
|
||||
class cStock
|
||||
{
|
||||
public:
|
||||
cStock(float px, float py, float pz, float lx, float ly, float lz, float res);
|
||||
~cStock();
|
||||
void Tessellate(Mesh::MeshObject & meshOuter, Mesh::MeshObject & meshInner);
|
||||
cStock(float px, float py, float pz, float lx, float ly, float lz, float res);
|
||||
~cStock();
|
||||
void Tessellate(Mesh::MeshObject& meshOuter, Mesh::MeshObject& meshInner);
|
||||
void CreatePocket(float x, float y, float rad, float height);
|
||||
void ApplyLinearTool(Point3D & p1, Point3D & p2, cSimTool &tool);
|
||||
void ApplyCircularTool(Point3D & p1, Point3D & p2, Point3D & cent, cSimTool &tool, bool isCCW);
|
||||
inline Point3D ToInner(Point3D & p) {
|
||||
return Point3D((p.x - m_px) / m_res, (p.y - m_py) / m_res, p.z);
|
||||
}
|
||||
void ApplyLinearTool(Point3D& p1, Point3D& p2, cSimTool& tool);
|
||||
void ApplyCircularTool(Point3D& p1, Point3D& p2, Point3D& cent, cSimTool& tool, bool isCCW);
|
||||
inline Point3D ToInner(Point3D& p)
|
||||
{
|
||||
return Point3D((p.x - m_px) / m_res, (p.y - m_py) / m_res, p.z);
|
||||
}
|
||||
|
||||
private:
|
||||
float FindRectTop(int & xp, int & yp, int & x_size, int & y_size, bool scanHoriz);
|
||||
void FindRectBot(int & xp, int & yp, int & x_size, int & y_size, bool scanHoriz);
|
||||
void SetFacetPoints(MeshCore::MeshGeomFacet & facet, Point3D & p1, Point3D & p2, Point3D & p3);
|
||||
void AddQuad(Point3D & p1, Point3D & p2, Point3D & p3, Point3D & p4, std::vector<MeshCore::MeshGeomFacet> & facets);
|
||||
int TesselTop(int x, int y);
|
||||
int TesselBot(int x, int y);
|
||||
int TesselSidesX(int yp);
|
||||
int TesselSidesY(int xp);
|
||||
Array2D<float> m_stock;
|
||||
Array2D<char> m_attr;
|
||||
float m_px, m_py, m_pz; // stock zero position
|
||||
float m_lx, m_ly, m_lz; // stock dimensions
|
||||
float m_res; // resoulution
|
||||
float m_plane; // stock plane height
|
||||
int m_x, m_y; // stock array size
|
||||
std::vector<MeshCore::MeshGeomFacet> facetsOuter;
|
||||
std::vector<MeshCore::MeshGeomFacet> facetsInner;
|
||||
float FindRectTop(int& xp, int& yp, int& x_size, int& y_size, bool scanHoriz);
|
||||
void FindRectBot(int& xp, int& yp, int& x_size, int& y_size, bool scanHoriz);
|
||||
void SetFacetPoints(MeshCore::MeshGeomFacet& facet, Point3D& p1, Point3D& p2, Point3D& p3);
|
||||
void AddQuad(Point3D& p1,
|
||||
Point3D& p2,
|
||||
Point3D& p3,
|
||||
Point3D& p4,
|
||||
std::vector<MeshCore::MeshGeomFacet>& facets);
|
||||
int TesselTop(int x, int y);
|
||||
int TesselBot(int x, int y);
|
||||
int TesselSidesX(int yp);
|
||||
int TesselSidesY(int xp);
|
||||
Array2D<float> m_stock;
|
||||
Array2D<char> m_attr;
|
||||
float m_px, m_py, m_pz; // stock zero position
|
||||
float m_lx, m_ly, m_lz; // stock dimensions
|
||||
float m_res; // resoulution
|
||||
float m_plane; // stock plane height
|
||||
int m_x, m_y; // stock array size
|
||||
std::vector<MeshCore::MeshGeomFacet> facetsOuter;
|
||||
std::vector<MeshCore::MeshGeomFacet> facetsInner;
|
||||
};
|
||||
|
||||
class cVolSim
|
||||
{
|
||||
public:
|
||||
cVolSim();
|
||||
~cVolSim();
|
||||
void CreateStock();
|
||||
cVolSim();
|
||||
~cVolSim();
|
||||
void CreateStock();
|
||||
|
||||
private:
|
||||
cStock *stock;
|
||||
cStock* stock;
|
||||
};
|
||||
|
||||
#endif // PATHSIMULATOR_VolSim_H
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include <Mod/Part/App/BRepMesh.h>
|
||||
|
||||
|
||||
|
||||
using namespace Base;
|
||||
using namespace CAMSimulator;
|
||||
|
||||
@@ -47,7 +46,7 @@ void CAMSimulator::CAMSim::resetSimulation()
|
||||
DlgCAMSimulator::GetInstance()->resetSimulation();
|
||||
}
|
||||
|
||||
void CAMSim::addTool(const std::vector<float> &toolProfilePoints,
|
||||
void CAMSim::addTool(const std::vector<float>& toolProfilePoints,
|
||||
int toolNumber,
|
||||
float diameter,
|
||||
float resolution)
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
|
||||
void BeginSimulation(const Part::TopoShape& stock, float resolution);
|
||||
void resetSimulation();
|
||||
void addTool(const std::vector<float> &toolProfilePoints,
|
||||
void addTool(const std::vector<float>& toolProfilePoints,
|
||||
int toolNumber,
|
||||
float diameter,
|
||||
float resolution);
|
||||
|
||||
@@ -68,8 +68,13 @@ PyObject* CAMSimPy::BeginSimulation(PyObject* args, PyObject* kwds)
|
||||
static const std::array<const char*, 3> kwlist {"stock", "resolution", nullptr};
|
||||
PyObject* pObjStock;
|
||||
float resolution;
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds,"O!f",
|
||||
kwlist, &(Part::TopoShapePy::Type), &pObjStock, &resolution)) {
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args,
|
||||
kwds,
|
||||
"O!f",
|
||||
kwlist,
|
||||
&(Part::TopoShapePy::Type),
|
||||
&pObjStock,
|
||||
&resolution)) {
|
||||
return nullptr;
|
||||
}
|
||||
CAMSim* sim = getCAMSimPtr();
|
||||
@@ -81,14 +86,23 @@ PyObject* CAMSimPy::BeginSimulation(PyObject* args, PyObject* kwds)
|
||||
|
||||
PyObject* CAMSimPy::AddTool(PyObject* args, PyObject* kwds)
|
||||
{
|
||||
static const std::array<const char*, 5> kwlist {
|
||||
"shape", "toolnumber", "diameter", "resolution", nullptr};
|
||||
static const std::array<const char*, 5> kwlist {"shape",
|
||||
"toolnumber",
|
||||
"diameter",
|
||||
"resolution",
|
||||
nullptr};
|
||||
PyObject* pObjToolShape;
|
||||
int toolNumber;
|
||||
float resolution;
|
||||
float diameter;
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "Oiff", kwlist, &pObjToolShape,
|
||||
&toolNumber, &diameter, &resolution)) {
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args,
|
||||
kwds,
|
||||
"Oiff",
|
||||
kwlist,
|
||||
&pObjToolShape,
|
||||
&toolNumber,
|
||||
&diameter,
|
||||
&resolution)) {
|
||||
return nullptr;
|
||||
}
|
||||
// The tool shape is defined by a list of 2d points that represents the tool revolving profile
|
||||
@@ -111,8 +125,13 @@ PyObject* CAMSimPy::SetBaseShape(PyObject* args, PyObject* kwds)
|
||||
static const std::array<const char*, 3> kwlist {"shape", "resolution", nullptr};
|
||||
PyObject* pObjBaseShape;
|
||||
float resolution;
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds,"O!f",
|
||||
kwlist, &(Part::TopoShapePy::Type), &pObjBaseShape, &resolution)) {
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args,
|
||||
kwds,
|
||||
"O!f",
|
||||
kwlist,
|
||||
&(Part::TopoShapePy::Type),
|
||||
&pObjBaseShape,
|
||||
&resolution)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!PyArg_ParseTuple(args, "O!f", &(Part::TopoShapePy::Type), &pObjBaseShape, &resolution)) {
|
||||
|
||||
@@ -39,24 +39,29 @@ namespace CAMSimulator
|
||||
static const float MouseScrollDelta = 120.0f;
|
||||
|
||||
DlgCAMSimulator::DlgCAMSimulator(QWindow* parent)
|
||||
: QWindow(parent) {
|
||||
: QWindow(parent)
|
||||
{
|
||||
setSurfaceType(QWindow::OpenGLSurface);
|
||||
mMillSimulator = new MillSimulation();
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::render(QPainter* painter) {
|
||||
void DlgCAMSimulator::render(QPainter* painter)
|
||||
{
|
||||
Q_UNUSED(painter);
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::render() {
|
||||
void DlgCAMSimulator::render()
|
||||
{
|
||||
mMillSimulator->ProcessSim((unsigned int)(QDateTime::currentMSecsSinceEpoch()));
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::renderLater() {
|
||||
void DlgCAMSimulator::renderLater()
|
||||
{
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
bool DlgCAMSimulator::event(QEvent* event) {
|
||||
bool DlgCAMSimulator::event(QEvent* event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::UpdateRequest:
|
||||
renderNow();
|
||||
@@ -67,7 +72,8 @@ bool DlgCAMSimulator::event(QEvent* event) {
|
||||
return QWindow::event(event);
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::exposeEvent(QExposeEvent* event) {
|
||||
void DlgCAMSimulator::exposeEvent(QExposeEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
if (isExposed()) {
|
||||
@@ -75,36 +81,42 @@ void DlgCAMSimulator::exposeEvent(QExposeEvent* event) {
|
||||
}
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::mouseMoveEvent(QMouseEvent* ev) {
|
||||
void DlgCAMSimulator::mouseMoveEvent(QMouseEvent* ev)
|
||||
{
|
||||
int modifiers = (ev->modifiers() & Qt::ShiftModifier) != 0 ? MS_KBD_SHIFT : 0;
|
||||
modifiers |= (ev->modifiers() & Qt::ControlModifier) != 0 ? MS_KBD_CONTROL : 0;
|
||||
modifiers |= (ev->modifiers() & Qt::AltModifier) != 0 ? MS_KBD_ALT : 0;
|
||||
mMillSimulator->MouseMove(ev->x(), ev->y(), modifiers);
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::mousePressEvent(QMouseEvent* ev) {
|
||||
void DlgCAMSimulator::mousePressEvent(QMouseEvent* ev)
|
||||
{
|
||||
mMillSimulator->MousePress(ev->button(), true, ev->x(), ev->y());
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::mouseReleaseEvent(QMouseEvent* ev) {
|
||||
void DlgCAMSimulator::mouseReleaseEvent(QMouseEvent* ev)
|
||||
{
|
||||
mMillSimulator->MousePress(ev->button(), false, ev->x(), ev->y());
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::wheelEvent(QWheelEvent* ev) {
|
||||
void DlgCAMSimulator::wheelEvent(QWheelEvent* ev)
|
||||
{
|
||||
mMillSimulator->MouseScroll((float)ev->angleDelta().y() / MouseScrollDelta);
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::resetSimulation() {
|
||||
}
|
||||
void DlgCAMSimulator::resetSimulation()
|
||||
{}
|
||||
|
||||
void DlgCAMSimulator::addGcodeCommand(const char* cmd) {
|
||||
void DlgCAMSimulator::addGcodeCommand(const char* cmd)
|
||||
{
|
||||
mMillSimulator->AddGcodeLine(cmd);
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::addTool(const std::vector<float>& toolProfilePoints,
|
||||
int toolNumber,
|
||||
float diameter,
|
||||
float resolution) {
|
||||
float resolution)
|
||||
{
|
||||
Q_UNUSED(resolution)
|
||||
std::string toolCmd = "T" + std::to_string(toolNumber);
|
||||
mMillSimulator->AddGcodeLine(toolCmd.c_str());
|
||||
@@ -113,7 +125,8 @@ void DlgCAMSimulator::addTool(const std::vector<float>& toolProfilePoints,
|
||||
}
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::hideEvent(QHideEvent* ev) {
|
||||
void DlgCAMSimulator::hideEvent(QHideEvent* ev)
|
||||
{
|
||||
mMillSimulator->Clear();
|
||||
doGlCleanup();
|
||||
mAnimating = false;
|
||||
@@ -122,7 +135,8 @@ void DlgCAMSimulator::hideEvent(QHideEvent* ev) {
|
||||
mInstance = nullptr;
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::resizeEvent(QResizeEvent* event) {
|
||||
void DlgCAMSimulator::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
if (!mContext) {
|
||||
return;
|
||||
}
|
||||
@@ -139,7 +153,8 @@ void DlgCAMSimulator::resizeEvent(QResizeEvent* event) {
|
||||
void DlgCAMSimulator::GetMeshData(const Part::TopoShape& tshape,
|
||||
float resolution,
|
||||
std::vector<Vertex>& verts,
|
||||
std::vector<GLushort>& indices) {
|
||||
std::vector<GLushort>& indices)
|
||||
{
|
||||
std::vector<int> normalCount;
|
||||
int nVerts = 0;
|
||||
for (auto& shape : tshape.getSubTopoShapes(TopAbs_FACE)) {
|
||||
@@ -183,7 +198,8 @@ void DlgCAMSimulator::GetMeshData(const Part::TopoShape& tshape,
|
||||
}
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::startSimulation(const Part::TopoShape& stock, float quality) {
|
||||
void DlgCAMSimulator::startSimulation(const Part::TopoShape& stock, float quality)
|
||||
{
|
||||
mQuality = quality;
|
||||
mNeedsInitialize = true;
|
||||
show();
|
||||
@@ -192,7 +208,8 @@ void DlgCAMSimulator::startSimulation(const Part::TopoShape& stock, float qualit
|
||||
setAnimating(true);
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::initialize() {
|
||||
void DlgCAMSimulator::initialize()
|
||||
{
|
||||
mMillSimulator->InitSimulation(mQuality);
|
||||
|
||||
const qreal retinaScale = devicePixelRatio();
|
||||
@@ -200,7 +217,8 @@ void DlgCAMSimulator::initialize() {
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::checkInitialization() {
|
||||
void DlgCAMSimulator::checkInitialization()
|
||||
{
|
||||
if (!mContext) {
|
||||
mLastContext = QOpenGLContext::currentContext();
|
||||
mContext = new QOpenGLContext(this);
|
||||
@@ -223,7 +241,8 @@ void DlgCAMSimulator::checkInitialization() {
|
||||
}
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::doGlCleanup() {
|
||||
void DlgCAMSimulator::doGlCleanup()
|
||||
{
|
||||
if (mLastContext != nullptr) {
|
||||
mLastContext->makeCurrent(this);
|
||||
}
|
||||
@@ -233,7 +252,8 @@ void DlgCAMSimulator::doGlCleanup() {
|
||||
}
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::renderNow() {
|
||||
void DlgCAMSimulator::renderNow()
|
||||
{
|
||||
static unsigned int lastTime = 0;
|
||||
static int frameCount = 0;
|
||||
static int fps = 0;
|
||||
@@ -260,7 +280,8 @@ void DlgCAMSimulator::renderNow() {
|
||||
(void)fps;
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::setAnimating(bool animating) {
|
||||
void DlgCAMSimulator::setAnimating(bool animating)
|
||||
{
|
||||
mAnimating = animating;
|
||||
|
||||
if (animating) {
|
||||
@@ -268,7 +289,8 @@ void DlgCAMSimulator::setAnimating(bool animating) {
|
||||
}
|
||||
}
|
||||
|
||||
DlgCAMSimulator* DlgCAMSimulator::GetInstance() {
|
||||
DlgCAMSimulator* DlgCAMSimulator::GetInstance()
|
||||
{
|
||||
if (mInstance == nullptr) {
|
||||
QSurfaceFormat format;
|
||||
format.setVersion(4, 1); // Request OpenGL 4.1 - for MacOS
|
||||
@@ -287,14 +309,16 @@ DlgCAMSimulator* DlgCAMSimulator::GetInstance() {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::SetStockShape(const Part::TopoShape& shape, float resolution) {
|
||||
void DlgCAMSimulator::SetStockShape(const Part::TopoShape& shape, float resolution)
|
||||
{
|
||||
std::vector<Vertex> verts;
|
||||
std::vector<GLushort> indices;
|
||||
GetMeshData(shape, resolution, verts, indices);
|
||||
mMillSimulator->SetArbitraryStock(verts, indices);
|
||||
}
|
||||
|
||||
void DlgCAMSimulator::SetBaseShape(const Part::TopoShape& tshape, float resolution) {
|
||||
void DlgCAMSimulator::SetBaseShape(const Part::TopoShape& tshape, float resolution)
|
||||
{
|
||||
std::vector<Vertex> verts;
|
||||
std::vector<GLushort> indices;
|
||||
GetMeshData(tshape, resolution, verts, indices);
|
||||
@@ -312,10 +336,12 @@ SimStock::SimStock(float px, float py, float pz, float lx, float ly, float lz, f
|
||||
, mPz(pz + 0.005 * lz)
|
||||
, mLx(lx)
|
||||
, mLy(ly)
|
||||
, mLz(1.01 * lz) {
|
||||
, mLz(1.01 * lz)
|
||||
{
|
||||
(void)res;
|
||||
}
|
||||
|
||||
SimStock::~SimStock() {}
|
||||
SimStock::~SimStock()
|
||||
{}
|
||||
|
||||
} // namespace CAMSimulator
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace MillSim
|
||||
// use short declaration as using 'include' causes a header loop
|
||||
class MillSimulation;
|
||||
struct Vertex;
|
||||
}
|
||||
} // namespace MillSim
|
||||
|
||||
namespace CAMSimulator
|
||||
{
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
void SetStockShape(const Part::TopoShape& tshape, float resolution);
|
||||
void SetBaseShape(const Part::TopoShape& tshape, float resolution);
|
||||
|
||||
public: // slots:
|
||||
public: // slots:
|
||||
void renderLater();
|
||||
void renderNow();
|
||||
void startSimulation(const Part::TopoShape& stock, float quality);
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace MillSim
|
||||
class EndMill
|
||||
{
|
||||
public:
|
||||
std::vector<float>profilePoints;
|
||||
std::vector<float> profilePoints;
|
||||
float radius;
|
||||
int nPoints = 0;
|
||||
int toolId = -1;
|
||||
|
||||
@@ -32,12 +32,12 @@
|
||||
constexpr auto EPSILON = 0.00001f;
|
||||
#define EQ_FLOAT(x, y) (fabs((x) - (y)) < EPSILON)
|
||||
|
||||
#define MS_MOUSE_LEFT 0x01
|
||||
#define MS_MOUSE_LEFT 0x01
|
||||
#define MS_MOUSE_RIGHT 0x02
|
||||
#define MS_MOUSE_MID 0x04
|
||||
#define MS_KBD_SHIFT 0x08
|
||||
#define MS_MOUSE_MID 0x04
|
||||
#define MS_KBD_SHIFT 0x08
|
||||
#define MS_KBD_CONTROL 0x10
|
||||
#define MS_KBD_ALT 0x20
|
||||
#define MS_KBD_ALT 0x20
|
||||
|
||||
#define GL(x) \
|
||||
{ \
|
||||
|
||||
@@ -28,20 +28,20 @@
|
||||
using namespace MillSim;
|
||||
|
||||
GuiItem guiItems[] = {
|
||||
{eGuiItemSlider, 0, 0, 240, -36, 0},
|
||||
{eGuiItemThumb, 0, 0, 328, -50, 1},
|
||||
{eGuiItemPause, 0, 0, 40, -50, 'P', true},
|
||||
{eGuiItemPlay, 0, 0, 40, -50, 'S', false},
|
||||
{eGuiItemSingleStep, 0, 0, 80, -50, 'T'},
|
||||
{eGuiItemFaster, 0, 0, 120, -50, 'F'},
|
||||
{eGuiItemRotate, 0, 0, -140, -50, ' ', false, GUIITEM_CHECKABLE},
|
||||
{eGuiItemCharXImg, 0, 0, 160, -50, 0, false, 0}, // 620
|
||||
{eGuiItemChar0Img, 0, 0, 200, -50, 0, false, 0},
|
||||
{eGuiItemChar1Img, 0, 0, 185, -50, 0, false, 0},
|
||||
{eGuiItemChar4Img, 0, 0, 180, -50, 0, true, 0},
|
||||
{eGuiItemPath, 0, 0, -100, -50, 'L', false, GUIITEM_CHECKABLE},
|
||||
{eGuiItemSlider, 0, 0, 240, -36, 0},
|
||||
{eGuiItemThumb, 0, 0, 328, -50, 1},
|
||||
{eGuiItemPause, 0, 0, 40, -50, 'P', true},
|
||||
{eGuiItemPlay, 0, 0, 40, -50, 'S', false},
|
||||
{eGuiItemSingleStep, 0, 0, 80, -50, 'T'},
|
||||
{eGuiItemFaster, 0, 0, 120, -50, 'F'},
|
||||
{eGuiItemRotate, 0, 0, -140, -50, ' ', false, GUIITEM_CHECKABLE},
|
||||
{eGuiItemCharXImg, 0, 0, 160, -50, 0, false, 0}, // 620
|
||||
{eGuiItemChar0Img, 0, 0, 200, -50, 0, false, 0},
|
||||
{eGuiItemChar1Img, 0, 0, 185, -50, 0, false, 0},
|
||||
{eGuiItemChar4Img, 0, 0, 180, -50, 0, true, 0},
|
||||
{eGuiItemPath, 0, 0, -100, -50, 'L', false, GUIITEM_CHECKABLE},
|
||||
{eGuiItemAmbientOclusion, 0, 0, -60, -50, 'A', false, GUIITEM_CHECKABLE},
|
||||
{eGuiItemView, 0, 0, -180, -50, 'V', false},
|
||||
{eGuiItemView, 0, 0, -180, -50, 'V', false},
|
||||
};
|
||||
|
||||
#define NUM_GUI_ITEMS (sizeof(guiItems) / sizeof(GuiItem))
|
||||
@@ -197,9 +197,8 @@ void GuiDisplay::MouseCursorPos(int x, int y)
|
||||
if (g->actionKey == 0) {
|
||||
continue;
|
||||
}
|
||||
bool mouseCursorContained =
|
||||
x > g->posx() && x < (g->posx() + g->texItem.w) &&
|
||||
y > g->posy() && y < (g->posy() + g->texItem.h);
|
||||
bool mouseCursorContained = x > g->posx() && x < (g->posx() + g->texItem.w) && y > g->posy()
|
||||
&& y < (g->posy() + g->texItem.h);
|
||||
|
||||
g->mouseOver = !g->hidden && mouseCursorContained;
|
||||
|
||||
|
||||
@@ -55,17 +55,19 @@ struct GuiItem
|
||||
{
|
||||
eGuiItems name;
|
||||
unsigned int vbo, vao;
|
||||
int sx, sy; // screen location
|
||||
int actionKey; // action key when item pressed
|
||||
int sx, sy; // screen location
|
||||
int actionKey; // action key when item pressed
|
||||
bool hidden {}; // is item hidden
|
||||
unsigned int flags {};
|
||||
bool mouseOver {};
|
||||
TextureItem texItem {};
|
||||
|
||||
int posx() {
|
||||
int posx()
|
||||
{
|
||||
return sx >= 0 ? sx : gWindowSizeW + sx;
|
||||
}
|
||||
int posy() {
|
||||
int posy()
|
||||
{
|
||||
return sy >= 0 ? sy : gWindowSizeH + sy;
|
||||
}
|
||||
void setPosx(int x)
|
||||
@@ -78,8 +80,8 @@ struct GuiItem
|
||||
}
|
||||
};
|
||||
|
||||
#define GUIITEM_CHECKABLE 0x01
|
||||
#define GUIITEM_CHECKED 0x02
|
||||
#define GUIITEM_CHECKABLE 0x01
|
||||
#define GUIITEM_CHECKED 0x02
|
||||
|
||||
|
||||
struct Vertex2D
|
||||
|
||||
@@ -62,4 +62,4 @@ static inline void MotionPosToVec(vec3 vec, const MillMotion* motion)
|
||||
vec[2] = motion->z;
|
||||
}
|
||||
} // namespace MillSim
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -28,16 +28,22 @@ void MillPathLine::GenerateModel()
|
||||
|
||||
// vertex attribs
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(MillPathPosition),
|
||||
(void*)offsetof(MillPathPosition, X));
|
||||
glVertexAttribPointer(0,
|
||||
3,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(MillPathPosition),
|
||||
(void*)offsetof(MillPathPosition, X));
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribIPointer(1, 1, GL_INT, sizeof(MillPathPosition),
|
||||
(void*)offsetof(MillPathPosition, SegmentId));
|
||||
glVertexAttribIPointer(1,
|
||||
1,
|
||||
GL_INT,
|
||||
sizeof(MillPathPosition),
|
||||
(void*)offsetof(MillPathPosition, SegmentId));
|
||||
|
||||
// unbind and free
|
||||
glBindVertexArray(0);
|
||||
MillPathPointsBuffer.clear();
|
||||
|
||||
}
|
||||
|
||||
void MillPathLine::Clear()
|
||||
@@ -55,6 +61,4 @@ void MillPathLine::Render()
|
||||
glDrawArrays(GL_LINE_STRIP, 0, mNumVerts);
|
||||
}
|
||||
|
||||
} // namespace Millsim
|
||||
|
||||
|
||||
} // namespace MillSim
|
||||
|
||||
@@ -28,7 +28,6 @@ protected:
|
||||
int mNumVerts;
|
||||
};
|
||||
|
||||
} // namespace Millsim
|
||||
} // namespace MillSim
|
||||
|
||||
#endif // !__millpathline_h__
|
||||
|
||||
|
||||
@@ -103,9 +103,9 @@ MillPathSegment::MillPathSegment(EndMill* _endmill, MillMotion* from, MillMotion
|
||||
}
|
||||
else {
|
||||
endmill->GenerateArcSegmentDL(mRadius,
|
||||
mStepAngRad * SWEEP_ARC_PAD,
|
||||
mDiff[PZ] / numSimSteps,
|
||||
&mShape);
|
||||
mStepAngRad * SWEEP_ARC_PAD,
|
||||
mDiff[PZ] / numSimSteps,
|
||||
&mShape);
|
||||
numSimSteps++;
|
||||
}
|
||||
|
||||
|
||||
@@ -493,7 +493,6 @@ void MillSimulation::HandleGuiAction(eGuiItems actionItem, bool checked)
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
guiDisplay.UpdatePlayState(mSimPlaying);
|
||||
}
|
||||
@@ -623,7 +622,7 @@ void MillSimulation::UpdateWindowScale(int width, int height)
|
||||
bool MillSimulation::LoadGCodeFile(const char* fileName)
|
||||
{
|
||||
if (mCodeParser.Parse(fileName)) {
|
||||
std::cout << "GCode file loaded successfully" << std::endl;
|
||||
std::cout << "GCode file loaded successfully" << std::endl;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -37,9 +37,9 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#define VIEWITEM_SIMULATION 1
|
||||
#define VIEWITEM_BASE_SHAPE 2
|
||||
#define VIEWITEM_MAX 4
|
||||
#define VIEWITEM_SIMULATION 1
|
||||
#define VIEWITEM_BASE_SHAPE 2
|
||||
#define VIEWITEM_MAX 4
|
||||
|
||||
namespace MillSim
|
||||
{
|
||||
@@ -82,7 +82,6 @@ public:
|
||||
void UpdateWindowScale(int width, int height);
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
void InitDisplay(float quality);
|
||||
void GlsimStart();
|
||||
@@ -139,7 +138,6 @@ protected:
|
||||
bool mIsInStock = false;
|
||||
bool mSimPlaying = false;
|
||||
bool mSingleStep = false;
|
||||
|
||||
};
|
||||
} // namespace MillSim
|
||||
#endif
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
// Xerces
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
|
||||
#endif //_PreComp_
|
||||
#endif //_PreComp_
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ void Shader::UpdateSsaoTexSlot(int ssaoSlot)
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::UpdateKernelVals(int nVals, float *vals)
|
||||
void Shader::UpdateKernelVals(int nVals, float* vals)
|
||||
{
|
||||
glUniform3fv(mSamplesPos, nVals, vals);
|
||||
}
|
||||
@@ -372,7 +372,7 @@ const char* FragShaderFlat = R"(
|
||||
)";
|
||||
|
||||
|
||||
const char* VertShader2DFbo = R"(
|
||||
const char* VertShader2DFbo = R"(
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) in vec2 aPosition;
|
||||
@@ -387,7 +387,7 @@ const char* FragShaderFlat = R"(
|
||||
}
|
||||
)";
|
||||
|
||||
const char* FragShader2dFbo = R"(
|
||||
const char* FragShader2dFbo = R"(
|
||||
#version 330
|
||||
|
||||
out vec4 FragColor;
|
||||
@@ -419,7 +419,7 @@ const char* VertShaderGeom = R"(
|
||||
void main()
|
||||
{
|
||||
vec4 viewPos = view * model * vec4(aPos, 1.0);
|
||||
FragPos = viewPos.xyz;
|
||||
FragPos = viewPos.xyz;
|
||||
|
||||
mat3 normalMatrix = transpose(inverse(mat3(view * model)));
|
||||
Normal = normalMatrix * (invertedNormals ? -aNormal : aNormal);
|
||||
@@ -440,7 +440,7 @@ const char* FragShaderGeom = R"(
|
||||
uniform vec3 objectColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
{
|
||||
// store the fragment position vector in the first gbuffer texture
|
||||
texPosition = FragPos;
|
||||
// also store the per-fragment normals into the gbuffer
|
||||
@@ -468,7 +468,7 @@ const char* FragShaderSSAO = R"(
|
||||
float bias = 0.025;
|
||||
|
||||
// tile noise texture over screen based on screen dimensions divided by noise size
|
||||
const vec2 noiseScale = vec2(800.0/4.0, 600.0/4.0);
|
||||
const vec2 noiseScale = vec2(800.0/4.0, 600.0/4.0);
|
||||
|
||||
uniform mat4 projection;
|
||||
|
||||
@@ -488,7 +488,7 @@ const char* FragShaderSSAO = R"(
|
||||
{
|
||||
// get sample position
|
||||
vec3 samplePos = TBN * ssaoSamples[i]; // from tangent to view-space
|
||||
samplePos = fragPos + samplePos * radius;
|
||||
samplePos = fragPos + samplePos * radius;
|
||||
|
||||
// project sample position (to sample texture) (to get position on screen/texture)
|
||||
vec4 offset = vec4(samplePos, 1.0);
|
||||
@@ -527,7 +527,7 @@ const char* FragShaderSSAOLighting = R"(
|
||||
uniform float lightLinear;
|
||||
|
||||
void main()
|
||||
{
|
||||
{
|
||||
// retrieve data from gbuffer
|
||||
vec4 DiffuseA = texture(texAlbedo, texCoord);
|
||||
vec3 Diffuse = DiffuseA.rgb;
|
||||
@@ -542,7 +542,7 @@ const char* FragShaderSSAOLighting = R"(
|
||||
vec3 lightDir = normalize(lightPos - FragPos);
|
||||
vec3 diffuse = max(dot(Normal, lightDir), 0.0) * Diffuse * lightColor;
|
||||
// specular
|
||||
vec3 halfwayDir = normalize(lightDir + viewDir);
|
||||
vec3 halfwayDir = normalize(lightDir + viewDir);
|
||||
float spec = pow(max(dot(Normal, halfwayDir), 0.0), 16.0);
|
||||
vec3 specular = lightColor * spec;
|
||||
// attenuation
|
||||
@@ -570,7 +570,7 @@ const char* FragShaderStdLighting = R"(
|
||||
uniform vec3 lightAmbient;
|
||||
|
||||
void main()
|
||||
{
|
||||
{
|
||||
// retrieve data from gbuffer
|
||||
vec4 DiffuseA = texture(texAlbedo, texCoord);
|
||||
vec3 Diffuse = DiffuseA.rgb;
|
||||
@@ -578,13 +578,13 @@ const char* FragShaderStdLighting = R"(
|
||||
vec3 Normal = texture(texNormal, texCoord).rgb;
|
||||
|
||||
// then calculate lighting as usual
|
||||
vec3 lighting = lightAmbient * Diffuse;
|
||||
vec3 lighting = lightAmbient * Diffuse;
|
||||
vec3 viewDir = normalize(-FragPos); // viewpos is (0.0.0)
|
||||
// diffuse
|
||||
vec3 lightDir = normalize(lightPos - FragPos);
|
||||
vec3 diffuse = max(dot(Normal, lightDir), 0.0) * Diffuse * lightColor;
|
||||
// specular
|
||||
vec3 halfwayDir = normalize(lightDir + viewDir);
|
||||
vec3 halfwayDir = normalize(lightDir + viewDir);
|
||||
float spec = pow(max(dot(Normal, halfwayDir), 0.0), 16.0);
|
||||
vec3 specular = lightColor * spec;
|
||||
// attenuation
|
||||
@@ -604,13 +604,13 @@ const char* FragShaderSSAOBlur = R"(
|
||||
|
||||
uniform sampler2D texSsao;
|
||||
|
||||
void main()
|
||||
void main()
|
||||
{
|
||||
vec2 texelSize = 1.0 / vec2(textureSize(texSsao, 0));
|
||||
float result = 0.0;
|
||||
for (int x = -2; x <= 1; ++x)
|
||||
for (int x = -2; x <= 1; ++x)
|
||||
{
|
||||
for (int y = -2; y <= 1; ++y)
|
||||
for (int y = -2; y <= 1; ++y)
|
||||
{
|
||||
vec2 offset = vec2(float(x), float(y)) * texelSize;
|
||||
result += texture(texSsao, texCoord + offset).r;
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
void UpdateNormalTexSlot(int normalSlot);
|
||||
void UpdateNoiseTexSlot(int noiseSlot);
|
||||
void UpdateSsaoTexSlot(int ssaoSlot);
|
||||
void UpdateKernelVals(int nVals, float *vals);
|
||||
void UpdateKernelVals(int nVals, float* vals);
|
||||
void UpdateCurSegment(int curSeg);
|
||||
unsigned int CompileShader(const char* vertShader, const char* fragShader);
|
||||
void Activate();
|
||||
|
||||
@@ -80,7 +80,6 @@ void SimDisplay::InitShaders()
|
||||
|
||||
// Mill Path Line Shader
|
||||
shaderLinePath.CompileShader(VertShader3DLine, FragShader3DLine);
|
||||
|
||||
}
|
||||
|
||||
void SimDisplay::CreateFboQuad()
|
||||
@@ -111,7 +110,15 @@ void SimDisplay::CreateDisplayFbos()
|
||||
// a color texture for the frame buffer
|
||||
glGenTextures(1, &mFboColTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, mFboColTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, gWindowSizeW, gWindowSizeH, 0, GL_RGBA, GL_UBYTE, NULL);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA8,
|
||||
gWindowSizeW,
|
||||
gWindowSizeH,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UBYTE,
|
||||
NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mFboColTexture, 0);
|
||||
@@ -119,7 +126,15 @@ void SimDisplay::CreateDisplayFbos()
|
||||
// a position texture for the frame buffer
|
||||
glGenTextures(1, &mFboPosTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, mFboPosTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, gWindowSizeW, gWindowSizeH, 0, GL_RGBA, GL_FLOAT, NULL);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA16F,
|
||||
gWindowSizeW,
|
||||
gWindowSizeH,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_FLOAT,
|
||||
NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, mFboPosTexture, 0);
|
||||
@@ -127,7 +142,15 @@ void SimDisplay::CreateDisplayFbos()
|
||||
// a normal texture for the frame buffer
|
||||
glGenTextures(1, &mFboNormTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, mFboNormTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, gWindowSizeW, gWindowSizeH, 0, GL_RGBA, GL_FLOAT, NULL);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA16F,
|
||||
gWindowSizeW,
|
||||
gWindowSizeH,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_FLOAT,
|
||||
NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, mFboNormTexture, 0);
|
||||
@@ -206,7 +229,7 @@ void SimDisplay::CreateSsaoFbos()
|
||||
vec3_set(sample,
|
||||
randomFloats(generator) * 2.0f - 1.0f,
|
||||
randomFloats(generator) * 2.0f - 1.0f,
|
||||
randomFloats(generator));// * 2.0f - 1.0f);
|
||||
randomFloats(generator)); // * 2.0f - 1.0f);
|
||||
vec3_norm(sample, sample);
|
||||
vec3_scale(sample, sample, randomFloats(generator));
|
||||
float scale = float(i) / 64.0f;
|
||||
|
||||
@@ -102,7 +102,7 @@ void Shape::RotateProfile(float* profPoints,
|
||||
float nx = ny * sx;
|
||||
ny *= sy;
|
||||
|
||||
vbuffer[vidx++] = {x1, y1, prevz, nx, ny, nz };
|
||||
vbuffer[vidx++] = {x1, y1, prevz, nx, ny, nz};
|
||||
vbuffer[vidx++] = {x2, y2, z2, nx, ny, nz};
|
||||
|
||||
if (j != nSlices) {
|
||||
|
||||
@@ -122,7 +122,6 @@ protected:
|
||||
int* vc2idx,
|
||||
int* ic1idx,
|
||||
int* ic2idx);
|
||||
|
||||
};
|
||||
|
||||
} // namespace MillSim
|
||||
|
||||
@@ -60,8 +60,7 @@ void SolidObject::GenerateSolid(std::vector<Vertex>& verts, std::vector<GLushort
|
||||
// calculate object's bounding box:
|
||||
float x = 999999.0f, y = 999999.0f, z = 999999.0f;
|
||||
float l = -999999.0f, w = -999999.0f, h = -999999.0f;
|
||||
for (auto& vert : verts)
|
||||
{
|
||||
for (auto& vert : verts) {
|
||||
x = std::fminf(x, vert.x);
|
||||
y = std::fminf(y, vert.y);
|
||||
z = std::fminf(z, vert.z);
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
/// Calls the display list.
|
||||
virtual void render();
|
||||
Shape shape;
|
||||
void GenerateSolid(std::vector<Vertex> & verts, std::vector<GLushort>& indices);
|
||||
void GenerateSolid(std::vector<Vertex>& verts, std::vector<GLushort>& indices);
|
||||
vec3 center = {};
|
||||
vec3 size = {};
|
||||
vec3 position = {};
|
||||
|
||||
@@ -27,8 +27,7 @@
|
||||
using namespace MillSim;
|
||||
|
||||
StockObject::StockObject()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
void StockObject::GenerateBoxStock(float x, float y, float z, float l, float w, float h)
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
namespace MillSim
|
||||
{
|
||||
|
||||
class StockObject : public SolidObject
|
||||
class StockObject: public SolidObject
|
||||
{
|
||||
public:
|
||||
StockObject();
|
||||
|
||||
@@ -46,7 +46,9 @@ TextureItem texItems[] = {
|
||||
|
||||
int sssize = -1;
|
||||
|
||||
TextureLoader::TextureLoader(std::string imgFolder, std::vector<std::string> fileNames, int textureSize)
|
||||
TextureLoader::TextureLoader(std::string imgFolder,
|
||||
std::vector<std::string> fileNames,
|
||||
int textureSize)
|
||||
: mImageFolder(imgFolder)
|
||||
{
|
||||
int buffsize = textureSize * textureSize * sizeof(unsigned int);
|
||||
@@ -63,15 +65,15 @@ TextureLoader::TextureLoader(std::string imgFolder, std::vector<std::string> fil
|
||||
|
||||
// parse compressed image into a texture buffer
|
||||
bool TextureLoader::AddImage(TextureItem* texItem,
|
||||
QImage& pixmap,
|
||||
unsigned int* buffPos,
|
||||
int stride)
|
||||
QImage& pixmap,
|
||||
unsigned int* buffPos,
|
||||
int stride)
|
||||
{
|
||||
int width = pixmap.width();
|
||||
int height = pixmap.height();
|
||||
buffPos += stride * texItem->ty + texItem->tx;
|
||||
for (int i = 0; i < height; i++) {
|
||||
unsigned int* line = reinterpret_cast<unsigned int *>(pixmap.scanLine(i));
|
||||
unsigned int* line = reinterpret_cast<unsigned int*>(pixmap.scanLine(i));
|
||||
for (int j = 0; j < width; j++) {
|
||||
buffPos[j] = line[j];
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace MillSim
|
||||
|
||||
struct TextureItem
|
||||
{
|
||||
int tx{}, ty{}; // texture location
|
||||
int w{}, h{}; // item size
|
||||
int tx {}, ty {}; // texture location
|
||||
int w {}, h {}; // item size
|
||||
};
|
||||
|
||||
class TextureLoader
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
/** \defgroup TEMPLATE PathSimulator
|
||||
* \ingroup WORKBENCHES */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user