Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Saturday, 30 December 2017

Blender & Unity: Manually Rigging Blender Humanoid Characters for use with Unity Mecanim


I'm definitely no character animator by trade, but there comes a time when you end up with a Unity project that somehow requires it. There are obviously many automatic rigging methods available (Blender does actually have an auto-Rigging system called Rigify for biped humanoids) and you could even try to download other rigs made by other people and plonk them into your scene, but I found that so many of the rigs including the rigify one seems to involve so many complicated bones you don't need, so you end up having to sift through the bones, deleting so many unwanted bones, renaming bones, perhaps even having the impression of the impossibility of rigging up them bones.

Although it may seem terrifying at the beginning (I'm not an animator or rigging specialist!), I found that surprisingly, it is not that difficult to manually rig up all your bones if what you have is a very simple humanoid character. You just need to be orderly and to stick with the admittedly tedious bone naming process. (Although our character is blobby, we're sticking with a humanoid as we're going to use it with the Kinect to sync it with the movement of the human user, and our human user is going to return a humanoid set of values that we'll need to rig up our character to...)



According to the Unity Blog's post on Mecanim Humanoid:

"The skeleton rig must respect a standard hierarchy to be compatible with our Humanoid Rig. The skeleton may have any number of in-between bones between humanoid bones, but it must respect the following pattern:"
Hips – Upper Leg – Lower Leg – Foot – Toes
Hips – Spine – Chest – Neck – Head
Chest – Shoulder – Arm – Forearm – Hand
Hand – Proximal – Intermediate – Distal



This is the list of all the bones you need (I found it useful to copy and paste in these names directly)

head
neck
collarbone.L
collarbone.R
upperArm.L
upperArm.R
lowerArm.L
lowerArm.R
hand.L
hand.R
chest
abdomen
hips
upperLeg.L
upperLeg.R
lowerLeg.L
lowerLeg.R
foot.L
foot.R
toes.L
toes.R

Optional: eye.L and eye.R

For starters: Ensure that your character model is positioned at origin and that its pivot point is also at origin (0,0,0). Make sure you reset the scale to 1 just in case (Ctrl+A, Select Scale). The hip bone is the key bone in all this, so start by creating one big bone starting from the bottom of hip to top of the chest. Hit Space and start typing "Subdivide Multi" (Armature) and give it 2 cuts so you get 3 bones. These will form the hips, abdomen and chest bone.



After you've done the main spine bones, you can turn on x-axis mirror.



- Select the ball on top of the bottom bone (hips bone). Make sure Options>Armature option>X-Axis Mirror is selected, then press Shift-E to extrude mirrored bones. When you're in mirror mode, every time you create a new bone, you'll have a second one mirrored on the other side of the X-Axis. Remember that you'll have to rename BOTH bones later on - if you are facing your model face-on, also remember that L is actually to the right and R is to the left, and name it accordingly.

- Arrange the leg bone into position (you may need uncheck "Connected" in order to let the leg bone go into the right position). Reposition the leg bones away from the hip. Subdivide Multi (1 cut) this leg bone into two bones, forming upperLeg and lowerLeg.

- Shift-E to extrude two more foot and toe bones, and also add in the collarbone, arms and neck+head bone. Do make sure you keep it all in a standing T-pose (as if the character is standing in the shape of the letter t).

- Ensure that all of your bones are renamed correctly as per the list. If there is an L bone there must always be a R bone.

- Go into Object Mode and Select first the character and then Shift select the armature. Press Ctrl+P and select Set Parent To - Armature Deform - With automatic weights. Your computer might lag for a second before its all connected up.



From there, you're in the home stretch. Export your Blender model in FBX format and then import it into Unity, and in Unity set the rig to humanoid (instead of generic) and at the bottom of that, hit Apply.

Let the wild rigging begin!



See also:
Animate Anything with Mecanim

Sunday, 4 August 2013

Simple Colour-changing Ambient Lamp (Arduino + 3 LED)

P8034922

In this continuation of posts on learning to do the most basic of things with the Arduino, the next experiment I made was a colour-changing lamp with 3 different LEDs. I followed this simple instructable but edited slightly. I noticed there were lots of "#define" in the instructable - it seems that #define is something from C that is for defining a constant. What is the difference between using #define and int to define which pins each LED is controlled via? Well in practice nothing much seems to be different except the conceptual difference is that #define is for defining a CONSTANT whereas technically speaking an int would be initialising a VARIABLE that can be changed later on in the program, although in this case we don't really intend to change the pin number. But we could, if we wanted to.

Things with # in front of them like #include and #define are preprocessed before the program compiles. Also, apparently #define does not take up any program space, whereas int is stored as variable in RAM. For more info see this wiki entry on C Preprocessor.

Colour Changing Lamp


For this you'll need: an arduino uno, 4 jumper wires, 3 LEDs of different colour, and 3 x 330ohm resistors

int delayTime = 2;
int maxBrightness = 255;
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
int red = 0;
int green = 170;
int blue = 170;

// Indicates whether a color will be incrementing (1) or decrementing (0) in brightness
int incR = 1;
int incG = 1;
int incB = 0;

void transition()
{
  if (red >= maxBrightness)
    incR = 0;
  else if (red <= 0)
    incR = 1;
  if (green >= maxBrightness)
    incG = 0;
  else if (green <= 0)
    incG = 1;
  if (blue >= maxBrightness)
    incB = 0;
  else if (blue <= 0)
    incB = 1;
  
  if (incR)
    red++;
  else
    red--;
  if(incG)
    green++;
  else
    green--;
  if(incB)
    blue++;
  else
    blue--;
}

void setColor()
{
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}

void setup()
{
  // do nothing
}

void loop()
{
  transition();
  setColor();
  delay(delayTime);
}
ambientled_bb

Stopping an Arduino Sketch

Now that you have this running, you might want to know how to make sketches stop. This baffled me for some time. My solution was eventually to create a blank sketch and to run it.
void setup(){}
void loop(){}

See also: Simple Light Meter (Arduino, Photocell and Servo)