Introduction
Introduction Statistics Contact Development Disclaimer Help
Make it easier to write new functions for blender - annna - Annna the nice frie…
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6…
Log
Files
Refs
Tags
README
---
commit 75a586ed745299e3ea0b24116aa4c45aa19e4a24
parent cce8587a0f1e93efe09b617a44406ee1e47b6a39
Author: Annna Robert-Houdin <[email protected]>
Date: Sun, 31 Jul 2022 18:46:42 +0200
Make it easier to write new functions for blender
Diffstat:
M blender-effect | 4 ++--
M modules/blender/.gitignore | 1 +
M modules/blender/effect.py | 38 +++++++++++++++++++----------…
3 files changed, 26 insertions(+), 17 deletions(-)
---
diff --git a/blender-effect b/blender-effect
@@ -26,6 +26,6 @@ ${BLENDER} --background \
"${BLEND_DIR}/${NAME}.blend" \
--python "${BLEND_DIR}/effect.py" \
--render-output "${IMAGE_DIR}/${NAME}." \
- --render-frame \
- 1 >&2 \
+ --render-frame 1 \
+ >&2 \
&& echo "${NAME}.0001.png"
diff --git a/modules/blender/.gitignore b/modules/blender/.gitignore
@@ -1 +1,2 @@
*.blend
+*.blend[0-9]
diff --git a/modules/blender/effect.py b/modules/blender/effect.py
@@ -3,7 +3,7 @@
# This is to be be called from blender itself (--python), and does not
# need 'bpy' to be installed from pip. It will be executed after blender
# is initialised and before the rendering begins.
-
+#
# The camera can be changed in the blender file before hand, with a nice
# default. The default camera will be used. The object original author
# did probably do it already.
@@ -11,32 +11,40 @@
import bpy
import os
-# all transformations will be done on the active object (orange in the GUI)
+def effect(fn):
+ """
+ add the function to a list of effects for calling an
+ effect from ${EFFECT} environment variable
+ """
+ effect_list[fn.__name__] = fn
+ def inner(kwargs):
+ print(f"running effect {fn.name}({value})")
+ return fn
+ return inner
+
+effect_list = {}
obj = bpy.context.active_object
+vars = {}
-def effect_translate(x=0, y=0, z=0):
+@effect
+def translate(x=0, y=0, z=0):
+ """
+ move an object on x, y, z axis
+ """
bpy.ops.transform.translate(value=(x, y, z))
-def effect_shape_key(value=0):
+@effect
+def reshape(value=0):
"""
Shape keys permits to adjust proportions of an object,
the active shape key is going to be adjusted.
"""
- print(f"running effect shape_key with value={value}")
-
if obj.active_shape_key.value == None:
raise Exception("there must be a shape key added in the blend file fir…
-
obj.active_shape_key.value = value
-# the below is used because we only can communicate with the shell script
-# through environment variables
-
-# grab all ${var_...} and turn it into python parameters
-vars = {}
+# out of environment variables, call $EFFECT($var_...)
for k, v in os.environ.items():
if k.startswith("var_"):
vars[k[4:]] = float(v)
-
-# call function depending on ${EFFECT} variable, and dispatch vars arguments
-locals()["effect_" + os.environ["EFFECT"]](**vars)
+effect_list[os.environ["EFFECT"]](**vars)
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.