finished fallout config, some call list performance tests

This commit is contained in:
Boblet 2022-07-01 15:24:06 +02:00
parent d011ada90d
commit fca57450ac
10 changed files with 537 additions and 1328 deletions

View File

@ -1,5 +1,6 @@
package com.hbm.blocks.generic; package com.hbm.blocks.generic;
import java.io.IOException;
import java.util.Random; import java.util.Random;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
@ -28,6 +29,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
@ -129,6 +131,11 @@ public class BlockStorageCrate extends BlockContainer {
if(!nbt.hasNoTags()) { if(!nbt.hasNoTags()) {
drop.stackTagCompound = nbt; drop.stackTagCompound = nbt;
try {
byte[] abyte = CompressedStreamTools.compress(nbt);
//System.out.println("size: " + abyte.length); //TODO: test capacity, make sure size is <20% of maximum allowed payload
} catch(IOException e) { }
} }
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, drop)); world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, drop));

View File

@ -6,6 +6,7 @@ import java.util.Random;
import com.hbm.blocks.IBlockMulti; import com.hbm.blocks.IBlockMulti;
import com.hbm.blocks.ILookOverlay; import com.hbm.blocks.ILookOverlay;
import com.hbm.blocks.ITooltipProvider;
import com.hbm.items.ModItems; import com.hbm.items.ModItems;
import com.hbm.items.tool.ItemLock; import com.hbm.items.tool.ItemLock;
import com.hbm.lib.RefStrings; import com.hbm.lib.RefStrings;
@ -29,11 +30,12 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre; import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre;
public class BlockMassStorage extends BlockContainer implements IBlockMulti, ILookOverlay { public class BlockMassStorage extends BlockContainer implements IBlockMulti, ILookOverlay, ITooltipProvider {
@SideOnly(Side.CLIENT) private IIcon[] iconTop; @SideOnly(Side.CLIENT) private IIcon[] iconTop;
@SideOnly(Side.CLIENT) private IIcon[] iconSide; @SideOnly(Side.CLIENT) private IIcon[] iconSide;
@ -262,4 +264,17 @@ public class BlockMassStorage extends BlockContainer implements IBlockMulti, ILo
ILookOverlay.printGeneric(event, title, full ? 0xffff00 : 0x00ffff, full ? 0x404000 : 0x004040, text); ILookOverlay.printGeneric(event, title, full ? 0xffff00 : 0x00ffff, full ? 0x404000 : 0x004040, text);
} }
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
if(!stack.hasTagCompound()) return;
ItemStack type = ItemStack.loadItemStackFromNBT(stack.stackTagCompound.getCompoundTag("slot1"));
if(type != null) {
list.add(EnumChatFormatting.GOLD + type.getDisplayName());
list.add("x" + String.format("%,d", stack.stackTagCompound.getInteger("stack")));
}
}
} }

View File

@ -5,6 +5,7 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -155,7 +156,7 @@ public class FalloutConfigJSON {
try { try {
JsonObject json = gson.fromJson(new FileReader(config), JsonObject.class); JsonObject json = gson.fromJson(new FileReader(config), JsonObject.class);
JsonArray recipes = json.get("recipes").getAsJsonArray(); JsonArray recipes = json.get("entries").getAsJsonArray();
List<FalloutEntry> conf = new ArrayList(); List<FalloutEntry> conf = new ArrayList();
for(JsonElement recipe : recipes) { for(JsonElement recipe : recipes) {
@ -163,7 +164,9 @@ public class FalloutConfigJSON {
} }
return conf; return conf;
} catch(Exception ex) { } } catch(Exception ex) {
ex.printStackTrace();
}
return null; return null;
} }
@ -275,6 +278,9 @@ public class FalloutConfigJSON {
if(obj.has("mustBeOpaque")) entry.mO(obj.get("mustBeOpaque").getAsBoolean()); if(obj.has("mustBeOpaque")) entry.mO(obj.get("mustBeOpaque").getAsBoolean());
if(obj.has("matchesMaterial")) entry.mMa(matNames.get(obj.get("mustBeOpaque").getAsString())); if(obj.has("matchesMaterial")) entry.mMa(matNames.get(obj.get("mustBeOpaque").getAsString()));
if(obj.has("primarySubstitution")) entry.prim(readMetaArray(obj.get("primarySubstitution")));
if(obj.has("secondarySubstitutions")) entry.sec(readMetaArray(obj.get("secondarySubstitutions")));
return entry; return entry;
} }
@ -294,8 +300,26 @@ public class FalloutConfigJSON {
writer.setIndent(" "); writer.setIndent(" ");
} }
private static Triplet<Block, Integer, Integer>[] readMetaArray(JsonObject obj) { private static Triplet<Block, Integer, Integer>[] readMetaArray(JsonElement jsonElement) {
return null; //TODO
if(!jsonElement.isJsonArray()) return null;
JsonArray array = jsonElement.getAsJsonArray();
Triplet<Block, Integer, Integer>[] metaArray = new Triplet[array.size()];
for(int i = 0; i < metaArray.length; i++) {
JsonElement metaBlock = array.get(i);
if(!metaBlock.isJsonArray()) {
throw new IllegalStateException("Could not read meta block " + metaBlock.toString());
}
JsonArray mBArray = metaBlock.getAsJsonArray();
metaArray[i] = new Triplet(Block.blockRegistry.getObject(mBArray.get(0).getAsString()), mBArray.get(1).getAsInt(), mBArray.get(2).getAsInt());
}
return metaArray;
} }
} }

View File

