From 64e5e007e330d34ad8f837389a8a38978c006ea2 Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Sun, 17 Nov 2019 00:01:52 -0800 Subject: [PATCH 1/5] load render mesh from command --- examples/SharedMemory/PhysicsClientC_API.cpp | 18 +++++++++++++ examples/SharedMemory/PhysicsClientC_API.h | 3 ++- .../PhysicsServerCommandProcessor.cpp | 26 +++++-------------- examples/SharedMemory/SharedMemoryCommands.h | 2 ++ 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/examples/SharedMemory/PhysicsClientC_API.cpp b/examples/SharedMemory/PhysicsClientC_API.cpp index 611a75655..5038f6e4b 100644 --- a/examples/SharedMemory/PhysicsClientC_API.cpp +++ b/examples/SharedMemory/PhysicsClientC_API.cpp @@ -338,6 +338,24 @@ B3_SHARED_API int b3LoadSoftBodySetStartOrientation(b3SharedMemoryCommandHandle return 0; } +B3_SHARED_API int b3LoadSoftBodyAddRenderMesh(b3SharedMemoryCommandHandle commandHandle, const char* filename) +{ + struct SharedMemoryCommand* command = (struct SharedMemoryCommand*)commandHandle; + b3Assert(command->m_type == CMD_LOAD_SOFT_BODY); + int len = strlen(filename); + if (len < MAX_FILENAME_LENGTH) + { + strcpy(command->m_loadSoftBodyArguments.m_renderFileName, filename); + } + else + { + command->m_loadSoftBodyArguments.m_renderFileName[0] = 0; + } + command->m_updateFlags |= LOAD_SOFT_BODY_RENDER_MESH; + return 0; + +} + B3_SHARED_API int b3LoadSoftBodyAddCorotatedForce(b3SharedMemoryCommandHandle commandHandle, double corotatedMu, double corotatedLambda) { struct SharedMemoryCommand* command = (struct SharedMemoryCommand*)commandHandle; diff --git a/examples/SharedMemory/PhysicsClientC_API.h b/examples/SharedMemory/PhysicsClientC_API.h index 220e5582f..df9e44895 100644 --- a/examples/SharedMemory/PhysicsClientC_API.h +++ b/examples/SharedMemory/PhysicsClientC_API.h @@ -375,7 +375,6 @@ extern "C" B3_SHARED_API b3SharedMemoryCommandHandle b3InitResetSimulationCommand(b3PhysicsClientHandle physClient); B3_SHARED_API b3SharedMemoryCommandHandle b3InitResetSimulationCommand2(b3SharedMemoryCommandHandle commandHandle); B3_SHARED_API int b3InitResetSimulationSetFlags(b3SharedMemoryCommandHandle commandHandle, int flags); - ///Load a robot from a URDF file. Status type will CMD_URDF_LOADING_COMPLETED. ///Access the robot from the unique body index, through b3GetStatusBodyIndex(statusHandle); B3_SHARED_API b3SharedMemoryCommandHandle b3LoadUrdfCommandInit(b3PhysicsClientHandle physClient, const char* urdfFileName); @@ -634,7 +633,9 @@ extern "C" B3_SHARED_API int b3LoadSoftBodySetCollisionMargin(b3SharedMemoryCommandHandle commandHandle, double collisionMargin); B3_SHARED_API int b3LoadSoftBodySetStartPosition(b3SharedMemoryCommandHandle commandHandle, double startPosX, double startPosY, double startPosZ); B3_SHARED_API int b3LoadSoftBodySetStartOrientation(b3SharedMemoryCommandHandle commandHandle, double startOrnX, double startOrnY, double startOrnZ, double startOrnW); + B3_SHARED_API int b3LoadSoftBodyAddRenderMesh(b3SharedMemoryCommandHandle commandHandle, const char* filename); B3_SHARED_API int b3LoadSoftBodyAddCorotatedForce(b3SharedMemoryCommandHandle commandHandle, double corotatedMu, double corotatedLambda); + B3_SHARED_API int b3LoadSoftBodyAddCorotatedForce(b3SharedMemoryCommandHandle commandHandle, double corotatedMu, double corotatedLambda); B3_SHARED_API int b3LoadSoftBodyAddNeoHookeanForce(b3SharedMemoryCommandHandle commandHandle, double NeoHookeanMu, double NeoHookeanLambda, double NeoHookeanDamping); B3_SHARED_API int b3LoadSoftBodyAddMassSpringForce(b3SharedMemoryCommandHandle commandHandle, double springElasticStiffness , double springDampingStiffness); B3_SHARED_API int b3LoadSoftBodyAddGravityForce(b3SharedMemoryCommandHandle commandHandle, double gravityX, double gravityY, double gravityZ); diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index 74c49a408..4c1e4253a 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -8086,29 +8086,14 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar const std::string& error_message_prefix = ""; std::string out_found_filename; - std::string out_found_sim_filename; - int out_type(0), out_sim_type(0); - - bool render_mesh_is_sim_mesh = true; + int out_type(0); bool foundFile = UrdfFindMeshFile(fileIO, pathPrefix, relativeFileName, error_message_prefix, &out_found_filename, &out_type); if (out_type == UrdfGeometry::FILE_OBJ) - { - foundFile = UrdfFindMeshFile(fileIO, pathPrefix, relativeFileName, error_message_prefix, &out_found_sim_filename, &out_sim_type); - render_mesh_is_sim_mesh = !foundFile; - } - - if (render_mesh_is_sim_mesh) - { - out_sim_type = out_type; - out_found_sim_filename = out_found_filename; - } - - if (out_sim_type == UrdfGeometry::FILE_OBJ) { std::vector shapes; tinyobj::attrib_t attribute; - std::string err = tinyobj::LoadObj(attribute, shapes, out_found_sim_filename.c_str(), "", fileIO); + std::string err = tinyobj::LoadObj(attribute, shapes, out_found_filename.c_str(), "", fileIO); if (!shapes.empty()) { const tinyobj::shape_t& shape = shapes[0]; @@ -8157,13 +8142,13 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar } #endif } - else if (out_sim_type == UrdfGeometry::FILE_VTK) + else if (out_type == UrdfGeometry::FILE_VTK) { #ifndef SKIP_DEFORMABLE_BODY btDeformableMultiBodyDynamicsWorld* deformWorld = getDeformableWorld(); if (deformWorld) { - psb = btSoftBodyHelpers::CreateFromVtkFile(deformWorld->getWorldInfo(), out_found_sim_filename.c_str()); + psb = btSoftBodyHelpers::CreateFromVtkFile(deformWorld->getWorldInfo(), out_found_filename.c_str()); btScalar corotated_mu, corotated_lambda; if (clientCmd.m_updateFlags & LOAD_SOFT_BODY_ADD_COROTATED_FORCE) { @@ -8192,6 +8177,7 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar deformWorld->addForce(psb, springForce); m_data->m_lf.push_back(springForce); } + } #endif } @@ -8200,6 +8186,7 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar { #ifndef SKIP_DEFORMABLE_BODY btDeformableMultiBodyDynamicsWorld* deformWorld = getDeformableWorld(); + bool foundRenderMesh = false; if (deformWorld) { if (!render_mesh_is_sim_mesh) @@ -8208,7 +8195,6 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar { - tinyobj::attrib_t attribute; std::vector shapes; diff --git a/examples/SharedMemory/SharedMemoryCommands.h b/examples/SharedMemory/SharedMemoryCommands.h index ab39daaa0..a03d2ca9f 100644 --- a/examples/SharedMemory/SharedMemoryCommands.h +++ b/examples/SharedMemory/SharedMemoryCommands.h @@ -505,6 +505,7 @@ enum EnumLoadSoftBodyUpdateFlags LOAD_SOFT_BODY_ADD_NEOHOOKEAN_FORCE = 1<<12, LOAD_SOFT_BODY_USE_SELF_COLLISION = 1<<13, LOAD_SOFT_BODY_USE_FACE_CONTACT = 1<<14, + LOAD_SOFT_BODY_RENDER_MESH = 1<<15, }; enum EnumSimParamInternalSimFlags @@ -535,6 +536,7 @@ struct LoadSoftBodyArgs double m_NeoHookeanLambda; double m_NeoHookeanDamping; int m_useFaceContact; + char m_renderFileName[MAX_FILENAME_LENGTH]; }; struct b3LoadSoftBodyResultArgs From 00add5490f3e5976a33d879e00d05ab316deeb3e Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Tue, 19 Nov 2019 21:01:28 -0800 Subject: [PATCH 2/5] fix separate render and sim mesh --- examples/SharedMemory/PhysicsClientC_API.cpp | 8 +- examples/SharedMemory/PhysicsClientC_API.h | 2 +- .../PhysicsServerCommandProcessor.cpp | 169 +++++++++--------- examples/SharedMemory/SharedMemoryCommands.h | 4 +- examples/SharedMemory/SharedMemoryPublic.h | 2 +- 5 files changed, 96 insertions(+), 89 deletions(-) diff --git a/examples/SharedMemory/PhysicsClientC_API.cpp b/examples/SharedMemory/PhysicsClientC_API.cpp index 5038f6e4b..ee506c143 100644 --- a/examples/SharedMemory/PhysicsClientC_API.cpp +++ b/examples/SharedMemory/PhysicsClientC_API.cpp @@ -338,20 +338,20 @@ B3_SHARED_API int b3LoadSoftBodySetStartOrientation(b3SharedMemoryCommandHandle return 0; } -B3_SHARED_API int b3LoadSoftBodyAddRenderMesh(b3SharedMemoryCommandHandle commandHandle, const char* filename) +B3_SHARED_API int b3LoadSoftBodyUpdateSimMesh(b3SharedMemoryCommandHandle commandHandle, const char* filename) { struct SharedMemoryCommand* command = (struct SharedMemoryCommand*)commandHandle; b3Assert(command->m_type == CMD_LOAD_SOFT_BODY); int len = strlen(filename); if (len < MAX_FILENAME_LENGTH) { - strcpy(command->m_loadSoftBodyArguments.m_renderFileName, filename); + strcpy(command->m_loadSoftBodyArguments.m_simFileName, filename); } else { - command->m_loadSoftBodyArguments.m_renderFileName[0] = 0; + command->m_loadSoftBodyArguments.m_simFileName[0] = 0; } - command->m_updateFlags |= LOAD_SOFT_BODY_RENDER_MESH; + command->m_updateFlags |= LOAD_SOFT_BODY_SIM_MESH; return 0; } diff --git a/examples/SharedMemory/PhysicsClientC_API.h b/examples/SharedMemory/PhysicsClientC_API.h index df9e44895..c67f79d9c 100644 --- a/examples/SharedMemory/PhysicsClientC_API.h +++ b/examples/SharedMemory/PhysicsClientC_API.h @@ -633,7 +633,7 @@ extern "C" B3_SHARED_API int b3LoadSoftBodySetCollisionMargin(b3SharedMemoryCommandHandle commandHandle, double collisionMargin); B3_SHARED_API int b3LoadSoftBodySetStartPosition(b3SharedMemoryCommandHandle commandHandle, double startPosX, double startPosY, double startPosZ); B3_SHARED_API int b3LoadSoftBodySetStartOrientation(b3SharedMemoryCommandHandle commandHandle, double startOrnX, double startOrnY, double startOrnZ, double startOrnW); - B3_SHARED_API int b3LoadSoftBodyAddRenderMesh(b3SharedMemoryCommandHandle commandHandle, const char* filename); + B3_SHARED_API int b3LoadSoftBodyUpdateSimMesh(b3SharedMemoryCommandHandle commandHandle, const char* filename); B3_SHARED_API int b3LoadSoftBodyAddCorotatedForce(b3SharedMemoryCommandHandle commandHandle, double corotatedMu, double corotatedLambda); B3_SHARED_API int b3LoadSoftBodyAddCorotatedForce(b3SharedMemoryCommandHandle commandHandle, double corotatedMu, double corotatedLambda); B3_SHARED_API int b3LoadSoftBodyAddNeoHookeanForce(b3SharedMemoryCommandHandle commandHandle, double NeoHookeanMu, double NeoHookeanLambda, double NeoHookeanDamping); diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index 4c1e4253a..1f96b2d09 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -1709,7 +1709,6 @@ struct PhysicsServerCommandProcessorInternalData m_dispatcher(0), m_solver(0), m_collisionConfiguration(0), - #ifndef SKIP_DEFORMABLE_BODY m_deformablebodySolver(0), #endif @@ -2651,23 +2650,25 @@ void PhysicsServerCommandProcessor::createEmptyDynamicsWorld(int flags) bv->setVelocityPrediction(0); m_data->m_broadphase = bv; } - - if (flags & RESET_USE_DEFORMABLE_WORLD) + + if (flags & RESET_USE_SOFT_MULTIBODY_WORLD) { -#ifndef SKIP_DEFORMABLE_BODY - m_data->m_deformablebodySolver = new btDeformableBodySolver(); - btDeformableMultiBodyConstraintSolver* solver = new btDeformableMultiBodyConstraintSolver; - m_data->m_solver = solver; - solver->setDeformableSolver(m_data->m_deformablebodySolver); - m_data->m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, solver, m_data->m_collisionConfiguration, m_data->m_deformablebodySolver); + m_data->m_solver = new btMultiBodyConstraintSolver; +#ifndef SKIP_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD + m_data->m_dynamicsWorld = new btSoftMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, m_data->m_solver, m_data->m_collisionConfiguration); +#else + m_data->m_dynamicsWorld = new btMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, m_data->m_solver, m_data->m_collisionConfiguration); #endif } - if ((0==m_data->m_dynamicsWorld) && (0==(flags&RESET_USE_DISCRETE_DYNAMICS_WORLD))) + if ((0==m_data->m_dynamicsWorld) && (0==(flags&RESET_USE_DISCRETE_DYNAMICS_WORLD))) { -#ifndef SKIP_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD - m_data->m_solver = new btMultiBodyConstraintSolver; - m_data->m_dynamicsWorld = new btSoftMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, m_data->m_solver, m_data->m_collisionConfiguration); +#ifndef SKIP_DEFORMABLE_BODY + m_data->m_deformablebodySolver = new btDeformableBodySolver(); + btDeformableMultiBodyConstraintSolver* solver = new btDeformableMultiBodyConstraintSolver; + m_data->m_solver = solver; + solver->setDeformableSolver(m_data->m_deformablebodySolver); + m_data->m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, solver, m_data->m_collisionConfiguration, m_data->m_deformablebodySolver); #endif } @@ -5126,24 +5127,24 @@ bool PhysicsServerCommandProcessor::processRequestMeshDataCommand(const struct S { btSoftBody* psb = bodyHandle->m_softBody; int totalBytesPerVertex = sizeof(btVector3); - bool separateRenderMesh = (psb->m_renderNodes.size() != 0); - int numVertices = separateRenderMesh ? psb->m_renderNodes.size() : psb->m_nodes.size(); + bool separateRenderMesh = (psb->m_renderNodes.size() != 0); + int numVertices = separateRenderMesh ? psb->m_renderNodes.size() : psb->m_nodes.size(); int maxNumVertices = bufferSizeInBytes / totalBytesPerVertex - 1; int numVerticesRemaining = numVertices - clientCmd.m_requestMeshDataArgs.m_startingVertex; int verticesCopied = btMin(maxNumVertices, numVerticesRemaining); btVector3* verticesOut = (btVector3*)bufferServerToClient; for (int i = 0; i < verticesCopied; ++i) { - if (separateRenderMesh) - { - const btSoftBody::Node& n = psb->m_renderNodes[i + clientCmd.m_requestMeshDataArgs.m_startingVertex]; - verticesOut[i] = n.m_x; - } - else - { - const btSoftBody::Node& n = psb->m_nodes[i + clientCmd.m_requestMeshDataArgs.m_startingVertex]; - verticesOut[i] = n.m_x; - } + if (separateRenderMesh) + { + const btSoftBody::Node& n = psb->m_renderNodes[i + clientCmd.m_requestMeshDataArgs.m_startingVertex]; + verticesOut[i] = n.m_x; + } + else + { + const btSoftBody::Node& n = psb->m_nodes[i + clientCmd.m_requestMeshDataArgs.m_startingVertex]; + verticesOut[i] = n.m_x; + } } serverStatusOut.m_type = CMD_REQUEST_MESH_DATA_COMPLETED; @@ -8069,7 +8070,7 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar { collisionMargin = clientCmd.m_loadSoftBodyArguments.m_collisionMargin; } - + { btSoftBody* psb = NULL; @@ -8083,17 +8084,26 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar b3FileUtils::extractPath(relativeFileName, pathPrefix, 1024); } - const std::string& error_message_prefix = ""; - std::string out_found_filename; - int out_type(0); + std::string out_found_filename, out_found_sim_filename; + int out_type(0), out_sim_type(0); bool foundFile = UrdfFindMeshFile(fileIO, pathPrefix, relativeFileName, error_message_prefix, &out_found_filename, &out_type); - if (out_type == UrdfGeometry::FILE_OBJ) + + if (clientCmd.m_updateFlags & LOAD_SOFT_BODY_SIM_MESH) + { + bool foundSimMesh = UrdfFindMeshFile(fileIO, pathPrefix, loadSoftBodyArgs.m_simFileName, error_message_prefix, &out_found_sim_filename, &out_sim_type); + } + else + { + out_sim_type = out_type; + out_found_sim_filename = out_found_filename; + } + if (out_sim_type == UrdfGeometry::FILE_OBJ) { std::vector shapes; tinyobj::attrib_t attribute; - std::string err = tinyobj::LoadObj(attribute, shapes, out_found_filename.c_str(), "", fileIO); + std::string err = tinyobj::LoadObj(attribute, shapes, out_found_sim_filename.c_str(), "", fileIO); if (!shapes.empty()) { const tinyobj::shape_t& shape = shapes[0]; @@ -8142,13 +8152,13 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar } #endif } - else if (out_type == UrdfGeometry::FILE_VTK) + else if (out_sim_type == UrdfGeometry::FILE_VTK) { #ifndef SKIP_DEFORMABLE_BODY btDeformableMultiBodyDynamicsWorld* deformWorld = getDeformableWorld(); if (deformWorld) { - psb = btSoftBodyHelpers::CreateFromVtkFile(deformWorld->getWorldInfo(), out_found_filename.c_str()); + psb = btSoftBodyHelpers::CreateFromVtkFile(deformWorld->getWorldInfo(), out_found_sim_filename.c_str()); btScalar corotated_mu, corotated_lambda; if (clientCmd.m_updateFlags & LOAD_SOFT_BODY_ADD_COROTATED_FORCE) { @@ -8185,58 +8195,55 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar if (psb != NULL) { #ifndef SKIP_DEFORMABLE_BODY - btDeformableMultiBodyDynamicsWorld* deformWorld = getDeformableWorld(); - bool foundRenderMesh = false; + btDeformableMultiBodyDynamicsWorld* deformWorld = getDeformableWorld(); if (deformWorld) { - if (!render_mesh_is_sim_mesh) - { - // load render mesh + // load render mesh + if (out_found_sim_filename != out_found_filename) + { + // load render mesh + { + tinyobj::attrib_t attribute; + std::vector shapes; + + std::string err = tinyobj::LoadObj(attribute, shapes, out_found_filename.c_str(), pathPrefix, m_data->m_pluginManager.getFileIOInterface()); + for (int s = 0; s < (int)shapes.size(); s++) + { + tinyobj::shape_t& shape = shapes[s]; + int faceCount = shape.mesh.indices.size(); + int vertexCount = attribute.vertices.size()/3; + for (int v=0;vm_renderNodes.push_back(n); + } - { - tinyobj::attrib_t attribute; - std::vector shapes; - - std::string err = tinyobj::LoadObj(attribute, shapes, out_found_filename.c_str(), pathPrefix, m_data->m_pluginManager.getFileIOInterface()); - - for (int s = 0; s < (int)shapes.size(); s++) - { - tinyobj::shape_t& shape = shapes[s]; - int faceCount = shape.mesh.indices.size(); - int vertexCount = attribute.vertices.size()/3; - for (int v=0;vm_renderNodes.push_back(n); - } - - for (int f = 0; f < faceCount; f += 3) - { - if (f < 0 && f >= int(shape.mesh.indices.size())) - { - continue; - } - tinyobj::index_t v_0 = shape.mesh.indices[f]; - tinyobj::index_t v_1 = shape.mesh.indices[f + 1]; - tinyobj::index_t v_2 = shape.mesh.indices[f + 2]; - btSoftBody::Face ff; - ff.m_n[0] = &psb->m_renderNodes[v_0.vertex_index]; - ff.m_n[1] = &psb->m_renderNodes[v_1.vertex_index]; - ff.m_n[2] = &psb->m_renderNodes[v_2.vertex_index]; - psb->m_renderFaces.push_back(ff); - } - } - - } - - btSoftBodyHelpers::interpolateBarycentricWeights(psb); - } - else - { - psb->m_renderNodes.resize(0); - } + for (int f = 0; f < faceCount; f += 3) + { + if (f < 0 && f >= int(shape.mesh.indices.size())) + { + continue; + } + tinyobj::index_t v_0 = shape.mesh.indices[f]; + tinyobj::index_t v_1 = shape.mesh.indices[f + 1]; + tinyobj::index_t v_2 = shape.mesh.indices[f + 2]; + btSoftBody::Face ff; + ff.m_n[0] = &psb->m_renderNodes[v_0.vertex_index]; + ff.m_n[1] = &psb->m_renderNodes[v_1.vertex_index]; + ff.m_n[2] = &psb->m_renderNodes[v_2.vertex_index]; + psb->m_renderFaces.push_back(ff); + } + } + + } + btSoftBodyHelpers::interpolateBarycentricWeights(psb); + } + else + { + psb->m_renderNodes.resize(0); + } btVector3 gravity = m_data->m_dynamicsWorld->getGravity(); btDeformableLagrangianForce* gravityForce = new btDeformableGravityForce(gravity); deformWorld->addForce(psb, gravityForce); diff --git a/examples/SharedMemory/SharedMemoryCommands.h b/examples/SharedMemory/SharedMemoryCommands.h index a03d2ca9f..ccb6357fe 100644 --- a/examples/SharedMemory/SharedMemoryCommands.h +++ b/examples/SharedMemory/SharedMemoryCommands.h @@ -505,7 +505,7 @@ enum EnumLoadSoftBodyUpdateFlags LOAD_SOFT_BODY_ADD_NEOHOOKEAN_FORCE = 1<<12, LOAD_SOFT_BODY_USE_SELF_COLLISION = 1<<13, LOAD_SOFT_BODY_USE_FACE_CONTACT = 1<<14, - LOAD_SOFT_BODY_RENDER_MESH = 1<<15, + LOAD_SOFT_BODY_SIM_MESH = 1<<15, }; enum EnumSimParamInternalSimFlags @@ -536,7 +536,7 @@ struct LoadSoftBodyArgs double m_NeoHookeanLambda; double m_NeoHookeanDamping; int m_useFaceContact; - char m_renderFileName[MAX_FILENAME_LENGTH]; + char m_simFileName[MAX_FILENAME_LENGTH]; }; struct b3LoadSoftBodyResultArgs diff --git a/examples/SharedMemory/SharedMemoryPublic.h b/examples/SharedMemory/SharedMemoryPublic.h index feed391a8..fa7d02f2b 100644 --- a/examples/SharedMemory/SharedMemoryPublic.h +++ b/examples/SharedMemory/SharedMemoryPublic.h @@ -567,7 +567,7 @@ enum b3NotificationType enum b3ResetSimulationFlags { - RESET_USE_DEFORMABLE_WORLD=1, + RESET_USE_SOFT_MULTIBODY_WORLD=1, RESET_USE_DISCRETE_DYNAMICS_WORLD=2, RESET_USE_SIMPLE_BROADPHASE=4, }; From edffb0cc551d0ef6139bc0b0a78df270f13051a9 Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Tue, 19 Nov 2019 23:09:49 -0800 Subject: [PATCH 3/5] update pybullet examples --- examples/pybullet/examples/deformable_anchor.py | 2 +- examples/pybullet/examples/deformable_ball.py | 4 ++-- examples/pybullet/examples/deformable_torus.py | 2 -- examples/pybullet/examples/load_soft_body.py | 1 + examples/pybullet/pybullet.c | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/pybullet/examples/deformable_anchor.py b/examples/pybullet/examples/deformable_anchor.py index 135a55c71..66753b0a6 100644 --- a/examples/pybullet/examples/deformable_anchor.py +++ b/examples/pybullet/examples/deformable_anchor.py @@ -3,7 +3,7 @@ from time import sleep physicsClient = p.connect(p.GUI) -p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD) +#p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD) gravZ=-10 p.setGravity(0, 0, gravZ) diff --git a/examples/pybullet/examples/deformable_ball.py b/examples/pybullet/examples/deformable_ball.py index 8803e2fb2..757994ad5 100644 --- a/examples/pybullet/examples/deformable_ball.py +++ b/examples/pybullet/examples/deformable_ball.py @@ -3,7 +3,7 @@ from time import sleep physicsClient = p.connect(p.GUI) -p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD) +#p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD) p.setGravity(0, 0, -10) @@ -24,4 +24,4 @@ while p.isConnected(): sleep(1./240.) #p.resetSimulation() -#p.stopStateLogging(logId) \ No newline at end of file +#p.stopStateLogging(logId) diff --git a/examples/pybullet/examples/deformable_torus.py b/examples/pybullet/examples/deformable_torus.py index ff02237d6..e71d0653c 100644 --- a/examples/pybullet/examples/deformable_torus.py +++ b/examples/pybullet/examples/deformable_torus.py @@ -3,8 +3,6 @@ from time import sleep physicsClient = p.connect(p.GUI) -p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD) - p.setGravity(0, 0, -10) planeId = p.loadURDF("plane.urdf", [0,0,-2]) diff --git a/examples/pybullet/examples/load_soft_body.py b/examples/pybullet/examples/load_soft_body.py index 3c55ca2e6..1e86d59bd 100644 --- a/examples/pybullet/examples/load_soft_body.py +++ b/examples/pybullet/examples/load_soft_body.py @@ -2,6 +2,7 @@ import pybullet as p from time import sleep physicsClient = p.connect(p.GUI) +p.resetSimulation(p.RESET_USE_SOFT_MULTIBODY_WORLD) p.setGravity(0, 0, -10) planeId = p.loadURDF("plane.urdf", [0,0,-2]) boxId = p.loadURDF("cube.urdf", [0,3,2],useMaximalCoordinates = True) diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index 0857ea0da..faaa971fb 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -12466,7 +12466,7 @@ initpybullet(void) //PyModule_AddIntConstant(m, "CONSTRAINT_SOLVER_LCP_NNCF",eConstraintSolverLCP_NNCG); //PyModule_AddIntConstant(m, "CONSTRAINT_SOLVER_LCP_BLOCK",eConstraintSolverLCP_BLOCK_PGS); - PyModule_AddIntConstant(m, "RESET_USE_DEFORMABLE_WORLD", RESET_USE_DEFORMABLE_WORLD); + PyModule_AddIntConstant(m, "RESET_USE_SOFT_MULTIBODY_WORLD", RESET_USE_SOFT_MULTIBODY_WORLD); PyModule_AddIntConstant(m, "RESET_USE_DISCRETE_DYNAMICS_WORLD", RESET_USE_DISCRETE_DYNAMICS_WORLD); PyModule_AddIntConstant(m, "RESET_USE_SIMPLE_BROADPHASE", RESET_USE_SIMPLE_BROADPHASE); From fa7cb25c95dd61127564a224d532afbf6a8d93ff Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Wed, 20 Nov 2019 23:47:15 -0800 Subject: [PATCH 4/5] revert the default world to SOFT_MULTIBODY_WORLD --- .../PhysicsServerCommandProcessor.cpp | 24 +++++++++---------- examples/SharedMemory/SharedMemoryPublic.h | 2 +- .../pybullet/examples/deformable_anchor.py | 2 +- examples/pybullet/examples/deformable_ball.py | 2 +- .../pybullet/examples/deformable_torus.py | 2 ++ examples/pybullet/examples/load_soft_body.py | 1 - examples/pybullet/pybullet.c | 2 +- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index 1f96b2d09..2231eb98a 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -2651,24 +2651,24 @@ void PhysicsServerCommandProcessor::createEmptyDynamicsWorld(int flags) m_data->m_broadphase = bv; } - if (flags & RESET_USE_SOFT_MULTIBODY_WORLD) + if (flags & RESET_USE_DEFORMABLE_WORLD) { - m_data->m_solver = new btMultiBodyConstraintSolver; -#ifndef SKIP_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD - m_data->m_dynamicsWorld = new btSoftMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, m_data->m_solver, m_data->m_collisionConfiguration); -#else - m_data->m_dynamicsWorld = new btMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, m_data->m_solver, m_data->m_collisionConfiguration); +#ifndef SKIP_DEFORMABLE_BODY + m_data->m_deformablebodySolver = new btDeformableBodySolver(); + btDeformableMultiBodyConstraintSolver* solver = new btDeformableMultiBodyConstraintSolver; + m_data->m_solver = solver; + solver->setDeformableSolver(m_data->m_deformablebodySolver); + m_data->m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, solver, m_data->m_collisionConfiguration, m_data->m_deformablebodySolver); #endif } if ((0==m_data->m_dynamicsWorld) && (0==(flags&RESET_USE_DISCRETE_DYNAMICS_WORLD))) { -#ifndef SKIP_DEFORMABLE_BODY - m_data->m_deformablebodySolver = new btDeformableBodySolver(); - btDeformableMultiBodyConstraintSolver* solver = new btDeformableMultiBodyConstraintSolver; - m_data->m_solver = solver; - solver->setDeformableSolver(m_data->m_deformablebodySolver); - m_data->m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, solver, m_data->m_collisionConfiguration, m_data->m_deformablebodySolver); + m_data->m_solver = new btMultiBodyConstraintSolver; +#ifndef SKIP_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD + m_data->m_dynamicsWorld = new btSoftMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, m_data->m_solver, m_data->m_collisionConfiguration); +#else + m_data->m_dynamicsWorld = new btMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, m_data->m_solver, m_data->m_collisionConfiguration); #endif } diff --git a/examples/SharedMemory/SharedMemoryPublic.h b/examples/SharedMemory/SharedMemoryPublic.h index fa7d02f2b..feed391a8 100644 --- a/examples/SharedMemory/SharedMemoryPublic.h +++ b/examples/SharedMemory/SharedMemoryPublic.h @@ -567,7 +567,7 @@ enum b3NotificationType enum b3ResetSimulationFlags { - RESET_USE_SOFT_MULTIBODY_WORLD=1, + RESET_USE_DEFORMABLE_WORLD=1, RESET_USE_DISCRETE_DYNAMICS_WORLD=2, RESET_USE_SIMPLE_BROADPHASE=4, }; diff --git a/examples/pybullet/examples/deformable_anchor.py b/examples/pybullet/examples/deformable_anchor.py index 66753b0a6..666334628 100644 --- a/examples/pybullet/examples/deformable_anchor.py +++ b/examples/pybullet/examples/deformable_anchor.py @@ -2,8 +2,8 @@ import pybullet as p from time import sleep physicsClient = p.connect(p.GUI) +p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD) -#p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD) gravZ=-10 p.setGravity(0, 0, gravZ) diff --git a/examples/pybullet/examples/deformable_ball.py b/examples/pybullet/examples/deformable_ball.py index 757994ad5..4ff81b613 100644 --- a/examples/pybullet/examples/deformable_ball.py +++ b/examples/pybullet/examples/deformable_ball.py @@ -3,7 +3,7 @@ from time import sleep physicsClient = p.connect(p.GUI) -#p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD) +p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD) p.setGravity(0, 0, -10) diff --git a/examples/pybullet/examples/deformable_torus.py b/examples/pybullet/examples/deformable_torus.py index e71d0653c..ff02237d6 100644 --- a/examples/pybullet/examples/deformable_torus.py +++ b/examples/pybullet/examples/deformable_torus.py @@ -3,6 +3,8 @@ from time import sleep physicsClient = p.connect(p.GUI) +p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD) + p.setGravity(0, 0, -10) planeId = p.loadURDF("plane.urdf", [0,0,-2]) diff --git a/examples/pybullet/examples/load_soft_body.py b/examples/pybullet/examples/load_soft_body.py index 1e86d59bd..3c55ca2e6 100644 --- a/examples/pybullet/examples/load_soft_body.py +++ b/examples/pybullet/examples/load_soft_body.py @@ -2,7 +2,6 @@ import pybullet as p from time import sleep physicsClient = p.connect(p.GUI) -p.resetSimulation(p.RESET_USE_SOFT_MULTIBODY_WORLD) p.setGravity(0, 0, -10) planeId = p.loadURDF("plane.urdf", [0,0,-2]) boxId = p.loadURDF("cube.urdf", [0,3,2],useMaximalCoordinates = True) diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index faaa971fb..0857ea0da 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -12466,7 +12466,7 @@ initpybullet(void) //PyModule_AddIntConstant(m, "CONSTRAINT_SOLVER_LCP_NNCF",eConstraintSolverLCP_NNCG); //PyModule_AddIntConstant(m, "CONSTRAINT_SOLVER_LCP_BLOCK",eConstraintSolverLCP_BLOCK_PGS); - PyModule_AddIntConstant(m, "RESET_USE_SOFT_MULTIBODY_WORLD", RESET_USE_SOFT_MULTIBODY_WORLD); + PyModule_AddIntConstant(m, "RESET_USE_DEFORMABLE_WORLD", RESET_USE_DEFORMABLE_WORLD); PyModule_AddIntConstant(m, "RESET_USE_DISCRETE_DYNAMICS_WORLD", RESET_USE_DISCRETE_DYNAMICS_WORLD); PyModule_AddIntConstant(m, "RESET_USE_SIMPLE_BROADPHASE", RESET_USE_SIMPLE_BROADPHASE); From f237a40621d4d03cf169a055f4ddd913ac7b2471 Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Thu, 21 Nov 2019 00:09:32 -0800 Subject: [PATCH 5/5] add a pybullet example to compare the result of soft body and deformable body --- examples/pybullet/examples/test_inertia.py | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/pybullet/examples/test_inertia.py diff --git a/examples/pybullet/examples/test_inertia.py b/examples/pybullet/examples/test_inertia.py new file mode 100644 index 000000000..a290f3bac --- /dev/null +++ b/examples/pybullet/examples/test_inertia.py @@ -0,0 +1,28 @@ +import pybullet as p +from time import sleep + +physicsClient = p.connect(p.GUI) + +useDeformable = True +if useDeformable: + p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD) + +gravZ=-10 +p.setGravity(0, 0, gravZ) + +planeOrn = [0,0,0,1]#p.getQuaternionFromEuler([0.3,0,0]) +planeId = p.loadURDF("plane.urdf", [0,0,-2],planeOrn) + +boxId = p.loadURDF("cube.urdf", [0,1,2],useMaximalCoordinates = True) + +clothId = p.loadSoftBody("bunny.obj", basePosition = [0,0,2], scale = 0.5, mass = 1., useNeoHookean = 0, useBendingSprings=1, useMassSpring=1, springElasticStiffness=100, springDampingStiffness=.001, useSelfCollision = 0, frictionCoeff = .5, useFaceContact=1) + +p.setTimeStep(0.0005) + +p.setRealTimeSimulation(1) + + +while p.isConnected(): + p.setGravity(0,0,gravZ) + sleep(1./240.) +