BlitzODE Physics Thread

Blitz3D Forums/Blitz3D Userlibs/BlitzODE Physics Thread

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Try this fixed code for creating trimesh. Pass it your level mesh.
;creates the mesh to collide with
Function ODECollisionMesh(mesh)
	tris_count% = 0
	vert_count% = 0
	For i = 1 To CountSurfaces(mesh)
		tris_count = tris_count + CountTriangles(GetSurface(mesh, i))
		vert_count = vert_count + CountVertices(GetSurface(mesh, i))
	Next
;	DebugLog "Tris count: " + tris_count
;	DebugLog "Vertices count: " + vert_count
;	DebugLog "surface count: "+CountSurfaces(mesh)
	vertices_bank% = CreateBank(vert_count * 4 * 4)
	indices_bank% = CreateBank(tris_count * 3 * 4)

	offset% = 0
	offset_tris% = 0
	baseverts=0
	For i = 1 To CountSurfaces(mesh)
		sf = GetSurface(mesh, i)
		For v = 0 To CountVertices(sf) - 1
			PokeFloat vertices_bank, offset, VertexX(sf, v)
			offset = offset + 4
			PokeFloat vertices_bank, offset, VertexY(sf, v)
			offset = offset + 4
			PokeFloat vertices_bank, offset, VertexZ(sf, v)
			offset = offset + 8
		Next
		For t = 0 To CountTriangles(sf) - 1
			For j = 0 To 2
				v = TriangleVertex(sf, t, j)+baseverts
				PokeInt indices_bank, offset_tris, v
				offset_tris = offset_tris + 4
			Next
		Next
		baseverts=baseverts+CountVertices(sf)
	Next
	
	t_data = ODE_dGeomTriMeshDataCreate()
	ODE_dGeomTriMeshDataBuildSimple(t_data, vertices_bank, vert_count, indices_bank, tris_count * 3)
 
	Return ODE_dCreateTriMesh(ODE, t_data)
	
End Function