Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions src/main/java/cam72cam/mod/model/obj/FaceAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,12 @@ public FaceAccessor getSubByGroup(String groupName) {
* @return OBJFace of current face
*/
public OBJFace asOBJFace() {
OBJFace face = new OBJFace();

face.vertex0 = new OBJFace.Vertex(v0);
face.vertex1 = new OBJFace.Vertex(v1);
face.vertex2 = new OBJFace.Vertex(v2);

if (vbo.hasNormals) {
face.normal = v0.normAsVec3d();
} else {
Vec3d v0 = face.vertex0.pos;
Vec3d v1 = face.vertex1.pos;
Vec3d v2 = face.vertex2.pos;
face.normal = v1.subtract(v0).crossProduct(v2.subtract(v0)).normalize();
}
return face;
OBJFace.Vertex vert0 = new OBJFace.Vertex(v0);
OBJFace.Vertex vert1 = new OBJFace.Vertex(v1);
OBJFace.Vertex vert2 = new OBJFace.Vertex(v2);
return new OBJFace(vert0, vert1, vert2,
vbo.hasNormals ? v0.normAsVec3d()
: vert1.pos.subtract(vert0.pos).crossProduct(vert2.pos.subtract(vert0.pos)).normalize());
}

/**
Expand Down
42 changes: 24 additions & 18 deletions src/main/java/cam72cam/mod/model/obj/OBJFace.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,38 @@
import cam72cam.mod.math.Vec3d;

public class OBJFace {
public Vertex vertex0;
public Vertex vertex1;
public Vertex vertex2;

public Vec3d normal;
public final Vertex vertex0;
public final Vertex vertex1;
public final Vertex vertex2;

public final Vec3d normal;
//TODO more accurate one
private IBoundingBox box;

public OBJFace(Vertex vertex0, Vertex vertex1, Vertex vertex2, Vec3d normal) {
this.vertex0 = vertex0;
this.vertex1 = vertex1;
this.vertex2 = vertex2;
this.normal = normal;
}

public IBoundingBox getBoundingBox() {
Vec3d min = vertex0.pos.min(vertex1.pos.min(vertex2.pos));
Vec3d max = vertex0.pos.max(vertex1.pos.max(vertex2.pos));
return IBoundingBox.from(min, max);
if (box == null) {
//Uses AABB for now but we may want OBB or something more accurate in the future
Vec3d min = vertex0.pos.min(vertex1.pos.min(vertex2.pos));
Vec3d max = vertex0.pos.max(vertex1.pos.max(vertex2.pos));
box = IBoundingBox.from(min, max);
}
return box;
}

public OBJFace scale(double factor) {
OBJFace scaled = new OBJFace();

scaled.vertex0 = vertex0.scale(factor);
scaled.vertex1 = vertex1.scale(factor);
scaled.vertex2 = vertex2.scale(factor);

scaled.normal = new Vec3d(normal.internal());
return scaled;
return new OBJFace(vertex0.scale(factor), vertex1.scale(factor), vertex2.scale(factor), normal);
}

public static class Vertex {
public Vec3d pos;
public Vec2f uv;
public final Vec3d pos;
public final Vec2f uv;

public Vertex(Vec3d vertex, Vec2f uv) {
this.pos = vertex;
Expand Down