Regenerate B3D files

Blitz3D Forums/Blitz3D Programming/Regenerate B3D files

Hi, i'm parsing the b3d format to built the whole stucture .

But unlucky i can't find where are stored the second Uv set ...

is anyone could help me ?

Here is the main part of the code

;====================================================================================
;    ==================         RIPP DU B3D         =====================
;====================================================================================

Const Max_B3DScene%=100

Global LogF%=WriteFile("log.txt")

Function LIB_WriteLog(File%,chaine$="",mode%=0)
   Select mode
      Case 0
         WriteLine(File,chaine)
      Case 1
         WriteString(File,String$(chaine,1))
      Case 2
         WriteInt(File,Int%(chaine))
      Case 3
         WriteFloat(File,Float#(chaine))
      Case 4
         WriteByte(File,chaine)
   End Select
End Function 



Type BB3D_Structure
	Field Scene_Root%			; Le Scene Root
	Field Id%					; Id de la scene
	Field filename$				; Nom du fichier
	Field File%					; Stream du fichier
	Field Cur_Pos%				; Position actuel de la lecture du fichier
	Field Reg_Pos[100]			; enregistrement de position interessante du fichier
	Field HandleBrush%[100]		; handle du type pour les Brushes max :100 brush
	Field HandleTex%[800]		; handle du type pour les textures max :100 brush* 8 textures
	Field NbTex%=-1				; Nombre de textures total
	Field NbBrush%=-1			; Nombre de Brushes total
	Field B3D_Tex.BB3D_TEXS		; Les textures de la scene
	Field B3D_Brs.BB3D_BRUSH	; Les Brushes de la scene
	Field NbNODE%				; Nombre de Nodes dans la scene
	Field NbMesh%				; Nombre de meshs dans la scene
	Field BGR,BGG,BGB			; background Color (ClsColor)
	Field AmbR%,AmbG%,AmbB%		; Ambientlight
	Field FogR%,FogG%,FogB%		; Fog Color
	Field FogN#,FogF#			; Fog Range
	Field HandleParent%[10000]
	Field NbParent%=-1
End Type


Type BB3D_TEXS
	Field Texture%
	Field tex_id%
	Field name$
	Field flags%
	Field blend%
	Field x_pos#
	Field y_pos#
	Field x_scl#
	Field y_scl#
	Field rot#
End Type


Type BB3D_BRUSH
	Field Brush%
	Field name$
	Field red#
	Field grn#
	Field blu#
	Field alp#
	Field shi#
	Field blend%
	Field fx%
	Field Tex_Id%[8],BrushNbTex%
End Type


Type BB3D_NODE
	Field Parent%
	Field Typ$
	Field Name$
	Field Entity%

	Field x_pos#=0,y_pos#=0,z_pos#=0
	Field x_scl#=1,y_scl#=1,z_scl#=1
	Field w_rot#=0
	Field x_rot#=0,y_rot#=0,z_rot#=0

	; case "BONE"
	Field NbVrt_inBone
	Field Vrt%[65537]
	Field Weight#[65537]

	;case "MESH"
	Field Surf.BB3D_SRF
	Field IdMesh%
	Field NbSurf%

	; case "CAMERA"
	Field CamFOV#
End Type


Type BB3D_VRT
	Field NbVrtx%
	Field x#[65537]
	Field y#[65537]
	Field z#[65537]

	Field nx#[65537]
	Field ny#[65537]
	Field nz#[65537]

	Field red#[65537]
	Field grn#[65537]
	Field blu#[65537]
	Field alp#[65537]

	Field u1#[65537]
	Field v1#[65537]
	Field u2#[65537]
	Field v2#[65537]

End Type


Type BB3D_SRF
	Field Surface%
	Field IdMesh%
	Field brush_id%
	Field NbTri%
	Field NbVrtx%

	Field vt.BB3D_VRT

	Field Tri%[65537]
	Field Vrt0%[65537]
	Field Vrt1%[65537]
	Field Vrt2%[65537]
	
End Type


Function BB3D_LoadAnimMesh(f_name$,parent%=0)
	For s.BB3D_structure=Each BB3D_Structure
		NbB3dScene=NbB3dScene+1
	Next
	s.BB3D_structure=New BB3D_Structure
			LIB_WriteLog(LogF,"=======================================================================================")
			LIB_WriteLog(LogF,"      ***********************                               *********************")
			LIB_WriteLog(LogF," -----------                   DUMP BB3D MESH Version 0.1                 -----------")
			LIB_WriteLog(LogF,"      ***********************                               *********************")
			LIB_WriteLog(LogF,"=======================================================================================")
		s\Id=NbB3dScene
		s\file=ReadFile( f_name$ )
		s\filename$=f_name
		If parent=0
			s\Scene_Root=CreatePivot()
			parent=s\Scene_Root
		EndIf
	If Not s\file RuntimeError "Unable to open b3d file"
	If BB3D_Decode_TAG$(s)<>"BB3D" RuntimeError "Invalid b3d file"
	If ReadInt(s\file)/100>0 RuntimeError "Invalid b3d file version"

	BB3D_Ripp_B3D(s,"",parent)
	CloseFile s\file
	If s\Scene_Root=0 s\Scene_Root=CreateMesh()
	NameEntity s\Scene_Root,Handle(s)
	BB3D_CreateMesh(s,Parent)
	Return s\Scene_Root
End Function



Function BB3D_CreateMesh(s.BB3D_Structure,Parent%=0)
	; creation des textures
	For s\B3D_Tex.BB3D_TEXS = Each BB3D_TEXS
		s\B3D_Tex\Texture=LoadTexture(s\B3D_Tex\name,s\B3D_Tex\flags)
		If s\B3D_Tex\Texture<>0
			TextureBlend s\B3D_Tex\texture,s\B3D_Tex\blend
			PositionTexture s\B3D_Tex\texture,s\B3D_Tex\x_pos,s\B3D_Tex\y_pos
			ScaleTexture s\B3D_Tex\texture,s\B3D_Tex\x_scl,s\B3D_Tex\y_scl
			RotateTexture s\B3D_Tex\texture,s\B3D_Tex\rot
		EndIf
	Next

	; Creation des brushes
	For s\B3D_Brs.BB3D_BRUSH = Each BB3D_BRUSH
		s\B3D_Brs\Brush=CreateBrush()
		If s\B3D_Brs\Brush<>0
			BrushColor s\B3D_Brs\Brush,s\B3D_Brs\red*255,s\B3D_Brs\grn*255,s\B3D_Brs\blu*255
			BrushAlpha s\B3D_Brs\brush,s\B3D_Brs\alp
			BrushShininess s\B3D_Brs\brush,s\B3D_Brs\shi
			BrushBlend s\B3D_Brs\brush,s\B3D_Brs\Blend
			BrushFX s\B3D_Brs\brush,s\B3D_Brs\fx
			nb=nb+1
			For i = 0 To s\B3D_Brs\BrushNbTex-1
				TexHandle=s\B3D_Brs\Tex_Id[i]
				If TexHandle<>0
					TexHandle=s\HandleTex[TexHandle]
					s\B3D_Tex.BB3D_TEXS=Object.BB3D_TEXS(TexHandle)
					If s\B3D_Tex\texture<>0	BrushTexture s\B3D_Brs\Brush,s\B3D_Tex\texture,0,i
				EndIf
			Next
		EndIf
	Next

	; Si pas de scene root, on en crée un !
	For n.BB3D_NODE=Each BB3D_NODE
		If n\name="Scene Root"
			Scene_Root_Present=True
			n\Typ="Scene Root"
		EndIf
	Next
		If Scene_Root_Present=0
		EndIf

	; Creation des Nodes de la Scene
	n.BB3D_NODE=First BB3D_NODE
		For NbNode=1 To s\NbNODE
			Select n\Typ$
				Case "Scene Root"
					If Parent=0
						s\Scene_Root=CreatePivot()
					Else
						s\Scene_Root=CreatePivot(Parent)
					EndIf
					n\Entity=s\Scene_Root
					NameEntity s\Scene_Root,"Scene Root"
				Case "MESH"
					n\Entity=CreateMesh(s\Scene_Root);n\Parent)
						For n\surf.BB3D_SRF=Each BB3D_SRF
							If n\IdMesh=n\surf\IdMesh
								n\surf\surface=CreateSurface(n\Entity)
								Color 0,255,0
								For vrt=0 To n\surf\vt\NbVrtx-1
									;vrtx%=0
									vn=vrt+1
									vpx#=n\surf\vt\x[vn]:vpy#=n\surf\vt\y[vn]:vpz#=n\surf\vt\z[vn]
									vpu#=n\surf\vt\u1[vn]:vpv#=n\surf\vt\v1[vn]
									vpr#=n\surf\vt\red[vn]:vpg#=n\surf\vt\grn[vn]:vpb#=n\surf\vt\blu[vn]:vpal#=n\surf\vt\alp[vn]
									vpnx#=n\surf\vt\nx[vn]:vpny#=n\surf\vt\ny[vn]:vpnz#=n\surf\vt\nz[vn]
									vrtx=AddVertex (n\surf\surface,vpx,vpy,vpz,vpu,vpv)
									VertexColor n\surf\surface,vrtx,vpnr,vpng,vpnb,vpal
									VertexNormal n\surf\surface,vrtx,vpnx,vpny,vpnz
								Next
								For tri= 0 To n\surf\NbTri-1
									v0=n\surf\Vrt0[tri]
									v1=n\surf\Vrt1[tri]
									v2=n\surf\Vrt2[tri]
									AddTriangle (n\surf\surface,v0,v1,v2)
								Next
								If n\surf\brush_id>-1
									s\B3D_Brs.BB3D_BRUSH=Object.BB3D_BRUSH(s\HandleBrush[n\surf\brush_id+1])
									If s\B3D_Brs\Brush<>0 PaintSurface n\surf\surface,s\B3D_Brs\Brush
								EndIf
								UpdateNormals n\Entity
							EndIf
						Next
						Print "Mesh "+n\name+" - pX#:"+n\x_pos+"pY#:"+n\y_pos+"pZ#:"+n\z_pos
						Print "                 "+"sX#:"+n\x_scl+"sY#:"+n\y_scl+"sZ#:"+n\z_scl
						Print "                 "+"rX#:"+n\x_rot+"rY#:"+n\y_rot+"rZ#:"+n\z_rot
						PositionEntity n\Entity,n\x_pos,n\y_pos,n\z_pos,0
						ScaleEntity n\Entity,n\x_scl,n\y_scl,n\z_scl,0
						RotateEntity n\Entity,n\x_rot,n_y_rot,n\z_rot,0
						;WaitKey
				Case "BONE"
