Jump to content
  • Advertisement
Sign in to follow this  
AhmedSaleh

Remove Triangles from ogre mesh

Recommended Posts

I'm having a ray to intersection and getting an intersection point, then I compare a condition. I would like to remove that particular triangle from the mesh.

In the RayCasting function, when I get hit, I save three variables u1,u2,u3 which are the indices of the triangle that has a hit.

Ogre::Ray ray;
                ray.setOrigin(Ogre::Vector3( ray_pos.x, ray_pos.y, ray_pos.z));
                ray.setDirection(Ogre::Vector3(ray_dir.x, ray_dir.y, ray_dir.z));
                Ogre::Vector3 result;

                RaycastFromPoint(ray.getOrigin(), ray.getDirection(), result, u1, u2, u3);
                float pointZ = out.pointlist[(3*i)+2];

                if(result.z < pointZ)
                {
                    std::cout << "Remove edge "<< u1 << " "<< u2 << " "<< u3 << std::endl;
                    Utility::DebugPrimitives::drawSphere( result, 0.3f , "RayMesh"+std::to_string(counter), "SimpleColors/SolidGreen" );

                    cntEdges++;
                    indices = static_cast<uint16_t *>(indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));

                    for (int i = 0; i<out.numberofedges; i++)
                    {
                        if(indices[i] == u1 || indices[i] == u2 || indices[i] == u3)
                        {
                            continue;
                        }

                        out.edgelist[i] = indices[i];


                    }
                    indexBuffer->unlock();


                    indices = static_cast<uint16_t *>(indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));

                    for (int i = 0; i<numEdges - cntEdges; i++)
                    {
                        indices[i] = out.edgelist[i];
                    }

                    indexBuffer->unlock();

                }

Share this post


Link to post
Share on other sites
Advertisement

You just need to erase those indices (u1, u2, and u3) from your indices list and resubmit/update it on the GPU.  You need to leave the vertices as they're still used by other indices no doubt, though you can verify this if you want to save that tiny bit of memory.

Share this post


Link to post
Share on other sites

I don't know Ogre or your code.  You don't show enough for me to deduce what you're doing.  Is indices a std::vector of unsigned int's?  What is the type of the u1, u2 and u3 variables?

If indices is a vector, look up std::vector::erase.

Share this post


Link to post
Share on other sites

I'm not sure why you're using a dynamically allocated C array when you're using C++ which has a perfectly fine working and easier to work with array class (std::vector).  I would move your code over to this and it will become a whole lot easier.  Otherwise here is some code (the accepted answer has the green check mark next to it) on one way to remove your elements: https://stackoverflow.com/questions/9246165/how-to-remove-elements-from-dynamically-allocated-array?noredirect=1&lq=1

Though, again, I would just translate your existing code to use std::vector<uint32_t> indices;  If something needs access to the raw array pass in &indices[0].  And erase elements with indices.erase( indices.begin() + u1 );, etc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!