ZenHAX

Free Game Research Forum | Official QuickBMS support | twitter @zenhax | SSL HTTPS://zenhax.com
It is currently Tue Aug 14, 2018 8:05 pm

All times are UTC




Post new topic  Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Thu Apr 05, 2018 2:40 pm 

Joined: Fri Nov 24, 2017 4:54 pm
Posts: 26
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?


Top
   
PostPosted: Thu Apr 05, 2018 7:14 pm 
User avatar

Joined: Mon Sep 15, 2014 5:13 am
Posts: 37
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.


Top
   
PostPosted: Thu Apr 05, 2018 7:37 pm 

Joined: Fri Nov 24, 2017 4:54 pm
Posts: 26
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


Top
   
PostPosted: Thu Apr 05, 2018 9:04 pm 
User avatar

Joined: Mon Sep 15, 2014 5:13 am
Posts: 37
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?


Top
   
PostPosted: Fri Apr 06, 2018 3:28 am 

Joined: Fri Nov 24, 2017 4:54 pm
Posts: 26
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
Attachment:
hex.txt [4.44 KiB]
Downloaded 32 times


Top
   
PostPosted: Fri Apr 06, 2018 7:45 am 
User avatar

Joined: Fri Aug 08, 2014 1:06 am
Posts: 511
looks like could be a typo in Vertex.cs on line 61
https://github.com/BlasSoriano/Paraworl ... /Vertex.cs
Code:
z = ix * (boundingBox.max.Z - boundingBox.min.Z) / MAX_VALUE_13BITS + boundingBox.min.Z;

should be :?:
Code:
z = iz * (boundingBox.max.Z - boundingBox.min.Z) / MAX_VALUE_13BITS + boundingBox.min.Z;

_________________
Quickbms.com link thread
Search bms scripts


Top
   
PostPosted: Fri Apr 06, 2018 8:45 am 
User avatar

Joined: Mon Sep 15, 2014 5:13 am
Posts: 37
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:
ix = (float)(((packedBits >> 0) & 0x1FFF) / 8191.0);
iy = (float)(((packedBits >> 13) & 0x1FFF) / 8191.0);
iz = (float)(((packedBits >> 26) & 0x1FFF) / 8191.0);


Top
   
PostPosted: Fri Apr 06, 2018 9:53 am 

Joined: Fri Nov 24, 2017 4:54 pm
Posts: 26
Yes, it should be the next step
Code:
        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);
        }


Top
   
PostPosted: Sat Apr 07, 2018 5:55 am 

Joined: Fri Nov 24, 2017 4:54 pm
Posts: 26
Thanks
Acewell wrote:
looks like could be a typo in Vertex.cs on line 61
https://github.com/BlasSoriano/Paraworl ... /Vertex.cs
Code:
z = ix * (boundingBox.max.Z - boundingBox.min.Z) / MAX_VALUE_13BITS + boundingBox.min.Z;

should be :?:
Code:
z = iz * (boundingBox.max.Z - boundingBox.min.Z) / MAX_VALUE_13BITS + boundingBox.min.Z;


It was so stupid...


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 9 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Limited