;					PositionEntity n\Entity,n\x_pos,n\y_pos,n\z_pos,0
;					ScaleEntity n\Entity,n\x_scl,n\y_scl,n\z_scl,0
;					RotateEntity n\Entity,n\x_rot,n_y_rot,n\z_rot,0
				Case "B3DEXT_BGCOLOR"
					s\BGR%=Float(n\x_pos)*255
					s\BGG%=Float(n\y_pos)*255
					s\BGB%=Float(n\z_pos)*255
				Case "B3DEXT_AMBIENT"
					s\AmbR%=Float(n\x_pos)*255
					s\AmbG%=Float(n\y_pos)*255
					s\AmbB%=Float(n\z_pos)*255
					AmbientLight s\AmbR,s\AmbG,s\AmbB
				Case "B3DEXT_FOGCOLOR"
					s\FogR%=n\x_pos
					s\FogG%=n\y_pos
					s\FogB%=n\z_pos
				Case "B3DEXT_FOGRANGE"
					s\FogN#=n\x_pos
					s\FogF#=n\z_pos
				Case "CAMERA"
					n\Entity=CreateCamera(s\Scene_Root)
						PositionEntity n\Entity,n\x_pos,n\y_pos,n\z_pos
					n\CamFov=Float(45)
						CameraClsColor n\Entity,s\BGR,s\BGG,s\BGB
						CameraZoom n\Entity,n\CamFOV
						If s\FogF<>0
							CameraFogMode n\Entity,1
							CameraFogRange n\Entity,s\FogN,s\FogF
							CameraFogColor n\Entity,s\FogR,s\FogG,s\FogB
						EndIf
			End Select
			n=After n
		Next

	Return s\Scene_Root
End Function






