diff --git a/src/main/java/com/hbm/main/ResourceManager.java b/src/main/java/com/hbm/main/ResourceManager.java index b97cbd31d..027f33180 100644 --- a/src/main/java/com/hbm/main/ResourceManager.java +++ b/src/main/java/com/hbm/main/ResourceManager.java @@ -9,6 +9,7 @@ import com.hbm.lib.RefStrings; import com.hbm.render.anim.AnimationLoader; import com.hbm.render.anim.BusAnimation; import com.hbm.render.loader.HFRWavefrontObject; +import com.hbm.render.loader.IModelCustomNamed; import com.hbm.render.loader.WavefrontObjDisplayList; import net.minecraft.util.ResourceLocation; @@ -327,7 +328,7 @@ public class ResourceManager { //Doors public static AnimatedModel transition_seal = ColladaLoader.load(new ResourceLocation(RefStrings.MODID, "models/doors/seal.dae"), true); public static Animation transition_seal_anim = ColladaLoader.loadAnim(24040, new ResourceLocation(RefStrings.MODID, "models/doors/seal.dae")); - public static final IModelCustom fire_door = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/doors/fire_door.obj")).asVBO(); + public static final IModelCustomNamed fire_door = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/doors/fire_door.obj")).asVBO(); //Secure Access Door public static final ResourceLocation secure_access_door_tex = new ResourceLocation(RefStrings.MODID, "textures/models/doors/secure_access_door.png"); diff --git a/src/main/java/com/hbm/render/loader/HFRWavefrontObject.java b/src/main/java/com/hbm/render/loader/HFRWavefrontObject.java index ddaae7ff7..a3e443e99 100644 --- a/src/main/java/com/hbm/render/loader/HFRWavefrontObject.java +++ b/src/main/java/com/hbm/render/loader/HFRWavefrontObject.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -16,12 +17,11 @@ 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.IModelCustom; import net.minecraftforge.client.model.ModelFormatException; import net.minecraftforge.client.model.obj.TextureCoordinate; import net.minecraftforge.client.model.obj.Vertex; -public class HFRWavefrontObject implements IModelCustom { +public class HFRWavefrontObject implements IModelCustomNamed { 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} *$)"); @@ -483,6 +483,15 @@ public class HFRWavefrontObject implements IModelCustom { return "obj"; } + @Override + public List getPartNames() { + List names = new ArrayList(); + for(S_GroupObject data : groupObjects) { + names.add(data.name); + } + return names; + } + public WavefrontObjVBO asVBO() { return new WavefrontObjVBO(this); } diff --git a/src/main/java/com/hbm/render/loader/IModelCustomNamed.java b/src/main/java/com/hbm/render/loader/IModelCustomNamed.java new file mode 100644 index 000000000..a12e1bdb4 --- /dev/null +++ b/src/main/java/com/hbm/render/loader/IModelCustomNamed.java @@ -0,0 +1,13 @@ +package com.hbm.render.loader; + +import java.util.List; + +import net.minecraftforge.client.model.IModelCustom; + +public interface IModelCustomNamed extends IModelCustom { + + // A little messy, but this is the cleanest refactor, and can be useful in the future + + public List getPartNames(); + +} diff --git a/src/main/java/com/hbm/render/loader/WavefrontObjDisplayList.java b/src/main/java/com/hbm/render/loader/WavefrontObjDisplayList.java index 99eef4360..b797be151 100644 --- a/src/main/java/com/hbm/render/loader/WavefrontObjDisplayList.java +++ b/src/main/java/com/hbm/render/loader/WavefrontObjDisplayList.java @@ -7,11 +7,10 @@ import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; import net.minecraft.client.renderer.Tessellator; -import net.minecraftforge.client.model.IModelCustom; import net.minecraftforge.client.model.obj.GroupObject; import net.minecraftforge.client.model.obj.WavefrontObject; -public class WavefrontObjDisplayList implements IModelCustom { +public class WavefrontObjDisplayList implements IModelCustomNamed { public List> nameToCallList = new ArrayList<>(); @@ -95,4 +94,13 @@ public class WavefrontObjDisplayList implements IModelCustom { } } } + + @Override + public List getPartNames() { + List names = new ArrayList(); + for(Pair data : nameToCallList) { + names.add(data.getLeft()); + } + return names; + } } \ No newline at end of file diff --git a/src/main/java/com/hbm/render/loader/WavefrontObjVBO.java b/src/main/java/com/hbm/render/loader/WavefrontObjVBO.java index b0d4302d3..f852ba4ee 100644 --- a/src/main/java/com/hbm/render/loader/WavefrontObjVBO.java +++ b/src/main/java/com/hbm/render/loader/WavefrontObjVBO.java @@ -7,13 +7,12 @@ import java.util.List; import org.lwjgl.BufferUtils; import org.lwjgl.opengl.*; -import net.minecraftforge.client.model.IModelCustom; import net.minecraftforge.client.model.obj.TextureCoordinate; import net.minecraftforge.client.model.obj.Vertex; -public class WavefrontObjVBO implements IModelCustom { +public class WavefrontObjVBO implements IModelCustomNamed { - class VBOBufferData { + public class VBOBufferData { String name; int vertices = 0; @@ -23,7 +22,7 @@ public class WavefrontObjVBO implements IModelCustom { } - List groups = new ArrayList(); + public List groups = new ArrayList(); static int VERTEX_SIZE = 3; static int UV_SIZE = 3; @@ -147,4 +146,13 @@ public class WavefrontObjVBO implements IModelCustom { } } + @Override + public List getPartNames() { + List names = new ArrayList(); + for(VBOBufferData data : groups) { + names.add(data.name); + } + return names; + } + } \ No newline at end of file diff --git a/src/main/java/com/hbm/render/tileentity/RenderDoorGeneric.java b/src/main/java/com/hbm/render/tileentity/RenderDoorGeneric.java index c72b78c24..33bdb32d9 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderDoorGeneric.java +++ b/src/main/java/com/hbm/render/tileentity/RenderDoorGeneric.java @@ -2,7 +2,6 @@ package com.hbm.render.tileentity; import java.nio.DoubleBuffer; -import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; import com.hbm.animloader.AnimatedModel; @@ -11,7 +10,7 @@ import com.hbm.animloader.AnimationWrapper; import com.hbm.animloader.AnimationWrapper.EndResult; import com.hbm.animloader.AnimationWrapper.EndType; import com.hbm.blocks.BlockDummyable; -import com.hbm.render.loader.WavefrontObjDisplayList; +import com.hbm.render.loader.IModelCustomNamed; import com.hbm.tileentity.DoorDecl; import com.hbm.tileentity.TileEntityDoorGeneric; @@ -19,7 +18,6 @@ import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; -import net.minecraftforge.client.model.IModelCustom; public class RenderDoorGeneric extends TileEntitySpecialRenderer { @@ -76,29 +74,36 @@ public class RenderDoorGeneric extends TileEntitySpecialRenderer { animModel.controller.setAnim(w); animModel.renderAnimated(System.currentTimeMillis()); } else { - // IModelCustom model = door.getModel(); + IModelCustomNamed model = door.getModel(); - // long ms = System.currentTimeMillis()-te.animStartTime; - // float openTicks = MathHelper.clamp_float(te.state == 2 || te.state == 0 ? door.timeToOpen()*50-ms : ms, 0, door.timeToOpen()*50)*0.02F; + long ms = System.currentTimeMillis()-te.animStartTime; + float openTicks = MathHelper.clamp_float(te.state == 2 || te.state == 0 ? door.timeToOpen()*50-ms : ms, 0, door.timeToOpen()*50)*0.02F; - // for(Pair p : model.nameToCallList){ - // if(!door.doesRender(p.getLeft(), false)) - // continue; - // GL11.glPushMatrix(); - // bindTexture(door.getTextureForPart(te.getSkinIndex(), p.getLeft())); - // doPartTransform(door, p.getLeft(), openTicks, false); - // GL11.glCallList(p.getRight()); - // for(String name : door.getChildren(p.getLeft())){ - // if(!door.doesRender(name, true)) - // continue; - // GL11.glPushMatrix(); - // bindTexture(door.getTextureForPart(te.getSkinIndex(), name)); - // doPartTransform(door, name, openTicks, true); - // model.renderPart(name); - // GL11.glPopMatrix(); - // } - // GL11.glPopMatrix(); - // } + for(String partName : model.getPartNames()) { + if(!door.doesRender(partName, false)) + continue; + + GL11.glPushMatrix(); + { + bindTexture(door.getTextureForPart(te.getSkinIndex(), partName)); + doPartTransform(door, partName, openTicks, false); + model.renderPart(partName); + + for(String innerPartName : door.getChildren(partName)) { + if(!door.doesRender(innerPartName, true)) + continue; + + GL11.glPushMatrix(); + { + bindTexture(door.getTextureForPart(te.getSkinIndex(), innerPartName)); + doPartTransform(door, innerPartName, openTicks, true); + model.renderPart(innerPartName); + } + GL11.glPopMatrix(); + } + } + GL11.glPopMatrix(); + } } for(int i = 0; i < clip.length; i ++){ diff --git a/src/main/java/com/hbm/tileentity/DoorDecl.java b/src/main/java/com/hbm/tileentity/DoorDecl.java index c8471327c..d28ae1e22 100644 --- a/src/main/java/com/hbm/tileentity/DoorDecl.java +++ b/src/main/java/com/hbm/tileentity/DoorDecl.java @@ -4,13 +4,12 @@ import com.hbm.animloader.AnimatedModel; import com.hbm.animloader.Animation; import com.hbm.lib.Library; import com.hbm.main.ResourceManager; -import com.hbm.render.loader.WavefrontObjDisplayList; +import com.hbm.render.loader.IModelCustomNamed; import com.hbm.util.BobMathUtil; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.model.IModelCustom; import org.lwjgl.opengl.GL11; @@ -92,7 +91,7 @@ public abstract class DoorDecl { @Override @SideOnly(Side.CLIENT) - public WavefrontObjDisplayList getModel() { + public IModelCustomNamed getModel() { return null; } }; @@ -181,7 +180,7 @@ public abstract class DoorDecl { @Override @SideOnly(Side.CLIENT) - public IModelCustom getModel() { + public IModelCustomNamed getModel() { return ResourceManager.fire_door; } }; @@ -269,7 +268,7 @@ public abstract class DoorDecl { } @Override - public WavefrontObjDisplayList getModel() { + public IModelCustomNamed getModel() { return null; } @@ -360,7 +359,7 @@ public abstract class DoorDecl { @Override @SideOnly(Side.CLIENT) - public WavefrontObjDisplayList getModel() { + public IModelCustomNamed getModel() { return ResourceManager.sliding_seal_door; } }; @@ -459,7 +458,7 @@ public abstract class DoorDecl { @Override @SideOnly(Side.CLIENT) - public WavefrontObjDisplayList getModel() { + public IModelCustomNamed getModel() { return ResourceManager.secure_access_door; } }; @@ -548,7 +547,7 @@ public abstract class DoorDecl { @Override @SideOnly(Side.CLIENT) - public WavefrontObjDisplayList getModel() { + public IModelCustomNamed getModel() { return ResourceManager.round_airlock_door; } }; @@ -631,7 +630,7 @@ public abstract class DoorDecl { @Override @SideOnly(Side.CLIENT) - public WavefrontObjDisplayList getModel() { + public IModelCustomNamed getModel() { return ResourceManager.qe_sliding_door; } @@ -717,7 +716,7 @@ public abstract class DoorDecl { @Override @SideOnly(Side.CLIENT) - public WavefrontObjDisplayList getModel() { + public IModelCustomNamed getModel() { return ResourceManager.qe_containment; } @@ -858,7 +857,7 @@ public abstract class DoorDecl { @Override @SideOnly(Side.CLIENT) - public WavefrontObjDisplayList getModel() { + public IModelCustomNamed getModel() { return ResourceManager.water_door; } @@ -920,7 +919,7 @@ public abstract class DoorDecl { @Override public int[] getDimensions() { return new int[] { 0, 0, 2, 2, 2, 2 }; } @Override @SideOnly(Side.CLIENT) public ResourceLocation getTextureForPart(String partName) { return ResourceManager.silo_hatch_tex; } @Override public ResourceLocation getTextureForPart(int skinIndex, String partName) { return ResourceManager.silo_hatch_tex; } - @Override @SideOnly(Side.CLIENT) public WavefrontObjDisplayList getModel() { return ResourceManager.silo_hatch; } + @Override @SideOnly(Side.CLIENT) public IModelCustomNamed getModel() { return ResourceManager.silo_hatch; } }; @@ -980,7 +979,7 @@ public abstract class DoorDecl { @Override public int[] getDimensions() { return new int[] { 0, 0, 3, 3, 3, 3 }; } @Override @SideOnly(Side.CLIENT) public ResourceLocation getTextureForPart(String partName) { return ResourceManager.silo_hatch_large_tex; } @Override public ResourceLocation getTextureForPart(int skinIndex, String partName) { return ResourceManager.silo_hatch_large_tex; } - @Override @SideOnly(Side.CLIENT) public WavefrontObjDisplayList getModel() { return ResourceManager.silo_hatch_large; } + @Override @SideOnly(Side.CLIENT) public IModelCustomNamed getModel() { return ResourceManager.silo_hatch_large; } }; @@ -1058,7 +1057,7 @@ public abstract class DoorDecl { @Override @SideOnly(Side.CLIENT) - public WavefrontObjDisplayList getModel() { + public IModelCustomNamed getModel() { return ResourceManager.large_vehicle_door; } @@ -1112,7 +1111,7 @@ public abstract class DoorDecl { public abstract ResourceLocation getTextureForPart(int skinIndex, String partName); @SideOnly(Side.CLIENT) - public abstract IModelCustom getModel(); + public abstract IModelCustomNamed getModel(); @SideOnly(Side.CLIENT) public AnimatedModel getAnimatedModel() {