Page 1 of 1

Battlefield 3 & Battlefield 4 mesh files

Posted: Sat Feb 22, 2014 8:15 pm
by dainazinas
Hi.

I`ve recently been looking into the game files of bf3/bf4 and mohwf (frostbite2/3). I have written working texture converters for them and a semi working mesh(chunk) to obj converter(based on hex2obj by shakotay).

But I want to breakdown the files further.
Ok so the model files are of two parts
1: the .mesh file (header file) and
2: the .chunk file (payload file).


There still are a few things I don`t quite understand. For instance some of the models have multiple parts in a single mesh. But in game they all are separate models or model parts if you like i.e car body and its wheels are separate models in game, but in game files they are stored as one continuous mesh. Would this info be stored in the .mesh (header) or a .chunk (payload files)?

video http://www.youtube.com/watch?v=URDXPxyoJvU

And I`m also interested in bone weights and bone structures. The skeleton files are in readable format(txt file) and all the skeletal structure is available but now I need to know where the vertex values are stored so I can tie these together.
Here is a section from a .chunk (payload file)

Image

so my question is is this how bone weights are typically stored in mesh files? Or do I got it completely wrong and should look elsewhere?

here are "rat" files https://dl.dropboxusercontent.com/u/881 ... ch/rat.rar

Re: Battlefield 3 & Battlefield 4 mesh files

Posted: Sun Feb 23, 2014 12:31 am
by luxox18
weights are stored in files called "bone influences" and bones in one standard bone structure named "skel"---- in BF3 - BF4 - MOHW all this files are inside of chunk files without names , for this is very difficult to find.

but in BFBC - BFBC2 - BF1943 all files have full names and are correctly classified , check the files from this games for find the structure and formats

Re: Battlefield 3 & Battlefield 4 mesh files

Posted: Sun Feb 23, 2014 9:48 am
by Chipicao
dainazinas wrote:some of the models have multiple parts in a single mesh. But in game they all are separate models or model parts if you like i.e car body and its wheels are separate models in game, but in game files they are stored as one continuous mesh.
It's not uncommon for vehicle parts to be controlled by bones via "hard" animations (blend weights =1). I've seen it in games like GTA IV/V, Driver SF and NFS Rivals.
dainazinas wrote:so my question is is this how bone weights are typically stored in mesh files? Or do I got it completely wrong and should look elsewhere?
I think blend weights are right after bone indices, stored as uint8 and need to be /255 to convert to floats.
Check some vehicle meshes. If the presumed blend weights are always 0xFF you can prove both theories.

Here's my take on the vertex structure. I double-checked normals and tangents in max, there's no doubt about them. So that only leaves one option for blend weights.
Image

Re: Battlefield 3 & Battlefield 4 mesh files

Posted: Sun Feb 23, 2014 11:43 am
by cra0
Dumping the vertex shader is always helpful when figuring those out

Code: Select all

HRESULT WINAPI hkCreateVertexShader( ID3D11Device * This, const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D11ClassLinkage *pClassLinkage, ID3D11VertexShader **ppVertexShader )
{
    ID3DBlob* pBlob = NULL;
    HRESULT hRet = D3DDisassemble( pShaderBytecode, BytecodeLength, 0, "/*========================DUMPED BY D1GITALSLR================================*/ \n", &pBlob );
    char* buffer = (char*)malloc(pBlob->GetBufferSize());
    memcpy(buffer, pBlob->GetBufferPointer(), pBlob->GetBufferSize());
    mFile << buffer;
    mFile << "\r\n\r\n";
    return oCreateVertexShader( This, pShaderBytecode, BytecodeLength, pClassLinkage, ppVertexShader);
}  
Credits to d1gitalSLR @unknowncheats

Re: Battlefield 3 & Battlefield 4 mesh files

Posted: Thu Feb 27, 2014 3:49 am
by dainazinas
luxox18 wrote:weights are stored in files called "bone influences" and bones in one standard bone structure named "skel"---- in BF3 - BF4 - MOHW all this files are inside of chunk files without names , for this is very difficult to find.

but in BFBC - BFBC2 - BF1943 all files have full names and are correctly classified , check the files from this games for find the structure and formats
Thanks for the info, but those files do not contain per/vertex information.
Chipicao wrote:It's not uncommon for vehicle parts to be controlled by bones via "hard" animations (blend weights =1). I've seen it in games like GTA IV/V, Driver SF and NFS Rivals.
This makes a lot of sense, thanks. So here is a model of vehicle from Battlefield 3 (M_FA_18F_D). But vehicle parts don`t seem to have 0xFF weights but instead uses same bone index x4 , strange... . + this model uses 2 sets of UV`s one for normal and second for diffuse.

Image
I wrote a maxscript that selects vertex`es based on bone indice positions in the chunk file, it seems to work quite well
Here`s the files if anyone wants to check them out. https://dl.dropboxusercontent.com/u/881 ... _18F_D.rar

cra0 wrote:Dumping the vertex shader is always helpful when figuring those out
Thanks, mind elaborating?

Re: Battlefield 3 & Battlefield 4 mesh files

Posted: Thu Feb 27, 2014 8:30 pm
by Chipicao
dainazinas wrote:vehicle parts don`t seem to have 0xFF weights but instead uses same bone index x4 , strange...
Not strange at all. Since blend weights would always be =1.0 in this model, it makes sense not to include them in order to save space and memory. The game probably detects this in a flag or in the shader.

