Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!   (85,499 visits to this link)

    2. News

    1. GTA Online

      1. Find Lobbies & Players
      2. Guides & Strategies
      3. Vehicles
      4. Content Creator
      5. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption 2

    2. Red Dead Redemption

    3. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

Sign in to follow this  
dexyfex

Help with collision polygon format (Bounds/YBN)

Recommended Posts

dexyfex

Hi everyone,

 

I've been working on adding collision mesh display in the CodeWalker app:

unknown.png

 

Unfortunately as you can see, triangles are rendering fine, but I'm having some trouble with the boxes, spheres, cylinders and capsules. Basically spheres are appearing in the wrong places, and most boxes are the wrong orientation and/or size (I think cylinders and capsules will have the same issue but those are not being rendered yet).

 

So does anyone here have any knowledge of the format of these polygons specified in the collision bounds data? (In YBN/WBN files and drawables)

The most detailed structure info I've found about these polygons is at:
https://github.com/Zuiron/FiveM/blob/portability-five/components/rage-formats-x/include/phBound.h (thanks FiveM guys!)
- see the struct phBoundPoly in that file (I'll refer to that from here on). In the sphere, capsule and box union structs, a type value is specified, which the file suggests is 1 for sphere, 2 for capsule, and 3 for box. Which is partly correct, but I've found it's just the lowest 3 bits in that value that defines the type. The rest of the bits in that type value is unknown to me, and seems to maybe contain the data for offsetting the spheres, and orienting the boxes. Unfortunately it's not obvious how though...

As far as I can tell, OpenIV can draw these bounds correctly, so obviously someone has solved this problem already.
Can anyone help?

Thanks!

Share this post


Link to post
Share on other sites
Chipsman

 

struct{    uint16_t type; // 1    uint16_t index;    float radius;} sphere;

index - vertex index which is the center of the sphere

radius - radius of the sphere

 

struct{    uint16_t type; // 2    uint16_t index;    float radius;    int16_t indexB;} capsule;

index - vertex index which is the center of the top hemisphere of the capsule

indexB - vertex index which is the center of the bottom hemisphere of the capsule

radius - the radius of the hemisphere

 

Cylinder has the same structure as a capsule: index and indexB - vertex indices which are the centers of the bases of the cylinder, radius - base radius

 

struct{    uint32_t type; // 3    int16_t indices[4];} box;

indices - vertex indices which form two diagonals of the box bases

 

00TA6EU.png

 

 

p.s.: I don't remember exactly vertices order, so you should check them anyway

Share this post


Link to post
Share on other sites
dexyfex

Thanks Chipsman,

 

I had already assumed most of what you mentioned from that code... However it seems that there is maybe also something else to it.

Here's a better spheres example:
unknown.png

 

The triangle vertices are lining up (almost) perfectly with the rendered models (see the tree trunks), but the spheres here seem to be in the wrong location. I triple checked the spheres are being drawn with their centers at the location specified by the poly's vertex. But obviously they are in the wrong position...


As for boxes, I had noticed that the 4 vertices seemed to specify the opposite diagonal corners, as shown in your pic. But the vertex order does not seem to be consistent. So this means that some boxes render fine but others are all messed up. (At the moment I calculate a quaternion from these vertices to orient my boxes, along with the centroid and the size vectors)

 

Most of this building is defined as boxes, and most of the boxes in it seem to be fine, but obviously my calculation is going wrong.
unknown.png

 

For reference, here's the calculation I'm using to get the box size and orientation:

uint boxType = BitConverter.ToUInt32(bytes, 0);short boxIndex1 = BitConverter.ToInt16(bytes, 4);short boxIndex2 = BitConverter.ToInt16(bytes, 6);short boxIndex3 = BitConverter.ToInt16(bytes, 8);short boxIndex4 = BitConverter.ToInt16(bytes, 10);int i1 = boxIndex1 & 0x7FFF;//this mask seems to be required...int i2 = boxIndex2 & 0x7FFF;int i3 = boxIndex3 & 0x7FFF;int i4 = boxIndex4 & 0x7FFF;Vector3 p1 = verts[i1];Vector3 p2 = verts[i2];Vector3 p3 = verts[i3];Vector3 p4 = verts[i4];Vector3 ax1 = Vector3.Normalize(Vector3.Cross(p2 - p1, p4 - p3));Vector3 ax2 = Vector3.Normalize(Vector3.Cross(p3 - p1, p4 - p2));Vector3 ax3 = Vector3.Normalize(Vector3.Cross(p4 - p1, p2 - p3));float s1 = Math.Abs(Vector3.Dot(ax1, p4 - p1));float s2 = Math.Abs(Vector3.Dot(ax2, p4 - p1));float s3 = Math.Abs(Vector3.Dot(ax3, p2 - p1));Vector3 scale = new Vector3(s1, s2, s3);Quaternion orientation = Quaternion.LookAtLH(Vector3.Zero, ax3, ax2);Vector3 center = (p1 + p2 + p3 + p4) * 0.25f;

I'm just not sure why it would end up with weird quaternions here... I think I wrote it such that as long as they are all diagonally opposite corners it should just work, but there could be some other issue that I'm not seeing. The main thing I did notice though is that the 3 axes I computed don't always seem to be orthogonal, but obviously they should be, if the 4 corners were all corners of a box...

Share this post


Link to post
Share on other sites
Chipsman

The situation with spheres is very strange as for me, I don't do anything special in openIV and it renders them as they should be rendered. Judging by your screenshots it looks like the pivot point of your sphere is not located in the center of it (looks like it is somewhere at AABB.Max or so)

 

As I remember I also had problems with boxes rotation in due time, and then I decided just to generate box in world coordinates at once. Primitive algorithm:

1) calculate the center of the top diagonal (c1)

2) calculate the center of the bottom diagonal (c2)

3) calculate orientation vector c1-c2=c

4) translate two top points along the vector -c

