Jump to content

[SOLVED] Import .obj to my mod


kitsushadow

Recommended Posts

Hey, I have a custom model for an item that id like to render. All the tutorials i've found so far use techne. Seeing as i'm a linux user and wine isn't running techne I opted to use blender. I have exported the blender model as an obj file but i have no idea how to create the model class to import the model. I have the Item renderer class built and ready but i need to have the model class obviously to make it work.

 

Any suggestions or links to tutorials that show how to make the java file for an obj would be welcome.

 

Thanks

WORKING CODE

 

package com.kitsu.medievalcraft.renderer;

 

import org.lwjgl.opengl.GL11;

 

//import com.kitsu.medievalcraft.models.Model;

 

 

import com.kitsu.medievalcraft.item.weapon.ItemWoodenShield;

 

import net.minecraft.client.Minecraft;

import net.minecraft.entity.Entity;

import net.minecraft.item.ItemStack;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.client.IItemRenderer;

import net.minecraftforge.client.model.AdvancedModelLoader;

import net.minecraftforge.client.model.IModelCustom;

 

 

 

public class ItemRenderWoodenShield implements IItemRenderer {

 

public static final ResourceLocation WOODEN_SHIELD = new ResourceLocation("kitsumedievalcraft:models/woodenShieldObjectTriangle.obj");

public static final ResourceLocation woodenshield = new ResourceLocation("kitsumedievalcraft:models/woodenshield.png");

 

public IModelCustom model = AdvancedModelLoader.loadModel(WOODEN_SHIELD);

 

@Override

public boolean handleRenderType(ItemStack item, ItemRenderType type) {

 

switch(type) {

case EQUIPPED: {

return true;

}

case EQUIPPED_FIRST_PERSON: {

return true;

}

 

default: return false;

}

}

 

@Override

public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item,

ItemRendererHelper helper) {

 

return false;

}

 

@Override

public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

 

switch(type) {

 

case EQUIPPED: {

 

GL11.glPushMatrix();

GL11.glScalef(0.875F, 0.875F, 0.875F);

 

//ANGLE, X ROTATE, Y ROTATE, Z ROTATE

GL11.glRotatef(270F, 0.0F, 1.0F, 0.0F);

GL11.glRotatef(10F, 0.0F, 0.0F, -1.0F);

GL11.glRotated(90, 1.0, 0.0, 0.0);

 

GL11.glTranslatef(-0.35F, -1.5F, -0.55F);

 

Minecraft.getMinecraft().renderEngine.bindTexture(woodenshield);

model.renderAll();

 

GL11.glPopMatrix();

} break;

 

case EQUIPPED_FIRST_PERSON: {

if (ItemWoodenShield.woodenShieldInUse == true) {

GL11.glPushMatrix();

GL11.glScalef(1.0F, 1.0F, 1.0F);

 

//ANGLE, X ROTATE, Y ROTATE, Z ROTATE

 

//GL11.glRotatef(0F, 0.0F, 0.0F, 0.0F);

 

GL11.glRotated(-85, 1.0, 0.0, 0.0);

GL11.glRotated(50, 0.0F, 0.0F, 1.0F);

GL11.glRotated(3, 0.0F, 1.0F, 0.0F);

 

GL11.glTranslatef(0.9F, -0.9F, 0.9F);

//GL11.glTranslatef(-0.35F, -1.5F, -0.55F);

 

Minecraft.getMinecraft().renderEngine.bindTexture(woodenshield);

model.renderAll();

 

GL11.glPopMatrix();

}

} break;

 

default:

break;

}

}

 

 

}

 

Link to comment
Share on other sites

Think i got the model stuff in the right places but the model is not rendering. Here is what i have so far.

 

Item Renderer

 

 

package com.kitsu.medievalcraft.renderer;

 

import org.lwjgl.opengl.GL11;

 

import com.kitsu.medievalcraft.models.Model;

 

import net.minecraft.client.Minecraft;

import net.minecraft.entity.Entity;

import net.minecraft.item.ItemStack;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.client.IItemRenderer;

 

 

 

public class ItemRenderWoodenShield implements IItemRenderer {

 

protected Model model;

private ResourceLocation woodenshield = new ResourceLocation("kitsumedievalcraft:models/woodenshield.png");

 

public ItemRenderWoodenShield() {

model = new Model();

}

 

 

 

@Override

public boolean handleRenderType(ItemStack item, ItemRenderType type) {

 

switch(type) {

case EQUIPPED: return true;

default: return false;

}

 

}

 

@Override

public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item,

ItemRendererHelper helper) {

 

return false;

}

 

@Override

public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

 

switch(type) {

case EQUIPPED: {

GL11.glPushMatrix();

float scale = 1.5F;

Minecraft.getMinecraft().renderEngine.bindTexture(woodenshield);

GL11.glScalef(scale, scale, scale);

model.render();

 

 

 

GL11.glPopMatrix();

}

default:

break;

}

}

 

 

}

 

 

 

Item WoodenShield

 

 

package com.kitsu.medievalcraft.item.weapon;

 

import com.google.common.collect.HashMultimap;

import com.google.common.collect.Multimap;

import com.kitsu.medievalcraft.CustomTab;

import com.kitsu.medievalcraft.Main;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.SharedMonsterAttributes;

import net.minecraft.entity.ai.attributes.AttributeModifier;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.item.ItemSword;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.world.World;

 

public class ItemWoodenShield extends ItemSword {

 

public static boolean woodenShieldInUse;

 

public ItemWoodenShield(String unlocalizedName, ToolMaterial mat) {

super(mat);

this.setUnlocalizedName(unlocalizedName);

//this.setTextureName(Main.MODID + ":" + unlocalizedName);

setCreativeTab(CustomTab.MedievalCraftTab);

setMaxStackSize(1);

setMaxDamage(mat.getMaxUses());

setFull3D().isRepairable();

}

 

@Override

public int getItemEnchantability () {

return 0;

 

}

 

@Override

public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player) {

 

 

woodenShieldInUse = true;

 

return super.onItemRightClick(stack, world, player);

}

 

    @Override

    public boolean getIsRepairable(ItemStack item, ItemStack repair)

    {

        return Item.getItemFromBlock(Blocks.planks) == repair.getItem() ? true : false;

    }

 

 

 

}

 

 

 

Model Class

 

 

package com.kitsu.medievalcraft.models;

 

import net.minecraft.entity.Entity;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.client.model.AdvancedModelLoader;

import net.minecraftforge.client.model.IModelCustom;

 

public class Model {

 

public static Model instance = new Model();

 

private IModelCustom woodenShield;

 

public static final ResourceLocation WOODEN_SHIELD = new ResourceLocation("kitsumedievalcraft:models/woodenShieldObject.obj");

 

 

public Model() {

woodenShield = AdvancedModelLoader.loadModel(WOODEN_SHIELD);

}

 

public void render() {

woodenShield.renderAll();

}

 

 

 

}

 

 

 

 

Client Proxy

 

 

package com.kitsu.medievalcraft;

 

import net.minecraft.client.renderer.entity.RenderSnowball;

import net.minecraft.world.World;

import net.minecraftforge.client.IItemRenderer;

import net.minecraftforge.client.MinecraftForgeClient;

 

import com.kitsu.medievalcraft.entity.EntityShit;

import com.kitsu.medievalcraft.item.ModItems;

import com.kitsu.medievalcraft.renderer.ItemRenderWoodenShield;

 

import cpw.mods.fml.client.FMLClientHandler;

import cpw.mods.fml.client.registry.RenderingRegistry;

 

public class ClientProxy extends CommonProxy {

 

    @Override

    public void registerRenderer() {

   

   

   

    }

   

    public void registerItemRenderers() {

    MinecraftForgeClient.registerItemRenderer(ModItems.woodenShield, (IItemRenderer)new ItemRenderWoodenShield());

    }

   

    @Override

    public Object getClient() {

    return FMLClientHandler.instance().getClient();

    }

 

    @Override

    public World getClientWorld() {

    return FMLClientHandler.instance().getClient().theWorld;

    }

   

}

 

 

Link to comment
Share on other sites

To load an obj model you need an IModelCustom, and a ResourceLocation. You don't need a model class, that just over complicates things. You just put these in the ItemRenderer. You only need a model class if you are using techne, and also, not needed, but if you are using tessellators too.

 


public final ResourceLocation modelResource = new ResourceLocation("modid:yourModelLocation/yourModel.obj");
public final ResourceLocation texture = new ResourceLocation("modid:yourTextureLocation/yourTexture.png");

public IModelCustom model = AdvancedModelLoader.loadModel(modelResource);

public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
        GL11.glPushMatrix();
        Minecraft.getMinecraft().renderEngine.bindTexture(this.texture); //Not 100% sure if I got this right, but you bing the texture here.
        //Do all your GL11 rotations, scales, and translaters here...
        this.model.renderAll(); //Finally render the model
        GL11.glPopMatrix();
}

 

Hope this helped!

 

Also please note that your model HAS to be triangulated. If your model isn't triangulated, you will get a crash saying ModelFormatException.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

Okay, for that crash, there is a NullPointerException on line 19 of your model class. always make sure something is not null if there is the possibility for it to be. Unfortunately, I can't look at the code you put on bitbucket, I am on a school pc, and that website is blocked due to a security error. May you put the code in "code" and "/code" (with square brackets [ ]) annotations? that way I can see what you have changed.

 

As I said though, you don't need a model class, put it in the ItemRenderer.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

ok i tried what u suggested im getting a ModelFormatException error now

I did triangulate it.

Error parsing entry ('o Cylinder.002_Cylinder.003', line 4)

 

ItemRenderer Class

 

package com.kitsu.medievalcraft.renderer;

 

import org.lwjgl.opengl.GL11;

 

//import com.kitsu.medievalcraft.models.Model;

 

import net.minecraft.client.Minecraft;

import net.minecraft.entity.Entity;

import net.minecraft.item.ItemStack;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.client.IItemRenderer;

import net.minecraftforge.client.model.AdvancedModelLoader;

import net.minecraftforge.client.model.IModelCustom;

 

 

 

public class ItemRenderWoodenShield implements IItemRenderer {

 

//protected Model model;

 

/*public ItemRenderWoodenShield() {

model = new Model();

}*/

 

 

public static final ResourceLocation WOODEN_SHIELD = new ResourceLocation("kitsumedievalcraft:models/woodenShieldObject.obj");

public static final ResourceLocation woodenshield = new ResourceLocation("kitsumedievalcraft:models/woodenshield.png");

 

public IModelCustom model = AdvancedModelLoader.loadModel(WOODEN_SHIELD);

 

@Override

public boolean handleRenderType(ItemStack item, ItemRenderType type) {

 

switch(type) {

case EQUIPPED: return true;

//EQUIPPED_FIRST_PERSON

default: return false;

}

 

}

 

@Override

public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item,

ItemRendererHelper helper) {

 

return false;

}

 

@Override

public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

 

switch(type) {

case EQUIPPED: {

 

GL11.glPushMatrix();

 

Minecraft.getMinecraft().renderEngine.bindTexture(woodenshield);

this.model.renderAll();

 

GL11.glPopMatrix();

}

default:

break;

}

}

 

 

}

 

 

Error

http://pastebin.com/0i0BgURQ

 

 

Link to comment
Share on other sites

Well, if it isn't rendering, you either haven't bound the texture properly, or it is out of the players FOV, if you go into third person mode, can you see it? if not, the texture is not done properly, if so, you just need to use GL11 to translate it into the players view, and from there, you need to figure out the rotations and translations as no two models have the same translations/rotations.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

