Difference between revisions of "Dev:Bone Layer"

From Synfig Studio :: Documentation
Jump to: navigation, search
(Setup and animation)
m (Move section)
Line 99: Line 99:
  
 
<math> P'=P\cdot T\cdot R\cdot S_x\cdot R'\cdot T'=P\cdot B</math>
 
<math> P'=P\cdot T\cdot R\cdot S_x\cdot R'\cdot T'=P\cdot B</math>
 +
 +
=== Can Points (Bone influenced) be moved independently? ===
 +
 +
Yes, they should be. If not the animator is tight to only do the animation with the bones animation what would end to some insoluble problems during the animation. Considered this, the point position result comes from the addition of two terms:
 +
*(a) The movement of the point as described by the influence of the bone(s): P(B)
 +
*(b) The free movement of the point in the 2D space. P(animated)
 +
 +
In terms of the interface with the user, the value P(animated)is just obtained in this way:
 +
 +
#In any position of the time line (bones are animated) the point have a position given by the influence of the bones: P(B).
 +
#The user wrap a point, drags it, placing it at P'.
 +
#The final position of the point is P' but the user cannot modify the first term P(B) so the second term (b) becomes: P(animated)=P'-P(B).
  
 
===What happen if there are more than one bone affecting the point?===
 
===What happen if there are more than one bone affecting the point?===
Line 113: Line 125:
  
 
Where <math>w_k</math> is the weight for the bone ''k'' over the point P.
 
Where <math>w_k</math> is the weight for the bone ''k'' over the point P.
 
=== Can Points (Bone influenced) be moved independently? ===
 
 
Yes, they should be. If not the animator is tight to only do the animation with the bones animation what would end to some insoluble problems during the animation. Considered this, the point position result comes from the addition of two terms:
 
*(a) The movement of the point as described by the influence of the bone(s): P(B)
 
*(b) The free movement of the point in the 2D space. P(animated)
 
 
In terms of the interface with the user, the value P(animated)is just obtained in this way:
 
 
#In any position of the time line (bones are animated) the point have a position given by the influence of the bones: P(B).
 
#The user wrap a point, drags it, placing it at P'.
 
#The final position of the point is P' but the user cannot modify the first term P(B) so the second term (b) becomes: P(animated)=P'-P(B).
 
  
 
=== Skeleton ===
 
=== Skeleton ===

Revision as of 21:48, 21 November 2008

Initial seed for concepts

This portion of IRC logs sets the basis for the implementation of a Bone Layer. The interesting part is from 16:49 to 18:56.

Also this one has some interesting thoughts. From 8:20 to 14:43

Concepts

This is a not sorted list of concepts what I would write to let me clarify my self and also allow others to understand the next sections.

Bones intentions

Initial intention of Bones is attempt to emulate the skeleton of a vertebrate animal. In this way you have a skin and a skeleton. Skin is associated to the bones of the skeleton. When the skeleton moves the skin follows.

Application of bones in animation

In traditional animation produce a walk cycle implies draw each keyframe for the walk and maybe, depending on the walking speed, draw the in betweens too. To avoid to draw the in between images there comes the tweening animation programs (like synfig) to help the animator. Then the animator just need to draw the keyframes and the application would do the rest. That's quite good but in certain situations you see your self redrawing the same pose (with small variations) frequently at different times. Then the bones comes to help. They allow to to the animator in the following manner.

  • With the manipulation of a single object (or a set of them) you can manage a lot of points of the drawing definition.
  • Rotations of drawings using keyframes needs lots of them (by the nature that the tweening is defined in the x,y coordinates system and the rotation is performed in the angle, radius coordinate system). Using bones you can perform rotations of large angles with just two waypoints. As well as characters have limbs and limbs in living beings do mainly rotations, the usage of bones becomes handy in that kind of animations.
  • Once the character (or whatever thing that uses bones) is rigged (the skeleton structure is created and the relationship between the skin and it is set) it is possible to produce different kind of keyframes for different purposes: Walk, run, jump, sit, ...

How can we do implement this?

The relationship between the skeleton and the skin is in this way:

  • The Skin is made by Points and blines. Blines are defined by Points. Points are made of Vertexes and Tangents
  • Skeleton is made of bones and its relationship.
  • If Bones would have influence on the Vertexes and Tangents then the bones movements would move the points and therefore the skin would be moved.

That's the key, if we understand how does a bones has influence on a vertex and a tangent then we can find the way a skeleton can have influence over a skin.

Bones Properties

By my experience with bones in other 2D animation applications, watching its strong and weak points, the bones needs to have the following properties:

  • A bone has a origin place where the rotation is performed.
  • A bone has a length.
  • A bone has an angle with the horizontal.
  • A bone can have a region of influence.
  • A bone can have a parent bone and only one.
  • A bone can have one (or more) child(ren) bone(s).
  • A skeleton is defined as a connected set of bones (consisting of exactly one parentless bone and its children bones and their children...).

All the bones on a synfig Document can produce several skeletons (depending on how many parent-less bones are in it).

How does a Vertex move under the influence of a single Bone?

Conceptually a bone has influence over a point doing affine transformation of it position according to the bone values. See also transformation matrix. A bone produces rotation, scale and translation to a point in this way:

File:Bonesimulation.png

As you can see the values that produces the movement of the point P to the point P' are given by:

  • Translation of the bone: O'-O
  • Rotation of the bone: alpha'-alpha
  • Scale of the bone: s=length'/length

