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();
}