2015-04-23 22:41:17 +00:00
|
|
|
/* Copyright (C) 2015 Google
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
2018-10-31 18:02:19 +00:00
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
2015-04-23 22:41:17 +00:00
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
2015-06-29 05:12:59 +00:00
|
|
|
#include "BulletUrdfImporter.h"
|
2016-06-19 01:02:20 +00:00
|
|
|
#include "../../CommonInterfaces/CommonRenderInterface.h"
|
2018-09-23 21:17:31 +00:00
|
|
|
#include "../../ThirdPartyLibs/Wavefront/tiny_obj_loader.h"
|
2015-04-22 23:35:27 +00:00
|
|
|
#include "URDFImporterInterface.h"
|
|
|
|
#include "btBulletCollisionCommon.h"
|
|
|
|
#include "../ImportObjDemo/LoadMeshFromObj.h"
|
|
|
|
#include "../ImportSTLDemo/LoadMeshFromSTL.h"
|
|
|
|
#include "../ImportColladaDemo/LoadMeshFromCollada.h"
|
2018-09-23 21:17:31 +00:00
|
|
|
#include "BulletCollision/CollisionShapes/btShapeHull.h" //to create a tesselation of a generic btConvexShape
|
2018-04-16 20:57:43 +00:00
|
|
|
#include "BulletCollision/CollisionShapes/btSdfCollisionShape.h"
|
2016-05-06 20:57:48 +00:00
|
|
|
#include "../../CommonInterfaces/CommonGUIHelperInterface.h"
|
2018-10-09 04:27:08 +00:00
|
|
|
#include "../../CommonInterfaces/CommonFileIOInterface.h"
|
2015-04-22 23:35:27 +00:00
|
|
|
#include "Bullet3Common/b3FileUtils.h"
|
2015-04-23 22:41:17 +00:00
|
|
|
#include <string>
|
2015-07-04 01:17:14 +00:00
|
|
|
#include "../../Utils/b3ResourcePath.h"
|
2018-10-09 04:27:08 +00:00
|
|
|
#include "../../Utils/b3BulletDefaultFileIO.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
#include "URDF2Bullet.h" //for flags
|
2016-06-19 01:02:20 +00:00
|
|
|
#include "../ImportMeshUtility/b3ImportMeshUtility.h"
|
2015-04-23 22:41:17 +00:00
|
|
|
|
2016-09-20 19:37:13 +00:00
|
|
|
static btScalar gUrdfDefaultCollisionMargin = 0.001;
|
2015-04-23 22:41:17 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
2017-03-08 11:49:39 +00:00
|
|
|
#include <list>
|
2015-06-28 21:09:21 +00:00
|
|
|
#include "UrdfParser.h"
|
2015-04-23 22:41:17 +00:00
|
|
|
|
2018-10-09 04:27:08 +00:00
|
|
|
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
ATTRIBUTE_ALIGNED16(struct)
|
|
|
|
BulletURDFInternalData
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
2017-01-16 21:05:26 +00:00
|
|
|
BT_DECLARE_ALIGNED_ALLOCATOR();
|
2018-10-09 04:27:08 +00:00
|
|
|
b3BulletDefaultFileIO m_defaultFileIO;
|
2015-06-28 21:09:21 +00:00
|
|
|
UrdfParser m_urdfParser;
|
2015-04-22 23:35:27 +00:00
|
|
|
struct GUIHelperInterface* m_guiHelper;
|
2018-10-09 04:27:08 +00:00
|
|
|
struct CommonFileIOInterface* m_fileIO;
|
2017-03-08 11:49:39 +00:00
|
|
|
std::string m_sourceFile;
|
2015-06-28 21:09:21 +00:00
|
|
|
char m_pathPrefix[1024];
|
2016-08-11 21:55:30 +00:00
|
|
|
int m_bodyId;
|
2018-09-23 21:17:31 +00:00
|
|
|
btHashMap<btHashInt, UrdfMaterialColor> m_linkColors;
|
|
|
|
btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes;
|
2018-02-22 07:22:16 +00:00
|
|
|
btAlignedObjectArray<int> m_allocatedTextures;
|
2017-08-24 16:16:11 +00:00
|
|
|
mutable btAlignedObjectArray<btTriangleMesh*> m_allocatedMeshInterfaces;
|
2018-01-08 20:25:56 +00:00
|
|
|
btHashMap<btHashPtr, UrdfCollision> m_bulletCollisionShape2UrdfCollision;
|
|
|
|
|
2018-01-17 20:48:48 +00:00
|
|
|
UrdfRenderingInterface* m_customVisualShapesConverter;
|
2017-10-06 20:46:24 +00:00
|
|
|
bool m_enableTinyRenderer;
|
2018-01-09 18:10:36 +00:00
|
|
|
int m_flags;
|
2015-04-23 22:41:17 +00:00
|
|
|
|
2017-03-08 11:49:39 +00:00
|
|
|
void setSourceFile(const std::string& relativeFileName, const std::string& prefix)
|
|
|
|
{
|
|
|
|
m_sourceFile = relativeFileName;
|
|
|
|
m_urdfParser.setSourceFile(relativeFileName);
|
|
|
|
strncpy(m_pathPrefix, prefix.c_str(), sizeof(m_pathPrefix));
|
2018-09-23 21:17:31 +00:00
|
|
|
m_pathPrefix[sizeof(m_pathPrefix) - 1] = 0; // required, strncpy doesn't write zero on overflow
|
2017-03-08 11:49:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-09 04:27:08 +00:00
|
|
|
BulletURDFInternalData(CommonFileIOInterface* fileIO)
|
|
|
|
:m_urdfParser(fileIO? fileIO : &m_defaultFileIO),
|
|
|
|
m_fileIO(fileIO? fileIO : &m_defaultFileIO)
|
2017-03-08 11:49:39 +00:00
|
|
|
{
|
2017-10-06 20:46:24 +00:00
|
|
|
m_enableTinyRenderer = true;
|
2017-03-08 11:49:39 +00:00
|
|
|
m_pathPrefix[0] = 0;
|
2018-09-23 21:17:31 +00:00
|
|
|
m_flags = 0;
|
2017-03-08 11:49:39 +00:00
|
|
|
}
|
2017-08-14 21:59:41 +00:00
|
|
|
|
|
|
|
void setGlobalScaling(btScalar scaling)
|
|
|
|
{
|
|
|
|
m_urdfParser.setGlobalScaling(scaling);
|
|
|
|
}
|
2018-10-09 04:27:08 +00:00
|
|
|
|
2018-10-31 18:02:19 +00:00
|
|
|
|
2017-03-08 11:49:39 +00:00
|
|
|
};
|
2016-04-11 23:42:02 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
void BulletURDFImporter::printTree()
|
2015-04-23 22:41:17 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// btAssert(0);
|
2015-04-23 22:41:17 +00:00
|
|
|
}
|
|
|
|
|
2018-10-09 04:27:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BulletURDFImporter::BulletURDFImporter(struct GUIHelperInterface* helper, UrdfRenderingInterface* customConverter, struct CommonFileIOInterface* fileIO,double globalScaling, int flags)
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
2018-10-09 04:27:08 +00:00
|
|
|
m_data = new BulletURDFInternalData(fileIO);
|
2017-08-14 21:59:41 +00:00
|
|
|
m_data->setGlobalScaling(globalScaling);
|
2018-01-09 18:10:36 +00:00
|
|
|
m_data->m_flags = flags;
|
2015-04-22 23:35:27 +00:00
|
|
|
m_data->m_guiHelper = helper;
|
2016-05-20 01:37:15 +00:00
|
|
|
m_data->m_customVisualShapesConverter = customConverter;
|
2015-04-23 22:41:17 +00:00
|
|
|
}
|
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
struct BulletErrorLogger : public ErrorLogger
|
|
|
|
{
|
|
|
|
int m_numErrors;
|
|
|
|
int m_numWarnings;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
BulletErrorLogger()
|
2018-09-23 21:17:31 +00:00
|
|
|
: m_numErrors(0),
|
|
|
|
m_numWarnings(0)
|
2015-06-28 21:09:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual void reportError(const char* error)
|
|
|
|
{
|
|
|
|
m_numErrors++;
|
|
|
|
b3Error(error);
|
|
|
|
}
|
|
|
|
virtual void reportWarning(const char* warning)
|
|
|
|
{
|
|
|
|
m_numWarnings++;
|
|
|
|
b3Warning(warning);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
virtual void printMessage(const char* msg)
|
|
|
|
{
|
|
|
|
b3Printf(msg);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
};
|
2015-06-28 21:09:21 +00:00
|
|
|
|
2018-10-02 15:39:47 +00:00
|
|
|
bool BulletURDFImporter::loadURDF(const char* fileName, bool forceFixedBase)
|
2015-04-23 22:41:17 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (strlen(fileName) == 0)
|
|
|
|
return false;
|
2015-04-23 22:41:17 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
//int argc=0;
|
2015-04-23 22:41:17 +00:00
|
|
|
char relativeFileName[1024];
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-04-23 22:41:17 +00:00
|
|
|
b3FileUtils fu;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-07-04 01:17:14 +00:00
|
|
|
//bool fileFound = fu.findFile(fileName, relativeFileName, 1024);
|
2018-10-29 17:25:40 +00:00
|
|
|
bool fileFound = m_data->m_fileIO->findResourcePath(fileName, relativeFileName, 1024);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-04-23 22:41:17 +00:00
|
|
|
std::string xml_string;
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!fileFound)
|
|
|
|
{
|
2017-03-08 11:49:39 +00:00
|
|
|
b3Warning("URDF file '%s' not found\n", fileName);
|
2015-04-23 22:41:17 +00:00
|
|
|
return false;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2017-03-08 11:49:39 +00:00
|
|
|
{
|
|
|
|
char path[1024];
|
|
|
|
fu.extractPath(relativeFileName, path, sizeof(path));
|
|
|
|
m_data->setSourceFile(relativeFileName, path);
|
2015-04-23 22:41:17 +00:00
|
|
|
|
2018-10-09 04:27:08 +00:00
|
|
|
//read file
|
|
|
|
int fileId = m_data->m_fileIO->fileOpen(relativeFileName,"r");
|
2018-10-31 18:02:19 +00:00
|
|
|
|
2018-10-09 04:27:08 +00:00
|
|
|
|
|
|
|
char destBuffer[8192];
|
|
|
|
char* line = 0;
|
2018-10-31 18:02:19 +00:00
|
|
|
do
|
2018-10-09 04:27:08 +00:00
|
|
|
{
|
|
|
|
line = m_data->m_fileIO->readLine(fileId, destBuffer, 8192);
|
|
|
|
if (line)
|
|
|
|
{
|
|
|
|
xml_string += (std::string(destBuffer) + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (line);
|
2018-10-10 03:45:17 +00:00
|
|
|
m_data->m_fileIO->fileClose(fileId);
|
2018-10-09 04:27:08 +00:00
|
|
|
#if 0
|
2018-09-23 21:17:31 +00:00
|
|
|
std::fstream xml_file(relativeFileName, std::fstream::in);
|
|
|
|
while (xml_file.good())
|
|
|
|
{
|
|
|
|
std::string line;
|
|
|
|
std::getline(xml_file, line);
|
|
|
|
xml_string += (line + "\n");
|
|
|
|
}
|
|
|
|
xml_file.close();
|
2018-10-09 04:27:08 +00:00
|
|
|
#endif
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2015-04-23 22:41:17 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
BulletErrorLogger loggie;
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_urdfParser.setParseSDF(false);
|
state 2 of FileIO plugin: adding/removing FileIO types, search through all registered FileIO types.
(not enabled by default yet)
Example:
fileIO = p.loadPlugin("fileIOPlugin")
print("fileIO=",fileIO)
p.executePluginCommand(fileIO,"e:/develop/bullet3/data/plane.zip", [p.AddFileIOAction,p.ZipFileIO])
p.executePluginCommand(fileIO,"e:/develop/bullet3/data/test2.zip", [p.AddFileIOAction,p.ZipFileIO])
planeId = p.loadURDF("plane.urdf")
duckId = p.loadURDF("duck_vhacd.urdf",[0,0,1])
2018-10-11 21:39:31 +00:00
|
|
|
bool result = false;
|
2018-10-31 18:02:19 +00:00
|
|
|
|
state 2 of FileIO plugin: adding/removing FileIO types, search through all registered FileIO types.
(not enabled by default yet)
Example:
fileIO = p.loadPlugin("fileIOPlugin")
print("fileIO=",fileIO)
p.executePluginCommand(fileIO,"e:/develop/bullet3/data/plane.zip", [p.AddFileIOAction,p.ZipFileIO])
p.executePluginCommand(fileIO,"e:/develop/bullet3/data/test2.zip", [p.AddFileIOAction,p.ZipFileIO])
planeId = p.loadURDF("plane.urdf")
duckId = p.loadURDF("duck_vhacd.urdf",[0,0,1])
2018-10-11 21:39:31 +00:00
|
|
|
if (xml_string.length())
|
|
|
|
{
|
|
|
|
result = m_data->m_urdfParser.loadUrdf(xml_string.c_str(), &loggie, forceFixedBase, (m_data->m_flags & CUF_PARSE_SENSORS));
|
|
|
|
}
|
2015-04-23 22:41:17 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
return result;
|
2015-04-23 22:41:17 +00:00
|
|
|
}
|
|
|
|
|
2016-05-10 00:25:07 +00:00
|
|
|
int BulletURDFImporter::getNumModels() const
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
return m_data->m_urdfParser.getNumModels();
|
2016-05-10 00:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BulletURDFImporter::activateModel(int modelIndex)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_urdfParser.activateModel(modelIndex);
|
2016-05-10 00:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BulletURDFImporter::loadSDF(const char* fileName, bool forceFixedBase)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
//int argc=0;
|
|
|
|
char relativeFileName[1024];
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3FileUtils fu;
|
|
|
|
|
|
|
|
//bool fileFound = fu.findFile(fileName, relativeFileName, 1024);
|
2018-10-29 17:25:40 +00:00
|
|
|
bool fileFound = (m_data->m_fileIO->findResourcePath(fileName, relativeFileName, 1024));
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
std::string xml_string;
|
|
|
|
|
|
|
|
if (!fileFound)
|
|
|
|
{
|
|
|
|
b3Warning("SDF file '%s' not found\n", fileName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-14 19:54:34 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
char path[1024];
|
|
|
|
fu.extractPath(relativeFileName, path, sizeof(path));
|
|
|
|
m_data->setSourceFile(relativeFileName, path);
|
2016-05-10 00:25:07 +00:00
|
|
|
|
2018-10-14 19:54:34 +00:00
|
|
|
//read file
|
|
|
|
int fileId = m_data->m_fileIO->fileOpen(relativeFileName,"r");
|
2018-10-31 18:02:19 +00:00
|
|
|
|
2018-10-14 19:54:34 +00:00
|
|
|
char destBuffer[8192];
|
|
|
|
char* line = 0;
|
2018-10-31 18:02:19 +00:00
|
|
|
do
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
2018-10-14 19:54:34 +00:00
|
|
|
line = m_data->m_fileIO->readLine(fileId, destBuffer, 8192);
|
|
|
|
if (line)
|
|
|
|
{
|
|
|
|
xml_string += (std::string(destBuffer) + "\n");
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2018-10-14 19:54:34 +00:00
|
|
|
while (line);
|
|
|
|
m_data->m_fileIO->fileClose(fileId);
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BulletErrorLogger loggie;
|
|
|
|
//todo: quick test to see if we can re-use the URDF parser for SDF or not
|
|
|
|
m_data->m_urdfParser.setParseSDF(true);
|
2018-10-14 19:54:34 +00:00
|
|
|
bool result = false;
|
|
|
|
if (xml_string.length())
|
|
|
|
{
|
|
|
|
result = m_data->m_urdfParser.loadSDF(xml_string.c_str(), &loggie);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2016-05-10 00:25:07 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
const char* BulletURDFImporter::getPathPrefix()
|
2015-04-23 22:41:17 +00:00
|
|
|
{
|
|
|
|
return m_data->m_pathPrefix;
|
2015-04-22 23:35:27 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 21:55:30 +00:00
|
|
|
void BulletURDFImporter::setBodyUniqueId(int bodyId)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_bodyId = bodyId;
|
2016-08-11 21:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BulletURDFImporter::getBodyUniqueId() const
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
return m_data->m_bodyId;
|
2016-08-11 21:55:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
BulletURDFImporter::~BulletURDFImporter()
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
|
|
|
delete m_data;
|
|
|
|
}
|
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
int BulletURDFImporter::getRootLinkIndex() const
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_data->m_urdfParser.getModel().m_rootLinks.size() == 1)
|
2015-06-28 21:09:21 +00:00
|
|
|
{
|
|
|
|
return m_data->m_urdfParser.getModel().m_rootLinks[0]->m_linkIndex;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
return -1;
|
2015-04-22 23:35:27 +00:00
|
|
|
};
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
void BulletURDFImporter::getLinkChildIndices(int linkIndex, btAlignedObjectArray<int>& childLinkIndices) const
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
2015-06-28 21:09:21 +00:00
|
|
|
childLinkIndices.resize(0);
|
|
|
|
UrdfLink* const* linkPtr = m_data->m_urdfParser.getModel().m_links.getAtIndex(linkIndex);
|
|
|
|
if (linkPtr)
|
|
|
|
{
|
|
|
|
const UrdfLink* link = *linkPtr;
|
|
|
|
//int numChildren = m_data->m_urdfParser->getModel().m_links.getAtIndex(linkIndex)->
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < link->m_childLinks.size(); i++)
|
2015-06-28 21:09:21 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int childIndex = link->m_childLinks[i]->m_linkIndex;
|
2015-06-28 21:09:21 +00:00
|
|
|
childLinkIndices.push_back(childIndex);
|
|
|
|
}
|
|
|
|
}
|
2015-04-22 23:35:27 +00:00
|
|
|
}
|
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
std::string BulletURDFImporter::getLinkName(int linkIndex) const
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
2015-06-28 21:09:21 +00:00
|
|
|
UrdfLink* const* linkPtr = m_data->m_urdfParser.getModel().m_links.getAtIndex(linkIndex);
|
|
|
|
btAssert(linkPtr);
|
|
|
|
if (linkPtr)
|
|
|
|
{
|
|
|
|
UrdfLink* link = *linkPtr;
|
2015-06-30 04:30:44 +00:00
|
|
|
return link->m_name;
|
2015-06-28 21:09:21 +00:00
|
|
|
}
|
|
|
|
return "";
|
2015-04-22 23:35:27 +00:00
|
|
|
}
|
2017-03-23 17:16:39 +00:00
|
|
|
|
|
|
|
std::string BulletURDFImporter::getBodyName() const
|
|
|
|
{
|
2017-03-29 22:37:33 +00:00
|
|
|
return m_data->m_urdfParser.getModel().m_name;
|
2017-03-23 17:16:39 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
std::string BulletURDFImporter::getJointName(int linkIndex) const
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
2015-06-28 21:09:21 +00:00
|
|
|
UrdfLink* const* linkPtr = m_data->m_urdfParser.getModel().m_links.getAtIndex(linkIndex);
|
|
|
|
btAssert(linkPtr);
|
|
|
|
if (linkPtr)
|
|
|
|
{
|
|
|
|
UrdfLink* link = *linkPtr;
|
|
|
|
if (link->m_parentJoint)
|
|
|
|
{
|
|
|
|
return link->m_parentJoint->m_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
2015-04-22 23:35:27 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
void BulletURDFImporter::getMassAndInertia2(int urdfLinkIndex, btScalar& mass, btVector3& localInertiaDiagonal, btTransform& inertialFrame, int flags) const
|
2018-05-03 21:24:16 +00:00
|
|
|
{
|
|
|
|
if (flags & CUF_USE_URDF_INERTIA)
|
|
|
|
{
|
|
|
|
getMassAndInertia(urdfLinkIndex, mass, localInertiaDiagonal, inertialFrame);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//the link->m_inertia is NOT necessarily aligned with the inertial frame
|
|
|
|
//so an additional transform might need to be computed
|
|
|
|
UrdfLink* const* linkPtr = m_data->m_urdfParser.getModel().m_links.getAtIndex(urdfLinkIndex);
|
|
|
|
|
|
|
|
btAssert(linkPtr);
|
|
|
|
if (linkPtr)
|
|
|
|
{
|
|
|
|
UrdfLink* link = *linkPtr;
|
|
|
|
btScalar linkMass;
|
|
|
|
if (link->m_parentJoint == 0 && m_data->m_urdfParser.getModel().m_overrideFixedBase)
|
|
|
|
{
|
|
|
|
linkMass = 0.f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
linkMass = link->m_inertia.m_mass;
|
|
|
|
}
|
|
|
|
mass = linkMass;
|
2018-09-23 21:17:31 +00:00
|
|
|
localInertiaDiagonal.setValue(0, 0, 0);
|
2018-05-03 21:24:16 +00:00
|
|
|
inertialFrame.setOrigin(link->m_inertia.m_linkLocalFrame.getOrigin());
|
|
|
|
inertialFrame.setBasis(link->m_inertia.m_linkLocalFrame.getBasis());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mass = 1.f;
|
|
|
|
localInertiaDiagonal.setValue(1, 1, 1);
|
|
|
|
inertialFrame.setIdentity();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-22 23:35:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void BulletURDFImporter::getMassAndInertia(int linkIndex, btScalar& mass, btVector3& localInertiaDiagonal, btTransform& inertialFrame) const
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
2015-06-28 21:09:21 +00:00
|
|
|
//the link->m_inertia is NOT necessarily aligned with the inertial frame
|
|
|
|
//so an additional transform might need to be computed
|
|
|
|
UrdfLink* const* linkPtr = m_data->m_urdfParser.getModel().m_links.getAtIndex(linkIndex);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
btAssert(linkPtr);
|
|
|
|
if (linkPtr)
|
|
|
|
{
|
|
|
|
UrdfLink* link = *linkPtr;
|
2016-09-11 01:05:14 +00:00
|
|
|
btMatrix3x3 linkInertiaBasis;
|
|
|
|
btScalar linkMass, principalInertiaX, principalInertiaY, principalInertiaZ;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (link->m_parentJoint == 0 && m_data->m_urdfParser.getModel().m_overrideFixedBase)
|
2016-06-03 01:04:22 +00:00
|
|
|
{
|
2016-09-11 01:05:14 +00:00
|
|
|
linkMass = 0.f;
|
|
|
|
principalInertiaX = 0.f;
|
|
|
|
principalInertiaY = 0.f;
|
|
|
|
principalInertiaZ = 0.f;
|
|
|
|
linkInertiaBasis.setIdentity();
|
2016-06-03 01:04:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-11 01:05:14 +00:00
|
|
|
linkMass = link->m_inertia.m_mass;
|
|
|
|
if (link->m_inertia.m_ixy == 0.0 &&
|
2018-09-23 21:17:31 +00:00
|
|
|
link->m_inertia.m_ixz == 0.0 &&
|
|
|
|
link->m_inertia.m_iyz == 0.0)
|
2016-09-11 01:05:14 +00:00
|
|
|
{
|
|
|
|
principalInertiaX = link->m_inertia.m_ixx;
|
|
|
|
principalInertiaY = link->m_inertia.m_iyy;
|
|
|
|
principalInertiaZ = link->m_inertia.m_izz;
|
|
|
|
linkInertiaBasis.setIdentity();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
principalInertiaX = link->m_inertia.m_ixx;
|
|
|
|
btMatrix3x3 inertiaTensor(link->m_inertia.m_ixx, link->m_inertia.m_ixy, link->m_inertia.m_ixz,
|
2018-09-23 21:17:31 +00:00
|
|
|
link->m_inertia.m_ixy, link->m_inertia.m_iyy, link->m_inertia.m_iyz,
|
|
|
|
link->m_inertia.m_ixz, link->m_inertia.m_iyz, link->m_inertia.m_izz);
|
2016-09-11 01:05:14 +00:00
|
|
|
btScalar threshold = 1.0e-6;
|
|
|
|
int numIterations = 30;
|
|
|
|
inertiaTensor.diagonalize(linkInertiaBasis, threshold, numIterations);
|
|
|
|
principalInertiaX = inertiaTensor[0][0];
|
|
|
|
principalInertiaY = inertiaTensor[1][1];
|
|
|
|
principalInertiaZ = inertiaTensor[2][2];
|
|
|
|
}
|
2016-06-03 01:04:22 +00:00
|
|
|
}
|
2016-09-11 01:05:14 +00:00
|
|
|
mass = linkMass;
|
|
|
|
if (principalInertiaX < 0 ||
|
2018-09-23 21:17:31 +00:00
|
|
|
principalInertiaX > (principalInertiaY + principalInertiaZ) ||
|
|
|
|
principalInertiaY < 0 ||
|
|
|
|
principalInertiaY > (principalInertiaX + principalInertiaZ) ||
|
|
|
|
principalInertiaZ < 0 ||
|
|
|
|
principalInertiaZ > (principalInertiaX + principalInertiaY))
|
2016-09-11 01:05:14 +00:00
|
|
|
{
|
|
|
|
b3Warning("Bad inertia tensor properties, setting inertia to zero for link: %s\n", link->m_name.c_str());
|
|
|
|
principalInertiaX = 0.f;
|
|
|
|
principalInertiaY = 0.f;
|
|
|
|
principalInertiaZ = 0.f;
|
|
|
|
linkInertiaBasis.setIdentity();
|
|
|
|
}
|
|
|
|
localInertiaDiagonal.setValue(principalInertiaX, principalInertiaY, principalInertiaZ);
|
|
|
|
inertialFrame.setOrigin(link->m_inertia.m_linkLocalFrame.getOrigin());
|
2018-09-23 21:17:31 +00:00
|
|
|
inertialFrame.setBasis(link->m_inertia.m_linkLocalFrame.getBasis() * linkInertiaBasis);
|
2015-06-28 21:09:21 +00:00
|
|
|
}
|
|
|
|
else
|
2016-09-11 01:05:14 +00:00
|
|
|
{
|
|
|
|
mass = 1.f;
|
2018-09-23 21:17:31 +00:00
|
|
|
localInertiaDiagonal.setValue(1, 1, 1);
|
2016-09-11 01:05:14 +00:00
|
|
|
inertialFrame.setIdentity();
|
|
|
|
}
|
2015-04-22 23:35:27 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
bool BulletURDFImporter::getJointInfo2(int urdfLinkIndex, btTransform& parent2joint, btTransform& linkTransformInWorld, btVector3& jointAxisInJointSpace, int& jointType, btScalar& jointLowerLimit, btScalar& jointUpperLimit, btScalar& jointDamping, btScalar& jointFriction, btScalar& jointMaxForce, btScalar& jointMaxVelocity) const
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
jointLowerLimit = 0.f;
|
|
|
|
jointUpperLimit = 0.f;
|
2016-03-17 21:54:46 +00:00
|
|
|
jointDamping = 0.f;
|
|
|
|
jointFriction = 0.f;
|
2017-03-26 20:06:46 +00:00
|
|
|
jointMaxForce = 0.f;
|
|
|
|
jointMaxVelocity = 0.f;
|
2016-03-17 21:54:46 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
UrdfLink* const* linkPtr = m_data->m_urdfParser.getModel().m_links.getAtIndex(urdfLinkIndex);
|
|
|
|
btAssert(linkPtr);
|
|
|
|
if (linkPtr)
|
|
|
|
{
|
|
|
|
UrdfLink* link = *linkPtr;
|
2016-05-11 22:52:50 +00:00
|
|
|
linkTransformInWorld = link->m_linkTransformInWorld;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
if (link->m_parentJoint)
|
|
|
|
{
|
|
|
|
UrdfJoint* pj = link->m_parentJoint;
|
|
|
|
parent2joint = pj->m_parentLinkToJointTransform;
|
|
|
|
jointType = pj->m_type;
|
|
|
|
jointAxisInJointSpace = pj->m_localJointAxis;
|
|
|
|
jointLowerLimit = pj->m_lowerLimit;
|
|
|
|
jointUpperLimit = pj->m_upperLimit;
|
2016-03-17 21:54:46 +00:00
|
|
|
jointDamping = pj->m_jointDamping;
|
|
|
|
jointFriction = pj->m_jointFriction;
|
2017-03-26 20:06:46 +00:00
|
|
|
jointMaxForce = pj->m_effortLimit;
|
|
|
|
jointMaxVelocity = pj->m_velocityLimit;
|
2015-06-28 21:09:21 +00:00
|
|
|
return true;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2015-06-28 21:09:21 +00:00
|
|
|
{
|
|
|
|
parent2joint.setIdentity();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-03-26 20:06:46 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
return false;
|
2017-03-26 20:06:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool BulletURDFImporter::getJointInfo(int urdfLinkIndex, btTransform& parent2joint, btTransform& linkTransformInWorld, btVector3& jointAxisInJointSpace, int& jointType, btScalar& jointLowerLimit, btScalar& jointUpperLimit, btScalar& jointDamping, btScalar& jointFriction) const
|
|
|
|
{
|
|
|
|
btScalar jointMaxForce;
|
|
|
|
btScalar jointMaxVelocity;
|
2018-09-23 21:17:31 +00:00
|
|
|
return getJointInfo2(urdfLinkIndex, parent2joint, linkTransformInWorld, jointAxisInJointSpace, jointType, jointLowerLimit, jointUpperLimit, jointDamping, jointFriction, jointMaxForce, jointMaxVelocity);
|
2015-04-22 23:35:27 +00:00
|
|
|
}
|
|
|
|
|
2017-06-03 17:57:56 +00:00
|
|
|
void BulletURDFImporter::setRootTransformInWorld(const btTransform& rootTransformInWorld)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_urdfParser.getModel().m_rootTransformInWorld = rootTransformInWorld;
|
2017-06-03 17:57:56 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 22:52:50 +00:00
|
|
|
bool BulletURDFImporter::getRootTransformInWorld(btTransform& rootTransformInWorld) const
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
rootTransformInWorld = m_data->m_urdfParser.getModel().m_rootTransformInWorld;
|
|
|
|
return true;
|
2016-05-11 22:52:50 +00:00
|
|
|
}
|
2015-04-22 23:35:27 +00:00
|
|
|
|
2018-06-13 22:35:56 +00:00
|
|
|
static btCollisionShape* createConvexHullFromShapes(std::vector<tinyobj::shape_t>& shapes, const btVector3& geomScale, int flags)
|
2016-09-19 14:02:43 +00:00
|
|
|
{
|
2017-04-12 22:02:47 +00:00
|
|
|
B3_PROFILE("createConvexHullFromShapes");
|
2016-09-19 14:02:43 +00:00
|
|
|
btCompoundShape* compound = new btCompoundShape();
|
2016-09-22 15:50:28 +00:00
|
|
|
compound->setMargin(gUrdfDefaultCollisionMargin);
|
|
|
|
|
2016-09-19 14:02:43 +00:00
|
|
|
btTransform identity;
|
|
|
|
identity.setIdentity();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int s = 0; s < (int)shapes.size(); s++)
|
2016-09-19 14:02:43 +00:00
|
|
|
{
|
|
|
|
btConvexHullShape* convexHull = new btConvexHullShape();
|
2016-09-22 15:50:28 +00:00
|
|
|
convexHull->setMargin(gUrdfDefaultCollisionMargin);
|
2016-09-19 14:02:43 +00:00
|
|
|
tinyobj::shape_t& shape = shapes[s];
|
|
|
|
int faceCount = shape.mesh.indices.size();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int f = 0; f < faceCount; f += 3)
|
2016-09-19 14:02:43 +00:00
|
|
|
{
|
|
|
|
btVector3 pt;
|
|
|
|
pt.setValue(shape.mesh.positions[shape.mesh.indices[f] * 3 + 0],
|
2018-09-23 21:17:31 +00:00
|
|
|
shape.mesh.positions[shape.mesh.indices[f] * 3 + 1],
|
|
|
|
shape.mesh.positions[shape.mesh.indices[f] * 3 + 2]);
|
|
|
|
|
|
|
|
convexHull->addPoint(pt * geomScale, false);
|
2016-09-19 14:02:43 +00:00
|
|
|
|
|
|
|
pt.setValue(shape.mesh.positions[shape.mesh.indices[f + 1] * 3 + 0],
|
|
|
|
shape.mesh.positions[shape.mesh.indices[f + 1] * 3 + 1],
|
|
|
|
shape.mesh.positions[shape.mesh.indices[f + 1] * 3 + 2]);
|
2018-09-23 21:17:31 +00:00
|
|
|
convexHull->addPoint(pt * geomScale, false);
|
2016-09-19 14:02:43 +00:00
|
|
|
|
|
|
|
pt.setValue(shape.mesh.positions[shape.mesh.indices[f + 2] * 3 + 0],
|
|
|
|
shape.mesh.positions[shape.mesh.indices[f + 2] * 3 + 1],
|
|
|
|
shape.mesh.positions[shape.mesh.indices[f + 2] * 3 + 2]);
|
2018-09-23 21:17:31 +00:00
|
|
|
convexHull->addPoint(pt * geomScale, false);
|
2016-09-19 14:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
convexHull->recalcLocalAabb();
|
|
|
|
convexHull->optimizeConvexHull();
|
2018-06-13 22:35:56 +00:00
|
|
|
if (flags & CUF_INITIALIZE_SAT_FEATURES)
|
|
|
|
{
|
|
|
|
convexHull->initializePolyhedralFeatures();
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
compound->addChildShape(identity, convexHull);
|
2016-09-19 14:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return compound;
|
|
|
|
}
|
2015-04-22 23:35:27 +00:00
|
|
|
|
2017-03-10 16:46:46 +00:00
|
|
|
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-01-08 20:25:56 +00:00
|
|
|
int BulletURDFImporter::getUrdfFromCollisionShape(const btCollisionShape* collisionShape, UrdfCollision& collision) const
|
|
|
|
{
|
|
|
|
UrdfCollision* col = m_data->m_bulletCollisionShape2UrdfCollision.find(collisionShape);
|
|
|
|
if (col)
|
|
|
|
{
|
|
|
|
collision = *col;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-24 16:16:11 +00:00
|
|
|
btCollisionShape* BulletURDFImporter::convertURDFToCollisionShape(const UrdfCollision* collision, const char* urdfPathPrefix) const
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
2016-12-29 05:51:54 +00:00
|
|
|
BT_PROFILE("convertURDFToCollisionShape");
|
|
|
|
|
2015-04-22 23:35:27 +00:00
|
|
|
btCollisionShape* shape = 0;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
switch (collision->m_geometry.m_type)
|
|
|
|
{
|
|
|
|
case URDF_GEOM_PLANE:
|
2017-06-02 03:13:39 +00:00
|
|
|
{
|
|
|
|
btVector3 planeNormal = collision->m_geometry.m_planeNormal;
|
2018-09-23 21:17:31 +00:00
|
|
|
btScalar planeConstant = 0; //not available?
|
|
|
|
btStaticPlaneShape* plane = new btStaticPlaneShape(planeNormal, planeConstant);
|
2017-06-02 03:13:39 +00:00
|
|
|
shape = plane;
|
2018-09-23 21:17:31 +00:00
|
|
|
shape->setMargin(gUrdfDefaultCollisionMargin);
|
2017-06-02 03:13:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-24 00:45:18 +00:00
|
|
|
case URDF_GEOM_CAPSULE:
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
2017-01-24 00:45:18 +00:00
|
|
|
btScalar radius = collision->m_geometry.m_capsuleRadius;
|
2017-03-27 19:29:24 +00:00
|
|
|
btScalar height = collision->m_geometry.m_capsuleHeight;
|
2018-09-23 21:17:31 +00:00
|
|
|
btCapsuleShapeZ* capsuleShape = new btCapsuleShapeZ(radius, height);
|
2017-03-27 19:29:24 +00:00
|
|
|
shape = capsuleShape;
|
2018-09-23 21:17:31 +00:00
|
|
|
shape->setMargin(gUrdfDefaultCollisionMargin);
|
2017-01-24 00:45:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case URDF_GEOM_CYLINDER:
|
|
|
|
{
|
2017-03-21 21:36:28 +00:00
|
|
|
btScalar cylRadius = collision->m_geometry.m_capsuleRadius;
|
2018-09-23 21:17:31 +00:00
|
|
|
btScalar cylHalfLength = 0.5 * collision->m_geometry.m_capsuleHeight;
|
2018-01-09 18:10:36 +00:00
|
|
|
if (m_data->m_flags & CUF_USE_IMPLICIT_CYLINDER)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 halfExtents(cylRadius, cylRadius, cylHalfLength);
|
2018-01-09 18:10:36 +00:00
|
|
|
btCylinderShapeZ* cylZShape = new btCylinderShapeZ(halfExtents);
|
|
|
|
shape = cylZShape;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2018-01-09 18:10:36 +00:00
|
|
|
{
|
|
|
|
btAlignedObjectArray<btVector3> vertices;
|
|
|
|
//int numVerts = sizeof(barrel_vertices)/(9*sizeof(float));
|
|
|
|
int numSteps = 32;
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numSteps; i++)
|
2018-01-09 18:10:36 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 vert(cylRadius * btSin(SIMD_2_PI * (float(i) / numSteps)), cylRadius * btCos(SIMD_2_PI * (float(i) / numSteps)), cylHalfLength);
|
2018-01-09 18:10:36 +00:00
|
|
|
vertices.push_back(vert);
|
|
|
|
vert[2] = -cylHalfLength;
|
|
|
|
vertices.push_back(vert);
|
|
|
|
}
|
|
|
|
btConvexHullShape* cylZShape = new btConvexHullShape(&vertices[0].x(), vertices.size(), sizeof(btVector3));
|
|
|
|
cylZShape->setMargin(gUrdfDefaultCollisionMargin);
|
|
|
|
cylZShape->recalcLocalAabb();
|
2018-06-13 22:35:56 +00:00
|
|
|
if (m_data->m_flags & CUF_INITIALIZE_SAT_FEATURES)
|
|
|
|
{
|
|
|
|
cylZShape->initializePolyhedralFeatures();
|
|
|
|
}
|
2018-01-09 18:10:36 +00:00
|
|
|
cylZShape->optimizeConvexHull();
|
|
|
|
shape = cylZShape;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case URDF_GEOM_BOX:
|
|
|
|
{
|
2015-06-28 21:09:21 +00:00
|
|
|
btVector3 extents = collision->m_geometry.m_boxSize;
|
2018-09-23 21:17:31 +00:00
|
|
|
btBoxShape* boxShape = new btBoxShape(extents * 0.5f);
|
2015-04-22 23:35:27 +00:00
|
|
|
//btConvexShape* boxShape = new btConeShapeX(extents[2]*0.5,extents[0]*0.5);
|
2018-06-13 22:35:56 +00:00
|
|
|
if (m_data->m_flags & CUF_INITIALIZE_SAT_FEATURES)
|
|
|
|
{
|
|
|
|
boxShape->initializePolyhedralFeatures();
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
shape = boxShape;
|
|
|
|
shape->setMargin(gUrdfDefaultCollisionMargin);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case URDF_GEOM_SPHERE:
|
|
|
|
{
|
2015-06-28 21:09:21 +00:00
|
|
|
btScalar radius = collision->m_geometry.m_sphereRadius;
|
2015-04-22 23:35:27 +00:00
|
|
|
btSphereShape* sphereShape = new btSphereShape(radius);
|
2018-09-23 21:17:31 +00:00
|
|
|
shape = sphereShape;
|
|
|
|
shape->setMargin(gUrdfDefaultCollisionMargin);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case URDF_GEOM_CDF:
|
2018-04-16 20:57:43 +00:00
|
|
|
{
|
|
|
|
char relativeFileName[1024];
|
|
|
|
char pathPrefix[1024];
|
|
|
|
pathPrefix[0] = 0;
|
2018-10-09 04:27:08 +00:00
|
|
|
if (m_data->m_fileIO->findResourcePath(collision->m_geometry.m_meshFileName.c_str(), relativeFileName, 1024))
|
2018-04-16 20:57:43 +00:00
|
|
|
{
|
|
|
|
b3FileUtils::extractPath(relativeFileName, pathPrefix, 1024);
|
|
|
|
|
|
|
|
btAlignedObjectArray<char> sdfData;
|
|
|
|
{
|
|
|
|
std::streampos fsize = 0;
|
|
|
|
std::ifstream file(relativeFileName, std::ios::binary);
|
|
|
|
if (file.good())
|
|
|
|
{
|
|
|
|
fsize = file.tellg();
|
|
|
|
file.seekg(0, std::ios::end);
|
|
|
|
fsize = file.tellg() - fsize;
|
|
|
|
file.seekg(0, std::ios::beg);
|
|
|
|
sdfData.resize(fsize);
|
|
|
|
int bytesRead = file.rdbuf()->sgetn(&sdfData[0], fsize);
|
|
|
|
btAssert(bytesRead == fsize);
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sdfData.size())
|
|
|
|
{
|
|
|
|
btSdfCollisionShape* sdfShape = new btSdfCollisionShape();
|
|
|
|
bool valid = sdfShape->initializeSDF(&sdfData[0], sdfData.size());
|
|
|
|
btAssert(valid);
|
|
|
|
|
|
|
|
if (valid)
|
|
|
|
{
|
|
|
|
shape = sdfShape;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete sdfShape;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case URDF_GEOM_MESH:
|
2017-03-10 16:46:46 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
GLInstanceGraphicsShape* glmesh = 0;
|
|
|
|
switch (collision->m_geometry.m_meshFileType)
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
case UrdfGeometry::FILE_OBJ:
|
|
|
|
if (collision->m_flags & URDF_FORCE_CONCAVE_TRIMESH)
|
|
|
|
{
|
|
|
|
char relativeFileName[1024];
|
|
|
|
char pathPrefix[1024];
|
|
|
|
pathPrefix[0] = 0;
|
2018-10-09 04:27:08 +00:00
|
|
|
if (m_data->m_fileIO->findResourcePath(collision->m_geometry.m_meshFileName.c_str(), relativeFileName, 1024))
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
|
|
|
b3FileUtils::extractPath(relativeFileName, pathPrefix, 1024);
|
|
|
|
}
|
2018-10-09 04:27:08 +00:00
|
|
|
glmesh = LoadMeshFromObj(collision->m_geometry.m_meshFileName.c_str(), pathPrefix,m_data->m_fileIO);
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<tinyobj::shape_t> shapes;
|
2018-10-09 04:27:08 +00:00
|
|
|
std::string err = tinyobj::LoadObj(shapes, collision->m_geometry.m_meshFileName.c_str(),"",m_data->m_fileIO);
|
2018-09-23 21:17:31 +00:00
|
|
|
//create a convex hull for each shape, and store it in a btCompoundShape
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
shape = createConvexHullFromShapes(shapes, collision->m_geometry.m_meshScale, m_data->m_flags);
|
|
|
|
m_data->m_bulletCollisionShape2UrdfCollision.insert(shape, *collision);
|
|
|
|
return shape;
|
|
|
|
}
|
|
|
|
break;
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case UrdfGeometry::FILE_STL:
|
2018-10-09 04:27:08 +00:00
|
|
|
glmesh = LoadMeshFromSTL(collision->m_geometry.m_meshFileName.c_str(), m_data->m_fileIO);
|
2018-09-23 21:17:31 +00:00
|
|
|
break;
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case UrdfGeometry::FILE_COLLADA:
|
|
|
|
{
|
|
|
|
btAlignedObjectArray<GLInstanceGraphicsShape> visualShapes;
|
|
|
|
btAlignedObjectArray<ColladaGraphicsInstance> visualShapeInstances;
|
|
|
|
btTransform upAxisTrans;
|
|
|
|
upAxisTrans.setIdentity();
|
|
|
|
float unitMeterScaling = 1;
|
2018-10-09 04:27:08 +00:00
|
|
|
LoadMeshFromCollada(collision->m_geometry.m_meshFileName.c_str(), visualShapes, visualShapeInstances, upAxisTrans, unitMeterScaling, 2, m_data->m_fileIO);
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
glmesh = new GLInstanceGraphicsShape;
|
|
|
|
glmesh->m_indices = new b3AlignedObjectArray<int>();
|
|
|
|
glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>();
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < visualShapeInstances.size(); i++)
|
|
|
|
{
|
|
|
|
ColladaGraphicsInstance* instance = &visualShapeInstances[i];
|
|
|
|
GLInstanceGraphicsShape* gfxShape = &visualShapes[instance->m_shapeIndex];
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3AlignedObjectArray<GLInstanceVertex> verts;
|
|
|
|
verts.resize(gfxShape->m_vertices->size());
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int baseIndex = glmesh->m_vertices->size();
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < gfxShape->m_vertices->size(); i++)
|
|
|
|
{
|
|
|
|
verts[i].normal[0] = gfxShape->m_vertices->at(i).normal[0];
|
|
|
|
verts[i].normal[1] = gfxShape->m_vertices->at(i).normal[1];
|
|
|
|
verts[i].normal[2] = gfxShape->m_vertices->at(i).normal[2];
|
|
|
|
verts[i].uv[0] = gfxShape->m_vertices->at(i).uv[0];
|
|
|
|
verts[i].uv[1] = gfxShape->m_vertices->at(i).uv[1];
|
|
|
|
verts[i].xyzw[0] = gfxShape->m_vertices->at(i).xyzw[0];
|
|
|
|
verts[i].xyzw[1] = gfxShape->m_vertices->at(i).xyzw[1];
|
|
|
|
verts[i].xyzw[2] = gfxShape->m_vertices->at(i).xyzw[2];
|
|
|
|
verts[i].xyzw[3] = gfxShape->m_vertices->at(i).xyzw[3];
|
|
|
|
}
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int curNumIndices = glmesh->m_indices->size();
|
|
|
|
int additionalIndices = gfxShape->m_indices->size();
|
|
|
|
glmesh->m_indices->resize(curNumIndices + additionalIndices);
|
|
|
|
for (int k = 0; k < additionalIndices; k++)
|
|
|
|
{
|
|
|
|
glmesh->m_indices->at(curNumIndices + k) = gfxShape->m_indices->at(k) + baseIndex;
|
|
|
|
}
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
//compensate upAxisTrans and unitMeterScaling here
|
|
|
|
btMatrix4x4 upAxisMat;
|
|
|
|
upAxisMat.setIdentity();
|
|
|
|
//upAxisMat.setPureRotation(upAxisTrans.getRotation());
|
|
|
|
btMatrix4x4 unitMeterScalingMat;
|
|
|
|
unitMeterScalingMat.setPureScaling(btVector3(unitMeterScaling, unitMeterScaling, unitMeterScaling));
|
|
|
|
btMatrix4x4 worldMat = unitMeterScalingMat * instance->m_worldTransform * upAxisMat;
|
|
|
|
//btMatrix4x4 worldMat = instance->m_worldTransform;
|
|
|
|
int curNumVertices = glmesh->m_vertices->size();
|
|
|
|
int additionalVertices = verts.size();
|
|
|
|
glmesh->m_vertices->reserve(curNumVertices + additionalVertices);
|
2015-04-22 23:35:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int v = 0; v < verts.size(); v++)
|
|
|
|
{
|
|
|
|
btVector3 pos(verts[v].xyzw[0], verts[v].xyzw[1], verts[v].xyzw[2]);
|
|
|
|
pos = worldMat * pos;
|
|
|
|
verts[v].xyzw[0] = float(pos[0]);
|
|
|
|
verts[v].xyzw[1] = float(pos[1]);
|
|
|
|
verts[v].xyzw[2] = float(pos[2]);
|
|
|
|
glmesh->m_vertices->push_back(verts[v]);
|
|
|
|
}
|
2015-04-22 23:35:27 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
glmesh->m_numIndices = glmesh->m_indices->size();
|
|
|
|
glmesh->m_numvertices = glmesh->m_vertices->size();
|
|
|
|
//glmesh = LoadMeshFromCollada(success.c_str());
|
|
|
|
break;
|
2015-04-22 23:35:27 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!glmesh || glmesh->m_numvertices <= 0)
|
|
|
|
{
|
|
|
|
b3Warning("%s: cannot extract mesh from '%s'\n", urdfPathPrefix, collision->m_geometry.m_meshFileName.c_str());
|
|
|
|
delete glmesh;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btAlignedObjectArray<btVector3> convertedVerts;
|
|
|
|
convertedVerts.reserve(glmesh->m_numvertices);
|
|
|
|
for (int i = 0; i < glmesh->m_numvertices; i++)
|
|
|
|
{
|
|
|
|
convertedVerts.push_back(btVector3(
|
|
|
|
glmesh->m_vertices->at(i).xyzw[0] * collision->m_geometry.m_meshScale[0],
|
|
|
|
glmesh->m_vertices->at(i).xyzw[1] * collision->m_geometry.m_meshScale[1],
|
|
|
|
glmesh->m_vertices->at(i).xyzw[2] * collision->m_geometry.m_meshScale[2]));
|
|
|
|
}
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (collision->m_flags & URDF_FORCE_CONCAVE_TRIMESH)
|
2017-03-08 11:49:39 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
BT_PROFILE("convert trimesh");
|
|
|
|
btTriangleMesh* meshInterface = new btTriangleMesh();
|
|
|
|
m_data->m_allocatedMeshInterfaces.push_back(meshInterface);
|
|
|
|
{
|
|
|
|
BT_PROFILE("convert vertices");
|
2017-04-12 22:02:47 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < glmesh->m_numIndices / 3; i++)
|
|
|
|
{
|
|
|
|
const btVector3& v0 = convertedVerts[glmesh->m_indices->at(i * 3)];
|
|
|
|
const btVector3& v1 = convertedVerts[glmesh->m_indices->at(i * 3 + 1)];
|
|
|
|
const btVector3& v2 = convertedVerts[glmesh->m_indices->at(i * 3 + 2)];
|
|
|
|
meshInterface->addTriangle(v0, v1, v2);
|
|
|
|
}
|
|
|
|
}
|
2017-04-12 22:02:47 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
BT_PROFILE("create btBvhTriangleMeshShape");
|
|
|
|
btBvhTriangleMeshShape* trimesh = new btBvhTriangleMeshShape(meshInterface, true, true);
|
|
|
|
//trimesh->setLocalScaling(collision->m_geometry.m_meshScale);
|
|
|
|
shape = trimesh;
|
2017-04-12 22:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
else
|
2017-04-12 22:02:47 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
BT_PROFILE("convert btConvexHullShape");
|
|
|
|
btConvexHullShape* convexHull = new btConvexHullShape(&convertedVerts[0].getX(), convertedVerts.size(), sizeof(btVector3));
|
|
|
|
convexHull->optimizeConvexHull();
|
|
|
|
if (m_data->m_flags & CUF_INITIALIZE_SAT_FEATURES)
|
|
|
|
{
|
|
|
|
convexHull->initializePolyhedralFeatures();
|
|
|
|
}
|
|
|
|
convexHull->setMargin(gUrdfDefaultCollisionMargin);
|
|
|
|
convexHull->recalcLocalAabb();
|
|
|
|
//convexHull->setLocalScaling(collision->m_geometry.m_meshScale);
|
|
|
|
shape = convexHull;
|
2018-06-13 22:35:56 +00:00
|
|
|
}
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
delete glmesh;
|
|
|
|
break;
|
|
|
|
} // mesh case
|
2015-04-22 23:35:27 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
default:
|
|
|
|
b3Warning("Error: unknown collision geometry type %i\n", collision->m_geometry.m_type);
|
2017-03-08 11:49:39 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (shape && collision->m_geometry.m_type == URDF_GEOM_MESH)
|
2018-01-08 20:25:56 +00:00
|
|
|
{
|
|
|
|
m_data->m_bulletCollisionShape2UrdfCollision.insert(shape, *collision);
|
|
|
|
}
|
2015-04-22 23:35:27 +00:00
|
|
|
return shape;
|
|
|
|
}
|
|
|
|
|
2018-10-14 19:54:34 +00:00
|
|
|
void BulletURDFImporter::convertURDFToVisualShapeInternal(const UrdfVisual* visual, const char* urdfPathPrefix, const btTransform& visualTransform, btAlignedObjectArray<GLInstanceVertex>& verticesOut, btAlignedObjectArray<int>& indicesOut, btAlignedObjectArray<BulletURDFTexture>& texturesOut, struct b3ImportMeshData& meshData) const
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
2016-12-29 05:51:54 +00:00
|
|
|
BT_PROFILE("convertURDFToVisualShapeInternal");
|
2016-06-01 05:55:13 +00:00
|
|
|
|
|
|
|
GLInstanceGraphicsShape* glmesh = 0;
|
|
|
|
|
|
|
|
btConvexShape* convexColShape = 0;
|
|
|
|
|
|
|
|
switch (visual->m_geometry.m_type)
|
|
|
|
{
|
2018-10-31 18:02:19 +00:00
|
|
|
case URDF_GEOM_CAPSULE:
|
|
|
|
{
|
|
|
|
btScalar radius = visual->m_geometry.m_capsuleRadius;
|
|
|
|
btScalar height = visual->m_geometry.m_capsuleHeight;
|
|
|
|
btCapsuleShapeZ* capsuleShape = new btCapsuleShapeZ(radius, height);
|
|
|
|
convexColShape = capsuleShape;
|
|
|
|
convexColShape->setMargin(gUrdfDefaultCollisionMargin);
|
|
|
|
break;
|
|
|
|
}
|
2016-06-01 05:55:13 +00:00
|
|
|
case URDF_GEOM_CYLINDER:
|
|
|
|
{
|
|
|
|
btAlignedObjectArray<btVector3> vertices;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2016-06-01 05:55:13 +00:00
|
|
|
//int numVerts = sizeof(barrel_vertices)/(9*sizeof(float));
|
|
|
|
int numSteps = 32;
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numSteps; i++)
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
2017-03-21 21:36:28 +00:00
|
|
|
btScalar cylRadius = visual->m_geometry.m_capsuleRadius;
|
2017-03-27 19:29:24 +00:00
|
|
|
btScalar cylLength = visual->m_geometry.m_capsuleHeight;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
btVector3 vert(cylRadius * btSin(SIMD_2_PI * (float(i) / numSteps)), cylRadius * btCos(SIMD_2_PI * (float(i) / numSteps)), cylLength / 2.);
|
2016-06-01 05:55:13 +00:00
|
|
|
vertices.push_back(vert);
|
|
|
|
vert[2] = -cylLength / 2.;
|
|
|
|
vertices.push_back(vert);
|
|
|
|
}
|
|
|
|
|
|
|
|
btConvexHullShape* cylZShape = new btConvexHullShape(&vertices[0].x(), vertices.size(), sizeof(btVector3));
|
2016-09-20 19:37:13 +00:00
|
|
|
cylZShape->setMargin(gUrdfDefaultCollisionMargin);
|
2017-12-20 22:54:32 +00:00
|
|
|
cylZShape->recalcLocalAabb();
|
2016-06-01 05:55:13 +00:00
|
|
|
convexColShape = cylZShape;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2016-06-01 05:55:13 +00:00
|
|
|
case URDF_GEOM_BOX:
|
|
|
|
{
|
|
|
|
btVector3 extents = visual->m_geometry.m_boxSize;
|
2018-09-23 21:17:31 +00:00
|
|
|
btBoxShape* boxShape = new btBoxShape(extents * 0.5f);
|
2016-06-01 05:55:13 +00:00
|
|
|
//btConvexShape* boxShape = new btConeShapeX(extents[2]*0.5,extents[0]*0.5);
|
|
|
|
convexColShape = boxShape;
|
2016-09-20 19:37:13 +00:00
|
|
|
convexColShape->setMargin(gUrdfDefaultCollisionMargin);
|
2016-06-01 05:55:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2016-06-01 05:55:13 +00:00
|
|
|
case URDF_GEOM_SPHERE:
|
|
|
|
{
|
|
|
|
btScalar radius = visual->m_geometry.m_sphereRadius;
|
|
|
|
btSphereShape* sphereShape = new btSphereShape(radius);
|
|
|
|
convexColShape = sphereShape;
|
2016-09-20 19:37:13 +00:00
|
|
|
convexColShape->setMargin(gUrdfDefaultCollisionMargin);
|
2016-06-01 05:55:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-08 11:49:39 +00:00
|
|
|
|
2016-06-01 05:55:13 +00:00
|
|
|
case URDF_GEOM_MESH:
|
|
|
|
{
|
2017-03-10 15:17:38 +00:00
|
|
|
switch (visual->m_geometry.m_meshFileType)
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
case UrdfGeometry::FILE_OBJ:
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
2018-10-31 18:02:19 +00:00
|
|
|
|
2018-10-09 04:27:08 +00:00
|
|
|
if (b3ImportMeshUtility::loadAndRegisterMeshFromFileInternal(visual->m_geometry.m_meshFileName, meshData, m_data->m_fileIO))
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
2017-10-25 15:15:01 +00:00
|
|
|
if (meshData.m_textureImage1)
|
2017-03-08 11:49:39 +00:00
|
|
|
{
|
2017-10-08 01:50:23 +00:00
|
|
|
BulletURDFTexture texData;
|
2017-03-08 11:49:39 +00:00
|
|
|
texData.m_width = meshData.m_textureWidth;
|
|
|
|
texData.m_height = meshData.m_textureHeight;
|
2017-10-25 15:15:01 +00:00
|
|
|
texData.textureData1 = meshData.m_textureImage1;
|
|
|
|
texData.m_isCached = meshData.m_isCached;
|
2017-03-08 11:49:39 +00:00
|
|
|
texturesOut.push_back(texData);
|
|
|
|
}
|
|
|
|
glmesh = meshData.m_gfxShape;
|
2016-06-01 05:55:13 +00:00
|
|
|
}
|
2017-03-08 11:49:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-06-01 05:55:13 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case UrdfGeometry::FILE_STL:
|
2017-03-08 11:49:39 +00:00
|
|
|
{
|
2018-10-09 04:27:08 +00:00
|
|
|
glmesh = LoadMeshFromSTL(visual->m_geometry.m_meshFileName.c_str(),m_data->m_fileIO);
|
2017-03-08 11:49:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-06-01 05:55:13 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case UrdfGeometry::FILE_COLLADA:
|
2017-03-08 11:49:39 +00:00
|
|
|
{
|
|
|
|
btAlignedObjectArray<GLInstanceGraphicsShape> visualShapes;
|
|
|
|
btAlignedObjectArray<ColladaGraphicsInstance> visualShapeInstances;
|
2018-09-23 21:17:31 +00:00
|
|
|
btTransform upAxisTrans;
|
|
|
|
upAxisTrans.setIdentity();
|
2017-03-08 11:49:39 +00:00
|
|
|
float unitMeterScaling = 1;
|
|
|
|
int upAxis = 2;
|
|
|
|
|
2017-03-10 15:17:38 +00:00
|
|
|
LoadMeshFromCollada(visual->m_geometry.m_meshFileName.c_str(),
|
2018-09-23 21:17:31 +00:00
|
|
|
visualShapes,
|
|
|
|
visualShapeInstances,
|
|
|
|
upAxisTrans,
|
|
|
|
unitMeterScaling,
|
2018-10-09 04:27:08 +00:00
|
|
|
upAxis,
|
|
|
|
m_data->m_fileIO);
|
2017-03-08 11:49:39 +00:00
|
|
|
|
|
|
|
glmesh = new GLInstanceGraphicsShape;
|
2018-09-23 21:17:31 +00:00
|
|
|
// int index = 0;
|
2017-03-08 11:49:39 +00:00
|
|
|
glmesh->m_indices = new b3AlignedObjectArray<int>();
|
|
|
|
glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < visualShapeInstances.size(); i++)
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
2017-03-08 11:49:39 +00:00
|
|
|
ColladaGraphicsInstance* instance = &visualShapeInstances[i];
|
|
|
|
GLInstanceGraphicsShape* gfxShape = &visualShapes[instance->m_shapeIndex];
|
2016-06-01 05:55:13 +00:00
|
|
|
|
2017-03-08 11:49:39 +00:00
|
|
|
b3AlignedObjectArray<GLInstanceVertex> verts;
|
|
|
|
verts.resize(gfxShape->m_vertices->size());
|
2016-06-01 05:55:13 +00:00
|
|
|
|
2017-03-08 11:49:39 +00:00
|
|
|
int baseIndex = glmesh->m_vertices->size();
|
2016-06-01 05:55:13 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < gfxShape->m_vertices->size(); i++)
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
2017-03-08 11:49:39 +00:00
|
|
|
verts[i].normal[0] = gfxShape->m_vertices->at(i).normal[0];
|
|
|
|
verts[i].normal[1] = gfxShape->m_vertices->at(i).normal[1];
|
|
|
|
verts[i].normal[2] = gfxShape->m_vertices->at(i).normal[2];
|
|
|
|
verts[i].uv[0] = gfxShape->m_vertices->at(i).uv[0];
|
|
|
|
verts[i].uv[1] = gfxShape->m_vertices->at(i).uv[1];
|
|
|
|
verts[i].xyzw[0] = gfxShape->m_vertices->at(i).xyzw[0];
|
|
|
|
verts[i].xyzw[1] = gfxShape->m_vertices->at(i).xyzw[1];
|
|
|
|
verts[i].xyzw[2] = gfxShape->m_vertices->at(i).xyzw[2];
|
|
|
|
verts[i].xyzw[3] = gfxShape->m_vertices->at(i).xyzw[3];
|
2016-06-01 05:55:13 +00:00
|
|
|
}
|
2017-03-08 11:49:39 +00:00
|
|
|
|
|
|
|
int curNumIndices = glmesh->m_indices->size();
|
|
|
|
int additionalIndices = gfxShape->m_indices->size();
|
|
|
|
glmesh->m_indices->resize(curNumIndices + additionalIndices);
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int k = 0; k < additionalIndices; k++)
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
2017-03-08 11:49:39 +00:00
|
|
|
glmesh->m_indices->at(curNumIndices + k) = gfxShape->m_indices->at(k) + baseIndex;
|
2016-06-01 05:55:13 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 11:49:39 +00:00
|
|
|
//compensate upAxisTrans and unitMeterScaling here
|
|
|
|
btMatrix4x4 upAxisMat;
|
|
|
|
upAxisMat.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
// upAxisMat.setPureRotation(upAxisTrans.getRotation());
|
2017-03-08 11:49:39 +00:00
|
|
|
btMatrix4x4 unitMeterScalingMat;
|
|
|
|
unitMeterScalingMat.setPureScaling(btVector3(unitMeterScaling, unitMeterScaling, unitMeterScaling));
|
2018-09-23 21:17:31 +00:00
|
|
|
btMatrix4x4 worldMat = unitMeterScalingMat * upAxisMat * instance->m_worldTransform;
|
2017-03-08 11:49:39 +00:00
|
|
|
//btMatrix4x4 worldMat = instance->m_worldTransform;
|
|
|
|
int curNumVertices = glmesh->m_vertices->size();
|
|
|
|
int additionalVertices = verts.size();
|
|
|
|
glmesh->m_vertices->reserve(curNumVertices + additionalVertices);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int v = 0; v < verts.size(); v++)
|
2017-03-08 11:49:39 +00:00
|
|
|
{
|
|
|
|
btVector3 pos(verts[v].xyzw[0], verts[v].xyzw[1], verts[v].xyzw[2]);
|
2018-09-23 21:17:31 +00:00
|
|
|
pos = worldMat * pos;
|
2017-03-08 11:49:39 +00:00
|
|
|
verts[v].xyzw[0] = float(pos[0]);
|
|
|
|
verts[v].xyzw[1] = float(pos[1]);
|
|
|
|
verts[v].xyzw[2] = float(pos[2]);
|
|
|
|
glmesh->m_vertices->push_back(verts[v]);
|
|
|
|
}
|
2016-06-01 05:55:13 +00:00
|
|
|
}
|
2017-03-08 11:49:39 +00:00
|
|
|
glmesh->m_numIndices = glmesh->m_indices->size();
|
|
|
|
glmesh->m_numvertices = glmesh->m_vertices->size();
|
2017-03-10 15:17:38 +00:00
|
|
|
//glmesh = LoadMeshFromCollada(visual->m_geometry.m_meshFileName);
|
2016-06-01 05:55:13 +00:00
|
|
|
|
2017-03-08 11:49:39 +00:00
|
|
|
break;
|
2016-06-01 05:55:13 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
} // switch file type
|
2016-06-01 05:55:13 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!glmesh || !glmesh->m_vertices || glmesh->m_numvertices <= 0)
|
2017-03-08 11:49:39 +00:00
|
|
|
{
|
2017-03-10 15:17:38 +00:00
|
|
|
b3Warning("%s: cannot extract anything useful from mesh '%s'\n", urdfPathPrefix, visual->m_geometry.m_meshFileName.c_str());
|
2017-03-08 11:49:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-06-01 05:55:13 +00:00
|
|
|
|
2017-03-08 11:49:39 +00:00
|
|
|
//apply the geometry scaling
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < glmesh->m_vertices->size(); i++)
|
2017-03-08 11:49:39 +00:00
|
|
|
{
|
|
|
|
glmesh->m_vertices->at(i).xyzw[0] *= visual->m_geometry.m_meshScale[0];
|
|
|
|
glmesh->m_vertices->at(i).xyzw[1] *= visual->m_geometry.m_meshScale[1];
|
|
|
|
glmesh->m_vertices->at(i).xyzw[2] *= visual->m_geometry.m_meshScale[2];
|
|
|
|
}
|
2016-06-01 05:55:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-30 18:01:33 +00:00
|
|
|
case URDF_GEOM_PLANE:
|
|
|
|
{
|
|
|
|
b3Warning("No default visual for URDF_GEOM_PLANE");
|
|
|
|
break;
|
|
|
|
}
|
2016-06-01 05:55:13 +00:00
|
|
|
default:
|
2017-03-30 18:01:33 +00:00
|
|
|
{
|
2017-03-13 23:32:02 +00:00
|
|
|
b3Warning("Error: unknown visual geometry type %i\n", visual->m_geometry.m_type);
|
2017-03-30 18:01:33 +00:00
|
|
|
}
|
2016-06-01 05:55:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//if we have a convex, tesselate into localVertices/localIndices
|
2018-09-23 21:17:31 +00:00
|
|
|
if ((glmesh == 0) && convexColShape)
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
2016-12-29 05:51:54 +00:00
|
|
|
BT_PROFILE("convexColShape");
|
|
|
|
|
2016-06-01 05:55:13 +00:00
|
|
|
btShapeHull* hull = new btShapeHull(convexColShape);
|
|
|
|
hull->buildHull(0.0);
|
|
|
|
{
|
|
|
|
// int strideInBytes = 9*sizeof(float);
|
|
|
|
int numVertices = hull->numVertices();
|
|
|
|
int numIndices = hull->numIndices();
|
|
|
|
|
|
|
|
glmesh = new GLInstanceGraphicsShape;
|
2018-09-23 21:17:31 +00:00
|
|
|
// int index = 0;
|
2016-06-01 05:55:13 +00:00
|
|
|
glmesh->m_indices = new b3AlignedObjectArray<int>();
|
|
|
|
glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>();
|
|
|
|
|
|
|
|
for (int i = 0; i < numVertices; i++)
|
|
|
|
{
|
|
|
|
GLInstanceVertex vtx;
|
|
|
|
btVector3 pos = hull->getVertexPointer()[i];
|
|
|
|
vtx.xyzw[0] = pos.x();
|
|
|
|
vtx.xyzw[1] = pos.y();
|
|
|
|
vtx.xyzw[2] = pos.z();
|
|
|
|
vtx.xyzw[3] = 1.f;
|
|
|
|
pos.normalize();
|
|
|
|
vtx.normal[0] = pos.x();
|
|
|
|
vtx.normal[1] = pos.y();
|
|
|
|
vtx.normal[2] = pos.z();
|
|
|
|
vtx.uv[0] = 0.5f;
|
|
|
|
vtx.uv[1] = 0.5f;
|
|
|
|
glmesh->m_vertices->push_back(vtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
btAlignedObjectArray<int> indices;
|
|
|
|
for (int i = 0; i < numIndices; i++)
|
|
|
|
{
|
|
|
|
glmesh->m_indices->push_back(hull->getIndexPointer()[i]);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2016-06-01 05:55:13 +00:00
|
|
|
glmesh->m_numvertices = glmesh->m_vertices->size();
|
|
|
|
glmesh->m_numIndices = glmesh->m_indices->size();
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
delete hull;
|
2016-06-01 05:55:13 +00:00
|
|
|
delete convexColShape;
|
|
|
|
convexColShape = 0;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
if (glmesh && glmesh->m_numIndices > 0 && glmesh->m_numvertices > 0)
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
2016-12-29 05:51:54 +00:00
|
|
|
BT_PROFILE("glmesh");
|
2016-06-01 05:55:13 +00:00
|
|
|
int baseIndex = verticesOut.size();
|
|
|
|
|
|
|
|
for (int i = 0; i < glmesh->m_indices->size(); i++)
|
|
|
|
{
|
|
|
|
indicesOut.push_back(glmesh->m_indices->at(i) + baseIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < glmesh->m_vertices->size(); i++)
|
|
|
|
{
|
|
|
|
GLInstanceVertex& v = glmesh->m_vertices->at(i);
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 vert(v.xyzw[0], v.xyzw[1], v.xyzw[2]);
|
|
|
|
btVector3 vt = visualTransform * vert;
|
2016-06-01 05:55:13 +00:00
|
|
|
v.xyzw[0] = vt[0];
|
|
|
|
v.xyzw[1] = vt[1];
|
|
|
|
v.xyzw[2] = vt[2];
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 triNormal(v.normal[0], v.normal[1], v.normal[2]);
|
|
|
|
triNormal = visualTransform.getBasis() * triNormal;
|
2016-06-01 05:55:13 +00:00
|
|
|
v.normal[0] = triNormal[0];
|
|
|
|
v.normal[1] = triNormal[1];
|
|
|
|
v.normal[2] = triNormal[2];
|
|
|
|
verticesOut.push_back(v);
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
delete glmesh;
|
2016-06-01 05:55:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BulletURDFImporter::convertLinkVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame) const
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int graphicsIndex = -1;
|
|
|
|
btAlignedObjectArray<GLInstanceVertex> vertices;
|
2016-06-01 05:55:13 +00:00
|
|
|
btAlignedObjectArray<int> indices;
|
2018-09-23 21:17:31 +00:00
|
|
|
btTransform startTrans;
|
|
|
|
startTrans.setIdentity();
|
2017-10-08 01:50:23 +00:00
|
|
|
btAlignedObjectArray<BulletURDFTexture> textures;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
const UrdfModel& model = m_data->m_urdfParser.getModel();
|
2016-06-01 05:55:13 +00:00
|
|
|
UrdfLink* const* linkPtr = model.m_links.getAtIndex(linkIndex);
|
|
|
|
if (linkPtr)
|
|
|
|
{
|
|
|
|
const UrdfLink* link = *linkPtr;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
for (int v = 0; v < link->m_visualArray.size(); v++)
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
|
|
|
const UrdfVisual& vis = link->m_visualArray[v];
|
|
|
|
btTransform childTrans = vis.m_linkLocalFrame;
|
|
|
|
btHashString matName(vis.m_materialName.c_str());
|
2018-09-23 21:17:31 +00:00
|
|
|
UrdfMaterial* const* matPtr = model.m_materials[matName];
|
2018-10-14 19:54:34 +00:00
|
|
|
b3ImportMeshData meshData;
|
|
|
|
|
|
|
|
convertURDFToVisualShapeInternal(&vis, pathPrefix, localInertiaFrame.inverse() * childTrans, vertices, indices, textures,meshData);
|
|
|
|
|
|
|
|
if (m_data->m_flags&CUF_USE_MATERIAL_COLORS_FROM_MTL)
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
2018-10-14 19:54:34 +00:00
|
|
|
if ((meshData.m_flags & B3_IMPORT_MESH_HAS_RGBA_COLOR) &&
|
|
|
|
(meshData.m_flags & B3_IMPORT_MESH_HAS_SPECULAR_COLOR))
|
|
|
|
{
|
|
|
|
UrdfMaterialColor matCol;
|
2018-10-31 18:02:19 +00:00
|
|
|
|
2018-10-14 19:54:34 +00:00
|
|
|
if (m_data->m_flags&CUF_USE_MATERIAL_TRANSPARANCY_FROM_MTL)
|
|
|
|
{
|
|
|
|
matCol.m_rgbaColor.setValue(meshData.m_rgbaColor[0],
|
|
|
|
meshData.m_rgbaColor[1],
|
|
|
|
meshData.m_rgbaColor[2],
|
|
|
|
meshData.m_rgbaColor[3]);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
matCol.m_rgbaColor.setValue(meshData.m_rgbaColor[0],
|
|
|
|
meshData.m_rgbaColor[1],
|
|
|
|
meshData.m_rgbaColor[2],
|
|
|
|
1);
|
|
|
|
}
|
2018-10-31 18:02:19 +00:00
|
|
|
|
2018-10-14 19:54:34 +00:00
|
|
|
matCol.m_specularColor.setValue(meshData.m_specularColor[0],
|
|
|
|
meshData.m_specularColor[1],
|
|
|
|
meshData.m_specularColor[2]);
|
|
|
|
m_data->m_linkColors.insert(linkIndex, matCol);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (matPtr)
|
|
|
|
{
|
|
|
|
UrdfMaterial* const mat = *matPtr;
|
|
|
|
//printf("UrdfMaterial %s, rgba = %f,%f,%f,%f\n",mat->m_name.c_str(),mat->m_rgbaColor[0],mat->m_rgbaColor[1],mat->m_rgbaColor[2],mat->m_rgbaColor[3]);
|
|
|
|
UrdfMaterialColor matCol;
|
|
|
|
matCol.m_rgbaColor = mat->m_matColor.m_rgbaColor;
|
|
|
|
matCol.m_specularColor = mat->m_matColor.m_specularColor;
|
|
|
|
m_data->m_linkColors.insert(linkIndex, matCol);
|
|
|
|
}
|
2016-06-01 05:55:13 +00:00
|
|
|
}
|
2018-10-31 18:02:19 +00:00
|
|
|
|
2016-06-01 05:55:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (vertices.size() && indices.size())
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// graphicsIndex = m_data->m_guiHelper->registerGraphicsShape(&vertices[0].xyzw[0], vertices.size(), &indices[0], indices.size());
|
2016-06-19 01:02:20 +00:00
|
|
|
//graphicsIndex = m_data->m_guiHelper->registerGraphicsShape(&vertices[0].xyzw[0], vertices.size(), &indices[0], indices.size());
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2016-07-08 02:24:44 +00:00
|
|
|
//CommonRenderInterface* renderer = m_data->m_guiHelper->getRenderInterface();
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2016-07-08 02:24:44 +00:00
|
|
|
if (1)
|
2016-06-19 01:02:20 +00:00
|
|
|
{
|
|
|
|
int textureIndex = -1;
|
|
|
|
if (textures.size())
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
textureIndex = m_data->m_guiHelper->registerTexture(textures[0].textureData1, textures[0].m_width, textures[0].m_height);
|
2018-02-22 07:22:16 +00:00
|
|
|
if (textureIndex >= 0)
|
|
|
|
{
|
|
|
|
m_data->m_allocatedTextures.push_back(textureIndex);
|
|
|
|
}
|
2016-06-19 01:02:20 +00:00
|
|
|
}
|
2017-10-06 20:46:24 +00:00
|
|
|
{
|
|
|
|
B3_PROFILE("registerGraphicsShape");
|
|
|
|
graphicsIndex = m_data->m_guiHelper->registerGraphicsShape(&vertices[0].xyzw[0], vertices.size(), &indices[0], indices.size(), B3_GL_TRIANGLES, textureIndex);
|
|
|
|
}
|
2016-06-19 01:02:20 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2016-06-19 01:02:20 +00:00
|
|
|
//delete textures
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < textures.size(); i++)
|
2016-06-19 01:02:20 +00:00
|
|
|
{
|
2017-10-06 20:46:24 +00:00
|
|
|
B3_PROFILE("free textureData");
|
2017-10-25 15:15:01 +00:00
|
|
|
if (!textures[i].m_isCached)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
free(textures[i].textureData1);
|
2017-10-25 15:15:01 +00:00
|
|
|
}
|
2016-06-01 05:55:13 +00:00
|
|
|
}
|
|
|
|
return graphicsIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BulletURDFImporter::getLinkColor(int linkIndex, btVector4& colorRGBA) const
|
|
|
|
{
|
2017-06-01 19:32:44 +00:00
|
|
|
const UrdfMaterialColor* matColPtr = m_data->m_linkColors[linkIndex];
|
|
|
|
if (matColPtr)
|
|
|
|
{
|
|
|
|
colorRGBA = matColPtr->m_rgbaColor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BulletURDFImporter::getLinkColor2(int linkIndex, UrdfMaterialColor& matCol) const
|
|
|
|
{
|
|
|
|
UrdfMaterialColor* matColPtr = m_data->m_linkColors[linkIndex];
|
|
|
|
if (matColPtr)
|
2016-06-01 05:55:13 +00:00
|
|
|
{
|
2017-06-01 19:32:44 +00:00
|
|
|
matCol = *matColPtr;
|
2016-06-01 05:55:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-23 03:26:00 +00:00
|
|
|
void BulletURDFImporter::setLinkColor2(int linkIndex, struct UrdfMaterialColor& matCol) const
|
|
|
|
{
|
|
|
|
m_data->m_linkColors.insert(linkIndex, matCol);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool BulletURDFImporter::getLinkContactInfo(int urdflinkIndex, URDFLinkContactInfo& contactInfo) const
|
2016-07-11 07:26:40 +00:00
|
|
|
{
|
2017-05-01 18:14:09 +00:00
|
|
|
UrdfLink* const* linkPtr = m_data->m_urdfParser.getModel().m_links.getAtIndex(urdflinkIndex);
|
2016-07-11 07:26:40 +00:00
|
|
|
if (linkPtr)
|
|
|
|
{
|
|
|
|
const UrdfLink* link = *linkPtr;
|
|
|
|
contactInfo = link->m_contactInfo;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-01 05:55:13 +00:00
|
|
|
|
2017-05-01 18:14:09 +00:00
|
|
|
bool BulletURDFImporter::getLinkAudioSource(int linkIndex, SDFAudioSource& audioSource) const
|
|
|
|
{
|
|
|
|
UrdfLink* const* linkPtr = m_data->m_urdfParser.getModel().m_links.getAtIndex(linkIndex);
|
|
|
|
if (linkPtr)
|
|
|
|
{
|
|
|
|
const UrdfLink* link = *linkPtr;
|
|
|
|
if (link->m_audioSource.m_flags & SDFAudioSource::SDFAudioSourceValid)
|
|
|
|
{
|
|
|
|
audioSource = link->m_audioSource;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-06 20:46:24 +00:00
|
|
|
void BulletURDFImporter::setEnableTinyRenderer(bool enable)
|
|
|
|
{
|
|
|
|
m_data->m_enableTinyRenderer = enable;
|
|
|
|
}
|
|
|
|
|
2017-03-16 23:09:55 +00:00
|
|
|
void BulletURDFImporter::convertLinkVisualShapes2(int linkIndex, int urdfIndex, const char* pathPrefix, const btTransform& localInertiaFrame, class btCollisionObject* colObj, int bodyUniqueId) const
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_data->m_enableTinyRenderer && m_data->m_customVisualShapesConverter)
|
2016-05-20 01:37:15 +00:00
|
|
|
{
|
|
|
|
const UrdfModel& model = m_data->m_urdfParser.getModel();
|
2018-09-23 21:17:31 +00:00
|
|
|
UrdfLink* const* linkPtr = model.m_links.getAtIndex(urdfIndex);
|
2017-03-16 23:09:55 +00:00
|
|
|
if (linkPtr)
|
|
|
|
{
|
2018-10-14 22:10:19 +00:00
|
|
|
m_data->m_customVisualShapesConverter->setFlags(m_data->m_flags);
|
2018-10-09 04:27:08 +00:00
|
|
|
m_data->m_customVisualShapesConverter->convertVisualShapes(linkIndex, pathPrefix, localInertiaFrame, *linkPtr, &model, colObj->getBroadphaseHandle()->getUid(), bodyUniqueId, m_data->m_fileIO);
|
2017-03-16 23:09:55 +00:00
|
|
|
}
|
2015-06-28 21:09:21 +00:00
|
|
|
}
|
2015-04-22 23:35:27 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:42:02 +00:00
|
|
|
int BulletURDFImporter::getNumAllocatedCollisionShapes() const
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
return m_data->m_allocatedCollisionShapes.size();
|
2016-04-11 23:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
btCollisionShape* BulletURDFImporter::getAllocatedCollisionShape(int index)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
return m_data->m_allocatedCollisionShapes[index];
|
2016-04-11 23:42:02 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 16:16:11 +00:00
|
|
|
int BulletURDFImporter::getNumAllocatedMeshInterfaces() const
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
return m_data->m_allocatedMeshInterfaces.size();
|
2017-08-24 16:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
btStridingMeshInterface* BulletURDFImporter::getAllocatedMeshInterface(int index)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
return m_data->m_allocatedMeshInterfaces[index];
|
2017-08-24 16:16:11 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 07:22:16 +00:00
|
|
|
int BulletURDFImporter::getNumAllocatedTextures() const
|
|
|
|
{
|
|
|
|
return m_data->m_allocatedTextures.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int BulletURDFImporter::getAllocatedTexture(int index) const
|
|
|
|
{
|
|
|
|
return m_data->m_allocatedTextures[index];
|
|
|
|
}
|
|
|
|
|
2018-09-13 02:30:49 +00:00
|
|
|
int BulletURDFImporter::getCollisionGroupAndMask(int linkIndex, int& colGroup, int& colMask) const
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
UrdfLink* const* linkPtr = m_data->m_urdfParser.getModel().m_links.getAtIndex(linkIndex);
|
|
|
|
btAssert(linkPtr);
|
|
|
|
if (linkPtr)
|
|
|
|
{
|
|
|
|
UrdfLink* link = *linkPtr;
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int v = 0; v < link->m_collisionArray.size(); v++)
|
2018-09-13 02:30:49 +00:00
|
|
|
{
|
|
|
|
const UrdfCollision& col = link->m_collisionArray[v];
|
|
|
|
if (col.m_flags & URDF_HAS_COLLISION_GROUP)
|
|
|
|
{
|
|
|
|
colGroup = col.m_collisionGroup;
|
|
|
|
result |= URDF_HAS_COLLISION_GROUP;
|
|
|
|
}
|
|
|
|
if (col.m_flags & URDF_HAS_COLLISION_MASK)
|
|
|
|
{
|
|
|
|
colMask = col.m_collisionMask;
|
|
|
|
result |= URDF_HAS_COLLISION_MASK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2017-08-24 16:16:11 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
class btCompoundShape* BulletURDFImporter::convertLinkCollisionShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame) const
|
2015-04-22 23:35:27 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
btCompoundShape* compoundShape = new btCompoundShape();
|
|
|
|
m_data->m_allocatedCollisionShapes.push_back(compoundShape);
|
|
|
|
|
|
|
|
compoundShape->setMargin(gUrdfDefaultCollisionMargin);
|
2015-06-28 21:09:21 +00:00
|
|
|
UrdfLink* const* linkPtr = m_data->m_urdfParser.getModel().m_links.getAtIndex(linkIndex);
|
|
|
|
btAssert(linkPtr);
|
|
|
|
if (linkPtr)
|
|
|
|
{
|
|
|
|
UrdfLink* link = *linkPtr;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
for (int v = 0; v < link->m_collisionArray.size(); v++)
|
2015-06-28 21:09:21 +00:00
|
|
|
{
|
|
|
|
const UrdfCollision& col = link->m_collisionArray[v];
|
2018-09-23 21:17:31 +00:00
|
|
|
btCollisionShape* childShape = convertURDFToCollisionShape(&col, pathPrefix);
|
2018-10-09 04:27:08 +00:00
|
|
|
if (childShape)
|
2017-06-08 02:00:44 +00:00
|
|
|
{
|
2018-10-09 04:27:08 +00:00
|
|
|
m_data->m_allocatedCollisionShapes.push_back(childShape);
|
|
|
|
if (childShape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
|
2017-06-08 02:00:44 +00:00
|
|
|
{
|
2018-10-09 04:27:08 +00:00
|
|
|
btCompoundShape* compound = (btCompoundShape*)childShape;
|
|
|
|
for (int i = 0; i < compound->getNumChildShapes(); i++)
|
|
|
|
{
|
|
|
|
m_data->m_allocatedCollisionShapes.push_back(compound->getChildShape(i));
|
|
|
|
}
|
2017-06-08 02:00:44 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
btTransform childTrans = col.m_linkLocalFrame;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
compoundShape->addChildShape(localInertiaFrame.inverse() * childTrans, childShape);
|
2016-07-17 00:58:06 +00:00
|
|
|
}
|
2015-06-28 21:09:21 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
return compoundShape;
|
2015-04-22 23:35:27 +00:00
|
|
|
}
|