From 1f9f5796639154512c26334a51f82d5423bfe991 Mon Sep 17 00:00:00 2001 From: pahimar Date: Fri, 15 Mar 2013 15:18:01 -0400 Subject: [PATCH] More pruning --- .../pahimar/ee3/client/model/ModelAludel.java | 12 +- .../ee3/client/model/ModelCalcinator.java | 12 +- .../minecraftforge/client/model/obj/Face.java | 35 ++-- .../client/model/obj/Group.java | 16 +- .../client/model/obj/TextureCoordinate.java | 35 +--- .../client/model/obj/Vertex.java | 158 +----------------- .../client/model/obj/WavefrontObject.java | 52 +++--- .../client/model/obj/parser/FaceParser.java | 54 +++--- .../client/model/obj/parser/NormalParser.java | 12 +- .../obj/parser/TextureCoordinateParser.java | 8 +- .../client/model/obj/parser/VertexParser.java | 12 +- 11 files changed, 104 insertions(+), 302 deletions(-) diff --git a/ee3_common/com/pahimar/ee3/client/model/ModelAludel.java b/ee3_common/com/pahimar/ee3/client/model/ModelAludel.java index 97847ea3..bcacd39c 100644 --- a/ee3_common/com/pahimar/ee3/client/model/ModelAludel.java +++ b/ee3_common/com/pahimar/ee3/client/model/ModelAludel.java @@ -57,21 +57,21 @@ public class ModelAludel extends ModelBase { float sumU = 0F; float sumV = 0F; - for (int i = 0; i < face.getTextures().length; ++i) { - sumU += face.getTextures()[i].getU(); - sumV += face.getTextures()[i].getV(); + for (int i = 0; i < face.getTextureCoordinates().length; ++i) { + sumU += face.getTextureCoordinates()[i].u; + sumV += face.getTextureCoordinates()[i].v; } for (int i = 0; i < face.getVertices().length; ++i) { float offsetU = Reference.MODEL_TEXTURE_OFFSET; float offsetV = Reference.MODEL_TEXTURE_OFFSET; - if (face.getTextures()[i].getU() > sumU / face.getTextures().length) { + if (face.getTextureCoordinates()[i].u > sumU / face.getTextureCoordinates().length) { offsetU = -offsetU; } - if (face.getTextures()[i].getV() > sumV / face.getTextures().length) { + if (face.getTextureCoordinates()[i].v > sumV / face.getTextureCoordinates().length) { offsetV = -offsetV; } - tessellator.addVertexWithUV(face.getVertices()[i].getX() * scale, face.getVertices()[i].getY() * scale, face.getVertices()[i].getZ() * scale, face.getTextures()[i].getU() + offsetU, face.getTextures()[i].getV() + offsetV); + tessellator.addVertexWithUV(face.getVertices()[i].x * scale, face.getVertices()[i].y * scale, face.getVertices()[i].z * scale, face.getTextureCoordinates()[i].u + offsetU, face.getTextureCoordinates()[i].v + offsetV); } tessellator.draw(); diff --git a/ee3_common/com/pahimar/ee3/client/model/ModelCalcinator.java b/ee3_common/com/pahimar/ee3/client/model/ModelCalcinator.java index f85f91af..86036a17 100644 --- a/ee3_common/com/pahimar/ee3/client/model/ModelCalcinator.java +++ b/ee3_common/com/pahimar/ee3/client/model/ModelCalcinator.java @@ -57,21 +57,21 @@ public class ModelCalcinator extends ModelBase { float sumU = 0F; float sumV = 0F; - for (int i = 0; i < face.getTextures().length; ++i) { - sumU += face.getTextures()[i].getU(); - sumV += face.getTextures()[i].getV(); + for (int i = 0; i < face.getTextureCoordinates().length; ++i) { + sumU += face.getTextureCoordinates()[i].u; + sumV += face.getTextureCoordinates()[i].v; } for (int i = 0; i < face.getVertices().length; ++i) { float offsetU = Reference.MODEL_TEXTURE_OFFSET; float offsetV = Reference.MODEL_TEXTURE_OFFSET; - if (face.getTextures()[i].getU() > sumU / face.getTextures().length) { + if (face.getTextureCoordinates()[i].u > sumU / face.getTextureCoordinates().length) { offsetU = -offsetU; } - if (face.getTextures()[i].getV() > sumV / face.getTextures().length) { + if (face.getTextureCoordinates()[i].v > sumV / face.getTextureCoordinates().length) { offsetV = -offsetV; } - tessellator.addVertexWithUV(face.getVertices()[i].getX() * scale, face.getVertices()[i].getY() * scale, face.getVertices()[i].getZ() * scale, face.getTextures()[i].getU() + offsetU, face.getTextures()[i].getV() + offsetV); + tessellator.addVertexWithUV(face.getVertices()[i].x * scale, face.getVertices()[i].y * scale, face.getVertices()[i].z * scale, face.getTextureCoordinates()[i].u + offsetU, face.getTextureCoordinates()[i].v + offsetV); } tessellator.draw(); diff --git a/ee3_common/net/minecraftforge/client/model/obj/Face.java b/ee3_common/net/minecraftforge/client/model/obj/Face.java index a5b0170b..fbc4e56f 100644 --- a/ee3_common/net/minecraftforge/client/model/obj/Face.java +++ b/ee3_common/net/minecraftforge/client/model/obj/Face.java @@ -6,18 +6,19 @@ import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class Face { - public int[] vertIndices; - public int[] normIndices; - public int[] texIndices; + public int[] vertexIndices; + public int[] vertexNormalIndices; + public int[] textureCoordinateIndices; + private Vertex[] vertices; - private Vertex[] normals; - private TextureCoordinate[] textures; + private Vertex[] vertexNormals; + private TextureCoordinate[] textureCoordinates; private int glDrawingMode; - public int[] getIndices() { + public int[] getVertexIndices() { - return vertIndices; + return vertexIndices; } public Vertex[] getVertices() { @@ -25,9 +26,9 @@ public class Face { return vertices; } - public void setIndices(int[] indices) { + public void setVertexIndices(int[] vertexIndices) { - vertIndices = indices; + this.vertexIndices = vertexIndices; } public void setVertices(Vertex[] vertices) { @@ -45,23 +46,23 @@ public class Face { this.glDrawingMode = glDrawingMode; } - public Vertex[] getNormals() { + public Vertex[] getVertexNormals() { - return normals; + return vertexNormals; } - public void setNormals(Vertex[] normals) { + public void setVertexNormals(Vertex[] vertexNormals) { - this.normals = normals; + this.vertexNormals = vertexNormals; } - public TextureCoordinate[] getTextures() { + public TextureCoordinate[] getTextureCoordinates() { - return textures; + return textureCoordinates; } - public void setTextures(TextureCoordinate[] textures) { + public void setTextureCoordinates(TextureCoordinate[] textureCoordinates) { - this.textures = textures; + this.textureCoordinates = textureCoordinates; } } diff --git a/ee3_common/net/minecraftforge/client/model/obj/Group.java b/ee3_common/net/minecraftforge/client/model/obj/Group.java index 93c7853f..cb78eacb 100644 --- a/ee3_common/net/minecraftforge/client/model/obj/Group.java +++ b/ee3_common/net/minecraftforge/client/model/obj/Group.java @@ -14,8 +14,8 @@ public class Group { public ArrayList indices = new ArrayList(); public ArrayList vertices = new ArrayList(); - public ArrayList normals = new ArrayList(); - public ArrayList texcoords = new ArrayList(); + public ArrayList vertexNormals = new ArrayList(); + public ArrayList textureCoordinates = new ArrayList(); public int indexCount; public Group(String name) { @@ -40,14 +40,14 @@ public class Group { currentFace = faces.get(i); for (int j = 0; j < currentFace.getVertices().length; j++) { currentVertex = currentFace.getVertices()[j]; - if (Math.abs(currentVertex.getX()) > minX) { - minX = Math.abs(currentVertex.getX()); + if (Math.abs(currentVertex.x) > minX) { + minX = Math.abs(currentVertex.x); } - if (Math.abs(currentVertex.getY()) > minY) { - minY = Math.abs(currentVertex.getY()); + if (Math.abs(currentVertex.y) > minY) { + minY = Math.abs(currentVertex.y); } - if (Math.abs(currentVertex.getZ()) > minZ) { - minZ = Math.abs(currentVertex.getZ()); + if (Math.abs(currentVertex.z) > minZ) { + minZ = Math.abs(currentVertex.z); } } } diff --git a/ee3_common/net/minecraftforge/client/model/obj/TextureCoordinate.java b/ee3_common/net/minecraftforge/client/model/obj/TextureCoordinate.java index a061c6a4..9607d528 100644 --- a/ee3_common/net/minecraftforge/client/model/obj/TextureCoordinate.java +++ b/ee3_common/net/minecraftforge/client/model/obj/TextureCoordinate.java @@ -6,38 +6,5 @@ import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class TextureCoordinate { - private float u; - private float v; - private float w; - - public float getU() { - - return u; - } - - public void setU(float u) { - - this.u = u; - } - - public float getV() { - - return v; - } - - public void setV(float v) { - - this.v = v; - } - - public float getW() { - - return w; - } - - public void setW(float w) { - - this.w = w; - } - + public float u, v, w; } diff --git a/ee3_common/net/minecraftforge/client/model/obj/Vertex.java b/ee3_common/net/minecraftforge/client/model/obj/Vertex.java index a99df997..573d6760 100644 --- a/ee3_common/net/minecraftforge/client/model/obj/Vertex.java +++ b/ee3_common/net/minecraftforge/client/model/obj/Vertex.java @@ -6,9 +6,7 @@ import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class Vertex { - private float x; - private float y; - private float z; + public float x, y, z; public Vertex() { @@ -21,159 +19,15 @@ public class Vertex { this.z = z; } - public Vertex(int i, int j) { + public Vertex(Vertex vertex) { - setX(i); - setY(j); + this.x = vertex.x; + this.y = vertex.y; + this.z = vertex.z; } - public Vertex(Vertex position) { - - setX(position.getX()); - setY(position.getY()); - setZ(position.getZ()); - } - - public float getX() { - - return x; - } - - public void setX(float x) { - - this.x = x; - } - - public float getY() { - - return y; - } - - public void setY(float y) { - - this.y = y; - } - - public float getZ() { - - return z; - } - - public void setZ(float z) { - - this.z = z; - } - - public double norm() { - - return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)); - } - - public void normalize() { - - double norm = norm(); - - setX(getX() / (float) norm); - setY(getY() / (float) norm); - setZ(getZ() / (float) norm); - } - - public double distanceFrom(Vertex to) { - - return Math.sqrt(this.getX() * to.getX() + this.getY() + to.getY() + this.getZ() * to.getZ()); - } - - public Vertex rotateZ(double angle) { - - float savedX = getX(); - x = (float) (x * Math.cos(angle) + y * Math.sin(angle)); - y = (float) (savedX * -Math.sin(angle) + y * Math.cos(angle)); - - return this; - - } - - public Vertex rotateX(double angle) { - - // Rotation matrix on X is - // 1 0 0 - // 0 cos(x) sin(x) - // 0 -sin(x) cos(x) - float savedY = y; - y = (float) (y * Math.cos(angle) + z * -Math.sin(angle)); - z = (float) (savedY * Math.sin(angle) + z * Math.cos(angle)); - return this; - - } - - public Vertex copyAndRotateZ(float angle) { - - float newX = (float) (x * Math.cos(angle) + y * Math.sin(angle)); - float newY = (float) (x * -Math.sin(angle) + y * Math.cos(angle)); - - return new Vertex(newX, newY, z); - - } - - public void add(Vertex offSet) { - - x += offSet.getX(); - y += offSet.getY(); - z += offSet.getZ(); - } - - public Vertex copyAndAdd(Vertex offSet) { - - return new Vertex(getX() + offSet.getX(), getY() + offSet.getY(), getZ() + offSet.getZ()); - } - - public Vertex mult(Vertex offSet) { - - return new Vertex(getX() * offSet.getX(), getY() * offSet.getY(), getZ() * offSet.getZ()); - } - - public Vertex mult(double factor) { - - return mult((float) factor); - } - - public Vertex mult(float factor) { - - return new Vertex(getX() * factor, getY() * factor, getZ() * factor); - } - - public Vertex copyAndSub(Vertex v) { - - // TODO Auto-generated method stub - return new Vertex(getX() - v.getX(), getY() - v.getY(), getZ() - v.getZ()); - } - - public Vertex copyAndMult(float coef) { - - // TODO Auto-generated method stub - return new Vertex(getX() * coef, getY() * coef, getZ() * coef); - } - - public float dot(Vertex v) { - - return v.x * x + v.y * y;//+ v.z * z; - } - - public float perpDot(Vertex v) { - - return x * v.y - y * v.x; - } - - public void subFrom(Vertex position) { - - setX(position.getX() - getX()); - setY(position.getY() - getY()); - setZ(position.getZ() - getZ()); - } - - @Override public String toString() { - return "x=" + x + ",y=" + y + ",z=" + z; + return "x: " + x + ", y: " + y + ", z: " + z; } } diff --git a/ee3_common/net/minecraftforge/client/model/obj/WavefrontObject.java b/ee3_common/net/minecraftforge/client/model/obj/WavefrontObject.java index ff828d36..460ab88a 100644 --- a/ee3_common/net/minecraftforge/client/model/obj/WavefrontObject.java +++ b/ee3_common/net/minecraftforge/client/model/obj/WavefrontObject.java @@ -16,7 +16,7 @@ import cpw.mods.fml.relauncher.SideOnly; public class WavefrontObject { private ArrayList vertices = new ArrayList(); - private ArrayList normals = new ArrayList(); + private ArrayList vertexNormals = new ArrayList(); private ArrayList textureCoordinates = new ArrayList(); private ArrayList groups = new ArrayList(); private Hashtable groupsDirectAccess = new Hashtable(); @@ -68,26 +68,12 @@ public class WavefrontObject { this.zScale = zScale; parse(fileName); - - calculateRadius(); } catch (Exception e) { System.out.println("Error, could not load obj:" + fileName); } } - private void calculateRadius() { - - double currentNorm = 0; - for (Vertex vertex : vertices) { - currentNorm = vertex.norm(); - if (currentNorm > radius) { - radius = currentNorm; - } - } - - } - public void parse(String fileName) { BufferedReader reader = null; @@ -128,9 +114,9 @@ public class WavefrontObject { } } - public void setTextureCoordinates(ArrayList textures) { + public void setTextureCoordinates(ArrayList textureCoordinates) { - textureCoordinates = textures; + this.textureCoordinates = textureCoordinates; } public ArrayList getTextureCoordinates() { @@ -148,14 +134,14 @@ public class WavefrontObject { return vertices; } - public void setNormals(ArrayList normals) { + public void setVertexNormals(ArrayList vertexNormals) { - this.normals = normals; + this.vertexNormals = vertexNormals; } - public ArrayList getNormals() { + public ArrayList getVertexNormals() { - return normals; + return vertexNormals; } public ArrayList getGroups() { @@ -190,25 +176,25 @@ public class WavefrontObject { Vertex currentVertex = null; for (int i = 0; i < getVertices().size(); i++) { currentVertex = getVertices().get(i); - if (currentVertex.getX() > maxX) { - maxX = currentVertex.getX(); + if (currentVertex.x > maxX) { + maxX = currentVertex.x; } - if (currentVertex.getX() < minX) { - minX = currentVertex.getX(); + if (currentVertex.x < minX) { + minX = currentVertex.x; } - if (currentVertex.getY() > maxY) { - maxY = currentVertex.getY(); + if (currentVertex.y > maxY) { + maxY = currentVertex.y; } - if (currentVertex.getY() < minY) { - minY = currentVertex.getY(); + if (currentVertex.y < minY) { + minY = currentVertex.y; } - if (currentVertex.getZ() > maxZ) { - maxZ = currentVertex.getZ(); + if (currentVertex.z > maxZ) { + maxZ = currentVertex.z; } - if (currentVertex.getZ() < minZ) { - minZ = currentVertex.getZ(); + if (currentVertex.z < minZ) { + minZ = currentVertex.z; } } diff --git a/ee3_common/net/minecraftforge/client/model/obj/parser/FaceParser.java b/ee3_common/net/minecraftforge/client/model/obj/parser/FaceParser.java index 801d3b92..6c04d27f 100644 --- a/ee3_common/net/minecraftforge/client/model/obj/parser/FaceParser.java +++ b/ee3_common/net/minecraftforge/client/model/obj/parser/FaceParser.java @@ -94,7 +94,7 @@ public class FaceParser extends LineParser { currentValue = Integer.parseInt(rawFaces[2]); nindices[i - 1] = currentValue - 1; - normals[i - 1] = object.getNormals().get(currentValue - 1); // -1 because references starts at 1 + normals[i - 1] = object.getVertexNormals().get(currentValue - 1); // -1 because references starts at 1 } //System.out.println(""); } @@ -124,23 +124,23 @@ public class FaceParser extends LineParser { group.vertices.add(vertices[0]); group.vertices.add(vertices[1]); group.vertices.add(vertices[2]); - group.normals.add(normals[0]); - group.normals.add(normals[1]); - group.normals.add(normals[2]); - group.texcoords.add(textures[0]); - group.texcoords.add(textures[1]); - group.texcoords.add(textures[2]); + group.vertexNormals.add(normals[0]); + group.vertexNormals.add(normals[1]); + group.vertexNormals.add(normals[2]); + group.textureCoordinates.add(textures[0]); + group.textureCoordinates.add(textures[1]); + group.textureCoordinates.add(textures[2]); group.indices.add(group.indexCount++); group.indices.add(group.indexCount++); group.indices.add(group.indexCount++); // create index list for current object - face.vertIndices = vindices; - face.normIndices = nindices; - face.texIndices = tindices; - face.setNormals(normals); - face.setNormals(normals); + face.vertexIndices = vindices; + face.vertexNormalIndices = nindices; + face.textureCoordinateIndices = tindices; + face.setVertexNormals(normals); + face.setVertexNormals(normals); face.setVertices(vertices); - face.setTextures(textures); + face.setTextureCoordinates(textures); wavefrontObject.getCurrentGroup().addFace(face); } @@ -151,26 +151,26 @@ public class FaceParser extends LineParser { group.vertices.add(vertices[1]); group.vertices.add(vertices[2]); group.vertices.add(vertices[3]); - group.normals.add(normals[0]); - group.normals.add(normals[1]); - group.normals.add(normals[2]); - group.normals.add(normals[3]); - group.texcoords.add(textures[0]); - group.texcoords.add(textures[1]); - group.texcoords.add(textures[2]); - group.texcoords.add(textures[3]); + group.vertexNormals.add(normals[0]); + group.vertexNormals.add(normals[1]); + group.vertexNormals.add(normals[2]); + group.vertexNormals.add(normals[3]); + group.textureCoordinates.add(textures[0]); + group.textureCoordinates.add(textures[1]); + group.textureCoordinates.add(textures[2]); + group.textureCoordinates.add(textures[3]); group.indices.add(group.indexCount++); group.indices.add(group.indexCount++); group.indices.add(group.indexCount++); group.indices.add(group.indexCount++); // create index list for current object - face.vertIndices = vindices; - face.normIndices = nindices; - face.texIndices = tindices; - face.setNormals(normals); - face.setNormals(normals); + face.vertexIndices = vindices; + face.vertexNormalIndices = nindices; + face.textureCoordinateIndices = tindices; + face.setVertexNormals(normals); + face.setVertexNormals(normals); face.setVertices(vertices); - face.setTextures(textures); + face.setTextureCoordinates(textures); wavefrontObject.getCurrentGroup().addFace(face); } diff --git a/ee3_common/net/minecraftforge/client/model/obj/parser/NormalParser.java b/ee3_common/net/minecraftforge/client/model/obj/parser/NormalParser.java index 263d4e51..0f5bf165 100644 --- a/ee3_common/net/minecraftforge/client/model/obj/parser/NormalParser.java +++ b/ee3_common/net/minecraftforge/client/model/obj/parser/NormalParser.java @@ -11,8 +11,6 @@ public class NormalParser extends LineParser { Vertex vertex = null; public NormalParser() { - - // TODO Auto-generated constructor stub } @Override @@ -21,9 +19,9 @@ public class NormalParser extends LineParser { vertex = new Vertex(); try { - vertex.setX(Float.parseFloat(words[1])); - vertex.setY(Float.parseFloat(words[2])); - vertex.setZ(Float.parseFloat(words[3])); + vertex.x = (Float.parseFloat(words[1])); + vertex.y = (Float.parseFloat(words[2])); + vertex.z = (Float.parseFloat(words[3])); } catch (Exception e) { throw new RuntimeException("NormalParser Error"); @@ -34,8 +32,6 @@ public class NormalParser extends LineParser { @Override public void incoporateResults(WavefrontObject wavefrontObject) { - wavefrontObject.getNormals().add(vertex); - + wavefrontObject.getVertexNormals().add(vertex); } - } diff --git a/ee3_common/net/minecraftforge/client/model/obj/parser/TextureCoordinateParser.java b/ee3_common/net/minecraftforge/client/model/obj/parser/TextureCoordinateParser.java index c138bb92..295893ed 100644 --- a/ee3_common/net/minecraftforge/client/model/obj/parser/TextureCoordinateParser.java +++ b/ee3_common/net/minecraftforge/client/model/obj/parser/TextureCoordinateParser.java @@ -20,15 +20,15 @@ public class TextureCoordinateParser extends LineParser { coordinate = new TextureCoordinate(); try { if (words.length >= 2) { - coordinate.setU(Float.parseFloat(words[1])); + coordinate.u = (Float.parseFloat(words[1])); } if (words.length >= 3) { - coordinate.setV(1 - Float.parseFloat(words[2])); // OBJ origin is at upper left, OpenGL origin is at lower left. + coordinate.v = (1 - Float.parseFloat(words[2])); // OBJ origin is at upper left, OpenGL origin is at lower left. } if (words.length >= 4) { - coordinate.setW(Float.parseFloat(words[3])); + coordinate.w = (Float.parseFloat(words[3])); } } @@ -41,7 +41,5 @@ public class TextureCoordinateParser extends LineParser { public void incoporateResults(WavefrontObject wavefrontObject) { wavefrontObject.getTextureCoordinates().add(coordinate); - } - } diff --git a/ee3_common/net/minecraftforge/client/model/obj/parser/VertexParser.java b/ee3_common/net/minecraftforge/client/model/obj/parser/VertexParser.java index e376553e..759842e8 100644 --- a/ee3_common/net/minecraftforge/client/model/obj/parser/VertexParser.java +++ b/ee3_common/net/minecraftforge/client/model/obj/parser/VertexParser.java @@ -20,9 +20,9 @@ public class VertexParser extends LineParser { vertex = new Vertex(); try { - vertex.setX(Float.parseFloat(words[1])); - vertex.setY(Float.parseFloat(words[2])); - vertex.setZ(Float.parseFloat(words[3])); + vertex.x = (Float.parseFloat(words[1])); + vertex.y = (Float.parseFloat(words[2])); + vertex.z = (Float.parseFloat(words[3])); } catch (Exception e) { throw new RuntimeException("VertexParser Error"); @@ -32,9 +32,9 @@ public class VertexParser extends LineParser { @Override public void incoporateResults(WavefrontObject wavefrontObject) { - vertex.setX((vertex.getX() + wavefrontObject.translate.getX()) * wavefrontObject.xScale); - vertex.setY((vertex.getY() + wavefrontObject.translate.getY()) * wavefrontObject.yScale); - vertex.setZ((vertex.getZ() + wavefrontObject.translate.getZ()) * wavefrontObject.zScale); + vertex.x = ((vertex.x + wavefrontObject.translate.x) * wavefrontObject.xScale); + vertex.y = ((vertex.y + wavefrontObject.translate.y) * wavefrontObject.yScale); + vertex.z = ((vertex.z + wavefrontObject.translate.z) * wavefrontObject.zScale); wavefrontObject.getVertices().add(vertex); }