Blender  V3.3
btDefaultSoftBodySolver.cpp
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
19 
23 
25 {
26  // Initial we will clearly need to update solver constants
27  // For now this is global for the cloths linked with this solver - we should probably make this body specific
28  // for performance in future once we understand more clearly when constants need to be updated
30 }
31 
33 {
34 }
35 
36 // In this case the data is already in the soft bodies so there is no need for us to do anything
38 {
39 }
40 
42 {
43  m_softBodySet.copyFromArray(softBodies);
44 }
45 
47 {
48  for (int i = 0; i < m_softBodySet.size(); i++)
49  {
50  btSoftBody *psb = (btSoftBody *)m_softBodySet[i];
51  if (psb->isActive())
52  {
53  psb->integrateMotion();
54  }
55  }
56 } // updateSoftBodies
57 
59 {
60  return true;
61 }
62 
64 {
65  // Solve constraints for non-solver softbodies
66  for (int i = 0; i < m_softBodySet.size(); ++i)
67  {
68  btSoftBody *psb = static_cast<btSoftBody *>(m_softBodySet[i]);
69  if (psb->isActive())
70  {
71  psb->solveConstraints();
72  }
73  }
74 } // btDefaultSoftBodySolver::solveConstraints
75 
77 {
78  // Currently only support CPU output buffers
79  // TODO: check for DX11 buffers. Take all offsets into the same DX11 buffer
80  // and use them together on a single kernel call if possible by setting up a
81  // per-cloth target buffer array for the copy kernel.
82 
84  {
85  const btAlignedObjectArray<btSoftBody::Node> &clothVertices(softBody->m_nodes);
86  int numVertices = clothVertices.size();
87 
88  const btCPUVertexBufferDescriptor *cpuVertexBuffer = static_cast<btCPUVertexBufferDescriptor *>(vertexBuffer);
89  float *basePointer = cpuVertexBuffer->getBasePointer();
90 
91  if (vertexBuffer->hasVertexPositions())
92  {
93  const int vertexOffset = cpuVertexBuffer->getVertexOffset();
94  const int vertexStride = cpuVertexBuffer->getVertexStride();
95  float *vertexPointer = basePointer + vertexOffset;
96 
97  for (int vertexIndex = 0; vertexIndex < numVertices; ++vertexIndex)
98  {
99  btVector3 position = clothVertices[vertexIndex].m_x;
100  *(vertexPointer + 0) = (float)position.getX();
101  *(vertexPointer + 1) = (float)position.getY();
102  *(vertexPointer + 2) = (float)position.getZ();
103  vertexPointer += vertexStride;
104  }
105  }
106  if (vertexBuffer->hasNormals())
107  {
108  const int normalOffset = cpuVertexBuffer->getNormalOffset();
109  const int normalStride = cpuVertexBuffer->getNormalStride();
110  float *normalPointer = basePointer + normalOffset;
111 
112  for (int vertexIndex = 0; vertexIndex < numVertices; ++vertexIndex)
113  {
114  btVector3 normal = clothVertices[vertexIndex].m_n;
115  *(normalPointer + 0) = (float)normal.getX();
116  *(normalPointer + 1) = (float)normal.getY();
117  *(normalPointer + 2) = (float)normal.getZ();
118  normalPointer += normalStride;
119  }
120  }
121  }
122 } // btDefaultSoftBodySolver::copySoftBodyToVertexBuffer
123 
125 {
126  softBody->defaultCollisionHandler(otherSoftBody);
127 }
128 
129 // For the default solver just leave the soft body to do its collision processing
131 {
132  softBody->defaultCollisionHandler(collisionObjectWrap);
133 } // btDefaultSoftBodySolver::processCollision
134 
136 {
137  for (int i = 0; i < m_softBodySet.size(); ++i)
138  {
139  btSoftBody *psb = m_softBodySet[i];
140 
141  if (psb->isActive())
142  {
143  psb->predictMotion(timeStep);
144  }
145  }
146 }
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
int numVertices() const
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
void copyFromArray(const btAlignedObjectArray &otherArray)
SIMD_FORCE_INLINE int size() const
return the number of elements in the array
virtual void predictMotion(btScalar solverdt)
btAlignedObjectArray< btSoftBody * > m_softBodySet
virtual void processCollision(btSoftBody *, const btCollisionObjectWrapper *)
virtual void optimize(btAlignedObjectArray< btSoftBody * > &softBodies, bool forceUpdate=false)
virtual void copySoftBodyToVertexBuffer(const btSoftBody *const softBody, btVertexBufferDescriptor *vertexBuffer)
virtual void solveConstraints(btScalar solverdt)
virtual void copyBackToSoftBodies(bool bMove=true)
void integrateMotion()
void defaultCollisionHandler(const btCollisionObjectWrapper *pcoWrap)
void predictMotion(btScalar dt)
void solveConstraints()
tNodeArray m_nodes
Definition: btSoftBody.h:799
virtual BufferTypes getBufferType() const =0
IconTextureDrawCall normal