Bullet Collision Detection & Physics Library
btDefaultSoftBodySolver.cpp
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
19
23
24
26{
27 // Initial we will clearly need to update solver constants
28 // For now this is global for the cloths linked with this solver - we should probably make this body specific
29 // for performance in future once we understand more clearly when constants need to be updated
31}
32
34{
35}
36
37// In this case the data is already in the soft bodies so there is no need for us to do anything
39{
40
41}
42
44{
45 m_softBodySet.copyFromArray( softBodies );
46}
47
49{
50 for ( int i=0; i < m_softBodySet.size(); i++)
51 {
53 if (psb->isActive())
54 {
55 psb->integrateMotion();
56 }
57 }
58} // updateSoftBodies
59
61{
62 return true;
63}
64
66{
67 // Solve constraints for non-solver softbodies
68 for(int i=0; i < m_softBodySet.size(); ++i)
69 {
70 btSoftBody* psb = static_cast<btSoftBody*>(m_softBodySet[i]);
71 if (psb->isActive())
72 {
73 psb->solveConstraints();
74 }
75 }
76} // btDefaultSoftBodySolver::solveConstraints
77
78
80{
81 // Currently only support CPU output buffers
82 // TODO: check for DX11 buffers. Take all offsets into the same DX11 buffer
83 // and use them together on a single kernel call if possible by setting up a
84 // per-cloth target buffer array for the copy kernel.
85
87 {
88 const btAlignedObjectArray<btSoftBody::Node> &clothVertices( softBody->m_nodes );
89 int numVertices = clothVertices.size();
90
91 const btCPUVertexBufferDescriptor *cpuVertexBuffer = static_cast< btCPUVertexBufferDescriptor* >(vertexBuffer);
92 float *basePointer = cpuVertexBuffer->getBasePointer();
93
94 if( vertexBuffer->hasVertexPositions() )
95 {
96 const int vertexOffset = cpuVertexBuffer->getVertexOffset();
97 const int vertexStride = cpuVertexBuffer->getVertexStride();
98 float *vertexPointer = basePointer + vertexOffset;
99
100 for( int vertexIndex = 0; vertexIndex < numVertices; ++vertexIndex )
101 {
102 btVector3 position = clothVertices[vertexIndex].m_x;
103 *(vertexPointer + 0) = (float)position.getX();
104 *(vertexPointer + 1) = (float)position.getY();
105 *(vertexPointer + 2) = (float)position.getZ();
106 vertexPointer += vertexStride;
107 }
108 }
109 if( vertexBuffer->hasNormals() )
110 {
111 const int normalOffset = cpuVertexBuffer->getNormalOffset();
112 const int normalStride = cpuVertexBuffer->getNormalStride();
113 float *normalPointer = basePointer + normalOffset;
114
115 for( int vertexIndex = 0; vertexIndex < numVertices; ++vertexIndex )
116 {
117 btVector3 normal = clothVertices[vertexIndex].m_n;
118 *(normalPointer + 0) = (float)normal.getX();
119 *(normalPointer + 1) = (float)normal.getY();
120 *(normalPointer + 2) = (float)normal.getZ();
121 normalPointer += normalStride;
122 }
123 }
124 }
125} // btDefaultSoftBodySolver::copySoftBodyToVertexBuffer
126
128{
129 softBody->defaultCollisionHandler( otherSoftBody);
130}
131
132// For the default solver just leave the soft body to do its collision processing
134{
135 softBody->defaultCollisionHandler( collisionObjectWrap );
136} // btDefaultSoftBodySolver::processCollision
137
138
140{
141 for ( int i=0; i < m_softBodySet.size(); ++i)
142 {
143 btSoftBody* psb = m_softBodySet[i];
144
145 if (psb->isActive())
146 {
147 psb->predictMotion(timeStep);
148 }
149 }
150}
151
int size() const
return the number of elements in the array
void copyFromArray(const btAlignedObjectArray &otherArray)
virtual float * getBasePointer() const
Return the base pointer in memory to the first vertex.
virtual void solveConstraints(float solverdt)
Solve constraints for a set of soft bodies.
virtual void updateSoftBodies()
Perform necessary per-step updates of soft bodies such as recomputing normals and bounding boxes.
btAlignedObjectArray< btSoftBody * > m_softBodySet
virtual void processCollision(btSoftBody *, const btCollisionObjectWrapper *)
virtual void predictMotion(float solverdt)
Predict motion of soft bodies into next timestep.
virtual void optimize(btAlignedObjectArray< btSoftBody * > &softBodies, bool forceUpdate=false)
Optimize soft bodies in this solver.
virtual void copySoftBodyToVertexBuffer(const btSoftBody *const softBody, btVertexBufferDescriptor *vertexBuffer)
bool m_updateSolverConstants
Variable to define whether we need to update solver constants on the next iteration.
virtual void copyBackToSoftBodies(bool bMove=true)
Copy necessary data back to the original soft body source objects.
virtual bool checkInitialized()
Ensure that this solver is initialized.
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:72
void integrateMotion()
void defaultCollisionHandler(const btCollisionObjectWrapper *pcoWrap)
void predictMotion(btScalar dt)
void solveConstraints()
tNodeArray m_nodes
Definition: btSoftBody.h:659
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:84
const btScalar & getZ() const
Return the z value.
Definition: btVector3.h:577
const btScalar & getY() const
Return the y value.
Definition: btVector3.h:575
const btScalar & getX() const
Return the x value.
Definition: btVector3.h:573
virtual BufferTypes getBufferType() const =0
Return the type of the vertex buffer descriptor.
virtual int getNormalOffset() const
Return the vertex offset in floats from the base pointer.
virtual int getVertexOffset() const
Return the vertex offset in floats from the base pointer.
virtual int getNormalStride() const
Return the vertex stride in number of floats between vertices.
virtual int getVertexStride() const
Return the vertex stride in number of floats between vertices.