Blender and .b3d

BlitzMax Forums/MiniB3D Module/Blender and .b3d

Brucey(Posted 2007) [#1]
I'd like to use Blender but it doesn't have export to .b3d format (and I've googled for one too, which there isn't - sure there's one for some train-simulator .b3d file format, but that ain't the same).

And being on anything-but-Windows, I would need to either
1) export as some format and find a "some format" to .b3d converter
2) write a .b3d exporter.


So, what's the endianness of .b3d files ?


btw, if anyone has a little .b3d aircraft model I could play with while testing my Flight Dynamics module with MiniB3D, it would be a great help.

:-)


deps(Posted 2007) [#2]
I remember searching for this too. Didn't find anything so I wrote my own. It didn't support textures and I think it disappeared last time I did some spring cleaning on my hard drives. Maybe a blender plugin could be the next community project?


Brucey(Posted 2007) [#3]
I was thinking it can't be too hard... just slap some Python together in the right way... and ta da!


bradford6(Posted 2007) [#4]
http://www.blitzbasic.com/sdkspecs/sdkspecs/b3dfile_specs.txt

Blitz3D files are stored little endian (intel) style.

blitz example
http://www.blitzbasic.com/sdkspecs/sdkspecs/b3dfile_utils.zip

not exactly an airplane but you are free to use it:
http://www.blitzbasic.com/Community/posts.php?topic=66556


ima747(Posted 2007) [#5]
I'm curently using blender but if there was a straight exporter it would make life a LOT easier. Currently I build and UV texture in blender, export everything to a 3ds, open that with decorator, then just save it again since I've already textured it in blender. It's all free and works well enough for my needs, but it requires a PC even though blender is cross platform just because there's no way to make a b3d file on a mac that I can find... and it's anoying to have to use a program just to translate file formats. Blender has a b3d exporter but it's not Blitz3D format it something else with a b3d extension. I think there was a thread on this in the tools forum.


Brucey(Posted 2007) [#6]
Seems to be going well so far... Everything looks like it's going in the right places (as far as the file format is concerned)... but will find out when I'm at a stage of trying to load the default cube into MiniB3d ;-)

Just a couple of questions... and thanks to Mr bradford for the links, which are helping a lot.

1) I presume that a b3d Brush is similar to a Blender material.. except that Material has about a million attributes to it ?

2) Triangles (TRIS). Not entirely sure what I'm going to do here... A Mesh has Faces, which in turn has Vertices. According to the spec, the TRIS block lists the "ids" of the triangle parts. Do I just re-process the list of vertices and put here the "index" of the particular vertex?
I'm guessing that TriangleVertex returns something useful in the example code...

Having no prior b3d experience makes this an interesting wee project to say the least, but I'm always up for a new challenge. (that and I can't actually *use* Blender in any way yet... still to sit down with the beginners tutorial ;-)

If I can get the core stuff working, perhaps others might be interested in tweaking it to cover everything that we need.
As far as I'm concerned, blender support would be great, since it imports/exports a whole swathe of formats - and works on Linux, being my primary dev environment.

If anyone has any hints etc about things, or stuff I might be able to read up on, I'm all ears (and eyes).

:-)


