How do you save a mesh made from blitz 3D?

Blitz3D Forums/Blitz3D Beginners Area/How do you save a mesh made from blitz 3D?

If you are saving terrain files, it is best you save them as an image file of TerrainSize by TerrainSize. Each pixel is then calculated to be of the same brightness as the height. An example would be a height of 126, so you would plot color 126, 126, 126 at the same coordinates. You cannot use WriteBB3D on terrains - they are NOT true meshes!

Anyway, if you read the code archives correctly, you'd notice there was a function called "WriteBB3D(Filename, mesh)". Make sure you include the "b3dfile.bb" file in your source (used for b3dWriteFloat et al) and call WriteBB3D whenever you need to save the mesh.

Oh, and one other thing - The file it saves is a B3D file, so no special loader is needed to reload it into Blitz. All you need do is use LoadMesh( filename ).

Some untested source code for you...
Function SaveTerrain( terra, filename$ )

	If terra = 0 Return False

	sze = TerrainSize(terra)	; width of terrain
	img = CreateImage(sze, sze)	; Create image used for heightmap

	buff = GraphicsBuffer()
	SetBuffer ImageBuffer(img)

	For x = 0 To (sze - 1)
		For y = 0 To (sze - 1)
			
			hgt = Floor(TerrainHeight#(terra, x, y))
			Color hgt, hgt, hgt
			Plot x, y
		Next
	Next

	SetBuffer buff

	SaveBuffer ImageBuffer(img), filename$

	Return True

End Function