diff --git a/examples/RobotSimulator/b3RobotSimulatorClientAPI.cpp b/examples/RobotSimulator/b3RobotSimulatorClientAPI.cpp index 6b4ca19bb..1a7bf5b77 100644 --- a/examples/RobotSimulator/b3RobotSimulatorClientAPI.cpp +++ b/examples/RobotSimulator/b3RobotSimulatorClientAPI.cpp @@ -1143,7 +1143,7 @@ void b3RobotSimulatorClientAPI::submitProfileTiming(const std::string& profileN b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle); } -void b3RobotSimulatorClientAPI::loadSoftBody(double scale, double mass, double collisionMargin) +void b3RobotSimulatorClientAPI::loadSoftBody(const std::string& fileName, double scale, double mass, double collisionMargin) { if (!isConnected()) { @@ -1151,7 +1151,7 @@ void b3RobotSimulatorClientAPI::loadSoftBody(double scale, double mass, double c return; } - b3SharedMemoryCommandHandle command = b3LoadSoftBodyCommandInit(m_data->m_physicsClientHandle); + b3SharedMemoryCommandHandle command = b3LoadSoftBodyCommandInit(m_data->m_physicsClientHandle, fileName.c_str()); b3LoadSoftBodySetScale(command, scale); b3LoadSoftBodySetMass(command, mass); b3LoadSoftBodySetCollisionMargin(command, collisionMargin); diff --git a/examples/RobotSimulator/b3RobotSimulatorClientAPI.h b/examples/RobotSimulator/b3RobotSimulatorClientAPI.h index 372fbb4a9..d2bee5338 100644 --- a/examples/RobotSimulator/b3RobotSimulatorClientAPI.h +++ b/examples/RobotSimulator/b3RobotSimulatorClientAPI.h @@ -229,7 +229,7 @@ public: //////////////// INTERNAL - void loadSoftBody(double scale, double mass, double collisionMargin); + void loadSoftBody(const std::string& fileName, double scale, double mass, double collisionMargin); //setGuiHelper is only used when embedded in existing example browser void setGuiHelper(struct GUIHelperInterface* guiHelper); diff --git a/examples/RoboticsLearning/GripperGraspExample.cpp b/examples/RoboticsLearning/GripperGraspExample.cpp index 5869ba7fb..222114779 100644 --- a/examples/RoboticsLearning/GripperGraspExample.cpp +++ b/examples/RoboticsLearning/GripperGraspExample.cpp @@ -336,7 +336,7 @@ public: } m_robotSim.setGravity(b3MakeVector3(0,0,-10)); - m_robotSim.loadSoftBody(0.1,0.1,0.02); + m_robotSim.loadSoftBody("bunny.obj",0.1,0.1,0.02); b3JointInfo revoluteJoint1; revoluteJoint1.m_parentFrame[0] = -0.055; @@ -412,7 +412,7 @@ public: m_robotSim.loadURDF("plane.urdf", args); } m_robotSim.setGravity(b3MakeVector3(0,0,-10)); - m_robotSim.loadSoftBody(0.3,10.0,0.1); + m_robotSim.loadSoftBody("bunny.obj",0.3,10.0,0.1); } } virtual void exitPhysics() diff --git a/examples/SharedMemory/PhysicsClientC_API.cpp b/examples/SharedMemory/PhysicsClientC_API.cpp index bccd60a32..827efa0be 100644 --- a/examples/SharedMemory/PhysicsClientC_API.cpp +++ b/examples/SharedMemory/PhysicsClientC_API.cpp @@ -256,18 +256,31 @@ B3_SHARED_API void b3LoadMJCFCommandSetFlags(b3SharedMemoryCommandHandle command } } -B3_SHARED_API b3SharedMemoryCommandHandle b3LoadSoftBodyCommandInit(b3PhysicsClientHandle physClient) +B3_SHARED_API b3SharedMemoryCommandHandle b3LoadSoftBodyCommandInit(b3PhysicsClientHandle physClient, const char* fileName) { PhysicsClient* cl = (PhysicsClient* ) physClient; b3Assert(cl); b3Assert(cl->canSubmitCommand()); - - struct SharedMemoryCommand* command = cl->getAvailableSharedMemoryCommand(); - b3Assert(command); - command->m_type = CMD_LOAD_SOFT_BODY; - command->m_updateFlags = 0; - - return (b3SharedMemoryCommandHandle) command; + + if (cl->canSubmitCommand()) + { + struct SharedMemoryCommand* command = cl->getAvailableSharedMemoryCommand(); + b3Assert(command); + command->m_type = CMD_LOAD_SOFT_BODY; + int len = strlen(fileName); + if (len < MAX_FILENAME_LENGTH) + { + strcpy(command->m_loadSoftBodyArguments.m_fileName, fileName); + } + else + { + command->m_loadSoftBodyArguments.m_fileName[0] = 0; + } + command->m_updateFlags = LOAD_SOFT_BODY_FILE_NAME; + + return (b3SharedMemoryCommandHandle) command; + } + return 0; } B3_SHARED_API int b3LoadSoftBodySetScale(b3SharedMemoryCommandHandle commandHandle, double scale) diff --git a/examples/SharedMemory/PhysicsClientC_API.h b/examples/SharedMemory/PhysicsClientC_API.h index 177d4e492..c2f11006f 100644 --- a/examples/SharedMemory/PhysicsClientC_API.h +++ b/examples/SharedMemory/PhysicsClientC_API.h @@ -512,7 +512,7 @@ B3_SHARED_API void b3ApplyExternalForce(b3SharedMemoryCommandHandle commandHandl B3_SHARED_API void b3ApplyExternalTorque(b3SharedMemoryCommandHandle commandHandle, int bodyUniqueId, int linkId, const double torque[/*3*/], int flag); ///experiments of robots interacting with non-rigid objects (such as btSoftBody) -B3_SHARED_API b3SharedMemoryCommandHandle b3LoadSoftBodyCommandInit(b3PhysicsClientHandle physClient); +B3_SHARED_API b3SharedMemoryCommandHandle b3LoadSoftBodyCommandInit(b3PhysicsClientHandle physClient, const char* fileName); B3_SHARED_API int b3LoadSoftBodySetScale(b3SharedMemoryCommandHandle commandHandle, double scale); B3_SHARED_API int b3LoadSoftBodySetMass(b3SharedMemoryCommandHandle commandHandle, double mass); B3_SHARED_API int b3LoadSoftBodySetCollisionMargin(b3SharedMemoryCommandHandle commandHandle, double collisionMargin); diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index 874cc7929..84247f9e7 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -5668,6 +5668,14 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar double scale = 0.1; double mass = 0.1; double collisionMargin = 0.02; + const LoadSoftBodyArgs& loadSoftBodyArgs = clientCmd.m_loadSoftBodyArguments; + if (m_data->m_verboseOutput) + { + b3Printf("Processed CMD_LOAD_SOFT_BODY:%s", loadSoftBodyArgs.m_fileName); + } + btAssert((clientCmd.m_updateFlags & LOAD_SOFT_BODY_FILE_NAME) !=0); + btAssert(loadSoftBodyArgs.m_fileName); + if (clientCmd.m_updateFlags & LOAD_SOFT_BODY_UPDATE_SCALE) { scale = clientCmd.m_loadSoftBodyArguments.m_scale; @@ -5693,7 +5701,7 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar char relativeFileName[1024]; char pathPrefix[1024]; pathPrefix[0] = 0; - if (b3ResourcePath::findResourcePath("bunny.obj", relativeFileName, 1024)) + if (b3ResourcePath::findResourcePath(loadSoftBodyArgs.m_fileName, relativeFileName, 1024)) { b3FileUtils::extractPath(relativeFileName, pathPrefix, 1024); } diff --git a/examples/SharedMemory/SharedMemoryCommands.h b/examples/SharedMemory/SharedMemoryCommands.h index e4f27b6e6..202556d73 100644 --- a/examples/SharedMemory/SharedMemoryCommands.h +++ b/examples/SharedMemory/SharedMemoryCommands.h @@ -430,9 +430,10 @@ enum EnumSimParamUpdateFlags enum EnumLoadSoftBodyUpdateFlags { - LOAD_SOFT_BODY_UPDATE_SCALE=1, - LOAD_SOFT_BODY_UPDATE_MASS=2, - LOAD_SOFT_BODY_UPDATE_COLLISION_MARGIN=4 + LOAD_SOFT_BODY_FILE_NAME=1, + LOAD_SOFT_BODY_UPDATE_SCALE=2, + LOAD_SOFT_BODY_UPDATE_MASS=4, + LOAD_SOFT_BODY_UPDATE_COLLISION_MARGIN=8 }; enum EnumSimParamInternalSimFlags @@ -446,6 +447,7 @@ enum EnumSimParamInternalSimFlags struct LoadSoftBodyArgs { + char m_fileName[MAX_FILENAME_LENGTH]; double m_scale; double m_mass; double m_collisionMargin;