Writing a .b3d

Blitz3D Forums/Blitz3D Programming/Writing a .b3d

Ross C(Posted 2006) [#1]
Ok, major edit. I have written this simple function, modified from marks example:

Function WriteBB3D( f_name$,mesh,mesh1 )

	file=WriteFile( f_name$ )

	b3dSetFile( file )
	
	b3dBeginChunk( "BB3D" )
		b3dWriteInt( 1 )	;version
		
		b3dBeginChunk( "BRUS" )
			b3dWriteInt( 0 )					;0 textures per brush
			b3dWriteString( "Shiny Red" )		;name
			b3dWriteFloat( 1 )					;red
			b3dWriteFloat( 0 )					;green
			b3dWriteFloat( 0 )					;blue
			b3dWriteFloat( 1 )					;alpha
			b3dWriteFloat( .75 )				;shininess
			b3dWriteInt( 1 )					;blend
			b3dWriteInt( 0 )					;FX
		b3dEndChunk()	;end of BRUS chunk
		
		b3dBeginChunk( "NODE" )
			b3dWriteString( "entity_name_here!" )
			b3dWriteFloat( 0 )	;x_pos
			b3dWriteFloat( 0 )	;y_pos
			b3dWriteFloat( 0 )	;y_pos
			b3dWriteFloat( 1 )	;x_scale
			b3dWriteFloat( 1 )	;y_scale
			b3dWriteFloat( 1 )	;z_scale
			b3dWriteFloat( 1 )	;rot_w
			b3dWriteFloat( 0 )	;rot_x
			b3dWriteFloat( 0 )	;rot_y
			b3dWriteFloat( 0 )	;rot_z
			WriteMESH( mesh )
		b3dEndChunk()	;end of NODE chunk

		b3dBeginChunk( "NODE" )
			b3dWriteString( "entity_name_herea!" )
			b3dWriteFloat( 0 )	;x_pos
			b3dWriteFloat( 0 )	;y_pos
			b3dWriteFloat( 0 )	;y_pos
			b3dWriteFloat( 1 )	;x_scale
			b3dWriteFloat( 1 )	;y_scale
			b3dWriteFloat( 1 )	;z_scale
			b3dWriteFloat( 1 )	;rot_w
			b3dWriteFloat( 0 )	;rot_x
			b3dWriteFloat( 0 )	;rot_y
			b3dWriteFloat( 0 )	;rot_z
			WriteMESH( mesh1 )
		b3dEndChunk()	;end of NODE chunk

	b3dEndChunk()	;end of BB3D chunk
	
	CloseFile file
End Function


It saves the meshes fine. Two different meshes, BUT, crashes when i load it, so i must be doing something wrong when i'm saving the second mesh. Like something i'm supposed to do between the nodes? Any ideas?


Ross C(Posted 2006) [#2]
This one jfk :D


Ross C(Posted 2006) [#3]
Ah, it's ok, i need to nest the NODE, in beside the other one it seems :D

Like so:

Function WriteBB3D( f_name$,mesh,mesh1 )

	file=WriteFile( f_name$ )

	b3dSetFile( file )
	
	b3dBeginChunk( "BB3D" )
		b3dWriteInt( 1 )	;version
		
		b3dBeginChunk( "BRUS" )
			b3dWriteInt( 0 )					;0 textures per brush
			b3dWriteString( "Shiny Red" )		;name
			b3dWriteFloat( 1 )					;red
			b3dWriteFloat( 0 )					;green
			b3dWriteFloat( 0 )					;blue
			b3dWriteFloat( 1 )					;alpha
			b3dWriteFloat( .75 )				;shininess
			b3dWriteInt( 1 )					;blend
			b3dWriteInt( 0 )					;FX
		b3dEndChunk()	;end of BRUS chunk
		
		b3dBeginChunk( "NODE" )
			b3dWriteString( "entity_name_here!" )
			b3dWriteFloat( 0 )	;x_pos
			b3dWriteFloat( 0 )	;y_pos
			b3dWriteFloat( 0 )	;y_pos
			b3dWriteFloat( 1 )	;x_scale
			b3dWriteFloat( 1 )	;y_scale
			b3dWriteFloat( 1 )	;z_scale
			b3dWriteFloat( 1 )	;rot_w
			b3dWriteFloat( 0 )	;rot_x
			b3dWriteFloat( 0 )	;rot_y
			b3dWriteFloat( 0 )	;rot_z
			WriteMESH( mesh )

				b3dBeginChunk( "NODE" )
					b3dWriteString( "entity_name_herea!" )
					b3dWriteFloat( 0 )	;x_pos
					b3dWriteFloat( 0 )	;y_pos
					b3dWriteFloat( 0 )	;y_pos
					b3dWriteFloat( 1 )	;x_scale
					b3dWriteFloat( 1 )	;y_scale
					b3dWriteFloat( 1 )	;z_scale
					b3dWriteFloat( 1 )	;rot_w
					b3dWriteFloat( 0 )	;rot_x
					b3dWriteFloat( 0 )	;rot_y
					b3dWriteFloat( 0 )	;rot_z
					WriteMESH( mesh1 )
				b3dEndChunk()	;end of NODE chunk

		b3dEndChunk()	;end of NODE chunk



	b3dEndChunk()	;end of BB3D chunk
	
	CloseFile file
End Function



Ross C(Posted 2006) [#4]
If you want more entities to be saved, simply put them inside the first node. I get how this works now :D


jfk EO-11110(Posted 2006) [#5]
Ok, I see. Thanks for sharing.