@ -21,8 +21,7 @@ import net.minecraftforge.client.model.ModelFormatException;
import net.minecraftforge.client.model.obj.TextureCoordinate; import net.minecraftforge.client.model.obj.TextureCoordinate;
import net.minecraftforge.client.model.obj.Vertex; import net.minecraftforge.client.model.obj.Vertex;
public class HFRWavefrontObject implements IModelCustom public class HFRWavefrontObject implements IModelCustom {
{
private static Pattern vertexPattern = Pattern.compile("(v( (\\-){0,1}\\d+(\\.\\d+)?){3,4} *\\n)|(v( (\\-){0,1}\\d+(\\.\\d+)?){3,4} *$)"); 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 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 textureCoordinatePattern = Pattern.compile("(vt( (\\-){0,1}\\d+\\.\\d+){2,3} *\\n)|(vt( (\\-){0,1}\\d+(\\.\\d+)?){2,3} *$)");
@ -42,95 +41,75 @@ public class HFRWavefrontObject implements IModelCustom
public ArrayList<S_GroupObject> groupObjects = new ArrayList<S_GroupObject>(); public ArrayList<S_GroupObject> groupObjects = new ArrayList<S_GroupObject>();
private S_GroupObject currentGroupObject; private S_GroupObject currentGroupObject;
private String fileName; private String fileName;
private boolean smoothing = true;
public HFRWavefrontObject(ResourceLocation resource) throws ModelFormatException public HFRWavefrontObject(ResourceLocation resource) throws ModelFormatException {
{
this.fileName = resource.toString(); this.fileName = resource.toString();
try try {
{
IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource); IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
loadObjModel(res.getInputStream()); loadObjModel(res.getInputStream());
} } catch(IOException e) {
catch (IOException e)
{
throw new ModelFormatException("IO Exception reading model format", e); throw new ModelFormatException("IO Exception reading model format", e);
} }
} }
public HFRWavefrontObject(String filename, InputStream inputStream) throws ModelFormatException public HFRWavefrontObject(ResourceLocation resource, boolean smoothing) throws ModelFormatException {
{ this(resource);
this.smoothing = smoothing;
}
public HFRWavefrontObject(String filename, InputStream inputStream) throws ModelFormatException {
this.fileName = filename; this.fileName = filename;
loadObjModel(inputStream); loadObjModel(inputStream);
} }
private void loadObjModel(InputStream inputStream) throws ModelFormatException private void loadObjModel(InputStream inputStream) throws ModelFormatException {
{
BufferedReader reader = null; BufferedReader reader = null;
String currentLine = null; String currentLine = null;
int lineCount = 0; int lineCount = 0;
try try {
{
reader = new BufferedReader(new InputStreamReader(inputStream)); reader = new BufferedReader(new InputStreamReader(inputStream));
while ((currentLine = reader.readLine()) != null) while((currentLine = reader.readLine()) != null) {
{
lineCount++; lineCount++;
currentLine = currentLine.replaceAll("\\s+", " ").trim(); currentLine = currentLine.replaceAll("\\s+", " ").trim();
if (currentLine.startsWith("#") || currentLine.length() == 0) if(currentLine.startsWith("#") || currentLine.length() == 0) {
{
continue; continue;
} } else if(currentLine.startsWith("v ")) {
else if (currentLine.startsWith("v "))
{
Vertex vertex = parseVertex(currentLine, lineCount); Vertex vertex = parseVertex(currentLine, lineCount);
if (vertex != null) if(vertex != null) {
{
vertices.add(vertex); vertices.add(vertex);
} }
} } else if(currentLine.startsWith("vn ")) {
else if (currentLine.startsWith("vn "))
{
Vertex vertex = parseVertexNormal(currentLine, lineCount); Vertex vertex = parseVertexNormal(currentLine, lineCount);
if (vertex != null) if(vertex != null) {
{
vertexNormals.add(vertex); vertexNormals.add(vertex);
} }
} } else if(currentLine.startsWith("vt ")) {
else if (currentLine.startsWith("vt "))
{
TextureCoordinate textureCoordinate = parseTextureCoordinate(currentLine, lineCount); TextureCoordinate textureCoordinate = parseTextureCoordinate(currentLine, lineCount);
if (textureCoordinate != null) if(textureCoordinate != null) {
{
textureCoordinates.add(textureCoordinate); textureCoordinates.add(textureCoordinate);
} }
} } else if(currentLine.startsWith("f ")) {
else if (currentLine.startsWith("f "))
{
if (currentGroupObject == null) if(currentGroupObject == null) {
{
currentGroupObject = new S_GroupObject("Default"); currentGroupObject = new S_GroupObject("Default");
} }
S_Face face = parseFace(currentLine, lineCount); S_Face face = parseFace(currentLine, lineCount);
if (face != null) if(face != null) {
{
currentGroupObject.faces.add(face); currentGroupObject.faces.add(face);
} }
} } else if(currentLine.startsWith("g ") | currentLine.startsWith("o ")) {
else if (currentLine.startsWith("g ") | currentLine.startsWith("o "))
{
S_GroupObject group = parseGroupObject(currentLine, lineCount); S_GroupObject group = parseGroupObject(currentLine, lineCount);
if (group != null) if(group != null) {
{ if(currentGroupObject != null) {
if (currentGroupObject != null)
{
groupObjects.add(currentGroupObject); groupObjects.add(currentGroupObject);
} }
} }
@ -140,28 +119,18 @@ public class HFRWavefrontObject implements IModelCustom
} }
groupObjects.add(currentGroupObject); groupObjects.add(currentGroupObject);
} } catch(IOException e) {
catch (IOException e)
{
throw new ModelFormatException("IO Exception reading model format", e); throw new ModelFormatException("IO Exception reading model format", e);
} } finally {
finally try {
{
try
{
reader.close(); reader.close();
} } catch(IOException e) {
catch (IOException e)
{
// hush // hush
} }
try try {
{
inputStream.close(); inputStream.close();
} } catch(IOException e) {
catch (IOException e)
{
// hush // hush
} }
} }
@ -169,16 +138,12 @@ public class HFRWavefrontObject implements IModelCustom
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void renderAll() public void renderAll() {
{
Tessellator tessellator = Tessellator.instance; Tessellator tessellator = Tessellator.instance;
if (currentGroupObject != null) if(currentGroupObject != null) {
{
tessellator.startDrawing(currentGroupObject.glDrawingMode); tessellator.startDrawing(currentGroupObject.glDrawingMode);
} } else {
else
{
tessellator.startDrawing(GL11.GL_TRIANGLES); tessellator.startDrawing(GL11.GL_TRIANGLES);
} }
tessellateAll(tessellator); tessellateAll(tessellator);
@ -187,24 +152,18 @@ public class HFRWavefrontObject implements IModelCustom
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void tessellateAll(Tessellator tessellator) public void tessellateAll(Tessellator tessellator) {
{ for(S_GroupObject groupObject : groupObjects) {
for (S_GroupObject groupObject : groupObjects)
{
groupObject.render(tessellator); groupObject.render(tessellator);
} }
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void renderOnly(String... groupNames) public void renderOnly(String... groupNames) {
{ for(S_GroupObject groupObject : groupObjects) {
for (S_GroupObject groupObject : groupObjects) for(String groupName : groupNames) {
{ if(groupName.equalsIgnoreCase(groupObject.name)) {
for (String groupName : groupNames)
{
if (groupName.equalsIgnoreCase(groupObject.name))
{
groupObject.render(); groupObject.render();
} }
} }
@ -213,12 +172,9 @@ public class HFRWavefrontObject implements IModelCustom
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void tessellateOnly(Tessellator tessellator, String... groupNames) { public void tessellateOnly(Tessellator tessellator, String... groupNames) {
for (S_GroupObject groupObject : groupObjects) for(S_GroupObject groupObject : groupObjects) {
{ for(String groupName : groupNames) {
for (String groupName : groupNames) if(groupName.equalsIgnoreCase(groupObject.name)) {
{
if (groupName.equalsIgnoreCase(groupObject.name))
{
groupObject.render(tessellator); groupObject.render(tessellator);
} }
} }
@ -227,12 +183,9 @@ public class HFRWavefrontObject implements IModelCustom
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void renderPart(String partName) public void renderPart(String partName) {
{ for(S_GroupObject groupObject : groupObjects) {
for (S_GroupObject groupObject : groupObjects) if(partName.equalsIgnoreCase(groupObject.name)) {
{
if (partName.equalsIgnoreCase(groupObject.name))
{
groupObject.render(); groupObject.render();
} }
} }
@ -240,10 +193,8 @@ public class HFRWavefrontObject implements IModelCustom
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void tessellatePart(Tessellator tessellator, String partName) { public void tessellatePart(Tessellator tessellator, String partName) {
for (S_GroupObject groupObject : groupObjects) for(S_GroupObject groupObject : groupObjects) {
{ if(partName.equalsIgnoreCase(groupObject.name)) {
if (partName.equalsIgnoreCase(groupObject.name))
{
groupObject.render(tessellator); groupObject.render(tessellator);
} }
} }
@ -251,179 +202,134 @@ public class HFRWavefrontObject implements IModelCustom
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void renderAllExcept(String... excludedGroupNames) public void renderAllExcept(String... excludedGroupNames) {
{ for(S_GroupObject groupObject : groupObjects) {
for (S_GroupObject groupObject : groupObjects)
{
boolean skipPart = false; boolean skipPart = false;
for (String excludedGroupName : excludedGroupNames) for(String excludedGroupName : excludedGroupNames) {
{ if(excludedGroupName.equalsIgnoreCase(groupObject.name)) {
if (excludedGroupName.equalsIgnoreCase(groupObject.name))
{
skipPart = true; skipPart = true;
} }
} }
if(!skipPart) if(!skipPart) {
{
groupObject.render(); groupObject.render();
} }
} }
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void tessellateAllExcept(Tessellator tessellator, String... excludedGroupNames) public void tessellateAllExcept(Tessellator tessellator, String... excludedGroupNames) {
{
boolean exclude; boolean exclude;
for (S_GroupObject groupObject : groupObjects) for(S_GroupObject groupObject : groupObjects) {
{
exclude = false; exclude = false;
for (String excludedGroupName : excludedGroupNames) for(String excludedGroupName : excludedGroupNames) {
{ if(excludedGroupName.equalsIgnoreCase(groupObject.name)) {
if (excludedGroupName.equalsIgnoreCase(groupObject.name))
{
exclude = true; exclude = true;
} }
} }
if(!exclude) if(!exclude) {
{
groupObject.render(tessellator); groupObject.render(tessellator);
} }
} }
} }
private Vertex parseVertex(String line, int lineCount) throws ModelFormatException private Vertex parseVertex(String line, int lineCount) throws ModelFormatException {
{
Vertex vertex = null; Vertex vertex = null;
if (isValidVertexLine(line)) if(isValidVertexLine(line)) {
{
line = line.substring(line.indexOf(" ") + 1); line = line.substring(line.indexOf(" ") + 1);
String[] tokens = line.split(" "); String[] tokens = line.split(" ");
try try {
{ if(tokens.length == 2) {
if (tokens.length == 2)
{
return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1])); return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]));
} } else if(tokens.length == 3) {
else if (tokens.length == 3)
{
return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2])); return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]));
} }
} } catch(NumberFormatException e) {
catch (NumberFormatException e)
{
throw new ModelFormatException(String.format("Number formatting error at line %d", lineCount), e); throw new ModelFormatException(String.format("Number formatting error at line %d", lineCount), e);
} }
} } else {
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format"); throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format");
} }
return vertex; return vertex;
} }
private Vertex parseVertexNormal(String line, int lineCount) throws ModelFormatException private Vertex parseVertexNormal(String line, int lineCount) throws ModelFormatException {
{
Vertex vertexNormal = null; Vertex vertexNormal = null;
if (isValidVertexNormalLine(line)) if(isValidVertexNormalLine(line)) {
{
line = line.substring(line.indexOf(" ") + 1); line = line.substring(line.indexOf(" ") + 1);
String[] tokens = line.split(" "); String[] tokens = line.split(" ");
try try {
{
if(tokens.length == 3) if(tokens.length == 3)
return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2])); return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]));
} } catch(NumberFormatException e) {
catch (NumberFormatException e)
{
throw new ModelFormatException(String.format("Number formatting error at line %d", lineCount), e); throw new ModelFormatException(String.format("Number formatting error at line %d", lineCount), e);
} }
} } else {
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format"); throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format");
} }
return vertexNormal; return vertexNormal;
} }
private TextureCoordinate parseTextureCoordinate(String line, int lineCount) throws ModelFormatException private TextureCoordinate parseTextureCoordinate(String line, int lineCount) throws ModelFormatException {
{
TextureCoordinate textureCoordinate = null; TextureCoordinate textureCoordinate = null;
if (isValidTextureCoordinateLine(line)) if(isValidTextureCoordinateLine(line)) {
{
line = line.substring(line.indexOf(" ") + 1); line = line.substring(line.indexOf(" ") + 1);
String[] tokens = line.split(" "); String[] tokens = line.split(" ");
try try {
{
if(tokens.length == 2) if(tokens.length == 2)
return new TextureCoordinate(Float.parseFloat(tokens[0]), 1 - Float.parseFloat(tokens[1])); return new TextureCoordinate(Float.parseFloat(tokens[0]), 1 - Float.parseFloat(tokens[1]));
else if(tokens.length == 3) else if(tokens.length == 3)
return new TextureCoordinate(Float.parseFloat(tokens[0]), 1 - Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2])); return new TextureCoordinate(Float.parseFloat(tokens[0]), 1 - Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]));
} } catch(NumberFormatException e) {
catch (NumberFormatException e)
{
throw new ModelFormatException(String.format("Number formatting error at line %d", lineCount), e); throw new ModelFormatException(String.format("Number formatting error at line %d", lineCount), e);
} }
} } else {
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format"); throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format");
} }
return textureCoordinate; return textureCoordinate;
} }
private S_Face parseFace(String line, int lineCount) throws ModelFormatException private S_Face parseFace(String line, int lineCount) throws ModelFormatException {
{
S_Face face = null; S_Face face = null;
if (isValidFaceLine(line)) if(isValidFaceLine(line)) {
{ face = new S_Face(this.smoothing);
face = new S_Face();
String trimmedLine = line.substring(line.indexOf(" ") + 1); String trimmedLine = line.substring(line.indexOf(" ") + 1);
String[] tokens = trimmedLine.split(" "); String[] tokens = trimmedLine.split(" ");
String[] subTokens = null; String[] subTokens = null;
if (tokens.length == 3) if(tokens.length == 3) {
{ if(currentGroupObject.glDrawingMode == -1) {
if (currentGroupObject.glDrawingMode == -1)
{
currentGroupObject.glDrawingMode = GL11.GL_TRIANGLES; currentGroupObject.glDrawingMode = GL11.GL_TRIANGLES;
} else if(currentGroupObject.glDrawingMode != GL11.GL_TRIANGLES) {
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName
+ "' - Invalid number of points for face (expected 4, found " + tokens.length + ")");
} }
else if (currentGroupObject.glDrawingMode != GL11.GL_TRIANGLES) } else if(tokens.length == 4) {
{ if(currentGroupObject.glDrawingMode == -1) {
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Invalid number of points for face (expected 4, found " + tokens.length + ")");
}
}
else if (tokens.length == 4)
{
if (currentGroupObject.glDrawingMode == -1)
{
currentGroupObject.glDrawingMode = GL11.GL_QUADS; currentGroupObject.glDrawingMode = GL11.GL_QUADS;
} } else if(currentGroupObject.glDrawingMode != GL11.GL_QUADS) {
else if (currentGroupObject.glDrawingMode != GL11.GL_QUADS) throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName
{ + "' - Invalid number of points for face (expected 3, found " + tokens.length + ")");
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Invalid number of points for face (expected 3, found " + tokens.length + ")");
} }
} }
// f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 ... // f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 ...
if (isValidFace_V_VT_VN_Line(line)) if(isValidFace_V_VT_VN_Line(line)) {
{
face.vertices = new Vertex[tokens.length]; face.vertices = new Vertex[tokens.length];
face.textureCoordinates = new TextureCoordinate[tokens.length]; face.textureCoordinates = new TextureCoordinate[tokens.length];
face.vertexNormals = new Vertex[tokens.length]; face.vertexNormals = new Vertex[tokens.length];
for (int i = 0; i < tokens.length; ++i) for(int i = 0; i < tokens.length; ++i) {
{
subTokens = tokens[i].split("/"); subTokens = tokens[i].split("/");
face.vertices[i] = vertices.get(Integer.parseInt(subTokens[0]) - 1); face.vertices[i] = vertices.get(Integer.parseInt(subTokens[0]) - 1);
@ -434,13 +340,11 @@ public class HFRWavefrontObject implements IModelCustom
face.faceNormal = face.calculateFaceNormal(); face.faceNormal = face.calculateFaceNormal();
} }
// f v1/vt1 v2/vt2 v3/vt3 ... // f v1/vt1 v2/vt2 v3/vt3 ...
else if (isValidFace_V_VT_Line(line)) else if(isValidFace_V_VT_Line(line)) {
{
face.vertices = new Vertex[tokens.length]; face.vertices = new Vertex[tokens.length];
face.textureCoordinates = new TextureCoordinate[tokens.length]; face.textureCoordinates = new TextureCoordinate[tokens.length];
for (int i = 0; i < tokens.length; ++i) for(int i = 0; i < tokens.length; ++i) {
{
subTokens = tokens[i].split("/"); subTokens = tokens[i].split("/");
face.vertices[i] = vertices.get(Integer.parseInt(subTokens[0]) - 1); face.vertices[i] = vertices.get(Integer.parseInt(subTokens[0]) - 1);
@ -450,13 +354,11 @@ public class HFRWavefrontObject implements IModelCustom
face.faceNormal = face.calculateFaceNormal(); face.faceNormal = face.calculateFaceNormal();
} }
// f v1//vn1 v2//vn2 v3//vn3 ... // f v1//vn1 v2//vn2 v3//vn3 ...
else if (isValidFace_V_VN_Line(line)) else if(isValidFace_V_VN_Line(line)) {
{
face.vertices = new Vertex[tokens.length]; face.vertices = new Vertex[tokens.length];
face.vertexNormals = new Vertex[tokens.length]; face.vertexNormals = new Vertex[tokens.length];
for (int i = 0; i < tokens.length; ++i) for(int i = 0; i < tokens.length; ++i) {
{
subTokens = tokens[i].split("//"); subTokens = tokens[i].split("//");
face.vertices[i] = vertices.get(Integer.parseInt(subTokens[0]) - 1); face.vertices[i] = vertices.get(Integer.parseInt(subTokens[0]) - 1);
@ -466,55 +368,42 @@ public class HFRWavefrontObject implements IModelCustom
face.faceNormal = face.calculateFaceNormal(); face.faceNormal = face.calculateFaceNormal();
} }
// f v1 v2 v3 ... // f v1 v2 v3 ...
else if (isValidFace_V_Line(line)) else if(isValidFace_V_Line(line)) {
{
face.vertices = new Vertex[tokens.length]; face.vertices = new Vertex[tokens.length];
for (int i = 0; i < tokens.length; ++i) for(int i = 0; i < tokens.length; ++i) {
{
face.vertices[i] = vertices.get(Integer.parseInt(tokens[i]) - 1); face.vertices[i] = vertices.get(Integer.parseInt(tokens[i]) - 1);
} }
face.faceNormal = face.calculateFaceNormal(); face.faceNormal = face.calculateFaceNormal();
} } else {
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format"); throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format");
} }
} } else {
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format"); throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format");
} }
return face; return face;
} }
private S_GroupObject parseGroupObject(String line, int lineCount) throws ModelFormatException private S_GroupObject parseGroupObject(String line, int lineCount) throws ModelFormatException {
{
S_GroupObject group = null; S_GroupObject group = null;
if (isValidGroupObjectLine(line)) if(isValidGroupObjectLine(line)) {
{
String trimmedLine = line.substring(line.indexOf(" ") + 1); String trimmedLine = line.substring(line.indexOf(" ") + 1);
if (trimmedLine.length() > 0) if(trimmedLine.length() > 0) {
{
group = new S_GroupObject(trimmedLine); group = new S_GroupObject(trimmedLine);
} }
} } else {
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format"); throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format");
} }
return group; return group;
} }
private static boolean isValidVertexLine(String line) private static boolean isValidVertexLine(String line) {
{ if(vertexMatcher != null) {
if (vertexMatcher != null)
{
vertexMatcher.reset(); vertexMatcher.reset();
} }
@ -522,10 +411,8 @@ public class HFRWavefrontObject implements IModelCustom
return vertexMatcher.matches(); return vertexMatcher.matches();
} }
private static boolean isValidVertexNormalLine(String line) private static boolean isValidVertexNormalLine(String line) {
{ if(vertexNormalMatcher != null) {
if (vertexNormalMatcher != null)
{
vertexNormalMatcher.reset(); vertexNormalMatcher.reset();
} }
@ -533,10 +420,8 @@ public class HFRWavefrontObject implements IModelCustom
return vertexNormalMatcher.matches(); return vertexNormalMatcher.matches();
} }
private static boolean isValidTextureCoordinateLine(String line) private static boolean isValidTextureCoordinateLine(String line) {
{ if(textureCoordinateMatcher != null) {
if (textureCoordinateMatcher != null)
{
textureCoordinateMatcher.reset(); textureCoordinateMatcher.reset();
} }
@ -544,10 +429,8 @@ public class HFRWavefrontObject implements IModelCustom
return textureCoordinateMatcher.matches(); return textureCoordinateMatcher.matches();
} }
private static boolean isValidFace_V_VT_VN_Line(String line) private static boolean isValidFace_V_VT_VN_Line(String line) {
{ if(face_V_VT_VN_Matcher != null) {
if (face_V_VT_VN_Matcher != null)
{
face_V_VT_VN_Matcher.reset(); face_V_VT_VN_Matcher.reset();
} }
@ -555,10 +438,8 @@ public class HFRWavefrontObject implements IModelCustom
return face_V_VT_VN_Matcher.matches(); return face_V_VT_VN_Matcher.matches();
} }
private static boolean isValidFace_V_VT_Line(String line) private static boolean isValidFace_V_VT_Line(String line) {
{ if(face_V_VT_Matcher != null) {
if (face_V_VT_Matcher != null)
{
face_V_VT_Matcher.reset(); face_V_VT_Matcher.reset();
} }
@ -566,10 +447,8 @@ public class HFRWavefrontObject implements IModelCustom
return face_V_VT_Matcher.matches(); return face_V_VT_Matcher.matches();
} }
private static boolean isValidFace_V_VN_Line(String line) private static boolean isValidFace_V_VN_Line(String line) {
{ if(face_V_VN_Matcher != null) {
if (face_V_VN_Matcher != null)
{
face_V_VN_Matcher.reset(); face_V_VN_Matcher.reset();
} }
@ -577,10 +456,8 @@ public class HFRWavefrontObject implements IModelCustom
return face_V_VN_Matcher.matches(); return face_V_VN_Matcher.matches();
} }
private static boolean isValidFace_V_Line(String line) private static boolean isValidFace_V_Line(String line) {
{ if(face_V_Matcher != null) {
if (face_V_Matcher != null)
{
face_V_Matcher.reset(); face_V_Matcher.reset();
} }
@ -588,15 +465,12 @@ public class HFRWavefrontObject implements IModelCustom
return face_V_Matcher.matches(); return face_V_Matcher.matches();
} }
private static boolean isValidFaceLine(String line) 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); return isValidFace_V_VT_VN_Line(line) || isValidFace_V_VT_Line(line) || isValidFace_V_VN_Line(line) || isValidFace_V_Line(line);
} }
private static boolean isValidGroupObjectLine(String line) private static boolean isValidGroupObjectLine(String line) {
{ if(groupObjectMatcher != null) {
if (groupObjectMatcher != null)
{
groupObjectMatcher.reset(); groupObjectMatcher.reset();
} }
@ -605,8 +479,11 @@ public class HFRWavefrontObject implements IModelCustom
} }
@Override @Override
public String getType() public String getType() {
{
return "obj"; return "obj";
} }
public WavefrontObjDisplayList asDisplayList() {
return new WavefrontObjDisplayList(this);
}
} }

