Enable rgba color update for TinyRender.

This commit is contained in:
yunfeibai
2017-06-01 23:32:26 -07:00
parent e97bb9d494
commit f350a506a6
4 changed files with 45 additions and 2 deletions

View File

@@ -526,6 +526,18 @@ void PhysicsClientExample::prepareAndSubmitCommand(int commandId)
b3SubmitClientCommand(m_physicsClientHandle, commandHandle); b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
break; 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: default:
{ {
@@ -604,6 +616,7 @@ void PhysicsClientExample::createButtons()
createButton("Load SDF",CMD_LOAD_SDF, isTrigger); createButton("Load SDF",CMD_LOAD_SDF, isTrigger);
createButton("Save World",CMD_SAVE_WORLD, isTrigger); createButton("Save World",CMD_SAVE_WORLD, isTrigger);
createButton("Set Shadow",CMD_SET_SHADOW, 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("Get Camera Image",CMD_REQUEST_CAMERA_IMAGE_DATA,isTrigger);
createButton("Step Sim",CMD_STEP_FORWARD_SIMULATION, isTrigger); createButton("Step Sim",CMD_STEP_FORWARD_SIMULATION, isTrigger);
createButton("Realtime Sim",CMD_CUSTOM_SET_REALTIME_SIMULATION, isTrigger); createButton("Realtime Sim",CMD_CUSTOM_SET_REALTIME_SIMULATION, isTrigger);

View File

@@ -5631,7 +5631,7 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
{ {
if (bodyHandle->m_multiBody->getBaseCollider()) 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(); int graphicsIndex = bodyHandle->m_multiBody->getBaseCollider()->getUserIndex();
m_data->m_guiHelper->changeRGBAColor(graphicsIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); 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) 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(); int graphicsIndex = bodyHandle->m_multiBody->getLink(linkIndex).m_collider->getUserIndex();
m_data->m_guiHelper->changeRGBAColor(graphicsIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor); m_data->m_guiHelper->changeRGBAColor(graphicsIndex,clientCmd.m_updateVisualShapeDataArguments.m_rgbaColor);
} }

View File

@@ -671,6 +671,34 @@ int TinyRendererVisualShapeConverter::getVisualShapesData(int bodyUniqueId, int
return 0; 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;v<visualArray->m_renderObjects.size();v++)
{
visualArray->m_renderObjects[v]->m_model->setColorRGBA(rgba);
}
}
void TinyRendererVisualShapeConverter::setUpAxis(int axis) void TinyRendererVisualShapeConverter::setUpAxis(int axis)
{ {

View File

@@ -21,6 +21,8 @@ struct TinyRendererVisualShapeConverter : public LinkVisualShapesConverter
virtual int getNumVisualShapes(int bodyUniqueId); virtual int getNumVisualShapes(int bodyUniqueId);
virtual int getVisualShapesData(int bodyUniqueId, int shapeIndex, struct b3VisualShapeData* shapeData); 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); virtual void removeVisualShape(class btCollisionObject* colObj);