Jump to content

Why is my model so large?


BananaBlighter

Recommended Posts

So I'm trying to make a parkour mod and part of it involves replacing the player model. I made a thread asking how to do this about a year and a half ago: (http://www.minecraftforge.net/forum/topic/40238-how-can-i-change-the-player-model/#comment-215772http://www.minecraftforge.net/forum/topic/40238-how-can-i-change-the-player-model/#comment-215772) and then I left modding for a while because I basically gave up and because I was busy with other stuff. Anyway, I came back to my mod a few days ago and finally figured out how to do it (also turns out Ernio was right and it was just my version of forge at the time), but for some reason my model has come out abnormally large (see the 1st attached image).

 

I figured there had to be some sort of scale factor to make it the same size as the regular player model, so I looked at the ModelPlayer class (and in the ModelBiped class) and in the constructor, a version of the addBox method that had a 7th argument for a scaleFactor was being used, whose value was being passed into the constructor as an argument called modelSize. So I looked at the RenderPlayer class and in the constructor they set 'new ModelPlayer(0.0F, useSmallArms)' as the mainModel. I thought it was a bit strange that they were using 0 as the so called 'scale factor', but I thought maybe the addBox method was just weird like that. So I tried using that version of the addBox method and using a scale factor similar to how it was done in the RenderPlayer class, and I of course set it to 0.

 

