From 64e5e007e330d34ad8f837389a8a38978c006ea2 Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Sun, 17 Nov 2019 00:01:52 -0800 Subject: [PATCH] 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