Reader small image

You're reading from  Python Scripting in Blender

Product typeBook
Published inJun 2023
PublisherPackt
ISBN-139781803234229
Edition1st Edition
Right arrow
Author (1)
Paolo Acampora
Paolo Acampora
author image
Paolo Acampora

Paolo Acampora is a 3D artist and programmer, with experience in Animation, Visual Effects, and Real Time computer graphics. He provides tools that streamline the production workflow and let artists focus on the creative aspects of their craft. He has worked with several studios for more than a decade. He contributes to the blender development and releases his tools for the community.
Read more about Paolo Acampora

Right arrow

Animation Modifiers

Animation curves, or F-Curves, can be altered by modifiers without having their keyframes changed. This way, cinematic or motion effects can replace the initial curve completely or add to its original value.

The output of a modifier can be the input of another modifier, which, when combined, allows us to build complex results on top of simple animations.

Python scripts can be used to help automate this and streamline the workflow.

Changing a parameter affects the modifier’s result, while its overall Influence can be reduced using the slider in the modifier interface.

In this chapter, you will learn how to add modifiers to animation F-Curves with your scripts and how to change their parameters.

This chapter will cover the following topics:

  • Understanding F-Curve Modifiers in the Blender UI
  • Adding F-Curve Modifiers via Python
  • Using F-Curve Modifiers in our add-ons

Technical requirements

We will use Blender and Visual Studio Code in this chapter. The examples created in this chapter can be found at https://github.com/PacktPublishing/Python-Scripting-in-Blender/tree/main/ch8.

Using F-Curve Modifiers

Modifiers for animation curves, called F-Curve Modifiers or F-Modifiers, add non-destructive changes to animations while preserving their original data. We examined similar functionality in Object Constraints in Chapter 4, where we learned how to affect an object’s position without changing the values stored in its channels.

Like object constraints, F-Modifiers are exposed to Python scripts through a collection property.

Before we delve into how F-Modifiers are scripted, we will have a look at how to create them in the Graph Editor.

Adding F-Curve Modifiers in the Graph Editor

We will now look at how to add variation to an animated object using F-Curve Modifiers.

For this example, we will use the ani_loop.blend scene, from the accompanying PythonScriptingBlender/ch8/_scenes_ folder, but you can use any scene.

The animation along the 8-shaped path in ani_loop.blend wasn’t created by hand: it was generated using the Vert Runner...

Writing the Shaker add-on

The Shaker add-on creates a shaky effect on the active object by adding noise modifiers to its animation curves.

There are cases when we want to add some shaking to a motion. For instance, directors often use a camera shake to suggest an object being bumped or hit. Another use case is the bumpy motion of a vehicle, or hairs and feathers in a windy environment. The Python script we are going to write will contain an operator and a menu function for quick execution.

Setting up the environment

We first create a Python script for our add-on:

  1. Create the PythonScriptingBlender/ch8/addons folder. We can use the file manager or the File tab of our code editor, such as VS Code.
  2. Create a new file in that folder and name it object_shaker.py. We can use the file manager or the New File button of our code editor.
  3. Open the file in your editor of choice.
  4. Set the Scripts path to PythonScriptingBlender/ch8 in the Blender File Paths preferences...

Summary

We have learned how to create animation effects for our scenes and have seen how we can convert an idea into a procedural tool. Artists and technical animators can come up with convoluted conceptual configurations, which we can turn into quick-setup operators following the process outlined in this chapter.

Using the animation system is a convenient way to implement parametric behaviors, as it relies on the application update logic and produces fast, reliable outputs.

We will explore a similar but more powerful technique in Chapter 9, thus completing our overview of the animation system.

Questions

  1. What do we mean by non-destructive modifiers?
  2. Do modifiers change the keyframe points of a curve?
  3. Can we add animation modifiers to non-animated objects?
  4. How do we make sure that a property is animated?
  5. What is a parameter soft limit?
  6. In which cases do we use soft rather than strong limits?
  7. How can we look for a class name in Python?
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Python Scripting in Blender
Published in: Jun 2023Publisher: PacktISBN-13: 9781803234229
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Paolo Acampora

Paolo Acampora is a 3D artist and programmer, with experience in Animation, Visual Effects, and Real Time computer graphics. He provides tools that streamline the production workflow and let artists focus on the creative aspects of their craft. He has worked with several studios for more than a decade. He contributes to the blender development and releases his tools for the community.
Read more about Paolo Acampora