Hey, this thread could use some reviving. So here's my newer irrlicht compatible version of the mesh to tree function. And guess what? I doesn't work. Could someone tell me what I did wrong?
Function AnimatedMeshToNewtonCollisionTree(nWorld:Byte Ptr,g_map:IAnimatedMesh,g_newtonMap:Byte Ptr) NewtonTreeCollisionBeginBuild(g_newtonmap) Local cMeshBuffer:Int,j:Int Local v1i:Int,v2i:Int,v3i:Int Local mb:IMeshBuffer Local vArray:Float[9] 'vertex array (3*3 floats) Local tmpCount:Int = 0 For cMeshBuffer=0 To g_map.getMesh(0).getMeshBufferCount() - 1 mb = g_map.getMesh(0).getMeshBuffer(cMeshBuffer) Local mb_vertices:Array_S3DVertex=mb.getVertices() Local mb_indices:Array_u16=mb.getIndices() 'add each triangle from the mesh For j=0 To mb.getIndexCount() - 1 Step 3 v1i=mb_indices.elementAt(j)[0] v2i=mb_indices.elementAt(j+1)[0] v3i=mb_indices.elementAt(j+2)[0] vArray[0]=mb_vertices.elementAt(v1i).getPos().getX() vArray[1]=mb_vertices.elementAt(v1i).getPos().getY() vArray[2]=mb_vertices.elementAt(v1i).getPos().getZ() vArray[3]=mb_vertices.elementAt(v2i).getPos().getX() vArray[4]=mb_vertices.elementAt(v2i).getPos().getY() vArray[5]=mb_vertices.elementAt(v2i).getPos().getZ() vArray[6]=mb_vertices.elementAt(v3i).getPos().getX() vArray[7]=mb_vertices.elementAt(v3i).getPos().getY() vArray[8]=mb_vertices.elementAt(v3i).getPos().getZ() NewtonTreeCollisionAddFace(g_newtonmap, 3,Varptr vArray[0], 12, 1) Next Next NewtonTreeCollisionEndBuild(g_newtonmap,0); Local g_newtonmapbody:Byte Ptr=NewtonCreateBody(nWorld,g_newtonmap); Rem After loading the bsp mesh in irrlicht we must create a newton collision tree consisting of all the triangles in the bsp mesh. To do this we loop through the indices list And add vertices 3 at a time into newton. I should mention here that I was lazy when writing this And just used a straight cast To video::S3DVertex2TCoords - this is because bsp meshes have lightmap textures on them. If you are using a mesh with only 1 set of texture co-ordinates (like a landscape Or .x level) Then use (video::S3DVertex). Newton requires 2 pointers For every Object - a NewtonBody* For the rigid body, And a NewtonCollision* that describes the objects geometry. After creating the tree collision geometry, we create a body For the map And assign it To the collision. Bodys which have a tree collision For their geometry are static And their mass will be ignored by newton - so you can only use meshes For your scenery! End Rem 'set the newton world size based on the bsp size Local boxP0:Float[3] Local boxP1:Float[3] Local matrix:Float[16] NewtonBodyGetMatrix g_newtonmapbody,Varptr matrix[0] NewtonCollisionCalculateAABB g_newtonmap,Varptr matrix[0],Varptr boxP0[0],Varptr boxP1[0] 'pad the box boxP0[0]:-10 boxP1[0]:+10 boxP0[1]:-10 boxP1[1]:+10 boxP0[2]:-10 boxP1[2]:+10 NewtonSetWorldSize nWorld,Varptr boxP0[0],Varptr boxP1[0] Rem After loading the map, we can calculate the bounding box surrounding it And set the newton world size To match. Newton should automatically disable anything which falls out of the map this way. End Rem End Function