Then, given a Point P in the 2D space and known the translation, rotation and scale of the bone you can calculate the new point position P' using this formulation:

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle T(-O)=\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ -O_x & -O_y & 1 \end{bmatrix} } Translation to origin (0,0)

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle R(-alpha)=\begin{bmatrix} \cos(-alpha) & \sin(-alpha) & 0 \\ -\sin(-alpha) & \cos(-alpha) & 0 \\ 0 & 0 & 1 \end{bmatrix} } Rotate an angle of amount '-alpha' around the origin. That aligns the bone with the X axis

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle S_x(lenght'/lenght)=\begin{bmatrix} length'/length & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} } Scale a value of 's=length'/length' in the direction of X (the current direction of the bone).

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle R'(alpha)=\begin{bmatrix} \cos(alpha^') & \sin(alpha^') & 0 \\ -\sin(alpha^') & \cos(alpha^') & 0 \\ 0 & 0 & 1 \end{bmatrix} } Rotate an angle of amount 'alpha around the origin.

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle T'=\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ O^'_x & O^'_y & 1 \end{bmatrix} } Translation to new position O'

Then the transformation from P to P' is give by the matrix multiplication:

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle P'=P\cdot T(-O)\cdot R(-alpha)\cdot S_x(length'/lenght)\cdot R(alpha')\cdot T(O')}

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle P'=P\cdot T\cdot R\cdot S_x\cdot R'\cdot T'=P\cdot B}

Can Points (Bone influenced) be moved independently?

Yes, they should be. If not the animator is tight to only do the animation with the bones animation what would end to some insoluble problems during the animation. Considered this, the point position result comes from the addition of two terms:

  • (a) The movement of the point as described by the influence of the bone(s): P(B)
  • (b) The free movement of the point in the 2D space. P(animated)

In terms of the interface with the user, the value P(animated)is just obtained in this way:

  1. In any position of the time line (bones are animated) the point have a position given by the influence of the bones: P(B).
  2. The user wrap a point, drags it, placing it at P'.
  3. The final position of the point is P' but the user cannot modify the first term P(B) so the second term (b) becomes: P(animated)=P'-P(B).

What happen if there are more than one bone affecting the point?

The first thing you can think when you deal with more than one bone making influence over the same point is to calculate the average of the sum of the influences of all bones. So if there are N bones affecting to the point then we can think on sum all the resulting points from each bone and then divide the result by N to not scale the result.

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle B=\frac{\sum_{k=1}^N B_k}{N} }

Where Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle B_k} is the bone matrix for the bone k on the point P.

That's fine but I would like to have more control to the way the bones affects to the points. When you move a bone it looks reasonable that not all the points are influence in the same way. This can be solved by using "weighted" average instead of a plain one. That means give different amount of influence to one bone than to other.

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle B=\frac{\sum_{k=1}^N B_k \cdot w_k}{\sum_{k=1}^N w_k} }

Where Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle w_k} is the weight for the bone k over the point P.

Skeleton

A skeleton is a set of bones linked one to others in a tree hierarchy. A bone can have several children (or none) but only one parent (or none). This configuration allows to do a easy calculation of the forward kinematic (FK )of the chain and the inverse kinematic (IK) of the chain of bones. If the hierarchy were not tree type then the FK and IK can be not soluble.

For those IK and FK calculations it is good to have the bone referenced to its parent. So the parameters of the bone are described as relative to the parent bone. The parent bone defines a local coordinate system where the origin of the coordinate system lies on the Origin of the bone and the tip of the bone is pointing to the positive direction of the X axis.

Skeleton.png

As you can see in this image, each skeleton position and orientation is defined by the relative position of its immediate parent bone. In the diagram bone3 is a child of bone2 and bone 2 is a child of bone1. The bone 1 is the root parent bone but you can imagine it attached to a "master root bone" (defined by the origin of coordinates -red circumference- and the horizontal) so it can be said that the bone1 has its origin and angle defined relative to its "parent".

In this skeleton the three bones are parented in a linear way. But as you can imagine, following the rules stated for child-parent, a bone can have more than one child but not more than one parent. That means that defined a bone in the skeleton, there is only one sequence of parents to reach the root parent of the skeleton. Also it means too that one root bone defines one skeleton so each skeleton has only one root bone and only one.

Consider this: B3 is child of B2 and B2 is child of B1. Also B4 is child of B2 and B5 is child of B4. The way to travel from B5 to B1 is unique: B5->B4->B2->B1.

Setup and Animation

During the animation of the skeleton it is supposed that the position of each bone, its angle and its scale changes. Position and angle are relative to the parent bone, but scale is a value that calculates the current length of the bone compared with the "original" bone length (scale=length'(length) as you can see from the original formulas in the previous section. That means that the "original" bone length shouldn't be never zero, otherwise there will be a division by zero and the scale of the bone becomes infinite.

Also, the final position P' of a point that moves influenced by a single bone is given by the original point position relative to the bone in its "original" position (P).

What I'm trying to explain you is that it is needed that the setup of the bone (position, alpha and length) and the setup position of the point (P) to be moved would be given to calculate the final position of the point (P') given a moved position of the bone (position', alpha', length')

Calculate the position and angle of a bone in setup

If the bones are described using relative coordinates to its predecessor, the position Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \textstyle O^'_j} and the angle Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \textstyle \alpha^'_j} of the bone 'j' in relation to the "master root bone" (ie. the global coordinate system) is given by those equations:

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle O^'_j = O_j \cdot B_j}

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \alpha'_j = \sum_{i=j}^{root} \alpha_i}

where

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle B_j=\prod_{i=parent}^{root} B_i}

where 'i' goes form the parent of the bone 'j' and climbs up by one parent each time until it reaches the 'root' bone of the skeleton.

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle B_i = T(-O_i) \cdot R(-\alpha_i)}

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle B_i} is the inverse matrix transformation of the position of the bone relative to its immediate parent.