write b3d files from code

Blitz3D Forums/Blitz3D Beginners Area/write b3d files from code

Prym(Posted 2014) [#1]
I don't want to use logiciels .
I want to save a created mesh into a b3d file .
Is there someone who can give me a complete example ( with b3d utils )
Their examples don't show all I need .
I don't find how to define textures and brushes .
My mesh, writen with "Function WriteBB3D( f_name$,mesh )", can not be load with the loadmesh() blitz3d command .

Thank you for your help .


Charrua(Posted 2014) [#2]
hi, i work a little with b3d file format when doing an editor

i started isolating the most important part of my save_b3d

and finally get an stand alone .bb

hope it helps

you need blitz3D+.dll (which is included in the zip file)


https://dl.dropboxusercontent.com/u/78894295/saveb3d.zip

or (as i did) you have to keep track of each texture, brush applied to each surface, so, when scanning the mesh you has all the info to be saved...





Prym(Posted 2014) [#3]
Charrua Hello and thank you for your reply.
I hope I do not owe you anything.
I am low and I can not fully exploit your example. Thank you anyway.
I did a lot of testing on my side , without success.
I answered you to ask yourself some questions:

Block of code from b3d.utils :

Function WriteBB3D( f_name$,mesh )
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!" )
etc ...
End Function

- How have the block textures ?
- The textures are they still attached to brushes ?
- Can you load a " .b3d " without texture , then the texture after ?
- So how to write ?


Charrua(Posted 2014) [#4]
well, i'm not an expert on the subject...

a entity has surfaces
each surface has a brush
each brush has color, blend, bright many other properties and up to 8 textures, each with it's own properties...

a .b3d file has some mandatory chunks (or sections) and other that may or may not be.

if the object has no textures, then should be at least one brush but no textures chunk (the example that cames with b3d_util has no textures for instance).

The function i wrote, scans the mesh, scan each surface, get each brush and scans each texture it has (if any), count how much textures are in the whole mesh and for each brush and then writes the list of textures and brushes, each brush has to include how many texture it has if any and at the end, the list of texture indexes as they appear on the TEXS chunk.

i know it is not easy at first (and after a while ...)

for example, you may load a mesh, texture it and afterwards save the mesh with the textures, but, you have to tell my function about the texture you applied:

;load a texture for it
texName$ = "tex.jpg"
texFlags = 1
tex=LoadTexture(texName,texFlags)
;create an tTexture object to keep track of some aditional info for each texture used
texobj.tTexture=New tTexture
texobj\file  = texName
texobj\flags = texFlags


this fragment, loads a texture, which will be applied to abrush (BrushTexture bru,tex) and then applied to the mesh (PaintMesh mesh,bru)

the sentence:
texobj.tTexture=New tTexture


creates an object to keep track of each texture
i need to know each texture the object has to properly place the texture index afterwards.

this save_b3d works only if you has the complete list of textures linked to tTexture objects if not it will fail.

blitz3d keeps trak of many properties not exposed via functions, for that reason i use blitz3d+.dll, to get some extra info about brush and textures

i correct a bug i found on the first version, and updated the demo code, now it creates two entities, textures them with 2 different textures, then makes one mesh and save to disk as one b3d file.

new file:
https://dl.dropboxusercontent.com/u/78894295/saveb3d.zip

juan


Blitzplotter(Posted 2014) [#5]
This looks very interesting, I've been wanting to do some mesh manipulation for a while but its been eluding me until now ;)


Prym(Posted 2014) [#6]
Thank you Charrua ,
I will explore these ideas and try to understand the architecture of " b3d ."
Hold the beginning of my address space game " http://prymprog.wikeo.net ." It is not very developed, but I little by little rule .