obj only face loading added
This commit is contained in:
1 parent
719e6993df
commit
58aa033b02
3 files changed
+43
-6
No files matched your search
@@ -99,6 +99,7 @@ public class Obj {
|
|||||||
{
|
{
|
||||||
i.add(a / 3);
|
i.add(a / 3);
|
||||||
vbo_el_found = true;
|
vbo_el_found = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +117,37 @@ public class Obj {
|
|||||||
// Add new index to indices
|
// Add new index to indices
|
||||||
i.add((temp_v_vbo.size() / 3) - 1);
|
i.add((temp_v_vbo.size() / 3) - 1);
|
||||||
}
|
}
|
||||||
|
} else if (line.contains("/")) {
|
||||||
|
|
||||||
|
} else { // Means the F is just 3 vertex indexes
|
||||||
|
int vertex_index = (Integer.parseInt(data[index]) - 1) * 3;
|
||||||
|
|
||||||
|
boolean vbo_el_found = false;
|
||||||
|
for (int a = 0; a < temp_v_vbo.size(); a += 3) {
|
||||||
|
boolean vertex_found = true;
|
||||||
|
|
||||||
|
for (int b = 0; b < 3; b++) {
|
||||||
|
if (temp_v_vbo.get(a + b) != v.get(vertex_index + b)) {
|
||||||
|
vertex_found = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vertex_found) {
|
||||||
|
i.add(a / 3);
|
||||||
|
vbo_el_found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!vbo_el_found) {
|
||||||
|
for (int a = 0; a < 3; a++)
|
||||||
|
temp_v_vbo.add(v.get(vertex_index + a));
|
||||||
|
|
||||||
|
i.add((temp_v_vbo.size() / 3) - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.xfe.engine.world;
|
|||||||
|
|
||||||
import org.lwjgl.opengl.GL30;
|
import org.lwjgl.opengl.GL30;
|
||||||
import org.lwjgl.system.MemoryStack;
|
import org.lwjgl.system.MemoryStack;
|
||||||
|
import org.lwjgl.system.MemoryUtil;
|
||||||
import org.xfe.engine.files.Obj;
|
import org.xfe.engine.files.Obj;
|
||||||
|
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
@@ -64,6 +65,8 @@ public class Mesh {
|
|||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||||
glBufferData(GL_ARRAY_BUFFER, vertices_buffer, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, vertices_buffer, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
MemoryUtil.memFree(vertices_buffer);
|
||||||
|
|
||||||
// Set Position Attribute
|
// Set Position Attribute
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
|
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
|
||||||
@@ -96,14 +99,16 @@ public class Mesh {
|
|||||||
|
|
||||||
// Bind indices in EBO
|
// Bind indices in EBO
|
||||||
if (this.indices.length > 0) {
|
if (this.indices.length > 0) {
|
||||||
|
|
||||||
|
System.out.println(indices.length);
|
||||||
vbo_id = glGenBuffers();
|
vbo_id = glGenBuffers();
|
||||||
vbo_id_list.add(vbo_id);
|
vbo_id_list.add(vbo_id);
|
||||||
|
|
||||||
IntBuffer indice_buffer = stack.callocInt(indices.length);
|
// IntBuffer indice_buffer = stack.callocInt(indices.length);
|
||||||
indice_buffer.put(0, this.indices);
|
// indice_buffer.put(0, this.indices);
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_id);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_id);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indice_buffer, GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices, GL_STATIC_DRAW);
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class Main implements GameLogic {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Window window, World world, Render render) {
|
public void init(Window window, World world, Render render) {
|
||||||
Entity cube = new Entity("resources/objs/sphere.obj", "resources/shaders/shader.frag", "resources/shaders/shader.vert");
|
Entity cube = new Entity("resources/objs/teapot.obj", "resources/shaders/shader.frag", "resources/shaders/shader.vert");
|
||||||
cube.model = new Matrix4f().identity().translate(0, 0, -10);
|
cube.model = new Matrix4f().identity().translate(0, 0, -10);
|
||||||
|
|
||||||
System.out.println(cube.model.toString());
|
System.out.println(cube.model.toString());
|
||||||
@@ -39,8 +39,9 @@ public class Main implements GameLogic {
|
|||||||
world.entities.get(0).model = new Matrix4f()
|
world.entities.get(0).model = new Matrix4f()
|
||||||
.identity()
|
.identity()
|
||||||
.translate(0, 0, -5)
|
.translate(0, 0, -5)
|
||||||
.rotate(ang, 0,1, 0)
|
.translate(0, -2, 0)
|
||||||
.rotate(ang * 2, 0, 0, 1);
|
.rotate(ang, 0,1, 0);
|
||||||
|
// .rotate(ang * 2, 0, 0, 1);
|
||||||
ang += 1.0f/100.0f;
|
ang += 1.0f/100.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user