Difference between revisions of "Doc:Following a Spline"

From Synfig Studio :: Documentation
Jump to: navigation, search
m (started with a copy of "Following a BLine (the old way)")
m (updated to use the newer way of linking things up)
Line 26: Line 26:
  
 
* [[Following a BLine#Create the Layers|Draw a curve and an arrow]]
 
* [[Following a BLine#Create the Layers|Draw a curve and an arrow]]
* [[Following a BLine#Make the Arrow Move|Link the arrow's Origin]] to the curve's Vertices' vector position so the arrow follows the curve
+
* [[Following a BLine#Make the Arrow Move and Rotate|Link the arrow's Origin and Rotation]] to the bline so the arrow follows the curve
* [[Following a BLine#Make the Arrow Rotate|Link the arrow's Rotate layer]] to the curve's Vertices' tangent so the arrow rotates with the curve
+
  
 
== Tutorial ==
 
== Tutorial ==
Line 36: Line 35:
  
 
File > New
 
File > New
 
Time tab > End Time > 10s > OK
 
  
 
=== Create the Layers ===
 
=== Create the Layers ===
Line 47: Line 44:
 
draw a bline that you want the arrow to move along
 
draw a bline that you want the arrow to move along
  
select the new bline layer, go to its parameters
+
click the "Make BLine" icon in the bottom left of the "Tool Options" panel to create the bline.
  
right-click on the vertices parameter and "export" it
+
still in the bline tool, enable Fill and Outline checkboxes in tool options
it will ask for a name.
+
  
you can use whatever name you like but for this tutorial I'm calling it "path"
+
draw an arrow or whatever, pointing to the right
  
(note that you could have checked the 'auto export' box in the draw tool, and set the name in the text box at the top of the tool options to save having to chose export from the menu - it doesn't matter which you use)
+
switch to the "Normal" tool
 
+
switch back to the 'Normal' tool and look in the "Children" dialog.
+
 
+
expand the ValueBase Nodes and you'll see all the things that have been exported.
+
 
+
selecting them will allow us to re-use them elsewhere in the animation later
+
 
+
back in the bline tool, enable Fill and Outline checkboxes in tool options
+
 
+
draw an arrow or whatever, pointing to the right
+
  
 
select the outline, hit control-a to select all its ducks except the green position duck
 
select the outline, hit control-a to select all its ducks except the green position duck
Line 73: Line 59:
  
 
encapsulate the rotate, outline, and region layers
 
encapsulate the rotate, outline, and region layers
 
rename the encapsulation layer "arrow"
 
  
 
so now you've got 2 top-level layers: a curved path, and an encapsulation containing an arrow and a rotate layer
 
so now you've got 2 top-level layers: a curved path, and an encapsulation containing an arrow and a rotate layer
  
=== Make the Arrow Move ===
+
=== Make the Arrow Move and Rotate ===
  
select the "arrow" encapsulation layer
+
select the "arrow" encapsulation layer by clicking it in the Layers panel
  
we want this layer to move along the "path" bline.  the Origin parameter of an encapsulation layer can be used to move everything it contains
+
select its green position duck by clicking on it in the canvas window
right-click the Origin parameter and select [[Convert#BLine_Vector|Convert > BLine Vertex]]
+
the Origin parameter will now be expandable - click the small triangle to its left to expand it
+
  
the Origin of the "arrow" layer is now defined by 3 sub parameters: a BLine, the amount to travel along the BLine, and a checkbox that we'll ignore for now.
+
additionally select the Rotate layer by holding Control and clicking it in the Layers panel
in the Children dialog, select the "path" ValueNode
+
  
then in the Params dialog, right-click on the "arrow" layer's BLine sub-parameter and "Connect" it to the selected "path" value
+
additionally select the blue "rotation amount" duck by holding Control and clicking on it in the canvas window
  
the arrow will move so that it is about half-way along the BLine path (because the Amount sub-parameter defaults to 0.5).
+
so now we should have 2 layers selected, and one duck from each of those 2 layers selected
  
edit the Amount sub parameter to 0 and to 1, and see the arrow moves to one end of the path and then the other.
+
now additionally select the curved bline layer (it should be the last layer in the Layer panel's list) by holding Control and clicking on it
  
the "Loop" sub parameter determines what happens if you use a value outside the range 0-1 for the Amount.  If "Loop" isn't checked, values less than 0 count as 0 and values greater than 1 count as 1.  If "Loop" is checked, the value wraps around, so Amounts of 2.4, 1.4, 0.4, -0.6, -1.6, etc all act the same.
+
right-click on the dotted line that indicates the position of the curved bline - not on any duck, but on the dotted link between ducks
  
So we've got the arrow moving along the line, but only if we manually edit the Amount parameter.  Let's get it to move automatically, by converting the constant Amount parameter into a linearly changing value.
+
from the context menu that pops up, select "Link to BLine"
  
Right-click the Amount parameter, and Convert it to Linear.  This adds sub parameters Rate (how fast the value goes up, per second) and Offset (what value it has at time zero).
+
the encapsulated arrow should move so that its green position duck is on the bline, and it should rotate so that the arrow points along the bline at that point
  
Set Rate to 0.1 and Offset to 0That will make the value of Amount be 0 at time 0 and 1 at time 10s, so the arrow will move from one end of the line to the other throughout the course of the animation.
+
select just the encapsulation layer, and drag its green duck aroundyou'll see that the duck is constrained now to lie on the bline, and that dragging it also affects the rotation of the arrow as expected
  
This linearly changing value of the Amount parameter will be useful later on, so let's export it into the Children dialog so we can find it easily later.  Right-click the Amount parameter and Export it as "engine"I call it "engine" because this is the parameter that drives the animation.
+
we can now animate the arrowturn on "animate edit mode" by clicking the icon in the bottom right of the canvas window.
  
Try File > Preview or View > Play to watch the animation.  If you like, play with the sub-parameters - turn the Rate up to 0.25 and turn on the Loop checkbox and watch the preview again.  You'll see that the arrow moves 3 times faster than before, reaching the end of the line after 4 seconds.
+
at time 0f, drag the encapsulation layer's green position duck to one end of the bline
  
Turning Loop on means that it will then reappear at the start of the line, and keep moving.  Not having Loop on would make it stay at the end of the line until the animation stopped.
+
at time 5s, drag the same position duck to the other end of the bline
  
Note that instead of using a Convert>Linear conversion to get the Amount sub-parameter to change over time, we could have used the more traditional method of turning on [[Animate Editing Mode]] and adjusting the parameter at different points in time.  Either way, we can still export the Amount parameter so that we can use it again in the next step.
+
Try File > Preview or View > Play to watch the animation.
 
+
=== Make the Arrow Rotate ===
+
 
+
You'll notice that although the arrow moves along the line, it doesn't rotate to face the direction of travel.  But that's what we're going to use the Rotate layer for.
+
 
+
Open up the "arrow" encapsulation layer and select the Rotate layer inside. 
+
 
+
Right-click the Amount parameter, which specifies the amount to rotate, and Convert it to type [[Convert#BLine Tangent|BLine Tangent]].
+
 
+
Open up the sub parameters, select the "path" value in the children dialog, and connect it to the rotate layer's BLine sub-parameter, and select the "engine" value in the children dialog and connect it to the rotate layer's Amount sub-parameter.
+
 
+
Now watch the preview and you'll see that the arrow is moving along the line, rotating to face the way it's traveling.
+
  
 
== Results ==
 
== Results ==
Line 128: Line 97:
  
 
== Commentary on the Feature ==
 
== Commentary on the Feature ==
 
I've noticed that if Loop is on, and amount is 1.0, then it acts as if amount is 0.0, ie. the arrow jumps back to the beginning of the line in the last frame.
 
  
 
Also, the arrow takes the same time to move along each segment of the bline.  So if there's a long straight part then a bendy complex part, the arrow will move much faster along the straight parts (since there will be less vertices in that part).
 
Also, the arrow takes the same time to move along each segment of the bline.  So if there's a long straight part then a bendy complex part, the arrow will move much faster along the straight parts (since there will be less vertices in that part).
  
 
It would be good to have the option of having the arrow move at constant speed along the length of the curve.
 
It would be good to have the option of having the arrow move at constant speed along the length of the curve.

Revision as of 21:18, 30 March 2008

Languages Language: 

English • čeština • Deutsch • español • français • русский



Introduction

This is only a rough draft. The content should be OK, but it needs tidying up and could really benefit from some screen shots. If you follow the tutorial, please consider taking some shots as you do so and uploading them here...

This bug report suggested a feature:

I would like to be able to draw a bline with N vertices and have a shape move along that bline (the whole shape or individual vertices). Currently the only way I have found to do what I want is to draw a bline, and then move a shape along that line manually at fairly small intervals (very frustrating).

Example: A triangle that should move along a sine curve always pointing in the direction it is going to move next.

The feature has recently been added to Synfig (23rd September 2007) and will be in the next release.

Summary

We're going to:

Tutorial

This is a brief tutorial giving an example of how to use it:

Create the Animation

File > New

Create the Layers

select the BLine Tool

enable just the Outline checkbox

draw a bline that you want the arrow to move along

click the "Make BLine" icon in the bottom left of the "Tool Options" panel to create the bline.

still in the bline tool, enable Fill and Outline checkboxes in tool options

draw an arrow or whatever, pointing to the right

switch to the "Normal" tool

select the outline, hit control-a to select all its ducks except the green position duck

drag the ducks so that the arrow is centred around the green position duck

add a rotate layer above the outline and region

encapsulate the rotate, outline, and region layers

so now you've got 2 top-level layers: a curved path, and an encapsulation containing an arrow and a rotate layer

Make the Arrow Move and Rotate

select the "arrow" encapsulation layer by clicking it in the Layers panel

select its green position duck by clicking on it in the canvas window

additionally select the Rotate layer by holding Control and clicking it in the Layers panel

additionally select the blue "rotation amount" duck by holding Control and clicking on it in the canvas window

so now we should have 2 layers selected, and one duck from each of those 2 layers selected

now additionally select the curved bline layer (it should be the last layer in the Layer panel's list) by holding Control and clicking on it

right-click on the dotted line that indicates the position of the curved bline - not on any duck, but on the dotted link between ducks

from the context menu that pops up, select "Link to BLine"

the encapsulated arrow should move so that its green position duck is on the bline, and it should rotate so that the arrow points along the bline at that point

select just the encapsulation layer, and drag its green duck around. you'll see that the duck is constrained now to lie on the bline, and that dragging it also affects the rotation of the arrow as expected

we can now animate the arrow. turn on "animate edit mode" by clicking the icon in the bottom right of the canvas window.

at time 0f, drag the encapsulation layer's green position duck to one end of the bline

at time 5s, drag the same position duck to the other end of the bline

Try File > Preview or View > Play to watch the animation.

Results

This is the animation I ended up with: arrow-follows-line-tut.sifz

Commentary on the Feature

Also, the arrow takes the same time to move along each segment of the bline. So if there's a long straight part then a bendy complex part, the arrow will move much faster along the straight parts (since there will be less vertices in that part).

It would be good to have the option of having the arrow move at constant speed along the length of the curve.


Languages Language: 

English • čeština • Deutsch • español • français • русский