Search in sources :

Example 1 with Vector3d

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

the class MeshUtils method mesh2CSG.

public static CSG mesh2CSG(Mesh mesh) throws IOException {
    List<Polygon> polygons = new ArrayList<>();
    List<Vector3d> vertices = new ArrayList<>();
    if (mesh instanceof TriangleMesh) {
        // Get faces
        ObservableFaceArray faces = ((TriangleMesh) mesh).getFaces();
        int[] f = new int[faces.size()];
        faces.toArray(f);
        // Get vertices
        ObservableFloatArray points = ((TriangleMesh) mesh).getPoints();
        float[] p = new float[points.size()];
        points.toArray(p);
        // convert faces to polygons
        for (int i = 0; i < faces.size() / 6; i++) {
            int i0 = f[6 * i], i1 = f[6 * i + 2], i2 = f[6 * i + 4];
            vertices.add(new Vector3d(p[3 * i0], p[3 * i0 + 1], p[3 * i0 + 2]));
            vertices.add(new Vector3d(p[3 * i1], p[3 * i1 + 1], p[3 * i1 + 2]));
            vertices.add(new Vector3d(p[3 * i2], p[3 * i2 + 1], p[3 * i2 + 2]));
            polygons.add(Polygon.fromPoints(vertices));
            vertices = new ArrayList<>();
        }
    }
    return CSG.fromPolygons(new PropertyStorage(), polygons);
}
Also used : PropertyStorage(eu.mihosoft.vrl.v3d.PropertyStorage) TriangleMesh(javafx.scene.shape.TriangleMesh) ArrayList(java.util.ArrayList) ObservableFaceArray(javafx.scene.shape.ObservableFaceArray) Vector3d(eu.mihosoft.vrl.v3d.Vector3d) Polygon(eu.mihosoft.vrl.v3d.Polygon) ObservableFloatArray(javafx.collections.ObservableFloatArray)

Aggregations

Polygon (eu.mihosoft.vrl.v3d.Polygon)1 PropertyStorage (eu.mihosoft.vrl.v3d.PropertyStorage)1 Vector3d (eu.mihosoft.vrl.v3d.Vector3d)1 ArrayList (java.util.ArrayList)1 ObservableFloatArray (javafx.collections.ObservableFloatArray)1 ObservableFaceArray (javafx.scene.shape.ObservableFaceArray)1 TriangleMesh (javafx.scene.shape.TriangleMesh)1