ParaWorld vertex unpacking

Skeletons, animations, shaders, texturing, converting, fixing and anything else related to read game models
DryFun
Posts: 27
Joined: Fri Nov 24, 2017 4:54 pm

ParaWorld vertex unpacking

Post by DryFun »

I need some help with vertex unpacking

Main topic viewtopic.php?f=9&t=6998
BSM viewer https://github.com/BlasSoriano/Paraworld

Basically everything is right but it seems there is a problem with z coordinate:
(I rotate the model for more convenient viewing)
Front view https://www.dropbox.com/s/lvowyfl6jzybr ... 281%29.jpg
Top view https://www.dropbox.com/s/uh5hanlcid43h ... 281%29.jpg

Vertices unpacking script https://www.dropbox.com/s/jm51uzgze7kzpwp/Vertex.cs
Vertices.obj https://www.dropbox.com/s/2mlc74ra9a3qiva/Vertices.obj

What could be the problem?
sleepyzay
Posts: 40
Joined: Mon Sep 15, 2014 5:13 am

Re: ParaWorld vertex unpacking

Post by sleepyzay »

Is it possible that your'e reading the wrong selection of bits for your x y z coordinates? I normally see packed vertices in either the 11:11:10 or 10:10:10 format, never 13:13:6.
DryFun
Posts: 27
Joined: Fri Nov 24, 2017 4:54 pm

Re: ParaWorld vertex unpacking

Post by DryFun »

BSM said: "There are still 9 remaining bits, for an unknown yet purpose: bits 0-12: x bits 13-25: y bits 26-38: z bits 39-47: unknown bits 48-55: u bits 56-63: v"
And as far as I can remember, he unpack the whole model correctly
sleepyzay
Posts: 40
Joined: Mon Sep 15, 2014 5:13 am

Re: ParaWorld vertex unpacking

Post by sleepyzay »

Oh, I assumed a ulong was 32 bits, not 64. But the bit selection still feels arbitrary. Do you have a sample file I can look at?
DryFun
Posts: 27
Joined: Fri Nov 24, 2017 4:54 pm

Re: ParaWorld vertex unpacking

Post by DryFun »

Yes
There are no triangles, only bits 0-12: x bits 13-25: y bits 26-38: z bits 39-47: unknown bits 48-55: u bits 56-63: v
hex.txt
Acewell
Posts: 706
Joined: Fri Aug 08, 2014 1:06 am

Re: ParaWorld vertex unpacking

Post by Acewell »

looks like could be a typo in Vertex.cs on line 61
https://github.com/BlasSoriano/Paraworl ... /Vertex.cs

Code: Select all

z = ix * (boundingBox.max.Z - boundingBox.min.Z) / MAX_VALUE_13BITS + boundingBox.min.Z;

should be :?:

Code: Select all

z = iz * (boundingBox.max.Z - boundingBox.min.Z) / MAX_VALUE_13BITS + boundingBox.min.Z;
sleepyzay
Posts: 40
Joined: Mon Sep 15, 2014 5:13 am

Re: ParaWorld vertex unpacking

Post by sleepyzay »

To get your desired values you need to divide your group of bits by their size. Since they're all 13, they all get divided by 8191.0.

Code: Select all

ix = (float)(((packedBits >> 0) & 0x1FFF) / 8191.0);
iy = (float)(((packedBits >> 13) & 0x1FFF) / 8191.0);
iz = (float)(((packedBits >> 26) & 0x1FFF) / 8191.0);
DryFun
Posts: 27
Joined: Fri Nov 24, 2017 4:54 pm

Re: ParaWorld vertex unpacking

Post by DryFun »

Yes, it should be the next step

Code: Select all

        public static Vertex FromUInt64(ulong packedBits, BoundingBox boundingBox)
        {
            int ix, iy, iz;
            float x, y, z;

            ix = (int)((packedBits >> 0) & 0x1FFF);
            iy = (int)((packedBits >> 13) & 0x1FFF);
            iz = (int)((packedBits >> 26) & 0x1FFF);

            x = ix * (boundingBox.max.X - boundingBox.min.X) / MAX_VALUE_13BITS + boundingBox.min.X;
            y = iy * (boundingBox.max.Y - boundingBox.min.Y) / MAX_VALUE_13BITS + boundingBox.min.Y;
            z = ix * (boundingBox.max.Z - boundingBox.min.Z) / MAX_VALUE_13BITS + boundingBox.min.Z;

            return new Vertex(x, y, z);
        }
DryFun
Posts: 27
Joined: Fri Nov 24, 2017 4:54 pm

Re: ParaWorld vertex unpacking

Post by DryFun »

Thanks
Acewell wrote:looks like could be a typo in Vertex.cs on line 61
https://github.com/BlasSoriano/Paraworl ... /Vertex.cs

Code: Select all

z = ix * (boundingBox.max.Z - boundingBox.min.Z) / MAX_VALUE_13BITS + boundingBox.min.Z;

should be :?:

Code: Select all

z = iz * (boundingBox.max.Z - boundingBox.min.Z) / MAX_VALUE_13BITS + boundingBox.min.Z;


It was so stupid...