-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathTestScene.java
More file actions
169 lines (135 loc) · 5.16 KB
/
Copy pathTestScene.java
File metadata and controls
169 lines (135 loc) · 5.16 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import app.f3d.F3D.*;
import java.io.*;
import java.lang.String;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class TestScene {
// On Windows, try to load opengl32 from Java path
// It's only useful in order to force Mesa software OpenGL
static {
if (System.getProperty("os.name").startsWith("Windows"))
{
try {
System.loadLibrary("opengl32");
} catch (UnsatisfiedLinkError e) {
// Ignore if opengl32 is not available
}
}
}
public static void main(String[] args) throws FileNotFoundException, IOException {
Engine.autoloadPlugins();
String testDataPath = args.length > 0 ? args[0] : ".";
String world = testDataPath + "data/world.obj";
String logo = testDataPath + "data/f3d.glb";
String sphere = testDataPath + "data/mb/recursive/mb_1_0.vtp";
Engine engine = Engine.createNone();
Scene scene = engine.getScene();
scene.supports("test.obj");
scene.add(sphere);
scene.add(new ArrayList<>(Arrays.asList(world, logo)));
scene.clear();
// Test the added files tracking
if (!scene.getAddedFiles().isEmpty()) {
throw new RuntimeException("a cleared scene should have no added file");
}
scene.add(sphere);
List<String> addedFiles = scene.getAddedFiles();
if (addedFiles.size() != 1 || !addedFiles.get(0).contains("mb_1_0.vtp")) {
throw new RuntimeException("scene should track the added file");
}
scene.clear();
if (!scene.getAddedFiles().isEmpty()) {
throw new RuntimeException("clear should reset the added files");
}
float[] points = new float[] { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f, 0.0f };
int[] faceSides = new int[] { 3 };
int[] faceIndices = new int[] { 0, 1, 2 };
Types.Mesh mesh = new Types.Mesh(points, new float[0], new float[0], faceSides, faceIndices);
scene.add(mesh);
scene.loadAnimationTime(0.5);
scene.animationTimeRange();
scene.getAnimationKeyFrames();
scene.availableAnimations();
scene.getAnimationName();
scene.getAnimationName(0);
scene.getAnimationNames();
Types.LightState lightState = new Types.LightState();
lightState.type = Types.LightType.HEADLIGHT;
lightState.intensity = 1.0;
lightState.switchState = true;
int lightIdx = scene.addLight(lightState);
scene.getLightCount();
if (lightIdx >= 0)
{
scene.getLight(lightIdx);
Types.LightState updateLight = new Types.LightState();
updateLight.type = Types.LightType.HEADLIGHT;
updateLight.intensity = 2.0;
updateLight.switchState = true;
scene.updateLight(lightIdx, updateLight);
scene.removeLight(lightIdx);
}
Types.LightState light1 = new Types.LightState();
light1.type = Types.LightType.HEADLIGHT;
light1.intensity = 1.0;
Types.LightState light2 = new Types.LightState();
light2.type = Types.LightType.CAMERA_LIGHT;
light2.intensity = 1.0;
light1.equals(light2);
scene.removeAllLights();
// Test the scene hierarchy
scene.clear();
if (!scene.getSceneHierarchy().isEmpty()) {
throw new RuntimeException("a cleared scene should have an empty scene hierarchy");
}
try {
scene.setNodeVisibility(0, false);
throw new RuntimeException(
"Expected Scene.NodeException was not thrown with an empty scene hierarchy");
} catch (Scene.NodeException e) {
}
scene.add(sphere);
List<Types.NodeState> hierarchy = scene.getSceneHierarchy();
if (hierarchy.isEmpty()) {
throw new RuntimeException("scene hierarchy should not be empty");
}
Types.NodeState root = hierarchy.get(0);
if (root.id != 0 || root.parentId != -1 || root.level != 0 || !root.visible
|| !root.label.contains("mb_1_0.vtp")) {
throw new RuntimeException("unexpected scene hierarchy root node");
}
for (Types.NodeState node : hierarchy) {
int expectedLevel = node.parentId < 0 ? 0 : hierarchy.get(node.parentId).level + 1;
if (node.level != expectedLevel) {
throw new RuntimeException("unexpected scene hierarchy node level");
}
}
scene.setNodeVisibility(0, false);
for (Types.NodeState node : scene.getSceneHierarchy()) {
if (node.visible) {
throw new RuntimeException("the whole subtree should be hidden");
}
}
scene.setNodeVisibility(0, true);
for (Types.NodeState node : scene.getSceneHierarchy()) {
if (!node.visible) {
throw new RuntimeException("the whole subtree should be visible");
}
}
try {
scene.setNodeVisibility(hierarchy.size(), false);
throw new RuntimeException(
"Expected Scene.NodeException was not thrown with an out of range index");
} catch (Scene.NodeException e) {
}
engine.close();
// --- Exception handling tests ---
// Adding a nonexistent file must throw LoadFailureException instead of crashing the JVM.
try (Engine tmpEngine = Engine.createNone()) {
tmpEngine.getScene().add("/absolutely_nonexistent_file_f3d_test.xyz");
throw new RuntimeException("Expected Scene.LoadFailureException was not thrown");
} catch (Scene.LoadFailureException e) {
}
}
}