Turns out that was a stupid idea because setting it to 0 does nothing (they stay the same size) and it wouldn't work doing it like this anyway, because scaling each individual box doesn't scale the entire model as a whole (see the 2nd attached image - scale factor of 2). Now I know I could just scale the model using GlStateManager but I specifically want to scale it to the EXACT same size as the regular player model (I tried random values and just under 0.6 works pretty well, though the change in size is still noticeable when the model switches, which I don't want). I can't find where the scaling of the regular player model is taking place or if there even is a scale factor at play. It could just be I've done something terribly stupid that somehow ended up with my model being about 5/3 as large as it should be (which is more likely). If someone recognizes this issue and has any idea what is going on here, or knows what scale factor I can use to get it to the same size, then that would be greatly appreciated. I mean I probably could just find a value that's close enough through trial and error, but I'd rather know if there's something I've done wrong and how to properly fix it.

 

My rendering code:

public class ModelAssassin extends ModelBase
{
	public ModelRenderer body;
	public ModelRenderer head;
	public ModelRenderer rightShoulder;
	public ModelRenderer leftShoulder;
	public ModelRenderer rightForearm;
	public ModelRenderer leftForearm;
	public ModelRenderer rightThigh;
	public ModelRenderer leftThigh;
	public ModelRenderer rightFoot;
	public ModelRenderer leftFoot;
	public ModelRenderer nose;
	
	public int textureWidth = 0;
	public int textureHeight = 0;
	
	public ModelAssassin(float modelSize)
	{	
		body = new ModelRenderer(this, 0, 0);
		body.addBox(-4, -6, -2, 8, 12, 4, modelSize);
		body.setRotationPoint(0, 18, 0);
		body.setTextureSize(textureWidth, textureHeight);
		setRotation(body, 0, 0, 0);
		
		head = new ModelRenderer(this, 0, 0);
		head.addBox(-4, 0, -4, 8, 8, 8, modelSize);
		head.setRotationPoint(0, 6, 0);
		head.setTextureSize(textureWidth, textureHeight);
		body.addChild(head);
		setRotation(head, 0, 0, 0);
		
		rightShoulder = new ModelRenderer(this, 0, 0);
		rightShoulder.addBox(-4, -4, -2, 4, 6, 4, modelSize);
		rightShoulder.setRotationPoint(-4, 4, 0);
		rightShoulder.setTextureSize(textureWidth, textureHeight);
		body.addChild(rightShoulder);
		setRotation(rightShoulder, 0, 0, 0);
		
		leftShoulder = new ModelRenderer(this, 0, 0);
		leftShoulder.addBox(0, -4, -2, 4, 6, 4, modelSize);
		leftShoulder.setRotationPoint(4, 4, 0);
		leftShoulder.setTextureSize(textureWidth, textureHeight);
		body.addChild(leftShoulder);
		setRotation(leftShoulder, 0, 0, 0);
		
		rightForearm = new ModelRenderer(this, 0, 0);
		rightForearm.addBox(-2, -6, -2, 4, 6, 4, modelSize);
		rightForearm.setRotationPoint(-2, -4, 0);
		rightForearm.setTextureSize(textureWidth, textureHeight);
		rightShoulder.addChild(rightForearm);
		setRotation(rightForearm, 0, 0, 0);
		
		leftForearm = new ModelRenderer(this, 0, 0);
		leftForearm.addBox(-2, -6, -2, 4, 6, 4, modelSize);
		leftForearm.setRotationPoint(2, -4, 0);
		leftForearm.setTextureSize(textureWidth, textureHeight);
		leftShoulder.addChild(leftForearm);
		setRotation(leftForearm, 0, 0, 0);
		
		rightThigh = new ModelRenderer(this, 0, 0);
		rightThigh.addBox(-2, -6, -2, 4, 6, 4, modelSize);
		rightThigh.setRotationPoint(-2, -6, 0);
		rightThigh.setTextureSize(textureWidth, textureHeight);
		body.addChild(rightThigh);
		setRotation(rightThigh, 0, 0, 0);
		
		leftThigh = new ModelRenderer(this, 0, 0);
		leftThigh.addBox(-2, -6, -2, 4, 6, 4, modelSize);
		leftThigh.setRotationPoint(2, -6, 0);
		leftThigh.setTextureSize(textureWidth, textureHeight);
		body.addChild(leftThigh);
		setRotation(leftThigh, 0, 0, 0);
		
		rightFoot = new ModelRenderer(this, 0, 0);
		rightFoot.addBox(-2, -6, -2, 4, 6, 4, modelSize);
		rightFoot.setRotationPoint(0, -6, 0);
		rightFoot.setTextureSize(textureWidth, textureHeight);
		rightThigh.addChild(rightFoot);
		setRotation(rightFoot, 0, 0, 0);
		
		leftFoot = new ModelRenderer(this, 0, 0);
		leftFoot.addBox(-2, -6, -2, 4, 6, 4, modelSize);
		leftFoot.setRotationPoint(0, -6, 0);
		leftFoot.setTextureSize(textureWidth, textureHeight);
		leftThigh.addChild(leftFoot);
		setRotation(leftFoot, 0, 0, 0);
		
		nose = new ModelRenderer(this, 0, 0);
		nose.addBox(-1, -1, 0, 2, 2, 2, modelSize);
		nose.setRotationPoint(0,  4,  4);
		nose.setTextureSize(textureWidth, textureHeight);
		head.addChild(nose);
		setRotation(nose, 0, 0, 0);
	}
	
	@Override
	public void render(Entity entity, float time, float swingSuppress, float par4, float headAngleY, float headAngleX, float par7)
	{
		this.setRotationAngles(time, swingSuppress, par4, headAngleY, headAngleX, par7, entity);
		
		GlStateManager.pushMatrix();
		GlStateManager.scale(1, 1, 1);
		
		body.render(par7);
		
		GlStateManager.popMatrix();
	}
	
	@Override
	public void setRotationAngles(float time, float swingSuppress, float par3, float headAngleY, float headAngleX, float par6, Entity entity)
	{
		if(entity.posX != entity.prevPosX || entity.posZ != entity.prevPosZ)
		{
			this.setRotation(body, 0, -headAngleY, 0);
		}
		
		this.setRotation(head, headAngleX, -headAngleY - radToDeg(body.rotateAngleY), 0);
	}
	
	protected float degToRad(float degrees)
	{
		return degrees * (float) Math.PI / 180;
	}
	
	protected float radToDeg(float radians)
	{
		return radians * 180 / (float) Math.PI;
	}

	protected void setRotation(ModelRenderer model, float rotX, float rotY, float rotZ)
	{
		model.rotateAngleX = degToRad(rotX);
		model.rotateAngleY = degToRad(rotY);
		model.rotateAngleZ = degToRad(rotZ);
	}
}

 

public class RenderAssassin extends RenderLivingBase<AbstractClientPlayer>
{		
	public RenderAssassin()
	{
		super(Minecraft.getMinecraft().getRenderManager(), new ModelAssassin(0), (float) 0.5);
	}
	
	@Override
	protected ResourceLocation getEntityTexture(AbstractClientPlayer entity)
	{
		return null;
	}
	
	@Override
	public void doRender(AbstractClientPlayer entity, double x, double y, double z, float entityYaw, float partialTicks)
    {
        this.getMainModel().render(entity, 0, 0, entity.getAge(), entity.rotationYaw, entity.rotationPitch, (float) 0.1);
    }
}

 

public class RenderEventHandler
{
	public RenderAssassin renderAssassin = new RenderAssassin();
	
	@SubscribeEvent
	public void onPlayerRender(RenderPlayerEvent.Pre event)
	{
		if(event.getRenderer() instanceof RenderPlayer)
		{	
			AbstractClientPlayer player = (AbstractClientPlayer) event.getEntity();
			
			if(player.getCapability(CapabilityProvider.PROFILE_STATE, null).isHighProfile())
			{
				event.setCanceled(true);
				
				renderAssassin.doRender(player, event.getX(), event.getY(), event.getZ(), 0, 0);
				//System.out.println(player.rotationYaw + " , " + player.rotationPitch);
			}
		}
	}
}

 

2018-01-03_21.10.15.png

2018-01-03_21.49.20.png

Edited by BananaBlighter
Slight title change and added my code
Link to comment
Share on other sites

4 hours ago, LeoCTH said:

and your model's texture seems broken too...

idk

Well I haven't tried adding a texture yet. I just assumed that's how it looks when you don't add one. I mean I originally thought that it's meant to be pink and black but yeah I didn't think much of it when the texture came out like this.

Link to comment
Share on other sites

Such weird things often happen when you cancel rendering, my guess is that GL11 or the render engine still have some options enabled that cause this.

If you cancel overlay rendering for instance, the overlays suddenly go white. But I have no clue how to solve this, you should maybe look when and where  the event is posted or try to reflect anotherbiped model with applied rotations in.

Edited by ArmamentHaki
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.