- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
Latest commit
106 lines (87 loc) · 3.74 KB
/
Copy pathExample.java
File metadata and controls
106 lines (87 loc) · 3.74 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
importjava.awt.Color;
importjava.awt.Graphics;
importjava.awt.image.BufferStrategy;
importjava.io.File;
importjava.util.List;
importjava.util.concurrent.TimeUnit;
importjavax.imageio.ImageIO;
importjavax.swing.JFrame;
importnet.steelswing.engine.api.util.MathHelper;
importnet.steelswing.engine.api.vecmath.MathUtil;
importorg.joml.Matrix4f;
/**
*
* @author LWJGL2
*/
publicclassExample {
protectedstaticintthreadCount = 12;
protectedstaticThreadPoolExecutorexecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(threadCount);
/**
* @param args the command line arguments
*/
publicstaticvoidmain(String[] args) {
JFrameframe = newJFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(856, 480);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.createBufferStrategy(1);
finalBufferbuffer = newBuffer(frame.getWidth(), frame.getHeight());
finalBufferStrategybufferStrategy = frame.getBufferStrategy();
finalGraphicsg = bufferStrategy.getDrawGraphics();
longtime = System.nanoTime();
longsecondInNanos = TimeUnit.SECONDS.toNanos(1);
intframes = 0;
init();
while (frame.isVisible()) {
if (buffer.width != frame.getWidth() || buffer.height != frame.getHeight()) {
buffer.create(frame.getWidth(), frame.getHeight());
}
buffer.clear(Color.black);
{
render(buffer);
}
buffer.draw(g, frame.getWidth(), frame.getHeight());
frames++;
if (System.nanoTime() - time > secondInNanos) {
time = System.nanoTime();
buffer.fps = frames;
frame.setTitle("FPS: " + buffer.fps);
frames = 0;
}
}
}
protectedstaticList<StaticMeshLoader.Mesh> model;
protectedstaticTexturetexture;
protectedstaticvoidinit() {
try {
model = StaticMeshLoader.load(newFile("teapot\\debug.fbx").getAbsoluteFile());
texture = newTexture(ImageIO.read(newFile("teapot\\debug.png").getAbsoluteFile()));
} catch (Exceptione) {
e.printStackTrace();
}
}
protectedstaticvoidrender(Bufferbuffer) {
buffer.viewMatrix = MathUtil.convertLwjglxToJoml(MathUtil.createViewMatrix(0, 0, 0, 25, System.nanoTime() / 10000000 % 360, 0, 2));
buffer.projectionMatrix = MathUtil.convertLwjglxToJoml(MathUtil.createProjectionMatrix(1000, -100, 70, buffer.width, buffer.height));
// buffer.normalMatrix = new Matrix4f(buffer.modelMatrix).invert().transpose();
buffer.modelMatrix = newMatrix4f().translate(0, -0.5f, 0);//.rotateX(MathHelper.toRadians(-90));
List<CompletableFuture<Void>> futures = newArrayList<>();
for (StaticMeshLoader.Meshmesh : model) {
finalintcount = mesh.indices.length / threadCount;
for (inti = 0; i < mesh.indices.length; i += count) {
finalintstart = i;
CompletableFuture<Void> runAsync = CompletableFuture.runAsync(() -> {
buffer.drawFilledTriangleInline(texture, mesh.vertices, mesh.indices, mesh.normals, mesh.textureCoords, start, start + count);
}, executor);
futures.add(runAsync);
}
}
CompletableFuture.allOf(futures.toArray(newCompletableFuture[0])).join();
/* single thread
for (StaticMeshLoader.Mesh mesh : model) {
System.out.println( mesh.vertices.length);
buffer.drawFilledTriangleInline(texture, mesh.vertices, mesh.indices, mesh.normals, mesh.textureCoords);
}*/
}
}