diff --git a/ee3_common/com/pahimar/ee3/client/model/ModelAludel.java b/ee3_common/com/pahimar/ee3/client/model/ModelAludel.java index e9151cdd..08c8819f 100644 --- a/ee3_common/com/pahimar/ee3/client/model/ModelAludel.java +++ b/ee3_common/com/pahimar/ee3/client/model/ModelAludel.java @@ -1,6 +1,7 @@ package com.pahimar.ee3.client.model; import net.minecraft.client.model.ModelBase; +import net.minecraftforge.client.model.ICustomModel; import net.minecraftforge.client.model.obj.WavefrontObject; import net.minecraftforge.common.ForgeDirection; @@ -24,7 +25,7 @@ import cpw.mods.fml.relauncher.SideOnly; * */ @SideOnly(Side.CLIENT) -public class ModelAludel extends ModelBase { +public class ModelAludel extends ModelBase implements ICustomModel { private WavefrontObject modelAludelOBJ; diff --git a/ee3_common/com/pahimar/ee3/client/model/ModelCalcinator.java b/ee3_common/com/pahimar/ee3/client/model/ModelCalcinator.java index b0e183b8..09566aa4 100644 --- a/ee3_common/com/pahimar/ee3/client/model/ModelCalcinator.java +++ b/ee3_common/com/pahimar/ee3/client/model/ModelCalcinator.java @@ -1,6 +1,7 @@ package com.pahimar.ee3.client.model; import net.minecraft.client.model.ModelBase; +import net.minecraftforge.client.model.ICustomModel; import net.minecraftforge.client.model.obj.WavefrontObject; import org.lwjgl.opengl.GL11; @@ -23,7 +24,7 @@ import cpw.mods.fml.relauncher.SideOnly; * */ @SideOnly(Side.CLIENT) -public class ModelCalcinator extends ModelBase { +public class ModelCalcinator extends ModelBase implements ICustomModel { private WavefrontObject modelCalcinatorOBJ; diff --git a/ee3_common/net/minecraftforge/client/model/ICustomModel.java b/ee3_common/net/minecraftforge/client/model/ICustomModel.java new file mode 100644 index 00000000..205d43a7 --- /dev/null +++ b/ee3_common/net/minecraftforge/client/model/ICustomModel.java @@ -0,0 +1,8 @@ +package net.minecraftforge.client.model; + + +public interface ICustomModel { + + public abstract void render(); + +} diff --git a/ee3_common/net/minecraftforge/client/model/obj/WavefrontObject.java b/ee3_common/net/minecraftforge/client/model/obj/WavefrontObject.java index 1ff75a17..09d56f58 100644 --- a/ee3_common/net/minecraftforge/client/model/obj/WavefrontObject.java +++ b/ee3_common/net/minecraftforge/client/model/obj/WavefrontObject.java @@ -6,6 +6,8 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.zip.DataFormatException; import net.minecraft.client.renderer.Tessellator; @@ -15,23 +17,26 @@ import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -/*** - * - * Wavefront Object importer; based heavily off of the specifications found at http://en.wikipedia.org/wiki/Wavefront_.obj_file - * +/** + * Wavefront Object importer + * Based heavily off of the specifications found at http://en.wikipedia.org/wiki/Wavefront_.obj_file */ @SideOnly(Side.CLIENT) public class WavefrontObject { - private static final String REGEX_VERTEX = "(v( (\\-){0,1}\\d+\\.\\d+){3,4} *\\n)|(v( (\\-){0,1}\\d+\\.\\d+){3,4} *$)"; - private static final String REGEX_VERTEX_NORMAL = "(vn( (\\-){0,1}\\d+\\.\\d+){3,4} *\\n)|(vn( (\\-){0,1}\\d+\\.\\d+){3,4} *$)"; - private static final String REGEX_TEXTURE_COORDINATE = "(vt( (\\-){0,1}\\d+\\.\\d+){3,4} *\\n)|(vt( (\\-){0,1}\\d+\\.\\d+){3,4} *$)"; - private static final String REGEX_FACE_VERTEX_TEXTURECOORD_VERTEXNORMAL = "(f( \\d+/\\d+/\\d+){3,4} *\\n)|(f( \\d+/\\d+/\\d+){3,4} *$)"; - private static final String REGEX_FACE_VERTEX_TEXTURECOORD = "(f( \\d+/\\d+){3,4} *\\n)|(f( \\d+/\\d+){3,4} *$)"; - private static final String REGEX_FACE_VERTEX_VERTEXNORMAL = "(f( \\d+//\\d+){3,4} *\\n)|(f( \\d+//\\d+){3,4} *$)"; - private static final String REGEX_FACE_VERTEX = "(f( \\d+){3,4} *\\n)|(f( \\d+){3,4} *$)"; - private static final String REGEX_GROUP_OBJECT = "([go]( [\\w\\d]+) *\\n)|([go]( [\\w\\d]+) *$)"; + private static Pattern vertexPattern = Pattern.compile("(v( (\\-){0,1}\\d+\\.\\d+){3,4} *\\n)|(v( (\\-){0,1}\\d+\\.\\d+){3,4} *$)"); + private static Pattern vertexNormalPattern = Pattern.compile("(vn( (\\-){0,1}\\d+\\.\\d+){3,4} *\\n)|(vn( (\\-){0,1}\\d+\\.\\d+){3,4} *$)"); + private static Pattern textureCoordinatePattern = Pattern.compile("(vt( (\\-){0,1}\\d+\\.\\d+){2,3} *\\n)|(vt( (\\-){0,1}\\d+\\.\\d+){2,3} *$)"); + private static Pattern face_V_VT_VN_Pattern = Pattern.compile("(f( \\d+/\\d+/\\d+){3,4} *\\n)|(f( \\d+/\\d+/\\d+){3,4} *$)"); + private static Pattern face_V_VT_Pattern = Pattern.compile("(f( \\d+/\\d+){3,4} *\\n)|(f( \\d+/\\d+){3,4} *$)"); + private static Pattern face_V_VN_Pattern = Pattern.compile("(f( \\d+//\\d+){3,4} *\\n)|(f( \\d+//\\d+){3,4} *$)"); + private static Pattern face_V_Pattern = Pattern.compile("(f( \\d+){3,4} *\\n)|(f( \\d+){3,4} *$)"); + private static Pattern groupObjectPattern = Pattern.compile("([go]( [\\w\\d]+) *\\n)|([go]( [\\w\\d]+) *$)"); + + private static Matcher vertexMatcher, vertexNormalMatcher, textureCoordinateMatcher; + private static Matcher face_V_VT_VN_Matcher, face_V_VT_Matcher, face_V_VN_Matcher, face_V_Matcher; + private static Matcher groupObjectMatcher; public ArrayList vertices = new ArrayList(); public ArrayList vertexNormals = new ArrayList(); @@ -351,7 +356,7 @@ public class WavefrontObject face.vertexNormals = new Vertex[tokens.length]; // f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 ... - if (line.matches(REGEX_FACE_VERTEX_TEXTURECOORD_VERTEXNORMAL)) + if (isValidFace_V_VT_VN_Line(line)) { for (int i = 0; i < tokens.length; ++i) { @@ -365,7 +370,7 @@ public class WavefrontObject face.faceNormal = face.calculateFaceNormal(); } // f v1/vt1 v2/vt2 v3/vt3 ... - else if (line.matches(REGEX_FACE_VERTEX_TEXTURECOORD)) + else if (isValidFace_V_VT_Line(line)) { for (int i = 0; i < tokens.length; ++i) { @@ -378,7 +383,7 @@ public class WavefrontObject face.faceNormal = face.calculateFaceNormal(); } // f v1//vn1 v2//vn2 v3//vn3 ... - else if (line.matches(REGEX_FACE_VERTEX_VERTEXNORMAL)) + else if (isValidFace_V_VN_Line(line)) { for (int i = 0; i < tokens.length; ++i) { @@ -391,7 +396,7 @@ public class WavefrontObject face.faceNormal = face.calculateFaceNormal(); } // f v1 v2 v3 ... - else if (line.matches(REGEX_FACE_VERTEX)) + else if (isValidFace_V_Line(line)) { for (int i = 0; i < tokens.length; ++i) { @@ -434,33 +439,141 @@ public class WavefrontObject return group; } + /*** + * Verifies that the given line from the model file is a valid vertex + * @param line the line being validated + * @return true if the line is a valid vertex, false otherwise + */ private static boolean isValidVertexLine(String line) { - - return line.matches(REGEX_VERTEX); + if (vertexMatcher != null) + { + vertexMatcher.reset(); + } + + vertexMatcher = vertexPattern.matcher(line); + return vertexMatcher.matches(); } + /*** + * Verifies that the given line from the model file is a valid vertex normal + * @param line the line being validated + * @return true if the line is a valid vertex normal, false otherwise + */ private static boolean isValidVertexNormalLine(String line) { + if (vertexNormalMatcher != null) + { + vertexNormalMatcher.reset(); + } - return line.matches(REGEX_VERTEX_NORMAL); + vertexNormalMatcher = vertexNormalPattern.matcher(line); + return vertexNormalMatcher.matches(); } + /*** + * Verifies that the given line from the model file is a valid texture coordinate + * @param line the line being validated + * @return true if the line is a valid texture coordinate, false otherwise + */ private static boolean isValidTextureCoordinateLine(String line) { + if (textureCoordinateMatcher != null) + { + textureCoordinateMatcher.reset(); + } - return line.matches(REGEX_TEXTURE_COORDINATE); + textureCoordinateMatcher = textureCoordinatePattern.matcher(line); + return textureCoordinateMatcher.matches(); } - - private static boolean isValidFaceLine(String line) + + /*** + * Verifies that the given line from the model file is a valid face that is described by vertices, texture coordinates, and vertex normals + * @param line the line being validated + * @return true if the line is a valid face that matches the format "f v1/vt1/vn1 ..." (with a minimum of 3 points in the face, and a maximum of 4), false otherwise + */ + private static boolean isValidFace_V_VT_VN_Line(String line) { + if (face_V_VT_VN_Matcher != null) + { + face_V_VT_VN_Matcher.reset(); + } - return line.matches(REGEX_FACE_VERTEX_TEXTURECOORD_VERTEXNORMAL) || line.matches(REGEX_FACE_VERTEX_TEXTURECOORD) || line.matches(REGEX_FACE_VERTEX_VERTEXNORMAL) || line.matches(REGEX_FACE_VERTEX); + face_V_VT_VN_Matcher = face_V_VT_VN_Pattern.matcher(line); + return face_V_VT_VN_Matcher.matches(); + } + + /*** + * Verifies that the given line from the model file is a valid face that is described by vertices and texture coordinates + * @param line the line being validated + * @return true if the line is a valid face that matches the format "f v1/vt1 ..." (with a minimum of 3 points in the face, and a maximum of 4), false otherwise + */ + private static boolean isValidFace_V_VT_Line(String line) + { + if (face_V_VT_Matcher != null) + { + face_V_VT_Matcher.reset(); + } + + face_V_VT_Matcher = face_V_VT_Pattern.matcher(line); + return face_V_VT_Matcher.matches(); + } + + /*** + * Verifies that the given line from the model file is a valid face that is described by vertices and vertex normals + * @param line the line being validated + * @return true if the line is a valid face that matches the format "f v1//vn1 ..." (with a minimum of 3 points in the face, and a maximum of 4), false otherwise + */ + private static boolean isValidFace_V_VN_Line(String line) + { + if (face_V_VN_Matcher != null) + { + face_V_VN_Matcher.reset(); + } + + face_V_VN_Matcher = face_V_VN_Pattern.matcher(line); + return face_V_VN_Matcher.matches(); + } + + /*** + * Verifies that the given line from the model file is a valid face that is described by only vertices + * @param line the line being validated + * @return true if the line is a valid face that matches the format "f v1 ..." (with a minimum of 3 points in the face, and a maximum of 4), false otherwise + */ + private static boolean isValidFace_V_Line(String line) + { + if (face_V_Matcher != null) + { + face_V_Matcher.reset(); + } + + face_V_Matcher = face_V_Pattern.matcher(line); + return face_V_Matcher.matches(); } + /*** + * Verifies that the given line from the model file is a valid face of any of the possible face formats + * @param line the line being validated + * @return true if the line is a valid face that matches any of the valid face formats, false otherwise + */ + private static boolean isValidFaceLine(String line) + { + return isValidFace_V_VT_VN_Line(line) || isValidFace_V_VT_Line(line) || isValidFace_V_VN_Line(line) || isValidFace_V_Line(line); + } + + /*** + * Verifies that the given line from the model file is a valid group (or object) + * @param line the line being validated + * @return true if the line is a valid group (or object), false otherwise + */ private static boolean isValidGroupObjectLine(String line) { + if (groupObjectMatcher != null) + { + groupObjectMatcher.reset(); + } - return line.matches(REGEX_GROUP_OBJECT); + groupObjectMatcher = groupObjectPattern.matcher(line); + return groupObjectMatcher.matches(); } }