Important information: this site is currently scheduled to go offline indefinitely by end of the year.

[solved] Flipping Models and Skeletons

Post questions about game models here, or help out others!
Post Reply
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

[solved] Flipping Models and Skeletons

Post by majidemo »

Hello,

I have been asking questions here for awhile now about unpacking 3d model files and bones and have successfully done them with help.

But today, after 2 months of working on this, I realized that all the files I unpacked are flipped.

This is an example taken from the actual game:

Image

You'll notice that the weapon, and animation is on the right hand.

While this is the result from the data I extracted (put into WebGL or OpenGL):

Image

The weapon and the animation of holding it is on the left side.

I do realize that flipping the mesh/3d model would require me to multiply -1 to the axis where I want to flip. (axis * -1)
But it isn't as easy for the bone/skeleton.

So my question is: How do I flip the bones and animation? so that the animation/holding of weapon is on the right side?

Additional Info:
The bone matrices are local to heirarchy.
The animation frame matrices are also local to heirarchy.

I also tried loading my files into Noesis just to check if it is an WebGL/OpenGL issue but I got the same flipped result: (I'm assuming Noesis uses DirectX)

Image
Last edited by majidemo on Sat Dec 03, 2016 11:13 am, edited 2 times in total.
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

Re: Flipping Models and Skeletons

Post by majidemo »

I tried multiplying the x-axis of the vertices with -1. So `vx, vy, xz * -1`.

Which gave me this result:

Image

I noticed that the face is getting culled, so it must due to the backface culling. So I reversed the order of the faces, instead of "f1, f2, f3" I made it "f3, f2, f1".

Which gave me this result:

Image
Image

But now the problem is that the skeleton/bones is facing the other direction. (still can't figure this out)
Sir Kane
veteran
Posts: 104
Joined: Mon Aug 06, 2012 4:14 am
Been thanked: 96 times

Re: Flipping Models and Skeletons

Post by Sir Kane »

For a ghetto solution you could invert the axis in your vertex shader after applying the skinning, before applying the other transforms.
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

Re: Flipping Models and Skeletons

Post by majidemo »

Hello,

I did try this. Which actually works, after changing the rendering side to BackFace/Side. But I would like to fix this on my file itself and outside the application. So the application just reads the data directly.
User avatar
Wobble
ultra-veteran
ultra-veteran
Posts: 584
Joined: Tue Jan 04, 2005 9:47 pm
Has thanked: 43 times
Been thanked: 112 times

Re: Flipping Models and Skeletons

Post by Wobble »

[out]
Last edited by Wobble on Sun Mar 12, 2017 10:37 am, edited 8 times in total.
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

Re: Flipping Models and Skeletons

Post by majidemo »

Thank you :) I have one question though, whats the formula for converting the bone matrices to worldspace? Or modelspace? And back?
Sir Kane
veteran
Posts: 104
Joined: Mon Aug 06, 2012 4:14 am
Been thanked: 96 times

Re: Flipping Models and Skeletons

Post by Sir Kane »

To get a bone's world transform, you multiply a bone's local transform by its parent's world transform (if the bone doesn't have a parent, copy the local transform to the world transform).

For the other way around, you multiply the bone's world transform by the inverse of the parent's worldtransform (any copy world to local for parentless bones).
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

Re: Flipping Models and Skeletons

Post by majidemo »

Great, I'll try this out tonight and give you guys feedback :)
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

Re: Flipping Models and Skeletons

Post by majidemo »

I negated the values as told by sir Wobble,

I did it like so:

Code: Select all

worldMatrix = mathutils.Matrix(( 
                (      modelMatrix[0],       modelMatrix[1],  -1 *  modelMatrix[2],        modelMatrix[3]  ), 
                (      modelMatrix[4],       modelMatrix[5],  -1 *  modelMatrix[6],        modelMatrix[7]  ), 
                ( -1 * modelMatrix[8], -1 *  modelMatrix[9],  -1 *  modelMatrix[10], -1 *  modelMatrix[11] ), 
                (      modelMatrix[12],      modelMatrix[13], -1 *  modelMatrix[14],       modelMatrix[15] ) 
            ))
While it did correct the handedness of the bones, it messed align some. Figured here:
Image

Some bones are in the correct position, while one bone is too long, and the hands are a on a narrower angle. Did I make a mistake on the negation?

----------------------------------
UPDATE (fixed rest pose)

I did make a mistake, I realized negating modelMatrix[10] wasn't necessary. Correcting that, fixed the whole thing. Thanks a bunch :)
Post Reply