Cal3d Loader for MiniB3d

BlitzMax Forums/MiniB3D Module/Cal3d Loader for MiniB3d

Leon Drake(Posted 2010) [#1]
I decided i wanted a Cal3d Loader for Minib3d, mainly just because i like the Cal3d format a lot.

Anyhoo so far i have got it so i can load the XSF Skeleton file and an XMF Mesh file into Minib3d. Here is where it's at currently.



My next phase is to get the bone's shown above weighted to the vertices. I am having some difficulty locating how this is done exactly in minib3d when a b3d file is loaded. I did find however in the TModel.bmx file under bone nodes and anim anim_surfaces are created and then the vertices in those surfaces are assigned weights and bone ids. I have more or less emulated this so far in my code e.g.

	Method WeighCal3DMesh()
	
		Local i,l,e
		Local bo_bone:TBone
		Local influence:TList
		Local influ:C3DInfluence
		If bones.length = 0 Then Return False
		
		mesh.anim=True
		mesh.anim_seqs_first[0]=0
		mesh.anim_seqs_last[0]=0

		For Local surf:TSurface=EachIn mesh.surf_list
		
			Local anim_surf:TSurface=New TSurface
			
			For e = 0 To numsubmesh-1
			
				If submeshes[e].surface = surf Then submeshes[e].animsurf = anim_surf
			
			
			Next
			
			ListAddLast(mesh.anim_surf_list,anim_surf)
		
			anim_surf.no_verts=surf.no_verts
						
			anim_surf.vert_coords=surf.vert_coords[..]
		
			anim_surf.vert_bone1_no=anim_surf.vert_bone1_no[..surf.no_verts+1]
			anim_surf.vert_bone2_no=anim_surf.vert_bone2_no[..surf.no_verts+1]
			anim_surf.vert_bone3_no=anim_surf.vert_bone3_no[..surf.no_verts+1]
			anim_surf.vert_bone4_no=anim_surf.vert_bone4_no[..surf.no_verts+1]
			anim_surf.vert_weight1=anim_surf.vert_weight1[..surf.no_verts+1]
			anim_surf.vert_weight2=anim_surf.vert_weight2[..surf.no_verts+1]
			anim_surf.vert_weight3=anim_surf.vert_weight3[..surf.no_verts+1]
			anim_surf.vert_weight4=anim_surf.vert_weight4[..surf.no_verts+1]
			
			' transfer vmin/vmax values for using with TrimVerts func after
			anim_surf.vmin=surf.vmin
			anim_surf.vmax=surf.vmax
		
		Next
				
		influence = GenerateInfluenceList()
		
		
		
		For influ = EachIn influence
		
		
			If influ.weight#>influ.submesh.animsurf.vert_weight1[influ.v]
								
				influ.submesh.animsurf.vert_bone4_no[influ.v]=influ.submesh.animsurf.vert_bone3_no[influ.v]
				influ.submesh.animsurf.vert_weight4[influ.v]=influ.submesh.animsurf.vert_weight3[influ.v]
				
				influ.submesh.animsurf.vert_bone3_no[influ.v]=influ.submesh.animsurf.vert_bone2_no[influ.v]
				influ.submesh.animsurf.vert_weight3[influ.v]=influ.submesh.animsurf.vert_weight2[influ.v]
				
				influ.submesh.animsurf.vert_bone2_no[influ.v]=influ.submesh.animsurf.vert_bone1_no[influ.v]
				influ.submesh.animsurf.vert_weight2[influ.v]=influ.submesh.animsurf.vert_weight1[influ.v]
				
				influ.submesh.animsurf.vert_bone1_no[influ.v]=influ.ID
				influ.submesh.animsurf.vert_weight1[influ.v]=influ.weight#
										
			Else If influ.weight#>influ.submesh.animsurf.vert_weight2[influ.v]
			
				influ.submesh.animsurf.vert_bone4_no[influ.v]=influ.submesh.animsurf.vert_bone3_no[influ.v]
				influ.submesh.animsurf.vert_weight4[influ.v]=influ.submesh.animsurf.vert_weight3[influ.v]
				
				influ.submesh.animsurf.vert_bone3_no[influ.v]=influ.submesh.animsurf.vert_bone2_no[influ.v]
				influ.submesh.animsurf.vert_weight3[influ.v]=influ.submesh.animsurf.vert_weight2[influ.v]
				
				influ.submesh.animsurf.vert_bone2_no[influ.v]=influ.ID
				influ.submesh.animsurf.vert_weight2[influ.v]=influ.weight#
																	
			Else If influ.weight#>influ.submesh.animsurf.vert_weight3[influ.v]
			
				influ.submesh.animsurf.vert_bone4_no[influ.v]=influ.submesh.animsurf.vert_bone3_no[influ.v]
				influ.submesh.animsurf.vert_weight4[influ.v]=influ.submesh.animsurf.vert_weight3[influ.v]

				influ.submesh.animsurf.vert_bone3_no[influ.v]=influ.ID
				influ.submesh.animsurf.vert_weight3[influ.v]=influ.weight#
	
			Else If influ.weight#>influ.submesh.animsurf.vert_weight4[influ.v]
			
				influ.submesh.animsurf.vert_bone4_no[influ.v]=influ.ID
				influ.submesh.animsurf.vert_weight4[influ.v]=influ.weight#
						
			EndIf			
		
		
		Next
		

	
	
	End Method


but yea i move the bones and nothing is weighted. Is there something else i'm not doing?


Leon Drake(Posted 2010) [#2]
perhaps i'm assuming the only way to move the bone and have the mesh deform is to set up tracks and keyframes. just simply moving the bone entity is probably not going to deform the mesh as i hoped.


ima747(Posted 2010) [#3]
First off, bravo for this, looks fantastic!

I don't know much about anim meshes and such but I thought I read somewhere a long long way back that minib3d currently doesn't support proper skeletons, only animated meshes, although it can load skeletons... someone correct me plz?


jhocking(Posted 2010) [#4]
Not sure what you mean by "animated meshes" if not models with skeletons.


FBEpyon(Posted 2010) [#5]

ima747

I don't know much about anim meshes and such but I thought I read somewhere a long long way back that minib3d currently doesn't support proper skeletons, only animated meshes, although it can load skeletons... someone correct me plz?



I think he is under the understanding that its a mesh with out bone placement that you just do kekframes, you move the mesh from point a to point b, and then move up one frame.

I too am very intrested in getting proper bone movement as this will help alot if you want to have rag doll movements.


Leon Drake(Posted 2010) [#6]
Still working on loading in animation up to see if after applying keys in the TMesh it will animate properly.