save b3d madness

Blitz3D Forums/Blitz3D Programming/save b3d madness

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.

this is costing me so much hair, i'm probably bald within an hour if i continue without your wise words. :)

i am trying to save a mesh that's createn in blitz using the codes from the code archives and specs and utils. it works well, except when i try to save vertices with color and alpha information. this is the spec:
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
  }

and this is what i write to the file (simplyfied):
2	;1=normal values present, 2=rgba values present
1	;texture coords per vertex (eg: 1 for simple U/V) max=8
2	 ;components per set (eg: 2 for simple U/V) max=4
{
float 1,1,1			;always present
float 1,1,1			;vertex normal: present if (flags&1)
float 1,0,0,.5		;vertex color: present if (flags&2)
float 0,0			;tex coords
}

and in code:
b3dBeginChunk( "VRTS" )
b3dWriteInt( 2 )	;flags - 0=no normal/color
b3dWriteInt( 1 )	;number of tex_coord sets (eg: 2 with lightmap)
b3dWriteInt( 2 )	;coords per set (u,v,w?) 2 with uv, 3 with uvw

For k=1 To n_surfs
	surf=GetSurface( mesh,k )
	n_verts=CountVertices( surf )-1
	
	For j=0 To n_verts
		
		b3dWriteFloat( VertexX( surf,j ) )
		b3dWriteFloat( VertexY( surf,j ) )
		b3dWriteFloat( VertexZ( surf,j ) )
		
		b3dWriteFloat( VertexNX( surf,j ) )
		b3dWriteFloat( VertexNY( surf,j ) )
		b3dWriteFloat( VertexNZ( surf,j ) )
		
		b3dWriteFloat( VertexRed( surf,j )/255.0 )
		b3dWriteFloat( VertexGreen( surf,j )/255.0 )
		b3dWriteFloat( VertexBlue( surf,j )/255.0 )
		b3dWriteFloat( VertexAlpha( surf,j ))
		
		b3dWriteFloat( VertexU#( surf,j,0 ) )
		b3dWriteFloat( VertexV#( surf,j,0 ) )


which should be ok (according to the specs), but the file is completely screwed up if you load it (if it loads at all, because sometimes it just hangs the program (the program that loads the b3d)).

any suggestions?