Asset Compiler

Blitz3D Forums/Blitz3D Programming/Asset Compiler

Craig H. Nisbet(Posted 2004) [#1]
I'm making an asset compiler. Is there a way to dig into a b3d file to figure out what images it's using for textures?


Moses(Posted 2004) [#2]
sure read the .b3d specs at http://blitzbasic.com/sdkspecs/sdkspecs/b3dfile_specs.txt


Craig H. Nisbet(Posted 2004) [#3]
Is it a text or a binary file? I've really only worked with text files. Anyone have any simple code that can read data from, or write data to, a b3d file?


Todd(Posted 2004) [#4]
B3d files are binary, but open one up in Notepad, and you can see that all of the textures it uses are still just normal text. As for code to read and write b3d files, look in the Specs and Utils link up above, and there's some sample code for reading b3d files. If all you want to do though is extract file names from the b3d file, then you could try something like this:

Type B3dTexture
	Field FileName$
End Type

Function GetB3dTextures(B3dFile)
	While Not Eof(B3dFile)
		Byte=ReadByte(B3dFile)
		If Byte > 32
			NewName$=NewName$+Chr(Byte)	
		Else
			If NewName$ <> ""
				Tex.B3dTexture=New B3dTexture
				Tex\FileName$=Trim(NewName$)
			EndIf
		EndIf
	Wend
	For Tex.B3dTexture=Each B3dTexture
		If Len(Tex\FileName$)=1
			Delete Tex
		Else
			If Instr(Tex\FileName$,".")=False
				Delete Tex
			EndIf
		EndIf
	Next
End Function


The 'B3dFile' parameter should be an open file handle (using OpenFile() or ReadFile()). Once it's done, you should have a list of all the files in the B3d file. Just loop through the B3dTexture type to read all of them. Hope that's what you're looking for.


Craig H. Nisbet(Posted 2004) [#5]
I tried that, it seemed to loop for infinity. I did notice it was catching the textue names, which is what I want. Unfortunately, it doesn't seem to end it's loop.


Heres the code I tested with.


; LoadMesh Example
; ----------------

Graphics3D 640,480
SetBuffer BackBuffer()

camera=CreateCamera()

light=CreateLight()
RotateEntity light,90,0,0

; Load mesh
drum=LoadMesh("Objects\NarnFighterRT_Final.B3D")
GetB3dTextures("Objects\NarnFighterRT_Final.B3D")

PositionEntity drum,0,0,MeshDepth(drum)*2

While Not KeyDown( 1 )
RenderWorld
Flip
Wend

End

Type B3dTexture
Field FileName$
End Type

Function GetB3dTextures(B3dFilename$)
Stop
B3dFile= ReadFile(B3dFilename$)

While Not Eof(B3dFile)
Byte=ReadByte(B3dFile)
If Byte > 32
NewName$=NewName$+Chr(Byte)
Else
If NewName$ <> ""
Tex.B3dTexture=New B3dTexture
Tex\FileName$=Trim(NewName$)
DebugLog Newname
EndIf
EndIf
Wend
For Tex.B3dTexture=Each B3dTexture
If Len(Tex\FileName$)=1
Delete Tex
Else
If Instr(Tex\FileName$,".")=False
Delete Tex
EndIf
EndIf
Next
CloseFile B3DFile
End Function


Craig H. Nisbet(Posted 2004) [#6]
Sorry, ignore the stop commend, I forget to take that out before I posted.