add a 3d shape-key effect command (initial version) - annna - Annna the nice fr… | |
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
commit 1a4411fb8d73e77aa3a4cc06504275cfe5fb9343 | |
parent 3524a992d47d9aa4016c82fd2bb5a7a85e86b9dc | |
Author: Josuah Demangeon <[email protected]> | |
Date: Sun, 31 Jul 2022 14:31:45 +0200 | |
add a 3d shape-key effect command (initial version) | |
Signed-off-by: Annna Robert-Houdin <[email protected]> | |
Diffstat: | |
M annna-message-common | 5 +++++ | |
A blender-effect | 30 ++++++++++++++++++++++++++++++ | |
A modules/blender/.gitignore | 1 + | |
A modules/blender/effect.py | 42 +++++++++++++++++++++++++++++… | |
4 files changed, 78 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/annna-message-common b/annna-message-common | |
@@ -924,6 +924,11 @@ case "${text}" in | |
} & | |
exit 0 | |
;; | |
+"${botname}, please 3d "*) | |
+ args=$(echo ${text} | cut -d' ' -f 4-) | |
+ outfile=$(blender-effect $args) | |
+ annna-say -s "${server}" -c "${channel}" "${user}, gopher://bitreich.o… | |
+ ;; | |
"${botname}, please simulate "*" simulator"*) | |
q="${text#* please simulate }" | |
q="${q% simulator*}" | |
diff --git a/blender-effect b/blender-effect | |
@@ -0,0 +1,30 @@ | |
+#!/bin/sh | |
+# https://docs.blender.org/manual/en/latest/advanced/command_line/render.html | |
+ | |
+if [ "$#" -lt 2 ] | |
+then | |
+ printf 'usage: %s effect-name model-name [param=value]\n' "${0##*/}" >… | |
+ exit 1 | |
+fi | |
+ | |
+export EFFECT="$1" | |
+export NAME="$2" | |
+shift 2 | |
+ | |
+BLENDER=blender | |
+BLEND_DIR="$(dirname "$0")/modules/blender" | |
+IMAGE_DIR=/bitreich/gopher/memecache/3d | |
+ | |
+# turn "key1=value key2=value key3=value" into variables used by blender-effec… | |
+for x in "$@" | |
+do | |
+ export "var_$1" | |
+done | |
+ | |
+${BLENDER} --background \ | |
+ "${BLEND_DIR}/${NAME}.blend" \ | |
+ --python "${BLEND_DIR}/effect.py" \ | |
+ --render-output "${IMAGE_DIR}/${NAME}." \ | |
+ --render-frame \ | |
+ 1 >&2 \ | |
+&& echo "${NAME}.0001.png" | |
diff --git a/modules/blender/.gitignore b/modules/blender/.gitignore | |
@@ -0,0 +1 @@ | |
+*.blend | |
diff --git a/modules/blender/effect.py b/modules/blender/effect.py | |
@@ -0,0 +1,42 @@ | |
+# https://docs.blender.org/api/current/index.html | |
+# | |
+# 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. | |
+ | |
+import bpy | |
+import os | |
+ | |
+# all transformations will be done on the active object (orange in the GUI) | |
+obj = bpy.context.active_object | |
+ | |
+def effect_translate(x=0, y=0, z=0): | |
+ bpy.ops.transform.translate(value=(x, y, z)) | |
+ | |
+def effect_shape_key(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 = {} | |
+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) |