Difference between revisions of "Dev:Bone Layer"

From Synfig Studio :: Documentation
Jump to: navigation, search
(How does a Vertex move under the influence of a single Bone?: fix scale formula)
(How does a Vertex move under the influence of a single Bone?: Finnaly I fixed the formula)
Line 50: Line 50:
 
As you can see the values that produces the movement of the point P to the point P' are given by:
 
As you can see the values that produces the movement of the point P to the point P' are given by:
  
* O'-O
+
*Translation of the bone: O'-O
* alpha'-alpha
+
*Rotation of the bone: alpha'-alpha  
* length'/lenght - 1
+
 
+
In other words, what has produces the movement form P to P' is the values:
+
 
+
*Translation of the bone: t=O'-O
+
*Rotation of the bone: a=alpha'-alpha
+
 
*Scale of the bone: s=length'/length
 
*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:
 
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:
 +
 
<math>
 
<math>
T=\begin{bmatrix}
+
T(-O)=\begin{bmatrix}
 
1 & 0 & 0 \\
 
1 & 0 & 0 \\
 
0 & 1 & 0 \\
 
0 & 1 & 0 \\
Line 70: Line 65:
  
 
<math>
 
<math>
S=\begin{bmatrix}
+
R(-alpha)=\begin{bmatrix}
s\cdot\cos(alpha) & 0 & 0 \\
+
\cos(-alpha) & \sin(-alpha) & 0 \\
0 & s\cdot\sin(alpha) & 0 \\
+
-\sin(-alpha) & \cos(-alpha) & 0 \\
 +
0 & 0 & 1
 +
\end{bmatrix}
 +
</math> Rotate an angle of amount '-alpha' around the origin. That aligns the bone with the X axis
 +
 
 +
<math>
 +
S(lenght'/lenght)=\begin{bmatrix}
 +
length'/length & 0 & 0 \\
 +
0 & 1 & 0 \\
 
0 & 0 & 1
 
0 & 0 & 1
 
\end{bmatrix}
 
\end{bmatrix}
  </math> Scale a value of 's' in the direction of the bone (alpha) form the origin.
+
  </math> Scale a value of 's=length'/length' in the direction of X (the current direction of the bone).
  
 
<math>
 
<math>
A=\begin{bmatrix}
+
R(alpha)=\begin{bmatrix}
\cos(a) & \sin(a) & 0 \\
+
\cos(alpha^') & \sin(alpha^') & 0 \\
-\sin(a) & \cos(a) & 0 \\
+
-\sin(alpha^') & \cos(alpha^') & 0 \\
 
0 & 0 & 1
 
0 & 0 & 1
 
\end{bmatrix}
 
\end{bmatrix}
  </math> Rotate an angle of amount 'a' around the origin.
+
  </math> Rotate an angle of amount 'alpha'' around the origin.
  
 
<math>
 
<math>
Line 95: Line 98:
 
Then the transformation from P to P' is give by the matrix multiplication:
 
Then the transformation from P to P' is give by the matrix multiplication:
  
<math> P'=P\cdot T\cdot S\cdot A\cdot V</math>
+
<math> P'=P\cdot T(-O)\cdot R(-alpha) S_x(length'/lenght)\cdot R(alpha')\cdot T(O')</math>

Revision as of 02:13, 16 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, ...

OK, cool, but how can we do this in synfig?

Before we research how to do that in synfig, first let's see how is it done in a abstract mode. 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.

Features of bones

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

  • 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 has 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).

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(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 V=\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) S_x(length'/lenght)\cdot R(alpha')\cdot T(O')}