allow textured cube/sphere from URDF 'box' and 'sphere' visual primitive, when using

texUid = p.loadTexture("tex256.png")
p.changeVisualShape(cube ,-1, textureUniqueId = texUid)
See also https://github.com/bulletphysics/bullet3/issues/2012
This commit is contained in:
erwincoumans
2018-11-29 15:41:32 -08:00
parent 2d07fc1f64
commit 69321a9ee6
2 changed files with 81 additions and 12 deletions

View File

@@ -32,7 +32,7 @@ subject to the following restrictions:
#include "../SharedMemory/SharedMemoryPublic.h" //for b3VisualShapeData
#include "../TinyRenderer/model.h"
#include "stb_image/stb_image.h"
#include "../OpenGLWindow/ShapeData.h"
struct MyTexture2
{
unsigned char* textureData1;
@@ -293,10 +293,47 @@ static void convertURDFToVisualShape(const UrdfShape* visual, const char* urdfPa
btVector3 extents = visual->m_geometry.m_boxSize;
btBoxShape* boxShape = new btBoxShape(extents * 0.5f);
//btConvexShape* boxShape = new btConeShapeX(extents[2]*0.5,extents[0]*0.5);
convexColShape = boxShape;
convexColShape->setMargin(0.001);
int strideInBytes = 9 * sizeof(float);
int numVertices = sizeof(cube_vertices_textured) / strideInBytes;
int numIndices = sizeof(cube_indices) / sizeof(int);
glmesh = new GLInstanceGraphicsShape;
// int index = 0;
glmesh->m_indices = new b3AlignedObjectArray<int>();
glmesh->m_vertices = new b3AlignedObjectArray<GLInstanceVertex>();
glmesh->m_indices->resize(numIndices);
for (int k = 0; k < numIndices; k++)
{
glmesh->m_indices->at(k) = cube_indices[k];
}
glmesh->m_vertices->resize(numVertices);
btScalar halfExtentsX = extents[0] * 0.5;
btScalar halfExtentsY = extents[1] * 0.5;
btScalar halfExtentsZ = extents[2] * 0.5;
GLInstanceVertex* verts = &glmesh->m_vertices->at(0);
btScalar textureScaling = 1;
for (int i = 0; i < numVertices; i++)
{
verts[i].xyzw[0] = halfExtentsX * cube_vertices_textured[i * 9];
verts[i].xyzw[1] = halfExtentsY * cube_vertices_textured[i * 9 + 1];
verts[i].xyzw[2] = halfExtentsZ * cube_vertices_textured[i * 9 + 2];
verts[i].xyzw[3] = cube_vertices_textured[i * 9 + 3];
verts[i].normal[0] = cube_vertices_textured[i * 9 + 4];
verts[i].normal[1] = cube_vertices_textured[i * 9 + 5];
verts[i].normal[2] = cube_vertices_textured[i * 9 + 6];
verts[i].uv[0] = cube_vertices_textured[i * 9 + 7] * textureScaling;
verts[i].uv[1] = cube_vertices_textured[i * 9 + 8] * textureScaling;
}
glmesh->m_numIndices = numIndices;
glmesh->m_numvertices = numVertices;
break;
}
case URDF_GEOM_SPHERE: