Working implementation of custom models for the Calcinator and Aludel (Requires OBJ Loader lib)

This commit is contained in:
pahimar 2013-03-11 23:23:06 -04:00
parent 811bbfe9f7
commit bfc28d6597
8 changed files with 110 additions and 194 deletions

View file

@ -1,7 +1,6 @@
package com.pahimar.ee3.client.model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraftforge.common.ForgeDirection;
@ -11,6 +10,7 @@ import com.obj.Face;
import com.obj.Group;
import com.obj.WavefrontObject;
import com.pahimar.ee3.lib.Models;
import com.pahimar.ee3.lib.Reference;
import com.pahimar.ee3.lib.Sprites;
import com.pahimar.ee3.tileentity.TileAludel;
@ -30,81 +30,46 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ModelAludel extends ModelBase {
private static final int TEXTURE_HEIGHT = 128;
private static final int TEXTURE_WIDTH = 128;
private float scale;
private WavefrontObject objModel;
private ModelRenderer baseStand, northStand, southStand, eastStand, westStand;
private ModelRenderer bottomBulb, topBulb;
private ModelRenderer chute;
private WavefrontObject modelAludelOBJ;
public ModelAludel() {
this.objModel = new WavefrontObject(this.getClass().getResource("/" + Models.ALUDEL).getFile());
this.scale = 1F;
this.modelAludelOBJ = new WavefrontObject(this.getClass().getResource("/" + Models.ALUDEL).getFile());
}
public ModelAludel(float scale) {
this.scale = scale;
textureHeight = TEXTURE_HEIGHT;
textureWidth = TEXTURE_WIDTH;
baseStand = new ModelRenderer(this, 0, 36);
baseStand.setRotationPoint(8F, 1F, 8F);
northStand = new ModelRenderer(this, 0, 36);
northStand.addBox(-3.5F, -1F, -1F, 7, 2, 2);
northStand.setRotationPoint(4.5F, 0F, 0F);
southStand = new ModelRenderer(this, 0, 36);
southStand.addBox(-3.5F, -1F, -1F, 7, 2, 2);
southStand.setRotationPoint(-4.5F, 0F, 0F);
eastStand = new ModelRenderer(this, 0, 36);
eastStand.addBox(-1F, -1F, -3.5F, 2, 2, 7);
eastStand.setRotationPoint(0F, 0F, 4.5F);
westStand = new ModelRenderer(this, 0, 36);
westStand.addBox(-1F, -1F, -3.5F, 2, 2, 7);
westStand.setRotationPoint(0F, 0F, -4.5F);
baseStand.addChild(northStand);
baseStand.addChild(southStand);
baseStand.addChild(eastStand);
baseStand.addChild(westStand);
baseStand.rotateAngleY = (float) (Math.PI / 4F);
bottomBulb = new ModelRenderer(this, 0, 36);
bottomBulb.addBox(-5F, -3F, -5F, 10, 6, 10);
bottomBulb.setRotationPoint(8F, 4.5F, 8F);
chute = new ModelRenderer(this, 0, 36);
chute.addBox(-2F, -1.5F, -2F, 4, 3, 4);
chute.setRotationPoint(8F, 9F, 8F);
topBulb = new ModelRenderer(this, 0, 36);
topBulb.addBox(-3F, -3F, -3F, 6, 6, 6);
topBulb.setRotationPoint(8F, 13F, 8F);
}
public void render(float scale) {
baseStand.render(scale);
bottomBulb.render(scale);
chute.render(scale);
topBulb.render(scale);
this.modelAludelOBJ = new WavefrontObject(this.getClass().getResource("/" + Models.ALUDEL).getFile());
}
public void render(Tessellator tessellator, float scale) {
if (objModel.getGroups().size() != 0) {
for (Group group : objModel.getGroups()) {
if (modelAludelOBJ.getGroups().size() != 0) {
for (Group group : modelAludelOBJ.getGroups()) {
if (group.getFaces().size() != 0) {
for (Face face : group.getFaces()) {
tessellator.startDrawing(GL11.GL_TRIANGLE_STRIP);
tessellator.startDrawing(GL11.GL_TRIANGLES);
float sumU = 0F;
float sumV = 0F;
for (int i = 0; i < face.getTextures().length; ++i) {
sumU += face.getTextures()[i].getU();
sumV += face.getTextures()[i].getV();
}
for (int i = 0; i < 3; ++i) {
tessellator.addVertexWithUV(face.getVertices()[i].getX(), face.getVertices()[i].getY(), face.getVertices()[i].getZ(), face.getTextures()[i].getU(), face.getTextures()[i].getV());
float offsetU = Reference.MODEL_TEXTURE_OFFSET;
float offsetV = Reference.MODEL_TEXTURE_OFFSET;
if (face.getTextures()[i].getU() > (sumU / face.getTextures().length)) {
offsetU = -offsetU;
}
if (face.getTextures()[i].getV() > (sumV / face.getTextures().length)) {
offsetV = -offsetV;
}
tessellator.addVertexWithUV(face.getVertices()[i].getX() * scale, face.getVertices()[i].getY() * scale, face.getVertices()[i].getZ() * scale, face.getTextures()[i].getU() + offsetU, face.getTextures()[i].getV() + offsetV);
}
tessellator.draw();
@ -120,8 +85,7 @@ public class ModelAludel extends ModelBase {
GL11.glDisable(GL11.GL_LIGHTING);
correctRotation(x, y, z, aludel.getOrientation());
FMLClientHandler.instance().getClient().renderEngine.func_98187_b(Sprites.MODEL_ALUDEL);
//this.render(scale);
this.render(Tessellator.instance, scale);
this.render(Tessellator.instance, this.scale);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}

View file

@ -1,10 +1,15 @@
package com.pahimar.ee3.client.model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.Tessellator;
import org.lwjgl.opengl.GL11;
import com.obj.Face;
import com.obj.Group;
import com.obj.WavefrontObject;
import com.pahimar.ee3.lib.Models;
import com.pahimar.ee3.lib.Reference;
import com.pahimar.ee3.lib.Sprites;
import com.pahimar.ee3.tileentity.TileCalcinator;
@ -24,129 +29,70 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ModelCalcinator extends ModelBase {
private static final int TEXTURE_HEIGHT = 128;
private static final int TEXTURE_WIDTH = 128;
private ModelRenderer firePotBottom, firePotLeft, firePotRight, firePotFront, firePotBack;
private ModelRenderer legFrontLeft, legFrontRight, legBackLeft, legBackRight;
private ModelRenderer armFrontLeft, armFrontRight, armBackLeft, armBackRight;
private ModelRenderer bowlBottom, bowlLeft, bowlRight, bowlFront, bowlBack;
private ModelRenderer firePotEmbers, bowlEmbers;
private float scale;
private WavefrontObject modelCalcinatorOBJ;
public ModelCalcinator() {
this.scale = 1F;
this.modelCalcinatorOBJ = new WavefrontObject(this.getClass().getResource("/" + Models.CALCINATOR).getFile());
}
public ModelCalcinator(float scale) {
this.scale = scale;
textureHeight = TEXTURE_HEIGHT;
textureWidth = TEXTURE_WIDTH;
firePotLeft = new ModelRenderer(this, 0, 36);
firePotLeft.addBox(-0.5F, -1.5F, -4F, 1, 3, 8, scale);
firePotLeft.setRotationPoint(3.5F, 1F, 0F);
firePotRight = new ModelRenderer(this, 0, 36);
firePotRight.addBox(-0.5F, -1.5F, -4F, 1, 3, 8, scale);
firePotRight.setRotationPoint(-3.5F, 1F, 0F);
firePotBack = new ModelRenderer(this, 0, 36);
firePotBack.addBox(-3F, -1.5F, -0.5F, 6, 3, 1, scale);
firePotBack.setRotationPoint(0F, 1F, -3.5F);
firePotFront = new ModelRenderer(this, 0, 36);
firePotFront.addBox(-3F, -1.5F, -0.5F, 6, 3, 1, scale);
firePotFront.setRotationPoint(0F, 1F, 3.5F);
firePotBottom = new ModelRenderer(this, 0, 36);
firePotBottom.addBox(-3F, -0.5F, -3F, 6, 1, 6, scale);
firePotBottom.setRotationPoint(8, 2, 8);
firePotBottom.addChild(firePotBack);
firePotBottom.addChild(firePotFront);
firePotBottom.addChild(firePotLeft);
firePotBottom.addChild(firePotRight);
legFrontLeft = new ModelRenderer(this, 0, 0);
legFrontLeft.addBox(-1F, -8F, -1F, 2, 8, 2, scale);
legFrontLeft.setRotationPoint(-9F, 6, 0);
legFrontRight = new ModelRenderer(this, 0, 0);
legFrontRight.addBox(-1F, -8F, -1F, 2, 8, 2, scale);
legFrontRight.setRotationPoint(9F, 6, 0);
legBackLeft = new ModelRenderer(this, 0, 0);
legBackLeft.addBox(-1F, -8F, -1F, 2, 8, 2, scale);
legBackLeft.setRotationPoint(0, 6, -9F);
legBackRight = new ModelRenderer(this, 0, 0);
legBackRight.addBox(-1F, -8F, -1F, 2, 8, 2, scale);
legBackRight.setRotationPoint(0, 6, 9F);
armFrontLeft = new ModelRenderer(this, 0, 10);
armFrontLeft.addBox(-2F, -0.5F, -1F, 4, 1, 2, scale);
armFrontLeft.setRotationPoint(6, 1, 0);
armFrontRight = new ModelRenderer(this, 0, 10);
armFrontRight.addBox(-2F, -0.5F, -1F, 4, 1, 2, scale);
armFrontRight.setRotationPoint(-6, 1, 0);
armBackLeft = new ModelRenderer(this, 12, 10);
armBackLeft.addBox(-1F, -0.5F, -2.0F, 2, 1, 4, scale);
armBackLeft.setRotationPoint(0, 1, 6);
armBackRight = new ModelRenderer(this, 12, 10);
armBackRight.addBox(-1F, -0.5F, -2.0F, 2, 1, 4, scale);
armBackRight.setRotationPoint(0, 1, -6);
firePotBottom.addChild(legFrontLeft);
firePotBottom.addChild(legFrontRight);
firePotBottom.addChild(legBackLeft);
firePotBottom.addChild(legBackRight);
firePotBottom.addChild(armFrontLeft);
firePotBottom.addChild(armFrontRight);
firePotBottom.addChild(armBackLeft);
firePotBottom.addChild(armBackRight);
firePotBottom.rotateAngleY = (float) (Math.PI / 4F);
bowlBack = new ModelRenderer(this, 0, 36);
bowlBack.addBox(-8F, -3.5F, -0.5F, 16, 7, 1, scale);
bowlBack.setRotationPoint(0F, 3.6F, 7.5F);
bowlFront = new ModelRenderer(this, 0, 36);
bowlFront.addBox(-8F, -3.5F, -0.5F, 16, 7, 1, scale);
bowlFront.setRotationPoint(0, 3.6F, -7.5F);
bowlLeft = new ModelRenderer(this, 0, 44);
bowlLeft.addBox(-0.5F, -3.5F, -7F, 1, 7, 14, scale);
bowlLeft.setRotationPoint(7.5F, 3.6F, 0);
bowlRight = new ModelRenderer(this, 0, 44);
bowlRight.addBox(-0.5F, -3.5F, -7F, 1, 7, 14, scale);
bowlRight.setRotationPoint(-7.5F, 3.6F, 0);
bowlBottom = new ModelRenderer(this, 0, 19);
bowlBottom.addBox(-8F, -1F, -8F, 16, 1, 16, scale);
bowlBottom.setRotationPoint(8, 9, 8);
bowlBottom.addChild(bowlBack);
bowlBottom.addChild(bowlFront);
bowlBottom.addChild(bowlLeft);
bowlBottom.addChild(bowlRight);
bowlEmbers = new ModelRenderer(this, 0, 65);
bowlEmbers.addBox(-7F, -0.5F, -7F, 14, 1, 14, scale);
bowlEmbers.setRotationPoint(8, 9, 8);
bowlEmbers.mirror = true;
firePotEmbers = new ModelRenderer(this, 0, 65);
firePotEmbers.addBox(-3F, -0.5F, -3F, 6, 1, 6, scale);
firePotEmbers.setRotationPoint(8, 3, 8);
firePotEmbers.rotateAngleY = (float) (Math.PI / 4F);
this.modelCalcinatorOBJ = new WavefrontObject(this.getClass().getResource("/" + Models.CALCINATOR).getFile());
}
public void render(float scale) {
public void render(Tessellator tessellator, float scale) {
firePotBottom.render(scale);
bowlBottom.render(scale);
firePotEmbers.render(scale);
bowlEmbers.render(scale);
if (modelCalcinatorOBJ.getGroups().size() != 0) {
for (Group group : modelCalcinatorOBJ.getGroups()) {
if (group.getName().equalsIgnoreCase("calcinator")) {
if (group.getFaces().size() != 0) {
for (Face face : group.getFaces()) {
tessellator.startDrawing(GL11.GL_TRIANGLES);
float sumU = 0F;
float sumV = 0F;
for (int i = 0; i < face.getTextures().length; ++i) {
sumU += face.getTextures()[i].getU();
sumV += face.getTextures()[i].getV();
}
for (int i = 0; i < 3; ++i) {
float offsetU = Reference.MODEL_TEXTURE_OFFSET;
float offsetV = Reference.MODEL_TEXTURE_OFFSET;
if (face.getTextures()[i].getU() > (sumU / face.getTextures().length)) {
offsetU = -offsetU;
}
if (face.getTextures()[i].getV() > (sumV / face.getTextures().length)) {
offsetV = -offsetV;
}
tessellator.addVertexWithUV(face.getVertices()[i].getX() * scale, face.getVertices()[i].getY() * scale, face.getVertices()[i].getZ() * scale, face.getTextures()[i].getU() + offsetU, face.getTextures()[i].getV() + offsetV);
}
tessellator.draw();
}
}
}
}
}
}
public void render(TileCalcinator calcinator, double x, double y, double z) {
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glTranslated(x, y, z);
GL11.glTranslatef((float)x + 0.5F, (float)y + 0.0F, (float)z + 1.2F);
GL11.glRotatef(45F, 0F, 1F, 0F);
GL11.glRotatef(-90F, 1F, 0F, 0F);
FMLClientHandler.instance().getClient().renderEngine.func_98187_b(Sprites.MODEL_CALCINATOR);
this.render(scale);
this.render(Tessellator.instance, this.scale);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
}

View file

@ -29,7 +29,6 @@ public class ItemAludelRenderer implements IItemRenderer {
public ItemAludelRenderer() {
//aludelModel = new ModelAludel(1 / 16F);
aludelModel = new ModelAludel();
}
@ -48,18 +47,21 @@ public class ItemAludelRenderer implements IItemRenderer {
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
float scale;
switch (type) {
case ENTITY: {
//renderAludel(-0.5F, 0F, -0.5F);
renderAludel(-0.5F, 0F, -0.5F);
scale = 0.66F;
renderAludel(-0.5F * scale, 0.0F * scale, 0.5F * scale, scale);
break;
}
case EQUIPPED: {
renderAludel(0F, 0.0F, 1F);
scale = 0.66F;
renderAludel(0.5F * scale, 0.0F * scale, 1.25F * scale, scale);
break;
}
case INVENTORY: {
renderAludel(-1.0F, -1.0F, 0.0F);
scale = 0.85F;
renderAludel(-1.0F * scale, -1.2F * scale, 0.0F * scale, scale);
break;
}
default:
@ -67,14 +69,15 @@ public class ItemAludelRenderer implements IItemRenderer {
}
}
private void renderAludel(float x, float y, float z) {
private void renderAludel(float x, float y, float z, float scale) {
FMLClientHandler.instance().getClient().renderEngine.func_98187_b(Sprites.MODEL_ALUDEL);
GL11.glPushMatrix(); //start
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glTranslatef(x, y, z); //size
GL11.glRotatef(-90F, 1F, 0, 0);
//aludelModel.render(0.0625F);
aludelModel.render(Tessellator.instance, 0.0625F);
aludelModel.render(Tessellator.instance, scale);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix(); //end
}
}

View file

@ -1,5 +1,6 @@
package com.pahimar.ee3.client.renderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;
@ -28,7 +29,7 @@ public class ItemCalcinatorRenderer implements IItemRenderer {
public ItemCalcinatorRenderer() {
calcinatorModel = new ModelCalcinator(1 / 16F);
calcinatorModel = new ModelCalcinator();
}
@Override
@ -46,17 +47,21 @@ public class ItemCalcinatorRenderer implements IItemRenderer {
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
float scale;
switch (type) {
case ENTITY: {
renderCalcinator(-0.5F, 0F, -0.5F);
scale = 1.0F;
renderCalcinator(-0.5F * scale, 0.0F * scale, 0.5F * scale, scale);
break;
}
case EQUIPPED: {
renderCalcinator(0F, 0.4F, 0F);
scale = 1.0F;
renderCalcinator(0.0F * scale, 0.0F * scale, 1.0F * scale, scale);
break;
}
case INVENTORY: {
renderCalcinator(1F, 0.65F, 1F);
scale = 1.0F;
renderCalcinator(0.0F * scale, -0.1F * scale, 1.0F * scale, scale);
break;
}
default:
@ -65,12 +70,15 @@ public class ItemCalcinatorRenderer implements IItemRenderer {
}
private void renderCalcinator(float x, float y, float z) {
private void renderCalcinator(float x, float y, float z, float scale) {
FMLClientHandler.instance().getClient().renderEngine.func_98187_b(Sprites.MODEL_CALCINATOR);
GL11.glPushMatrix(); //start
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glTranslatef(x, y, z); //size
calcinatorModel.render(0.0625F);
GL11.glRotatef(-90F, 1F, 0, 0);
calcinatorModel.render(Tessellator.instance, scale);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix(); //end
}
}

View file

@ -21,16 +21,12 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class TileEntityAludelRenderer extends TileEntitySpecialRenderer {
static final float scale = (float) (1.0 / 16.0);
//private ModelAludel modelAludel = new ModelAludel(scale);
private ModelAludel modelAludelObj = new ModelAludel();
private ModelAludel modelAludel = new ModelAludel();
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick) {
//modelAludel.render((TileAludel) tileEntity, x, y, z);
modelAludelObj.render((TileAludel) tileEntity, x, y, z);
modelAludel.render((TileAludel) tileEntity, x, y, z);
}
}

View file

@ -21,9 +21,7 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class TileEntityCalcinatorRenderer extends TileEntitySpecialRenderer {
static final float scale = (float) (1.0 / 16.0);
private ModelCalcinator modelCalcinator = new ModelCalcinator(scale);
private ModelCalcinator modelCalcinator = new ModelCalcinator();
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick) {

View file

@ -24,5 +24,6 @@ public class Reference {
public static final String SERVER_PROXY_CLASS = "com.pahimar.ee3.core.proxy.CommonProxy";
public static final String CLIENT_PROXY_CLASS = "com.pahimar.ee3.core.proxy.ClientProxy";
public static final int VERSION_CHECK_ATTEMPTS = 3;
public static final float MODEL_TEXTURE_OFFSET = 0.0002F;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB