writing 2 b3d

Blitz3D Forums/Blitz3D Programming/writing 2 b3d

D4NM4N(Posted 2005) [#1]
using the save to b3d code,im trying to save all the children in my mesh 2 b3d.

when i add the section in the ####s below it reloads my mesh oh but causes an 'entity does not exist' error on an END statement, and then blitzcc crashes with a runtime error - abnormal prog termination! however, it works when debug is off

it works without it though for just the parent.

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( EntityName(mesh) )		;name
			b3dWriteFloat( 0 )					;red
			b3dWriteFloat( 0 )					;green
			b3dWriteFloat( 0 )					;blue
			b3dWriteFloat( 1 )					;alpha
			b3dWriteFloat( 0)				;shininess
			b3dWriteInt( 1 )					;blend
			b3dWriteInt( 32+2 )					;FX
		b3dEndChunk()	;end of BRUS chunk

		b3dBeginChunk( "NODE" )
			b3dWriteString( EntityName(mesh) )
			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 )
		b3dEndChunk()	;end of NODE chunk
		;####################################
		For a=1 To CountChildren(mesh)
			b3dBeginChunk( "NODE" )
				chi=GetChild(mesh,a)
				b3dWriteString( EntityName(chi) )
				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( chi )
			b3dEndChunk()	;end of NODE chunk
		Next
		;###################################

		
	b3dEndChunk()	;end of BB3D chunk
	
	CloseFile file
End Function



WolRon(Posted 2005) [#2]
Well, I don't know anything about saving B3D's but what if your mesh has no children at all?


Luke.H(Posted 2005) [#3]
Try putting the Children Nodes in the base Node?


jfk EO-11110(Posted 2005) [#4]
The problem may be: if you want to load a B3D, all "Children" become surfces unless you are using LoadAnimMesh. But if you are using LoadAnimMesh, then the top parent is not a mesh but a pivot. So saving a mesh with children meshes doesn't make much sense. You better save all meshes and their children under a main top level pivot, so you can load it with loadAnimMesh, or, the other way, you could AddMEsh all children together and then save this one Mesh with multiple surfaces (as seen in the SaveB3D evample in the archives). When using AddMesh, you have to make sure not to use PositionEntity, instead use PositionMesh. So maybe you have to store all entities xyz positions, move them to 0,0,0 then use PositionMEsh with the stored coords.

RifRaf should know this in detail, he used to write something that was capable of saving children.


D4NM4N(Posted 2005) [#5]
ahh,ok so if i use addmesh ie mesh1,mesh2 does mesh1 become a new surface of mesh2? and is this possible to addmesh to a pivot? (im not at my pc to try)


jfk EO-11110(Posted 2005) [#6]
Not sure about the pivot thing, I guess NO.

Adding meshes will leave the original unchanged, so you need to add all meshes to a new mesh, and after saving it simply delete it.
eg:
numesh=createmesh()
for i=0 to stuff
 dummy=copymesh(thing(i))
 positionentity dummy,0,0,0
 positionmesh dummy entityx(thingy(i)),entityy(thingy(i)),entityz(thingy(i)),1
; the same for rotation and scale, and use paintbrush etc. instead of entitytexture
 addmesh dummy, numesh
 freeentity dummy
next


have a look at the AddMesh Documentation. You need to prevent using Entitycommands, or store the values (eg. for Scaleentity) to be able to reuse them with Mesh-based commands.


D4NM4N(Posted 2005) [#7]
i have tried using addmesh but i loose all surface information. Is there a way of combining a mesh easily that retains vertex alpha and texture info. where each added mesh becomes a surface of the original?