It is currently Sat Aug 22, 2020 4:29 am


All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How to adjust vertices and indices when splitting meshes?
PostPosted: Sat Jun 01, 2013 1:31 pm 
User avatar

Joined: Sun Apr 14, 2013 12:47 am
Posts: 30
Location: Northern Tablelands, NSW, Australia
Ok, I've figured out a system for dividing the larger-than-65000-indices extracted mesh into smaller sections (less than ~65000 indices) so they'll work in DBPro. What I do is this:

1. Extract mesh.
2. Run through entire mesh, 3 indices at a time.
3. Check triangle (set of 3 indices) for uniformity (fully uniform, 1-2 non, 1-3 non, 2-3 non and fully nonuniform....for testing I only actually check for fully uniform).
4. Search through an array containing sets of meshes, each with a different material, and find if one with this material already exists; if it doesn't, create one; if it does, add this triangle to it.
5. When each mesh in the array gets above about ~65000 indices, it's moved to the "completed meshes" array.

That system works well (I think) for dividing the mesh into the largest chunks possible. The easier method would be to just extract small sections (small enough that they will probably never go above 65000 indices) and split that mesh based on material (actually that probably wouldn't be easier), but that would mean probably 10x more draw calls and the small chance that one of the meshes might actually go above 65000 indices. So I don't do it that way.

The problem isn't that bit. The problem is when I go to use the divided meshes. The indices still point to the full-sized extracted mesh's vertices. Let me explain a bit better with this example:

I have a set of 3 indices. They hold the values 74,371, 9,476 and 35,985 (it's a very big triangle, ok? ;)). These indices have been pulled from the single large extracted mesh and stuck into one of the smaller single-material meshes. Now I am creating the visual mesh, so I need to reassign those vertices as 1, 2 and 3 and have every index that references the old values (74,371, 9,476 and 35,985) now reference the new values (1, 2 and 3). How do I do this without having to run through arrays that are 65000 elements big more than once? Should I split the mesh up differently? Should I be recording any information during the mesh splitting (I can do that easily)?

I don't know whether you've come across this kind of problem before (or whether you even understand me) but I hope you have....actually I only hope you can help me ;)

Clonkex


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to adjust vertices and indices when splitting meshes
PostPosted: Sun Jun 02, 2013 6:55 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
You should take a look at a function called 'extractSubset' which is in SurfaceMesh.inl here: https://bitbucket.org/volumesoffun/poly ... lop#cl-396

I'm not sure if it's an optimal approach, but it makes use of a 'index map' to convert old index values to new ones. This is just an array of integers, where the positin in the array represents the old index value and the value at that position represents the new index value. So if the old index is 12345 and the new index is 42 then 'indexMap[12345] = 42'. This makes it very easy o look up the new index corresponding to an old index.

At least, that's what I recall. It's an old function so maybe I haven't explained it right.

This 'extractSubset' function is probably pretty relevant to you... I should have mentioned it before but I haven't used it for a while so I forgot about it :?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to adjust vertices and indices when splitting meshes
PostPosted: Sun Jun 02, 2013 1:02 pm 
User avatar

Joined: Sun Apr 14, 2013 12:47 am
Posts: 30
Location: Northern Tablelands, NSW, Australia
Hmm....interesting. The code could perhaps be adapted for my purpose (it wouldn't currently work because I don't extract a "subset" per-region but per-triangle), but I have a couple of questions:

1. What exactly does the setMaterials parameter do? I can't understand that bit of the code :?
2. Is there any protection against vertex duplication? Each vertex can be (and almost always is, as far as I know) referenced by multiple indices. It seems to me that the function simply adds every vertex referenced by every index, even if that vertex has already been added previously :( Does SurfaceMesh have built-in protection against this?

In the meantime I'll continue my own experiments and see what I can come up with.

Thanks,
Clonkex

P.S. At first I was wondering how it could be accessing m_vecTriangleIndices and then I realised the function itself was in the SurfaceMesh class ;)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to adjust vertices and indices when splitting meshes
PostPosted: Mon Jun 03, 2013 12:34 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Clonkex wrote:
1. What exactly does the setMaterials parameter do? I can't understand that bit of the code :?


As I recall, the idea behind the function is that you can provide an input mesh which contains many different materials, and then generate an output mesh which only contains those materials which you are interested in (other triangles are discarded). The 'setMaterial' parameter is used to specify which materials these are.

Clonkex wrote:
2. Is there any protection against vertex duplication? Each vertex can be (and almost always is, as far as I know) referenced by multiple indices. It seems to me that the function simply adds every vertex referenced by every index, even if that vertex has already been added previously :( Does SurfaceMesh have built-in protection against this?


The surface extractors avoid duplicated vertices by using arrays to track when a particular vertex already exists, so the meshes they generate should have multiple indices referencing the same vertex (as you say).

I think this property is maintained by the extractSubset() code. The code fills the 'indexMap' with '-1' in each element, and always checks this value before adding a vertex. But the code is a little confusing so I'm not certain!

Clonkex wrote:
P.S. At first I was wondering how it could be accessing m_vecTriangleIndices and then I realised the function itself was in the SurfaceMesh class ;)


Nope, I've just lazily declared them as public :-) Be aware there's two versions of extractSubset() - one is a member (commented out) and the other is a free function. To be honest this mesh code needs some refactoring but it's not high priority at the moment.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to adjust vertices and indices when splitting meshes
PostPosted: Mon Jun 03, 2013 1:43 pm 
User avatar

Joined: Sun Apr 14, 2013 12:47 am
Posts: 30
Location: Northern Tablelands, NSW, Australia
Ah, I see.

Quote:
As I recall, the idea behind the function is that you can provide an input mesh which contains many different materials, and then generate an output mesh which only contains those materials which you are interested in (other triangles are discarded). The 'setMaterial' parameter is used to specify which materials these are.


That's what I would have assumed. Good, could be useful.

Quote:
The surface extractors avoid duplicated vertices by using arrays to track when a particular vertex already exists, so the meshes they generate should have multiple indices referencing the same vertex (as you say).

I think this property is maintained by the extractSubset() code. The code fills the 'indexMap' with '-1' in each element, and always checks this value before adding a vertex. But the code is a little confusing so I'm not certain!


I only glanced over that bit before and thought it was checking to see that the vertex wasn't -1, but it makes more sense now. That's brilliant! I'll begin that adaptation right away! As far as I can see, this function can be modified to fit my application perfectly :D Well actually....I should only need a few parts of your function...excellent, much faster that way.

Ahh it's FREEZING in here! :? Why are you not roaring yet, fire?! :x

Thanks for your help (again) :D
Clonkex


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to adjust vertices and indices when splitting meshes
PostPosted: Tue Jun 04, 2013 8:19 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Clonkex wrote:
Ahh it's FREEZING in here! :? Why are you not roaring yet, fire?! :x


Ah, of course, it is winter for you. Glorious sun here in the Netherlands! And we can't often say that...


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


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:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net