diff --git a/examples/Importers/ImportURDFDemo/UrdfRenderingInterface.h b/examples/Importers/ImportURDFDemo/UrdfRenderingInterface.h index 8c5c9a5d6..5404fae8b 100644 --- a/examples/Importers/ImportURDFDemo/UrdfRenderingInterface.h +++ b/examples/Importers/ImportURDFDemo/UrdfRenderingInterface.h @@ -13,14 +13,14 @@ class btTransform; struct UrdfRenderingInterface { ///given a URDF link, convert all visual shapes into internal renderer (loading graphics meshes, textures etc) - ///use the shapeUid as a unique identified to remove it - virtual void convertVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfLink* linkPtr, const UrdfModel* model, int shapeUid, int objectIndex) =0; + ///use the collisionObjectUid as a unique identifier to synchronize the world transform and to remove the visual shape. + virtual void convertVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfLink* linkPtr, const UrdfModel* model, int collisionObjectUid, int bodyUniqueId) =0; ///remove a visual shapes, based on the shape unique id (shapeUid) - virtual void removeVisualShape(int shapeUid)=0; + virtual void removeVisualShape(int collisionObjectUid)=0; ///update the world transform + scaling of the visual shape, using the shapeUid - virtual void syncTransform(int shapeUid, const class btTransform& worldTransform, const class btVector3& localScaling)=0; + virtual void syncTransform(int collisionObjectUid, const class btTransform& worldTransform, const class btVector3& localScaling)=0; ///return the number of visual shapes, for a particular body unique id virtual int getNumVisualShapes(int bodyUniqueId)=0; @@ -28,9 +28,12 @@ struct UrdfRenderingInterface ///return the visual shape information, for a particular body unique id and 'shape index' virtual int getVisualShapesData(int bodyUniqueId, int shapeIndex, struct b3VisualShapeData* shapeData)=0; - ///change the RGBA color for a body unique id and link index - virtual void changeRGBAColor(int bodyUniqueId, int linkIndex, const double rgbaColor[4])=0; - + ///change the RGBA color for some visual shape. + virtual void changeRGBAColor(int bodyUniqueId, int linkIndex, int shapeIndex, const double rgbaColor[4])=0; + + ///select a given texture for some visual shape. + virtual void changeShapeTexture(int objectUniqueId, int linkIndex, int shapeIndex, int textureUniqueId)=0; + ///pick the up-axis, either Y (1) or Z (2) virtual void setUpAxis(int axis)=0; @@ -88,8 +91,7 @@ struct UrdfRenderingInterface ///register a texture using an in-memory pixel buffer of a given width and height virtual int registerTexture(unsigned char* texels, int width, int height)=0; - ///select a given texture for some visual shape. - virtual void activateShapeTexture(int objectUniqueId, int jointIndex, int shapeIndex, int textureUniqueId)=0; + }; diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index de13c05ce..a0471ff1d 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -8453,7 +8453,10 @@ bool PhysicsServerCommandProcessor::processUpdateVisualShapeCommand(const struct { if (m_data->m_pluginManager.getRenderInterface()) { - m_data->m_pluginManager.getRenderInterface()->activateShapeTexture(clientCmd.m_updateVisualShapeDataArguments.m_bodyUniqueId, clientCmd.m_updateVisualShapeDataArguments.m_jointIndex, clientCmd.m_updateVisualShapeDataArguments.m_shapeIndex, texHandle->m_tinyRendererTextureId); + m_data->m_pluginManager.getRenderInterface()->changeShapeTexture(clientCmd.m_updateVisualShapeDataArguments.m_bodyUniqueId, + clientCmd.m_updateVisualShapeDataArguments.m_jointIndex, + clientCmd.m_updateVisualShapeDataArguments.m_shapeIndex, + texHandle->m_tinyRendererTextureId); } } } @@ -8485,12 +8488,15 @@ bool PhysicsServerCommandProcessor::processUpdateVisualShapeCommand(const struct { if (m_data->m_pluginManager.getRenderInterface()) { - m_data->m_pluginManager.getRenderInterface()->changeRGBAColor(bodyUniqueId,linkIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); + m_data->m_pluginManager.getRenderInterface()->changeRGBAColor(bodyUniqueId,linkIndex, + clientCmd.m_updateVisualShapeDataArguments.m_shapeIndex, + clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); } m_data->m_guiHelper->changeRGBAColor(graphicsIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); } if (clientCmd.m_updateFlags & CMD_UPDATE_VISUAL_SHAPE_SPECULAR_COLOR) { + m_data->m_guiHelper->changeSpecularColor(graphicsIndex,clientCmd.m_updateVisualShapeDataArguments.m_specularColor); } @@ -8514,7 +8520,8 @@ bool PhysicsServerCommandProcessor::processUpdateVisualShapeCommand(const struct { if (m_data->m_pluginManager.getRenderInterface()) { - m_data->m_pluginManager.getRenderInterface()->changeRGBAColor(bodyUniqueId,linkIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); + m_data->m_pluginManager.getRenderInterface()->changeRGBAColor(bodyUniqueId,linkIndex, + clientCmd.m_updateVisualShapeDataArguments.m_shapeIndex, clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); } m_data->m_guiHelper->changeRGBAColor(graphicsIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); } @@ -8543,7 +8550,8 @@ bool PhysicsServerCommandProcessor::processUpdateVisualShapeCommand(const struct { if (m_data->m_pluginManager.getRenderInterface()) { - m_data->m_pluginManager.getRenderInterface()->changeRGBAColor(bodyUniqueId,linkIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); + m_data->m_pluginManager.getRenderInterface()->changeRGBAColor(bodyUniqueId,linkIndex, + clientCmd.m_updateVisualShapeDataArguments.m_shapeIndex, clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); } m_data->m_guiHelper->changeRGBAColor(graphicsIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); } diff --git a/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.cpp b/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.cpp index e5c595f3c..8697f0b60 100644 --- a/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.cpp +++ b/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.cpp @@ -550,7 +550,7 @@ static btVector4 sColors[4] = void TinyRendererVisualShapeConverter::convertVisualShapes( int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfLink* linkPtr, const UrdfModel* model, - int shapeUid, int bodyUniqueId) + int collisionObjectUniqueId, int bodyUniqueId) { btAssert(linkPtr); // TODO: remove if (not doing it now, because diff will be 50+ lines) if (linkPtr) @@ -627,12 +627,12 @@ void TinyRendererVisualShapeConverter::convertVisualShapes( } } - TinyRendererObjectArray** visualsPtr = m_data->m_swRenderInstances[shapeUid]; + TinyRendererObjectArray** visualsPtr = m_data->m_swRenderInstances[collisionObjectUniqueId]; if (visualsPtr==0) { - m_data->m_swRenderInstances.insert(shapeUid,new TinyRendererObjectArray); + m_data->m_swRenderInstances.insert(collisionObjectUniqueId,new TinyRendererObjectArray); } - visualsPtr = m_data->m_swRenderInstances[shapeUid]; + visualsPtr = m_data->m_swRenderInstances[collisionObjectUniqueId]; btAssert(visualsPtr); TinyRendererObjectArray* visuals = *visualsPtr; @@ -753,7 +753,7 @@ int TinyRendererVisualShapeConverter::getVisualShapesData(int bodyUniqueId, int -void TinyRendererVisualShapeConverter::changeRGBAColor(int bodyUniqueId, int linkIndex, const double rgbaColor[4]) +void TinyRendererVisualShapeConverter::changeRGBAColor(int bodyUniqueId, int linkIndex, int shapeIndex, const double rgbaColor[4]) { int start = -1; for (int i = 0; i < m_data->m_visualShapes.size(); i++) @@ -778,7 +778,10 @@ void TinyRendererVisualShapeConverter::changeRGBAColor(int bodyUniqueId, int lin { for (int q=0;qm_renderObjects.size();q++) { - visuals->m_renderObjects[q]->m_model->setColorRGBA(rgba); + if (shapeIndex<0 || q==shapeIndex) + { + visuals->m_renderObjects[q]->m_model->setColorRGBA(rgba); + } } } } @@ -786,6 +789,7 @@ void TinyRendererVisualShapeConverter::changeRGBAColor(int bodyUniqueId, int lin } + void TinyRendererVisualShapeConverter::setUpAxis(int axis) { m_data->m_upAxis = axis; @@ -832,9 +836,9 @@ void TinyRendererVisualShapeConverter::render() } -void TinyRendererVisualShapeConverter::syncTransform(int shapeUid, const btTransform& worldTransform, const btVector3& localScaling) +void TinyRendererVisualShapeConverter::syncTransform(int collisionObjectUniqueId, const btTransform& worldTransform, const btVector3& localScaling) { - TinyRendererObjectArray** renderObjPtr = m_data->m_swRenderInstances[shapeUid]; + TinyRendererObjectArray** renderObjPtr = m_data->m_swRenderInstances[collisionObjectUniqueId]; if (renderObjPtr) { TinyRendererObjectArray* renderObj = *renderObjPtr; @@ -1109,9 +1113,9 @@ void TinyRendererVisualShapeConverter::copyCameraImageData(unsigned char* pixels } } -void TinyRendererVisualShapeConverter::removeVisualShape(int shapeUid) +void TinyRendererVisualShapeConverter::removeVisualShape(int collisionObjectUniqueId) { - TinyRendererObjectArray** ptrptr = m_data->m_swRenderInstances[shapeUid]; + TinyRendererObjectArray** ptrptr = m_data->m_swRenderInstances[collisionObjectUniqueId]; if (ptrptr && *ptrptr) { TinyRendererObjectArray* ptr = *ptrptr; @@ -1123,7 +1127,7 @@ void TinyRendererVisualShapeConverter::removeVisualShape(int shapeUid) } } delete ptr; - m_data->m_swRenderInstances.remove(shapeUid); + m_data->m_swRenderInstances.remove(collisionObjectUniqueId); } } @@ -1160,7 +1164,7 @@ void TinyRendererVisualShapeConverter::resetAll() } -void TinyRendererVisualShapeConverter::activateShapeTexture(int objectUniqueId, int jointIndex, int shapeIndex, int textureUniqueId) +void TinyRendererVisualShapeConverter::changeShapeTexture(int objectUniqueId, int jointIndex, int shapeIndex, int textureUniqueId) { btAssert(textureUniqueId < m_data->m_textures.size()); if (textureUniqueId >= 0 && textureUniqueId < m_data->m_textures.size()) diff --git a/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.h b/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.h index 60f9089b4..98d9dc076 100644 --- a/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.h +++ b/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.h @@ -18,7 +18,9 @@ struct TinyRendererVisualShapeConverter : public UrdfRenderingInterface virtual int getVisualShapesData(int bodyUniqueId, int shapeIndex, struct b3VisualShapeData* shapeData); - virtual void changeRGBAColor(int bodyUniqueId, int linkIndex, const double rgbaColor[4]); + virtual void changeRGBAColor(int bodyUniqueId, int linkIndex, int shapeIndex, const double rgbaColor[4]); + + virtual void changeShapeTexture(int objectUniqueId, int linkIndex, int shapeIndex, int textureUniqueId); virtual void removeVisualShape(int shapeUid); @@ -49,7 +51,7 @@ struct TinyRendererVisualShapeConverter : public UrdfRenderingInterface virtual int loadTextureFile(const char* filename); virtual int registerTexture(unsigned char* texels, int width, int height); - virtual void activateShapeTexture(int objectUniqueId, int jointIndex, int shapeIndex, int textureUniqueId); + virtual void syncTransform(int shapeUid, const class btTransform& worldTransform, const class btVector3& localScaling);