b3GpuDynamicsWorld improvements:
apply forces copy linear/angular velocity every frame at the CPU side, initial velocity works now hook up setGravity Note: the 'stepSimulation' for GPU only simulates a single simulation frame.
This commit is contained in:
@@ -249,6 +249,19 @@ void b3GpuSapBroadphase::calculateOverlappingPairsHost()
|
||||
|
||||
}
|
||||
|
||||
void b3GpuSapBroadphase::reset()
|
||||
{
|
||||
m_allAabbsGPU.resize(0);
|
||||
m_allAabbsCPU.resize(0);
|
||||
|
||||
m_smallAabbsGPU.resize(0);
|
||||
m_smallAabbsCPU.resize(0);
|
||||
|
||||
m_largeAabbsGPU.resize(0);
|
||||
m_largeAabbsCPU.resize(0);
|
||||
}
|
||||
|
||||
|
||||
void b3GpuSapBroadphase::calculateOverlappingPairs()
|
||||
{
|
||||
int axis = 0;//todo on GPU for now hardcode
|
||||
|
||||
@@ -51,6 +51,8 @@ class b3GpuSapBroadphase
|
||||
|
||||
void calculateOverlappingPairs();
|
||||
void calculateOverlappingPairsHost();
|
||||
|
||||
void reset();
|
||||
|
||||
void init3dSap();
|
||||
void calculateOverlappingPairsHostIncremental3Sap();
|
||||
|
||||
@@ -19,7 +19,7 @@ struct b3Config
|
||||
int m_maxTriConvexPairCapacity;
|
||||
|
||||
b3Config()
|
||||
:m_maxConvexBodies(32*1024),
|
||||
:m_maxConvexBodies(64*1024),
|
||||
m_maxConvexShapes(8192),
|
||||
m_maxVerticesPerFace(64),
|
||||
m_maxFacesPerShape(64),
|
||||
|
||||
@@ -683,6 +683,12 @@ const struct b3RigidBodyCL* b3GpuNarrowPhase::getBodiesCpu() const
|
||||
return &m_data->m_bodyBufferCPU->at(0);
|
||||
};
|
||||
|
||||
struct b3RigidBodyCL* b3GpuNarrowPhase::getBodiesCpu()
|
||||
{
|
||||
return &m_data->m_bodyBufferCPU->at(0);
|
||||
};
|
||||
|
||||
|
||||
int b3GpuNarrowPhase::getNumBodiesGpu() const
|
||||
{
|
||||
return m_data->m_bodyBufferGPU->size();
|
||||
@@ -852,7 +858,7 @@ int b3GpuNarrowPhase::registerRigidBody(int collidableIndex, float mass, const f
|
||||
} else
|
||||
{
|
||||
|
||||
assert(body.m_collidableIdx>=0);
|
||||
b3Assert(body.m_collidableIdx>=0);
|
||||
|
||||
//approximate using the aabb of the shape
|
||||
|
||||
@@ -917,6 +923,28 @@ void b3GpuNarrowPhase::writeAllBodiesToGpu()
|
||||
|
||||
}
|
||||
|
||||
|
||||
void b3GpuNarrowPhase::reset()
|
||||
{
|
||||
m_data->m_numAcceleratedShapes = 0;
|
||||
m_data->m_numAcceleratedRigidBodies = 0;
|
||||
this->m_static0Index = -1;
|
||||
m_data->m_uniqueEdges.resize(0);
|
||||
m_data->m_convexVertices.resize(0);
|
||||
m_data->m_convexPolyhedra.resize(0);
|
||||
m_data->m_convexIndices.resize(0);
|
||||
m_data->m_cpuChildShapes.resize(0);
|
||||
m_data->m_convexFaces.resize(0);
|
||||
m_data->m_collidablesCPU.resize(0);
|
||||
m_data->m_localShapeAABBCPU->resize(0);
|
||||
m_data->m_bvhData.resize(0);
|
||||
m_data->m_treeNodesCPU.resize(0);
|
||||
m_data->m_subTreesCPU.resize(0);
|
||||
m_data->m_bvhInfoCPU.resize(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void b3GpuNarrowPhase::readbackAllBodiesToCpu()
|
||||
{
|
||||
m_data->m_bodyBufferGPU->copyToHostPointer(&m_data->m_bodyBufferCPU->at(0),m_data->m_numAcceleratedRigidBodies);
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
void setObjectTransform(const float* position, const float* orientation , int bodyIndex);
|
||||
|
||||
void writeAllBodiesToGpu();
|
||||
|
||||
void reset();
|
||||
void readbackAllBodiesToCpu();
|
||||
void getObjectTransformFromCpu(float* position, float* orientation , int bodyIndex) const;
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
|
||||
cl_mem getBodiesGpu();
|
||||
const struct b3RigidBodyCL* getBodiesCpu() const;
|
||||
struct b3RigidBodyCL* getBodiesCpu();
|
||||
|
||||
int getNumBodiesGpu() const;
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ b3GpuRigidBodyPipeline::b3GpuRigidBodyPipeline(cl_context ctx,cl_device_id devic
|
||||
m_data->m_broadphaseDbvt = broadphaseDbvt;
|
||||
m_data->m_broadphaseSap = broadphaseSap;
|
||||
m_data->m_narrowphase = narrowphase;
|
||||
m_data->m_gravity.setValue(0.f,-9.8f,0.f);
|
||||
|
||||
cl_int errNum=0;
|
||||
|
||||
@@ -98,6 +99,12 @@ b3GpuRigidBodyPipeline::~b3GpuRigidBodyPipeline()
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
void b3GpuRigidBodyPipeline::reset()
|
||||
{
|
||||
m_data->m_allAabbsGPU->resize(0);
|
||||
m_data->m_allAabbsCPU.resize(0);
|
||||
m_data->m_joints.resize(0);
|
||||
}
|
||||
|
||||
void b3GpuRigidBodyPipeline::addConstraint(b3TypedConstraint* constraint)
|
||||
{
|
||||
@@ -148,7 +155,7 @@ void b3GpuRigidBodyPipeline::stepSimulation(float deltaTime)
|
||||
int numContacts = 0;
|
||||
|
||||
|
||||
int numBodies = m_data->m_narrowphase->getNumBodiesGpu();
|
||||
int numBodies = m_data->m_narrowphase->getNumRigidBodies();
|
||||
|
||||
if (numPairs)
|
||||
{
|
||||
@@ -194,9 +201,9 @@ void b3GpuRigidBodyPipeline::stepSimulation(float deltaTime)
|
||||
//solve constraints
|
||||
|
||||
b3OpenCLArray<b3RigidBodyCL> gpuBodies(m_data->m_context,m_data->m_queue,0,true);
|
||||
gpuBodies.setFromOpenCLBuffer(m_data->m_narrowphase->getBodiesGpu(),m_data->m_narrowphase->getNumBodiesGpu());
|
||||
gpuBodies.setFromOpenCLBuffer(m_data->m_narrowphase->getBodiesGpu(),m_data->m_narrowphase->getNumRigidBodies());
|
||||
b3OpenCLArray<b3InertiaCL> gpuInertias(m_data->m_context,m_data->m_queue,0,true);
|
||||
gpuInertias.setFromOpenCLBuffer(m_data->m_narrowphase->getBodyInertiasGpu(),m_data->m_narrowphase->getNumBodiesGpu());
|
||||
gpuInertias.setFromOpenCLBuffer(m_data->m_narrowphase->getBodyInertiasGpu(),m_data->m_narrowphase->getNumRigidBodies());
|
||||
b3OpenCLArray<b3Contact4> gpuContacts(m_data->m_context,m_data->m_queue,0,true);
|
||||
gpuContacts.setFromOpenCLBuffer(m_data->m_narrowphase->getContactsGpu(),m_data->m_narrowphase->getNumContactsGpu());
|
||||
|
||||
@@ -214,7 +221,7 @@ void b3GpuRigidBodyPipeline::stepSimulation(float deltaTime)
|
||||
b3TypedConstraint** joints = numJoints? &m_data->m_joints[0] : 0;
|
||||
b3Contact4* contacts = numContacts? &hostContacts[0]: 0;
|
||||
// m_data->m_solver->solveContacts(m_data->m_narrowphase->getNumBodiesGpu(),&hostBodies[0],&hostInertias[0],numContacts,contacts,numJoints, joints);
|
||||
m_data->m_solver->solveContacts(m_data->m_narrowphase->getNumBodiesGpu(),&hostBodies[0],&hostInertias[0],0,0,numJoints, joints);
|
||||
m_data->m_solver->solveContacts(m_data->m_narrowphase->getNumRigidBodies(),&hostBodies[0],&hostInertias[0],0,0,numJoints, joints);
|
||||
|
||||
}
|
||||
gpuBodies.copyFromHost(hostBodies);
|
||||
@@ -302,14 +309,14 @@ void b3GpuRigidBodyPipeline::integrate(float timeStep)
|
||||
|
||||
b3LauncherCL launcher(m_data->m_queue,m_data->m_integrateTransformsKernel);
|
||||
launcher.setBuffer(m_data->m_narrowphase->getBodiesGpu());
|
||||
int numBodies = m_data->m_narrowphase->getNumBodiesGpu();
|
||||
int numBodies = m_data->m_narrowphase->getNumRigidBodies();
|
||||
launcher.setConst(numBodies);
|
||||
launcher.setConst(timeStep);
|
||||
float angularDamp = 0.99f;
|
||||
launcher.setConst(angularDamp);
|
||||
|
||||
b3Vector3 gravity(0.f,-9.8f,0.f);
|
||||
launcher.setConst(gravity);
|
||||
|
||||
launcher.setConst(m_data->m_gravity);
|
||||
|
||||
launcher.launch1D(numBodies);
|
||||
}
|
||||
@@ -320,7 +327,7 @@ void b3GpuRigidBodyPipeline::setupGpuAabbsFull()
|
||||
{
|
||||
cl_int ciErrNum=0;
|
||||
|
||||
int numBodies = m_data->m_narrowphase->getNumBodiesGpu();
|
||||
int numBodies = m_data->m_narrowphase->getNumRigidBodies();
|
||||
if (!numBodies)
|
||||
return;
|
||||
|
||||
@@ -356,9 +363,13 @@ cl_mem b3GpuRigidBodyPipeline::getBodyBuffer()
|
||||
|
||||
int b3GpuRigidBodyPipeline::getNumBodies() const
|
||||
{
|
||||
return m_data->m_narrowphase->getNumBodiesGpu();
|
||||
return m_data->m_narrowphase->getNumRigidBodies();
|
||||
}
|
||||
|
||||
void b3GpuRigidBodyPipeline::setGravity(const float* grav)
|
||||
{
|
||||
m_data->m_gravity.setValue(grav[0],grav[1],grav[2]);
|
||||
}
|
||||
|
||||
void b3GpuRigidBodyPipeline::writeAllInstancesToGpu()
|
||||
{
|
||||
|
||||
@@ -33,7 +33,9 @@ public:
|
||||
int registerPhysicsInstance(float mass, const float* position, const float* orientation, int collisionShapeIndex, int userData, bool writeInstanceToGpu);
|
||||
//if you passed "writeInstanceToGpu" false in the registerPhysicsInstance method (for performance) you need to call writeAllInstancesToGpu after all instances are registered
|
||||
void writeAllInstancesToGpu();
|
||||
|
||||
void setGravity(const float* grav);
|
||||
void reset();
|
||||
|
||||
void addConstraint(class b3TypedConstraint* constraint);
|
||||
|
||||
cl_mem getBodyBuffer();
|
||||
|
||||
@@ -37,7 +37,8 @@ struct b3GpuRigidBodyPipelineInternalData
|
||||
|
||||
b3AlignedObjectArray<b3TypedConstraint*> m_joints;
|
||||
class b3GpuNarrowPhase* m_narrowphase;
|
||||
|
||||
b3Vector3 m_gravity;
|
||||
|
||||
};
|
||||
|
||||
#endif //B3_GPU_RIGIDBODY_PIPELINE_INTERNAL_DATA_H
|
||||
|
||||
Reference in New Issue
Block a user