save b3d madness

Blitz3D Forums/Blitz3D Programming/save b3d madness

koekjesbaby(Posted 2004) [#1]
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?


fredborg(Posted 2004) [#2]
The first flag needs to be 3 instead of 2, as you are saving both vertex colors and normal.

The way the flags work, is that you combine them.
1 = Vertex Normal
2 = Vertex Color
3 = Vertex Normal + Color

Now bring on the editor :)


koekjesbaby(Posted 2004) [#3]
heh, fredborg to the resque. they might have been clearer on that in the unofficial specifications...

and the editor is coming along fine. the only problems are that i have a) too many ideas for it b) i want it to be solid and a nice tool in general c) i've got a full time job since last friday (and a girlfriend four five years) which takes a lot of time.

so. please, be patient.