Skip to main content

Animation In FreeCAD

When it comes to scripting macros in FreeCAD there is one main purpose that comes to mind; animation.  In 3D packages such as Maya, Lightwave, Studio max etc the subject of animation is tackled via a keyframe timeline system.  You move an object from one key frame to another and the 3D package fills in the gaps.  This is known as tweening as in 'in-between'.  The system is intelligent enough to figure out the next frames.  In CAD we don't have the same privileges because CAD is geared towards building technical models and simulation rather than animation, for example we can simulate airflow with precise parameters, test the strength of and stresses on materials, discover clashes between component within building a structure etc.  These are all engineering and scientific areas and it's easy to loose track of the fact that when we look at the earlier 3D packages mentioned we are in the subject area of entertainment i.e. film, TV, games etc  

There are a number of options in FreeCAD to create and control animation simulations.  Depending on the reason for the animation then we may not even have to write a single line of code.  When we do a simplistic animation which requires a number of objects to move over time, then writing the least code possible and leveraging constraints or manipulating object parameters such as position and rotation makes our life easier.

There are a number of workbenches called assembly's.  These allow you to place (assemble) your objects (parts) together in what is known as an 'assembly'.  Constraints are made against each part, moving one part will affect all other parts in constraint. This movement can either be done manually or by code.  

By clicking and dragging a part or changing the properties through the FreeCAD's user interface we can see our assembly animate but if we want to playback this movement or run a simulation with certain parameters such as speed, distance etc then we need code.

Some assembly workbench allow for us to create an exploded assembly through recording our movements to show how parts fit together.  When we are looking at more complex areas such as the kinematics of suspension systems to the mechanical movement of complex parts, relationships can be created with constraints. Manually moving parts with the mouse will allows us to see the effect on others parts, if we want our animation to be permanent then we also need to write some code.  The Assembly 4 workbench does have a utility which can control movement via changing the value of variables, allowing us to play our animation but this is very basic and doesn't have the ability to save. Scripting a macro allows you full control over your animation whilst leveraging these tools.

Please be aware that the workbench know as the 'Animation Workbench' is no longer in active development so is not supported in later versions of FreeCAD 

We will look at three methods of animation along with simple examples to understand how these work.  Firstly by controlling animation directly through Python without using any supporting assembly tools or workbenches, a "vanilla" environment. Then we will look at two of the most used workbenches; Assembly 2 plus and Assembly 4

Assembly 2 Plus and Assembly 4 In a Nutshell

The two workbenches offer two different ways to work with parts.  Assemblies allow for each part to be either created in the same or separate document(s) and then positioned relative to the assembly and contained parts.  Assembly 2 plus offers a number of constraints; you add to faces and / or edges of opposing parts, combine them together to create more complex ones and observe the results on your assembly.  Parts can be fixed in 3D space to allow others to be constrained in this fixed point creating a direct or indirect relationship. For instance you can make the faces of planes or spheres coincide with each other, doing this with a sphere and the shell of another sphere with similar diameter will create a simple ball joint.  We can then attach one end to an arm which rotates around a fixed point offered by a part such as a bolt which has been set with the fixed property.  

The Assembly 4 workbench works differently.  It offers two ways to create assemblies by allowing parts to be given one or more local coordinate system(s) (LCS) to align them with others.  This also allows for a  master sketch concept where a basic bone system can be created for a more kinematic approach.

Kinematics

As you can see we are allowing FreeCAD to do the hard work, calculating the position of our parts by constraining different parts to each other in a chain to simulate cause and effect between multiple bodies. This motion is known as "Kinematics".

The word Kinematics is the study of the maths of movement, it comes from the world of robotics where individual joint movements are calculated to get the desired outcome.  Kinematic movement is split into two areas; Forward Kinematics (FK) and Inverse Kinematics (IK) and relate to the manipulation of something called a hierarchical bone chain.

Forward Kinematics

When a bone chain is chained from parent to children it is know as FK if you rotate a parent bone all of the children will follow.  If we have a three bone chain Bone A , B and C,  rotating Bone A will cause Bone B and C to follow, Bone A is the parent of Bone B, Bone B is the parent of Bone C.  Rotating Bone A rotates Bone B, Bone B is the parent of C so it to will follow.  Rotating just Bone B with cause Bone C to rotate but Bone A will stay where it is allowing Bone B to pivot at the attachment point. This means that all movements are arc or curved based you have to rotate each bone separately.

