Fix up door rendering, moving it to a more generic interface

This commit is contained in:
George Paton 2024-04-18 17:14:04 +10:00
parent b9fa946440
commit 3c760ba95d
7 changed files with 91 additions and 48 deletions

View File

@ -9,6 +9,7 @@ import com.hbm.lib.RefStrings;
import com.hbm.render.anim.AnimationLoader; import com.hbm.render.anim.AnimationLoader;
import com.hbm.render.anim.BusAnimation; import com.hbm.render.anim.BusAnimation;
import com.hbm.render.loader.HFRWavefrontObject; import com.hbm.render.loader.HFRWavefrontObject;
import com.hbm.render.loader.IModelCustomNamed;
import com.hbm.render.loader.WavefrontObjDisplayList; import com.hbm.render.loader.WavefrontObjDisplayList;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -327,7 +328,7 @@ public class ResourceManager {
//Doors //Doors
public static AnimatedModel transition_seal = ColladaLoader.load(new ResourceLocation(RefStrings.MODID, "models/doors/seal.dae"), true); 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 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 //Secure Access Door
public static final ResourceLocation secure_access_door_tex = new ResourceLocation(RefStrings.MODID, "textures/models/doors/secure_access_door.png"); public static final ResourceLocation secure_access_door_tex = new ResourceLocation(RefStrings.MODID, "textures/models/doors/secure_access_door.png");

View File

@ -5,6 +5,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -16,12 +17,11 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.IResource;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.client.model.ModelFormatException; 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 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 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} *$)");
@ -483,6 +483,15 @@ public class HFRWavefrontObject implements IModelCustom {
return "obj"; return "obj";
} }
@Override
public List<String> getPartNames() {
List<String> names = new ArrayList<String>();
for(S_GroupObject data : groupObjects) {
names.add(data.name);
}
return names;
}
public WavefrontObjVBO asVBO() { public WavefrontObjVBO asVBO() {
return new WavefrontObjVBO(this); return new WavefrontObjVBO(this);
} }

View File

@ -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<String> getPartNames();
}

View File

@ -7,11 +7,10 @@ import org.apache.commons.lang3.tuple.Pair;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import net.minecraft.client.renderer.Tessellator; 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.GroupObject;
import net.minecraftforge.client.model.obj.WavefrontObject; import net.minecraftforge.client.model.obj.WavefrontObject;
public class WavefrontObjDisplayList implements IModelCustom { public class WavefrontObjDisplayList implements IModelCustomNamed {
public List<Pair<String, Integer>> nameToCallList = new ArrayList<>(); public List<Pair<String, Integer>> nameToCallList = new ArrayList<>();
@ -95,4 +94,13 @@ public class WavefrontObjDisplayList implements IModelCustom {
} }
} }
} }
@Override
public List<String> getPartNames() {
List<String> names = new ArrayList<String>();
for(Pair<String, Integer> data : nameToCallList) {
names.add(data.getLeft());
}
return names;
}
} }

View File

@ -7,13 +7,12 @@ import java.util.List;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.*; import org.lwjgl.opengl.*;
import net.minecraftforge.client.model.IModelCustom;
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 WavefrontObjVBO implements IModelCustom { public class WavefrontObjVBO implements IModelCustomNamed {
class VBOBufferData { public class VBOBufferData {
String name; String name;
int vertices = 0; int vertices = 0;
@ -23,7 +22,7 @@ public class WavefrontObjVBO implements IModelCustom {
} }
List<VBOBufferData> groups = new ArrayList<VBOBufferData>(); public List<VBOBufferData> groups = new ArrayList<VBOBufferData>();
static int VERTEX_SIZE = 3; static int VERTEX_SIZE = 3;
static int UV_SIZE = 3; static int UV_SIZE = 3;
@ -147,4 +146,13 @@ public class WavefrontObjVBO implements IModelCustom {
} }
} }
@Override
public List<String> getPartNames() {
List<String> names = new ArrayList<String>();
for(VBOBufferData data : groups) {
names.add(data.name);
}
return names;
}
} }

View File

