TexTools / xivModdingFramework

GNU General Public License v3.0
9 stars 16 forks source link

Racial Model Export #9

Closed Lunaretic closed 4 years ago

Lunaretic commented 4 years ago

Racial Model export (for non existent) racial models I suspect is simply a function of matrix math - as we've not actually done that yet, as I'm aware of.

The general function should be:

These transformations need only be applied to the position coordinates of each vertex, indices and other values are by nature unaffected.

Lunaretic commented 4 years ago

My drunken ramblings here are actually pretty much bang on here after some further digging. Ideally you're treating the new racial skeleton as a new bone animation state, from the original race as the bind pose. The math to do this is simply

SUM[ Weight * [New Transformation Matrix] x [Old Inverse Transformation Matrix] x World space vector position ] ]

The main question here is whether or not the bone transformation matrices in the skelb file are already composed with their parent, or if we need to compose them with the parent matrix first (In which case, we have to walk the skeleton forward from the base items to create the proper transformation matrices for each bone).

Really great answer from someone on skeletal animation that helps: https://gamedev.stackexchange.com/questions/28012/bones-animation-matrices-and-calculations and : https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-4-animation-dawn-demo

Further information - It seems the Bone PoseMatrixes are not combined, wherease the InversePoseMatrixes in the Skelb files are already combined.

Lunaretic commented 4 years ago

Closing this issue for now as a more information needed. Performing racial bone transformation results in effects on par with CMTool's forced Data Path change for animations. Current thought is there may be a separate set of skeletons used specifically for transforming gear between races in the files, which then standard anims are composed ontop of, rather than just the known racial skels.

Lunaretic commented 4 years ago

Reopening this because I ended up finding the correct method to do this.

The bone deformations for converting gear are located int

The format of the file is [248 byte header] [Entries]

Where an entry is composed of [int # bones] [short x # bones - offset to bone name within the entry] [padding to nearest 4 bytes] [float x 12 - Bone deformation matrix (first 3 rows, last is always 0,0,0,1) ] [bone names] [padding to nearest 4 bytes]

Then these Matrices are directly applied per-bone to the vertices, based on weights.

Furthermore, because this calculation does not take into account the current skeleton, these deformations must be chained based on the racial chain of the item. Ex. The Midlander F deformation only takes Midlander M => Midlander F, The MIqo'te F deformation only takes Midlander F => Miqo'te F.

Lunaretic commented 4 years ago

Racial model transformation works, need to identify which deformation matricies are for which races now (other than Miqo F which has already been found), and add a UI for managing them.

Lunaretic commented 4 years ago

Racial Model Export is now available via the Full Model Viewer - Though it might be good to add it down the line to the basic model viewer as well.