pybullet: allow programmatic creation of heightfield. See https://github.com/erwincoumans/bullet3/tree/master/examples/pybullet/examples/heightfield.py
premake4: allow to build example browser without C++11, re-enable stable PD control plugin using --enable_stable_pd=True
This commit is contained in:
@@ -1338,6 +1338,39 @@ B3_SHARED_API int b3CreateCollisionShapeAddHeightfield(b3SharedMemoryCommandHand
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_meshScale[1] = meshScale[1];
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_meshScale[2] = meshScale[2];
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_heightfieldTextureScaling = textureScaling;
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_numHeightfieldRows = -1;
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_numHeightfieldColumns = -1;
|
||||
command->m_createUserShapeArgs.m_numUserShapes++;
|
||||
return shapeIndex;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
B3_SHARED_API int b3CreateCollisionShapeAddHeightfield2(b3PhysicsClientHandle physClient, b3SharedMemoryCommandHandle commandHandle, const double meshScale[/*3*/], double textureScaling, float* heightfieldData, int numHeightfieldRows, int numHeightfieldColumns)
|
||||
{
|
||||
PhysicsClient* cl = (PhysicsClient*)physClient;
|
||||
b3Assert(cl);
|
||||
struct SharedMemoryCommand* command = (struct SharedMemoryCommand*)commandHandle;
|
||||
b3Assert(command);
|
||||
b3Assert((command->m_type == CMD_CREATE_COLLISION_SHAPE) || (command->m_type == CMD_CREATE_VISUAL_SHAPE));
|
||||
if ((command->m_type == CMD_CREATE_COLLISION_SHAPE) || (command->m_type == CMD_CREATE_VISUAL_SHAPE))
|
||||
{
|
||||
int shapeIndex = command->m_createUserShapeArgs.m_numUserShapes;
|
||||
if (shapeIndex < MAX_COMPOUND_COLLISION_SHAPES)
|
||||
{
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_type = GEOM_HEIGHTFIELD;
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_collisionFlags = 0;
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_visualFlags = 0;
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_hasChildTransform = 0;
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_meshFileName[0] = 0;
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_meshScale[0] = meshScale[0];
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_meshScale[1] = meshScale[1];
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_meshScale[2] = meshScale[2];
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_heightfieldTextureScaling = textureScaling;
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_numHeightfieldRows = numHeightfieldRows;
|
||||
command->m_createUserShapeArgs.m_shapes[shapeIndex].m_numHeightfieldColumns = numHeightfieldColumns;
|
||||
cl->uploadBulletFileToSharedMemory((const char*)heightfieldData, numHeightfieldRows*numHeightfieldColumns* sizeof(float));
|
||||
command->m_createUserShapeArgs.m_numUserShapes++;
|
||||
return shapeIndex;
|
||||
}
|
||||
|
||||
@@ -490,6 +490,7 @@ extern "C"
|
||||
B3_SHARED_API int b3CreateCollisionShapeAddCapsule(b3SharedMemoryCommandHandle commandHandle, double radius, double height);
|
||||
B3_SHARED_API int b3CreateCollisionShapeAddCylinder(b3SharedMemoryCommandHandle commandHandle, double radius, double height);
|
||||
B3_SHARED_API int b3CreateCollisionShapeAddHeightfield(b3SharedMemoryCommandHandle commandHandle, const char* fileName, const double meshScale[/*3*/], double textureScaling);
|
||||
B3_SHARED_API int b3CreateCollisionShapeAddHeightfield2(b3PhysicsClientHandle physClient, b3SharedMemoryCommandHandle commandHandle, const double meshScale[/*3*/], double textureScaling, float* heightfieldData, int numHeightfieldRows, int numHeightfieldColumns);
|
||||
|
||||
B3_SHARED_API int b3CreateCollisionShapeAddPlane(b3SharedMemoryCommandHandle commandHandle, const double planeNormal[/*3*/], double planeConstant);
|
||||
B3_SHARED_API int b3CreateCollisionShapeAddMesh(b3SharedMemoryCommandHandle commandHandle, const char* fileName, const double meshScale[/*3*/]);
|
||||
|
||||
@@ -1610,7 +1610,7 @@ struct PhysicsServerCommandProcessorInternalData
|
||||
btAlignedObjectArray<std::string*> m_strings;
|
||||
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
btAlignedObjectArray<unsigned char*> m_heightfieldDatas;
|
||||
btAlignedObjectArray<const unsigned char*> m_heightfieldDatas;
|
||||
btAlignedObjectArray<int> m_allocatedTextures;
|
||||
btHashMap<btHashPtr, UrdfCollision> m_bulletCollisionShape2UrdfCollision;
|
||||
btAlignedObjectArray<btStridingMeshInterface*> m_meshInterfaces;
|
||||
@@ -4394,7 +4394,7 @@ static unsigned char* MyGetRawHeightfieldData(CommonFileIOInterface& fileIO, PHY
|
||||
for (int j = 0; j < height; ++j)
|
||||
{
|
||||
|
||||
float z = allValues[i + width*j];
|
||||
double z = allValues[i + width*j];
|
||||
//convertFromFloat(p, z, type);
|
||||
btScalar * pf = (btScalar *)p;
|
||||
*pf = z;
|
||||
@@ -4545,7 +4545,29 @@ bool PhysicsServerCommandProcessor::processCreateCollisionShapeCommand(const str
|
||||
btScalar minHeight, maxHeight;
|
||||
PHY_ScalarType scalarType = PHY_FLOAT;
|
||||
CommonFileIOInterface* fileIO = m_data->m_pluginManager.getFileIOInterface();
|
||||
unsigned char* heightfieldData = MyGetRawHeightfieldData(*fileIO, scalarType, clientCmd.m_createUserShapeArgs.m_shapes[i].m_meshFileName, width, height, minHeight, maxHeight);
|
||||
const unsigned char* heightfieldData = 0;
|
||||
if (clientCmd.m_createUserShapeArgs.m_shapes[i].m_numHeightfieldColumns > 0 &&
|
||||
clientCmd.m_createUserShapeArgs.m_shapes[i].m_numHeightfieldRows > 0)
|
||||
{
|
||||
|
||||
width = clientCmd.m_createUserShapeArgs.m_shapes[i].m_numHeightfieldRows;
|
||||
height = clientCmd.m_createUserShapeArgs.m_shapes[i].m_numHeightfieldColumns;
|
||||
float* heightfieldDataSrc = (float*)bufferServerToClient;
|
||||
heightfieldData = new unsigned char[width*height * sizeof(btScalar)];
|
||||
btScalar* datafl = (btScalar*)heightfieldData;
|
||||
minHeight = heightfieldDataSrc[0];
|
||||
maxHeight = heightfieldDataSrc[0];
|
||||
for (int i = 0; i < width*height; i++)
|
||||
{
|
||||
datafl[i] = heightfieldDataSrc[i];
|
||||
minHeight = btMin(minHeight, (btScalar)datafl[i]);
|
||||
maxHeight = btMax(maxHeight, (btScalar)datafl[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
heightfieldData = MyGetRawHeightfieldData(*fileIO, scalarType, clientCmd.m_createUserShapeArgs.m_shapes[i].m_meshFileName, width, height, minHeight, maxHeight);
|
||||
}
|
||||
if (heightfieldData)
|
||||
{
|
||||
|
||||
|
||||
@@ -17,10 +17,7 @@ struct SharedMemoryBlock
|
||||
int m_numServerCommands;
|
||||
int m_numProcessedServerCommands;
|
||||
|
||||
//m_bulletStreamDataClientToServer is a way for the client to create collision shapes, rigid bodies and constraints
|
||||
//the Bullet data structures are more general purpose than the capabilities of a URDF file.
|
||||
char m_bulletStreamDataClientToServer[SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE];
|
||||
|
||||
|
||||
//m_bulletStreamDataServerToClient is used to send (debug) data from server to client, for
|
||||
//example to provide all details of a multibody including joint/link names, after loading a URDF file.
|
||||
char m_bulletStreamDataServerToClientRefactor[SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE];
|
||||
|
||||
@@ -24,7 +24,7 @@ typedef unsigned long long int smUint64_t;
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE (512 * 1024)
|
||||
#define SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE (1024 * 1024)
|
||||
#else
|
||||
#define SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE (8 * 1024 * 1024)
|
||||
#endif
|
||||
@@ -961,6 +961,8 @@ struct b3CreateUserShapeData
|
||||
int m_numUVs;
|
||||
int m_numNormals;
|
||||
double m_heightfieldTextureScaling;
|
||||
int m_numHeightfieldRows;
|
||||
int m_numHeightfieldColumns;
|
||||
double m_rgbaColor[4];
|
||||
double m_specularColor[3];
|
||||
};
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
//Please don't replace an existing magic number:
|
||||
//instead, only ADD a new one at the top, comment-out previous one
|
||||
|
||||
#define SHARED_MEMORY_MAGIC_NUMBER 201908050
|
||||
#define SHARED_MEMORY_MAGIC_NUMBER 201908110
|
||||
//#define SHARED_MEMORY_MAGIC_NUMBER 201908050
|
||||
//#define SHARED_MEMORY_MAGIC_NUMBER 2019060190
|
||||
//#define SHARED_MEMORY_MAGIC_NUMBER 201904030
|
||||
//#define SHARED_MEMORY_MAGIC_NUMBER 201902120
|
||||
|
||||
Reference in New Issue
Block a user