Find indices and vertices from triangle selector

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
malloc
Posts: 13
Joined: Sat Feb 04, 2012 7:25 pm

Find indices and vertices from triangle selector

Post by malloc »

I've spent the entire day googling, reading code and trying stuff out. Now I'm absolutely exhausted, but still without a solution to my problem: Erasing the selected triangle from the mesh.

REDDemon's been helping me out, and says that I need to create my own custom triangle selector. Trouble is, I don't know how to do that. Is there no other way?

I've made my CMeshBuffer:

Code: Select all

irr::scene::IMesh *mesh = selectedSceneNode->getMesh();
irr::scene::CMeshBuffer<S3DVertex> *buffer =
        (irr::scene::CMeshBuffer<S3DVertex>*)mesh->getMeshBuffer(0);
Now I to know where the indices and vertices belonging to that triangle are within the buffer, so that I can call erase upon them.

Surely the triangle3df I gave getSceneNodeAndCollisionPointFromRay() has the information inside it somewhere.

Thanks in advance for any help.
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Find indices and vertices from triangle selector

Post by smso »

The points of triangle resulted from collision test are in world space. They have to be transformed to local space of the node. The transformed points are then searched within the mesh.

Code: Select all

        core::vector3df ptA = tri.pointA;
        core::vector3df ptB = tri.pointB;
        core::vector3df ptC = tri.pointC;
       
        core::matrix4 matrix = node->getAbsoluteTransformation();
        core::matrix4 inverse;
        core::vector3df p0, p1, p2;
 
        if (matrix.getInverse(inverse))
        {
                printf("Inverse matrix of node found\n");
                inverse.transformVect(p0, ptA);
                inverse.transformVect(p1, ptB);
                inverse.transformVect(p2, ptC);
 
                printf("ptA: "); Util::print(ptA);
                printf("p0: "); Util::print(p0);
        }
        else { p0 = ptA; p1 = ptB; p2 = ptC; }
 
 
Regards
smso
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Find indices and vertices from triangle selector

Post by REDDemon »

smso wrote:The points of triangle resulted from collision test are in world space. They have to be transformed to local space of the node. The transformed points are then searched within the mesh.
you are assuming every vertex at different coordinates right? this will generally work for lots of cases, but not all cases

and what if there are vertices with the same exact coordinates? (likely to happen very often in a minecraft clone game). will also not works for degenerated meshes with duplicated vertices (unless you take as behaviour to deliberately select all vertices with the same coordinates). The nice thing of a world of cubes is that is highly probable that also all the 3 vertex of a triangle are at the same position of the 3 vertex of another triangle in the adiacent cube.
:(
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Find indices and vertices from triangle selector

Post by smso »

REDDemon wrote:
smso wrote:The points of triangle resulted from collision test are in world space. They have to be transformed to local space of the node. The transformed points are then searched within the mesh.
you are assuming every vertex at different coordinates right? this will generally work for lots of cases, but not all cases

and what if there are vertices with the same exact coordinates? (likely to happen very often in a minecraft clone game). will also not works for degenerated meshes with duplicated vertices (unless you take as behaviour to deliberately select all vertices with the same coordinates). The nice thing of a world of cubes is that is highly probable that also all the 3 vertex of a triangle are at the same position of the 3 vertex of another triangle in the adiacent cube.
:(
I think the points of the collision triangle belong to the same node.

Regards
smso
malloc
Posts: 13
Joined: Sat Feb 04, 2012 7:25 pm

Re: Find indices and vertices from triangle selector

Post by malloc »

Thank you. This seems to be working exactly how I want it to.
Post Reply