Jump to content

[1.12.2] Problem with OBJ Model rendering


Darth

Recommended Posts

Hi gyus. I have really strange problem with model rendering.

 

If you look at the model at the first angle - everything is fine, but if you look under the second... I use TESR for render model. All code u can find above:

1:

Spoiler

1.thumb.png.36f1872a1ab05e4a25031d7d9ebf3814.png

2:

Spoiler

2.thumb.png.6e7123a4af2c1947784f7598addcdc30.png

3:

Spoiler

3.thumb.png.4f8ea59e7e24908b9c69abc1b49fdb4a.png

model:

Spoiler

Code:

Block:

Spoiler

package com.ancient.thaumicgadgets.blocks;

import java.util.Random;

import com.ancient.thaumicgadgets.init.ModBlocks;
import com.ancient.thaumicgadgets.objects.machines.eye.TileEntityEye;
import com.ancient.thaumicgadgets.util.Reference;

import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockEye extends BlockBase implements ITileEntityProvider
{

	private final String name;
	
	public BlockEye(String name) 
	{
		super(name, Material.GLASS);
		
		this.name = name;
		setSoundType(SoundType.GLASS);
		setHardness(4f);
		setResistance(30f);
		setLightOpacity(0);
		setHarvestLevel("pickaxe", 0);

	}

	@Override
	public TileEntity createNewTileEntity(World worldIn, int meta) 
	{
		return new TileEntityEye();
	}

	@Override
	public Item getItemDropped(IBlockState state, Random rand, int fortune) 
	{
		return Item.getItemFromBlock(ModBlocks.EYE);
	}
	
	@Override
	public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) 
	{
		return new ItemStack(ModBlocks.EYE);
	}

	@Override
	public EnumBlockRenderType getRenderType(IBlockState state) 
	{
		return EnumBlockRenderType.INVISIBLE;
	}
	
    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer()
    {
        return BlockRenderLayer.CUTOUT;
    }

	@Override
	public boolean isOpaqueCube(IBlockState state) 
	{
		return false;
	}
	
	@Override
	public boolean isFullCube(IBlockState state) 
	{
		return false;
	}

	@Override
	public void registerModels() 
	{
		ModelResourceLocation itemModel = new ModelResourceLocation(Reference.MOD_ID + ":" + this.name + ".obj");
		
		ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, itemModel);
	}
}

 

TileEntity:

Spoiler

package com.ancient.thaumicgadgets.objects.machines.eye;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.Vec3d;

public class TileEntityEye extends TileEntity implements ITickable
{

	public Vec3d vec = Vec3d.ZERO;
	
	public TileEntityEye()
	{
		
	}
	
	@Override
	public void update() 
	{
		if (world.isRemote)
		{
			EntityPlayer pl = Minecraft.getMinecraft().world.getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), 10, false);
			if (pl != null)
			{
				vec = new Vec3d(this.pos.getX() - pl.posX, this.pos.getY() - (pl.posY +  (pl.height / 2)), this.pos.getZ() - pl.posZ).normalize();
			}
			else
			{
				vec = Vec3d.ZERO;
			}
		}
	}

}

 

TESR:

Spoiler

package com.ancient.thaumicgadgets.objects.machines.eye;

import com.ancient.thaumicgadgets.util.IFunctionLibrary;
import com.ancient.thaumicgadgets.util.Reference;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.util.ResourceLocation;

public class RenderEye extends TileEntitySpecialRenderer<TileEntityEye>
{
	private float timer = 0f;
	private static final ResourceLocation modelLoc = new ResourceLocation(Reference.MOD_ID, "models/block/eye.obj");
	private static final IBakedModel model = IFunctionLibrary.loadModel(modelLoc);
	@Override
	public void render(TileEntityEye te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) 
	{

		double teX = te.getPos().getX();
		double teY = te.getPos().getY();
		double teZ = te.getPos().getZ();

		BlockRendererDispatcher brd = Minecraft.getMinecraft().getBlockRendererDispatcher();
		
		GlStateManager.pushMatrix();
		
		GlStateManager.color(1f, 1f, 1f, 1f);
		
		if (++timer > 7200)
		{
			timer = 0f;
		}
		
		GlStateManager.translate(x + 0.5d, y + (Math.sin(timer*0.05d)*0.1d) + 0.5d, z + 0.5d);
		GlStateManager.rotate((float) (te.vec.y * 180/Math.PI), 0, 1f, 0);
		GlStateManager.enableBlend();
		
		IBlockState state = te.getWorld().getBlockState(te.getPos());
		
		brd.getBlockModelRenderer().renderModelBrightness(model, state, 1.0f, false);
		
		GlStateManager.disableBlend();
		GlStateManager.popMatrix();
	}
}

 

 

Link to comment
Share on other sites

13 minutes ago, Darth said:

I use TESR for render model. All code u can find above:

Is the model going to be animated? If not dont use a TESR use the normal model system, forge adds support for obj models.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

3 hours ago, Darth said:

GlStateManager.rotate((float) (te.vec.y * 180/Math.PI), 0, 1f, 0);

This is not how vectors work. You need to get an angle between your vector and the default unitZ vector to get the rotation you need to apply around the Y axis.

 

As for your direct issue - you must bind the TextureMap.LOCATION_BLOCKS_TEXTURE before rendering your TE otherwise the last bound texture is used.

  • Like 1
Link to comment
Share on other sites

you should probably also te#getWorld#getTotalWorldTime() instead of your timer variable. If you need even more accuracy you can also add the partialTicks to the world time.

 

You might want to take a look at https://github.com/Cadiboo/WIPTechAlpha/blob/fc508e4dd439603888ca2caf08c0b871372764d4/src/main/java/cadiboo/wiptech/client/ClientUtil.java#L776-L801 for the trigonometry and at https://github.com/Cadiboo/WIPTechAlpha/blob/fc508e4dd439603888ca2caf08c0b871372764d4/src/main/java/cadiboo/wiptech/client/ClientUtil.java#L247-L292 for my use of it

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

On 9/2/2018 at 4:54 PM, Cadiboo said:

you should probably also te#getWorld#getTotalWorldTime() instead of your timer variable. If you need even more accuracy you can also add the partialTicks to the world time.

 

You might want to take a look at https://github.com/Cadiboo/WIPTechAlpha/blob/fc508e4dd439603888ca2caf08c0b871372764d4/src/main/java/cadiboo/wiptech/client/ClientUtil.java#L776-L801 for the trigonometry and at https://github.com/Cadiboo/WIPTechAlpha/blob/fc508e4dd439603888ca2caf08c0b871372764d4/src/main/java/cadiboo/wiptech/client/ClientUtil.java#L247-L292 for my use of it

Problem was with rendering, not with trigonometry, but thanks anyway.

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



×
×
  • Create New...

Important Information

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