Well, if it isn't rendering, you either haven't bound the texture properly, or it is out of the players FOV, if you go into third person mode, can you see it? if not, the texture is not done properly, if so, you just need to use GL11 to translate it into the players view, and from there, you need to figure out the rotations and translations as no two models have the same translations/rotations.

 

 

Got It all working, thnx a lot for ur help

 

spoiler is broken again so

package com.kitsu.medievalcraft.renderer;

 

import org.lwjgl.opengl.GL11;

 

//import com.kitsu.medievalcraft.models.Model;

 

 

import com.kitsu.medievalcraft.item.weapon.ItemWoodenShield;

 

import net.minecraft.client.Minecraft;

import net.minecraft.entity.Entity;

import net.minecraft.item.ItemStack;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.client.IItemRenderer;

import net.minecraftforge.client.model.AdvancedModelLoader;

import net.minecraftforge.client.model.IModelCustom;

 

 

 

public class ItemRenderWoodenShield implements IItemRenderer {

 

public static final ResourceLocation WOODEN_SHIELD = new ResourceLocation("kitsumedievalcraft:models/woodenShieldObjectTriangle.obj");

public static final ResourceLocation woodenshield = new ResourceLocation("kitsumedievalcraft:models/woodenshield.png");

 

public IModelCustom model = AdvancedModelLoader.loadModel(WOODEN_SHIELD);

 

@Override

public boolean handleRenderType(ItemStack item, ItemRenderType type) {

 

switch(type) {

case EQUIPPED: {

return true;

}

case EQUIPPED_FIRST_PERSON: {

return true;

}

 

default: return false;

}

}

 

@Override

public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item,

ItemRendererHelper helper) {

 

return false;

}

 

@Override

public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

 

