diff --git a/client/pom.xml b/client/pom.xml index b68005f..6627c7d 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -100,11 +100,6 @@ lwjgl ${lwjgl.natives} - - org.lwjgl - lwjgl-assimp - ${lwjgl.natives} - org.lwjgl lwjgl-bgfx diff --git a/client/res/textures/test_texture.png b/client/res/textures/test_texture.png deleted file mode 100644 index 25f8a24..0000000 Binary files a/client/res/textures/test_texture.png and /dev/null differ diff --git a/client/src/main/java/core/engine/Engine.java b/client/src/main/java/core/engine/Engine.java index 9896df6..31de8f6 100644 --- a/client/src/main/java/core/engine/Engine.java +++ b/client/src/main/java/core/engine/Engine.java @@ -112,24 +112,6 @@ public class Engine { // Set the clear color glClearColor(1.0f, 0.0f, 0.0f, 0.0f); StaticShader shader = new StaticShader(); - float[] vertices = { - -0.5f, 0.5f, 0f, - -0.5f, -0.5f, 0f, - 0.5f, -0.5f, 0f, - 0.5f, 0.5f, 0f, - }; - int[] indices = { - 0,1,3, - 3,1,2 - }; - - float[] textureCoords = { - 0,0, // V0 - 0,1, // V1 - 1,1, // V2 - 1,0 // V3 - - }; Camera camera = new Camera(); glfwSetKeyCallback(window, glfwKeyCallback = new GLFWKeyCallback() { @@ -156,13 +138,14 @@ public class Engine { }); Renderer renderer = new Renderer(shader); - RawModel model = loader.loadToVAO(vertices,textureCoords, indices); - ModelTexture modelTexture = new ModelTexture(loader.loadTexture("test_texture")); + RawModel model = OBJLoader.loadOBJModel("stall", loader); + ModelTexture modelTexture = new ModelTexture(loader.loadTexture("stallTexture")); TexturedModel texturedModel = new TexturedModel(model, modelTexture); - Entity entity = new Entity(texturedModel, new Vector3f(-1,0,-1), 0,0,0,1); + Entity entity = new Entity(texturedModel, new Vector3f(0,0,-50), 0,0,0,1); // Run the rendering loop until the user has attempted to close // the window or has pressed the ESCAPE key. while ( !glfwWindowShouldClose(window) ) { + entity.increaseRotation(0,1,0); renderer.prepare(); shader.start(); shader.loadViewMatrix(camera); diff --git a/client/src/main/java/core/engine/Loader.java b/client/src/main/java/core/engine/Loader.java index 607fa3c..902a7af 100644 --- a/client/src/main/java/core/engine/Loader.java +++ b/client/src/main/java/core/engine/Loader.java @@ -29,7 +29,7 @@ public class Loader { } public int loadTexture(String fileName) { - Texture texture = new Texture("res/textures/" + fileName + ".png"); + Texture texture = new Texture("res/" + fileName + ".png"); int textureID = texture.getTextureID(); this.textureIDs.add(textureID); return textureID; diff --git a/client/src/main/java/core/engine/OBJLoader.java b/client/src/main/java/core/engine/OBJLoader.java new file mode 100644 index 0000000..f08a9b6 --- /dev/null +++ b/client/src/main/java/core/engine/OBJLoader.java @@ -0,0 +1,119 @@ +package core.engine; + +import core.engine.model.RawModel; +import utils.vectors.Vector2f; +import utils.vectors.Vector3f; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.List; + +public class OBJLoader { + + public static RawModel loadOBJModel(String fileName, Loader loader) { + FileReader fileReader = null; + try { + fileReader = new FileReader("res/" + fileName + ".obj"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + if(fileReader != null) { + BufferedReader bufferedReader = new BufferedReader(fileReader); + String line = null; + List vertices = new ArrayList<>(); + List textures = new ArrayList<>(); + List normals = new ArrayList<>(); + List indices = new ArrayList<>(); + + float[] verticesArray = null; + float[] normalsArray = null; + float[] texturesArray = null; + int[] indicesArray = null; + + try { + while(bufferedReader.ready()) { + line = bufferedReader.readLine(); + String[] splittedLine = line.split(" "); + if(splittedLine[0].equals("v")) { + Vector3f vertex = new Vector3f(Float.parseFloat(splittedLine[1]), + Float.parseFloat(splittedLine[2]), Float.parseFloat(splittedLine[3])); + vertices.add(vertex); + } else if(splittedLine[0].equals("vt")) { + Vector2f texture = new Vector2f(Float.parseFloat(splittedLine[1]), Float.parseFloat(splittedLine[2])); + textures.add(texture); + } else if(splittedLine[0].equals("vn")) { + Vector3f normal = new Vector3f(Float.parseFloat(splittedLine[1]), + Float.parseFloat(splittedLine[2]), Float.parseFloat(splittedLine[3])); + normals.add(normal); + } else if(splittedLine[0].equals("f")) { + //No more vertices/textures/normals should be added at this point in the file + texturesArray = new float[vertices.size()*2]; + normalsArray = new float[vertices.size()*3]; + break; + } + } + + while(line != null) { + if(!line.startsWith("f ")) { + line = bufferedReader.readLine(); + continue; + } + + String[] splittedLine = line.split(" "); + String[] vertex1 = splittedLine[1].split("/"); + String[] vertex2 = splittedLine[2].split("/"); + String[] vertex3 = splittedLine[3].split("/"); + + processVertex(vertex1, indices, textures, normals, texturesArray, normalsArray); + processVertex(vertex2, indices, textures, normals, texturesArray, normalsArray); + processVertex(vertex3, indices, textures, normals, texturesArray, normalsArray); + + line = bufferedReader.readLine(); + } + + bufferedReader.close(); + fileReader.close(); + } catch(Exception e) { + e.printStackTrace(); + } + + verticesArray = new float[vertices.size()*3]; + indicesArray = new int[indices.size()]; + int vertexPointer = 0; + + for(Vector3f vertex: vertices) { + verticesArray[vertexPointer++] = vertex.x; + verticesArray[vertexPointer++] = vertex.y; + verticesArray[vertexPointer++] = vertex.z; + } + + for(int i=0; i indices, List textures, + List normals, float[] textureArray, float[] normalsArray) { + int currentVertexPointer = Integer.parseInt(vertexData[0]) -1; + indices.add(currentVertexPointer); + Vector2f currentTex = textures.get(Integer.parseInt(vertexData[1])-1); + textureArray[currentVertexPointer*2] = currentTex.x; + textureArray[currentVertexPointer*2+1] = 1 - currentTex.y; + Vector3f currentNorm = normals.get(Integer.parseInt(vertexData[2])-1); + normalsArray[currentVertexPointer*3] = currentNorm.x; + normalsArray[currentVertexPointer*3+1] = currentNorm.y; + normalsArray[currentVertexPointer*3+2] = currentNorm.z; + + } + + + +} diff --git a/client/src/main/java/core/engine/Renderer.java b/client/src/main/java/core/engine/Renderer.java index e6d4346..79c8d18 100644 --- a/client/src/main/java/core/engine/Renderer.java +++ b/client/src/main/java/core/engine/Renderer.java @@ -29,7 +29,7 @@ public class Renderer { public void prepare() { GL11.glEnable(GL11.GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer - GL11.glClearColor(1,0,0,1); + GL11.glClearColor(5,195,221,1); } public void render(Entity entity, StaticShader shader) { diff --git a/client/src/main/java/core/engine/entity/Camera.java b/client/src/main/java/core/engine/entity/Camera.java index 718c99a..0c11402 100644 --- a/client/src/main/java/core/engine/entity/Camera.java +++ b/client/src/main/java/core/engine/entity/Camera.java @@ -10,19 +10,19 @@ public class Camera { private float roll; public void moveLeft() { - position.x += 0.02f; + position.x += 0.5f; } public void moveForward() { - position.z -= 0.02f; + position.z -= .5f; } public void moveBackward() { - position.z += 0.02f; + position.z += .5f; } public void moveRight() { - position.x -= 0.02f; + position.x -= .5f; } public Vector3f getPosition() {