Page 2 of 2

Re: GuildWars models

Posted: Sun Jan 22, 2012 10:49 am
by Demonsangel
There are so many "if else if not then else " in the script format/script it's even hard for me to follow the code but i'll give it a shot.

Global overview of the file:
Image

Header:
Image

Code: Select all

4 bytes = FFNA
1 byte  = constant 02 for models
4 bytes = might be the difference between a model file and an animation file but i still have to look into that
4 bytes = INT slightly smaller than filesize
1 byte = always 26, end of header
Modifiers:
Image

Code: Select all

7 bytes = unknown
4 bytes = has an impact on how many meshes, usually if not 0800 or 09xx it's +2 meshes and weird behavior
4 bytes = TYPEA : defines global behavior on every part of the rest of the file
          -reduce meshamount
          -more dwords in the vertex list
          -behavior after/inbetween vertex lists
4 bytes = TYPEB : I haven't seen it influence anything (yet)
20 bytes = "modifiers" -> determine, along with the mesh modifiers( listed lower) how many bytes are in between meshmodifiers and facelist
8 bytes = double float : small range of constant floats, could be scaling values
20 bytes = unknown
1 byte = amount of "meshes"
Meshmodifiers:
Image

Code: Select all

15 bytes = unknown
meshamount * 8 bytes = i think global mesh info, it's mostly the last byte (#8) that influences anything in the file; here there are 2 "meshes"
next bytes untill end of image (usually terminated by "00 00 00 00") I have no clue what they do, probably some shadow settings or whatnot, way too complicated
Face-Vertex:
Image

Code: Select all

12 Bytes = 3 * Int : amount of triangles in the facelist, they add up if the values differ from eachother
4 bytes = Int : amount of vertices
4 bytes = Int : defines the amount of dwords in 1 "vertex line","17" adds a "00 00 00 00" inbetween xyz and the normals
8 bytes = 2 * Int: add up to define part 1 after vertex list
4 bytes = Int: define part 2 after vertex list
After that the facelist immediately starts, followed by the vertex list:
Image

Code: Select all

12 bytes = 3* float = x,y,z
depending what else is in there it usually is, I have seen it add up to 12*4 bytes, perhaps bones? still have to look into it
12 bytes = normals
8 bytes = UV
after the vertex list comes a chunk which i do not know what it does: (part 1 and 2 described above in light and dark gray)
Image

immediately the face count + vertex count again if multiple meshes in file

Re: GuildWars models

Posted: Sun Jan 22, 2012 7:31 pm
by finale00
Good work.
That outline is easier to understand than reading from the code.
Now I can look at the code and go "oh ya, that's what that flag is for and that's what the condition is about"

I think the more complicated part of the code is the getattr and setattr. You really don't need those if you're just setting/getting values. Just store them in a list.

Ya, conditionals...I don't really have a fixed way of describing them either.

Re: GuildWars models

Posted: Sun Jan 22, 2012 8:34 pm
by Demonsangel
I'm used to the get/setattr but seeing as how my code is one giant clusterfuck I'd try anything to make it readable.
I mainly use it when there are a variable amount of subclasses to be declared, like the meshmodifiers. When using Meshes[0][0], for example, I always forget what I'm actually looking up. Granted Meshes.mesh1._1 isn't that much clearer.

I'm still looking at some variables that behave oddly and I'll start rewriting/cleaning up the code after my next exam.

Re: GuildWars models

Posted: Sun Jan 22, 2012 9:11 pm
by finale00
I usually don't use classes like structs (it looks like that's how they're being used). I just toss stuff in lists or dicts and grab them later. That's what they're for anyways lol

Here's my attempt at reproducing the code (based on what you've written and uploaded so far)
But I'm using the rpg interface so a lot of things require less code to do.

Only handles the cases where meshamounts == 1
For vertex parsing, I only checked one variable (faces.unknown2, I called it vertexType)

Didn't feel like continuing cause you most likely figured out more of those odd conditions.

Re: GuildWars models

Posted: Sun Feb 05, 2012 11:54 pm
by Demonsangel
I was rewriting the script while I noticed something weird
print(self.inFile.tell())
self.inFile.read('hihc')
print(self.inFile.tell())
gives me 105 -> 116
print(self.inFile.tell())
self.inFile.read('ihhc')
print(self.inFile.tell())
gives me 105->114 as I expected the code above to do as well.
Is this a bug or intended? I don't need the format to be in that order necessarily, but it does help me figure out how/where to edit when making format adjustments.

Re: GuildWars models

Posted: Mon Feb 06, 2012 1:36 am
by finale00
That is a known issue with the struct module. First time I ran into it, had no clue what was going on and spent about an hour just trying to figure out why I'm reading 22 bytes rather than (what I thought would be) 14 :[

http://docs.python.org/library/struct.html#examples

Code: Select all

import struct
struct.calcsize('ih')
6
struct.calcsize('hi')
8
Because of this I typically don't mix formats.

Re: GuildWars models

Posted: Mon Feb 06, 2012 3:34 pm
by Demonsangel
I hope this one is easier to follow. Script attached below.

I also used the extractor posted on the wiki which netted me 89k files.
after sorting them I came up with 10 'filetypes" and filetype "a00f0000" had 3020 "formattypes". So turns out i'm not nearly done going through them all.

I also noticed theformatSUBtypes 0C00 and 2900 follow what seems to be a pretty fixed format, but they don't seem to contain any vertex data.

They might be the bone files for the models but not sure yet as I don't really know what the boneinfo should look like.

Re: GuildWars models

Posted: Mon Feb 06, 2012 11:25 pm
by finale00
Ya I think it's a lot easier to follow now.