Results 1 to 4 of 4
  1. #1
    Jeffthe is offline Member
    Join Date
    Jun 2016
    Posts
    2
    Rep Power
    0

    Default Java FX Stl - Viewer

    Dear guys,
    Please I need your help

    I have a Javafx Gui and id like to view a stl file. I found these library to import CAD Files (JavaFX 3D Model Importers).
    i have a actionlistener if i click on the button "Datei importieren" then iŽd like to show the CAD - File in a kind of Viewer.
    Java FX Stl - Viewer-gui.jpg
    I found these description to show a cad model
    Java FX Stl - Viewer-description.jpg

    but it is not working.

    Im using a scenebuilder and there are a lot of viewer like meshviewer or kind of cameras

    i dont care which kind of viewer essential it is working

    I hope you understand my problem

    Thanks a lot

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: Java FX Stl - Viewer

    I could not see anything wrong with the file import or the meshview. Since the description of " it is not working" is a little vague, I can only guess that you still have to set parameters for the camera. First you might have to back off the camera a little camera.setTranslateZ(-500); then you still have to define in between which range the 3D object will be visible by using the methods camera.setNearClip(//some parameter here); and camera.setFarClip(//some parameter here);

    Documentation of 3D graphics in JavaFX is still rudimentary, there is a helpful article about this on mobile.developer.com
    Last edited by benji2505; 06-21-2016 at 05:33 AM.

  3. #3
    Jeffthe is offline Member
    Join Date
    Jun 2016
    Posts
    2
    Rep Power
    0

    Default Re: Java FX Stl - Viewer

    Thank you, but look here
    Java FX Stl - Viewer-console.jpg
    The code is working, I get the mashes, but in my camera thereŽs nothing to see
    I tried more values for near and farclip

  4. #4
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: Java FX Stl - Viewer

    I am not working in 3D view too often, so I am not sure what precisely is happening, I think it might be something simple like the line color (white eagle on white background).

    When I dug into FXML, I copied/re-programmed a sample. Maybe you can check whether this compiles in your environment and compare it to your code. This modified sample is from the book Pro JavaFX 8.0.

    Java FX Code:
    package FX3DMesh;
    import javafx.application.Application;
    import javafx.beans.property.DoubleProperty;
    import javafx.beans.property.SimpleDoubleProperty;
    import javafx.scene.AmbientLight;
    import javafx.scene.Group;
    import javafx.scene.PerspectiveCamera;
    import javafx.scene.PointLight;
    import javafx.scene.Scene;
    import javafx.scene.paint.Color;
    import javafx.scene.paint.PhongMaterial;
    import javafx.scene.shape.CullFace;
    import javafx.scene.shape.DrawMode;
    import javafx.scene.shape.MeshView;
    import javafx.scene.shape.TriangleMesh;
    import javafx.scene.transform.Rotate;
    import javafx.stage.Stage;
    
    public class FX3DMesh extends Application {
    	
    	private Scene scene;
    	private int sceneWidth = 600;
    	private int sceneHeight = 600;
    	PerspectiveCamera camera;
    	Group pyramidGroup;
    	private double sceneX, sceneY=0;
    	private double fixedXAngle, fixedYAngle=0;
    	private final DoubleProperty angleX = new SimpleDoubleProperty(0);
    	private final DoubleProperty angleY = new SimpleDoubleProperty(0);
    
    	
    	@Override
    	public void start(Stage primaryStage) {
    		
    		Group root = new Group();
    		scene = new Scene( root, sceneWidth, sceneHeight);
    		scene.setFill(Color.BLACK);
    		
    		camera = new PerspectiveCamera(true);
    		camera.setNearClip(.1);								// true in camera constructor determines center of pane as origin, all axis are 0,0,0 there 
    		camera.setFarClip(10000.0);							// false moves it to top left corner
    		camera.setTranslateZ(-1000);
    		scene.setCamera(camera);
    		
    		PointLight light = new PointLight();		//add a pointlight to show highlights
    		root.getChildren().add(light);
    		light.setTranslateZ(-sceneWidth);
    		light.setTranslateY(-sceneHeight);
    		
    		Group pyramid1 = buildPyramid(100,200,Color.GOLDENROD,true, false);
    		pyramid1.setTranslateX(-100);	//closer to camera
    		
    		Group pyramid2 = buildPyramid(100,200,Color.GOLD,true, true);
    		pyramid2.setTranslateX(-100);
    		pyramid2.setTranslateY(-100);
    		pyramid2.setRotationAxis(Rotate.Z_AXIS);
    		pyramid2.setRotate(180);
    		
    		Group pyramid3 = buildPyramid(100,200,Color.LAWNGREEN,true, true);
    		pyramid3.setTranslateX(100);
    		
    		Group pyramid4 = buildPyramid(100,200,Color.GREEN,true,false);
    		pyramid4.setTranslateX(100);
    		pyramid4.setTranslateY(-100);
    		pyramid4.setRotationAxis(Rotate.Z_AXIS);
    		pyramid4.setRotate(180);
    		
    		pyramidGroup = new Group();
    		pyramidGroup.getChildren().addAll(pyramid1, pyramid2, pyramid3, pyramid4);
    		
    		hookupRotate();
    		
    		root.getChildren().addAll(pyramidGroup);
    		primaryStage.setTitle("meshes and similar fun");
    		primaryStage.setScene(scene);
    		primaryStage.show();
    	}
    	
    	private Group buildPyramid(
    			float height,
    			float hypotenuse,
    			Color color,
    			boolean ambient,
    			boolean fill
    			){
    		
    		TriangleMesh mesh = new TriangleMesh();
    		
    		mesh.getPoints().addAll(
    				0,0,0,						//point 0
    				0,height,-hypotenuse/2,		// point 1
    				-hypotenuse/2,height,0,		// point 2
    				hypotenuse/2,height,0,		// point 3
    				0,height,hypotenuse/2		// point 4
    				);
    		
    		mesh.getTexCoords().addAll(0,0);
    		mesh.getFaces().addAll(
    				0,0,2,0,1,0,	// vertical faces, wind counterclockwise
    				0,0,1,0,3,0,
    				0,0,3,0,4,0,
    				0,0,4,0,2,0,
    				4,0,1,0,2,0,	// base triangle 1, wind counterclockwise because camera has rotated
    				4,0,3,0,1,0
    				);
    		MeshView meshView = new MeshView(mesh);
    		
    		meshView.setDrawMode(DrawMode.LINE);	// show lines only by default
    		meshView.setCullFace(CullFace.BACK);	// Removing culling to show backlines
    		
    		Group pyramidGroup = new Group();
    		pyramidGroup.getChildren().add(meshView);
    		
    		if(color != null){
    			PhongMaterial material = new PhongMaterial(color);
    			meshView.setMaterial(material);
    		}
    		
    		if (ambient==true){
    			AmbientLight light = new AmbientLight(Color.WHITE);
    			light.getScope().add(meshView);
    			pyramidGroup.getChildren().add(light);
    		}
    		
    		if (fill==true){
    			meshView.setDrawMode(DrawMode.FILL);
    		}
    		return pyramidGroup;
    	}
    	
    	private void hookupRotate(){
    		Rotate xRotate = new Rotate(0, Rotate.X_AXIS);
    		Rotate yRotate = new Rotate(0, Rotate.Y_AXIS);
    		pyramidGroup.getTransforms().addAll(xRotate, yRotate);
    		xRotate.angleProperty().bind(angleX);
    		yRotate.angleProperty().bind(angleY);
    		
    		scene.setOnMousePressed(event -> {
    			sceneX = event.getSceneX();
    			sceneY = event.getSceneY();
    			fixedXAngle = angleX.get();
    			fixedYAngle = angleY.get();
    		});
    		
    		scene.setOnMouseDragged(event ->{
    			angleX.set(fixedXAngle - (sceneX - event.getSceneY()));
    			angleY.set(fixedYAngle + (sceneY - event.getSceneX()));
    		});
    		
    	}
    
    	
    	public static void main(String[] args) {
    		launch(args);
    	}
    }
    Last edited by benji2505; 06-21-2016 at 03:40 PM.

Similar Threads

  1. Big Faceless Java PDF Viewer 2.13.2
    By java software in forum Java Software
    Replies: 0
    Last Post: 05-15-2013, 01:30 AM
  2. Can i run JAVA-Viewer.jad on website?
    By DeDanan in forum New To Java
    Replies: 4
    Last Post: 02-28-2011, 10:17 PM
  3. PPT viewer which is developed in Java
    By maniselvaraj in forum Advanced Java
    Replies: 3
    Last Post: 12-16-2010, 11:08 AM
  4. Who know Java Based X9.37 file viewer?
    By jasonjoy1108 in forum New To Java
    Replies: 1
    Last Post: 02-21-2009, 05:07 PM
  5. java applet viewer dimensions
    By yuriythebest in forum Java Applets
    Replies: 1
    Last Post: 11-08-2008, 10:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •