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


All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Problem with getVertices()
PostPosted: Wed Apr 17, 2013 8:24 am 
User avatar

Joined: Sun Apr 14, 2013 12:47 am
Posts: 30
Location: Northern Tablelands, NSW, Australia
I currently define the class that will contain the vertices and indices and related mesh information like so:

Code:
class meshInfo
{
public:
   SurfaceMesh<PositionMaterialNormal> *mesh;
   MarchingCubesSurfaceExtractor<LargeVolume<uint8_t>> *surfaceExtractor;
   vector<unsigned int> indices;
   vector<PositionMaterialNormal> vertices;
   meshInfo()
   {
      mesh=NULL; //seem hacky? tough, it works; ignore this as it's used for an unrelated function
      surfaceExtractor=NULL; //also ignore this
   }
};


Actually in the real code I have stuff to support cubic mesh extraction as well but that's irrelevant here. I then do this, except this is normally in a function:

Code:
volume[index].meshData.mesh=new SurfaceMesh<PositionMaterialNormal>;
volume[index].meshData.surfaceExtractor=new MarchingCubesSurfaceExtractor<LargeVolume<uint8_t>>(volume[index].volume,Region(pos1X,pos1Y,pos1Z,pos2X,pos2Y,pos2Z),volume[index].meshData.mesh);
volume[index].meshData.surfaceExtractor->execute();
volume[index].meshData.vertices=volume[index].meshData.mesh->getVertices();
volume[index].meshData.indices=volume[index].meshData.mesh->getIndices();


And that all compiles fine. In a different section I assign some of the voxels a density, and using getNoOfVertices() and getNoOfIndices(), I know there's about 18 vertices and about 96 indices. But when I use the size() function of the volume[index].meshData.vertices vector, it returns 0. I can guarantee I'm using the correct 'index' variable.

What does getVertices() actually return? Data or a pointer? If it's a pointer, that may be the issue, because my vector is assigned the value/pointer of getVertices() in one function and I call .size() in another. If it is a pointer, how would I handle this?

Also, what is the actual format of the meshes returned? I mean, how many indices per vertex? Or does it not work like that? I don't understand well how mesh formats work exactly.

I know I should probably understand all of this a lot better before I try to use it, but to be honest this is by the best way to learn; that is, by doing.

Clonkex


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Problem with getVertices()
PostPosted: Wed Apr 17, 2013 11:39 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
It's not exactly clear to me what's going on but I'll give you some general points. Firtly you should have a look in 'SurfaceMesh.inl' where you will see that the definition of getVertices() and getNoOfVertices() are very simple:

Code:
template <typename VertexType>
const std::vector<VertexType>& SurfaceMesh<VertexType>::getVertices(void) const
{
   return m_vecVertices;
}

template <typename VertexType>
uint32_t SurfaceMesh<VertexType>::getNoOfVertices(void) const
{
   return m_vecVertices.size();
}


So getVertices() returns the actual std::vector which holds the vertex data and it should be valid to assign this to another vector (it's probably not necessary though). getNoOfVertices() just calls the std::vector's size() method as you were doing manually.

Clonkex wrote:
Also, what is the actual format of the meshes returned? I mean, how many indices per vertex? Or does it not work like that? I don't understand well how mesh formats work exactly.


In this paricular case the format of a vertex is specified in the 'PositionMaterialNormal' and basically consists of floats representing the position, material, and normal. The vertex data is then just an std::vector of these vertices.

The interesting part is then the index buffer, which specifies how these vertices are connected to form triangles. Every group of three entries in the index buffer represents a triangle. Each index is just a number telling you which vertex to use. You should probably read a bit more about index and vertex buffers here:

http://rbwhitaker.wikidot.com/index-and-vertex-buffers
http://msdn.microsoft.com/en-us/library/windows/desktop/bb147325(v=vs.85).aspx

Note that zero if a perfectly valid index (it refers to the first entry in the vertex data).

I'm not sure if the above helps... just ask if it's still not clear. Oh, and have a look at the BasicExample because it might help clarify some of this.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Problem with getVertices()
PostPosted: Wed Apr 17, 2013 1:10 pm 
User avatar

Joined: Sun Apr 14, 2013 12:47 am
Posts: 30
Location: Northern Tablelands, NSW, Australia
David Williams wrote:
(it's probably not necessary though)


That's what fixed it for me. It had never occurred to me that I could access the necessary directly through getVertices() function, like so:

Code:
float position=volume[index].meshData.mesh->getVertices()[vertexNumber].getPosition().getX();


That drastically simplified things for me and made my code work :D I still have no idea why it wasn't copying properly but I no longer care ;)

David Williams wrote:
In this paricular case the format of a vertex is specified in the 'PositionMaterialNormal' and basically consists of floats representing the position, material, and normal. The vertex data is then just an std::vector of these vertices.


I understood that bit alright. I actually understood more about how meshes are composed than I thought I did. I just confused myself by thinking that the number of indices (in my case, 96) needed to be divisible by the number of vertices (18), but of course it doesn't. There's only a problem if the number of indices isn't divisible by 3.

David Williams wrote:
The interesting part is then the index buffer, which specifies how these vertices are connected to form triangles. Every group of three entries in the index buffer represents a triangle. Each index is just a number telling you which vertex to use.


Ah good, just as I thought. I was hoping it wasn't something weird that was going to make it difficult to integrate with DBPro, but all is well :) I often struggle to get my head around seemingly simple concepts until someone else (in this case you) explains it, even if they explain in a similar way. My brain sort of freezes up :P

David Williams wrote:
You should probably read a bit more about index and vertex buffers here:

http://rbwhitaker.wikidot.com/index-and-vertex-buffers
http://msdn.microsoft.com/en-us/library ... 25(v=vs.85).aspx


I'll do that because I really need to understand what I'm working with. Thanks for the links :)

David Williams wrote:
I'm not sure if the above helps


It did help, thanks :)

Thank you for helping me over and over again with dumb little things :) You're the best support-person I could hope for, particularly with free software such as PolyVox :D

Clonkex


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Problem with getVertices()
PostPosted: Wed Apr 17, 2013 8:49 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Clonkex wrote:
Thank you for helping me over and over again with dumb little things :) You're the best support-person I could hope for, particularly with free software such as PolyVox :D


Thanks, I try to help where I can. I'm mostly trying to compensate for the fact that the documentation is still rather lacking :-)


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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