Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

41
Copyright © 2015 Curt Hill Models and Textures Making your entity interesting

Transcript of Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Page 1: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Copyright © 2015 Curt Hill

Models and Textures

Making your entity interesting

Page 2: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Introduction• Single cubes are not impressive• Rather we wish to build up our

entity with a series a various sized cubes to go with the cubist theme

• We have to be able to:– Size them– Place them– Connect them– Texture them

• First the coordinate system

Copyright © 2015 Curt Hill

Page 3: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Coordinate System• You should all be familiar with

Cartesian coordinates– X is left right– Y is up down

• This is not enough for a 3D space• We need X, Y, Z

– This is the order we always specify them

• However, it is not the extension we would expect

Copyright © 2015 Curt Hill

Page 4: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

3D Coordinates• In this coordinate system, the

Cartesian plane is turned 90° rotating on the Y axis:

• X comes out of the screen toward us– Positive is moving towards the viewer

• Y is up-down– Positive is down

• Z is left-right– Positive moves towards the right

Copyright © 2015 Curt Hill

Page 5: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Pixels• The units of position, size and

other things are always in pixels– Size must be an integer– Position may be fractional, so a float

• The Minecraft pixel is not the screen pixel

• A block is a cube 16 pixels on a side

• If we have a 32 by 32 texture each Minecraft pixel gets four texture pixels

Copyright © 2015 Curt Hill

Page 6: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Coordinate Zero

• In some sense the X and Z zero points are relative– Thus we do not care

• The Y zero point is 23 pixels above the surface

• Thus the Y zero is about a block and half above the floor

Copyright © 2015 Curt Hill

Page 7: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Coordinate Diagram

Copyright © 2015 Curt Hill

Page 8: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Box Creation

• As we saw in previous presentation the box is created by the addBox method– This is a method of the

ModelRenderer object

• Each box will have an addBox call that sizes and positions it

Copyright © 2015 Curt Hill

Page 9: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Unit Cube

Copyright © 2015 Curt Hill

