modify loadSoftBody to enable separate render mesh from simulation mesh
This commit is contained in:
@@ -7989,6 +7989,9 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
btSoftBody* psb = NULL;
|
||||||
|
btScalar spring_elastic_stiffness, spring_damping_stiffness;
|
||||||
|
|
||||||
CommonFileIOInterface* fileIO(m_data->m_pluginManager.getFileIOInterface());
|
CommonFileIOInterface* fileIO(m_data->m_pluginManager.getFileIOInterface());
|
||||||
char relativeFileName[1024];
|
char relativeFileName[1024];
|
||||||
char pathPrefix[1024];
|
char pathPrefix[1024];
|
||||||
@@ -7997,20 +8000,38 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar
|
|||||||
{
|
{
|
||||||
b3FileUtils::extractPath(relativeFileName, pathPrefix, 1024);
|
b3FileUtils::extractPath(relativeFileName, pathPrefix, 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add _sim.vtk postfix
|
||||||
|
char relativeSimFileName[1024];
|
||||||
|
char sim_file_ending[9] = "_sim.vtk";
|
||||||
|
strncpy(relativeSimFileName, relativeFileName, strlen(relativeFileName));
|
||||||
|
strncpy(relativeSimFileName + strlen(relativeFileName)-4, sim_file_ending, sizeof(sim_file_ending));
|
||||||
|
|
||||||
const std::string& error_message_prefix = "";
|
const std::string& error_message_prefix = "";
|
||||||
std::string out_found_filename;
|
std::string out_found_filename;
|
||||||
int out_type=0;
|
std::string out_found_sim_filename;
|
||||||
|
int out_type, out_sim_type;
|
||||||
|
|
||||||
|
bool render_mesh_is_sim_mesh = true;
|
||||||
|
|
||||||
bool foundFile = UrdfFindMeshFile(fileIO, pathPrefix, relativeFileName, error_message_prefix, &out_found_filename, &out_type);
|
bool foundFile = UrdfFindMeshFile(fileIO, pathPrefix, relativeFileName, error_message_prefix, &out_found_filename, &out_type);
|
||||||
btSoftBody* psb = NULL;
|
|
||||||
if (foundFile)
|
|
||||||
{
|
|
||||||
btScalar spring_elastic_stiffness, spring_damping_stiffness;
|
|
||||||
if (out_type == UrdfGeometry::FILE_OBJ)
|
if (out_type == UrdfGeometry::FILE_OBJ)
|
||||||
|
{
|
||||||
|
bool foundFile = UrdfFindMeshFile(fileIO, pathPrefix, relativeSimFileName, 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<tinyobj::shape_t> shapes;
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
tinyobj::attrib_t attribute;
|
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())
|
if (!shapes.empty())
|
||||||
{
|
{
|
||||||
const tinyobj::shape_t& shape = shapes[0];
|
const tinyobj::shape_t& shape = shapes[0];
|
||||||
@@ -8039,10 +8060,10 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (out_type == UrdfGeometry::FILE_VTK)
|
else if (out_sim_type == UrdfGeometry::FILE_VTK)
|
||||||
{
|
{
|
||||||
#ifndef SKIP_DEFORMABLE_BODY
|
#ifndef SKIP_DEFORMABLE_BODY
|
||||||
psb = btSoftBodyHelpers::CreateFromVtkFile(m_data->m_dynamicsWorld->getWorldInfo(), out_found_filename.c_str());
|
psb = btSoftBodyHelpers::CreateFromVtkFile(m_data->m_dynamicsWorld->getWorldInfo(), out_found_sim_filename.c_str());
|
||||||
btScalar corotated_mu, corotated_lambda;
|
btScalar corotated_mu, corotated_lambda;
|
||||||
if (clientCmd.m_updateFlags & LOAD_SOFT_BODY_ADD_COROTATED_FORCE)
|
if (clientCmd.m_updateFlags & LOAD_SOFT_BODY_ADD_COROTATED_FORCE)
|
||||||
{
|
{
|
||||||
@@ -8070,16 +8091,18 @@ bool PhysicsServerCommandProcessor::processLoadSoftBodyCommand(const struct Shar
|
|||||||
if (psb != NULL)
|
if (psb != NULL)
|
||||||
{
|
{
|
||||||
#ifndef SKIP_DEFORMABLE_BODY
|
#ifndef SKIP_DEFORMABLE_BODY
|
||||||
|
if (!render_mesh_is_sim_mesh)
|
||||||
|
{
|
||||||
|
// load render mesh
|
||||||
|
btSoftBodyHelpers::readRenderMeshFromObj(out_found_filename.c_str(), psb);
|
||||||
|
btSoftBodyHelpers::interpolateBarycentricWeights(psb);
|
||||||
|
}
|
||||||
btVector3 gravity = m_data->m_dynamicsWorld->getGravity();
|
btVector3 gravity = m_data->m_dynamicsWorld->getGravity();
|
||||||
if (clientCmd.m_updateFlags & LOAD_SOFT_BODY_ADD_GRAVITY_FORCE)
|
if (clientCmd.m_updateFlags & LOAD_SOFT_BODY_ADD_GRAVITY_FORCE)
|
||||||
{
|
{
|
||||||
m_data->m_dynamicsWorld->addForce(psb, new btDeformableGravityForce(gravity));
|
m_data->m_dynamicsWorld->addForce(psb, new btDeformableGravityForce(gravity));
|
||||||
}
|
}
|
||||||
btScalar collision_hardness = 1;
|
btScalar collision_hardness = 1;
|
||||||
if (clientCmd.m_updateFlags & LOAD_SOFT_BODY_SET_COLLISION_HARDNESS)
|
|
||||||
{
|
|
||||||
collision_hardness = loadSoftBodyArgs.m_collisionHardness;
|
|
||||||
}
|
|
||||||
psb->m_cfg.kKHR = collision_hardness;
|
psb->m_cfg.kKHR = collision_hardness;
|
||||||
psb->m_cfg.kCHR = collision_hardness;
|
psb->m_cfg.kCHR = collision_hardness;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user