Author Topic: Understanding model files  (Read 9605 times)

picklejar

  • *
  • Posts: 147
    • View Profile
Understanding model files
« on: 2012-05-08 02:00:01 »
Hello everyone, I am new to the forums and a little new to working with FF7 models.

I'd like to create a new game that uses some of the FF7 models.  To get started, I'd like to create a program that can do basically what Ifalna does: load model data and render 3D models (and ultimately animations) in a window.

I have successfully used LGPTools to extract (from char.lgp) all the model-related files: *.p, *.a, *.rsd, *.tex

So now, my question is: Where can I find more information on the file format of these files, and/or source code that reads these files and generates 3D models and animations from them?

Thanks in advance!

syntax error

  • *
  • Posts: 147
    • View Profile
Re: Understanding model files
« Reply #1 on: 2012-05-08 10:16:46 »
Its easier to export them to Blender or some other
3D renderer, look at the wiki to find all infos about formats and rotations.

picklejar

  • *
  • Posts: 147
    • View Profile
Re: Understanding model files
« Reply #2 on: 2012-05-08 18:33:28 »
I somehow missed the fact that we have a Wiki!  Wow, there's so much useful info there!  This is such an awesome community!  :D

I found the info I wanted on the Wiki.  In case anyone else wants the same info, here it is:

*.P file format: http://wiki.qhimm.com/FF7/P (also discusses relationship to *.RSD and *.HRC)
*.A file format: currently in: http://wiki.qhimm.com/FF7/Field (but maybe needs to be separated into separate Wiki page)
*.RSD file format: maybe http://wiki.qhimm.com/PSX/RSD (but this is for PSX)
*.TEX file format: maybe http://wiki.qhimm.com/PSX/TIM_file (TIM is really TEX I think)

Borde

  • *
  • Posts: 891
    • View Profile
Re: Understanding model files
« Reply #3 on: 2012-05-12 10:46:30 »
If you need source code, you can take a look at Kimera's source (in the tools subforum). I also have C code for working with field models if you need it (it's pretty old, though)

picklejar

  • *
  • Posts: 147
    • View Profile
Re: Understanding model files
« Reply #4 on: 2012-05-23 19:44:03 »
Ah, thanks Borde, I see that you are the one that wrote Kimera.  Awesome, I will definitely have to check it out, including the source.  :D

I'm stuck at rendering the complete model correctly.  I can render individual bones (e.g. hip, chest, etc.), and I can parse the skeleton structure fine (chest is a child of the hip, etc.).  I'm just having problems with putting all the bones in the right places.

I am REALLY close, though, I think.  Once I place a parent bone, the way I place one of its child bones is that I apply the following transformation: Translate by "parent bone length" in the negative Z direction, then apply Y rotation, then apply X rotation, then apply Z rotation.  This is REALLY close to the right solution, I think, but it's not quite right: Cloud's upper body looks perfect, but his lower body, starting with his legs, is messed up: his legas are going behind him instead of downward from the hip.

Anyway, I'll keep playing with it... thanks!

picklejar

  • *
  • Posts: 147
    • View Profile
Re: Understanding model files
« Reply #5 on: 2012-05-23 19:59:47 »
Sure enough, as soon as I posted my last message, I realized what my problem was: my code is not applying rotations on the root bones.  As some of you know, many character models, including Clouds and others, have multiple root bones, e.g. a hip (upper body connected to this), a left hip (left leg connected to this), and a right hip (right leg connected to this).  I wasn't applying rotations to any of the hip bones.  Once I apply those rotations, I'm almost certain that will fix Cloud's legs in my program.

TLDR: You can ignore my last message.  :D

picklejar

  • *
  • Posts: 147
    • View Profile
Re: Understanding model files
« Reply #6 on: 2012-05-30 18:39:31 »
Okay so now I'm a little stuck on understanding the texture coordinates.  When the coordinates are between 0.0 and 1.0, my program does great, but when a coordinate is greater than 1.0, it fails.  (According to Alhexx's document, when a coordinate is greater than 1.0, I should just subtract 1.0, but this doesn't seem to produce the correct result.)

Let's take a specific example: Cloud's "head" bone (aaba.p) contains one big non-textured polygon group (0) for his head+hair, then three textured polygon groups, which I will call left eye (1), right eye (2), and mouth (3).

left eye uses the first 5 coordinates (and uses texture aabb):
TextureCoordinate[0] = (1.0, 0.0625)
TextureCoordinate[1] = (1.03125, 0.9375)
TextureCoordinate[2] = (1.84375, 0.03125)
TextureCoordinate[3] = (1.84375, 0.90625)
TextureCoordinate[4] = (1.96875, 0.90625)

right eye uses the next 5 coordinates (and uses texture aabc):
TextureCoordinate[5] = (0.03125, 0.0625)
TextureCoordinate[6] = (0.8125, 0.03125)
TextureCoordinate[7] = (0.03125, 0.9375)
TextureCoordinate[8] = (0.8125, 0.90625)
TextureCoordinate[9] = (0.96875, 0.90625)

mouth uses the remaining 4 coordinates(and uses texture aabd):
TextureCoordinate[10] = (0.96875, 5.21875)
TextureCoordinate[11] = (0.46875, 5.9375)
TextureCoordinate[12] = (0.46875, 5.0)
TextureCoordinate[13] = (0.03125, 5.21875)

My program can correctly apply the texture for the right eye.  Its texture coordinates are all between 0.0 and 1.0.

My program has trouble applying the textures for the left eye and the mouth.  Their texture coordinates go as high as 1.96 and 5.21, respectively.  I don't know how to interpret values greater than 1.0.

I don't mind digging into Borde's Kimera source code.  But I'm hoping that Borde or someone else will know exactly what my problem is and can save me the trouble and explain how to interpret these coordinate values.  :D

Thanks in advance for any insight you can give me!

picklejar

  • *
  • Posts: 147
    • View Profile
Re: Understanding model files
« Reply #7 on: 2012-05-30 19:04:55 »
BTW, I found this thread:
http://forums.qhimm.com/index.php?topic=1593.msg23376#msg23376

NeutopiaW explains the texture coordinates somewhat, and Alhexx learned from this, which presumably is how he got Ifalna to draw the textures correctly.  But it doesn't explain it fully, and Alhexx didn't update his documentation completely.

I'll need to understand the "hundreds" chunks more thoroughly, and then understand what the texture coordinates mean in a larger context...

picklejar

  • *
  • Posts: 147
    • View Profile
Re: Understanding model files
« Reply #8 on: 2012-05-31 16:05:47 »
Quick update for those who are reading this thread:

The "Hundreds" Chunks seem to provide some texture info, but not the kind of info I'm looking for:

HundredInfo[1 1 0   -126 3 2 0 2 0 0 0 0 0 0 0 2 -1 0 0 2 1 2 0 4 0 0 0 0 0 255 0
HundredInfo[1 1 14 -126 3 2 0 2 0 0 0 0 0 0 0 1 -1 0 0 2 1 2 0 4 0 0 0 0 0 255 0
HundredInfo[1 1 14 -126 3 2 0 2 1 0 0 0 0 0 0 1 -1 0 0 2 1 2 0 4 0 0 0 0 0 255 0
HundredInfo[1 1 14 -126 3 2 0 2 2 0 0 0 0 0 0 1 -1 0 0 2 1 2 0 4 0 0 0 0 0 255 0

I assume rows 2-4 represent groups 2-4, which are the textured groups.  The 9th value is probably a texture index (0, 1, 2).  All the other values are the same across all textured groups.  So, in short, the Hundreds Chunk won't tell me how to interpret texture coordinates greater than 1.0.

So I'm guessing I will need to understand the TEX file format more, to understand how individual texture "files" are loaded into the memory buffer, and use that information to correctly interpret texture coordinates.

If I figure it out before someone else helps me, I'll update this thread.  :D

picklejar

  • *
  • Posts: 147
    • View Profile
Re: Understanding model files
« Reply #9 on: 2012-06-01 04:25:55 »
So, after analyzing the TEX files for Cloud's left eye and right eye, I found that they are mostly the same, except that one of the bits is set to 1 for his left eye, but not his right.

Also, for Cloud's left eye, I found out that if I reverse the image AND if I change the texture x-coordinates from x to 2.0-x, it looks right.

So, I'm suspecting that "image reversing" might be a possible operation that should be done before applying the texture coordinates?  (This kinda makes sense because if you view Cloud's two eyes in a TEX viewer program, they are both facing the same direction.)

Borde, I could really use your insight here, if you can spare a few minutes to help a fellow programmer.  :D  BTW I downloaded Kimera's source; if I don't hear from you I will start digging into it.  There's a lot of .BAS files but hopefully I can figure out which one applies the textures...

Aali

  • *
  • Posts: 1196
    • View Profile
Re: Understanding model files
« Reply #10 on: 2012-06-01 09:29:21 »
Those texture coordinates wouldn't give you any trouble if you were familiar with how 3d rendering works on.. pretty much anything since the 1990s. Curious since you claim to be creating a game (presumably) using 3d models.

Anyway, you can safely assume that all textures in FF7 repeat infinitely, a texture coordinate of 1.5 is equivalent to 0.5 and so is 2.5 and 3.5 etc. It's technically possible to turn this off in the "hundreds" structure (thats a terrible name for it but it has stuck, even my code refers to it as such) but FF7 doesn't use this feature and my driver does not support it. (If you were to turn it off the texture coordinates would be clamped to 0.0-1.0 and the very edge of the texture would be repeated instead)

picklejar

  • *
  • Posts: 147
    • View Profile
Re: Understanding model files
« Reply #11 on: 2012-06-01 18:50:04 »
Aali: Nice to meet you, and thanks for your Wiki contributions with regards to interpreting FF7 files.

Thanks for the response.  I just wanted to make sure I was interpreting the FF7 files correctly, and that there wasn't some other extra data that was required to interpret the texture coordinates correctly.  Just knowing that helps me to focus my troubleshooting (e.g. maybe I have to explicitly enable texture repeating in my API's).

Thanks everyone.  I have all the info I need.  And I know nobody cares yet because I haven't shown anybody what I'm making yet.  :D

picklejar

  • *
  • Posts: 147
    • View Profile
Re: Understanding model files
« Reply #12 on: 2012-06-07 02:55:35 »
BTW I think I have resolved my texture issues.  Now I can concentrate on other parts of the game.

Pretty soon I will reveal what I'm making so that I can get some feedback and ideas.  It will probably be in another forum.

picklejar

  • *
  • Posts: 147
    • View Profile
Re: Understanding model files
« Reply #13 on: 2012-06-07 23:44:18 »
BTW I revealed what I'm making in the following thread:

http://forums.qhimm.com/index.php?topic=13186.0

Basically it's a "Final Fantasy 7 Online" game.  :D