FANDOM


2013-06-10 17.57.24
Finally, you've reached the part to make the model! But before making the animations, a few specific things need to be made in the model. Again, it's recommended to have a sufficient knowledge of modeling in code in contrast to just making models in Techne.


Starting the Model

Let's start out by making a simple model called ModelTest. We'll give it a body and a head:

public class ModelTest extends ModelBase {
	
	public ModelRenderer body, head;
	
	public static final float PI = (float)Math.PI;
	
	public ModelTest() {
		body = new ModelRenderer(this, 32, 0);
		body.addBox(-3F, -10F, -3F, 6, 10, 6);
		body.setRotationPoint(0F, 24F, 0F);
		head = new ModelRenderer(this, 0, 0);
		head.addBox(-4F, -8F, -4F, 8, 8, 8);
		head.setRotationPoint(0F, -10F, 0F);
		body.addChild(head);
	}
	
	public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
		animate((IAnimatedEntity)entity, f, f1, f2, f3, f4, f5);
		body.render(f5);
	}
	
	public void setAngles() {
	}
	
	public void animate(IAnimatedEntity entity, float f, float f1, float f2, float f3, float f4, float f5) {
		setAngles();
	}
}

This is what a typical model should look like. Since our model is simple enough that no rotations need to be made by default, the method setAngles() is left empty. If your model is more complicated, remember to reset the angles in setAngles(). The animate method is tick method where all the animation code will be written later. The PI is just a float reference for PI (3.1415926....), which is useful for angles.

Adding the Animator

So far, what you've done is fairly simple. Next, you need to add the Animator into the model. The Animator is basically the class that handles the animations you give it. It helps rotate the boxes when required, and stuff like that. To add in the animator, create a field for it and initialize it in the constructor:

private Animator animator;
public ModelTest() {
	body = new ModelRenderer(this, 32, 0);
	body.addBox(-3F, -10F, -3F, 6, 10, 6);
	body.setRotationPoint(0F, 24F, 0F);
	head = new ModelRenderer(this, 0, 0);
	head.addBox(-4F, -8F, -4F, 8, 8, 8);
	head.setRotationPoint(0F, -10F, 0F);
	body.addChild(head);
	
	//initialize; it takes a ModelBase instance as a parameter
	animator = new Animator(this);
}

Next, the animator has to be constantly linked with the model, so call the Animator's update method in the animate method before setAngles():

public void animate(IAnimatedEntity entity, float f, float f1, float f2, float f3, float f4, float f5) {
	animator.update(entity);
	setAngles();

}

Animator.update() is an important method because it resets most of the temporary animation data. Since one model is shared among many entities, we don't want data from the previous entity to affect the other entity's animations. Also, this method resets all of the boxes' rotations to 0, so it's important to put setAngles() after animator.update(entity).

That's enough to have the basic model working! To link the entity with the model, you can create your own render class, or just simply use RenderLiving in your ClientProxy with this line:

RenderingRegistry.registerEntityRenderingHandler(EntityTest.class, new RenderLiving(new ModelTest(), 0.25F));

Finishing Up

At this point, you can test and make sure everything's working. You should have everything except the actual animations. Your ModelTest should look something like the source below. Go on to Step 5: Animating the Model!

ModelTest.java

public class ModelTest extends ModelBase {
	
	public ModelRenderer body, head;
	private Animator animator;
	
	public static final float PI = (float)Math.PI;
	
	public ModelTest() {
		body = new ModelRenderer(this, 32, 0);
		body.addBox(-3F, -10F, -3F, 6, 10, 6);
		body.setRotationPoint(0F, 24F, 0F);
		head = new ModelRenderer(this, 0, 0);
		head.addBox(-4F, -8F, -4F, 8, 8, 8);
		head.setRotationPoint(0F, -10F, 0F);
		body.addChild(head);
		
		animator = new Animator(this);
	}
	
	public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
		animate((IAnimatedEntity)entity, f, f1, f2, f3, f4, f5);
		body.render(f5);
	}
	
	public void setAngles() {
	}
	
	public void animate(IAnimatedEntity entity, float f, float f1, float f2, float f3, float f4, float f5) {
		animator.update(entity);
		setAngles();
	}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.