mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-16 01:24:36 +00:00
Filters performance improved
This commit is contained in:
parent
5d845e8f0f
commit
ac01f61e61
@ -7,7 +7,7 @@ MeshSubFilter::MeshSubFilter(){
|
||||
|
||||
void MeshSubFilter::initParameterSet(QAction* action,MeshDocument& md, RichParameterSet & par){
|
||||
par.addParam(new RichInt("fps", 100, "Frames per second", "The number of times per second the physics simulation is updated"));
|
||||
par.addParam(new RichInt("iterations", 10, "Physics method iterations", "Number of iterations of the physics iterative method for equation solving"));
|
||||
par.addParam(new RichInt("iterations", 20, "Physics method iterations", "Number of iterations of the physics iterative method for equation solving"));
|
||||
par.addParam(new RichInt("contacts", 20, "Max contacts", "Maximum number of contact points to generate per object pair"));
|
||||
par.addParam(new RichFloat("bounciness", 0.1f, "Bounciness", "The amount of bounciness of a collision: 0 means the surfaces are not bouncy at all, 1 is the maximum bounciness"));
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@ using namespace std;
|
||||
using namespace vcg;
|
||||
|
||||
bool ODEFacade::m_initialized;
|
||||
int ODEFacade::m_maxIterations = 10;
|
||||
float ODEFacade::m_bounciness = 0.1f;
|
||||
|
||||
dSpaceID ODEFacade::m_space;
|
||||
@ -110,17 +109,14 @@ void ODEFacade::setAsRigidBody(MeshModel& mesh, bool isRigidBody){
|
||||
m_registeredMeshes[index()].second->body = dBodyCreate(m_world);
|
||||
dGeomSetBody(m_registeredMeshes[index()].second->geom, m_registeredMeshes[index()].second->body);
|
||||
|
||||
tri::Inertia<CMeshO> inertia;
|
||||
inertia.Compute(m_registeredMeshes[index()].first->cm);
|
||||
|
||||
dMass* mass = &m_registeredMeshes[index()].second->mass;
|
||||
dMassSetTrimesh(mass, 1.0f, m_registeredMeshes[index()].second->geom);
|
||||
mass->mass = 10;
|
||||
mass->mass = 5;
|
||||
|
||||
dReal centerOfMass[3] = { mass->c[0], mass->c[1], mass->c[2] };
|
||||
dMassTranslate(&m_registeredMeshes[index()].second->mass, -centerOfMass[0], -centerOfMass[1], -centerOfMass[2]);
|
||||
dBodySetMass(m_registeredMeshes[index()].second->body, &m_registeredMeshes[index()].second->mass);
|
||||
dBodySetPosition(m_registeredMeshes[index()].second->body, inertia.CenterOfMass()[0], inertia.CenterOfMass()[1], inertia.CenterOfMass()[2]);
|
||||
dBodySetPosition(m_registeredMeshes[index()].second->body, m_registeredMeshes[index()].second->centerOfMass[0], m_registeredMeshes[index()].second->centerOfMass[1], m_registeredMeshes[index()].second->centerOfMass[2]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,7 +158,7 @@ void ODEFacade::updateTransform(){
|
||||
|
||||
void ODEFacade::integrate(float step){
|
||||
dSpaceCollide(m_space, this, collisionCallback);
|
||||
dWorldStepFast1(m_world, step, m_maxIterations);
|
||||
dWorldQuickStep(m_world, step);
|
||||
dJointGroupEmpty(m_contactGroup);
|
||||
}
|
||||
|
||||
@ -176,11 +172,10 @@ void ODEFacade::collisionCallback(dGeomID o1, dGeomID o2){
|
||||
dBodyID body2 = dGeomGetBody(o2);
|
||||
|
||||
for(int i = 0; i < m_contacts.size(); i++){
|
||||
m_contacts[i].surface.mode = dContactBounce | dContactSoftCFM;
|
||||
m_contacts[i].surface.mode = dContactBounce;
|
||||
m_contacts[i].surface.mu = 0.5;
|
||||
m_contacts[i].surface.bounce = m_bounciness;
|
||||
m_contacts[i].surface.bounce_vel = 0.1;
|
||||
m_contacts[i].surface.soft_cfm = 0.01;
|
||||
}
|
||||
|
||||
int collisions = dCollide(o1, o2, m_contacts.size(), &m_contacts[0].geom, sizeof(dContact));
|
||||
@ -232,7 +227,7 @@ vcg::Matrix44f ODEFacade::getTransformationMatrix(MeshModel& mesh){
|
||||
}
|
||||
|
||||
void ODEFacade::setIterations(int iterations){
|
||||
m_maxIterations = iterations;
|
||||
dWorldSetQuickStepNumIterations(m_world, iterations);
|
||||
}
|
||||
|
||||
void ODEFacade::setMaxContacts(int contacts){
|
||||
|
||||
@ -64,7 +64,6 @@ protected:
|
||||
|
||||
//This class is a monostate
|
||||
static bool m_initialized;
|
||||
static int m_maxIterations;
|
||||
static float m_bounciness;
|
||||
|
||||
static dWorldID m_world;
|
||||
|
||||
@ -80,9 +80,9 @@ bool RandomFillFilter::applyFilter(QAction* filter, MeshDocument &md, RichParame
|
||||
}
|
||||
|
||||
vcg::Point3<float> RandomFillFilter::getRandomOrigin(RichParameterSet& par){
|
||||
int randomFace = static_cast<float>(rand())/RAND_MAX*(par.getMesh("container")->cm.face.size() - 1);
|
||||
CFaceO& face = par.getMesh("container")->cm.face[randomFace];
|
||||
return face.P(0) + (face.N() * par.getMesh("filler")->cm.bbox.Diag());
|
||||
int randomVertex = static_cast<float>(rand())/RAND_MAX*(par.getMesh("container")->cm.vert.size() - 1);
|
||||
CVertexO& vertex = par.getMesh("container")->cm.vert[randomVertex];
|
||||
return vertex.P() + (vertex.N() * par.getMesh("filler")->cm.bbox.Diag());
|
||||
}
|
||||
|
||||
void RandomFillFilter::addRandomObject(MeshDocument& md, MeshModel* filler, const vcg::Point3<float>& origin, int meshID){
|
||||
|
||||
@ -25,9 +25,9 @@ FilterPhysics::~FilterPhysics(){
|
||||
case FP_PHYSICS_GRAVITY:
|
||||
return QString("Physics gravity simulation");
|
||||
case FP_PHYSICS_RNDDROP:
|
||||
return QString("Physics random drop simulation");
|
||||
return QString("Physics random drop");
|
||||
case FP_PHYSICS_RNDFILL:
|
||||
return QString("Physics random fill simulation");
|
||||
return QString("Physics random fill");
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
@ -31,7 +31,7 @@ class FilterPhysics : public QObject, public MeshFilterInterface
|
||||
virtual QString filterName(FilterIDType filter) const;
|
||||
virtual QString filterInfo(FilterIDType filter) const;
|
||||
|
||||
virtual int getRequirements(QAction*){return MeshModel::MM_FACEVERT | MeshModel::MM_FACENORMAL;}
|
||||
virtual int getRequirements(QAction*){return MeshModel::MM_FACEVERT | MeshModel::MM_FACENORMAL | MeshModel::MM_VERTNORMAL; }
|
||||
virtual int postCondition( QAction* ) const{return MeshModel::MM_FACENORMAL; /*MeshModel::MM_TRANSFMATRIX; */}
|
||||
|
||||
virtual bool autoDialog(QAction*) {return true;}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user