2

I develop a java application to generate a 3D object as a .obj file. I would like to visualize this object in a viewer3D of my application before exporting it but I only have a java object containing a list of faces and vertices of my 3D object. From my list of faces and vertices I would like to create a javafx type Shape or MeshView.

In fact, I'm trying to convert my java object into a javafx 3D object.

I have implement a Face Object :

public class Face {

    private int id, idVertice1, idVertice2, idVertice3;

    public Face(int idVertice1, int idVertice2, int idVertice3) {
        this.idVertice1 = idVertice1;
        this.idVertice2 = idVertice2;
        this.idVertice3 = idVertice3;
    }

    public int getIdVertice1() {
        return idVertice1;
    }

    public int getIdVertice2() {
        return idVertice2;
    }

    public int getIdVertice3() {
        return idVertice3;
    }
}

I have too an Vertices class :

public class Vertices {

    private double x, y, z;

    public Vertices(double line, double height, double column) {
        x = column;
        y = height;
        z = line;
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    public double getZ() {
        return z;
    }

And her is my Mesh class :

public class Mesh {

    private TreeMap<Double, TreeMap<Double, Vertices>> setOfVertices;
    private LinkedList<Face> setOfFaces;


public Mesh() {
    setOfFaces = new LinkedList();
    setOfVertices = new TreeMap<Double, TreeMap<Double, Vertices>>();
}

public TreeMap getSetOfVertices() {
    return setOfVertices;
}

public LinkedList<Face> getSetOfFaces() {
    return setOfFaces;
}

How convert this Mesh object to a JavaFX mesh object into my viewer 3D (my viewer 3D is a subScene) :

Is this possible?

DevLoots
  • 747
  • 1
  • 6
  • 21
  • Are you saying you have your data in a JavaFX "Mesh" object type already? Or have you created some custom Java class to hold your faces and vertices? – Birdasaur Jun 01 '17 at 00:41
  • 1
    I have created a custom Java class for the faces and vertices and I would like a JavaFX Mesh. – DevLoots Jun 01 '17 at 06:26
  • 1
    How is it related to the Java3D API? You seem to use JavaFX 3D API, please remove the" java-3d" tag. Java3D != JavaFX 3D – gouessej Jun 01 '17 at 09:53
  • No, I use JavaFX 3D. I have update my question and I have add some code. – DevLoots Jun 01 '17 at 12:35
  • 1
    It is possible to convert your data to a JavaFX 3D TriangleMesh in a couple ways based what I understand so far. You say you have the ability to write out an .obj format already. If true you could write it to a temp file, then read that .obj model in using the free model importer here: http://www.interactivemesh.org/models/jfx3dimporter.html A bit clunky but it would also test your export algorithm. If you want to have a viewer without the export/import transaction, then you need to map your Vertices to actual TriangleMesh X,Y,Z coordinates. This will require a triangle winding algorithm. – Birdasaur Jun 02 '17 at 11:42
  • 1
    We could help you with building that triangle winding algorithm but we would need to know more about your Vertices info... you have values like line, column and height... I'm not sure how they might be translating to X,Y,Z coordinates just by reading your code. If you have never created a custom triangle winding algorithm for a TriangleMesh... its challenging but not too hard. There are some open source examples in the FXyz3D primitives package that should help: https://github.com/FXyz/FXyz/tree/master/FXyz-Core/src/main/java/org/fxyz3d/shapes/primitives – Birdasaur Jun 02 '17 at 11:49
  • Thanks for your informations ! I will try, I have too foud this link : http://www.dummies.com/programming/java/javafx-add-a-mesh-object-to-a-3d-world/ – DevLoots Jun 03 '17 at 11:46

0 Answers0