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
17 changes: 8 additions & 9 deletions src/main/java/cam72cam/mod/model/obj/FaceAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,17 @@ public FaceAccessor getSubByGroup(String groupName) {
*/
public OBJFace asOBJFace() {
OBJFace face = new OBJFace();
face.vertices.add(v0.posAsVec3d());
face.vertices.add(v1.posAsVec3d());
face.vertices.add(v2.posAsVec3d());
face.uv.add(v0.uvAsVec2f());
face.uv.add(v1.uvAsVec2f());
face.uv.add(v2.uvAsVec2f());

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.vertices.get(0);
Vec3d v1 = face.vertices.get(1);
Vec3d v2 = face.vertices.get(2);
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;
Expand Down
42 changes: 32 additions & 10 deletions src/main/java/cam72cam/mod/model/obj/OBJFace.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,47 @@
import cam72cam.mod.entity.boundingbox.IBoundingBox;
import cam72cam.mod.math.Vec3d;

import java.util.ArrayList;
import java.util.List;

public class OBJFace {
public List<Vec3d> vertices = new ArrayList<>(3);
public Vertex vertex0;
public Vertex vertex1;
public Vertex vertex2;

public Vec3d normal;
public List<Vec2f> uv = new ArrayList<>(3);

public IBoundingBox getBoundingBox() {
Vec3d min = vertices.get(0).min(vertices.get(1).min(vertices.get(2)));
Vec3d max = vertices.get(0).max(vertices.get(1).max(vertices.get(2)));
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);
}

public OBJFace scale(double scale) {
public OBJFace scale(double factor) {
OBJFace scaled = new OBJFace();
vertices.forEach(vec3d -> scaled.vertices.add(vec3d.scale(scale)));

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

scaled.normal = new Vec3d(normal.internal());
scaled.uv = new ArrayList<>(uv);
return scaled;
}

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

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

public Vertex(FaceAccessor.VertexAccessor accessor) {
this.pos = accessor.posAsVec3d();
this.uv = accessor.uvAsVec2f();
}

public Vertex scale(double factor) {
Vec3d newPos = pos.scale(factor);
return new Vertex(newPos, uv);
}
}
}