Hi
I've been feeling a little bad about posting here so much. I tried to avoid it, but I just can't figure it out. I'm trying to delete the indices and vertices that compose a cube within a mesh that I used Lonesome Ducky's mesh combiner to meld together. From reading the forums here, I learnt that a cube is made of 12 vertices and 36 indices. I managed to erase that from the mesh fine, but not the cube I wanted to remove (the one highlighted by the triangle selector). So I made a few loops and tried to reach the right vertices and indices within the array, but it always seems to erase from the front. smso wrote me some code in another thread to find the right index, and it seemed to work but only for 1 of the indices. Then it stopped working entirely and I couldn't revert it back.
Another strange problem is that inversing hitTriangle's coordinates never seems to change anything. p0 and ptA are always the same.
I made a youtube video of my problem, to hopefully help. Here's my code. It's within the event receiver for a right click.
Code: Select all
case EMIE_RMOUSE_PRESSED_DOWN:
if(World.mapcreator == 1 || World.running == 1 && selectedSceneNode && Player->iequipped == 0) {
irr::scene::IMesh *mesh = selectedSceneNode->getMesh();
irr::scene::CMeshBuffer<S3DVertex> *buffer =
(irr::scene::CMeshBuffer<S3DVertex>*)mesh->getMeshBuffer(0);
std::cout << buffer->getIndexCount() << std::endl << buffer->getVertexCount() << std::endl;
irr::core::vector3df ptA = hitTriangle.pointA;
irr::core::vector3df ptB = hitTriangle.pointB;
irr::core::vector3df ptC = hitTriangle.pointC;
irr::core::matrix4 matrix = selectedSceneNode->getAbsoluteTransformation();
irr::core::matrix4 inverse;
irr::core::vector3df p0, p1, p2, intersectioninverse;
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: %.2f %.2f %.2f\n", ptA.X, ptA.Y, ptA.Z); //Util::print(ptA);
printf("ptB: %.2f %.2f %.2f\n", ptB.X, ptB.Y, ptB.Z);
printf("ptC: %.2f %.2f %.2f\n", ptC.X, ptC.Y, ptC.Z);
printf("p0: %.2f %.2f %.2f\n", p0.X, p0.Y, p0.Z); //Util::print(p0);
printf("p1: %.2f %.2f %.2f\n", p1.X, p1.Y, p1.Z);
printf("p2: %.2f %.2f %.2f\n", p2.X, p2.Y, p2.Z);
}
else { puts("not found"); p0 = ptA; p1 = ptB; p2 = ptC; }
selectedSceneNode->setDebugDataVisible(irr::scene::EDS_BBOX);
int i, q, icount, vcount;
icount = buffer->getIndexCount();
vcount = buffer->getVertexCount();
printf("Intersection: %.2f %.2f %.2f\np0: %.2f %.2f %.2f\np1: %.2f %.2f %.2f\np2: %.2f %.2f %.2f\n",
intersection.X, intersection.Y, intersection.Z, p0.X, p0.Y, p0.Z, p1.X, p1.Y, p1.Z, p2.X, p2.Y, p2.Z);
if(p0.equals(intersection)) {
puts("pto == intersection");
}
irr::core::vector3df bpos;
for(i=0, q=0; i<icount; i+=36, q+=12) {
bpos = buffer->getPosition(i);
//printf("%d: %.2f, %.2f, %.2f\np0: %.2f, %.2f, %.2f\n", i, bpos.X, bpos.Y, bpos.Z, p0.X, p0.Y, p0.Z);
if(bpos.X > intersection.X && bpos.X < intersection.X+50) {
if(bpos.Z > intersection.Z && bpos.Z < intersection.Z+50) {
puts("here?");
for(int j = 0; j<36; j++)
buffer->Indices.erase(i+j);
//buffer->Indices.erase(i);
for(int j = 0; j<12; j++)
buffer->Vertices.erase(q+j);
}
}
}
irr::scene::ITriangleSelector *selector = selectedSceneNode->getTriangleSelector();
selectedSceneNode->setTriangleSelector(0);
g_selector->removeTriangleSelector(selector);
buffer->recalculateBoundingBox();
selector = g_smgr->createOctreeTriangleSelector(selectedSceneNode->getMesh(), selectedSceneNode);
selectedSceneNode->setTriangleSelector(selector);
g_selector->addTriangleSelector(selector);
selector->drop();
}
break;