switch(type) {

 

case EQUIPPED: {

 

GL11.glPushMatrix();

GL11.glScalef(0.875F, 0.875F, 0.875F);

 

//ANGLE, X ROTATE, Y ROTATE, Z ROTATE

GL11.glRotatef(270F, 0.0F, 1.0F, 0.0F);

GL11.glRotatef(10F, 0.0F, 0.0F, -1.0F);

//GL11.glRotatef(30F, 0.0F, 0.0F, 1.0F);

GL11.glRotated(90, 1.0, 0.0, 0.0);

 

GL11.glTranslatef(-0.35F, -1.5F, -0.55F);

 

Minecraft.getMinecraft().renderEngine.bindTexture(woodenshield);

model.renderAll();

 

GL11.glPopMatrix();

} break;

 

case EQUIPPED_FIRST_PERSON: {

if (ItemWoodenShield.woodenShieldInUse == true) {

GL11.glPushMatrix();

GL11.glScalef(1.0F, 1.0F, 1.0F);

 

//ANGLE, X ROTATE, Y ROTATE, Z ROTATE

//GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);

GL11.glRotatef(0F, 0.0F, 0.0F, 0.0F);

//GL11.glRotatef(30F, 0.0F, 0.0F, 1.0F);

 

 

GL11.glRotated(-85, 1.0, 0.0, 0.0);

GL11.glRotated(50, 0.0F, 0.0F, 1.0F);

GL11.glRotated(3, 0.0F, 1.0F, 0.0F);

 

GL11.glTranslatef(0.9F, -0.9F, 0.9F);

//GL11.glTranslatef(-0.35F, -1.5F, -0.55F);

 

Minecraft.getMinecraft().renderEngine.bindTexture(woodenshield);

model.renderAll();

 

GL11.glPopMatrix();

}

} break;

 

default:

break;

}

}

 

 

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Slot deposit 3000 adalah situs slot deposit 3000 via dana yang super gacor dimana para pemain dijamin garansi wd hari ini juga hanya dengan modal receh berupa deposit sebesar 3000 baik via dana, ovo, gopay maupun linkaja untuk para pemain pengguna e-wallet di seluruh Indonesia.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT 3000 ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • OLXTOTO: Menikmati Sensasi Bermain Togel dan Slot dengan Aman dan Mengasyikkan Dunia perjudian daring terus berkembang dengan cepat, dan salah satu situs yang telah menonjol dalam pasar adalah OLXTOTO. Sebagai platform resmi untuk permainan togel dan slot, OLXTOTO telah memenangkan kepercayaan banyak pemain dengan menyediakan pengalaman bermain yang aman, adil, dan mengasyikkan. DAFTAR OLXTOTO DISINI <a href="https://imgbb.com/"><img src="https://i.ibb.co/GnjSVpx/daftar1-480x480.webp" alt="daftar1-480x480" border="0" /></a> Keamanan Sebagai Prioritas Utama Salah satu aspek utama yang membuat OLXTOTO begitu menonjol adalah komitmennya terhadap keamanan pemain. Dengan menggunakan teknologi enkripsi terkini, situs ini memastikan bahwa semua informasi pribadi dan keuangan para pemain tetap aman dan terlindungi dari akses yang tidak sah. Beragam Permainan yang Menarik Di OLXTOTO, pemain dapat menemukan beragam permainan yang menarik untuk dinikmati. Mulai dari permainan klasik seperti togel hingga slot modern dengan fitur-fitur inovatif, ada sesuatu untuk setiap selera dan preferensi. Grafik yang memukau dan efek suara yang mengagumkan menambah keseruan setiap putaran. Peluang Menang yang Tinggi Salah satu hal yang paling menarik bagi para pemain adalah peluang menang yang tinggi yang ditawarkan oleh OLXTOTO. Dengan pembayaran yang adil dan peluang yang setara bagi semua pemain, setiap taruhan memberikan kesempatan nyata untuk memenangkan hadiah besar. Layanan Pelanggan yang Responsif Tim layanan pelanggan OLXTOTO siap membantu para pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Dengan layanan yang ramah dan responsif, pemain dapat yakin bahwa mereka akan mendapatkan bantuan yang mereka butuhkan dengan cepat dan efisien. Kesimpulan OLXTOTO telah membuktikan dirinya sebagai salah satu situs terbaik untuk penggemar togel dan slot online. Dengan fokus pada keamanan, beragam permainan yang menarik, peluang menang yang tinggi, dan layanan pelanggan yang luar biasa, tidak mengherankan bahwa situs ini telah menjadi pilihan utama bagi banyak pemain. Jadi, jika Anda mencari pengalaman bermain yang aman, adil, dan mengasyikkan, jangan ragu untuk bergabung dengan OLXTOTO hari ini dan rasakan sensasi kemenangan!
    • Slot deposit dana adalah situs slot deposit dana yang juga menerima dari e-wallet lain seperti deposit via dana, ovo, gopay & linkaja terlengkap saat ini, sehingga para pemain yang tidak memiliki rekening bank lokal bisa tetap bermain slot dan terbantu dengan adanya fitur tersebut.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit dana adalah situs slot deposit dana minimal 5000 yang dijamin garansi super gacor dan gampang menang, dimana para pemain yang tidak memiliki rekening bank lokal tetap dalam bermain slot dengan melakukan deposit dana serta e-wallet lainnya seperti ovo, gopay maupun linkaja lengkap. Agar para pecinta slot di seluruh Indonesia tetap dapat menikmati permainan tanpa halangan apapun khususnya metode deposit, dimana ketersediaan cara deposit saat ini yang lebih beragam tentunya sangat membantu para pecinta slot.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit pulsa adalah situs slot deposit pulsa tanpa potongan apapun yang dijamin garansi terpercaya, dimana kamu bisa bermain slot dengan melakukan deposit pulsa dan tanpa dikenakan potongan apapun sehingga dana yang masuk ke dalam akun akan 100% utuh. Proses penarikan dana juga dijamin gampang dan tidak sulit sehingga kamu tidak perlu khawatir akan kemenangan yang akan kamu peroleh dengan sangat mudah jika bermain disini.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT PULSA TANPA POTONGAN ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.