@ -2,7 +2,6 @@ package com.hbm.render.tileentity;
import java.nio.DoubleBuffer; import java.nio.DoubleBuffer;
import org.apache.commons.lang3.tuple.Pair;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import com.hbm.animloader.AnimatedModel; 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.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.loader.WavefrontObjDisplayList; import com.hbm.render.loader.IModelCustomNamed;
import com.hbm.tileentity.DoorDecl; import com.hbm.tileentity.DoorDecl;
import com.hbm.tileentity.TileEntityDoorGeneric; 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.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraftforge.client.model.IModelCustom;
public class RenderDoorGeneric extends TileEntitySpecialRenderer { public class RenderDoorGeneric extends TileEntitySpecialRenderer {
@ -76,29 +74,36 @@ public class RenderDoorGeneric extends TileEntitySpecialRenderer {
animModel.controller.setAnim(w); animModel.controller.setAnim(w);
animModel.renderAnimated(System.currentTimeMillis()); animModel.renderAnimated(System.currentTimeMillis());
} else { } else {
// IModelCustom model = door.getModel(); IModelCustomNamed model = door.getModel();
// long ms = System.currentTimeMillis()-te.animStartTime; 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; float openTicks = MathHelper.clamp_float(te.state == 2 || te.state == 0 ? door.timeToOpen()*50-ms : ms, 0, door.timeToOpen()*50)*0.02F;
// for(Pair<String, Integer> p : model.nameToCallList){ for(String partName : model.getPartNames()) {
// if(!door.doesRender(p.getLeft(), false)) if(!door.doesRender(partName, false))
// continue; continue;
// GL11.glPushMatrix();
// bindTexture(door.getTextureForPart(te.getSkinIndex(), p.getLeft())); GL11.glPushMatrix();
// doPartTransform(door, p.getLeft(), openTicks, false); {
// GL11.glCallList(p.getRight()); bindTexture(door.getTextureForPart(te.getSkinIndex(), partName));
// for(String name : door.getChildren(p.getLeft())){ doPartTransform(door, partName, openTicks, false);
// if(!door.doesRender(name, true)) model.renderPart(partName);
// continue;
// GL11.glPushMatrix(); for(String innerPartName : door.getChildren(partName)) {
// bindTexture(door.getTextureForPart(te.getSkinIndex(), name)); if(!door.doesRender(innerPartName, true))
// doPartTransform(door, name, openTicks, true); continue;
// model.renderPart(name);
// GL11.glPopMatrix(); GL11.glPushMatrix();
// } {
// GL11.glPopMatrix(); 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 ++){ for(int i = 0; i < clip.length; i ++){

View File

@ -4,13 +4,12 @@ import com.hbm.animloader.AnimatedModel;
import com.hbm.animloader.Animation; import com.hbm.animloader.Animation;
import com.hbm.lib.Library; import com.hbm.lib.Library;
import com.hbm.main.ResourceManager; import com.hbm.main.ResourceManager;
import com.hbm.render.loader.WavefrontObjDisplayList; import com.hbm.render.loader.IModelCustomNamed;
import com.hbm.util.BobMathUtil; import com.hbm.util.BobMathUtil;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModelCustom;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -92,7 +91,7 @@ public abstract class DoorDecl {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public WavefrontObjDisplayList getModel() { public IModelCustomNamed getModel() {
return null; return null;
} }
}; };
@ -181,7 +180,7 @@ public abstract class DoorDecl {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public IModelCustom getModel() { public IModelCustomNamed getModel() {
return ResourceManager.fire_door; return ResourceManager.fire_door;
} }
}; };
@ -269,7 +268,7 @@ public abstract class DoorDecl {
} }
@Override @Override
public WavefrontObjDisplayList getModel() { public IModelCustomNamed getModel() {
return null; return null;
} }
@ -360,7 +359,7 @@ public abstract class DoorDecl {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public WavefrontObjDisplayList getModel() { public IModelCustomNamed getModel() {
return ResourceManager.sliding_seal_door; return ResourceManager.sliding_seal_door;
} }
}; };
@ -459,7 +458,7 @@ public abstract class DoorDecl {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public WavefrontObjDisplayList getModel() { public IModelCustomNamed getModel() {
return ResourceManager.secure_access_door; return ResourceManager.secure_access_door;
} }
}; };
@ -548,7 +547,7 @@ public abstract class DoorDecl {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public WavefrontObjDisplayList getModel() { public IModelCustomNamed getModel() {
return ResourceManager.round_airlock_door; return ResourceManager.round_airlock_door;
} }
}; };
@ -631,7 +630,7 @@ public abstract class DoorDecl {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public WavefrontObjDisplayList getModel() { public IModelCustomNamed getModel() {
return ResourceManager.qe_sliding_door; return ResourceManager.qe_sliding_door;
} }
@ -717,7 +716,7 @@ public abstract class DoorDecl {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public WavefrontObjDisplayList getModel() { public IModelCustomNamed getModel() {
return ResourceManager.qe_containment; return ResourceManager.qe_containment;
} }
@ -858,7 +857,7 @@ public abstract class DoorDecl {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public WavefrontObjDisplayList getModel() { public IModelCustomNamed getModel() {
return ResourceManager.water_door; 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 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 @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 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 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 @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 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 @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public WavefrontObjDisplayList getModel() { public IModelCustomNamed getModel() {
return ResourceManager.large_vehicle_door; return ResourceManager.large_vehicle_door;
} }
@ -1112,7 +1111,7 @@ public abstract class DoorDecl {
public abstract ResourceLocation getTextureForPart(int skinIndex, String partName); public abstract ResourceLocation getTextureForPart(int skinIndex, String partName);
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public abstract IModelCustom getModel(); public abstract IModelCustomNamed getModel();
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public AnimatedModel getAnimatedModel() { public AnimatedModel getAnimatedModel() {