public class CurtCubeModel extends ModelBase{ public ModelRenderer body; public CurtCubeModel(){ body = new ModelRenderer(this,20,0); body.addBox(0F,0F,0F,1,1,1); body.setRotationPoint(.5F,.5F,.5F);}

Page 10: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

The addBox• The first three parameters are floats

– These are the X, Y, Z positions respectively

• The second three parameters are integers in pixels– Again X, Y, Z respectively– These determine size

• The zero Y will make this thing float in the air– Normally it would have legs or some such

support

Copyright © 2015 Curt Hill

Page 11: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Produces This

Copyright © 2015 Curt Hill

Page 12: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Commentary

• The unit cube is somewhat in front of the back wall and the camera is above it

• Therefore it looks like it is more like 16-18 Minecraft pixels from the floor

Copyright © 2015 Curt Hill

Page 13: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

One More Time

• What does the setRotationPoint do?

• Describes the center of the object• When the entity turns it rotates

around this location• By default this becomes 0,0,0

which is a corner• We will now drop the cube to the

floor

Copyright © 2015 Curt Hill

Page 14: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Down To Earth

Copyright © 2015 Curt Hill

@SideOnly(Side.CLIENT)public class CurtCubeModel extends ModelBase{ public ModelRenderer body; public CurtCubeModel(){ body = new ModelRenderer(this, 0, 0); body.addBox(0F,22.5F,0F,1,1,1); body.setRotationPoint(.5F,.5F,.5F); }

Page 15: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Floored

Copyright © 2015 Curt Hill

Page 16: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Commentary• Since the center is set by

setRotationPoint to the cube’s midpoint we must set the Y to 22.5 rather than 23– Otherwise half the cube is below the

floor

• Typically the main body of an entity is the middle of a cube

• Appendages usually specify the joint location– That is where we want it to rotate, not

the middle

Copyright © 2015 Curt Hill

Page 17: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

addBox Again• The positional parameters define a

corner• The three integers do not define sizes

but distances to travel from the corner– Thus they may also be negative

• Thus we cannot determine which corner the positions specify until we look

• If the Y integer is negative then the positions determine a bottom corner

Copyright © 2015 Curt Hill

Page 18: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

addBox Again

• We typically want to center the X and Z values and make the Y the height

• Thus if X size is 8 we often make the X position -4– The X then varies from -4 to 4

• If we do this then the item falls into the middle of its shadow

Copyright © 2015 Curt Hill

Page 19: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Interlude

• Now we can size and place multiple pieces

• Now we have to connect them• The Minecraft method is addChild• A child maintains its spatial

relationship with the parent as Minecraft moves the parent

Copyright © 2015 Curt Hill

Page 20: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Modeling • Two common approaches: • The first is to just build the thing in

Java code• The second is to build it with Techne

and then import the results into Minecraft– http://techne.zeux.me/

• I will do the first– You are free to do either– However, you still need to know the

connection thing

Copyright © 2015 Curt Hill

Page 21: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Example• My example will to make an Emu

like entity• It will contain a body, two legs,

head and neck• When that part works we will

animate the legs and head• Three classes:

– CurtEmu– CurtModelEmu– CurtRenderEmu

Copyright © 2015 Curt Hill

Page 22: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Process• It is easy to mess this up, so you

should use an incremental approach• Get one thing right, then add the

next– Alas, 30 second compiles slow things

• After modeling is right, animate• You may do textures before or after

animation• I will now abandon the CurtCube

and start developing the CurtEmu

Copyright © 2015 Curt Hill

Page 23: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Directionality

• Minecraft must guess as to which end of your entity is front

• The guess it makes is that it is always facing the negative Z direction

• Thus for a cow the Z dimension will be larger than the X dimention

• A crab would be the reverse

Copyright © 2015 Curt Hill

Page 24: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Connection• We would like several pieces that

move as one• This is most easily done with the

addChild method• Each new piece becomes a child of

an existing piece• Typically start at the most

important or bulkiest piece and work outward

• For the Emu the body is the center

Copyright © 2015 Curt Hill

Page 25: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Body

Copyright © 2015 Curt Hill

public ModelRenderer body; public ModelRenderer leg1; public ModelRenderer leg2; public ModelRenderer neck; public ModelRenderer head;… body = new ModelRenderer(this, 0, 0);body.addBox(-3F,10F,-1.5F,3,-3,6); body.setRotationPoint(0F, 8.5F, 0F);

Page 26: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Observations

• The body will be 3 by 3 by 6– The Z is the longest dimension

• It will be positioned 10 pixels from ground

• Y size is negative so bottom corner is origin

• The Y value of 10 puts the body in the air

Copyright © 2015 Curt Hill

Page 27: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

One more time with addBox

• The coordinates for children are different than the parent

• The parent’s position is relative to the coordinate system

• The child’s position is relative to the parent

• Of course we cannot tell until we do the addChild

Copyright © 2015 Curt Hill

Page 28: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

The addChild method

• Takes only one parameter:parent.addChild(child);

• See the example in next screen and observe that the new item is relative to the old

Copyright © 2015 Curt Hill

Page 29: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Apply the neck

Copyright © 2015 Curt Hill

body = new ModelRenderer(this, 0, 0);body.addBox(-3F, 10F, -1.5F, 3, -3, 6);body.setRotationPoint(0F, 8.5F, 0F); neck = new ModelRenderer(this, 0, 0);neck.addBox(-2F, 2F, 0F, 1, 5, 1);neck.setRotationPoint(0F, 0F, 0F);body.addChild(neck);

Notice the 0F for Y position – relative to the body not the regular coordinate system

Page 30: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

The Rest

• The legs go below and attach to the body– We will not put feet on the legs, but

could

• The head attaches to the neck• Thus a child may also have

children

Copyright © 2015 Curt Hill

Page 31: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Rest of Body

Copyright © 2015 Curt Hill

head = new ModelRenderer(this, 0, 0);head.addBox(0F, 2F, 0, -1, -1, -3);head.setRotationPoint(-1F, 0F, 1F);neck.addChild(head); leg1 = new ModelRenderer(this, 0, 0);leg1.addBox(-3F, 5F, 0F, 1, 6, 1);leg1.setRotationPoint(0F, 5F, 0F);body.addChild(leg1);

leg2 = new ModelRenderer(this, 0, 0);leg2.addBox(-1.0f, 5F, 0F, 1, 6, 1);leg2.setRotationPoint(0F, 5F, 0F);body.addChild(leg2);

Page 32: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Doofuss Bird

Copyright © 2015 Curt Hill

Page 33: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Modeling Summary

• Not an awful lot of science• Create your boxes and attach

them• The addBox, setRotationPoint and

addChild are the most important now

• The rotation point becomes more important as we animate

Copyright © 2015 Curt Hill

Page 34: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Rotation Point

• The animation process works better if the rotation point is properly set relative to the addBox positions

• I found at least three combinations of addBox, setRotationPoint settings that made the head sit properly on the neck

• Only one of them allowed proper turning of the head on the neck

Copyright © 2015 Curt Hill

Page 35: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Textures Again• The textures are not applied in the

modeler, but the renderer– CurtModelEmu and CurtRenderEmu

respectively

• Rather there is just one texture and it must be used by all parts– This may have changed before or

after 1.7 for I have seen other ways

• The trick then is to use offsets in a single png file

Copyright © 2015 Curt Hill

Page 36: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

ModelRenderer• The constructor comes in several

forms• First parameter is always the parent

ModelBase– In most of our code that will be this– A self reference

• One– Second parameter is a string name

• Other– Second and third are offsets

Copyright © 2015 Curt Hill

Page 37: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Three Parameter

• Signature ModelRenderer( ModelBase m, int xoffset, int yoffset);

• Example:body = new ModelRenderer( this,300,300);

• We will see this in the next screens

Copyright © 2015 Curt Hill

Page 38: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

The Graphic

Copyright © 2015 Curt Hill

• This is a 512 by 512 png file

Page 39: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Textured

Copyright © 2015 Curt Hill

Page 40: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Interlude• Minecraft only moves the main

object• It does this based on what it thinks is

front• It moves in a semi-random motion• Now we want to move the legs, when

Minecraft moves the whole item• We will see this in an animation

presentation

Copyright © 2015 Curt Hill

Page 41: Copyright © 2015 Curt Hill Models and Textures Making your entity interesting.

Conclusion

• We construct the structure from rectanguloid boxes– addBox determines size and position– The setRotationPoint determines

“center”

• We connect them with addChild• Textures are applied in the

renderer• Next: On to animation

Copyright © 2015 Curt Hill