diff --git a/examples/SharedMemory/PhysicsClientExample.cpp b/examples/SharedMemory/PhysicsClientExample.cpp index 0a9cfa805..df914fafe 100644 --- a/examples/SharedMemory/PhysicsClientExample.cpp +++ b/examples/SharedMemory/PhysicsClientExample.cpp @@ -526,6 +526,18 @@ void PhysicsClientExample::prepareAndSubmitCommand(int commandId) b3SubmitClientCommand(m_physicsClientHandle, commandHandle); break; } + case CMD_UPDATE_VISUAL_SHAPE: + { + int objectUniqueId = 0; + int linkIndex = -1; + int shapeIndex = -1; + int textureIndex = -1; + double rgbaColor[4] = {0.0, 1.0, 0.0, 1.0}; + b3SharedMemoryCommandHandle commandHandle = b3InitUpdateVisualShape(m_physicsClientHandle, objectUniqueId, linkIndex, shapeIndex, textureIndex); + b3UpdateVisualShapeRGBAColor(commandHandle, rgbaColor); + b3SubmitClientCommand(m_physicsClientHandle, commandHandle); + break; + } default: { @@ -604,6 +616,7 @@ void PhysicsClientExample::createButtons() createButton("Load SDF",CMD_LOAD_SDF, isTrigger); createButton("Save World",CMD_SAVE_WORLD, isTrigger); createButton("Set Shadow",CMD_SET_SHADOW, isTrigger); + createButton("Update Visual Shape",CMD_UPDATE_VISUAL_SHAPE, isTrigger); createButton("Get Camera Image",CMD_REQUEST_CAMERA_IMAGE_DATA,isTrigger); createButton("Step Sim",CMD_STEP_FORWARD_SIMULATION, isTrigger); createButton("Realtime Sim",CMD_CUSTOM_SET_REALTIME_SIMULATION, isTrigger); diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index d1e3d4ddc..0f5538d6e 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -5631,7 +5631,7 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm { if (bodyHandle->m_multiBody->getBaseCollider()) { - //m_data->m_visualConverter.changeRGBAColor(...) + m_data->m_visualConverter.changeRGBAColor(bodyUniqueId,linkIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); int graphicsIndex = bodyHandle->m_multiBody->getBaseCollider()->getUserIndex(); m_data->m_guiHelper->changeRGBAColor(graphicsIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); } @@ -5641,7 +5641,7 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm { if (bodyHandle->m_multiBody->getLink(linkIndex).m_collider) { - //m_data->m_visualConverter.changeRGBAColor(...) + m_data->m_visualConverter.changeRGBAColor(bodyUniqueId,linkIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); int graphicsIndex = bodyHandle->m_multiBody->getLink(linkIndex).m_collider->getUserIndex(); m_data->m_guiHelper->changeRGBAColor(graphicsIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); } diff --git a/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp b/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp index a9bcd3256..4be708af7 100644 --- a/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp +++ b/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp @@ -671,6 +671,34 @@ int TinyRendererVisualShapeConverter::getVisualShapesData(int bodyUniqueId, int return 0; } +void TinyRendererVisualShapeConverter::changeRGBAColor(int bodyUniqueId, int linkIndex, const double rgbaColor[4]) +{ + int start = -1; + for (int i = 0; i < m_data->m_visualShapes.size(); i++) + { + if (m_data->m_visualShapes[i].m_objectUniqueId == bodyUniqueId && m_data->m_visualShapes[i].m_linkIndex == linkIndex) + { + start = i; + m_data->m_visualShapes[i].m_rgbaColor[0] = rgbaColor[0]; + m_data->m_visualShapes[i].m_rgbaColor[1] = rgbaColor[1]; + m_data->m_visualShapes[i].m_rgbaColor[2] = rgbaColor[2]; + m_data->m_visualShapes[i].m_rgbaColor[3] = rgbaColor[3]; + break; + } + } + + TinyRendererObjectArray** visualArrayPtr = m_data->m_swRenderInstances.getAtIndex(start); + TinyRendererObjectArray* visualArray = *visualArrayPtr; + + btHashPtr colObjHash = m_data->m_swRenderInstances.getKeyAtIndex(start); + const btCollisionObject* colObj = (btCollisionObject*) colObjHash.getPointer(); + + float rgba[4] = {rgbaColor[0], rgbaColor[1], rgbaColor[2], rgbaColor[3]}; + for (int v=0;vm_renderObjects.size();v++) + { + visualArray->m_renderObjects[v]->m_model->setColorRGBA(rgba); + } +} void TinyRendererVisualShapeConverter::setUpAxis(int axis) { diff --git a/examples/SharedMemory/TinyRendererVisualShapeConverter.h b/examples/SharedMemory/TinyRendererVisualShapeConverter.h index 9af426fda..4c979ae13 100644 --- a/examples/SharedMemory/TinyRendererVisualShapeConverter.h +++ b/examples/SharedMemory/TinyRendererVisualShapeConverter.h @@ -21,6 +21,8 @@ struct TinyRendererVisualShapeConverter : public LinkVisualShapesConverter virtual int getNumVisualShapes(int bodyUniqueId); virtual int getVisualShapesData(int bodyUniqueId, int shapeIndex, struct b3VisualShapeData* shapeData); + + virtual void changeRGBAColor(int bodyUniqueId, int shapeIndex, const double rgbaColor[4]); virtual void removeVisualShape(class btCollisionObject* colObj);