2017-08-01 12:30:58 +00:00
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
2022-01-06 22:37:49 +00:00
|
|
|
Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BT_SOFT_BODY_SOLVERS_H
|
|
|
|
#define BT_SOFT_BODY_SOLVERS_H
|
|
|
|
|
|
|
|
#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h"
|
|
|
|
|
|
|
|
class btSoftBodyTriangleData;
|
|
|
|
class btSoftBodyLinkData;
|
|
|
|
class btSoftBodyVertexData;
|
|
|
|
class btVertexBufferDescriptor;
|
|
|
|
class btCollisionObject;
|
|
|
|
class btSoftBody;
|
|
|
|
|
|
|
|
class btSoftBodySolver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum SolverTypes
|
|
|
|
{
|
|
|
|
DEFAULT_SOLVER,
|
|
|
|
CPU_SOLVER,
|
|
|
|
CL_SOLVER,
|
|
|
|
CL_SIMD_SOLVER,
|
|
|
|
DX_SOLVER,
|
2020-01-08 17:05:43 +00:00
|
|
|
DX_SIMD_SOLVER,
|
2021-09-29 13:47:08 +00:00
|
|
|
DEFORMABLE_SOLVER
|
2017-08-01 12:30:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int m_numberOfPositionIterations;
|
|
|
|
int m_numberOfVelocityIterations;
|
|
|
|
// Simulation timescale
|
|
|
|
float m_timeScale;
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
public:
|
2019-01-03 13:26:51 +00:00
|
|
|
btSoftBodySolver() : m_numberOfPositionIterations(10),
|
|
|
|
m_timeScale(1)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_numberOfVelocityIterations = 0;
|
|
|
|
m_numberOfPositionIterations = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~btSoftBodySolver()
|
|
|
|
{
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
/**
|
|
|
|
* Return the type of the solver.
|
|
|
|
*/
|
|
|
|
virtual SolverTypes getSolverType() const = 0;
|
|
|
|
|
|
|
|
/** Ensure that this solver is initialized. */
|
|
|
|
virtual bool checkInitialized() = 0;
|
|
|
|
|
|
|
|
/** Optimize soft bodies in this solver. */
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void optimize(btAlignedObjectArray<btSoftBody *> &softBodies, bool forceUpdate = false) = 0;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
/** Copy necessary data back to the original soft body source objects. */
|
|
|
|
virtual void copyBackToSoftBodies(bool bMove = true) = 0;
|
|
|
|
|
|
|
|
/** Predict motion of soft bodies into next timestep */
|
2020-01-08 17:05:43 +00:00
|
|
|
virtual void predictMotion(btScalar solverdt) = 0;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
/** Solve constraints for a set of soft bodies */
|
2020-01-08 17:05:43 +00:00
|
|
|
virtual void solveConstraints(btScalar solverdt) = 0;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
/** Perform necessary per-step updates of soft bodies such as recomputing normals and bounding boxes */
|
|
|
|
virtual void updateSoftBodies() = 0;
|
|
|
|
|
|
|
|
/** Process a collision between one of the world's soft bodies and another collision object */
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void processCollision(btSoftBody *, const struct btCollisionObjectWrapper *) = 0;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
/** Process a collision between two soft bodies */
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void processCollision(btSoftBody *, btSoftBody *) = 0;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
/** Set the number of velocity constraint solver iterations this solver uses. */
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void setNumberOfPositionIterations(int iterations)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_numberOfPositionIterations = iterations;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the number of velocity constraint solver iterations this solver uses. */
|
|
|
|
virtual int getNumberOfPositionIterations()
|
|
|
|
{
|
|
|
|
return m_numberOfPositionIterations;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the number of velocity constraint solver iterations this solver uses. */
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void setNumberOfVelocityIterations(int iterations)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_numberOfVelocityIterations = iterations;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the number of velocity constraint solver iterations this solver uses. */
|
|
|
|
virtual int getNumberOfVelocityIterations()
|
|
|
|
{
|
|
|
|
return m_numberOfVelocityIterations;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the timescale that the simulation is using */
|
|
|
|
float getTimeScale()
|
|
|
|
{
|
|
|
|
return m_timeScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/**
|
|
|
|
* Add a collision object to be used by the indicated softbody.
|
|
|
|
*/
|
|
|
|
virtual void addCollisionObjectForSoftBody( int clothIdentifier, btCollisionObject *collisionObject ) = 0;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to manage movement of data from a solver to a given target.
|
|
|
|
* This version is abstract. Subclasses will have custom pairings for different combinations.
|
|
|
|
*/
|
|
|
|
class btSoftBodySolverOutput
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
public:
|
|
|
|
btSoftBodySolverOutput()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~btSoftBodySolverOutput()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Output current computed vertex data to the vertex buffers for all cloths in the solver. */
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void copySoftBodyToVertexBuffer(const btSoftBody *const softBody, btVertexBufferDescriptor *vertexBuffer) = 0;
|
2017-08-01 12:30:58 +00:00
|
|
|
};
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif // #ifndef BT_SOFT_BODY_SOLVERS_H
|