JV-ODE Physics Thread 6

Blitz3D Forums/Blitz3D Userlibs/JV-ODE Physics Thread 6

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.

Here it is my code to create full trimesh from animmesh. It should be easy to choose what meshes to export and what not:

;-------------------------------------------------;
Function KODE_dTriMeshCreateRecursive%(space,mesh%)
; USE THIS IF USING LOADANIMMESH
;-------------------------------------------------;
	tris_count% = 0
	vert_count% = 0

	RecursiveCount(mesh)

	vertices_bank% = CreateBank(vert_count * 4 * 4)
	indices_bank% = CreateBank(tris_count * 3 * 4)

	offset% = 0
	offset_tris% = 0
	baseverts=0
	
	RecursiveAdd(mesh)
	
	t_data = KODE_dGeomTriMeshDataCreate()
	KODE_dGeomTriMeshDataBuildSimple(t_data, vertices_bank, vert_count, indices_bank, tris_count * 3)

	Return KODE_dCreateTriMesh(space, t_data)
End Function

;-----------------------------;
Function RecursiveCount(mesh%)
; Add to the Global Values the Vertex and Tris Count
;-----------------------------;
children = CountChildren(mesh)

If (children = 0)
	For k = 1 To CountSurfaces(mesh)
		tris_count = tris_count + CountTriangles(GetSurface(mesh, k))
		vert_count = vert_count + CountVertices(GetSurface(mesh, k))
	Next
Else
	For k = 1 To Children
		RecursiveCount(GetChild(mesh,k))
	Next
EndIf

End Function

Function RecursiveAdd(mesh%)

children = CountChildren(mesh)

If (children = 0)	
	For i = 1 To CountSurfaces(mesh)
		sf = GetSurface(mesh, i)
		For v = 0 To CountVertices(sf) - 1	
			v1x# = VertexX(sf,v)
			v1y# = VertexY(sf,v)
			v1z# = VertexZ(sf,v)			
			TFormPoint v1x,v1y,v1z,mesh,0
			
			PokeFloat vertices_bank, offset, TFormedX()
			offset = offset + 4
			PokeFloat vertices_bank, offset, TFormedY()
			offset = offset + 4
			PokeFloat vertices_bank, offset, TFormedZ()
			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
Else
	For k = 1 To Children
		RecursiveAdd(GetChild(mesh,k))
	Next
EndIf

End Function


Cheers, KuRiX