5) translate two bottom points along the vector +c

6) that's all, we have 4 vertices of the top base and 4 vertices of the bottom base, now we can generate faces

Edited by Chipsman

Share this post


Link to post
Share on other sites
dexyfex

Thanks again...

I found out eventually the problem with the spheres.. It was a silly mistake, I was using the bounds base class position vector rather than the geometry subclass position vector. Seems strange that there would be two (slightly) different position vectors. Perhaps something to do with the BVH, or bounding boxes..?

I also managed to get the boxes drawing correctly, by using an algorithm very similar to what you described. Your approach worked well to generate individual triangles to make up the boxes, but I wanted to use an instanced rendering approach, so I needed a more compact form to represent the box. So using your approach I calculated the 3 vertices adjacent to vertex 1 (ie connected by an edge), which then I use like a 3x3 matrix to finally position the vertices to be rendered (rather than using a quaternion).

unknown.png
(Screenshot of correct collision boxes)

I still need to implement the cylinders and capsules but I think they should be fairly simple in comparison to the boxes.

Share this post


Link to post
Share on other sites
Chipsman

I was using the bounds base class position vector rather than the geometry subclass position vector. Seems strange that there would be two (slightly) different position vectors. Perhaps something to do with the BVH, or bounding boxes..?

As I understand, the first one is just the center of AABB, the second one - pivot point of the geometry, in most cases they are the same but can be different.

Share this post


Link to post
Share on other sites
dexyfex

It just seems a bit odd since I thought the vertex data would have to always be inside the bounding box. I guess R* have their reasons though! (perhaps the vertex data does not cover the full 16-bit range).

Still on-topic I think - I've been searching for a while to find a complete list of all the material IDs and names (and colours) to use.. Do you know if there is one available anywhere? Also does OpenIV use colours from game data or are they just chosen for the material name? I guess it would be nice to have the same colours in my app.
The closest I've found to a list of names corresponding to the IDs has been in the NY to V converter at: (it's not complete)
https://github.com/Zuiron/FiveM/blob/portability-five/components/rage-formats-x/include/convert/phBound_ny_five.h

Share this post


Link to post
Share on other sites
_CP_

It's in materials.dat
update\update.rpf\common\data\materials\materials.dat

Share this post


Link to post
Share on other sites
dexyfex

Ah thanks! I guess I should have found that one already :)
A bit unfortunate in this case that it doesn't define a colour for the materials though...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.