View File

@ -15,12 +15,11 @@ public class S_Face {
public Vertex[] vertexNormals; public Vertex[] vertexNormals;
public Vertex faceNormal; public Vertex faceNormal;
public TextureCoordinate[] textureCoordinates; public TextureCoordinate[] textureCoordinates;
private boolean smoothing;
/*public S_Face copy() { public S_Face(boolean smoothing) {
S_Face f = new S_Face(); this.smoothing = smoothing;
}
return f;
}*/
public void addFaceForRender(Tessellator tessellator) { public void addFaceForRender(Tessellator tessellator) {
addFaceForRender(tessellator, 0.0F); addFaceForRender(tessellator, 0.0F);
@ -32,7 +31,9 @@ public class S_Face {
this.faceNormal = calculateFaceNormal(); this.faceNormal = calculateFaceNormal();
} }
if(!this.smoothing) {
tessellator.setNormal(this.faceNormal.x, this.faceNormal.y, this.faceNormal.z); tessellator.setNormal(this.faceNormal.x, this.faceNormal.y, this.faceNormal.z);
}
float averageU = 0.0F; float averageU = 0.0F;
float averageV = 0.0F; float averageV = 0.0F;
@ -61,7 +62,7 @@ public class S_Face {
if(this.textureCoordinates[i].v > averageV) { if(this.textureCoordinates[i].v > averageV) {
offsetV = -offsetV; offsetV = -offsetV;
} }
if ((this.vertexNormals != null) && (i < this.vertexNormals.length)) { if(this.smoothing && (this.vertexNormals != null) && (i < this.vertexNormals.length)) {
tessellator.setNormal(this.vertexNormals[i].x, this.vertexNormals[i].y, this.vertexNormals[i].z); tessellator.setNormal(this.vertexNormals[i].x, this.vertexNormals[i].y, this.vertexNormals[i].z);
} }

View File

@ -1,79 +0,0 @@
package com.hbm.render.loader;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.client.model.obj.Vertex;
@SideOnly(Side.CLIENT)
public abstract class S_ModelCustom implements IModelCustom {
public float min = 100000.0F;
public float minX = 100000.0F;
public float minY = 100000.0F;
public float minZ = 100000.0F;
public float max = -100000.0F;
public float maxX = -100000.0F;
public float maxY = -100000.0F;
public float maxZ = -100000.0F;
public float size = 0.0F;
public float sizeX = 0.0F;
public float sizeY = 0.0F;
public float sizeZ = 0.0F;
public void checkMinMax(Vertex v) {
if (v.x < this.minX) {
this.minX = v.x;
}
if (v.y < this.minY) {
this.minY = v.y;
}
if (v.z < this.minZ) {
this.minZ = v.z;
}
if (v.x > this.maxX) {
this.maxX = v.x;
}
if (v.y > this.maxY) {
this.maxY = v.y;
}
if (v.z > this.maxZ) {
this.maxZ = v.z;
}
}
public void checkMinMaxFinal() {
if (this.minX < this.min) {
this.min = this.minX;
}
if (this.minY < this.min) {
this.min = this.minY;
}
if (this.minZ < this.min) {
this.min = this.minZ;
}
if (this.maxX > this.max) {
this.max = this.maxX;
}
if (this.maxY > this.max) {
this.max = this.maxY;
}
if (this.maxZ > this.max) {
this.max = this.maxZ;
}
this.sizeX = (this.maxX - this.minX);
this.sizeY = (this.maxY - this.minY);
this.sizeZ = (this.maxZ - this.minZ);
this.size = (this.max - this.min);
}
public abstract boolean containsPart(String paramString);
public abstract void renderAll(int paramInt1, int paramInt2);
public abstract void renderAllLine(int paramInt1, int paramInt2);
public abstract int getVertexNum();
public abstract int getFaceNum();
}

View File

@ -1,633 +0,0 @@
package com.hbm.render.loader;
import java.io.BufferedReader;
import java.io.IOException;
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 cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.resources.IResource;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelFormatException;
import net.minecraftforge.client.model.obj.TextureCoordinate;
import net.minecraftforge.client.model.obj.Vertex;
@SideOnly(Side.CLIENT)
public class S_WavefrontObject extends S_ModelCustom
{
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;
private static Matcher vertexNormalMatcher;
private static Matcher textureCoordinateMatcher;
private static Matcher face_V_VT_VN_Matcher;
private static Matcher face_V_VT_Matcher;
private static Matcher face_V_VN_Matcher;
private static Matcher face_V_Matcher;
private static Matcher groupObjectMatcher;
public ArrayList<Vertex> vertices = new ArrayList();
public ArrayList<Vertex> vertexNormals = new ArrayList();
public ArrayList<TextureCoordinate> textureCoordinates = new ArrayList();
public ArrayList<S_GroupObject> groupObjects = new ArrayList();
private S_GroupObject currentS_GroupObject;
private String fileName;
public S_WavefrontObject(ResourceLocation resource)
throws ModelFormatException
{
this.fileName = resource.toString();
try
{
IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
loadObjModel(res.getInputStream());
}
catch (IOException e)
{
throw new ModelFormatException("IO Exception reading model format", e);
}
}
public S_WavefrontObject(String fileName, URL resource)
throws ModelFormatException
{
this.fileName = fileName;
try
{
loadObjModel(resource.openStream());
}
catch (IOException e)
{
throw new ModelFormatException("IO Exception reading model format", e);
}
}
public S_WavefrontObject(String filename, InputStream inputStream)
throws ModelFormatException
{
this.fileName = filename;
loadObjModel(inputStream);
}
public boolean containsPart(String partName)
{
for (S_GroupObject groupObject : this.groupObjects) {
if (partName.equalsIgnoreCase(groupObject.name)) {
return true;
}
}
return false;
}
private void loadObjModel(InputStream inputStream)
throws ModelFormatException
{
BufferedReader reader = null;
String currentLine = null;
int lineCount = 0;
try
{
reader = new BufferedReader(new InputStreamReader(inputStream));
while ((currentLine = reader.readLine()) != null)
{
lineCount++;
currentLine = currentLine.replaceAll("\\s+", " ").trim();
if ((!currentLine.startsWith("#")) && (currentLine.length() != 0)) {
if (currentLine.startsWith("v "))
{
Vertex vertex = parseVertex(currentLine, lineCount);
if (vertex != null)
{
checkMinMax(vertex);
this.vertices.add(vertex);
}
}
else if (currentLine.startsWith("vn "))
{
Vertex vertex = parseVertexNormal(currentLine, lineCount);
if (vertex != null) {
this.vertexNormals.add(vertex);
}
}
else if (currentLine.startsWith("vt "))
{
TextureCoordinate textureCoordinate = parseTextureCoordinate(currentLine, lineCount);
if (textureCoordinate != null) {
this.textureCoordinates.add(textureCoordinate);
}
}
else if (currentLine.startsWith("f "))
{
if (this.currentS_GroupObject == null) {
this.currentS_GroupObject = new S_GroupObject("Default");
}
S_Face face = parseFace(currentLine, lineCount);
if (face != null) {
this.currentS_GroupObject.faces.add(face);
}
}
else if (((currentLine.startsWith("g ") | currentLine.startsWith("o "))) &&
(currentLine.charAt(2) == '$'))
{
S_GroupObject group = parseS_GroupObject(currentLine, lineCount);
if (group != null) {
if (this.currentS_GroupObject != null) {
this.groupObjects.add(this.currentS_GroupObject);
}
}
this.currentS_GroupObject = group;
}
}
}
this.groupObjects.add(this.currentS_GroupObject); return;
}
catch (IOException e)
{
throw new ModelFormatException("IO Exception reading model format", e);
}
finally
{
checkMinMaxFinal();
try
{
reader.close();
}
catch (IOException e) {}
try
{
inputStream.close();
}
catch (IOException e) {}
}
}
public void renderAll()
{
Tessellator tessellator = Tessellator.instance;
if (this.currentS_GroupObject != null) {
tessellator.startDrawing(this.currentS_GroupObject.glDrawingMode);
} else {
tessellator.startDrawing(4);
}
tessellateAll(tessellator);
tessellator.draw();
}
public void tessellateAll(Tessellator tessellator)
{
for (S_GroupObject groupObject : this.groupObjects) {
groupObject.render(tessellator);
}
}
public void renderOnly(String... groupNames)
{
for (S_GroupObject groupObject : this.groupObjects) {
for (String groupName : groupNames) {
if (groupName.equalsIgnoreCase(groupObject.name)) {
groupObject.render();
}
}
}
}
public void tessellateOnly(Tessellator tessellator, String... groupNames)
{
for (S_GroupObject groupObject : this.groupObjects) {
for (String groupName : groupNames) {
if (groupName.equalsIgnoreCase(groupObject.name)) {
groupObject.render(tessellator);
}
}
}
}
public void renderPart(String partName)
{
for (S_GroupObject groupObject : this.groupObjects) {
if (partName.equalsIgnoreCase(groupObject.name)) {
groupObject.render();
}
}
}
public void tessellatePart(Tessellator tessellator, String partName)
{
for (S_GroupObject groupObject : this.groupObjects) {
if (partName.equalsIgnoreCase(groupObject.name)) {
groupObject.render(tessellator);
}
}
}
public void renderAllExcept(String... excludedGroupNames)
{
for (S_GroupObject groupObject : this.groupObjects)
{
boolean skipPart = false;
for (String excludedGroupName : excludedGroupNames) {
if (excludedGroupName.equalsIgnoreCase(groupObject.name)) {
skipPart = true;
}
}
if (!skipPart) {
groupObject.render();
}
}
}
public void tessellateAllExcept(Tessellator tessellator, String... excludedGroupNames)
{
for (S_GroupObject groupObject : this.groupObjects)
{
boolean exclude = false;
for (String excludedGroupName : excludedGroupNames) {
if (excludedGroupName.equalsIgnoreCase(groupObject.name)) {
exclude = true;
}
}
if (!exclude) {
groupObject.render(tessellator);
}
}
}
private Vertex parseVertex(String line, int lineCount)
throws ModelFormatException
{
Vertex vertex = null;
if (isValidVertexLine(line))
{
line = line.substring(line.indexOf(" ") + 1);
String[] tokens = line.split(" ");
try
{
if (tokens.length == 2) {
return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]));
}
if (tokens.length == 3) {
return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]));
}
}
catch (NumberFormatException e)
{
throw new ModelFormatException(String.format("Number formatting error at line %d", new Object[] { Integer.valueOf(lineCount) }), e);
}
}
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + this.fileName + "' - Incorrect format");
}
return vertex;
}
private Vertex parseVertexNormal(String line, int lineCount)
throws ModelFormatException
{
Vertex vertexNormal = null;
if (isValidVertexNormalLine(line))
{
line = line.substring(line.indexOf(" ") + 1);
String[] tokens = line.split(" ");
try
{
if (tokens.length == 3) {
return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]));
}
}
catch (NumberFormatException e)
{
throw new ModelFormatException(String.format("Number formatting error at line %d", new Object[] { Integer.valueOf(lineCount) }), e);
}
}
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + this.fileName + "' - Incorrect format");
}
return vertexNormal;
}
private TextureCoordinate parseTextureCoordinate(String line, int lineCount)
throws ModelFormatException
{
TextureCoordinate textureCoordinate = null;
if (isValidTextureCoordinateLine(line))
{
line = line.substring(line.indexOf(" ") + 1);
String[] tokens = line.split(" ");
try
{
if (tokens.length == 2) {
return new TextureCoordinate(Float.parseFloat(tokens[0]), 1.0F - Float.parseFloat(tokens[1]));
}
if (tokens.length == 3) {
return new TextureCoordinate(Float.parseFloat(tokens[0]), 1.0F - Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]));
}
}
catch (NumberFormatException e)
{
throw new ModelFormatException(String.format("Number formatting error at line %d", new Object[] { Integer.valueOf(lineCount) }), e);
}
}
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + this.fileName + "' - Incorrect format");
}
return textureCoordinate;
}
private S_Face parseFace(String line, int lineCount)
throws ModelFormatException
{
S_Face face = null;
if (isValidFaceLine(line))
{
face = new S_Face();
String trimmedLine = line.substring(line.indexOf(" ") + 1);
String[] tokens = trimmedLine.split(" ");
String[] subTokens = null;
if (tokens.length == 3)
{
if (this.currentS_GroupObject.glDrawingMode == -1) {
this.currentS_GroupObject.glDrawingMode = 4;
} else if (this.currentS_GroupObject.glDrawingMode != 4) {
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + this.fileName + "' - Invalid number of points for face (expected 4, found " + tokens.length + ")");
}
}
else if (tokens.length == 4) {
if (this.currentS_GroupObject.glDrawingMode == -1) {
this.currentS_GroupObject.glDrawingMode = 7;
} else if (this.currentS_GroupObject.glDrawingMode != 7) {
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + this.fileName + "' - Invalid number of points for face (expected 3, found " + tokens.length + ")");
}
}
if (isValidFace_V_VT_VN_Line(line))
{
face.vertices = new Vertex[tokens.length];
face.textureCoordinates = new TextureCoordinate[tokens.length];
face.vertexNormals = new Vertex[tokens.length];
for (int i = 0; i < tokens.length; i++)
{
subTokens = tokens[i].split("/");
face.vertices[i] = ((Vertex)this.vertices.get(Integer.parseInt(subTokens[0]) - 1));
face.textureCoordinates[i] = ((TextureCoordinate)this.textureCoordinates.get(Integer.parseInt(subTokens[1]) - 1));
face.vertexNormals[i] = ((Vertex)this.vertexNormals.get(Integer.parseInt(subTokens[2]) - 1));
}
face.faceNormal = face.calculateFaceNormal();
}
else if (isValidFace_V_VT_Line(line))
{
face.vertices = new Vertex[tokens.length];
face.textureCoordinates = new TextureCoordinate[tokens.length];
for (int i = 0; i < tokens.length; i++)
{
subTokens = tokens[i].split("/");
face.vertices[i] = ((Vertex)this.vertices.get(Integer.parseInt(subTokens[0]) - 1));
face.textureCoordinates[i] = ((TextureCoordinate)this.textureCoordinates.get(Integer.parseInt(subTokens[1]) - 1));
}
face.faceNormal = face.calculateFaceNormal();
}
else if (isValidFace_V_VN_Line(line))
{
face.vertices = new Vertex[tokens.length];
face.vertexNormals = new Vertex[tokens.length];
for (int i = 0; i < tokens.length; i++)
{
subTokens = tokens[i].split("//");
face.vertices[i] = ((Vertex)this.vertices.get(Integer.parseInt(subTokens[0]) - 1));
face.vertexNormals[i] = ((Vertex)this.vertexNormals.get(Integer.parseInt(subTokens[1]) - 1));
}
face.faceNormal = face.calculateFaceNormal();
}
else if (isValidFace_V_Line(line))
{
face.vertices = new Vertex[tokens.length];
for (int i = 0; i < tokens.length; i++) {
face.vertices[i] = ((Vertex)this.vertices.get(Integer.parseInt(tokens[i]) - 1));
}
face.faceNormal = face.calculateFaceNormal();
}
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + this.fileName + "' - Incorrect format");
}
}
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + this.fileName + "' - Incorrect format");
}
return face;
}
private S_GroupObject parseS_GroupObject(String line, int lineCount)
throws ModelFormatException
{
S_GroupObject group = null;
if (isValidS_GroupObjectLine(line))
{
String trimmedLine = line.substring(line.indexOf(" ") + 1);
if (trimmedLine.length() > 0) {
group = new S_GroupObject(trimmedLine);
}
}
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + this.fileName + "' - Incorrect format");
}
return group;
}
private static boolean isValidVertexLine(String line)
{
if (vertexMatcher != null) {
vertexMatcher.reset();
}
vertexMatcher = vertexPattern.matcher(line);
return vertexMatcher.matches();
}
private static boolean isValidVertexNormalLine(String line)
{
if (vertexNormalMatcher != null) {
vertexNormalMatcher.reset();
}
vertexNormalMatcher = vertexNormalPattern.matcher(line);
return vertexNormalMatcher.matches();
}
private static boolean isValidTextureCoordinateLine(String line)
{
if (textureCoordinateMatcher != null) {
textureCoordinateMatcher.reset();
}
textureCoordinateMatcher = textureCoordinatePattern.matcher(line);
return textureCoordinateMatcher.matches();
}
private static boolean isValidFace_V_VT_VN_Line(String line)
{
if (face_V_VT_VN_Matcher != null) {
face_V_VT_VN_Matcher.reset();
}
face_V_VT_VN_Matcher = face_V_VT_VN_Pattern.matcher(line);
return face_V_VT_VN_Matcher.matches();
}
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();
}
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();
}
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();
}
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));
}
private static boolean isValidS_GroupObjectLine(String line)
{
if (groupObjectMatcher != null) {
groupObjectMatcher.reset();
}
groupObjectMatcher = groupObjectPattern.matcher(line);
return groupObjectMatcher.matches();
}
public String getType()
{
return "obj";
}
public void renderAllLine(int startLine, int maxLine)
{
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawing(1);
renderAllLine(tessellator, startLine, maxLine);
tessellator.draw();
}
public void renderAllLine(Tessellator tessellator, int startLine, int maxLine)
{
int lineCnt = 0;
for (S_GroupObject groupObject : this.groupObjects) {
if (groupObject.faces.size() > 0) {
for (S_Face face : groupObject.faces) {
for (int i = 0; i < face.vertices.length / 3; i++)
{
Vertex v1 = face.vertices[(i * 3 + 0)];
Vertex v2 = face.vertices[(i * 3 + 1)];
Vertex v3 = face.vertices[(i * 3 + 2)];
lineCnt++;
if (lineCnt > maxLine) {
return;
}
tessellator.addVertex(v1.x, v1.y, v1.z);
tessellator.addVertex(v2.x, v2.y, v2.z);
lineCnt++;
if (lineCnt > maxLine) {
return;
}
tessellator.addVertex(v2.x, v2.y, v2.z);
tessellator.addVertex(v3.x, v3.y, v3.z);
lineCnt++;
if (lineCnt > maxLine) {
return;
}
tessellator.addVertex(v3.x, v3.y, v3.z);
tessellator.addVertex(v1.x, v1.y, v1.z);
}
}
}
}
}
public int getVertexNum()
{
return this.vertices.size();
}
public int getFaceNum()
{
return getVertexNum() / 3;
}
public void renderAll(int startFace, int maxFace)
{
if (startFace < 0) {
startFace = 0;
}
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawing(4);
renderAll(tessellator, startFace, maxFace);
tessellator.draw();
}
public void renderAll(Tessellator tessellator, int startFace, int maxLine)
{
int faceCnt = 0;
for (S_GroupObject groupObject : this.groupObjects) {
if (groupObject.faces.size() > 0) {
for (S_Face face : groupObject.faces)
{
faceCnt++;
if (faceCnt >= startFace)
{
if (faceCnt > maxLine) {
return;
}
face.addFaceForRender(tessellator);
}
}
}
}
}
}