Function BB3D_Ripp_B3D( s.BB3D_structure,tab$="",Parent%=0 )
	tt$=tab$
	tab$=tab$+"  "
	s\NbParent=s\NbParent+1
	While ( s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
		b3d_TAG$=BB3D_Decode_TAG$(s)
		Select b3d_TAG$
		Case "MESH"
			LIB_WriteLog(LogF,tab+"MESH============================================================================")
			s\NbMesh=s\NbMesh+1
			brush_id=ReadInt(s\file)
			n.BB3D_NODE=Last BB3D_NODE
				n\Typ="MESH"
				n\IdMesh=s\NbMesh
		Case "NODE"
			BB3D_Parse_Nodes(s,tab)
		Case "TEXS"
			BB3D_Parse_Texs(s,tab)
		Case "BRUS"
			BB3D_Parse_Brushes(s,tab)
		Case "VRTS"
			BB3D_Parse_Vertex(s,tab)
		Case "TRIS"
			BB3D_Parse_Tris(s,tab)
		Case "BONE"
			n.BB3D_NODE=Last BB3D_NODE
			BB3D_Parse_Bone(s,n,tab)
		Case "ANIM"
			BB3D_Parse_Anims(s,tab)
		Case "KEYS"
			BB3D_Parse_Keys(s,tab)
		Default
			DebugLog tab$+"Tag mmm...non supporté..."
		End Select

		BB3D_Ripp_B3D( s,tab$,CurParent )								;enfant de cette branche
		SeekFile s\file,s\Reg_Pos[s\Cur_Pos]:s\Cur_Pos=s\Cur_Pos-1		;cloture de la branche
	Wend
End Function













;====================================================================================
;       ==================      Fonctions PRIVEES      =====================
;====================================================================================

;     =======
;***** functions for reading from B3D files *****
;     =======

;     =======
Function BB3D_Decode_String$(s.BB3D_structure)
	Repeat
		ch=ReadByte(s\file)
		If ch=0 Return t$
		t$=t$+Chr$(ch)
	Forever
End Function
;     =======

;     =======
Function BB3D_Decode_TAG$(s.BB3D_structure)
	For k=1 To 4
		byt=ReadByte(s\file)
		tag$=tag$+Chr$(byt)
	Next
	offset=ReadInt( s\file)
	s\Cur_Pos=s\Cur_Pos+1
	s\Reg_Pos[s\Cur_Pos]=FilePos( s\file)+offset
	Return tag$
End Function
;     =======

Function BB3D_____________NODES()
	End Function
;     =======
Function BB3D_Parse_Nodes(s.BB3D_Structure,tab$="")
	Color 255,255,0
	LIB_WriteLog(LogF,tab+"NODE============================================================================")
	s\NbNODE=s\NbNODE+1
	n.BB3D_NODE=New BB3D_NODE
	If s\NbParent>1
		s\HandleParent[s\NbParent]=Handle(n)
		n\Parent=s\NbParent
	EndIf
	n\name$  =BB3D_Decode_String$(s)
	n\x_pos# =ReadFloat(s\file)
	n\y_pos# =ReadFloat(s\file)
	n\z_pos# =ReadFloat(s\file)
	n\x_scl# =ReadFloat(s\file)
	n\y_scl# =ReadFloat(s\file)
	n\z_scl# =ReadFloat(s\file)
	n\w_rot# =ReadFloat(s\file)
	n\x_rot# =ReadFloat(s\file)
	n\y_rot# =ReadFloat(s\file)
	n\z_rot# =ReadFloat(s\file)
	If n\name="B3DEXT_CAMERA"
		Fov#=n\x_pos
		n=Before n
		n\typ="CAMERA"
			n\CamFOV#=fov
			n.BB3D_NODE= Last BB3D_NODE
			Delete Last BB3D_NODE
			s\NbNODE=s\NbNODE-1
			n.BB3D_NODE= Last BB3D_NODE
			LIB_WriteLog(LogF,tab$+"name="+n\name$+" : px:"+n\x_pos+"_py:"+n\y_pos+"_pz:"+n\z_pos)
	ElseIf n\name="B3DEXT_BGCOLOR"
		n\typ=n\name
			LIB_WriteLog(LogF,tab$+"ClsColor="+n\name$+" : ClsRed:"+n\x_pos+" ClsGreen:"+n\y_pos+" ClsBlue:"+n\z_pos)
	ElseIf n\name="B3DEXT_AMBIENT"
		n\typ=n\name
			LIB_WriteLog(LogF,tab$+"AmbientLight="+n\name$+" : AmbR:"+n\x_pos+" AmbG:"+n\y_pos+" AmbB:"+n\z_pos)
	ElseIf n\name="B3DEXT_FOGCOLOR"
		n\typ=n\name
			LIB_WriteLog(LogF,tab$+"Fog Color="+n\name$+" : FogR:"+n\x_pos+" FogG:"+n\y_pos+" FogB:"+n\z_pos)
	ElseIf n\name="B3DEXT_FOGRANGE"
		n\typ=n\name
			LIB_WriteLog(LogF,tab$+"Fog Range="+n\name$+" : FogN:"+n\x_pos+" FogF:"+n\z_pos)
	Else
		LIB_WriteLog(LogF,tab$+"name="+n\name$)
		LIB_WriteLog(LogF,tab$+"Pos : "+n\x_pos+"|"+n\y_pos+"|"+n\z_pos)
		LIB_WriteLog(LogF,tab$+"Scl : "+n\x_scl+"|"+n\y_scl+"|"+n\z_scl)
		LIB_WriteLog(LogF,tab$+"Rot : "+Int(n\x_rot)+"|"+Int(n\y_rot)+"|"+Int(n\z_rot))
	EndIf
End Function
;     =======

Function BB3D__________TEXTURES()
	End Function
;     =======
Function BB3D_Parse_TexS(s.BB3D_Structure,tab$="")
	Color 0,255,0
	LIB_WriteLog(LogF,tab+"===============TEXS=================================")
	AllTex=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
	While AllTex>0
		s\NbTex=s\NbTex+1
		s\B3D_Tex.BB3D_TEXS=New BB3D_TEXS
		s\B3D_Tex\name$=BB3D_Decode_String$(s)
		s\HandleTex[s\NbTex]=Handle(s\B3D_Tex)
		LIB_WriteLog(LogF,tab+tab+"tex :"+s\B3D_Tex\name)
		s\B3D_Tex\flags  =ReadInt(s\file)
		s\B3D_Tex\blend  =ReadInt(s\file)
		s\B3D_Tex\x_pos# =ReadFloat(s\file)
		s\B3D_Tex\y_pos# =ReadFloat(s\file)
		s\B3D_Tex\x_scl# =ReadFloat(s\file)
		s\B3D_Tex\y_scl# =ReadFloat(s\file)
		s\B3D_Tex\rot#   =ReadFloat(s\file)
		AllTex=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
	Wend
End Function
;     =======

Function BB3D___________BRUSHES()
	End Function
;     =======
Function BB3D_Parse_Brushes(s.BB3D_Structure,tab$="")
	Color 255,0,0
	LIB_WriteLog(LogF,tab+"===============BRUS==================================")
	n_texs=ReadInt(s\file)
	AllBrush=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
	While AllBrush>0
		s\B3D_Brs.BB3D_BRUSH=New BB3D_BRUSH
			s\B3D_Brs\name$=BB3D_Decode_String$(s)
			s\B3D_Brs\red#=ReadFloat(s\file)
			s\B3D_Brs\grn#=ReadFloat(s\file)
			s\B3D_Brs\blu#=ReadFloat(s\file)
			s\B3D_Brs\alp#=ReadFloat(s\file)
			s\B3D_Brs\shi#=ReadFloat(s\file)
			s\B3D_Brs\blend%=ReadInt(s\file)
			s\B3D_Brs\fx%=ReadInt(s\file)
			s\B3D_Brs\BrushNbTex=n_texs-1
			Print " Brush Propertys ====================="
			Print " RGB   : "+s\B3D_Brs\red+" - "+s\B3D_Brs\grn+" - "+s\B3D_Brs\blu
			Print " Alpha : "+s\B3D_Brs\alp
			Print " Shins : "+s\B3D_Brs\shi
			Print " blend : "+s\B3D_Brs\blend
			Print " Fx    : "+s\B3D_Brs\fx
			WaitKey
			For k=0 To n_texs-1
				NumTex%=ReadInt(s\file)+1
				s\B3D_Brs\Tex_Id[k]=NumTex
				If NumTex<>0
					s\B3D_Tex.BB3D_TEXS=Object.BB3D_TEXS(s\HandleTex[NumTex])
				EndIf
			Next
			s\NbBrush=s\NbBrush+1
			s\HandleBrush[s\NbBrush]=Handle(s\B3D_Brs)
			LIB_WriteLog(LogF,tab+tab+s\B3D_Brs\name)
		AllBrush=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
	Wend
End Function
;     =======

Function BB3D_____________BONES()
	End Function
;     =======
Function BB3D_Parse_Bone(s.BB3D_Structure,n.BB3D_NODE,tab$="")
	LIB_WriteLog(LogF,tab+"BONE============================================================================")
	n\NbVrt_inBone=0
	n\Typ="BONE"
	CurParent =n\Entity
	Print tab+tab+"BONE"
	sz=8
	n_weights=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))/sz
	If n_weights*sz=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
		While (s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
			n\NbVrt_inBone=n\NbVrt_inBone+1
			n\Vrt[n\NbVrt_inBone]=ReadInt(s\file)
			n\weight#[n\NbVrt_inBone]=ReadFloat(s\file)
			LIB_WriteLog(LogF,tab+"VrtId:"+n\Vrt[n\NbVrt_inBone]+" w#:"+n\weight#[n\NbVrt_inBone])
		Wend
	Else
		DebugLog tab$+"***** Illegal number of bone weights *****"
	EndIf
End Function
;     =======

Function BB3D__________VERTICES()
	End Function
;     =======
Function BB3D_Parse_Vertex(s.BB3D_structure,tab$="")
	vt.BB3D_VRT=New BB3D_VRT
	flags=ReadInt(s\file)
	tc_sets=ReadInt(s\file)
	tc_size=ReadInt(s\file)
	sz=12+tc_sets*tc_size*4
	If flags And 1 Then sz=sz+12
	If flags And 2 Then sz=sz+16
	n_verts=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))/sz
	If n_verts*sz=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file )) 
		IdVrt=0
		While (s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
			IdVrt=IdVrt+1
			vt\x#[IdVrt]=ReadFloat(s\file)
			vt\y#[IdVrt]=ReadFloat(s\file)
			vt\z#[IdVrt]=ReadFloat(s\file)
			If flags And 1
				vt\nx#[IdVrt]=ReadFloat(s\file)
				vt\ny#[IdVrt]=ReadFloat(s\file)
				vt\nz#[IdVrt]=ReadFloat(s\file)
			EndIf
			If flags And 2
				vt\red#[IdVrt]=ReadFloat(s\file)
				vt\grn#[IdVrt]=ReadFloat(s\file)
				vt\blu#[IdVrt]=ReadFloat(s\file)
				vt\alp#[IdVrt]=ReadFloat(s\file)
			EndIf
			a=-1
			For j=1 To tc_sets*tc_size
				a=a+1
				If a=0 vt\u1#[IdVrt]=ReadFloat(s\file)
				If a=1 vt\v1#[IdVrt]=ReadFloat(s\file)
				If a=2 vt\u2#[IdVrt]=ReadFloat(s\file)
				If a=3 vt\v2#[IdVrt]=ReadFloat(s\file):a=-1
			Next
			LIB_WriteLog(LogF,tab+"Vrt "+IdVrt+" Pos:"+vt\x#[IdVrt]+" "+vt\y#[IdVrt]+" "+vt\z#[IdVrt])
			LIB_WriteLog(LogF,tab+tab+"Nrm:"+vt\nx#[IdVrt]+" "+vt\ny#[IdVrt]+" "+vt\nz#[IdVrt])
			LIB_WriteLog(LogF,tab+tab+"Clr:"+vt\red#[IdVrt]+" "+vt\grn#[IdVrt]+" "+vt\blu#[IdVrt]+" "+vt\alp#[IdVrt])
			LIB_WriteLog(LogF,tab+tab+"UV#: u "+vt\u1#[IdVrt]+" "+vt\u2#[IdVrt]+" v "+vt\v1#[IdVrt]+" "+vt\v2#[IdVrt])
		Wend
		vt\NbVrtx=IdVrt
	Else
		LIB_WriteLog(LogF,tab$+"***** Illegal number of vertices *****")
	EndIf
End Function
;     =======


Function BB3D_________TRIANGLES()
	End Function
;     =======


Function BB3D_Parse_Tris(s.BB3D_Structure,tab$="")
	n.BB3D_NODE= Last BB3D_NODE
	n\NbSurf=n\NbSurf+1
	n\surf.BB3D_SRF=New BB3D_SRF
	n\surf\IdMesh=n\IdMesh
	n\surf\vt.BB3D_VRT=Last BB3D_VRT
	n\surf\brush_id=ReadInt(s\file)
	sz=12
	n_tris=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))/sz
	Print n_tris
	If n_tris*sz=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
		ntri=0
		While (s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
			ntri=ntri+1
			n\surf\vrt0[ntri]=ReadInt(s\file)
			n\surf\vrt1[ntri]=ReadInt(s\file)
			n\surf\vrt2[ntri]=ReadInt(s\file)
		Wend
		n\surf\NbTri=ntri
		LIB_WriteLog(LogF,tab+tab+"Surface créée - "+ntri+" tris créés")
	Else
		LIB_WriteLog(LogF,tab$+"***** Illegal number of triangles *****")
	EndIf
End Function
;     =======


Function BB3D_______________KEYS()
	End Function
;     =======


Function BB3D_Parse_Keys(s.BB3D_Structure,tab$="")
	LIB_WriteLog(LogF,tab+"=>clé <=")
	flags=ReadInt(s\file)
	sz=4
	If flags And 1 sz=sz+12
	If flags And 2 sz=sz+12
	If flags And 4 sz=sz+16
	n_keys= (s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))/sz
	If n_keys*sz=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file )) 
		While (s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
			frame=ReadInt(s\file)
			If flags And 1
				key_px#=ReadFloat(s\file)
				key_py#=ReadFloat(s\file)
				key_pz#=ReadFloat(s\file)
			EndIf
			If flags And 2
				key_sx#=ReadFloat(s\file)
				key_sy#=ReadFloat(s\file)
				key_sz#=ReadFloat(s\file)
			EndIf
			If flags And 4
				key_rw#=ReadFloat(s\file)
				key_rx#=ReadFloat(s\file)
				key_ry#=ReadFloat(s\file)
				key_rz#=ReadFloat(s\file)
			EndIf
			LIB_WriteLog(LogF," - pos :"+key_px+" "+key_py+" "+key_pz,1)
			LIB_WriteLog(LogF," - scl :"+key_sx+" "+key_sy+" "+key_sz,1)
			LIB_WriteLog(LogF," - rot :"+key_rx+" "+key_ry+" "+key_rz)
		Wend
	Else
		LIB_WriteLog(LogF,tab$+"***** Illegal number of keys *****")
	EndIf
End Function
;     =======

Function BB3D______________ANIMS()
	End Function
;     =======
Function BB3D_Parse_Anims(s.BB3D_Structure,tab$="")
	LIB_WriteLog(LogF,tab+"ANIM============================================================================")
	flags=ReadInt(s\file)
	n_frames=ReadInt(s\file)
	fps=ReadFloat(s\file)
	LIB_WriteLog(LogF,tab+tab$+flags+" "+n_frames+" "+fps)
End Function
;     =======



Ok, If i had look better, i would have found it ...


{
char file[] ;texture file name
int flags,blend ;blitz3D TextureFLags and TextureBlend: default=1,2
float x_pos,y_pos ;x and y position of texture: default=0,0
float x_scale,y_scale ;x and y scale of texture: default=1,1
float rotation ;rotation of texture (in radians): default=0
}

The TEXS chunk contains a list of all textures used in the file.

The flags field value can conditional an additional flag value of '65536'. This is used to indicate that the texture uses secondary UV values, ala the TextureCoords command. Yes, I forgot about this one




It is cumulated on the flag for the texture coord set

and all vertexTexCoords are stored using a flag too

VRTS:
int flags ;1=normal values present, 2=rgba values present
int tex_coord_sets ;texture coords per vertex (eg: 1 for simple U/V) max=8
int tex_coord_set_size ;components per set (eg: 2 for simple U/V) max=4
{
float x,y,z ;always present
float nx,ny,nz ;vertex normal: present if (flags&1)
float red,green,blue,alpha ;vertex color: present if (flags&2)
float tex_coords[tex_coord_sets][tex_coord_set_size] ;tex coords
}

The VRTS chunk contains a list of vertices. The 'flags' value is used to indicate how much extra
data (normal/color) is stored with each vertex, and the tex_coord_sets and tex_coord_set_size
values describe texture coordinate information stored with each vertex.



Just one thing don't understand ...


; Int tex_coord_set_size ;components per set (eg: 2 for simple U/V) max=4




how can we have more than two coordinates for one vertex ?
u,v and what else ???

I knw about a certain w , that i have never been abble to understand, but however it should be one the the four , what is the last ?

allright, in fact, there is the w mapping coords and an additionnal optional setting just here to prevent a different version that could need one more setting.

and, the 8 UV sets are here because, Blitz3D does not support more than 2 uv sets coords, but we can load b3d file from other engine. Like torque or Irrlicht that support more than 2 Uv Sets .

No any question :) , finally, i found answers.
( and my code is in a good way ... i'm happy :D )

This all seems quite exciting - what is it for?

An animation tool :) I need to parse b3d, and then export the scene from Blitz, with anim, keys and bones.

For an other way, I need it for the Eliza3D Module for bmax.

updated
;====================================================================================
;    ==================         RIPP DU B3D         =====================
;====================================================================================

Const Max_B3DScene%=100

Global LogF%=WriteFile("log.txt")

Function LIB_WriteLog(File%,chaine$="",mode%=0)
	Select mode
		Case 0
;			WriteLine(File,chaine)
		Case 1
;			WriteString(File,String$(chaine,1))
		Case 2
;			WriteInt(File,Int%(chaine))
		Case 3
;			WriteFloat(File,Float#(chaine))
		Case 4
;			WriteByte(File,chaine)
	End Select
End Function 



Type BB3D_Structure
	Field Scene_Root%			; Le Scene Root
	Field Id%					; Id de la scene
	Field filename$				; Nom du fichier
	Field File%					; Stream du fichier
	Field Cur_Pos%				; Position actuel de la lecture du fichier
	Field Reg_Pos[100]			; enregistrement de position interessante du fichier
	Field HandleBrush%[100]		; handle du type pour les Brushes max :100 brush
	Field HandleTex%[800]		; handle du type pour les textures max :100 brush* 8 textures
	Field NbTex%=-1				; Nombre de textures total
	Field NbBrush%=-1			; Nombre de Brushes total
	Field B3D_Tex.BB3D_TEXS		; Les textures de la scene
	Field B3D_Brs.BB3D_BRUSH	; Les Brushes de la scene
	Field NbNODE%				; Nombre de Nodes dans la scene
	Field NbMesh%				; Nombre de meshs dans la scene
	Field BGR,BGG,BGB			; background Color (ClsColor)
	Field AmbR%,AmbG%,AmbB%		; Ambientlight
	Field FogR%,FogG%,FogB%		; Fog Color
	Field FogN#,FogF#			; Fog Range
	Field HandleParent%[10000]
	Field NbParent%=-1
End Type


Type BB3D_TEXS
	Field CoordS%
	Field Texture%
	Field tex_id%
	Field name$
	Field flags%
	Field blend%
	Field x_pos#
	Field y_pos#
	Field x_scl#
	Field y_scl#
	Field rot#
End Type


Type BB3D_BRUSH
	Field Brush%
	Field name$
	Field red#
	Field grn#
	Field blu#
	Field alp#
	Field shi#
	Field blend%
	Field fx%
	Field Tex_Id%[8],BrushNbTex%
End Type


Type BB3D_NODE
	Field Parent%
	Field Parenthandle%
	Field Typ$
	Field Name$
	Field Entity%

	Field x_pos#=0,y_pos#=0,z_pos#=0
	Field x_scl#=1,y_scl#=1,z_scl#=1
	Field w_rot#=0
	Field x_rot#=0,y_rot#=0,z_rot#=0

	; case "BONE"
	Field NbVrt_inBone
	Field Vrt%[65537]
	Field Weight#[65537]

	;case "MESH"
	Field Surf.BB3D_SRF
	Field IdMesh%
	Field NbSurf%

	; case "CAMERA"
	Field CamFOV#
End Type


Type BB3D_VRT
	Field NbVrtx%
	Field TexC%[65537]
	Field x#[65537]
	Field y#[65537]
	Field z#[65537]

	Field nx#[65537]
	Field ny#[65537]
	Field nz#[65537]

	Field red#[65537]
	Field grn#[65537]
	Field blu#[65537]
	Field alp#[65537]

	Field u1#[65537]
	Field u2#[65537]
	Field u3#[65537]
	Field u4#[65537]
	Field u5#[65537]
	Field u6#[65537]
	Field u7#[65537]
	Field u8#[65537]

	Field v1#[65537]
	Field v2#[65537]
	Field v3#[65537]
	Field v4#[65537]
	Field v5#[65537]
	Field v6#[65537]
	Field v7#[65537]
	Field v8#[65537]

	Field w1#[65537]
	Field w2#[65537]
	Field w3#[65537]
	Field w4#[65537]
	Field w5#[65537]
	Field w6#[65537]
	Field w7#[65537]
	Field w8#[65537]

	Field q1#[65537]
	Field q2#[65537]
	Field q3#[65537]
	Field q4#[65537]
	Field q5#[65537]
	Field q6#[65537]
	Field q7#[65537]
	Field q8#[65537]
End Type


Type BB3D_SRF
	Field Surface%
	Field IdMesh%
	Field brush_id%
	Field NbTri%
	Field NbVrtx%

	Field vt.BB3D_VRT

	Field Tri%[65537]
	Field Vrt0%[65537]
	Field Vrt1%[65537]
	Field Vrt2%[65537]
	
End Type


Function BB3D_LoadAnimMesh(f_name$,parent%=0)
	For s.BB3D_structure=Each BB3D_Structure
		NbB3dScene=NbB3dScene+1
	Next
	s.BB3D_structure=New BB3D_Structure
			LIB_WriteLog(LogF,"=======================================================================================")
			LIB_WriteLog(LogF,"      ***********************                               *********************")
			LIB_WriteLog(LogF," -----------                   DUMP BB3D MESH Version 0.1                 -----------")
			LIB_WriteLog(LogF,"      ***********************                               *********************")
			LIB_WriteLog(LogF,"=======================================================================================")
		s\Id=NbB3dScene
		s\file=ReadFile( f_name$ )
		s\filename$=f_name
		If parent=0
			s\Scene_Root=CreatePivot()
			parent=s\Scene_Root
		EndIf
	If Not s\file RuntimeError "Unable to open b3d file"
	If BB3D_Decode_TAG$(s)<>"BB3D" RuntimeError "Invalid b3d file"
	If ReadInt(s\file)/100>0 RuntimeError "Invalid b3d file version"

	BB3D_Ripp_B3D(s,"",Null)
	CloseFile s\file
	If s\Scene_Root=0 s\Scene_Root=CreateMesh()
	NameEntity s\Scene_Root,Handle(s)
	BB3D_CreateMesh(s,Parent)
	Return s\Scene_Root
End Function



Function BB3D_CreateMesh(s.BB3D_Structure,Parent%=0)
	; creation des textures
	For s\B3D_Tex.BB3D_TEXS = Each BB3D_TEXS
		s\B3D_Tex\Texture=LoadTexture(s\B3D_Tex\name,s\B3D_Tex\flags)
		If s\B3D_Tex\Texture<>0
			TextureBlend s\B3D_Tex\texture,s\B3D_Tex\blend
			PositionTexture s\B3D_Tex\texture,s\B3D_Tex\x_pos,s\B3D_Tex\y_pos
			ScaleTexture s\B3D_Tex\texture,s\B3D_Tex\x_scl,s\B3D_Tex\y_scl
			RotateTexture s\B3D_Tex\texture,s\B3D_Tex\rot
			TextureCoords s\B3D_Tex\texture,s\B3D_Tex\Coords
		EndIf
	Next

	; Creation des brushes
	For s\B3D_Brs.BB3D_BRUSH = Each BB3D_BRUSH
		s\B3D_Brs\Brush=CreateBrush()
		If s\B3D_Brs\Brush<>0
			BrushColor s\B3D_Brs\Brush,s\B3D_Brs\red*255,s\B3D_Brs\grn*255,s\B3D_Brs\blu*255
			BrushAlpha s\B3D_Brs\brush,s\B3D_Brs\alp
			BrushShininess s\B3D_Brs\brush,s\B3D_Brs\shi
			BrushBlend s\B3D_Brs\brush,s\B3D_Brs\Blend
			BrushFX s\B3D_Brs\brush,s\B3D_Brs\fx
			nb=nb+1
			For i = 0 To s\B3D_Brs\BrushNbTex-1
				TexHandle=s\B3D_Brs\Tex_Id[i]
				If TexHandle<>0
					TexHandle=s\HandleTex[TexHandle]
					s\B3D_Tex.BB3D_TEXS=Object.BB3D_TEXS(TexHandle)
					If s\B3D_Tex<>Null
						If s\B3D_Tex\texture<>0	BrushTexture s\B3D_Brs\Brush,s\B3D_Tex\texture,0,i
					EndIf
				EndIf
			Next
		EndIf
	Next

	; Si pas de scene root, on en crée un !
	For n.BB3D_NODE=Each BB3D_NODE
		If n\name="Scene Root"
			Scene_Root_Present=True
			n\Typ="Scene Root"
		EndIf
	Next
		If Scene_Root_Present=0
		EndIf


Cls
Color 0,255,0

	; Creation des Nodes de la Scene
	n.BB3D_NODE=First BB3D_NODE
		For NbNode=1 To s\NbNODE
			Select n\Typ$
				Case "Scene Root"
					If Parent=0
						s\Scene_Root=CreatePivot()
					Else
						s\Scene_Root=CreatePivot(Parent)
					EndIf
					n\Entity=s\Scene_Root
					NameEntity s\Scene_Root,"Scene Root"
				Case "MESH"
					If n\Parenthandle<>0
						parpx#=0
						parpy#=0
						parpz#=0
						parsx#=1
						parsy#=1
						parsz#=1
						parrx#=0
						parry#=0
						parrz#=0

						Par.BB3D_NODE=Object.BB3D_NODE(n\Parenthandle)
						If par<>Null
							If par\Entity<>0
								n\Entity	=	CreateMesh	()
								parpx#=par\x_pos
								parpy#=par\y_pos
								parpz#=par\z_pos
								parsx#=par\x_scl
								parsy#=par\y_scl
								parsz#=par\z_scl
								parrx#=par\x_rot
								parry#=par\y_rot
								parrz#=par\z_rot
								PositionEntity	n\Entity,parpx,parpy,parpz
								RotateEntity	n\entity,parrx,parry,parrz
								EntityParent	n\entity,par\Entity
								NameEntity		n\entity,n\name
								Print "Mesh : "+n\entity+" ( "+EntityName(n\entity)+" ) => parent : "+par\Entity+" ( "+EntityName(par\Entity)+" )"
								Print "       px:"+parpax+" / py:"+parpy+" / pz:"+parpz+" => sx:"+parsx+" sy:"+parsy+" sz:"+parsz+" => rx:"+parrx+" ry:"+parry+" rz:"+parrz
							Else
								n\Entity	=	CreateMesh	(s\Scene_Root)
												NameEntity	n\entity,n\name
							EndIf
						Else
							n\Entity	=	CreateMesh	(s\Scene_Root)
											NameEntity	n\entity,n\name
						EndIf
					Else
						n\Entity	=	CreateMesh	(s\Scene_Root)
										NameEntity	n\entity,n\name
					EndIf

						For n\surf.BB3D_SRF=Each BB3D_SRF
							If n\IdMesh=n\surf\IdMesh
								n\surf\surface=CreateSurface(n\Entity)
								Color 0,255,0
								For vrt=0 To n\surf\vt\NbVrtx-1
									;vrtx%=0
									vn		=	vrt+1
									vpx#	=	n\surf\vt\x[vn]
									vpy#	=	n\surf\vt\y[vn]
									vpz#	=	n\surf\vt\z[vn]
									vpu1#	=	n\surf\vt\u1[vn]
									vpv1#	=	n\surf\vt\v1[vn]
									vpw1#	=	n\surf\vt\w1[vn]
									vpu2#	=	n\surf\vt\u2[vn]
									vpv2#	=	n\surf\vt\v2[vn]
									vpw2#	=	n\surf\vt\w2[vn]
									vpr#	=	n\surf\vt\red[vn]
									vpg#	=	n\surf\vt\grn[vn]
									vpb#	=	n\surf\vt\blu[vn]
									vpal#	=	n\surf\vt\alp[vn]
									vpnx#	=	n\surf\vt\nx[vn]
									vpny#	=	n\surf\vt\ny[vn]
									vpnz#	=	n\surf\vt\nz[vn]
									TexSet%	=	n\surf\vt\TexC[vn]
									vrtx	=	AddVertex		(n\surf\surface,vpx,vpy,vpz,vpu1,vpv1,vpw1)
												VertexColor		n\surf\surface,vrtx,vpnr,vpng,vpnb,vpal
												VertexNormal	n\surf\surface,vrtx,vpnx,vpny,vpnz
									If TexSet>0	VertexTexCoords n\surf\surface,vrtx,vpu1,vpv1,vpw1,0
									If TexSet>1	VertexTexCoords n\surf\surface,vrtx,vpu2,vpv2,vpw2,1
								Next
								For tri= 0 To n\surf\NbTri
									v0	=	n\surf\Vrt0[tri]
									v1	=	n\surf\Vrt1[tri]
									v2	=	n\surf\Vrt2[tri]
											AddTriangle	(n\surf\surface,v0,v1,v2)
								Next
								If n\surf\brush_id>-1
									s\B3D_Brs.BB3D_BRUSH=Object.BB3D_BRUSH(s\HandleBrush[n\surf\brush_id+1])
									If s\B3D_Brs<>Null
										If s\B3D_Brs\Brush<>0
											PaintSurface	n\surf\surface,s\B3D_Brs\Brush
										EndIf
									EndIf
								EndIf
								UpdateNormals n\Entity
							EndIf
						Next
;						Print "Mesh "+n\name+" - pX#:"+n\x_pos+"pY#:"+n\y_pos+"pZ#:"+n\z_pos
;						Print "                 "+"sX#:"+n\x_scl+"sY#:"+n\y_scl+"sZ#:"+n\z_scl
;						Print "                 "+"rX#:"+n\x_rot+"rY#:"+n\y_rot+"rZ#:"+n\z_rot
						PositionEntity	n\Entity,n\x_pos,n\y_pos,n\z_pos,0
						ScaleEntity		n\Entity,n\x_scl,n\y_scl,n\z_scl,0
						RotateEntity	n\Entity,n\x_rot,n_y_rot,n\z_rot,0

				Case "BONE"

			; Variables specifiques des export b3d de pipeline ( 3dsmax )
				Case "B3DEXT_BGCOLOR"
					s\BGR%	=	Float(n\x_pos)*255
					s\BGG%	=	Float(n\y_pos)*255
					s\BGB%	=	Float(n\z_pos)*255
				Case "B3DEXT_AMBIENT"
					s\AmbR%	=	Float(n\x_pos)*255
					s\AmbG%	=	Float(n\y_pos)*255
					s\AmbB%	=	Float(n\z_pos)*255
					AmbientLight	s\AmbR,s\AmbG,s\AmbB
				Case "B3DEXT_FOGCOLOR"
					s\FogR%	=	n\x_pos
					s\FogG%	=	n\y_pos
					s\FogB%	=	n\z_pos
				Case "B3DEXT_FOGRANGE"
					s\FogN#	=	n\x_pos
					s\FogF#	=	n\z_pos
				Case "CAMERA"
					n\Entity	=	CreateCamera	(s\Scene_Root)
									CameraProjMode	n\Entity,0
									PositionEntity	n\Entity,n\x_pos,n\y_pos,n\z_pos
					n\CamFov	=	Float(45)
									CameraClsColor	n\Entity,s\BGR,s\BGG,s\BGB
									CameraZoom		n\Entity,n\CamFOV
					If s\FogF<>0
						CameraFogMode	n\Entity,1
						CameraFogRange	n\Entity,s\FogN,s\FogF
						CameraFogColor	n\Entity,s\FogR,s\FogG,s\FogB
					EndIf


		; Variables specifiques des export b3d de Gile[s]
				Case "GLS_"
			End Select
			n=After n
		Next
	Print " ============= / Ripp ! ============="
WaitKey
	Return s\Scene_Root
End Function




;	BB3D
;		Int version                 ;file format version: default=1
;		[TEXS]                      ;optional textures chunk
;		[BRUS]                      ;optional brushes chunk
;		[NODE]                      ;optional node chunk

Function BB3D_Ripp_B3D( s.BB3D_structure,tab$="",Parent.BB3D_NODE )
	tt$=tab$
	tab$=tab$+"  "
	s\NbParent=s\NbParent+1
	While ( s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
		b3d_TAG$=BB3D_Decode_TAG$(s)
		Select b3d_TAG$
		Case "MESH"
			LIB_WriteLog(LogF,tab+"MESH============================================================================")
			s\NbMesh=s\NbMesh+1
			brush_id=ReadInt(s\file)
			n.BB3D_NODE=Last BB3D_NODE
				If parent<>Null
					n\Parenthandle=Handle(Parent)
				EndIf
				n\Typ="MESH"
				n\IdMesh=s\NbMesh
				CurParent.BB3D_NODE= n.BB3D_NODE
		Case "NODE"
			BB3D_Parse_Nodes(s,tab)
		Case "TEXS"
			BB3D_Parse_Texs(s,tab)
		Case "BRUS"
			BB3D_Parse_Brushes(s,tab)
		Case "VRTS"
			BB3D_Parse_Vertex(s,tab)
		Case "TRIS"
			BB3D_Parse_Tris(s,tab)
		Case "BONE"
			n.BB3D_NODE=Last BB3D_NODE
			CurParent.BB3D_NODE=BB3D_Parse_Bone(s,n,tab)
		Case "ANIM"
			BB3D_Parse_Anims(s,tab)
		Case "KEYS"
			BB3D_Parse_Keys(s,tab)
		Default
			DebugLog tab$+"Tag mmm...non supporté..."
		End Select

		BB3D_Ripp_B3D( s,tab$,CurParent )								;enfant de cette branche
		SeekFile s\file,s\Reg_Pos[s\Cur_Pos]:s\Cur_Pos=s\Cur_Pos-1		;cloture de la branche
	Wend
End Function













;====================================================================================
;       ==================      Fonctions PRIVEES      =====================
;====================================================================================

;     =======
;***** functions for reading from B3D files *****
;     =======

;     =======
Function BB3D_Decode_String$(s.BB3D_structure)
	Repeat
		ch=ReadByte(s\file)
		If ch=0 Return t$
		t$=t$+Chr$(ch)
	Forever
End Function
;     =======

;     =======
Function BB3D_Decode_TAG$(s.BB3D_structure)
	For k=1 To 4
		byt=ReadByte(s\file)
		tag$=tag$+Chr$(byt)
	Next
	offset=ReadInt( s\file)
	s\Cur_Pos=s\Cur_Pos+1
	s\Reg_Pos[s\Cur_Pos]=FilePos( s\file)+offset
	Return tag$
End Function
;     =======

Function BB3D_____________NODES()
;	NODE:
;		char name[]                 ;name of node
;		Float position[3]           ;local...
;		Float scale[3]              ;coord...
;		Float rotation[4]           ;system...
;		[MESH|BONE]                 ;what 'kind' of node this is - if unrecognized, just use a Blitz3D pivot.
;		[KEYS[,KEYS...]]            ;optional animation keys
;		[NODE[,NODE...]]            ;optional child nodes
;		[ANIM]                      ;optional animation

;	The NODE chunk describes a Blitz3D Entity. The scene hierarchy is expressed by the nesting of NODE
;	chunks.

;	NODE kinds are currently mutually exclusive - ie: a node can be a MESH, Or a BONE, but Not both!
;	However, it can be neither...If no kind is specified, the node is just a 'Null' node - in Blitz3D
;	speak, a pivot.

;	The presence of an ANIM chunk in a NODE indicates that an animation starts here in the hierarchy.
;	This allows animations of differing speeds/lengths To be potentially nested.

;	There are many more 'kind' chunks coming, including camera, light, sprite, plane etc. For Now, the
;	use of a Pivot in cases where the node kind is unknown will allow For backward compatibility.
	End Function
;     =======
Function BB3D_Parse_Nodes(s.BB3D_Structure,tab$="")
	Color 255,255,0
	LIB_WriteLog(LogF,tab+"NODE============================================================================")
	s\NbNODE=s\NbNODE+1
	n.BB3D_NODE=New BB3D_NODE
	n\name$  =BB3D_Decode_String$(s)
	n\x_pos# =ReadFloat(s\file)
	n\y_pos# =ReadFloat(s\file)
	n\z_pos# =ReadFloat(s\file)
	n\x_scl# =ReadFloat(s\file)
	n\y_scl# =ReadFloat(s\file)
	n\z_scl# =ReadFloat(s\file)
	n\w_rot# =ReadFloat(s\file)
	n\x_rot# =ReadFloat(s\file)
	n\y_rot# =ReadFloat(s\file)
	n\z_rot# =ReadFloat(s\file)
	; tag specifiques aux export de b3d pipeline
	If n\name="B3DEXT_CAMERA"
		Fov#=n\x_pos
		n=Before n
		n\typ="CAMERA"
			n\CamFOV#=fov
			n.BB3D_NODE= Last BB3D_NODE
			Delete Last BB3D_NODE
			s\NbNODE=s\NbNODE-1
			n.BB3D_NODE= Last BB3D_NODE
			LIB_WriteLog(LogF,tab$+"name="+n\name$+" : px:"+n\x_pos+"_py:"+n\y_pos+"_pz:"+n\z_pos)
	ElseIf n\name="B3DEXT_BGCOLOR"
		n\typ=n\name
			LIB_WriteLog(LogF,tab$+"ClsColor="+n\name$+" : ClsRed:"+n\x_pos+" ClsGreen:"+n\y_pos+" ClsBlue:"+n\z_pos)
	ElseIf n\name="B3DEXT_AMBIENT"
		n\typ=n\name
			LIB_WriteLog(LogF,tab$+"AmbientLight="+n\name$+" : AmbR:"+n\x_pos+" AmbG:"+n\y_pos+" AmbB:"+n\z_pos)
	ElseIf n\name="B3DEXT_FOGCOLOR"
		n\typ=n\name
			LIB_WriteLog(LogF,tab$+"Fog Color="+n\name$+" : FogR:"+n\x_pos+" FogG:"+n\y_pos+" FogB:"+n\z_pos)
	ElseIf n\name="B3DEXT_FOGRANGE"
		n\typ=n\name
			LIB_WriteLog(LogF,tab$+"Fog Range="+n\name$+" : FogN:"+n\x_pos+" FogF:"+n\z_pos)
	Else
		LIB_WriteLog(LogF,tab$+"name="+n\name$)
		LIB_WriteLog(LogF,tab$+"Pos : "+n\x_pos+"|"+n\y_pos+"|"+n\z_pos)
		LIB_WriteLog(LogF,tab$+"Scl : "+n\x_scl+"|"+n\y_scl+"|"+n\z_scl)
		LIB_WriteLog(LogF,tab$+"Rot : "+Int(n\x_rot)+"|"+Int(n\y_rot)+"|"+Int(n\z_rot))
	EndIf
End Function
;     =======

Function BB3D__________TEXTURES()
;	TEXS
;		{
;			char file[]                 ;texture file name
;			Int flags,blend             ;blitz3D TextureFLags and TextureBlend: default=1,2
;			Float x_pos,y_pos           ;x and y position of texture: default=0,0
;			Float x_scale,y_scale       ;x and y scale of texture: default=1,1
;			Float rotation              ;rotation of texture (in radians): default=0
;		}
	End Function
;     =======
Function BB3D_Parse_TexS(s.BB3D_Structure,tab$="")
	Color 0,255,0
	LIB_WriteLog(LogF,tab+"===============TEXS=================================")
	AllTex=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
	While AllTex>0
		s\B3D_Tex.BB3D_TEXS	=	New BB3D_TEXS
		s\NbTex				=	s\NbTex+1
		s\B3D_Tex\name$		=	BB3D_Decode_String$(s)
		s\HandleTex[s\NbTex]=	Handle(s\B3D_Tex)
		s\B3D_Tex\flags  	=	ReadInt(s\file)
		s\B3D_Tex\blend  	=	ReadInt(s\file)
		s\B3D_Tex\x_pos# 	=	ReadFloat(s\file)
		s\B3D_Tex\y_pos# 	=	ReadFloat(s\file)
		s\B3D_Tex\x_scl# 	=	ReadFloat(s\file)
		s\B3D_Tex\y_scl# 	=	ReadFloat(s\file)
		s\B3D_Tex\rot#   	=	ReadFloat(s\file)
		AllTex=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
		If s\B3D_Tex\flags>65535
			s\B3D_Tex\flags=s\B3D_Tex\flags-65536
			s\B3D_Tex\CoordS=1
		EndIf
		LIB_WriteLog(LogF,tab+tab+"tex :"+s\B3D_Tex\name)
	Wend
End Function
;     =======

Function BB3D___________BRUSHES()
;	BRUS
;	Int n_texs
;	{
;		char name[]                 ;eg "WATER" - just use texture name by default
;		Float red,green,blue,alpha  ;Blitz3D Brushcolor and Brushalpha: default=1,1,1,1
;		Float shininess             ;Blitz3D BrushShininess: default=0
;		Int blend,fx                ;Blitz3D Brushblend and BrushFX: default=1,0
;		Int texture_id[n_texs]      ;textures used in brush
;	}
	End Function
;     =======
Function BB3D_Parse_Brushes(s.BB3D_Structure,tab$="")
	Color 255,0,0
	LIB_WriteLog(LogF,tab+"===============BRUS==================================")
	n_texs	=	ReadInt(s\file)
	AllBrush=	(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
	While AllBrush>0
		s\B3D_Brs.BB3D_BRUSH=New BB3D_BRUSH
			s\B3D_Brs\name$	=BB3D_Decode_String$(s)		; nom$ de la brush
			s\B3D_Brs\red#	=	ReadFloat(s\file)		; R# BrushColor ( de 0 à 1 => à multiplié par 255 ! )
			s\B3D_Brs\grn#	=	ReadFloat(s\file)		; G#
			s\B3D_Brs\blu#	=	ReadFloat(s\file)		; B#
			s\B3D_Brs\alp#	=	ReadFloat(s\file)		; alpha#
			s\B3D_Brs\shi#	=	ReadFloat(s\file)		; Shininess#
			s\B3D_Brs\blend%=	ReadInt(s\file)			; Blend%
			s\B3D_Brs\fx%	=	ReadInt(s\file)			; fx%
			s\B3D_Brs\BrushNbTex=n_texs-1
			For k=0 To n_texs-1
				NumTex%				=	ReadInt(s\file)+1
				s\B3D_Brs\Tex_Id[k]	=	NumTex
				If NumTex<>0
					s\B3D_Tex.BB3D_TEXS=Object.BB3D_TEXS(s\HandleTex[NumTex])
				EndIf
			Next
			s\NbBrush				=	s\NbBrush+1
			s\HandleBrush[s\NbBrush]=	Handle(s\B3D_Brs)
			AllBrush				=	(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
										LIB_WriteLog(LogF,tab+tab+s\B3D_Brs\name)
	Wend
End Function
;     =======

Function BB3D_____________BONES()
;	BONE:
;		{
;			Int vertex_id               ;vertex affected by this bone
;			Float weight                ;how much the vertex is affected
;		}
;
;	The BONE chunk describes a bone. Weights are applied To the mesh described in the enclosing ANIM -
;	in 99% of cases, this will simply be the MESH contained in the root NODE chunk.
	End Function
;     =======
Function BB3D_Parse_Bone.BB3D_NODE(s.BB3D_Structure,n.BB3D_NODE,tab$="")
	LIB_WriteLog(LogF,tab+"BONE============================================================================")
	n\NbVrt_inBone	=	0
	n\Typ			=	"BONE"
	sz				=	8
	n_weights		=	(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))/sz
	If n_weights*sz=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
		While (s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
			n\NbVrt_inBone				=	n\NbVrt_inBone+1
			n\Vrt[n\NbVrt_inBone]		=	ReadInt(s\file)		; Index du vertex
			n\weight#[n\NbVrt_inBone]	=	ReadFloat(s\file)	; poid
			LIB_WriteLog(LogF,tab+"VrtId:"+n\Vrt[n\NbVrt_inBone]+" w#:"+n\weight#[n\NbVrt_inBone])
		Wend
	Else
		DebugLog tab$+"***** Illegal number of bone weights *****"
	EndIf
	Return n
End Function
;     =======

Function BB3D__________VERTICES()
	;VRTS:
	;  Int flags                   ;1=normal values present, 2=rgba values present
	;  Int tex_coord_sets          ;texture coords per vertex (eg: 1 for simple U/V) max=8
	;  Int tex_coord_set_size      ;components per set (eg: 2 for simple U/V) max=4
	;  {
	;  Float x,y,z                 ;always present
	;  Float nx,ny,nz              ;vertex normal: present if (flags&1)
	;  Float red,green,blue,alpha  ;vertex color: present if (flags&2)
	;  Float tex_coords[tex_coord_sets][tex_coord_set_size]	;tex coords
	;  }

	;The VRTS chunk contains a list of vertices. The 'flags' value is used To indicate how much extra
	;Data (normal/Color) is stored with Each vertex, And the tex_coord_sets And tex_coord_set_size
	;values describe texture coordinate information stored with Each vertex.
	End Function

;     =======
Function BB3D_Parse_Vertex(s.BB3D_structure,tab$="")
	vt.BB3D_VRT=New BB3D_VRT
	flags=ReadInt(s\file)
	; => flag = 1 => Normal coord
	; => flag = 2 => VertexColor RGB
	tc_sets=ReadInt(s\file) ; textureCoord Set
	tc_size=ReadInt(s\file)
	sz=12+tc_sets*tc_size*4
	If flags And 1 Then sz=sz+12
	If flags And 2 Then sz=sz+16
	n_verts=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))/sz
	If n_verts*sz=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file )) 
		IdVrt=0
		While (s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
			IdVrt=IdVrt+1
			vt\TexC%[IdVrt]=tc_sets
			vt\x#[IdVrt]=ReadFloat(s\file)							; X# vertexCoords
			vt\y#[IdVrt]=ReadFloat(s\file)							; y#
			vt\z#[IdVrt]=ReadFloat(s\file)							; z#
			If flags And 1
				vt\nx#[IdVrt]=ReadFloat(s\file)						; Nx# VertexNormal
				vt\ny#[IdVrt]=ReadFloat(s\file)						; Ny#
				vt\nz#[IdVrt]=ReadFloat(s\file)						; Nz#
			EndIf
			If flags And 2
				vt\red#[IdVrt]=ReadFloat(s\file)					; R# VertexColor ( range 0 , 1 => à multiplier par 255 )
				vt\grn#[IdVrt]=ReadFloat(s\file)					; G#
				vt\blu#[IdVrt]=ReadFloat(s\file)					; B#
				vt\alp#[IdVrt]=ReadFloat(s\file)					; alpha#
			EndIf
			If tc_sets>0
				If tc_size >0 vt\u1#[IdVrt]=ReadFloat(s\file)		; u1# VertexTexCoords ( UV set 1 )
				If tc_size >1 vt\v1#[IdVrt]=ReadFloat(s\file)		; v1#
				If tc_size >2 vt\w1#[IdVrt]=ReadFloat(s\file)		; w1# profondeur ...
				If tc_size >3 vt\q1#[IdVrt]=ReadFloat(s\file)		; ...# param additionnel au cas où .
			EndIf
			If tc_sets>1
				If tc_size >0 vt\u2#[IdVrt]=ReadFloat(s\file)		; deuxieme set d'UV
				If tc_size >1 vt\v2#[IdVrt]=ReadFloat(s\file)
				If tc_size >2 vt\w2#[IdVrt]=ReadFloat(s\file)
				If tc_size >3 vt\q2#[IdVrt]=ReadFloat(s\file)
			EndIf
			If tc_sets>2
				If tc_size >0 vt\u3#[IdVrt]=ReadFloat(s\file)		; troisieme ...
				If tc_size >1 vt\v3#[IdVrt]=ReadFloat(s\file)
				If tc_size >2 vt\w3#[IdVrt]=ReadFloat(s\file)
				If tc_size >3 vt\q3#[IdVrt]=ReadFloat(s\file)
			EndIf
			If tc_sets>3
				If tc_size >0 vt\u4#[IdVrt]=ReadFloat(s\file)		; etc...
				If tc_size >1 vt\v4#[IdVrt]=ReadFloat(s\file)
				If tc_size >2 vt\w4#[IdVrt]=ReadFloat(s\file)
				If tc_size >3 vt\q4#[IdVrt]=ReadFloat(s\file)
			EndIf
			If tc_sets>4
				If tc_size >0 vt\u5#[IdVrt]=ReadFloat(s\file)
				If tc_size >1 vt\v5#[IdVrt]=ReadFloat(s\file)
				If tc_size >2 vt\w5#[IdVrt]=ReadFloat(s\file)
				If tc_size >3 vt\q5#[IdVrt]=ReadFloat(s\file)
			EndIf
			If tc_sets>5
				If tc_size >0 vt\u6#[IdVrt]=ReadFloat(s\file)
				If tc_size >1 vt\v6#[IdVrt]=ReadFloat(s\file)
				If tc_size >2 vt\w6#[IdVrt]=ReadFloat(s\file)
				If tc_size >3 vt\q6#[IdVrt]=ReadFloat(s\file)
			EndIf
			If tc_sets>6
				If tc_size >0 vt\u7#[IdVrt]=ReadFloat(s\file)
				If tc_size >1 vt\v7#[IdVrt]=ReadFloat(s\file)
				If tc_size >2 vt\w7#[IdVrt]=ReadFloat(s\file)
				If tc_size >3 vt\q7#[IdVrt]=ReadFloat(s\file)
			EndIf
			If tc_sets>7
				If tc_size >0 vt\u8#[IdVrt]=ReadFloat(s\file)		; jusqu'au 8 eme set 
				If tc_size >1 vt\v8#[IdVrt]=ReadFloat(s\file)
				If tc_size >2 vt\w8#[IdVrt]=ReadFloat(s\file)
				If tc_size >3 vt\q8#[IdVrt]=ReadFloat(s\file)
			EndIf
			LIB_WriteLog(LogF,tab+"Vrt "+IdVrt+" Pos:"+vt\x#[IdVrt]+" "+vt\y#[IdVrt]+" "+vt\z#[IdVrt])
			LIB_WriteLog(LogF,tab+tab+"Nrm:"+vt\nx#[IdVrt]+" "+vt\ny#[IdVrt]+" "+vt\nz#[IdVrt])
			LIB_WriteLog(LogF,tab+tab+"Clr:"+vt\red#[IdVrt]+" "+vt\grn#[IdVrt]+" "+vt\blu#[IdVrt]+" "+vt\alp#[IdVrt])
			LIB_WriteLog(LogF,tab+tab+"UV#: u1 "+vt\u1#[IdVrt]+" u2 "+vt\u2#[IdVrt]+" v1 "+vt\v1#[IdVrt]+" v2"+vt\v2#[IdVrt])
		Wend
		vt\NbVrtx=IdVrt
	Else
		LIB_WriteLog(LogF,tab$+"***** Illegal number of vertices *****")
	EndIf
End Function
;     =======


Function BB3D_________TRIANGLES()
;	TRIS:
;		Int brush_id                ;brush applied to these TRIs: default=-1
;		{
;			Int vertex_id[3]            ;vertex indices
;		}
;	The TRIS chunk contains a list of triangles that all share a common brush.
	End Function
;     =======


Function BB3D_Parse_Tris(s.BB3D_Structure,tab$="")
	n.BB3D_NODE= Last BB3D_NODE
	n\NbSurf=n\NbSurf+1
	n\surf.BB3D_SRF=New BB3D_SRF
	n\surf\IdMesh=n\IdMesh
	n\surf\vt.BB3D_VRT=Last BB3D_VRT
	n\surf\brush_id=ReadInt(s\file)
	sz=12
	n_tris=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))/sz
;	Print n_tris
	If n_tris*sz=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
		ntri=0
		While (s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
			ntri=ntri+1
			n\surf\vrt0[ntri]=ReadInt(s\file)
			n\surf\vrt1[ntri]=ReadInt(s\file)
			n\surf\vrt2[ntri]=ReadInt(s\file)
		Wend
		n\surf\NbTri=ntri
		LIB_WriteLog(LogF,tab+tab+"Surface créée - "+ntri+" tris créés")
	Else
		LIB_WriteLog(LogF,tab$+"***** Illegal number of triangles *****")
	EndIf
End Function
;     =======


Function BB3D_______________KEYS()
;	KEYS:
;		Int flags		                ;1=position, 2=scale, 4=rotation
;		{
;			Int frame                   ;where key occurs
;			Float position[3]           ;present if (flags&1)
;			Float scale[3]              ;present if (flags&2)
;			Float rotation[4]           ;present if (flags&4)
;		}

;	The KEYS chunk is a list of animation keys. The 'flags' value describes what kind of animation
;	info is stored in the chunk - position, scale, rotation, Or any combination of.
	End Function
;     =======


Function BB3D_Parse_Keys(s.BB3D_Structure,tab$="")
	LIB_WriteLog(LogF,tab+"=>clé <=")
	flags=ReadInt(s\file)
	sz=4
	If flags And 1 sz=sz+12
	If flags And 2 sz=sz+12
	If flags And 4 sz=sz+16
	n_keys= (s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))/sz
	If n_keys*sz=(s\Reg_Pos[s\Cur_Pos]-FilePos( s\file )) 
		While (s\Reg_Pos[s\Cur_Pos]-FilePos( s\file ))
			frame=ReadInt(s\file)
			If flags And 1
				key_px#=ReadFloat(s\file)
				key_py#=ReadFloat(s\file)
				key_pz#=ReadFloat(s\file)
			EndIf
			If flags And 2
				key_sx#=ReadFloat(s\file)
				key_sy#=ReadFloat(s\file)
				key_sz#=ReadFloat(s\file)
			EndIf
			If flags And 4
				key_rw#=ReadFloat(s\file)
				key_rx#=ReadFloat(s\file)
				key_ry#=ReadFloat(s\file)
				key_rz#=ReadFloat(s\file)
			EndIf
			LIB_WriteLog(LogF," - pos :"+key_px+" "+key_py+" "+key_pz,1)
			LIB_WriteLog(LogF," - scl :"+key_sx+" "+key_sy+" "+key_sz,1)
			LIB_WriteLog(LogF," - rot :"+key_rx+" "+key_ry+" "+key_rz)
		Wend
	Else
		LIB_WriteLog(LogF,tab$+"***** Illegal number of keys *****")
	EndIf
End Function
;     =======

Function BB3D______________ANIMS()
;	ANIM:
;		Int flags                   ;unused: default=0
;		Int frames                  ;how many frames in anim
;		Float fps                   ;default=60

;	The ANIM chunk describes an animation.
	End Function
;     =======
Function BB3D_Parse_Anims(s.BB3D_Structure,tab$="")
	LIB_WriteLog(LogF,tab+"ANIM============================================================================")
	flags	=	ReadInt(s\file)
	n_frames=	ReadInt(s\file)
	fps		=	ReadFloat(s\file)
	LIB_WriteLog(LogF,tab+tab$+flags+" "+n_frames+" "+fps)
End Function
;     =======



Animation tool. Interesting.

Are you planning on making any animated RPG characters - like the ones in my sig?

you 're a nomad shop :)

I don't expect it. I just want to ave my own tool for a rpg I'm developing. So I'won't have to explain where my models come from :)
Imagine i have to justify Models from 3dsmax ( 5000€ license ... hum ... )

Maybe i'll share the tool, but for the moment, I don't know.

What i can say, The Eliza3D engine ( which will need this part of code ) is a freeware blitzmax 3D module developped by TMyke => http://www.eliza3d.com/index.htm

So, I'll see when i'll finish all this stuff :)

Puki: ....like the ones in my sig?

What sig?