1

I am build a javafx application and am looking to display some 3D models that are currently in an STL file. I have seen some similar examples to this online, but all examples are not working. Below is my code.

import com.interactivemesh.jfx.importer.ImportException;
import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.*;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.DrawMode;
import javafx.scene.shape.MeshView;
import javafx.scene.shape.TriangleMesh;
import javafx.scene.shape.VertexFormat;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;

StlMeshImporter stlImporter = new StlMeshImporter();

        try {
            stlImporter.read(this.getClass().getResource("zeb.3ds"));
        }
        catch (ImportException e) {
            System.out.println("Error!");
            e.printStackTrace();
            return;
        }

        Group root = new Group();

        stlImporter.getImport();
        System.out.println(stlImporter.getImport());
        TriangleMesh mesh = stlImporter.getImport();
        stlImporter.close();
        MeshView meshView = new MeshView(mesh);

        meshView.setMaterial(new PhongMaterial(Color.RED));
        meshView.setDrawMode(DrawMode.FILL);
        meshView.setVisible(true);
        root.getChildren().add(meshView);

        Scene scene = new Scene(root, 1024, 800);
        Camera camera = new PerspectiveCamera();
        scene.setCamera(camera);
        stage.setScene(scene);
        stage.show();

Nothing shows in up the scene when I run the file. Are there ways I might be able to test this methodology? http://www.interactivemesh.org/models/jfx3dimporter.html recommends that I create a TriangleMesh object, but this isn't working for me

1 Answers1

0

Seeing your code my comments would be

  • Can you show an screenshot?
  • Is your model correct? Have you tried it with interactivemrsh stl viewer? that could discard some errors.
  • You should try adding some lights. That would help.

If you want a basic Mesh viewer functionality, you have a great example here: How to create 3d shape from STL in JavaFX 8? (a little old, but it works like a charm)

SoulWanderer
  • 315
  • 3
  • 11