4
$\begingroup$

I would like to do 3D animations.

M spheres appear moving around and rotating along N frames (all spheres will appear in every frame).

For each sphere at every frame, these values are saved in a text file, which I'd like Blender to read:

  • position
  • angle rotation

Is it possible to read this file from blender, (so that Blender will create N frames and move and rotate at each frame the M spheres with the data read)?

I can write the file with the positions and angles in the most easily format to perform this. Eg. csv file:

time step | sphere number | x | y | z | mx | my | mz

(where m is refered to the rotation components)

$\endgroup$
  • $\begingroup$ The last sentence is unclear. Do you mean you can save the file in 'some easy to read' format? E.g. JSON, XML, CSV ? $\endgroup$ – Howard Pautz Aug 25 '16 at 17:46
  • $\begingroup$ It looks like you are asking the same question as this one: blender.stackexchange.com/questions/61605/… $\endgroup$ – Ed Tate Aug 25 '16 at 18:03
8
$\begingroup$

example animation

Using a data file to control position and rotation can be done using the animation nodes add-on. If this is not installed, then install it from the Git repository

To install the animation nodes, see http://animation-nodes-manual.readthedocs.io/en/latest/user_guide/install/install.html

Tested in Blender 2.77


To start, create a simple scene with a sphere and a plane. Add a material to the sphere so rotation can easily be seen. scene setup

Open the node editor, switch to the animation node mode, then create a new animation node network. new network

Add the 'Compose Matrix' and 'Object Matrix Output' nodes. Connect the matrix output to the matrix input. In the 'Object Matrix Output' node, set the object to the sphere is the scene. nodes to control an object location and rotation

At this point, if you change any of the values in the 'Compose Matrix' you should see the sphere move, rotate, or scale.

Add a 'Combine Vector' node and a 'Combine Euler' node. This will expose scalar values that can be used set. In the 'Combine Euler' node set the 'Use Degree' check box. Combine vector

Once again, changing these values will move and rotate the sphere.

The next couple of steps will add the logic to convert a string into a vector. Add a 'String Input' node, a 'Split Text' node, a 'Get List Element' node, and a 'Parse Number' node as shown. Also 'Debug' nodes can be added to see what values flow through the node network. The 'Split By:' value should be set to ',' (a comma).

Converting strings to vector

Now changing the inputs string, which is CSV separated, will change the location of the sphere.

Create the input file for location and rotation. It should look something like the following. Save it to 'sphere-1.csv' in the current directory.

csv delimited data

The next steps will replace the string with the input from a file. Delete the 'String Input' node. Add a 'Text File Reader', a 'Split Text' node, and a 'Get List Element' node. Change the 'Split Text' to use 'Lines' to separate the text file. file inputs

This will set the x position of the sphere to the value of the 1st line in the 'sphere-1.csv' file. To animate this, add a 'Time Info' and 'to Integer (floor)' node. frame animator logic

To see this animation work, open a timeline panel and set the start to 0 and the end as 12. This will then only animation the first 13 lines in the data file. animation setup

If animated, the result will be the following: animation along x axis


At this point, all of the pieces are in place to translate and rotate an object. The next step is to hook up all of the information from the file to the object. Extend the previous network into this one. all data added

The result of this network should be the following animation. translate and rotate


To animate multiple spheres, the animation logic is converted into a 'group' which has a file name and object as the input.

Add a group to the network. Connect the output of the group to the path and to the object. Then add a group instance. This will behave just like the previous example. The difference is that that group instance passes the path name and the object to the group. This group can be reused. group setup

Add three spheres to the scene and create the three more data files with location and rotation like 'sphere-1.csv'.

Add a 'Create String List' node and populate it with the files names with the data for each sphere. Add a 'Create Object List' node and populate it with the name of each sphere. Add two 'Get List Element' nodes. Add a 'Loop Input' node. Connect all of this so the 'Loop Input' is used to specify the 'Index' of the object and data file for each iteration of the loop. Finally, add a 'Invoke Subprogram' that points to the loop and has 4 iterations. The part of the network is shown below.

Loop network

The entire network is shown here:

Whole network

By adding more data to the input files and setting the last frame in the animation larger, an animation like the following is generated.

example animation


This blend file can be downloaded here:

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.