Search in sources :

Example 1 with Vertex

use of eu.mihosoft.vrl.v3d.Vertex in project FXyzLib by Birdasaur.

the class CSGMesh method createCSGMesh.

private TriangleMesh createCSGMesh() {
    List<Vertex> vertices = new ArrayList<>();
    List<List<Integer>> indices = new ArrayList<>();
    listVertices.clear();
    primitive.getPolygons().forEach(p -> {
        List<Integer> polyIndices = new ArrayList<>();
        p.vertices.forEach(v -> {
            if (!vertices.contains(v)) {
                vertices.add(v);
                listVertices.add(new Point3D((float) v.pos.x, (float) v.pos.y, (float) v.pos.z));
                polyIndices.add(vertices.size());
            } else {
                polyIndices.add(vertices.indexOf(v) + 1);
            }
        });
        indices.add(polyIndices);
    });
    textureCoords = new float[] { 0f, 0f };
    listTextures.clear();
    listFaces.clear();
    indices.forEach(pVerts -> {
        int index1 = pVerts.get(0);
        for (int i = 0; i < pVerts.size() - 2; i++) {
            int index2 = pVerts.get(i + 1);
            int index3 = pVerts.get(i + 2);
            listTextures.add(new Face3(0, 0, 0));
            listFaces.add(new Face3(index1 - 1, index2 - 1, index3 - 1));
        }
    });
    int[] faceSmoothingGroups = new int[listFaces.size()];
    smoothingGroups = faceSmoothingGroups;
    return createMesh();
}
Also used : Vertex(eu.mihosoft.vrl.v3d.Vertex) Point3D(org.fxyz.geometry.Point3D) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Face3(org.fxyz.geometry.Face3)

Aggregations

Vertex (eu.mihosoft.vrl.v3d.Vertex)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Face3 (org.fxyz.geometry.Face3)1 Point3D (org.fxyz.geometry.Point3D)1