Blender to blitz3d.

Im working on a exporter for blitz 3d heavily based on the CAL3d exporter already available, once done the exporter will be able to export a model with bones in b3d format, right now Im working in just exporting a mesh with uv coordinates.

This is my first blender exporter Though (Dont worry I have plenty of coding experience just not in python ) so I will need all the help I can get. So I will be around asking newbie exporter questions. I hope you find the exporter helpful though.

Wish me luck!

Much good luck ! :slight_smile:

Go for it :slight_smile:

many Blitz3d users will love it…though most are not over here, I’m afraid…

Thanks! yes Im aware of that so Im also posting on blitzcoder so they know this new exporter will exist. :wink:

Now first newbie question, in b3d I have to export each “chunk” (vert list, material list, etc) and its size, how can I get the size in bytes of an struct or a class in python?

Ok I think Ive solved that by myself. thanks anyway

Now what I really must do. Is how can I create an stack in python (or an array at least) what I need to do is to store a number and then pop it out in fifo fashion.

Hmm… ok this is not working, Im not going to ask anything else in this thread , I will just post any progress in the plugin. Please dont answer anymore questions here, I will create threads for each important question. just ask about the plugin itself. thanks ! :wink:

Ok heres the code for the b3d script,
however I cant get this to load in a b3d viewer

I am (I think) using the specs listed here:
http://www.blitzbasic.com/sdkspecs/sdkspecs/b3dfile_specs.txt

but still no dice

Could someone lend a hand?:

#!BPY
"""
Name: 'B3D Exporter by German Cons'
Blender: 234
Group: 'Export'
Tip: 'Export mesh to the B3D format.'
"""

####[ Consts ]####

TRUE=1
FALSE=0

####[ Imports ]####

import sys, os, os.path, struct, math, string
import Blender
from Blender.BGL import *
from Blender.Draw import *
from Blender.Armature import *
from Blender.Registry import *


# HACK -- it seems that some Blender versions don't define sys.argv,
# which may crash Python if a warning occurs.
if not hasattr(sys, "argv"): sys.argv = ["???"]

# Export this very polygon, and all related information!
def b3dWriteVertex(f,ObjData,Face,v1):
  Vert1=Face.v[v1].index       # Face vertex reference information...
  Coord1=ObjData.verts[Vert1].co     # Coord information of this vertex
  Normal1=ObjData.verts[Vert1].no    # Normal information
  UV1=[0,1]  #,[1,0],[1,1]	# Default values for uv info
  UV1=Face.uv[v1]			# Grab the uv coords!
  #Coord information...X,Y,Z
  b3dWriteFloat(f,Coord1[0])  #X,Y,Z coords (reletive to the center)..
  b3dWriteFloat(f,Coord1[1])
  b3dWriteFloat(f,Coord1[2])
  b3dWriteFloat(f,Normal1[0])  #X,Y,Z normal
  b3dWriteFloat(f,Normal1[1])
  b3dWriteFloat(f,Normal1[2])
  #no colors for now
  b3dWriteFloat(f,UV1[0])    #U
  b3dWriteFloat(f,UV1[1])    #V

def b3dWriteVerts(f,obj):
    if obj:
       iPolyCount=0
       b3dBeginChunk(f,'VRTS')
       b3dWriteInt(f,1) #Flags 1 normal values present 2 rgba values present
       b3dWriteInt(f,1) #uv
       b3dWriteInt(f,2) #uv sets?

       ObjData=obj.getData()
       if ObjData:
           for face in ObjData.faces:
               iPolyCount=iPolyCount+1

               for v in range(0,2):
                   b3dWriteVertex(f,ObjData,face,v)
       print iPolyCount
       #x,y,z
       #nx,ny,nz
       #r,g,b,a ;not available at the time
       #u,v
       b3dEndChunk(f)
       return iPolyCount

def b3dWriteTris(f,obj,PolyCount):
    if obj:
       b3dBeginChunk(f,'TRIS')
       b3dWriteInt(f,-1) #no brush
       #since we dont have sharing indices we just write down the whole polygon count
       print PolyCount
       for c in range(0,PolyCount):
           b3dWriteInt(f,3*c)
           b3dWriteInt(f,3*c+1)
           b3dWriteInt(f,3*c+2)
       b3dEndChunk(f)


def b3dWriteMesh(f,obj):
    if obj:
       b3dBeginChunk(f,'MESH')
       b3dWriteInt(f,-1) #no brush, sorry not at the time
       PolyCount=b3dWriteVerts(f,obj)
       b3dWriteTris(f,obj,PolyCount)
       b3dEndChunk(f)

# This will loop through the mesh and export all the polygons (3 vert and 4 verts)
def ExportObject(f,obj):
  if obj:
    b3dBeginChunk(f,'NODE')
    #f.write(obj.name+chr(0))    # Save the name of this mesh first!
    b3dWriteString(f,obj.name) #name
    b3dWriteVector(f,0,0,0)  #position
    b3dWriteVector(f,1,1,1)  #escala (this will change in the future)
    b3dWriteQuaternion(f,1,0,0,0)  #rotation
    b3dWriteMesh(f,obj)
    b3dEndChunk(f)

#b3d_tos = 0  (deprecated)
b3d_stack = [0]

#new functions for b3d
def b3dWriteByte(f,dat):
    f.write(struct.pack('b',dat))

def b3dWriteFloat(f,dat):
    f.write(struct.pack('f',dat))

def b3dWriteInt(f,dat):
    f.write(struct.pack('i',dat))

def b3dWriteString(f,dat):
    l=len(dat)
    for c in range(0,l):
        f.write(struct.pack('1s',dat[c]))
    f.write(struct.pack('b',0))

def b3dWriteVector(f,datx,daty,datz):
    b3dWriteFloat(f,datx)
    b3dWriteFloat(f,daty)
    b3dWriteFloat(f,datz)

def b3dWriteQuaternion(f,datw,datx,daty,datz):
    b3dWriteFloat(f,datw)
    b3dWriteFloat(f,datx)
    b3dWriteFloat(f,daty)
    b3dWriteFloat(f,datz)

def b3dBeginChunk(f,tag):
    #b3d_tos=b3d_tos+1
    b3dWriteString(f,tag)
    b3dWriteInt(f,0)
    #b3d_stack[b3d_tos]=OutputFile.tell()
    b3d_stack.append(f.tell())
    #b3d_stack.append(OutputFile.tell())

def b3dEndChunk(f):
    n=f.tell()
    p=b3d_stack.pop()
    f.seek(p-4)
    #SeekFile b3d_file,b3d_stack(b3d_tos)-4
    b3dWriteInt(f,n-p)
    f.seek(n)
    #SeekFile b3d_file,n
    #b3d_tos=b3d_tos-1 #decrease reference


####[ Main program ]####

def fs_callback(filename):
  print ""
  print filename
  print "Exporting begins."
  #If the user has selected a object to work on...
  if Blender.Object.GetSelected()[0]:
     OutputFile=open(filename,'w+b')
     if OutputFile:
        b3dBeginChunk(OutputFile,'BB3D')
        b3dWriteInt(OutputFile,100) #version
        #export selected object
        ExportObject(OutputFile,Blender.Object.GetSelected()[0])
        b3dEndChunk(OutputFile)
        OutputFile.close()
     else:
        print "Couldn't export file"
  print "Exporter ended."


# Main script

#global OutputFile                 # File pointer to the above file while saving

defaultname = Blender.Get('filename')

if defaultname.endswith(".blend"):
   defaultname = defaultname[0:len(defaultname)-len(".blend")] + ".b3d"

Blender.Window.FileSelector(fs_callback, "B3D Export", defaultname)

