Hi. Given a mesh like a box that have index, position, normals and tex. buffers. Is there a way to iterate over the faces (a triangle of three vertices) of the mesh and delete just those faces from the mesh given some filter?
For example, the box have the faces with the normals:
0 normal: (0.0, 0.0, 1.0) (0.0, 0.0, 1.0) (0.0, 0.0, 1.0)
1 normal: (0.0, 0.0, 1.0) (0.0, 0.0, 1.0) (0.0, 0.0, 1.0)
2 normal: (0.0, -1.0, 0.0) (0.0, -1.0, 0.0) (0.0, -1.0, 0.0)
3 normal: (0.0, -1.0, 0.0) (0.0, -1.0, 0.0) (0.0, -1.0, 0.0)
4 normal: (-1.0, 0.0, 0.0) (-1.0, 0.0, 0.0) (-1.0, 0.0, 0.0)
5 normal: (-1.0, 0.0, 0.0) (-1.0, 0.0, 0.0) (-1.0, 0.0, 0.0)
6 normal: (0.0, 0.0, -1.0) (0.0, 0.0, -1.0) (0.0, 0.0, -1.0)
7 normal: (0.0, 0.0, -1.0) (0.0, 0.0, -1.0) (0.0, 0.0, -1.0)
8 normal: (1.0, 0.0, 0.0) (1.0, 0.0, 0.0) (1.0, 0.0, 0.0)
9 normal: (1.0, 0.0, 0.0) (1.0, 0.0, 0.0) (1.0, 0.0, 0.0)
10 normal: (0.0, 1.0, 0.0) (0.0, 1.0, 0.0) (0.0, 1.0, 0.0)
11 normal: (0.0, 1.0, 0.0) (0.0, 1.0, 0.0) (0.0, 1.0, 0.0)
I want to delete all faces with z=-1, i.e. all faces that are facing downwards. That’s not the same as culling, because it’s independent from the camera. So even if you rotate the camera those faces should not be there.
I just tried something like this below but the results were terrible.
var model = modelsg.get(ModelCacheObject.class, ModelCacheObject.OBJECT_TYPE, mb.getObject());
var mesh = ((Geometry) ((Node) model.model).getChild(0)).getMesh();
var bindex = mesh.getShortBuffer(Type.Index).rewind();
var bnormal = mesh.getFloatBuffer(Type.Normal).rewind();
var bpos = mesh.getFloatBuffer(Type.Position).rewind();
var btex = mesh.getFloatBuffer(Type.TexCoord).rewind();
int delta = cindex.position();
for (int i = 0; i < bindex.limit() / 3; i++) {
short i0 = (short) (bindex.get() * 3);
short i1 = (short) (bindex.get() * 3);
short i2 = (short) (bindex.get() * 3);
var n0 = temp.vect1.set(bnormal.get(i0), bnormal.get(i0 + 1), bnormal.get(i0 + 2));
var n1 = temp.vect2.set(bnormal.get(i1), bnormal.get(i1 + 1), bnormal.get(i1 + 2));
var n2 = temp.vect3.set(bnormal.get(i2), bnormal.get(i2 + 1), bnormal.get(i2 + 2));
n0.addLocal(n1.addLocal(n2)).divideLocal(3f);
if (n0.z < 0.0f) {
continue;
}
cindex.put((short) (i0 + delta));
cindex.put((short) (i1 + delta));
cindex.put((short) (i2 + delta));
System.out.printf("%d normal: %s %s %s\n", i, n0, n1, n2); // TODO
}
copyNormal(mb, mesh, cnormal);
copyTex(mb, mesh, ctex);
copyPos(mb, mesh, cpos, transform, w, h, d);
Deleted faces:
All faces: