effect.py - annna - Annna the nice friendly bot.
(HTM) git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
---
effect.py (1456B)
---
1 # https://docs.blender.org/api/current/index.html
2 #
3 # This is to be be called from blender itself (--python), and does not
4 # need 'bpy' to be installed from pip. It will be executed after blender
5 # is initialised and before the rendering begins.
6 #
7 # The camera can be changed in the blender file before hand, with a nice
8 # default. The default camera will be used. The object original author
9 # did probably do it already.
10
11 import bpy
12 import os
13
14 def effect(fn):
15 """
16 add the function to a list of effects for calling an
17 effect from ${EFFECT} environment variable
18 """
19 effect_list[fn.__name__] = fn
20 def inner(kwargs):
21 print(f"running effect {fn.name}({value})")
22 return fn
23 return inner
24
25 effect_list = {}
26 obj = bpy.context.active_object
27 vars = {}
28
29 @effect
30 def translate(x=0, y=0, z=0):
31 """
32 move an object on x, y, z axis
33 """
34 bpy.ops.transform.translate(value=(x, y, z))
35
36 @effect
37 def reshape(value=0):
38 """
39 Shape keys permits to adjust proportions of an object,
40 the active shape key is going to be adjusted.
41 """
42 if obj.active_shape_key.value == None:
43 raise Exception("there must be a shape key added in the blend file first, you can use the GUI")
44 obj.active_shape_key.value = value
45
46 # out of environment variables, call $EFFECT($var_...)
47 for k, v in os.environ.items():
48 if k.startswith("var_"):
49 vars[k[4:]] = float(v)
50 effect_list[os.environ["EFFECT"]](**vars)