View File

@ -1,4 +1,4 @@
package com.hbm.render; package com.hbm.render.loader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -6,9 +6,6 @@ import java.util.List;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import com.hbm.render.loader.HFRWavefrontObject;
import com.hbm.render.loader.S_GroupObject;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraftforge.client.model.IModelCustom; import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.client.model.obj.GroupObject; import net.minecraftforge.client.model.obj.GroupObject;

View File

@ -11,7 +11,7 @@ import com.hbm.animloader.AnimationWrapper;
import com.hbm.animloader.AnimationWrapper.EndResult; import com.hbm.animloader.AnimationWrapper.EndResult;
import com.hbm.animloader.AnimationWrapper.EndType; import com.hbm.animloader.AnimationWrapper.EndType;
import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.BlockDummyable;
import com.hbm.render.WavefrontObjDisplayList; import com.hbm.render.loader.WavefrontObjDisplayList;
import com.hbm.tileentity.DoorDecl; import com.hbm.tileentity.DoorDecl;
import com.hbm.tileentity.TileEntityDoorGeneric; import com.hbm.tileentity.TileEntityDoorGeneric;

View File

@ -5,7 +5,7 @@ import org.lwjgl.opengl.GL11;
import com.hbm.animloader.AnimatedModel; import com.hbm.animloader.AnimatedModel;
import com.hbm.animloader.Animation; import com.hbm.animloader.Animation;
import com.hbm.main.ResourceManager; import com.hbm.main.ResourceManager;
import com.hbm.render.WavefrontObjDisplayList; import com.hbm.render.loader.WavefrontObjDisplayList;
import com.hbm.util.BobMathUtil; import com.hbm.util.BobMathUtil;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;