implement specular, URDF non-standard specular part (see sphere2.urdf) and SDF specular support.
pybullet.changeVisualShape(obUid,linkIndex,specularColor=[R,G,B]) and Bullet C-API b3UpdateVisualShapeSpecularColor Bug fixes in b3ResourcePath::findResourcePath resolution. add stadium.sdf and roboschool/models_outdoor/stadium assets https://github.com/openai/roboschool/tree/master/roboschool/models_outdoor/stadium minor fixes to obj2sdf
This commit is contained in:
@@ -42,6 +42,7 @@ struct MyTexture
|
||||
unsigned char* textureData;
|
||||
};
|
||||
|
||||
|
||||
ATTRIBUTE_ALIGNED16(struct) BulletURDFInternalData
|
||||
{
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
@@ -51,7 +52,7 @@ ATTRIBUTE_ALIGNED16(struct) BulletURDFInternalData
|
||||
std::string m_sourceFile;
|
||||
char m_pathPrefix[1024];
|
||||
int m_bodyId;
|
||||
btHashMap<btHashInt,btVector4> m_linkColors;
|
||||
btHashMap<btHashInt,UrdfMaterialColor> m_linkColors;
|
||||
btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes;
|
||||
|
||||
LinkVisualShapesConverter* m_customVisualShapesConverter;
|
||||
@@ -1094,7 +1095,10 @@ int BulletURDFImporter::convertLinkVisualShapes(int linkIndex, const char* pathP
|
||||
{
|
||||
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]);
|
||||
m_data->m_linkColors.insert(linkIndex,mat->m_rgbaColor);
|
||||
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);
|
||||
}
|
||||
convertURDFToVisualShapeInternal(&vis, pathPrefix, localInertiaFrame.inverse()*childTrans, vertices, indices,textures);
|
||||
|
||||
@@ -1132,10 +1136,21 @@ int BulletURDFImporter::convertLinkVisualShapes(int linkIndex, const char* pathP
|
||||
|
||||
bool BulletURDFImporter::getLinkColor(int linkIndex, btVector4& colorRGBA) const
|
||||
{
|
||||
const btVector4* rgbaPtr = m_data->m_linkColors[linkIndex];
|
||||
if (rgbaPtr)
|
||||
const UrdfMaterialColor* matColPtr = m_data->m_linkColors[linkIndex];
|
||||
if (matColPtr)
|
||||
{
|
||||
colorRGBA = *rgbaPtr;
|
||||
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)
|
||||
{
|
||||
matCol = *matColPtr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -41,6 +41,8 @@ public:
|
||||
|
||||
virtual bool getLinkColor(int linkIndex, btVector4& colorRGBA) const;
|
||||
|
||||
virtual bool getLinkColor2(int linkIndex, UrdfMaterialColor& matCol) const;
|
||||
|
||||
virtual bool getLinkContactInfo(int urdflinkIndex, URDFLinkContactInfo& contactInfo ) const;
|
||||
|
||||
virtual bool getLinkAudioSource(int linkIndex, SDFAudioSource& audioSource) const;
|
||||
|
||||
@@ -11,9 +11,17 @@ public:
|
||||
|
||||
|
||||
virtual void createRigidBodyGraphicsInstance(int linkIndex, class btRigidBody* body, const btVector3& colorRgba, int graphicsIndex) = 0;
|
||||
|
||||
virtual void createRigidBodyGraphicsInstance2(int linkIndex, class btRigidBody* body, const btVector3& colorRgba, const btVector3& specularColor, int graphicsIndex)
|
||||
{
|
||||
createRigidBodyGraphicsInstance(linkIndex,body,colorRgba,graphicsIndex);
|
||||
}
|
||||
|
||||
///optionally create some graphical representation from a collision object, usually for visual debugging purposes.
|
||||
virtual void createCollisionObjectGraphicsInstance(int linkIndex, class btCollisionObject* col, const btVector3& colorRgba) = 0;
|
||||
virtual void createCollisionObjectGraphicsInstance2(int linkIndex, class btCollisionObject* col, const btVector4& colorRgba, const btVector3& specularColor)
|
||||
{
|
||||
createCollisionObjectGraphicsInstance(linkIndex,col,colorRgba);
|
||||
}
|
||||
|
||||
virtual class btMultiBody* allocateMultiBody(int urdfLinkIndex, int totalNumJoints,btScalar mass, const btVector3& localInertiaDiagonal, bool isFixedBase, bool canSleep) =0;
|
||||
|
||||
|
||||
@@ -194,15 +194,33 @@ void MyMultiBodyCreator::addLinkMapping(int urdfLinkIndex, int mbLinkIndex)
|
||||
|
||||
void MyMultiBodyCreator::createRigidBodyGraphicsInstance(int linkIndex, btRigidBody* body, const btVector3& colorRgba, int graphicsIndex)
|
||||
{
|
||||
|
||||
m_guiHelper->createRigidBodyGraphicsObject(body, colorRgba);
|
||||
}
|
||||
|
||||
void MyMultiBodyCreator::createRigidBodyGraphicsInstance2(int linkIndex, class btRigidBody* body, const btVector3& colorRgba, const btVector3& specularColor, int graphicsIndex)
|
||||
{
|
||||
m_guiHelper->createRigidBodyGraphicsObject(body, colorRgba);
|
||||
int graphicsInstanceId = body->getUserIndex();
|
||||
m_guiHelper->changeSpecularColor(graphicsInstanceId,specularColor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MyMultiBodyCreator::createCollisionObjectGraphicsInstance(int linkIndex, class btCollisionObject* colObj, const btVector3& colorRgba)
|
||||
{
|
||||
m_guiHelper->createCollisionObjectGraphicsObject(colObj,colorRgba);
|
||||
}
|
||||
|
||||
void MyMultiBodyCreator::createCollisionObjectGraphicsInstance2(int linkIndex, class btCollisionObject* col, const btVector4& colorRgba, const btVector3& specularColor)
|
||||
{
|
||||
createCollisionObjectGraphicsInstance(linkIndex,col,colorRgba);
|
||||
int graphicsInstanceId = col->getUserIndex();
|
||||
m_guiHelper->changeSpecularColor(graphicsInstanceId,specularColor);
|
||||
|
||||
}
|
||||
|
||||
|
||||
btMultiBody* MyMultiBodyCreator::getBulletMultiBody()
|
||||
{
|
||||
return m_bulletMultiBody;
|
||||
|
||||
@@ -41,10 +41,12 @@ public:
|
||||
virtual ~MyMultiBodyCreator() {}
|
||||
|
||||
virtual void createRigidBodyGraphicsInstance(int linkIndex, class btRigidBody* body, const btVector3& colorRgba, int graphicsIndex) ;
|
||||
virtual void createRigidBodyGraphicsInstance2(int linkIndex, class btRigidBody* body, const btVector3& colorRgba, const btVector3& specularColor, int graphicsIndex) ;
|
||||
|
||||
///optionally create some graphical representation from a collision object, usually for visual debugging purposes.
|
||||
virtual void createCollisionObjectGraphicsInstance(int linkIndex, class btCollisionObject* col, const btVector3& colorRgba);
|
||||
|
||||
virtual void createCollisionObjectGraphicsInstance2(int linkIndex, class btCollisionObject* col, const btVector4& colorRgba, const btVector3& specularColor);
|
||||
|
||||
virtual class btMultiBody* allocateMultiBody(int urdfLinkIndex, int totalNumJoints,btScalar mass, const btVector3& localInertiaDiagonal, bool isFixedBase, bool canSleep);
|
||||
|
||||
virtual class btRigidBody* allocateRigidBody(int urdfLinkIndex, btScalar mass, const btVector3& localInertiaDiagonal, const btTransform& initialWorldTrans, class btCollisionShape* colShape);
|
||||
|
||||
@@ -272,8 +272,15 @@ void ConvertURDF2BulletInternal(
|
||||
{
|
||||
|
||||
|
||||
btVector4 color = selectColor2();
|
||||
u2b.getLinkColor(urdfLinkIndex,color);
|
||||
UrdfMaterialColor matColor;
|
||||
btVector4 color2 = selectColor2();
|
||||
btVector3 specular(0.5,0.5,0.5);
|
||||
if (u2b.getLinkColor2(urdfLinkIndex,matColor))
|
||||
{
|
||||
color2 = matColor.m_rgbaColor;
|
||||
specular = matColor.m_specularColor;
|
||||
}
|
||||
|
||||
/*
|
||||
if (visual->material.get())
|
||||
{
|
||||
@@ -315,7 +322,7 @@ void ConvertURDF2BulletInternal(
|
||||
u2b.getLinkContactInfo(urdfLinkIndex, contactInfo);
|
||||
|
||||
processContactParameters(contactInfo, body);
|
||||
creation.createRigidBodyGraphicsInstance(urdfLinkIndex, body, color, graphicsIndex);
|
||||
creation.createRigidBodyGraphicsInstance2(urdfLinkIndex, body, color2,specular, graphicsIndex);
|
||||
cache.registerRigidBody(urdfLinkIndex, body, inertialFrameInWorldSpace, mass, localInertiaDiagonal, compoundShape, localInertialFrame);
|
||||
|
||||
|
||||
@@ -490,9 +497,16 @@ void ConvertURDF2BulletInternal(
|
||||
}
|
||||
world1->addCollisionObject(col,collisionFilterGroup,collisionFilterMask);
|
||||
|
||||
btVector4 color = selectColor2();//(0.0,0.0,0.5);
|
||||
u2b.getLinkColor(urdfLinkIndex,color);
|
||||
creation.createCollisionObjectGraphicsInstance(urdfLinkIndex,col,color);
|
||||
btVector4 color2 = selectColor2();//(0.0,0.0,0.5);
|
||||
btVector3 specularColor(1,1,1);
|
||||
UrdfMaterialColor matCol;
|
||||
if (u2b.getLinkColor2(urdfLinkIndex,matCol))
|
||||
{
|
||||
color2 = matCol.m_rgbaColor;
|
||||
specularColor = matCol.m_specularColor;
|
||||
}
|
||||
|
||||
creation.createCollisionObjectGraphicsInstance2(urdfLinkIndex,col,color2,specularColor);
|
||||
|
||||
u2b.convertLinkVisualShapes2(mbLinkIndex, urdfLinkIndex, pathPrefix, localInertialFrame,col, u2b.getBodyUniqueId());
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@ public:
|
||||
/// optional method to provide the link color. return true if the color is available and copied into colorRGBA, return false otherwise
|
||||
virtual bool getLinkColor(int linkIndex, btVector4& colorRGBA) const { return false;}
|
||||
|
||||
virtual bool getLinkColor2(int linkIndex, struct UrdfMaterialColor& matCol) const { return false;}
|
||||
|
||||
|
||||
virtual int getCollisionGroupAndMask(int linkIndex, int& colGroup, int& colMask) const { return 0;}
|
||||
///this API will likely change, don't override it!
|
||||
virtual bool getLinkContactInfo(int linkIndex, URDFLinkContactInfo& contactInfo ) const { return false;}
|
||||
|
||||
@@ -63,4 +63,15 @@ enum UrdfCollisionFlags
|
||||
URDF_HAS_COLLISION_MASK=4,
|
||||
};
|
||||
|
||||
struct UrdfMaterialColor
|
||||
{
|
||||
btVector4 m_rgbaColor;
|
||||
btVector3 m_specularColor;
|
||||
UrdfMaterialColor()
|
||||
:m_rgbaColor(0.8, 0.8, 0.8, 1),
|
||||
m_specularColor(0.5,0.5,0.5)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif //URDF_JOINT_TYPES_H
|
||||
|
||||
@@ -100,17 +100,33 @@ bool UrdfParser::parseMaterial(UrdfMaterial& material, TiXmlElement *config, Err
|
||||
}
|
||||
|
||||
// color
|
||||
TiXmlElement *c = config->FirstChildElement("color");
|
||||
if (c)
|
||||
{
|
||||
if (c->Attribute("rgba"))
|
||||
{
|
||||
if (!parseVector4(material.m_rgbaColor,c->Attribute("rgba")))
|
||||
TiXmlElement *c = config->FirstChildElement("color");
|
||||
if (c)
|
||||
{
|
||||
if (c->Attribute("rgba"))
|
||||
{
|
||||
std::string msg = material.m_name+" has no rgba";
|
||||
logger->reportWarning(msg.c_str());
|
||||
if (!parseVector4(material.m_matColor.m_rgbaColor,c->Attribute("rgba")))
|
||||
{
|
||||
std::string msg = material.m_name+" has no rgba";
|
||||
logger->reportWarning(msg.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// specular (non-standard)
|
||||
TiXmlElement *s = config->FirstChildElement("specular");
|
||||
if (s)
|
||||
{
|
||||
if (s->Attribute("rgb"))
|
||||
{
|
||||
if (!parseVector3(material.m_matColor.m_specularColor,s->Attribute("rgb"),logger))
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -552,16 +568,29 @@ bool UrdfParser::parseVisual(UrdfModel& model, UrdfVisual& visual, TiXmlElement*
|
||||
if (name_char)
|
||||
matPtr->m_name = name_char;
|
||||
model.m_materials.insert(matPtr->m_name.c_str(),matPtr);
|
||||
TiXmlElement *diffuse = mat->FirstChildElement("diffuse");
|
||||
if (diffuse) {
|
||||
std::string diffuseText = diffuse->GetText();
|
||||
btVector4 rgba(1,0,0,1);
|
||||
parseVector4(rgba,diffuseText);
|
||||
matPtr->m_rgbaColor = rgba;
|
||||
{
|
||||
TiXmlElement *diffuse = mat->FirstChildElement("diffuse");
|
||||
if (diffuse) {
|
||||
std::string diffuseText = diffuse->GetText();
|
||||
btVector4 rgba(1,0,0,1);
|
||||
parseVector4(rgba,diffuseText);
|
||||
matPtr->m_matColor.m_rgbaColor = rgba;
|
||||
|
||||
visual.m_materialName = matPtr->m_name;
|
||||
visual.m_geometry.m_hasLocalMaterial = true;
|
||||
}
|
||||
visual.m_materialName = matPtr->m_name;
|
||||
visual.m_geometry.m_hasLocalMaterial = true;
|
||||
}
|
||||
}
|
||||
{
|
||||
TiXmlElement *specular = mat->FirstChildElement("specular");
|
||||
if (specular) {
|
||||
std::string specularText = specular->GetText();
|
||||
btVector3 rgba(1,1,1);
|
||||
parseVector3(rgba,specularText,logger);
|
||||
matPtr->m_matColor.m_specularColor = rgba;
|
||||
visual.m_materialName = matPtr->m_name;
|
||||
visual.m_geometry.m_hasLocalMaterial = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -577,7 +606,8 @@ bool UrdfParser::parseVisual(UrdfModel& model, UrdfVisual& visual, TiXmlElement*
|
||||
|
||||
TiXmlElement *t = mat->FirstChildElement("texture");
|
||||
TiXmlElement *c = mat->FirstChildElement("color");
|
||||
if (t||c)
|
||||
TiXmlElement *s = mat->FirstChildElement("specular");
|
||||
if (t||c||s)
|
||||
{
|
||||
if (parseMaterial(visual.m_geometry.m_localMaterial, mat,logger))
|
||||
{
|
||||
|
||||
@@ -17,13 +17,15 @@ struct ErrorLogger
|
||||
virtual void printMessage(const char* msg)=0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct UrdfMaterial
|
||||
{
|
||||
std::string m_name;
|
||||
std::string m_textureFilename;
|
||||
btVector4 m_rgbaColor; // [0]==r [1]==g [2]==b [3]==a
|
||||
UrdfMaterial():
|
||||
m_rgbaColor(0.8, 0.8, 0.8, 1)
|
||||
UrdfMaterialColor m_matColor;
|
||||
|
||||
UrdfMaterial()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user