I’ve been looking at the resulting bb3d file and I’ve noticed the headers appear to be more than 8 bytes; like there is a null 00 in there somewhere.
I used XVI32 to analyse the file structure.

Normal b3d file

42 42 33 44 a5 7f 00 00 01 00 00 00 B B 3 D * * * *

Current Blend to B3d export

42 42 33 44 xx xx 00 01 00 00 00 00 B B 3 D * * * *

The version type is off kilter I think. I tried to modify the code to compensate for this, but I don’t know enough really. Regardless, I hope this offers a clue to fixing the exporter.

Have you looked at this exporter?

http://www.blitzbasic.com/Community/posts.php?topic=17050

It’s not quite the same as it doesn’t export directly to bb3d, but again it might offer clues about how to do it in your exporter.

:smiley:

Ps) Im Shagwana

I was thinking of exporting a .bb file to use in cojunction with B3dfile.bb, I figured you get it to export a .bb file that eventually turns itsself into a .b3d file. Here’s my code, heavily based on the Makeb3d.bb file. It doesn’t create a fully independant program that will result in exporting a .b3d file, but it’s a start.

I think it only exports a mesh.


#!BPY

"""
Name: 'B3D...'
Blender: 233
Group: 'Export'
Tooltip: 'Export selected mesh to Blitz Basic 3d SCRIPT format (*.bb)'
"""

# +---------------------------------------------------------+
# | Copyright (c) 2004 Wiremu Te Kani				|
# | 									      |
# |				   					      |
# |            		       		                  |
# | Released under the Blender Artistic Licence (BAL)       |
# | Import Export Suite v0.1                                |
# +---------------------------------------------------------+
# | Read and write Blitz Basic 3d SCRIPT format (*.bb)   	|
# +---------------------------------------------------------+

import Blender
#import time
import mod_flags, mod_meshtools

