I've attached the promised sample to this post. I'm not finished with it yet, but it does everything that you require.
I haven't had a chance to annotate the source file properly yet, so I'll give a quick rundown of how to use it here:
- Call the PrepareForNewFileGen() function prior to generating any meshes
- Use the AddMeshBlockFromFile/Object/Mesh() functions to register your 'building blocks' with the system. These functions require that you specify a unique id string for each building block that the system will use to identify it later on. For your project, the unique id can be the ASCII character you use to represent different blocks in your map file.
Example:
make object box 1, 10, 10, 10
AddMeshBlockFromObject( 1, "texture.png", "a_box" )
` No longer need this
delete object 1
- When you have defined all of your blocks, call BeginGeneration() to switch into object generation mode.
- Once in this mode, use the AddToOutput( id as string, x_pos as float, y_pos as float, z_pos as float ) function to add instances of your building blocks to the generated mesh.
- Call EndGeneration() to exit this mode and generate the x file. The name of the generated file is stored in the TEMP_FILE_NAME constant.
Example:
BeginGeneration()
AddToOutput( "a_box", 0, 0, 0 )
AddToOutput( "a_box", 10, 0, 0 )
EndGeneration()
load object TEMP_FILE_NAME, 1
- If nothing seems to be happening, check the return values of the functions that you call and use the GetErrorDescription() function to get a string containing a description of any errors that are going on (NB. not all of the functions return an error value)
The attached example takes a couple of seconds to generate the file. There's lots that I can do to speed up the file generation and I'll work on that when I next get some spare time.
There's still some work to be done on it (mostly just speeding up the generation of the X file). I also want to add the ability to combine multiple textures into a single image to further improve performance (less textures = less render state changes = faster rendering!)
I'm going away for few days now so you may not see any replies from me until a little later next week!