ima747(Posted 2007) [#7]
Sory I don't have too much to offer in the way of help except for a pat on the back and a "good job!" It would really save me and a lot of people some headaches if you can get it working. Currently, to my knowledge, blender is the only free 3 os modeler and since blitz and mini b3d are also 3 os it's rather anoying that everyone still needs a wintel box to translate files. So keep up the good work and keep us posted, I'm dying to give it a try!

I'm still figuring out blender myself but I found the tutorials to be of not much use. I just poked around in all the menus and googled anything I wanted to do but couldn't find where they hid the function (stupid transform property's window took me 3 days to find). So feel free to send any questions you may have regarding using it my way and I'll try to help as best I can.


LineOf7s(Posted 2007) [#8]
I've nothing helpful to add Brucey, but I just wanted to say that if you manage this there'll be a not inconsiderable number of people looking to have your babies.


klepto2(Posted 2007) [#9]
I haven't used B3D abd espacially the B3D format before, but i think it is a very powerfull and extandable format. I have worked a lot with the B3D exporter the last days to find some bugs etc. If you need any some help, just mail me (if you want also the phyton script) .
I think the trick behind a blender to b3d exporter is the balance how to convert blender materials to b3d brushes.

As a second idea about the b3d exporter would be a small extension interface where you maybe set the export for Shaders or Physic data. Just an idea. But firstly we should build a stable frontend which could be improved later.


Difference(Posted 2007) [#10]
@Brucey: If you don't use Blitz3D this will not be of much use, but others (including myself) have had good use of this XML version of the b3d format when writing exporters and debugging the results: http://blitzbasic.com/codearcs/codearcs.php?code=665

It could of course also be used as an export format to be converted later, but with your track record I'm sure you can manage binary right away.

I've been meaning to port the functions to BlitzMax using libxml, but have not gotten around to it yet.


Brucey(Posted 2007) [#11]
Thanks for the help folks :-)

I ran the b3d example progs through the BB Project converter, and was surprised when they ran first time in Max. All these little tools help in their own way to shape the bigger picture.

Am I write in thinking that there are a set of Tris for each brush/texture used ?
And if I didn't happen to have any textures I'd have a list of Tris for the "default" brush only?


Brucey(Posted 2007) [#12]
Well, here we are... my first attempt :



...the default blender "cube" exported to .b3d, and spinning in BlitzMax via MiniB3D.

If I had realized that the faces of the cubes had 4 vertices to begin with, I'd probably be a bit further on by now...

What's next....


Brucey(Posted 2007) [#13]
Am reasonably happy with the mesh exporter now :



An A-10, imported into Blender as a .ac file, exported as .b3d.

It's getting there... (At least now that I'm exporting all the right bits in the right places.)
I guess the next task is to have a look at UVs... which is going to be fun, having never used them before.
In at the deep end... ;-)


Brucey(Posted 2007) [#14]
Am open to suggestions etc.


Brucey(Posted 2007) [#15]
Would someone mind throwing together a little example .blend / image using a UV please? Nothing fancy.
Perhaps one with a single image, and one that uses two images... should give me enough to work on.
Thanks ! (email addy is in my profile)

...otherwise I'll be slowed up having to learn the UV stuff in blender first ;-)


ardee(Posted 2007) [#16]
Give me an hour or so to wake-up and I'll create a couple of blends for you. Default cube with a single UV map for starters and then something a bit more complex with a couple of UV maps sound OK?


ardee(Posted 2007) [#17]
Here you go, a simple cube with correct seams, unwrapped and UV texture co-ords applied with test grid image.

cubeUVmapped.zip

I'll do something a bit more complex later on.

HTH


Brucey(Posted 2007) [#18]
Thanks ardee... helps a lot !

Almost working, other than Blender using bottom-left origin, and Max B3d using top-left origin... which I need to transform at some point... probably... matrix anyone? :-p


Brucey(Posted 2007) [#19]
Here we are then...

version 0.4 of the export script : b3d_export.py

Install it into your <blender dir>/.blender/scripts folder.

The biggest issue is the y origin problem for UVs...
I'm hoping someone with more experience of transformations will know what to do.
If you flip the y tex coords it works, but the image appears mirrored.

Other issues include support for only a single texture at the moment. Well, it stores them all ok, just only references the first one....

See what you think anyways...

I can see it's possible to add bone support to it - all the info is available for that in the blender docs.
So it has lots of potential, me thinks.

knock yourselves out...


ima747(Posted 2007) [#20]
Thanks Brucey! can't wait to give this a try later today, will post my results.


ksalomao(Posted 2007) [#21]
Very nice!


ima747(Posted 2007) [#22]
Seems to export geometry perfectly so far. Has an error when I try to export any of my existing textured models but I'm pretty sure they all use multiple textures... I'll play around a bit more and see where it starts complaining at me... fantastic work!


Brucey(Posted 2007) [#23]
Minor update (to 0.5) which fixes a couple of export errors.

Just exported a .ac version of an F16 with textures - as expected, the textures look pretty bad, but it tries...


Brucey(Posted 2007) [#24]
Question with regards vertices and tex coords.

I've gone the way of exporting *every* face vertex separately, regardless of the number of tex coords might be associated to the vertex.
This makes for many more vertices overall.

Originally, I had each vertex only once - which is great for non UV meshes - but with UVs there needs to be more than one of the same due to it having different tex coords.
I think, for non-UV meshes I'm going to put it back to that method, which will make for smaller b3d meshes.
eg.
a non UV cube has 8 vertices.
a UV cube has 24.

Unless I've mis-understood the spec ?

Given then that a particular vertex might only have one set of text coords, and another two... and another 4... I wonder how easy it would be to "optimize" the exported mesh ?

Anyone done any mesh optimizing before?


zzz(Posted 2007) [#25]
Hi, nice to see a blender exporter in the workings! Have to keep an eye on this.

For the uv stuff, if i remember correctly, the 3ds exporter dublicate vertices only where needed, so you might want to take a look on the guys who wrote that do it.


Brucey(Posted 2007) [#26]
Latest version 0.6 now supports multi-textures per mesh - probably... the code is there anyways ;-)

The UV cube test now creates 14 vertices, which looks about right. 8 shared + 6 unique tex coords.

Please let me know your mileage...


mongia2(Posted 2007) [#27]
thanks

i attend a plug or script

mongia


bruZard(Posted 2007) [#28]
BRUCEY ... BRUCEY !!!

i'm still waiting for a full featured Blender > B3D Exporter :D

excuse my bad english ... please ;)


ima747(Posted 2007) [#29]
I can't export any of my existing textured models. I get the following output in the blender console.

B3DExporter (v 0.6)
Exporting <C:\blablahblah file path>
++ Starting BB3D chunk .
++ Starting TEXS chunk.
Traceback (most recent call last):
File "<string>", line 569, in file_callback
File "<string>", line 77, in export
File "<string>", line 111, in makeFileChunk
File "<string>", line 164, in makeTexsChunk
ValueError: face has no texture values


some of my models will have a list of images used for textures after the ++ Starting TEXS chunk line, I think those are when I've packed the images.

It doesn't happen when I just make a new cube, texture it and export it, that works fine. I'm guessing from the ValueError message I have some un-textured faces on my other models and it doesn't know what to do if there are textures but not everything is textured....

trying to load the exported cube into minib3d doesn't show anything but it also doesn't crash minib3d...

Keep goin I'll keep testing whenever I get a chance.


Brucey(Posted 2007) [#30]
Thanks for trying...

I'll sort that out.


trying to load the exported cube into minib3d doesn't show anything

At all ?
That's a bit strange. I have cubes and planes loading fine. Maybe I'm doing something different?


skidracer(Posted 2007) [#31]
Brucey the other reason for duplicate vertices is for non smooth (hard / sharp) edges where the normals of the faces are not shared, a reference cube should ideally have flat lighting on each face with the edges looking nice and sharp (front face has vertices "facing forwards" top face has vertices "facing up" etc.).


ima747(Posted 2007) [#32]
yea an exported textured cube made and textured by me didn't give me any errors on export or on load in minib3d but nothing at all showed up... I haven't really experimented too much with it yet though so I don't know if maybe the cube is inside out or something... I'll try to troubleshoot it a bit more for you when I get a moment. I did get a cube that I pulled some vertexes around on to export without a texture on an earilier version of your script but I haven't tried that again... I've been wreslting with lightmaps and a pool liner (rl stuff is wierd, no?) so I haven't had a chance to look deeper yet.


bruZard(Posted 2007) [#33]
it doesnt work in blender2.44 :(

Console:

Traceback (most recent call last):
File "<string>", line 38, in <module>
ImportError: No module named string




bruZard(Posted 2007) [#34]
works now ... i've to install phyton2.5 ...


mongia2(Posted 2007) [#35]
# matrices for changing y to up and z to depth (Blender is opposite)
matrixBlender2B3d = Mathutils.Matrix([1,0,0,0], \
[0,0,1,0], \
[0,-1,0,0], \
[0,0,0,1])

matrixB3d2Blender = Mathutils.Matrix([1,0,0,0], \
[0,0,-1,0], \ change in 1 not -1
[0,1,0,0], \
[0,0,0,1])


error in -1

i use for blender a script:

http://rafb.net/p/oZ9qa939.html

see this code for your exporter!