public void deleteCommand()
{
if (!topology)
return;
TriangleMesh theMesh = (TriangleMesh) objInfo.getObject();
Vertex vert[] = (Vertex []) theMesh.getVertices();
Edge edge[] = theMesh.getEdges();
Face face[] = theMesh.getFaces();
boolean deleteVert[] = new boolean [vert.length];
boolean deleteFace[] = new boolean [face.length];
// Determine which parts of the mesh to delete.
if (selectMode == POINT_MODE)
{
for (int i = 0; i < deleteVert.length; i++)
deleteVert[i] = selected[i];
for (int i = 0; i < deleteFace.length; i++)
deleteFace[i] = (deleteVert[face[i].v1] || deleteVert[face[i].v2] || deleteVert[face[i].v3]);
}
else if (selectMode == EDGE_MODE)
{
for (int i = 0; i < deleteFace.length; i++)
deleteFace[i] = (selected[face[i].e1] || selected[face[i].e2] || selected[face[i].e3]);
for (int i = 0; i < deleteVert.length; i++)
deleteVert[i] = true;
for (int i = 0; i < deleteFace.length; i++)
if (!deleteFace[i])
deleteVert[face[i].v1] = deleteVert[face[i].v2] = deleteVert[face[i].v3] = false;
}
else
{
for (int i = 0; i < deleteFace.length; i++)
deleteFace[i] = selected[i];
for (int i = 0; i < deleteVert.length; i++)
deleteVert[i] = true;
for (int i = 0; i < deleteFace.length; i++)
if (!deleteFace[i])
deleteVert[face[i].v1] = deleteVert[face[i].v2] = deleteVert[face[i].v3] = false;
}
// Make sure this will still be a valid object.
for (int i = 0; i < vert.length; i++)
{
int e[] = vert[i].getEdges();
int f, fprev = edge[e[0]].f1, breaks = 0;
for (int j = 1; j < e.length; j++)
{
f = (edge[e[j]].f1 == fprev ? edge[e[j]].f2 : edge[e[j]].f1);
if (f == -1)
break;
if (!deleteFace[fprev] && deleteFace[f])
breaks++;
fprev = f;
}
if (!deleteFace[fprev] && (edge[e[0]].f2 == -1 || deleteFace[edge[e[0]].f1]))
breaks++;
int vertFaceCount[] = new int [vert.length];
for (int j = 0; j < face.length; j++)
if (!deleteFace[j])
{
vertFaceCount[face[j].v1]++;
vertFaceCount[face[j].v2]++;
vertFaceCount[face[j].v3]++;
}
boolean strayVert = false;
for (int j = 0; j < vertFaceCount.length; j++)
if (!deleteVert[j] && vertFaceCount[j] == 0)
strayVert = true;
if (breaks > 1 || strayVert)
{
new BStandardDialog("", UIUtilities.breakString(Translate.text("illegalDelete")), BStandardDialog.ERROR).showMessageDialog(this);
return;
}
}
// Find the new lists of vertices and faces.
int newVertCount = 0, newFaceCount = 0;
int newVertIndex[] = new int [vert.length];
for (int i = 0; i < deleteVert.length; i++)
{
newVertIndex[i] = -1;
if (!deleteVert[i])
newVertCount++;
}
for (int i = 0; i < deleteFace.length; i++)
if (!deleteFace[i])
newFaceCount++;
Vertex v[] = new Vertex [newVertCount];
int f[][] = new int [newFaceCount][];
newVertCount = 0;
for (int i = 0; i < vert.length; i++)
if (!deleteVert[i])
{
newVertIndex[i] = newVertCount;
v[newVertCount++] = vert[i];
}
newFaceCount = 0;
for (int i = 0; i < face.length; i++)
if (!deleteFace[i])
f[newFaceCount++] = new int [] {newVertIndex[face[i].v1], newVertIndex[face[i].v2], newVertIndex[face[i].v3]};
// Update the texture parameters.
ParameterValue oldParamVal[] = theMesh.getParameterValues();
ParameterValue newParamVal[] = new ParameterValue [oldParamVal.length];
for (int i = 0; i < oldParamVal.length; i++)
{
if (oldParamVal[i] instanceof VertexParameterValue)
{
double oldval[] = ((VertexParameterValue) oldParamVal[i]).getValue();
double newval[] = new double [newVertCount];
for (int j = 0, k = 0; j < oldval.length; j++)
if (!deleteVert[j])
newval[k++] = oldval[j];
newParamVal[i] = new VertexParameterValue(newval);
}
else if (oldParamVal[i] instanceof FaceParameterValue)
{
double oldval[] = ((FaceParameterValue) oldParamVal[i]).getValue();
double newval[] = new double [newFaceCount];
for (int j = 0, k = 0; j < oldval.length; j++)
if (!deleteFace[j])
newval[k++] = oldval[j];
newParamVal[i] = new FaceParameterValue(newval);
}
else if (oldParamVal[i] instanceof FaceVertexParameterValue)
{
FaceVertexParameterValue fvpv = (FaceVertexParameterValue) oldParamVal[i];
double newval[][] = new double [newFaceCount][3];
for (int j = 0, k = 0; j < fvpv.getFaceCount(); j++)
if (!deleteFace[j])
{
newval[k][0] = fvpv.getValue(j, 0);
newval[k][1] = fvpv.getValue(j, 1);
newval[k][2] = fvpv.getValue(j, 2);
k++;
}
newParamVal[i] = new FaceVertexParameterValue(newval);
}
else
newParamVal[i] = oldParamVal[i].duplicate();
}
// Construct the new mesh.
TriangleMesh newmesh = new TriangleMesh(v, f);
Edge newedge[] = newmesh.getEdges();
newmesh.getSkeleton().copy(theMesh.getSkeleton());
newmesh.copyTextureAndMaterial(theMesh);
newmesh.setSmoothingMethod(theMesh.getSmoothingMethod());
newmesh.setParameterValues(newParamVal);
// Copy over the smoothness values for edges.
for (int i = 0; i < edge.length; i++)
{