Page 1 of 1

Extracting models from binary files

Posted: Sun Apr 26, 2020 6:23 pm
by rithesh
I am trying to build a tool to export and import binary models from an old DX9 game. The models are packed in a single file and I have managed to extract the relevant parts in hexadecimal.

The data below corresponds to a simple rectangle plane in the game. (First image is the Vertex Buffer and the second image is the Indices)

Image

Vertex Buffer

Code: Select all

[8B F6 00 00] [65 09 03 00] [80 FF 80 FF] [FF FF FF FF] [00 00 00 00] [00 00 00 00]
[8B F6 00 00] [9B F6 03 00] [80 FF 80 FF] [FF FF FF FF] [00 00 00 00] [00 00 80 3F]
[75 09 00 00] [65 09 03 00] [80 FF 80 FF] [FF FF FF FF] [00 00 80 3F] [00 00 00 00]
[75 09 00 00] [9B F6 03 00] [80 FF 80 FF] [FF FF FF FF] [00 00 80 3F] [00 00 80 3F]
Indices

Code: Select all

[00 00] [01 00] [02 00] [03 00] [02 00] [01 00]
By analyzing the Vertex buffer, I have concluded that it was using the following format. Basically the stride is 24 bytes.

Code: Select all

struct CUSTOMVERTEX
{
    CUSTOMVERTEX(FLOAT fx, FLOAT fy, FLOAT fz, DWORD dwcolor, FLOAT fu, FLOAT fv) :
        X(fx), Y(fy), Z(fz), COLOR(dwcolor), U(fu), V(fv) {}
    FLOAT X, Y, Z;
    DWORD COLOR;
    FLOAT U, V;
};
I believe the vertex buffer is not in the correct format since i am getting NAN values when I convert them to 32bit floats. Any idea how I can convert these vertices and indices to any 3D file format so that I can open them using blender or 3DS?

Re: Project3 extracting models from binary files

Posted: Sun Apr 26, 2020 6:38 pm
by shakotay2
Sample file?

Re: Project3 extracting models from binary files

Posted: Sun Apr 26, 2020 7:13 pm
by rithesh

Re: Project3 extracting models from binary files

Posted: Sun Apr 26, 2020 7:46 pm
by shakotay2
here's your cube (file 2):
.
cube.png
File 1: there's floats (6x4 floats) (bounding box I think, not tested) and float uvs, funny. Strange combination with short vertices.

(Correct me if I'm wrong: are there 321 identical cubes in file 1? :D )

(Sword is from file 2.)

Re: Project3 extracting models from binary files

Posted: Sun Apr 26, 2020 9:38 pm
by rithesh
Thanks a lot! I didn't expect short vertices. :D

Re: Project3 extracting models from binary files

Posted: Mon Apr 27, 2020 7:52 am
by shakotay2
Here's a tool for conversion to obj, roughly tested only:
Make_obj-Project3-test.zip

Re: Project3 extracting models from binary files

Posted: Mon Apr 27, 2020 7:54 am
by shakotay2
File 1 (1696 meshes, maybe more), all in one clump:
.
file 1.jpg

Re: Project3 extracting models from binary files

Posted: Mon Apr 27, 2020 3:05 pm
by rithesh
Works great! Thanks a ton.

How are the short vertices converted to float in your tool?

Re: Project3 extracting models from binary files

Posted: Mon Apr 27, 2020 3:46 pm
by shakotay2

Code: Select all

void log_short_Verts(DWORD addrV, DWORD Vcnt, BYTE vStride)
{
    char *pFBuf ;
    BYTE i, l ;
    int nValue[2] ;
    DWORD k ;
    float lPosXYZ ;

    pFBuf = (char *) lpFBuf ;
    pFBuf += addrV ;
    for (k=0;k < Vcnt;k++) {
        fprintf( stream, "v ") ;
	for (l=0;l<3;l++) {
	    for (i=0;i<2;i++) {						// 1x Word
		nValue[i] = (*pFBuf & 255) ; pFBuf++ ;
	    }
            lPosXYZ= nValue[0] + nValue[1]*256 ;
            if (lPosXYZ>32767) lPosXYZ -= 65536;
	    fprintf( stream, "%f ", lPosXYZ/256.0) ;
	}
	fprintf( stream, "\n") ;
	pFBuf += vStride-6 ;
    }
}