I was not able to find enough samples. Actually I want to bring a complex shape such torus 3d model.
I was able to bring a simple cube with the following code
Code: Select all
[self addContentFromPODResourceFile: @"shapeCube.pod"]; // cocos 3d way of importing 3d file
CC3MeshNode* triMeshNode1 = (CC3MeshNode*)[self getNodeNamed:@"BigCube"];
float* vertexData1 = (float*)((CC3VertexArrayMeshModel*)triMeshNode1.mesh).vertexLocations.elements;
int vertexCount1 = ((CC3VertexArrayMeshModel*)triMeshNode1.mesh).vertexLocations.elementCount;
btTriangleMesh* triMesh1 = new btTriangleMesh();
int offset = 0;
for (int i = 0; i < (vertexCount1 / 3); i++)
{
unsigned int index1 = offset;
unsigned int index2 = offset+6;
unsigned int index3 = offset+12;
triMesh1->addTriangle(btVector3(vertexData1[index1], vertexData1[index1+1], vertexData1[index1+2] ),
btVector3(vertexData1[index2], vertexData1[index2+1], vertexData1[index2+2] ),
btVector3(vertexData1[index3], vertexData1[index3+1], vertexData1[index3+2] ));
offset += 18;
}
triMeshNode1.location = cc3v(-2, 2, 0);
btBvhTriangleMeshShape* triMeshShape1 = new btBvhTriangleMeshShape(triMesh1,true);
CC3PhysicsObject3D *torusobject1 = [_physicsWorld createPhysicsObject:triMeshNode1 shape:triMeshShape1 mass:0 restitution:1.0 position:triMeshNode1.location];