我正在使用reactphysics3d库https://github.com/DanielChappuis/reactphysics3d
我正在尝试创建一个方形金字塔作为多面体网格-4个外部三角形面和两个基本三角形面。
我能够成功创建多边形顶点数组,但是在多面体创建阶段遇到问题。
我正在遵循用户手册中概述的形状创建过程。
在此我将不胜感激! 谢谢
这是我的代码-我尝试使用三角形金字塔(带有三角形面的三角形基座)创建三角形网格,并且能够做到这一点。然后我就可以创建一个凹形。
但是,我想使用多面体网格为具有正方形底面的三角形金字塔创建凸形。 任何建议将不胜感激!
//array of 5 points, 3 coordinates
float vertices[15];
for(int k=0; k<5; k++){
std::string vert = "v" + std::to_string(k);
vertices[3*k] = j3["data"]["vertices"][vert]["x"];
vertices[3*k+1] = j3["data"]["vertices"][vert]["y"];
vertices[3*k+2] = j3["data"]["vertices"][vert]["z"];
std::cout << std::setprecision(8);
std::cout << "added " << vertices[3*k] << "to index" << 3*k << std::endl;
std::cout << "added " << vertices[3*k+1] << "to index" << 3*k+1 << std::endl;
std::cout << "added " << vertices[3*k+2] << "to index" << 3*k+2 << std::endl;
}
//6 triangle faces
int indices[18];
//each face is defined through vertices (ccw)
//face1
indices[0] = 0; indices[1] = 2; indices[2] = 1;
//face2
indices[3] = 0; indices[4] = 2; indices[5] = 3;
//face3
indices[6] = 0; indices[7] = 4; indices[8] = 3;
//face4
indices[9] = 0; indices[10] = 1; indices[11] = 4;
//face5
indices[12] = 1; indices[13] = 2; indices[14] = 4;
//face6
indices[15] = 4; indices[16] = 2; indices[17] = 3;
rp3d::PolygonVertexArray::PolygonFace* polygonFaces = new rp3d::PolygonVertexArray::PolygonFace[6];
rp3d::PolygonVertexArray::PolygonFace* face = polygonFaces;
//each face has 3 indices
//6 triangles
for (int f=0; f<6; f++){
face->indexBase = f*3;
face->nbVertices = 3;
}
std::cout << "created polygon faces" << std::endl;
//create the polygon vertex array
rp3d::PolygonVertexArray* pva = new rp3d::PolygonVertexArray(5, vertices, sizeof(float), indices, sizeof(int), 6, polygonFaces, rp3d::PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, rp3d::PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE);
std::cout << "polygon vertex array created" << std::endl;
//create the polyhedron mesh
rp3d::PolyhedronMesh* pMesh = new rp3d::PolyhedronMesh(pva);
std::cout << "polyhedron mesh created" << std::endl;
//create the convex mesh collision shape
rp3d::ConvexMeshShape* convexMesh = new rp3d::ConvexMeshShape(pMesh);
std::cout << "convex mesh shape created" << std::endl;
答案 0 :(得分:0)
我认为您在faces循环中忘记了face ++