Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Pair {
- public double u, v;
- public Pair(double u, double v) {
- this.u = u;
- this.v = v;
- }
- }
- public class Vertex extends Point3 {
- public Vector3 vn = null;
- public Pair vt = null;
- public Vertex(double x, double y, double z) {
- super(x, y, z);
- }
- }
- public class Face {
- public Vertex p0;
- public Vertex p1;
- public Vertex p2;
- public Face(Vertex p0, Vertex p1, Vertex p2) {
- this.p0 = p0;
- this.p1 = p1;
- this.p2 = p2;
- }
- }
- public class Triangle implements Object {
- public Face face; //public for debugging
- private final double epsilon = 0.00001;
- private Vector3 normal;
- private boolean smoothShaded = false;
- public Material material;
- // constructor with smooth shaded boolean for defining a normal
- public Triangle(Vertex v1, Vertex v2, Vertex v3, boolean smoothShaded) {
- face = new Face(v1, v2, v3);
- this.smoothShaded = smoothShaded;
- }
- ..........................
- //in format: v/vt/vn
- String[] aEls = a.split("/");
- String[] bEls = b.split("/");
- String[] cEls = c.split("/");
- Vertex v1 = vertexList.get(Integer.parseInt(aEls[0]) - 1);
- Vertex v2 = vertexList.get(Integer.parseInt(bEls[0]) - 1);
- Vertex v3 = vertexList.get(Integer.parseInt(cEls[0]) - 1);
- v1.vt = vtList.get(Integer.parseInt(aEls[1]) - 1);
- v2.vt = vtList.get(Integer.parseInt(bEls[1]) - 1);
- v3.vt = vtList.get(Integer.parseInt(cEls[1]) - 1);
- v1.vn = normals.get(Integer.parseInt(aEls[2]) - 1);
- v2.vn = normals.get(Integer.parseInt(bEls[2]) - 1);
- v3.vn = normals.get(Integer.parseInt(cEls[2]) - 1);
- Triangle t = new Triangle(v1, v2, v3, true);
- t.material = currentMtl;
- if (currentTexture != null) {
- t.material.texture = currentTexture;
- }
- System.out.println("unlisted!");
- System.out.println("vt 0 a: " + t.face.p0.vt.u + ", vt b: " + t.face.p0.vt.v);
- System.out.println("vt 1 a: " + t.face.p1.vt.u + ", vt b: " + t.face.p1.vt.v);
- System.out.println("vt 2 a: " + t.face.p2.vt.u + ", vt b: " + t.face.p2.vt.v);
- addTriangle(t);
- System.out.println("Current triangles: ");
- for (Triangle tr : triangleList) {
- System.out.println("vt 0 a: " + tr.face.p0.vt.u + ", vt b: " + tr.face.p0.vt.v);
- System.out.println("vt 1 a: " + tr.face.p1.vt.u + ", vt b: " + tr.face.p1.vt.v);
- System.out.println("vt 2 a: " + tr.face.p2.vt.u + ", vt b: " + tr.face.p2.vt.v);
- }
- private void addTriangle(Triangle t){
- if(triangleList != null){
- int newSize = triangleList.length + 1;
- Triangle[] temp = new Triangle[newSize];
- for(int i = 0; i < triangleList.length;i++){
- temp[i] = triangleList[i];
- }
- temp[newSize-1] = t;
- triangleList = temp;
- }else{
- triangleList = new Triangle[]{t};
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement