/
BOSceneTest.java
126 lines (96 loc) · 4.22 KB
/
BOSceneTest.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
package com.ss.editor.test.external;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.*;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.shader.BufferObject;
import java.util.concurrent.ThreadLocalRandom;
/**
* The simple test of j3s scenes.
*
* @author JavaSaBr
*/
public class BOSceneTest extends BaseExternalTest {
public static void main(String[] args) {
run(BOSceneTest.class);
}
private BufferObject ssbo;
private BufferObject ssbo2;
private BufferObject ubo;
@Override
public void simpleInitApp() {
super.simpleInitApp();
getFlyByCamera().setEnabled(false);
getInputManager().setCursorVisible(true);
final Box box = new Box(1, 1, 1);
Geometry geometry = new Geometry("Geom", box);
ssbo = new BufferObject(3);
ssbo.setFieldValue("light_1", ColorRGBA.Red);
ssbo.setFieldValue("light_2", ColorRGBA.Green);
ubo = new BufferObject(2);
ubo.setFieldValue("light_1", ColorRGBA.Yellow);
ubo.setFieldValue("light_2", ColorRGBA.Red);
final Matrix3f matrix3f = new Matrix3f();
matrix3f.setColumn(0, new Vector3f(0, 0, 1));
matrix3f.setColumn(1, new Vector3f(0, 1, 0));
matrix3f.setColumn(2, new Vector3f(0, 1, 0));
final Matrix4f matrix4f = new Matrix4f();
matrix4f.setColumn(1, new float[]{0, 1, 0, 0});
ssbo2 = new BufferObject(4);
ssbo2.setFieldValue("index", 1);
ssbo2.setFieldValue("colors", new ColorRGBA[]{ColorRGBA.Green, ColorRGBA.Red, ColorRGBA.Blue});
ssbo2.setFieldValue("alp", 1F);
ssbo2.setFieldValue("matrix3", matrix3f);
ssbo2.setFieldValue("matrix4", matrix4f);
ssbo2.setFieldValue("positions", new Vector3f[]{Vector3f.UNIT_X, new Vector3f(0.3F, 0.3f, 0.3F), Vector3f.UNIT_Z});
ssbo2.setFieldValue("index2", 1);
ssbo2.setFieldValue("matrixes", new Matrix3f[] {new Matrix3f(), matrix3f});
ssbo2.setFieldValue("vector2", new Vector2f(0, 0));
ssbo2.setFieldValue("fvalue", 0.4F);
final Material materialSSBO = new Material(assetManager, "MatDefs/UnshadedSSBO.j3md");
materialSSBO.setShaderStorageBufferObject("TestSSBO", ssbo);
materialSSBO.setColor("Color", ColorRGBA.DarkGray);
geometry.setMaterial(materialSSBO);
geometry.setLocalTranslation(1, 0, 0);
rootNode.attachChild(geometry);
final Material materialUBO = new Material(assetManager, "MatDefs/UnshadedUBO.j3md");
materialUBO.setUniformBufferObject("TestUBO", ubo);
materialUBO.setColor("Color", ColorRGBA.DarkGray);
geometry = geometry.clone();
geometry.setMaterial(materialUBO);
geometry.setLocalTranslation(-1, 0, 0);
rootNode.attachChild(geometry);
final Material materialSSBO2 = new Material(assetManager, "MatDefs/UnshadedSSBO2.j3md");
materialSSBO2.setShaderStorageBufferObject("TestSSBO", ssbo2);
materialSSBO2.setColor("Color", ColorRGBA.DarkGray);
geometry = geometry.clone();
geometry.setMaterial(materialSSBO2);
geometry.setLocalTranslation(-3, 0, 0);
rootNode.attachChild(geometry);
getFlyByCamera().setMoveSpeed(5);
getInputManager().addMapping("mouse", new KeyTrigger(KeyInput.KEY_SPACE));
getInputManager().addListener((ActionListener) (name, isPressed, tpf) -> {
if (isPressed) {
getFlyByCamera().setEnabled(!getFlyByCamera().isEnabled());
}
}, "mouse");
}
@Override
public void simpleUpdate(final float tpf) {
super.simpleUpdate(tpf);
final ThreadLocalRandom random = ThreadLocalRandom.current();
ColorRGBA randomColor = new ColorRGBA(random.nextFloat(),
random.nextFloat(),
random.nextFloat(),
1F);
ssbo.setFieldValue("light_2", randomColor);
randomColor = new ColorRGBA(random.nextFloat(),
random.nextFloat(),
random.nextFloat(),
1F);
ubo.setFieldValue("light_2", randomColor);
}
}