Re: Battlefield 3 & Battlefield 4 mesh files

Posted: Mon Mar 03, 2014 4:01 pm
by dainazinas
Chipicao wrote:
dainazinas wrote:vehicle parts don`t seem to have 0xFF weights but instead uses same bone index x4 , strange...
Not strange at all. Since blend weights would always be =1.0 in this model, it makes sense not to include them in order to save space and memory. The game probably detects this in a flag or in the shader.

I`m having trouble finding in (*.mesh/aka_header file) something that would indicate the data structure in the .chunk file. What I do know is where the vertex block size, vertex/faceindice count, string name, for each model + total mesh/submesh count. But no reliable UV`s position. Anyone could shed some light on this?

Re: Battlefield 3 & Battlefield 4 mesh files

Posted: Mon Mar 03, 2014 5:12 pm
by Chipicao
This would go a bit faster if you'd share the structure you have identified so far.

Am I correct on the following?
Image

Send me one or two more meshes that have different VB structures than the rat.

Re: Battlefield 3 & Battlefield 4 mesh files

Posted: Mon Mar 03, 2014 6:01 pm
by dainazinas
Chipicao wrote: Send me one or two more meshes that have different VB structures than the rat.

Various models and a rat.hbk(in rat.rar)

https://dl.dropboxusercontent.com/u/881 ... models.rar
https://dl.dropboxusercontent.com/u/881 ... F4/Rat.rar

thanks

Re: Battlefield 3 & Battlefield 4 mesh files

Posted: Tue Mar 04, 2014 8:29 pm
by dainazinas
Chipicao did you get a chance to have a look at the structures?

I`ve been trying and failing as the offsets I can read are inconsistent.

Please help when you get a chance :)

Re: Battlefield 3 & Battlefield 4 mesh files

Posted: Wed Mar 05, 2014 9:18 am
by Chipicao
Sorry, I didn't have time to analyze them properly.
The only thing you got wrong in your hbk was the IB offset. What you bookmarked as "Mesh.0 Face Indice Count" is actually the offset in indices for the second mesh. It's just a coincidence that it matches the index count of the first mesh because they are both the same.

When I have some free time I will look more into it.

Re: Battlefield 3 & Battlefield 4 mesh files

Posted: Fri Mar 07, 2014 6:25 pm
by dainazinas
Chipicao wrote:When I have some free time I will look more into it.
I really hope you can help me with the mesh files. As for now I managed to get maxscript to import and name the skeletons(I think it does it properly) however it does not deal with hierarchy just yet, and another script that imports the geometry, it needs some manual input, and that`s where reading the .mesh/header files properly would be super useful.

And thanks for the update Chipicao :)

here are the updated scripts, skeleton, geometry and mesh/header files again. https://dl.dropboxusercontent.com/u/881 ... ch/Rat.rar

Re: Battlefield 3 & Battlefield 4 mesh files

Posted: Tue Jan 12, 2016 10:44 pm
by LALHW
Sorry for messing with this old thread, but do you still have the texture converters?