3d model reading

Blitz3D Forums/Blitz3D Programming/3d model reading

David819(Posted 2004) [#1]
Hi i have been trying to quite a long time to make a game ripper but have not got far, i was given the advise to start by reading the .pcx file first and go from there but have not been able to do that, can anyone help me read file and suggest an easier file format to read. please reply soon.


big10p(Posted 2004) [#2]
What is a 'game ripper'?


Mustang(Posted 2004) [#3]
I think he means something like this (Dragon UnPACKer 5):

http://www.elberethzone.net/index.php?page=dup5&language=en#formats


David819(Posted 2004) [#4]
I mean like as Mustang said (Dragon UnPACKer 5) and biturn and unmass which allow you to remove game files from bigger pack files and read and convert them to a format which is usable by the programer, but can anyone help me get started with reading a really easy format like a black and white bmp picture or something please.


Gabriel(Posted 2004) [#5]
Look up the SaveTGA function in the code archives. It doesn't get much simpler than Targa.


David819(Posted 2004) [#6]
Sybixsus, thanks for the code, it might be useful later on when i am trying to rewrite the file formate but at present i'm mainly trying to read in file into blitz and go from there.


Gabriel(Posted 2004) [#7]
That was kinda the point. Convert the SaveTGA function into a LoadTGA function to give yourself practice of the most basic format around.


David819(Posted 2004) [#8]
I dont understand how to convert the savetga file so that it loads it, sorry but i aint that skill in the file area and need more information rather that all source code.


(tu) sinu(Posted 2004) [#9]
look at how the function saves the parts of the tga and in what order and then using that info try and do it for loading ie reading in headers etc then pixels/colors whatever etc.


David819(Posted 2004) [#10]
:(


David819(Posted 2004) [#11]
ok, i have made a start on reding the tga file but have got stuck, i'm currently reading the header of the file which the specs show as followed:
Size
byte - Id Length (offset=0)
byte - Color Map Type (ofset=1)
byte - Image type (offset=2)
5 bytes - Color Map Specification (offset=3)
10 bytes - Image Specification (offset=8)

I have read the 3 byte parts and am stuck at the last 2, how do you read bytes, and you please help me here is my code so far...

Graphics 640,480,32,2
SetBuffer BackBuffer()

filein=ReadFile("test.tga")
Idlength=ReadByte( Filein )
ColorMapType=ReadByte( Filein )
imagetype=ReadByte( Filein )


Color 255,255,255
Print Idlength
Print ColorMapType
Print Imagetype


WaitKey()


David819(Posted 2004) [#12]
Please help me please.


Odds On(Posted 2004) [#13]
Game pack files usually use custom formats and maybe even encryption to protect their data.. I'll save you some time and tell you to stop now. If you can't interpret those two bits of data on your own or by doing your own research into the tga format for example, then you don't stand a chance of extracting the data from game pack files.


David819(Posted 2004) [#14]
look, i have the specs i know of some file reading cause i have only just started and have asked how to read more than one byte i.e bytes, but i dont know what commands to use to do that, and i want to be able to read files not just game formats so when i get round to it i will be able to make my own. so can you please help me so i can stop bothering the community with this topic.


Odds On(Posted 2004) [#15]
To read more than one byte you simply call ReadByte() as many times as you need to. There are no data types in Blitz that are 5 or 10 bytes long. You can read 2 bytes at a time with ReadShort(), and 4 bytes at a time with ReadInt() or ReadFloat().


David819(Posted 2004) [#16]
ok thanks, I'll see where i can get with that.


David819(Posted 2004) [#17]
Ok, i have made progress and am now at the stage where i need to get the picture to display and dont know how to do so, can you please help me with this. My code goes as follows:
Graphics 640,480,32,2
SetBuffer BackBuffer()

filein=ReadFile("test2.tga")

;TGA File Header
Idlength=ReadByte( Filein )
ColorMapType=ReadByte( Filein )
imagetype=ReadByte( Filein )

;color map specifications
index=ReadShort( filein )
length=ReadShort( filein )
size=ReadByte( filein )

xorig=ReadShort( filein )
yorig=ReadShort( filein )
width=ReadShort( filein )
height=ReadShort( filein)
depth=ReadByte( filein )
attributes=ReadByte( filein )


Color 255,255,255
Print "ID Length: "+Idlength
Print "Color Map Type: "+ColorMapType
Print "Image Type: "+Imagetype

Print "Index: "+index
Print "Length: "+length
Print "Size: "+size
Print "XOrigin: "+xorig
Print "YOrigin: "+yorig
Print "Width: "+width
Print "Height: "+height
Print "Depth: "+depth
Print "attributes: "+attributes




WaitKey()


Odds On(Posted 2004) [#18]
Basically you need to create an image to the width and height that you read in from the file, then loop through and read the rgb value for each pixel.

Graphics 640,480,32,2 
SetBuffer BackBuffer() 

filein=ReadFile("test2.tga") 

;TGA File Header 
Idlength=ReadByte( Filein ) 
ColorMapType=ReadByte( Filein ) 
imagetype=ReadByte( Filein ) 

;color map specifications 
index=ReadShort( filein ) 
length=ReadShort( filein ) 
size=ReadByte( filein ) 

xorig=ReadShort( filein ) 
yorig=ReadShort( filein ) 
width=ReadShort( filein ) 
height=ReadShort( filein) 
depth=ReadByte( filein ) 
attributes=ReadByte( filein ) 

Color 255,255,255 
Print "ID Length: "+Idlength 
Print "Color Map Type: "+ColorMapType 
Print "Image Type: "+Imagetype 

Print "Index: "+index 
Print "Length: "+length 
Print "Size: "+size 
Print "XOrigin: "+xorig 
Print "YOrigin: "+yorig 
Print "Width: "+width 
Print "Height: "+height 
Print "Depth: "+depth 
Print "attributes: "+attributes 

image = CreateImage( width, height )
SetBuffer ImageBuffer( image )
LockBuffer

For Y = height - 1 To 0 Step -1
	For X = width - 1 To 0 Step -1
		rgb = ReadInt( filein ) And $FFFFFFFF
		WritePixelFast X, Y, rgb
	Next
Next

UnlockBuffer
SetBuffer BackBuffer(  )

DrawBlock image, 0, 0
Flip

WaitKey
End

It's not that simple though, because TGA files can be saved in several different formats (you have to interpret the ColorMapType etc and decide how to read in the data)


David819(Posted 2004) [#19]
Thanks for the help chriss fuller.