From 8f380b3fd24164ebbb276aefdcb0e240abb8ec19 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Fri, 8 May 2020 10:44:39 -0700 Subject: [PATCH] use white as default undefined color instead of the googley colors. use loadURDF(..., flags = pybullet.URDF_GOOGLEY_UNDEFINED_COLORS) to get Googley colors when colors are undefined. --- .../ImportMJCFDemo/BulletMJCFImporter.cpp | 12 ++++++++++-- .../Importers/ImportURDFDemo/URDF2Bullet.cpp | 19 ++++++++++--------- .../Importers/ImportURDFDemo/URDFJointTypes.h | 1 + examples/SharedMemory/SharedMemoryPublic.h | 1 + .../TinyRendererVisualShapeConverter.cpp | 4 ++-- examples/pybullet/pybullet.c | 1 + 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.cpp b/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.cpp index fe48dc8a6..b8142d90a 100644 --- a/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.cpp +++ b/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.cpp @@ -724,7 +724,14 @@ struct BulletMJCFImporterInternalData } { - geom.m_localMaterial.m_matColor.m_rgbaColor = sGoogleColors[linkIndex & 3]; + if (m_flags & CUF_GOOGLEY_UNDEFINED_COLORS) + { + geom.m_localMaterial.m_matColor.m_rgbaColor = sGoogleColors[linkIndex & 3]; + } + else + { + geom.m_localMaterial.m_matColor.m_rgbaColor.setValue(1, 1, 1, 1); + } geom.m_localMaterial.m_matColor.m_specularColor.setValue(1, 1, 1); geom.m_hasLocalMaterial = true; } @@ -1597,7 +1604,8 @@ bool BulletMJCFImporter::getLinkColor2(int linkIndex, struct UrdfMaterialColor& if (!hasLinkColor) { - matCol.m_rgbaColor = sGoogleColors[linkIndex & 3]; + + matCol.m_rgbaColor = (m_data->m_flags & CUF_GOOGLEY_UNDEFINED_COLORS) ? sGoogleColors[linkIndex & 3] : btVector4(1,1,1,1); matCol.m_specularColor.setValue(1, 1, 1); hasLinkColor = true; } diff --git a/examples/Importers/ImportURDFDemo/URDF2Bullet.cpp b/examples/Importers/ImportURDFDemo/URDF2Bullet.cpp index 1a85c1928..c21e7fc9a 100644 --- a/examples/Importers/ImportURDFDemo/URDF2Bullet.cpp +++ b/examples/Importers/ImportURDFDemo/URDF2Bullet.cpp @@ -21,12 +21,12 @@ //static int bodyCollisionFilterMask=btBroadphaseProxy::AllFilter&(~btBroadphaseProxy::CharacterFilter); static bool enableConstraints = true; -static btVector4 colors[4] = - { - btVector4(1, 0, 0, 1), - btVector4(0, 1, 0, 1), - btVector4(0, 1, 1, 1), - btVector4(1, 1, 0, 1), +static btVector4 gGoogleyColors[4] = +{ + btVector4(60. / 256., 186. / 256., 84. / 256., 1), + btVector4(244. / 256., 194. / 256., 13. / 256., 1), + btVector4(219. / 256., 50. / 256., 54. / 256., 1), + btVector4(72. / 256., 133. / 256., 237. / 256., 1), }; static btVector4 selectColor2() @@ -36,7 +36,7 @@ static btVector4 selectColor2() sMutex.lock(); #endif static int curColor = 0; - btVector4 color = colors[curColor]; + btVector4 color = gGoogleyColors[curColor]; curColor++; curColor &= 3; #ifdef BT_THREADSAFE @@ -303,7 +303,8 @@ btTransform ConvertURDF2BulletInternal( if (compoundShape) { UrdfMaterialColor matColor; - btVector4 color2 = selectColor2(); + + btVector4 color2 = (flags & CUF_GOOGLEY_UNDEFINED_COLORS) ? selectColor2() : btVector4(1, 1, 1, 1); btVector3 specular(0.5, 0.5, 0.5); if (u2b.getLinkColor2(urdfLinkIndex, matColor)) { @@ -642,7 +643,7 @@ btTransform ConvertURDF2BulletInternal( } world1->addCollisionObject(col, collisionFilterGroup, collisionFilterMask); - btVector4 color2 = selectColor2(); //(0.0,0.0,0.5); + btVector4 color2 = (flags & CUF_GOOGLEY_UNDEFINED_COLORS) ? selectColor2() : btVector4(1, 1, 1, 1); btVector3 specularColor(1, 1, 1); UrdfMaterialColor matCol; if (u2b.getLinkColor2(urdfLinkIndex, matCol)) diff --git a/examples/Importers/ImportURDFDemo/URDFJointTypes.h b/examples/Importers/ImportURDFDemo/URDFJointTypes.h index ed163ec34..fff0fee2e 100644 --- a/examples/Importers/ImportURDFDemo/URDFJointTypes.h +++ b/examples/Importers/ImportURDFDemo/URDFJointTypes.h @@ -104,6 +104,7 @@ enum ConvertURDFFlags CUF_IGNORE_VISUAL_SHAPES = 1 << 20, CUF_IGNORE_COLLISION_SHAPES = 1 << 21, CUF_PRINT_URDF_INFO = 1 << 22, + CUF_GOOGLEY_UNDEFINED_COLORS = 1 << 23, }; diff --git a/examples/SharedMemory/SharedMemoryPublic.h b/examples/SharedMemory/SharedMemoryPublic.h index eea99bd3c..cb94ec75b 100644 --- a/examples/SharedMemory/SharedMemoryPublic.h +++ b/examples/SharedMemory/SharedMemoryPublic.h @@ -931,6 +931,7 @@ enum eURDF_Flags URDF_IGNORE_VISUAL_SHAPES = 1 << 20, URDF_IGNORE_COLLISION_SHAPES = 1 << 21, URDF_PRINT_URDF_INFO = 1 << 22, + URDF_GOOGLEY_UNDEFINED_COLORS = 1 << 23, }; enum eUrdfGeomTypes //sync with UrdfParser UrdfGeomTypes diff --git a/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.cpp b/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.cpp index 6d0ce3fa2..6ffb5d2c1 100644 --- a/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.cpp +++ b/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.cpp @@ -646,7 +646,7 @@ static void convertURDFToVisualShape(const UrdfShape* visual, const char* urdfPa delete glmesh; } -static btVector4 sColors[4] = +static btVector4 sGoogleyColors[4] = { btVector4(60. / 256., 186. / 256., 84. / 256., 1), btVector4(244. / 256., 194. / 256., 13. / 256., 1), @@ -705,7 +705,7 @@ int TinyRendererVisualShapeConverter::convertVisualShapes( colorIndex = 0; colorIndex &= 3; btVector4 color; - color = sColors[colorIndex]; + color = (m_data->m_flags & URDF_GOOGLEY_UNDEFINED_COLORS) ? sGoogleyColors[colorIndex] : btVector4(1, 1, 1, 1); float rgbaColor[4] = {(float)color[0], (float)color[1], (float)color[2], (float)color[3]}; //if (colObj->getCollisionShape()->getShapeType()==STATIC_PLANE_PROXYTYPE) //{ diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index bb47c5948..dc70dd94e 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -12773,6 +12773,7 @@ initpybullet(void) PyModule_AddIntConstant(m, "URDF_IGNORE_VISUAL_SHAPES", URDF_IGNORE_VISUAL_SHAPES); PyModule_AddIntConstant(m, "URDF_IGNORE_COLLISION_SHAPES",URDF_IGNORE_COLLISION_SHAPES); PyModule_AddIntConstant(m, "URDF_PRINT_URDF_INFO", URDF_PRINT_URDF_INFO); + PyModule_AddIntConstant(m, "URDF_GOOGLEY_UNDEFINED_COLORS", URDF_GOOGLEY_UNDEFINED_COLORS); PyModule_AddIntConstant(m, "ACTIVATION_STATE_ENABLE_SLEEPING", eActivationStateEnableSleeping); PyModule_AddIntConstant(m, "ACTIVATION_STATE_DISABLE_SLEEPING", eActivationStateDisableSleeping);