Inverse Kinematics

With IK you loose the the parent child effect but you gain a more natural movement.  Moving a bone in the chain causes all the other bones to follow in a dragging motion.  Think of it as a string of paper clips linked together. Move the last paper clip and all the rest will follow.  This gives movement that follows lines rather than arcs as the movement will follow the point of drag.




You can get these effects from the Assembly workbench.  With Assembly A2 Plus you will find that the motion is more geared towards inverse kinematics when dragging one of the parts all the rest follow The Assembly 4 workbench allows for both forward and inverse Kinematic through a master sketch workflow.  We see from the examples above that the first examples shows FK movement through applying a angle constraints to the sketch between each link where the second shows IK movement by removing these angle constraints and leaving the coincident constraint at the point of origin anchoring the upper arm but allowing it to rotate around this point.

It must be noted that this is not a full kinematic system.  There are a number of other workbenches that are appear that give more control over animation.  Again we have to be mindful of what we are trying to do.  When we start trying to create say a walking skeleton then we have to question if we should be using CAD or a 3D animation package.  This is all down to the subject area.  I have had some kind followers explain to me what they are doing only to realise they are not wanting a mechanical or kinetic model but would be better off learning a mesh modelling package rather that parametric modelling.  Any time spent in either realm is not a mistake or time wasted.  Having knowledge in both realms give you exposure to those technologies that may come useful in the future.


Comments

Popular posts from this blog

Beginners FreeCAD: Exercise 5.1 & 5.2 (Reference Images)

Welcome to the total beginners course to FreeCAD 0.20. In this is a two part lesson we will practice our tracing skill in the form of a mini project. Using the below reference photos we will create a more complex part which will consist of repeating features. We will utilise the symmetry tools to ease construction in both FreeCAD sketcher and Part Design workbench. This project work will help teach the fundamentals of freeCAD allowing a understanding of the basics but delivering this information via teaching you different workflows. In this tutorial we will be tracing photos imported into FreeCAD via the image workbench https://wiki.freecadweb.org/Image_Workbench JUMP TO IMAGES Do you want to purchase the complete series along with others and keep forever?  Check out my shop https://ko-fi.com/mang0/shop The story of this tutorial The idea and first attempt at creating this tutorial was back in FreeCAD 0.18.  The physical part itself, well, I have no idea what really it is, i...

FreeCAD For Beginners: CAD Thinking Part 1

Step-by-Step CAD Thinking FreeCAD Tutorial: Modeling a Latch Part (Part 1) Learning how to turn real life objects into CAD Models. Using FreeCAD we explain at a beginner level how to break down a physical object into its primitive shapes to digitise it into a 3D model, with this episode we are looking at a multi-part assembly, modelling each piece individually. The series aims to open your eyes and mind giving you the ground skills to pick the correct profiles, geometry and workflow when it comes to modelling your parts. This is not just for FreeCAD but for all CAD packages out there. Introduction This tutorial is the first in a series guiding you through modeling a latch assembly in FreeCAD (version 0.21) using the Part Design and A2Plus workbenches. It focuses on modeling the first part (a slotted component) by selecting the top profile to create a slot and adding side arcs, emphasizing CAD thinking to break down complex shapes into primitives. The tutorial highlights model stability...

Beginner FreeCAD Tutorial 14: Reference Document for Exercise 1

This tutorial focuses on modelling a deck eye plate. These items are normally made of stainless steel with some kind of galvanised coating to stop corrosion. They are used in many industries but are most commonly found around boats, ships, sail lofts and docks where they play an important part in marine industry. Finding their use in many applications, they are often wall mounted acting as lashing points for mooring and for tying down sails or canopies. They can even be used for domestic use around the house and garden, for example to anchor ropes, cords and lines. So if your into 3D printing your finished creations, you can make use of the finished result.   Disclaimer : The strength of the part will depend on the internal structure, settings of the slicer and the material it has been printed on.  This will limit its application as failure of the part, damage to property and injury is a possibility.  These items are normally made of steel and are tested to take a...