Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Vertexdata and Indexdata Questions

Author
Message
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 28th Jan 2015 23:55
Hi guys

How do you retrieve vertex positions of a face your hitting without using memblocks?

Since I need to face test lots of objects I can't make a memblock of all of them on the fly.

What is the difference between an object that does and doesn't have indices? How does that affect the object or what your trying to do with it?

Thanks in advance

"Get in the Van!" - Van B
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 28th Jan 2015 23:58
An object with indices can have shared vertices between different faces, if you don't have indices all vertices are unique.
If you use an index list every set of 3 indices make up a triangle; if you use vertices the same thing applies there (such that every set of three concurrent vertices make up a triangle). If you have index data two subsequent vertices does not necessarily belong to the same face.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Jan 2015 00:30
This might interest you: http://forum.thegamecreators.com/?m=forum_view&t=197498&b=1&msg=2359996#m2359996

The only way to do great work is to love what you do -- Steve Jobs
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 29th Jan 2015 00:35 Edited at: 29th Jan 2015 00:46
Rudolpho, I see, so I guess each has there cons and pros?

TheComet, still the same problem, as with your example you use memblock (it's actually the same method I use that I even credited you for in my work). If I wanted to face test for vertices of every object that goes in my world, I can't make a memblock of all of them... or can I? I have no clue how this would affect performance

(old code but it's the same memblock method)


"Get in the Van!" - Van B
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 29th Jan 2015 11:57
Quote: "so I guess each has there cons and pros?"

Not so much, the only con with index data is that it will use some more memory to store the indices and possibly slightly slower operations since it has to look up the actual vertex id's through the index table. For most any situation you will want to use indices still so; my Ziggurat project enforces indices on all meshes to avoid the hassle of having two different mesh layouts.

You can use the get indexdata function to get the vertex id that you can use with the get / set vertex data xxx functions. get vertexdata index count returns the number of indices in the currently locked mesh (lock vertexdata for limb / unlock vertexdata).

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Jan 2015 20:42 Edited at: 30th Jan 2015 04:52
Quote: "What is the difference between an object that does and doesn't have indices? How does that affect the object or what your trying to do with it?"


I'll quickly answer this with an example so there is no confusion. Imagine we wanted to draw a quad. This would require two triangles, so 6 vertices in total:


Assuming we're using DBPs default FVF, that's 36 bytes per vertex, so the quad would be using a total of 216 bytes.

Index buffers become useful when there are a lot of duplicate vertices in a model, and this is almost always the case with any decent model in existence. We can therefore optimise:


Now we're using only 144 bytes of memory for vertices and 3 bytes for indices (one index is an unsigned short in DBP), a total of 147 bytes.

When the GPU renders the object, it will convert the vertexdata/indexdata into an un-indexed vertex stream identical to the first example, which gets fed in to the rendering pipeline.

Quote: "I guess each has there cons and pros?"


Not only do indices save memory and file size, they will also speed up the time it takes to render the object, because the GPU can perform cache optimisations on the vertex data (reading the same vertex a second time will be a LOT faster if it was cached the first time).

The only case in which indices make no sense is when there are no shared vertices.

Quote: "TheComet, still the same problem, as with your example you use memblock (it's actually the same method I use that I even credited you for in my work). If I wanted to face test for vertices of every object that goes in my world, I can't make a memblock of all of them... or can I? I have no clue how this would affect performance"


The problem is, SC_GetFaceHit() returns a face ID, which when multiplied by 3 gives you the un-indexed vertex ID, and it is impossible to reverse lookup to see which index it belongs to.

My suggestion to you is: For every unique object you load, extract the information you require into a DBP array. If the only thing you're interested in about the face being hit are the vertex positions, then you might do something like this:



(obviously you will want to have an array of vertexData() arrays, so you can maintain lists of multiple object's vertices).

This will be more memory efficient than keeping a memblock around because you're only storing the data you're interested in, and it will give you very fast results because you can directly look up the three vertices from the array.

The only way to do great work is to love what you do -- Steve Jobs
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 30th Jan 2015 02:54
Quote: "The problem is, SC_GetFaceHit() returns the un-indexed vertex ID, and it is impossible to reverse lookup to see which index it belongs to."

Not that I can claim direct knowledge of this function but that sounds like some serious misleading naming if that's what it returns.
Wouldn't it make better sense that it refers to the triangle (face) being hit, such that it is composed of the three vertices given by the indices at offsets sc_getFaceHit() * 3 and the two subsequent ones?

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 30th Jan 2015 04:53
@Rudolpho - That's what it does, I said it wrong. Fixed.

The only way to do great work is to love what you do -- Steve Jobs

Login to post a reply

Server time is: 2026-07-05 03:49:15
Your offset time is: 2026-07-05 03:49:15