Exporting multiple meshes into 1 .b3d model

Blitz3D Forums/Blitz3D Programming/Exporting multiple meshes into 1 .b3d model

Chroma(Posted 2006) [#1]
Hi...anyone have any advice on the proper way to save multiple meshes into one .b3d file and have accessible when loaded with the LoadAnimMesh command? I'm think you have to give them unique names and probably parent them to a single pivot. Any help is appreciated.


jfk EO-11110(Posted 2006) [#2]
I think you need to use nested nodes to define the hierarchy.

An other solution would be to use AddMesh to collapse multiple surfaces in one mesh, then use the SaveB3D source from the archives. The source also explains how to identify certain loaded surfaces by their textures without to use LoadAnimMesh.


Bobysait(Posted 2006) [#3]
b3d pipeline system's like may be a good solution.

All parented to a Node named "Scene Root"

then accessing them in Blitz3D will esay as
Mesh =loadanimmesh("your b3d file.b3d")
nc=CountChildren (Mesh)
for ch=1 to nc
child=getchild(Mesh,nc)
;=> Get the child name
name$=entityname(child)
; => do what you want with the child
select Name
case "Hero"
p.player= new player
p\model = child
... etc...
end select
endif

i often use this system, using Taged name as "BON_Pelvis" , "MSH_hero", "MSH_Door", "STC_Tree01", etc...

When i ripp the content of the AnimMesh, I simply use
Tag$=left(entityname(Child),3)
then i use the tag to know what to do with the entity.
=> if tag="MSH" => i store in an array => The entity is dynamic and will be checked in the optimisation loop of the level
=> if tag="STC" => static object, it will be locked on the level, and i only need to use a sphere detection for the collision
=> if tag="BON" => It is a bone...
etc...

But one question...
=> you want to save a scene from Blitz3D ? or just save a scene from a modeling soft ?


Ross C(Posted 2006) [#4]
Jfk is right. When saving, using code, you need to set a nested node for each mesh. I'm not sure exactly how it goes, as details are sketchy. Thing that annoys me a little is, alot of people have done .b3d exporters, but they are never around to answer any of these questions :o)


Chroma(Posted 2006) [#5]
Well basically I'm gonna use it to save my entire level as one .b3d file. But I just need to know how to store each model so it can be accessed when I reload the level with LoadAnimMesh.


jfk EO-11110(Posted 2006) [#6]
I have to agree. A clear documentation of the format including nested nodes, as well as animation, right on the Specs Page would be nice. Although some people who are selling advanced B3D tools maybe don't like it when everybody comes up with their own B3D tools, I guess it will help the format a lot.

There was a user named Andrea who released an animation tool including the sources, but the download was removed. I also have some animation saving sources, but they were given to my privately and I'm not allowed to publish them (I think).

Then there was this B3Ddocs.zip that has also vanished mysteriously.

Well nesting nodes shouldn't be that hard. Simply nest them :o). I think the hierarchy will then be built automaticly. This doesn't contain animation data, so altough you may load it using LoadAnimMesh, it will still give you a "No Animation" error when you try to "Animate" it.

EDIT:
I just see, Andrea doesn't offer the source in the download right now, but you may send him a (nice) Email and ask for the source. See comment and mail adress here: http://www.blitzbasic.com/codearcs/codearcs.php?code=866

I take it it's "him". Andrea is a name for both men and women, but since there are only a few female Blitz coders I assume it's "him". (If it isn't then please excuse me :) )


kevin8084(Posted 2006) [#7]
defoc8 has/had the B3Ddocs.zip file


jfk EO-11110(Posted 2006) [#8]
Unfortunately: HAD.


kevin8084(Posted 2006) [#9]
Beaker also said that he had docs (checked back in the forum)


Ross C(Posted 2006) [#10]
I will try and dig out my nesting code. I managed to save 3 meshes in the one .b3d file. Need to gimme about 30 mins to find it though :o)


Iamhere(Posted 2006) [#11]
I updated the download now, and it includes now the source.

@jfk EO-11110
"She" is right, but no problem.


Ross C(Posted 2006) [#12]
Well, i dunno if this helps now. I'll mess about to get it working later, but it works something like so:

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!" )
			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



kevin8084(Posted 2006) [#13]
@Ross C - did you mean to make the second NODE a child of the first? Is it possible to have two or more different entities (not parents...not children) if you end the first NODE chunk with b3dEndChunk() and then start another b3dBeginChunk("NODE")? They will still be nested within the main BB3D chunk, yes?


Ricky Smith(Posted 2006) [#14]
@jfk - That code is really based on the b3d2Xml code by Peter Scheutz which shows clearly how to load and save animated models and has been around for years so I never bothered to upload my version.
However, I've done so now if it will help anyone ;)
http://www.blitzbasic.com/codearcs/codearcs.php?code=1794

To create a .b3d file containing more than one model/mesh you would create a new root node above the first model/meshes's root and then parent any additionl mesh root nodes to this new Root. All meshes are then siblings that can be accessed individually.


jfk EO-11110(Posted 2006) [#15]
Andrea - thanks a lot! Sorry for the misunderstanding.

Ross - wouldn't it be better to use a meshless top node, a simple pivot? That's also my question, how do I make a pivot node? would it simply look like this:

	b3dBeginChunk( "NODE" )
			b3dWriteString( "top_node" )
				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
				b3dBeginChunk( "NODE" )
					b3dWriteString( "first_gen" )
					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



Would this "top_node" be the top pivot? What happens when the first node is a
mesh? In Blitz there's always a pivot at the top, isn't it?
And is a node automaticly a pivot when there's no mesh data?


Well now we really are able to
A: Read Andreas Source
B: As suggested by Smiff use the B3D to XML source to make exported B3D (eg. by Pacemaker :) ) human readable.
C: Use Smiffs code from the archives.

All of a sudden we have multiple choices WOW!

Thanks a lot everybody!