1 /*
2 * Copyright (c) 2010, 2014, Oracle and/or its affiliates.
3 * All rights reserved. Use is subject to license terms.
4 *
5 * This file is available and licensed under the following license:
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the distribution.
16 * - Neither the name of Oracle Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 import java.io.File;
35 import java.io.IOException;
36 import java.util.List;
37
38 import javafx.animation.KeyFrame;
39 import javafx.animation.KeyValue;
40 import javafx.animation.Timeline;
41 import javafx.application.Application;
42 import javafx.scene.Group;
43 import javafx.scene.Node;
44 import javafx.scene.PerspectiveCamera;
45 import javafx.scene.Scene;
46 import javafx.scene.paint.Color;
47 import javafx.scene.transform.Rotate;
48 import javafx.scene.transform.Translate;
49 import javafx.stage.Stage;
50 import javafx.stage.StageStyle;
51 import javafx.util.Duration;
52
53 import com.javafx.experiments.importers.Importer3D;
54 import com.sun.javafx.perf.PerformanceTracker;
55
56 /**
57 * JavaFX 3D Viewer Application
58 */
59 public class SimpleViewerApp extends Application {
60 private final Group root3D = new Group();
61 private final PerspectiveCamera camera = new PerspectiveCamera(true);
62 private final Rotate cameraXRotate = new Rotate(-20,0,0,0,Rotate.X_AXIS);
63 private final Rotate cameraYRotate = new Rotate(-20,0,0,0,Rotate.Y_AXIS);
64 private final Rotate cameraLookXRotate = new Rotate(0,0,0,0,Rotate.X_AXIS);
65 private final Rotate cameraLookZRotate = new Rotate(0,0,0,0,Rotate.Z_AXIS);
66 private final Translate cameraPosition = new Translate(0,0,-7);
67 private AutoScalingGroup autoScalingGroup = new AutoScalingGroup(2);
68
69 @Override public void start(Stage stage) throws Exception {
70 List<String> args = getParameters().getRaw();
71 final Scene scene = new Scene(root3D,1920,1080,true);
72 scene.setFill(Color.TRANSPARENT);
73 stage.initStyle(StageStyle.TRANSPARENT);
74
91 content = Importer3D.load(ContentModel.class.getResource("drop-here.obj").toExternalForm());
92 } else {
93 content = Importer3D.load(new File(args.get(0)).toURI().toURL().toExternalForm());
94 }
95 autoScalingGroup.getChildren().add(content);
96 } catch (IOException e) {
97 e.printStackTrace();
98 }
99
100 Timeline timeline = new Timeline(
101 new KeyFrame(Duration.ZERO, new KeyValue(cameraYRotate.angleProperty(),0)),
102 new KeyFrame(Duration.seconds(4), new KeyValue(cameraYRotate.angleProperty(),360))
103 );
104 timeline.setCycleCount(Timeline.INDEFINITE);
105 timeline.play();
106
107 stage.setScene(scene);
108 stage.show();
109
110 // MEASURE FPS
111 Timeline fpsTimeline = new Timeline(new KeyFrame(Duration.seconds(2), t -> System.out.println("fps = " + PerformanceTracker.getSceneTracker(scene).getInstantFPS())));
112 fpsTimeline.setCycleCount(Timeline.INDEFINITE);
113 fpsTimeline.play();
114 }
115
116 public static void main(String[] args) {
117 launch(args);
118 }
119 }
|
1 /*
2 * Copyright (c) 2010, 2015, Oracle and/or its affiliates.
3 * All rights reserved. Use is subject to license terms.
4 *
5 * This file is available and licensed under the following license:
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the distribution.
16 * - Neither the name of Oracle Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 import java.io.File;
35 import java.io.IOException;
36 import java.util.List;
37
38 import javafx.animation.KeyFrame;
39 import javafx.animation.KeyValue;
40 import javafx.animation.Timeline;
41 import javafx.application.Application;
42 import javafx.scene.Group;
43 import javafx.scene.Node;
44 import javafx.scene.PerspectiveCamera;
45 import javafx.scene.Scene;
46 import javafx.scene.paint.Color;
47 import javafx.scene.transform.Rotate;
48 import javafx.scene.transform.Translate;
49 import javafx.stage.Stage;
50 import javafx.stage.StageStyle;
51 import javafx.util.Duration;
52
53 import com.javafx.experiments.importers.Importer3D;
54
55 /**
56 * JavaFX 3D Viewer Application
57 */
58 public class SimpleViewerApp extends Application {
59 private final Group root3D = new Group();
60 private final PerspectiveCamera camera = new PerspectiveCamera(true);
61 private final Rotate cameraXRotate = new Rotate(-20,0,0,0,Rotate.X_AXIS);
62 private final Rotate cameraYRotate = new Rotate(-20,0,0,0,Rotate.Y_AXIS);
63 private final Rotate cameraLookXRotate = new Rotate(0,0,0,0,Rotate.X_AXIS);
64 private final Rotate cameraLookZRotate = new Rotate(0,0,0,0,Rotate.Z_AXIS);
65 private final Translate cameraPosition = new Translate(0,0,-7);
66 private AutoScalingGroup autoScalingGroup = new AutoScalingGroup(2);
67
68 @Override public void start(Stage stage) throws Exception {
69 List<String> args = getParameters().getRaw();
70 final Scene scene = new Scene(root3D,1920,1080,true);
71 scene.setFill(Color.TRANSPARENT);
72 stage.initStyle(StageStyle.TRANSPARENT);
73
90 content = Importer3D.load(ContentModel.class.getResource("drop-here.obj").toExternalForm());
91 } else {
92 content = Importer3D.load(new File(args.get(0)).toURI().toURL().toExternalForm());
93 }
94 autoScalingGroup.getChildren().add(content);
95 } catch (IOException e) {
96 e.printStackTrace();
97 }
98
99 Timeline timeline = new Timeline(
100 new KeyFrame(Duration.ZERO, new KeyValue(cameraYRotate.angleProperty(),0)),
101 new KeyFrame(Duration.seconds(4), new KeyValue(cameraYRotate.angleProperty(),360))
102 );
103 timeline.setCycleCount(Timeline.INDEFINITE);
104 timeline.play();
105
106 stage.setScene(scene);
107 stage.show();
108
109 // MEASURE FPS
110 //TODO: RT-40270 - Public PerformanceTracker support should be added
111 // Timeline fpsTimeline = new Timeline(new KeyFrame(Duration.seconds(2), t ->
112 // System.out.println("fps = " + PerformanceTracker.getSceneTracker(scene).getInstantFPS())));
113 // fpsTimeline.setCycleCount(Timeline.INDEFINITE);
114 // fpsTimeline.play();
115 }
116
117 public static void main(String[] args) {
118 launch(args);
119 }
120 }
|