Blender

HOW TO? FILES

FROM BLENDER GAME TO ANIMATION

To achieve this feat, we will be using two separate scripts 'object2text.py' and 'text_to_keyframe.py'.

THINGS TO NOTE:

'object2text.py' - [Records data into a csv file]

This script has two main control variables;

  • target_object: Set this to the name of whatever object (gameobject) you wish to record.
  • rate: Use this variable to control the speed at which data is recorded or logged.

And two main functions;

  • write_data(data, filename='recorded_data.csv'): This function takes two arguments; data and filename[optional] and is called when the game ends by pressing 'Q' to write out the data recorded to a .csv file.
  • main(): This function uses an 'Always' sensor with 'usePosPulseMode= True' for repetitive execution/ call of the sensor and hence the controller which hosts the script. Data logging/ recording of the 'target_object' occurs here at the 'rate' set by the user.

'text_to_keyframe.py' - [Reads the recorded csv file and re-create the animation]

The script has three main control variables;

  • target_object: Set this to the name of whatever object (gameobject) you wish to record.
  • framerate: Use this to control the speed of the animation.
  • filename: Full path to the recorded file you wish to animate.

And one function;

  • read_data(filename): This function takes the name of the file to be read as argument and re-creates the animation on the target object at the rate set by the user.


GAME ENGINE SETUP [BLENDER GAME ENGINE]

  1. Add 'Always Sensor' and change its name to 'recorder'
  2. Add and connect a PythonController to the sensor in 1
  3. Set the text-data block of the controller in 2 to the 'object2text.py' script
  4. Add and connect a 'Game Actuator' to the output of the python controller in 3 and set its name to 'quit_game'
  5. Set the 'target_object' and 'rate' variables.

Run your game as you would normally but remember to end the game by pressing the 'Q' key. Very important else the recorded data will not get written out to the file.



ANIMATION PLAYBACK [BLENDER RENDER/ CYCLES]

  1. Open the 'text_to_keyframe.py' script and set the control variables as stated earlier.
  2. Press 'Run Script' or [Alt + P] to execute the script.
Done! You can press 'Alt + A' to run the animation. Hope I managed to help someone out (:-D), Thanks!.