mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-22 13:10:13 +00:00
Techne Rendering
* Fixes problem with texture sizes (Forge bug) * Implements a framework that allows easy rendering of only parts of models. * Changes telepad to use that.
This commit is contained in:
1 parent
9f9d0cce3f
commit
832d3bd4f6
8 files changed
+144
-57
No files matched your search
@@ -345,8 +345,9 @@ public class ClientProxy extends CommonProxy {
|
||||
RenderingRegistry.registerBlockHandler(new PaintedBlockRenderer(BlockTravelAnchor.renderId, EnderIO.blockTravelPlatform));
|
||||
|
||||
BlockTelePad.renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
RenderingRegistry.registerBlockHandler(new TelePadRenderer());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileTelePad.class, new TelePadSpecialRenderer());
|
||||
TelePadRenderer telePadRenderer = new TelePadRenderer();
|
||||
RenderingRegistry.registerBlockHandler(telePadRenderer);
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileTelePad.class, new TelePadSpecialRenderer(telePadRenderer));
|
||||
|
||||
MinecraftForgeClient.registerItemRenderer(EnderIO.itemMachinePart, new MachinePartRenderer());
|
||||
MinecraftForgeClient.registerItemRenderer(EnderIO.itemConduitFacade, new FacadeRenderer());
|
||||
|
||||
@@ -117,6 +117,9 @@ public abstract class TileEntityEio extends TileEntity {
|
||||
/**
|
||||
* Called directly after the TE is constructed. This is the place to call
|
||||
* non-final methods.
|
||||
*
|
||||
* Note: This will not be called when the TE is loaded from the save. Hook
|
||||
* into the nbt methods for that.
|
||||
*/
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
|
||||
iconBuffer[0][11] = iIconRegister.registerIcon(side);
|
||||
|
||||
iconBuffer[1][0] = iIconRegister.registerIcon(getModelIconKey(false));
|
||||
iconBuffer[1][1] = iIconRegister.registerIcon(getModelIconKey(false));
|
||||
iconBuffer[1][1] = iIconRegister.registerIcon(getModelIconKey(true));
|
||||
|
||||
registerOverlayIcons(iIconRegister);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.google.common.collect.ObjectArrays;
|
||||
|
||||
import crazypants.render.CustomCubeRenderer;
|
||||
import crazypants.render.TechneModelRenderer;
|
||||
import crazypants.render.TechneUtil;
|
||||
import crazypants.render.VertexRotationFacing;
|
||||
import crazypants.render.VertexTransform;
|
||||
import crazypants.render.VertexTransformComposite;
|
||||
@@ -22,6 +23,10 @@ public class TechneMachineRenderer<T extends AbstractMachineEntity> extends Tech
|
||||
super(modelPath, block.getRenderType(), new VertexTransformComposite(new VertexRotationFacing(ForgeDirection.NORTH)));
|
||||
}
|
||||
|
||||
public TechneMachineRenderer(int renderId, String modelPath) {
|
||||
super(TechneUtil.getModel(modelPath), renderId, new VertexTransformComposite(new VertexRotationFacing(ForgeDirection.NORTH)));
|
||||
}
|
||||
|
||||
public TechneMachineRenderer<T> addTransform(VertexTransform vt) {
|
||||
this.vt = new VertexTransformComposite(ObjectArrays.concat(vt, ((VertexTransformComposite) this.vt).xforms));
|
||||
return this;
|
||||
|
||||
@@ -20,19 +20,32 @@ import crazypants.util.BlockCoord;
|
||||
|
||||
public class TelePadRenderer extends TechneModelRenderer {
|
||||
|
||||
public static final Map<String, GroupObject> all = TechneUtil.getModel("models/telePad");
|
||||
private final Collection<GroupObject> strippedModel = Lists.newArrayList();
|
||||
|
||||
public TelePadRenderer() {
|
||||
super(getModel(), BlockTelePad.renderId);
|
||||
}
|
||||
|
||||
private static Collection<GroupObject> getModel() {
|
||||
Collection<GroupObject> model = Lists.newArrayList();
|
||||
for (String s : all.keySet()) {
|
||||
super(TechneUtil.getModel("models/telePad"), BlockTelePad.renderId);
|
||||
for (String s : this.model.keySet()) {
|
||||
if(!s.equals("glass") && !s.contains("blade")) {
|
||||
model.add(all.get(s));
|
||||
strippedModel.add(this.model.get(s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Collection<GroupObject> getModel() {
|
||||
return strippedModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<GroupObject> getModel(Block block, int metadata) {
|
||||
return getModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<GroupObject> getModel(IBlockAccess world, int x, int y, int z) {
|
||||
return getModel();
|
||||
}
|
||||
|
||||
Map<String, GroupObject> getFullModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,16 +16,26 @@ import crazypants.render.TechneUtil;
|
||||
|
||||
public class TelePadSpecialRenderer extends TileEntitySpecialRenderer {
|
||||
|
||||
private static GroupObject blade1 = TelePadRenderer.all.get("blade1");
|
||||
private static GroupObject blade2 = TelePadRenderer.all.get("blade2");
|
||||
private static GroupObject blade3 = TelePadRenderer.all.get("blade3");
|
||||
private final GroupObject blade1;
|
||||
private final GroupObject blade2;
|
||||
private final GroupObject blade3;
|
||||
// Reverse order for top to bottom
|
||||
private static List<GroupObject> blades = Lists.newArrayList(blade3, blade2, blade1);
|
||||
private final List<GroupObject> blades;
|
||||
|
||||
private static GroupObject glass = TelePadRenderer.all.get("glass");
|
||||
private final GroupObject glass;
|
||||
|
||||
private static Random rand = new Random();
|
||||
|
||||
public TelePadSpecialRenderer(TelePadRenderer telePadRenderer) {
|
||||
super();
|
||||
blade1 = telePadRenderer.getFullModel().get("blade1");
|
||||
blade2 = telePadRenderer.getFullModel().get("blade2");
|
||||
blade3 = telePadRenderer.getFullModel().get("blade3");
|
||||
blades = Lists.newArrayList(blade3, blade2, blade1);
|
||||
|
||||
glass = telePadRenderer.getFullModel().get("glass");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float p_147500_8_) {
|
||||
TileTelePad tp = (TileTelePad) te;
|
||||
@@ -51,8 +61,8 @@ public class TelePadSpecialRenderer extends TileEntitySpecialRenderer {
|
||||
|
||||
private void render(GroupObject model, TileEntity te, Tessellator tes) {
|
||||
tes.startDrawingQuads();
|
||||
TechneUtil.renderWithIcon(model, te.getBlockType().getIcon(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, 0), null, Tessellator.instance,
|
||||
te.getWorldObj(), 0, 0, 0, null, false);
|
||||
TechneUtil.renderWithIcon(model, te.getBlockType().getIcon(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, 0), null,
|
||||
Tessellator.instance, te.getWorldObj(), 0, 0, 0, null, false);
|
||||
tes.draw();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package crazypants.render;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
@@ -10,7 +11,7 @@ import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
|
||||
public class TechneModelRenderer implements ISimpleBlockRenderingHandler {
|
||||
|
||||
private Collection<GroupObject> model;
|
||||
protected Map<String, GroupObject> model;
|
||||
private int renderId;
|
||||
|
||||
protected VertexTransform vt;
|
||||
@@ -20,29 +21,39 @@ public class TechneModelRenderer implements ISimpleBlockRenderingHandler {
|
||||
}
|
||||
|
||||
public TechneModelRenderer(String modelPath, int renderId, VertexTransform vt) {
|
||||
this(TechneUtil.getModelAll(modelPath), renderId, vt);
|
||||
this(TechneUtil.getModel(modelPath), renderId, vt);
|
||||
}
|
||||
|
||||
public TechneModelRenderer(Collection<GroupObject> model, int renderId) {
|
||||
public TechneModelRenderer(Map<String, GroupObject> model, int renderId) {
|
||||
this(model, renderId, null);
|
||||
}
|
||||
|
||||
public TechneModelRenderer(Collection<GroupObject> model, int renderId, VertexTransform vt) {
|
||||
public TechneModelRenderer(Map<String, GroupObject> model, int renderId, VertexTransform vt) {
|
||||
this.model = model;
|
||||
this.renderId = renderId;
|
||||
this.vt = vt;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected Collection<GroupObject> getModel(Block block, int metadata) {
|
||||
return model.values();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected Collection<GroupObject> getModel(IBlockAccess world, int x, int y, int z) {
|
||||
return model.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
TechneUtil.vt = this.vt;
|
||||
TechneUtil.renderInventoryBlock(model, block, metadata, renderer);
|
||||
TechneUtil.renderInventoryBlock(getModel(block, metadata), block, metadata, renderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
TechneUtil.vt = this.vt;
|
||||
return TechneUtil.renderWorldBlock(model, world, x, y, z, block, renderer);
|
||||
return TechneUtil.renderWorldBlock(getModel(world, x, y, z), world, x, y, z, block, renderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -84,16 +84,16 @@ public class TechneUtil {
|
||||
|
||||
private static final Tessellator tes = Tessellator.instance;
|
||||
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model) {
|
||||
return bakeModel(model, 1);
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, TechneModel supermodel) {
|
||||
return bakeModel(model, supermodel, 1);
|
||||
}
|
||||
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, float scale) {
|
||||
return bakeModel(model, scale, new Matrix4f());
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, TechneModel supermodel, float scale) {
|
||||
return bakeModel(model, supermodel, scale, new Matrix4f());
|
||||
}
|
||||
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, float scale, Matrix4f matrix) {
|
||||
return bakeModel(model, scale, matrix, false);
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, TechneModel supermodel, float scale, Matrix4f matrix) {
|
||||
return bakeModel(model, supermodel, scale, matrix, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +111,18 @@ public class TechneUtil {
|
||||
* ModelRenderer.render
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, float scale, Matrix4f matrix, boolean rotateYFirst) {
|
||||
public static List<GroupObject> bakeModel(ModelRenderer model, TechneModel supermodel, float scale, Matrix4f matrix,
|
||||
boolean rotateYFirst) {
|
||||
|
||||
// Correction for the fact that TechneModel sets the texture size on the
|
||||
// ModelRenderer after the texture positions have been calculated. It also
|
||||
// never sets the size on the TechneModel, so we can use that value (which
|
||||
// is taken by the ModelRenderer for the calculations) to correct the
|
||||
// positions.
|
||||
|
||||
float uCorrection = ((int) model.textureWidth) / supermodel.textureWidth;
|
||||
float vCorrection = ((int) model.textureHeight) / supermodel.textureHeight;
|
||||
|
||||
Matrix4f m = new Matrix4f(matrix);
|
||||
|
||||
m.translate(new Vector3f(model.offsetX + model.rotationPointX * scale, model.offsetY + model.rotationPointY * scale, model.offsetZ + model.rotationPointZ
|
||||
@@ -137,6 +148,16 @@ public class TechneUtil {
|
||||
Face face = new Face();
|
||||
face.vertices = new Vertex[4];
|
||||
face.textureCoordinates = new TextureCoordinate[4];
|
||||
float minU = -1, minV = -1;
|
||||
for (int j = 0; j < 4; j++) {
|
||||
PositionTextureVertex pv = quads[i].vertexPositions[j];
|
||||
if (minU < 0 || minU > pv.texturePositionX) {
|
||||
minU = pv.texturePositionX;
|
||||
}
|
||||
if (minV < 0 || minV > pv.texturePositionY) {
|
||||
minV = pv.texturePositionY;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < 4; j++) {
|
||||
PositionTextureVertex pv = quads[i].vertexPositions[j];
|
||||
|
||||
@@ -149,15 +170,23 @@ public class TechneUtil {
|
||||
|
||||
face.vertices[j] = new Vertex(vec.x / vec.w, vec.y / vec.w, vec.z / vec.w);
|
||||
|
||||
// Increase the interpolation scale by multiples of 2
|
||||
while (pv.texturePositionX > uMult) {
|
||||
uMult *= 2;
|
||||
// The small offset will reduce the amount of visible errors (white
|
||||
// pixels) at the edges of textures a lot. The introduced visible
|
||||
// offset is very small, about 1 screen pixel between a 1/16 block
|
||||
// wide element and a 1 block wide element when standing "on touch".
|
||||
float u;
|
||||
float v;
|
||||
if (pv.texturePositionX == minU) {
|
||||
u = pv.texturePositionX / uCorrection + 0.0001f;
|
||||
} else {
|
||||
u = pv.texturePositionX / uCorrection - 0.0001f;
|
||||
}
|
||||
while (pv.texturePositionY > vMult) {
|
||||
vMult *= 2;
|
||||
if (pv.texturePositionY == minV) {
|
||||
v = pv.texturePositionY / vCorrection + 0.0001f;
|
||||
} else {
|
||||
v = pv.texturePositionY / vCorrection - 0.0001f;
|
||||
}
|
||||
|
||||
face.textureCoordinates[j] = new TextureCoordinate(pv.texturePositionX, pv.texturePositionY);
|
||||
face.textureCoordinates[j] = new TextureCoordinate(u, v);
|
||||
}
|
||||
face.faceNormal = face.calculateFaceNormal();
|
||||
obj.faces.add(face);
|
||||
@@ -180,9 +209,6 @@ public class TechneUtil {
|
||||
return bakeModel(model, scale, m, false);
|
||||
}
|
||||
|
||||
// Used in the second pass of baking to adjust UVs to the proper interpolation
|
||||
private static int uMult = 1, vMult = 1;
|
||||
|
||||
/**
|
||||
* Use this to convert TechneModel to it's static representation
|
||||
*/
|
||||
@@ -192,24 +218,10 @@ public class TechneUtil {
|
||||
Map<String, GroupObject> res = Maps.newHashMap();
|
||||
|
||||
for (Map.Entry<String, ModelRenderer> e : parts.entrySet()) {
|
||||
GroupObject obj = bakeModel(e.getValue(), scale, m, rotateYFirst).get(0);
|
||||
GroupObject obj = bakeModel(e.getValue(), model, scale, m, rotateYFirst).get(0);
|
||||
res.put(e.getKey(), obj);
|
||||
}
|
||||
|
||||
// Second pass, adjust the UVs to be on a 0-1 interpolation scale
|
||||
if(uMult + vMult != 2) {
|
||||
for (GroupObject go : res.values()) {
|
||||
for (Face f : go.faces) {
|
||||
for (TextureCoordinate tc : f.textureCoordinates) {
|
||||
tc.u /= uMult;
|
||||
tc.v /= vMult;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uMult = vMult = 1;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -304,12 +316,22 @@ public class TechneUtil {
|
||||
tes.addVertexWithUV(v.x, v.y, v.z, override.getInterpolatedU(interpX * 16), override.getInterpolatedV(interpY * 16));
|
||||
} else {
|
||||
TextureCoordinate t = f.textureCoordinates[i];
|
||||
tes.addVertexWithUV(v.x, v.y, v.z, icon.getInterpolatedU(t.u * 16), icon.getInterpolatedV(t.v * 16));
|
||||
tes.addVertexWithUV(v.x, v.y, v.z, getInterpolatedU(icon, t.u), getInterpolatedV(icon, t.v));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reducing texture positioning error by working in double and not multiplying
|
||||
// and dividing by 16.
|
||||
public static double getInterpolatedV(IIcon icon, double offset) {
|
||||
return icon.getMinV() + (icon.getMaxV() - icon.getMinV()) * offset;
|
||||
}
|
||||
|
||||
public static double getInterpolatedU(IIcon icon, double offset) {
|
||||
return icon.getMinU() + (icon.getMaxU() - icon.getMinU()) * offset;
|
||||
}
|
||||
|
||||
private static ForgeDirection getNormalFor(Vertex n) {
|
||||
if(n.x != 0) {
|
||||
return n.x > 0 ? ForgeDirection.EAST : ForgeDirection.WEST;
|
||||
@@ -334,6 +356,17 @@ public class TechneUtil {
|
||||
resetVT();
|
||||
}
|
||||
|
||||
public static void renderInventoryBlock(GroupObject model, Block block, int metadata, RenderBlocks rb) {
|
||||
IIcon icon = getIconFor(block, metadata);
|
||||
tes.startDrawingQuads();
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(0, -0.47f, 0);
|
||||
renderWithIcon(model, icon, rb.overrideBlockTexture, tes, null, 0, 0, 0, vt, true);
|
||||
tes.addTranslation(0, 0.47f, 0);
|
||||
tes.draw();
|
||||
resetVT();
|
||||
}
|
||||
|
||||
public static boolean renderWorldBlock(Collection<GroupObject> model, IBlockAccess world, int x, int y, int z, Block block, RenderBlocks rb) {
|
||||
IIcon icon = getIconFor(block, world, x, y, z);
|
||||
return renderWorldBlock(model, icon, world, x, y, z, block, rb);
|
||||
@@ -349,6 +382,17 @@ public class TechneUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean renderWorldBlock(GroupObject model, IBlockAccess world, int x, int y, int z, Block block, RenderBlocks rb) {
|
||||
IIcon icon = getIconFor(block, world, x, y, z);
|
||||
tes.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(x + .5F, y + 0.0375f, z + .5F);
|
||||
renderWithIcon(model, icon, rb.overrideBlockTexture, tes, world, x, y, z, vt, true);
|
||||
tes.addTranslation(-x - .5F, -y - 0.0375f, -z - .5F);
|
||||
resetVT();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void resetVT() {
|
||||
vt = null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user