implement pybullet.changeTexture. For now, the width/height has to match the target texture unique id, otherwise crashes may happen (a check for width/height match will be added)
See also examples\pybullet\examples\changeTexture.py
This commit is contained in:
@@ -2918,6 +2918,25 @@ void b3GetVisualShapeInformation(b3PhysicsClientHandle physClient, struct b3Visu
|
||||
}
|
||||
}
|
||||
|
||||
b3SharedMemoryCommandHandle b3CreateChangeTextureCommandInit(b3PhysicsClientHandle physClient, int textureUniqueId, int width, int height, const char* rgbPixels)
|
||||
{
|
||||
PhysicsClient* cl = (PhysicsClient* ) physClient;
|
||||
b3Assert(cl);
|
||||
b3Assert(cl->canSubmitCommand());
|
||||
struct SharedMemoryCommand* command = cl->getAvailableSharedMemoryCommand();
|
||||
b3Assert(command);
|
||||
command->m_type = CMD_CHANGE_TEXTURE;
|
||||
|
||||
command->m_changeTextureArgs.m_textureUniqueId = textureUniqueId;
|
||||
command->m_changeTextureArgs.m_width = width;
|
||||
command->m_changeTextureArgs.m_height = height;
|
||||
int numPixels = width*height;
|
||||
cl->uploadBulletFileToSharedMemory(rgbPixels,numPixels*3);
|
||||
command->m_updateFlags = 0;
|
||||
return (b3SharedMemoryCommandHandle) command;
|
||||
}
|
||||
|
||||
|
||||
b3SharedMemoryCommandHandle b3InitLoadTexture(b3PhysicsClientHandle physClient, const char* filename)
|
||||
{
|
||||
PhysicsClient* cl = (PhysicsClient* ) physClient;
|
||||
|
||||
@@ -219,6 +219,7 @@ void b3GetVisualShapeInformation(b3PhysicsClientHandle physClient, struct b3Visu
|
||||
b3SharedMemoryCommandHandle b3InitLoadTexture(b3PhysicsClientHandle physClient, const char* filename);
|
||||
int b3GetStatusTextureUniqueId(b3SharedMemoryStatusHandle statusHandle);
|
||||
|
||||
b3SharedMemoryCommandHandle b3CreateChangeTextureCommandInit(b3PhysicsClientHandle physClient, int textureUniqueId, int width, int height, const char* rgbPixels);
|
||||
|
||||
b3SharedMemoryCommandHandle b3InitUpdateVisualShape(b3PhysicsClientHandle physClient, int bodyUniqueId, int jointIndex, int shapeIndex, int textureUniqueId);
|
||||
void b3UpdateVisualShapeRGBAColor(b3SharedMemoryCommandHandle commandHandle, double rgbaColor[4]);
|
||||
|
||||
@@ -1368,7 +1368,9 @@ void PhysicsClientSharedMemory::uploadBulletFileToSharedMemory(const char* data,
|
||||
SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
} else {
|
||||
for (int i = 0; i < len; i++) {
|
||||
m_data->m_testBlock1->m_bulletStreamDataClientToServer[i] = data[i];
|
||||
//m_data->m_testBlock1->m_bulletStreamDataClientToServer[i] = data[i];
|
||||
m_data->m_testBlock1->m_bulletStreamDataServerToClientRefactor[i] = data[i];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1095,6 +1095,14 @@ void PhysicsDirect::setSharedMemoryKey(int key)
|
||||
|
||||
void PhysicsDirect::uploadBulletFileToSharedMemory(const char* data, int len)
|
||||
{
|
||||
if (len>SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE)
|
||||
{
|
||||
len = SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE;
|
||||
}
|
||||
for (int i=0;i<len;i++)
|
||||
{
|
||||
m_data->m_bulletStreamDataServerToClient[i] = data[i];
|
||||
}
|
||||
//m_data->m_physicsClient->uploadBulletFileToSharedMemory(data,len);
|
||||
}
|
||||
|
||||
|
||||
@@ -6863,6 +6863,24 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CMD_CHANGE_TEXTURE:
|
||||
{
|
||||
SharedMemoryStatus& serverCmd = serverStatusOut;
|
||||
serverCmd.m_type = CMD_CHANGE_TEXTURE_COMMAND_FAILED;
|
||||
|
||||
InternalTextureHandle* texH = m_data->m_textureHandles.getHandle(clientCmd.m_changeTextureArgs.m_textureUniqueId);
|
||||
if(texH)
|
||||
{
|
||||
int gltex = texH->m_openglTextureId;
|
||||
m_data->m_guiHelper->changeTexture(gltex,
|
||||
(const unsigned char*)bufferServerToClient, clientCmd.m_changeTextureArgs.m_width,clientCmd.m_changeTextureArgs.m_height);
|
||||
|
||||
serverCmd.m_type = CMD_CLIENT_COMMAND_COMPLETED;
|
||||
}
|
||||
hasStatus = true;
|
||||
break;
|
||||
}
|
||||
case CMD_LOAD_TEXTURE:
|
||||
{
|
||||
BT_PROFILE("CMD_LOAD_TEXTURE");
|
||||
|
||||
@@ -133,6 +133,7 @@ enum MultiThreadedGUIHelperCommunicationEnums
|
||||
eGUIHelperSetVisualizerFlag,
|
||||
eGUIHelperChangeGraphicsInstanceTextureId,
|
||||
eGUIHelperGetShapeIndexFromInstance,
|
||||
eGUIHelperChangeTexture,
|
||||
};
|
||||
|
||||
|
||||
@@ -958,6 +959,23 @@ public:
|
||||
workerThreadWait();
|
||||
}
|
||||
|
||||
|
||||
int m_changeTextureUniqueId;
|
||||
const unsigned char* m_changeTextureRgbTexels;
|
||||
int m_changeTextureWidth;
|
||||
int m_changeTextureHeight;
|
||||
|
||||
virtual void changeTexture(int textureUniqueId, const unsigned char* rgbTexels, int width, int height)
|
||||
{
|
||||
m_changeTextureUniqueId = textureUniqueId;
|
||||
m_changeTextureRgbTexels = rgbTexels;
|
||||
m_changeTextureWidth = width;
|
||||
m_changeTextureHeight = height;
|
||||
m_cs->lock();
|
||||
m_cs->setSharedParam(1,eGUIHelperChangeTexture);
|
||||
workerThreadWait();
|
||||
}
|
||||
|
||||
double m_rgbaColor[4];
|
||||
int m_graphicsInstanceChangeColor;
|
||||
virtual void changeRGBAColor(int instanceUid, const double rgbaColor[4])
|
||||
@@ -1955,6 +1973,16 @@ void PhysicsServerExample::updateGraphics()
|
||||
}
|
||||
|
||||
|
||||
case eGUIHelperChangeTexture:
|
||||
{
|
||||
m_multiThreadedHelper->m_childGuiHelper->changeTexture(
|
||||
m_multiThreadedHelper->m_changeTextureUniqueId,
|
||||
m_multiThreadedHelper->m_changeTextureRgbTexels,
|
||||
m_multiThreadedHelper->m_changeTextureWidth,
|
||||
m_multiThreadedHelper->m_changeTextureHeight);
|
||||
m_multiThreadedHelper->mainThreadRelease();
|
||||
break;
|
||||
}
|
||||
|
||||
case eGUIHelperChangeGraphicsInstanceRGBAColor:
|
||||
{
|
||||
|
||||
@@ -898,6 +898,12 @@ struct b3CreateMultiBodyResultArgs
|
||||
int m_bodyUniqueId;
|
||||
};
|
||||
|
||||
struct b3ChangeTextureArgs
|
||||
{
|
||||
int m_textureUniqueId;
|
||||
int m_width;
|
||||
int m_height;
|
||||
};
|
||||
|
||||
struct SharedMemoryCommand
|
||||
{
|
||||
@@ -950,6 +956,7 @@ struct SharedMemoryCommand
|
||||
struct b3CreateVisualShapeArgs m_createVisualShapeArgs;
|
||||
struct b3CreateMultiBodyArgs m_createMultiBodyArgs;
|
||||
struct b3RequestCollisionInfoArgs m_requestCollisionInfoArgs;
|
||||
struct b3ChangeTextureArgs m_changeTextureArgs;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ enum EnumSharedMemoryClientCommand
|
||||
CMD_CREATE_MULTI_BODY,
|
||||
CMD_REQUEST_COLLISION_INFO,
|
||||
CMD_REQUEST_MOUSE_EVENTS_DATA,
|
||||
CMD_CHANGE_TEXTURE,
|
||||
//don't go beyond this command!
|
||||
CMD_MAX_CLIENT_COMMANDS,
|
||||
|
||||
@@ -161,6 +162,7 @@ enum EnumSharedMemoryServerStatus
|
||||
CMD_REQUEST_COLLISION_INFO_COMPLETED,
|
||||
CMD_REQUEST_COLLISION_INFO_FAILED,
|
||||
CMD_REQUEST_MOUSE_EVENTS_DATA_COMPLETED,
|
||||
CMD_CHANGE_TEXTURE_COMMAND_FAILED,
|
||||
//don't go beyond 'CMD_MAX_SERVER_COMMANDS!
|
||||
CMD_MAX_SERVER_COMMANDS
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user