/
Demo.java
134 lines (120 loc) · 5.02 KB
/
Demo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package samples;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.controlsfx.control.action.Action;
import com.jme3.animation.AnimControl;
import com.jme3.animation.Animation;
import com.jme3.animation.SpatialTrack;
import com.jme3.app.SimpleApplication;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import com.jme3.system.AppSettings;
import jme3_ext_spatial_explorer.AppStateSpatialExplorer;
import jme3_ext_spatial_explorer.Helper;
import jme3_ext_spatial_explorer.SpatialExplorer;
public class Demo {
public static void main(String[] args) {
Logger.getLogger("").setLevel(Level.WARNING);
AppSettings settings = new AppSettings(true);
settings.setResolution(1280, 720);
settings.setVSync(true);
settings.setFullscreen(false);
SimpleApplication app = new SimpleApplication(){
@Override
public void simpleInitApp() {
}
};
app.setSettings(settings);
app.setShowSettings(false);
app.setDisplayStatView(true);
app.setDisplayFps(true);
// !!!! without .setPauseOnLostFocus(false)you should switch focus from javafx window to jme to see update
app.setPauseOnLostFocus(false);
app.start();
//Setup Camera
app.enqueue(() -> {
app.getFlyByCamera().setEnabled(true);
app.getFlyByCamera().setDragToRotate(true);
//app.getStateManager().detach(app.getStateManager().getState(FlyCamAppState.class));
app.getInputManager().setCursorVisible(true);
return null;
});
//Setup a default scene (grid + axis)
app.enqueue(() -> {
app.getRootNode().attachChild(Helper.makeScene(app));
app.getRootNode().attachChild(sampleCube(app));
app.getRootNode().attachChild(sampleShapes(app));
return null;
});
//Setup SpatialExplorer
Helper.setupSpatialExplorerWithAll(app);
// app.enqueue(() -> {
// AppStateSpatialExplorer se = new AppStateSpatialExplorer();
// Helper.registerAction_Refresh(se.spatialExplorer);
// Helper.registerAction_ShowLocalAxis(se.spatialExplorer, app);
// Helper.registerAction_SaveAsJ3O(se.spatialExplorer, app);
// Helper.registerAction_ShowSkeleton(se.spatialExplorer, app);
// Helper.registerAction_ShowWireframe(se.spatialExplorer, app);
// Helper.registerBarAction_ShowFps(se.spatialExplorer, app);
// Helper.registerBarAction_ShowStats(se.spatialExplorer, app);
// Helper.registerBarAction_SceneInWireframe(se.spatialExplorer, app);
// Helper.registerBarAction_SceneInDebugPhysic(se.spatialExplorer, app);
// app.getStateManager().attach(se);
// return null;
// });
app.enqueue(() -> {
AppStateSpatialExplorer se = app.getStateManager().getState(AppStateSpatialExplorer.class);
registerBarAction_PrintToto(se.spatialExplorer);
return null;
});
}
public static Spatial sampleCube(SimpleApplication app) {
Geometry cube = Helper.makeShape("cube", new Box(0.5f, 0.5f, 0.5f), ColorRGBA.Brown, app.getAssetManager(), false);
cube.setUserData("sample String", "string");
cube.setUserData("sample int", 42);
cube.setUserData("sample float", 42.0f);
cube.setUserData("sample vector3f", new Vector3f(-2.0f, 3.0f, 4.0f));
AnimControl ac = new AnimControl();
Animation aniY = new Animation("Y basic translation", 10);
aniY.addTrack(new SpatialTrack(new float[]{0, 5 , 10}, new Vector3f[]{new Vector3f(0, -5, 0), new Vector3f(0, 5, 0), new Vector3f(0, -5, 0)}, null, null));
ac.addAnim(aniY);
Animation aniX = new Animation("X basic translation", 10);
aniX.addTrack(new SpatialTrack(new float[]{0, 5 , 10}, new Vector3f[]{new Vector3f(-5, 0, 0), new Vector3f(5, 0, 0), new Vector3f(-5, 0, 0)}, null, null));
ac.addAnim(aniX);
Animation aniZ = new Animation("Z basic translation", 10);
aniZ.addTrack(new SpatialTrack(new float[]{0, 5 , 10}, new Vector3f[]{new Vector3f(0, 0, -5), new Vector3f(0, 0, 5), new Vector3f(0, 0, -5)}, null, null));
ac.addAnim(aniZ);
cube.addControl(ac);
return cube;
}
public static Spatial sampleShapes(SimpleApplication app) {
Node anchor = new Node("anchor");
float l = 0;
for (float x = -5; x <6; x += 2.0, l++) {
Geometry cube = Helper.makeShape("cube_"+x, new Box(0.5f, 0.5f, 0.5f), ColorRGBA.Yellow, app.getAssetManager(), false);
cube.setLocalTranslation(new Vector3f(x, x*0.5f, 5));
cube.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.PI * (1.0f/3f) * l, Vector3f.UNIT_Y));
anchor.attachChild(cube);
Geometry sphere = Helper.makeShape("sphere_"+x, new Sphere(8, 8, 0.5f), ColorRGBA.Cyan, app.getAssetManager(), false);
sphere.setLocalTranslation(new Vector3f(x, x*0.5f, -5));
anchor.attachChild(sphere);
}
return anchor;
}
public static void registerBarAction_PrintToto(SpatialExplorer se) {
Action action = new Action("Toto", (evt) -> {
System.out.println("toto");
});
// Action action = Helper.makeAction("toto", FontAwesome.Glyph.GLASS, (evt) -> {
// System.out.println("toto");
// });
se.barActions.add(action);
}
}