3d model reading
Blitz3D Forums/Blitz3D Programming/3d model reading
| ||
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. |
| ||
What is a 'game ripper'? |
| ||
I think he means something like this (Dragon UnPACKer 5): http://www.elberethzone.net/index.php?page=dup5&language=en#formats |
| ||
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. |
| ||
Look up the SaveTGA function in the code archives. It doesn't get much simpler than Targa. |
| ||
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. |
| ||
That was kinda the point. Convert the SaveTGA function into a LoadTGA function to give yourself practice of the most basic format around. |
| ||
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. |
| ||
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. |
| ||
:( |
| ||
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() |
| ||
Please help me please. |
| ||
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. |
| ||
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. |
| ||
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(). |
| ||
ok thanks, I'll see where i can get with that. |
| ||
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() |
| ||
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) |
| ||
Thanks for the help chriss fuller. |