Horde3D

Next-Generation Graphics Engine
It is currently 16.04.2024, 11:06

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Get Vertex Location
PostPosted: 12.12.2011, 04:24 
Offline

Joined: 14.07.2011, 02:18
Posts: 20
I'm hoping to use collision meshes for a game engine that I'm working on and I was curious if Horde3D has some method for retrieving vertex locations. I'm guessing that I'd use h3dFineNode(Mesh), though I don't know if I can get specific vertices from that. Thank you in advance!

On a side not, if anyone could point me to a good tutorial on content creation for Horde, I'd appreciate it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Vertex Location
PostPosted: 12.12.2011, 09:00 
Offline

Joined: 17.11.2009, 17:00
Posts: 205
Location: Russia, Moscow
Hi, Elnof.
If you wish to get vertex data from mesh, you can find the code here.
I should warn you that the code is untested. You can find more detailed code in Horde Bullet Physics Integration.


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Vertex Location
PostPosted: 12.12.2011, 21:50 
Offline

Joined: 14.07.2011, 02:18
Posts: 20
Sweet. Thank you. I'll look this over as soon as I have time.

I glanced at it and noticed that the code assumed that there would only be one mesh per model. Getting the handle for various meshes is just a matter of changing the index in h3dGetNodeChild(model, index), right?


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Vertex Location
PostPosted: 13.12.2011, 08:31 
Offline

Joined: 17.11.2009, 17:00
Posts: 205
Location: Russia, Moscow
Yes. You can do something like that:
Code:
   h3dFindNodes(H3DRootNode, "model_name", H3DNodeTypes::Mesh); // find your mesh
   H3DNode mesh = h3dGetNodeFindResult(0);   
       
   int i = 0;
   H3DNode childMesh = 0;
   while( ( childMesh = h3dGetNodeChild( mesh, i++ ) ) != 0 )
   {
        // your code here
   }


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Vertex Location
PostPosted: 15.01.2012, 09:04 
Offline

Joined: 14.07.2011, 02:18
Posts: 20
I have that code mostly working now (just some simple problems I should be able to figure out). Thank you for linking it to me.


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Vertex Location
PostPosted: 15.01.2012, 23:29 
Offline

Joined: 14.07.2011, 02:18
Posts: 20
Quick question:
Code:
unsigned int numVertices = h3dGetNodeParamI(mesh, H3DMesh::VertREndI) - h3dGetNodeParamI(mesh, H3DMesh::VertRStartI) + 1;
In my model with 40 verticies, numVertices is equal to 120. I assume that's because the vertex index is only a single dimension so numVertices = vertices * 3? However, when I loop through to put nodes a the vertices, I have to multiply numVertices by three again or I don't get them all.
Code:
for(int i = 0; i < numVertices * 3; i += 3) {
    H3DNode newbox = h3dAddNodes(holder, boxres);
    h3dSetNodeTransform(newbox, sx * vertexBase[i], sy * vertexBase[i + 1], sz * vertexBase[i + 2], 0, 0, 0, .1, .1, .1);
}


Why is that? All the vertices are correct, so I'm not sure whether I'm using the vertex index incorrectly or whether the geometry resource has duplicates.


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Vertex Location
PostPosted: 16.01.2012, 10:10 
Offline

Joined: 17.11.2009, 17:00
Posts: 205
Location: Russia, Moscow
In the Bullet Physics module getting vertices from mesh was handled like this:
Code:
// Create new mesh in physics engine
            m_btTriangleMesh = new btTriangleMesh();
            int offset = 3;
            //if (triangleMode == 5) // Triangle Strip
            //   offset = 1;

            // copy mesh from graphics to physics
            bool index16 = false;
            if (TriangleBase16)
               index16 = true;

            for (unsigned int i = 0; i < numTriangleIndices - 2; i+=offset)
               {
                  unsigned int index1 = index16 ? (TriangleBase16[i]   - vertRStart) * 3 : (TriangleBase32[i]   - vertRStart) * 3;
                  unsigned int index2 = index16 ? (TriangleBase16[i+1] - vertRStart) * 3 : (TriangleBase32[i+1] - vertRStart) * 3;
                  unsigned int index3 = index16 ? (TriangleBase16[i+2] - vertRStart) * 3 : (TriangleBase32[i+2] - vertRStart) * 3;

                  m_btTriangleMesh->addTriangle(
                     btVector3(vertexBase[index1], vertexBase[index1+1], vertexBase[index1+2] ),
                     btVector3(vertexBase[index2], vertexBase[index2+1], vertexBase[index2+2] ),
                     btVector3(vertexBase[index3], vertexBase[index3+1], vertexBase[index3+2] )
                  );
               }   

So basically your first step is to get triangle indices and only then you can get the vertex.


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Vertex Location
PostPosted: 19.01.2012, 01:52 
Offline

Joined: 14.07.2011, 02:18
Posts: 20
I'm getting the correct number of faces now, and I suppose that's what really matters. Thank you.


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Vertex Location
PostPosted: 24.01.2012, 23:51 
Offline

Joined: 14.07.2011, 02:18
Posts: 20
The geometry resource will not change based on animations, correct?

Edit:

The geometry does have duplicate vertices. Is there a reason for this?
Code:
Vertex Location @ Index:

(1, 1, -1) @ 0
(-1, 1, 1) @ 3
(0.999999, 1, 1) @ 6
---
(1, 1, -1) @ 0
(-1, 1, -1) @ 9
(-1, 1, 1) @ 3
---
(1, -1, 1) @ 12
(0.999999, 1, 1) @ 15
(-1, 1, 1) @ 18
---
(1, -1, 1) @ 12
(-1, 1, 1) @ 18
(-1, -1, 1) @ 21
---
(1, -1, -1) @ 24
(1, -1, 1) @ 27
(-1, -1, 1) @ 30
---
(1, -1, -1) @ 24
(-1, -1, 1) @ 30
(-1, -1, -1) @ 33
---
(1, -1, -1) @ 36
(0.999999, 1, 1) @ 39
(1, -1, 1) @ 42
---
(1, -1, -1) @ 36
(1, 1, -1) @ 45
(0.999999, 1, 1) @ 39
---
(-1, -1, 1) @ 48
(-1, 1, 1) @ 51
(-1, 1, -1) @ 54
---
(-1, -1, 1) @ 48
(-1, 1, -1) @ 54
(-1, -1, -1) @ 57
---
(1, 1, -1) @ 60
(-1, -1, -1) @ 63
(-1, 1, -1) @ 66
---
(1, 1, -1) @ 60
(1, -1, -1) @ 69
(-1, -1, -1) @ 63
---


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 16 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® Forum Software © phpBB Group