# ==============================
# ====== Write B3dS Format ======
# ==============================
def write(filename):
	#start = time.clock()
	file = open(filename, "w")

	objects = Blender.Object.GetSelected()
	objname = objects[0].name
	meshname = objects[0].data.name
	mesh = Blender.NMesh.GetRaw(meshname)
	#mesh = Blender.NMesh.GetRawFromObject(meshname)	# for SubSurf
	obj = Blender.Object.Get(objname)

	# === BB3d Header ===
	file.write("Function WriteBB3D( f_name$,mesh )

")
	file.write("	file=WriteFile( f_name$ )

")
	file.write("	b3dSetFile( file )

")
	file.write("	b3dBeginChunk( \"BB3D\" )
")
	file.write("		b3dWriteInt( 1 )	;version

")
	file.write("		b3dBeginChunk( \"BRUS\" )
")
	file.write("			b3dWriteInt( 0 )					;0 textures per brush
")
	file.write("			b3dWriteString( \"Shiny Red\" )		;name
")
	file.write("			b3dWriteFloat( 1 )					;red
")
	file.write("			b3dWriteFloat( 0 )					;green
")
	file.write("			b3dWriteFloat( 0 )					;blue
")
	file.write("			b3dWriteFloat( .40 )					;alpha
")
	file.write("			b3dWriteFloat( 1)				;shininess
")
	file.write("			b3dWriteInt( 1 )					;blend
")
	file.write("			b3dWriteInt( 0 )					;FX
")
	file.write("		b3dEndChunk()	;end of BRUS chunk

")
	file.write("		b3dBeginChunk( \"NODE\" )
")
	file.write("			b3dWriteString( \"entity_name_here!\" )
")
	file.write("			b3dWriteFloat( 0 )	;x_pos
")
	file.write("			b3dWriteFloat( 0 )	;y_pos
")
	file.write("			b3dWriteFloat( 0 )	;y_pos
")
	file.write("			b3dWriteFloat( 1 )	;x_scale
")
	file.write("			b3dWriteFloat( 1 )	;y_scale
")
	file.write("			b3dWriteFloat( 1 )	;z_scale
")
	file.write("			b3dWriteFloat( 1 )	;rot_w
")
	file.write("			b3dWriteFloat( 0 )	;rot_x
")
	file.write("			b3dWriteFloat( 0 )	;rot_y
")
	file.write("			b3dWriteFloat( 0 )	;rot_z
")
	file.write("			WriteMESH( mesh )
")
	file.write("		b3dEndChunk()	;end of NODE chunk

")
	file.write("	b3dEndChunk()	;end of BB3D chunk

")
	file.write("	CloseFile file
")
	file.write("End Function


")
	file.write("Function WriteMESH( mesh )
")


	file.write("	n_surfs=CountSurfaces( mesh ) 
")
	
	file.write("	b3dBeginChunk( \"MESH\" )
")
	file.write("		b3dWriteInt( -1 )				;no 'entity' brush
")
		
	file.write("		b3dBeginChunk( \"VRTS\" )
")
	file.write("			b3dWriteInt( 0 )			;flags - 0=no normal/color
")
	file.write("			b3dWriteInt( 0 )			;0 tex_coord sets
")
	file.write("			b3dWriteInt( 0 )			;0 coords per set
")
			
	# === Vertex List ===
	for i in range(len(mesh.verts)):
			if not i%100 and mod_flags.show_progress:
				Blender.Window.DrawProgressBar(float(i)/len(mesh.verts), "Writing Verts")
			x, y, z = mesh.verts[i].co
			file.write("					b3dWriteFloat( %f ) : b3dWriteFloat( %f ) : b3dWriteFloat( %f )
" % (x, y, z))

	file.write("		b3dEndChunk()	;end of VRTS chunk
")
	file.write("			b3dBeginChunk( \"TRIS\" )
")
	file.write("				b3dWriteInt( 0 )		;brush for these triangles
")

	# === Face List ===
	for i in range(len(mesh.faces)):
			if not i%100 and mod_flags.show_progress:
				Blender.Window.DrawProgressBar(float(i)/len(mesh.faces), "Writing Faces")
			mesh.faces[i].v.reverse()
			for j in range(len(mesh.faces[i].v)):
				file.write("			b3dWriteInt( ")
				file.write(`mesh.faces[i].v[j].index`+' ) : ')
			file.write("
")


	Blender.Window.DrawProgressBar(1.0, '')  # clear progressbar
	file.close()
	#end = time.clock()
	#seconds = " in %.2f %s" % (end-start, "seconds")
	message = "Successfully exported " + Blender.sys.basename(filename)# + seconds
	mod_meshtools.print_boxed(message)

def fs_callback(filename):
	if filename.find('.bb', -4) <= 0: filename += '.bb'
	write(filename)

Blender.Window.FileSelector(fs_callback, "BB3d Script Export")

Oh ! hi Shagwana, well now that I think about it thats not a bad idea. I just thought It would be possible to create a b3d file considering we have the format specs and all. but yes, there are some intrincancies that I havent been able to figure out ( like the header you mentioned.)

perhaps it would be better to create an intermediate file that could then be transformed into b3d by b3d itself (after all I think is possible to create bones and all in realtime isnt?) also I think python CAN somehow execute an exe so we could (theorically at least) do this.

->Create the intermediate file.
->Run a b3d program to load and interpret the immediate file
->close the helper program
->Save the final b3d file.

Now all is missing would be to find out if this is possible.

It’s Billamu, actually.

Have you got the bb3d.bb files? I assumed you did becasue the python code kinda looked like the b3dfile.bb code. Anyway here’s the Blitzbaseic code…

This is b3dfile.bb



;
;b3d file utils to be included
;

Dim b3d_stack(100)
Global b3d_file,b3d_tos

Function b3dSetFile( file )
	b3d_tos=0
	b3d_file=file
End Function

;***** functions for reading from B3D files *****

Function b3dReadByte()
	Return ReadByte( b3d_file )
End Function

Function b3dReadInt()
	Return ReadInt( b3d_file )
End Function

Function b3dReadFloat#()
	Return ReadFloat( b3d_file )
End Function

Function b3dReadString$()
	Repeat
		ch=b3dReadByte()
		If ch=0 Return t$
		t$=t$+Chr$(ch)
	Forever
End Function

Function b3dReadChunk$()
	For k=1 To 4
		tag$=tag$+Chr$(b3dReadByte())
	Next
	sz=ReadInt( b3d_file )
	b3d_tos=b3d_tos+1
	b3d_stack(b3d_tos)=FilePos( b3d_file )+sz
	Return tag$
End Function

Function b3dExitChunk()
	SeekFile b3d_file,b3d_stack(b3d_tos)
	b3d_tos=b3d_tos-1
End Function

Function b3dChunkSize()
	Return b3d_stack(b3d_tos)-FilePos( b3d_file )
End Function

;***** Functions for writing to B3D files *****

Function b3dWriteByte( n )
	WriteByte( b3d_file,n )
End Function

Function b3dWriteInt( n )
	WriteInt( b3d_file,n )
End Function

Function b3dWriteFloat( n# )
	WriteFloat( b3d_file,n )
End Function

Function b3dWriteString( t$ )
	For k=1 To Len( t$ )
		ch=Asc(Mid$(t$,k,1))
		b3dWriteByte(ch)
		If ch=0 Return
	Next
	b3dWriteByte( 0 )
End Function

Function b3dBeginChunk( tag$ )
	b3d_tos=b3d_tos+1
	For k=1 To 4
		b3dWriteByte(Asc(Mid$( tag$,k,1 )))
	Next
	b3dWriteInt( 0 )
	b3d_stack(b3d_tos)=FilePos( b3d_file )
End Function

Function b3dEndChunk()
	n=FilePos( b3d_file )
	SeekFile b3d_file,b3d_stack(b3d_tos)-4
	b3dWriteInt( n-b3d_stack(b3d_tos) )
	SeekFile b3d_file,n
	b3d_tos=b3d_tos-1
End Function

this is makeb3d.bb . It makes a red sphere, saves it as a .b3d file, then opens and displays the .b3d file.


;
;simple demo which creates a mesh, writes it to a b3d file,
;then loads it back in and displays it.
;
Include "b3dfile.bb"

Graphics3D 640,480

mesh=CreateSphere( 32 )

WriteBB3D( "temp.b3d",mesh )

FreeEntity mesh

mesh=LoadMesh( "temp.b3d" )

camera=CreateCamera()
PositionEntity camera,0,0,-3

light=CreateLight()
TurnEntity light,45,45,0

While Not KeyHit(1)
	UpdateWorld
	RenderWorld
	Flip
Wend

End

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( .40 )					;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 )
		b3dEndChunk()	;end of NODE chunk
		
	b3dEndChunk()	;end of BB3D chunk
	
	CloseFile file
End Function

Function WriteMESH( mesh )

	n_surfs=CountSurfaces( mesh )
	
	b3dBeginChunk( "MESH" )
		b3dWriteInt( -1 )				;no 'entity' brush
		
		b3dBeginChunk( "VRTS" )
			b3dWriteInt( 0 )			;flags - 0=no normal/color
			b3dWriteInt( 0 )			;0 tex_coord sets
			b3dWriteInt( 0 )			;0 coords per set
			
			For k=1 To n_surfs
				surf=GetSurface( mesh,k )
				n_verts=CountVertices( surf )-1
				
				For j=0 To n_verts
					b3dWriteFloat( VertexX( surf,j ) )
					b3dWriteFloat( VertexY( surf,j ) )
					b3dWriteFloat( VertexZ( surf,j ) )
				Next
			Next
		b3dEndChunk()	;end of VRTS chunk
		
		first_vert=0
		For k=1 To n_surfs
			surf=GetSurface( mesh,k )
			n_tris=CountTriangles( surf )-1
			
			b3dBeginChunk( "TRIS" )
				b3dWriteInt( 0 )		;brush for these triangles
				
				For j=0 To n_tris
					b3dWriteInt( first_vert+TriangleVertex( surf,j,0 ) )
					b3dWriteInt( first_vert+TriangleVertex( surf,j,1 ) )
					b3dWriteInt( first_vert+TriangleVertex( surf,j,2 ) )
				Next
				
			b3dEndChunk()	;end of TRIS chunk
			
			first_vert=first_vert+CountVertices( surf )
			
		Next
		
	b3dEndChunk()	;end of MESH chunk
	
End Function

And this is dumpb3d.bb . This tells you whether the file is gonna work or not.



;
;little demo to dump the contents of a B3D file
;

Include "b3dfile.bb"

f_name$=Input$( "B3D file to dump:" )

file=ReadFile( f_name$ )
If Not file RuntimeError "Unable to open b3d file"

b3dSetFile( file )

If b3dReadChunk$()<>"BB3D" RuntimeError "Invalid b3d file"

If b3dReadInt()/100>0 RuntimeError "Invalid b3d file version"

Print "Dumping file to debug log..."

DebugLog "File opened..."

DumpChunks()

b3dExitChunk()

CloseFile file

WaitKey

End

Function DumpChunks( tab$="" )
	tt$=tab$
	tab$=tab$+"  "
	While b3dChunkSize()
		chunk$=b3dReadChunk$()
		DebugLog tt$+"Chunk:"+chunk$+" (size="+b3dChunkSize()+")"
		Select chunk$
		Case "ANIM"
			flags=b3dReadInt()
			n_frames=b3dReadInt()
			fps=b3dReadFloat()
			DebugLog tab$+flags+" "+n_frames+" "+fps
		Case "KEYS"
			flags=b3dReadInt()
			sz=4
			If flags And 1 sz=sz+12
			If flags And 2 sz=sz+12
			If flags And 4 sz=sz+16
			n_keys=b3dChunkSize()/sz
			If n_keys*sz=b3dChunkSize() 
				DebugLog tab$+n_keys+" keys"
				;read all keys in chunk
				While b3dChunkSize()
					frame=b3dReadInt()
					If flags And 1
						key_px#=b3dReadFloat()
						key_py#=b3dReadFloat()
						key_pz#=b3dReadFloat()
					EndIf
					If flags And 2
						key_sx#=b3dReadFloat()
						key_sy#=b3dReadFloat()
						key_sz#=b3dReadFloat()
					EndIf
					If flags And 4
						key_rw#=b3dReadFloat()
						key_rx#=b3dReadFloat()
						key_ry#=b3dReadFloat()
						key_rz#=b3dReadFloat()
					EndIf
				Wend
			Else
				DebugLog tab$+"***** Illegal number of keys *****"
			EndIf
		Case "TEXS"
			While b3dChunkSize()
				name$=b3dReadString$()
				flags=b3dReadInt()
				blend=b3dReadInt()
				x_pos#=b3dReadFloat()
				y_pos#=b3dReadFloat()
				x_scl#=b3dReadFloat()
				y_scl#=b3dReadFloat()
				rot#=b3dReadFloat()
				DebugLog tab$+name$
			Wend
		Case "BRUS"
			n_texs=b3dReadInt()
			;read all brushes in chunk...
			While b3dChunkSize()
				name$=b3dReadString$()
				red#=b3dReadFloat()
				grn#=b3dReadFloat()
				blu#=b3dReadFloat()
				alp#=b3dReadFloat()
				shi#=b3dReadFloat()
				blend=b3dReadInt()
				fx=b3dReadInt()
				For k=0 To n_texs-1
					tex_id=b3dReadInt()
				Next
				DebugLog tab$+name$
			Wend
		Case "VRTS"
			flags=b3dReadInt()
			tc_sets=b3dReadInt()
			tc_size=b3dReadInt()
			sz=12+tc_sets*tc_size*4
			If flags And 1 Then sz=sz+12
			If flags And 2 Then sz=sz+16
			n_verts=b3dChunkSize()/sz
			If n_verts*sz=b3dChunkSize() 
				DebugLog tab$+n_verts+" vertices"
				;read all verts in chunk
				While b3dChunkSize()
					x#=b3dReadFloat()
					y#=b3dReadFloat()
					z#=b3dReadFloat()
					If flags And 1
						nx#=b3dReadFloat()
						ny#=b3dReadFloat()
						nz#=b3dReadFloat()
					EndIf
					If flags And 2
						red#=b3dReadFloat()
						grn#=b3dReadFloat()
						blu#=b3dReadFloat()
						lfa#=b3dReadFloat()
					EndIf
					;read tex coords...
					For j=1 To tc_sets*tc_size
						b3dReadFloat()
					Next
				Wend
			Else
				DebugLog tab$+"***** Illegal number of vertices *****"
			EndIf
		Case "TRIS"
			brush_id=b3dReadInt()
			sz=12
			n_tris=b3dChunkSize()/sz
			If n_tris*sz=b3dChunkSize()
				DebugLog tab$+n_tris+" triangles"
				;read all tris in chunk
				While b3dChunkSize()
					v0=b3dReadInt()
					v1=b3dReadInt()
					v2=b3dReadInt()
				Wend
			Else
				DebugLog tab$+"***** Illegal number of triangles *****"
			EndIf
		Case "MESH"
			brush_id=b3dReadInt()
			DebugLog tab$+"brush="+brush_id
		Case "BONE"
			sz=8
			n_weights=b3dChunkSize()/sz
			If n_weights*sz=b3dChunkSize()
				DebugLog tab$+n_weights+" weights"
				;read all weights
				While b3dChunkSize()
					vertex_id=b3dReadInt()
					weight#=b3dReadFloat()
				Wend
			Else
				DebugLog tab$+"***** Illegal number of bone weights *****"
			EndIf
		Case "NODE"
			name$=b3dReadString$()
			x_pos#=b3dReadFloat()
			y_pos#=b3dReadFloat()
			z_pos#=b3dReadFloat()
			x_scl#=b3dReadFloat()
			y_scl#=b3dReadFloat()
			z_scl#=b3dReadFloat()
			w_rot#=b3dReadFloat()
			x_rot#=b3dReadFloat()
			y_rot#=b3dReadFloat()
			z_rot#=b3dReadFloat()
			DebugLog tab$+"name="+name$
		End Select

		DumpChunks( tab$ )	;dump any subchunks
		b3dExitChunk()		;exit this chunk
		
	Wend
End Function

Hope this helps

Billamu

Yes I have seen the python script and I heavily based the exporter on it (im not that experienced in python after all) but I havent seen the dump b3d part. That could be really useful.

The problem with it is that it doesnt support bones which is the true advantage of the b3d format (after all a non animated mesh can be exported in an x format and skeletal animation in 3ds-) do you know any code to save a b3d file from blitz with bones?

Thanks! Sorry about getting your name wrong.

Maybe I’m wrong, but doesn’t the code support bones? I saw the word BONES in the .bb file.

As far as how you implement it, that’s another story. I’ve read through the text document on the b3d format and it’s ‘consise’ to say the least.

Looks like another mindless search through the forums back at Blitzbasic.com

And I wasn’t aware you could export the animation to 3ds; why not do that instead? I have tried using Bob Holcolm’s md2 exporter, but I don’t like the ‘lumpy vertices’ thing it does when it animates. It also has issues with the normals (I think)

Billamu