Skip to content

Instantly share code, notes, and snippets.

@xx7y7xx
Last active February 23, 2016 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xx7y7xx/feffe28c4da50b666422 to your computer and use it in GitHub Desktop.
Save xx7y7xx/feffe28c4da50b666422 to your computer and use it in GitHub Desktop.
Create scene and render with Blender
#!/bin/bash
# Create scene and render with Blender.
# This script depends some other scripts to work.
# Run this script in jenkins: http://192.168.2.21:8080/view/render/job/render
# You can download this script from https://gist.github.com/xxd3vin/feffe28c4da50b666422
# Copyright (C) 2015 Devin Chen - All Rights Reserved
# Permission to copy and modify is granted under the MIT license
# Last modified 2/23/2016
#
# macro
#
NHOME="/home/handle/nhandler"
blender="/var/local/blender-2.72b-linux-glibc211-x86_64/blender"
convert="/usr/bin/convert"
jp2a="/opt/jp2a-1.0.6/src/jp2a"
FLAG="$NHOME/weihuzhong.txt"
render_py="$NHOME/res/render.py"
check_pic_py="$NHOME/res/check_pic.py"
create_scene_py="$NHOME/res/create_scene.py"
tm_sh="/opt/glue/tm.sh"
pano2vr_sh="$NHOME/res/pano2vr.sh"
empty1="$NHOME/res/empty1.blend"
empty2="$NHOME/res/empty2.blend"
TMP="$NHOME/temp"
INPUT="$TMP/input"
OUTPUT="$TMP/output"
# input params
#/home/glue/share/repository/9fde/71eb/8020/4409/8a62/13f6/b42a/f282
REPO="$1"
#
# functions
#
function noty() {
local title="render_gpu2"
local content="$1"
curl "http://192.168.2.21:8080/job/chenyang_notification/buildWithParameters?token=sp12345678&title=$title&content=$content"
}
#
# main()
#
# make sure handler not receive new job.
if [ ! -f "$FLAG" ]; then
exit 1
fi
# The Nodejs way:
# curl -F "jid=job_fake_id_123" -F "path=/tmp/render_test_repo/input" 127.0.0.1:4001/dojob
# The Shell script way:
# as below
ls -l -R $TMP
rm -rf $TMP/*
ls -l -R $TMP
mkdir $TMP/input
mkdir $TMP/output
# Copy models from repo
ls -l -R $REPO
cp $REPO/input/* $INPUT
# check_pic
for f in $INPUT/*.blend
do
echo "check_pic: $f"
$blender -b $f -P $check_pic_py
done
# Create scene
cd /tmp
export path="$INPUT/render.json"
export input="$INPUT"
export output="$INPUT"
$blender -b $empty2 -P $create_scene_py
cd -
# render type
# flag.txt is created by create_scene.py
type=`cat $INPUT/flag.txt`
# Render ...
$blender -b "$INPUT/main.blend" -P $render_py -- HDR,PNG -- "$OUTPUT" 2>&1 | tee "$OUTPUT/render.log"
ls -l $OUTPUT
# Check render result
$convert "$OUTPUT/0000.png" jpg:- | $jp2a -
if [ $type = "PERSP" ]; then
# Tone Mapping ...
$tm_sh persp $OUTPUT/0000.png $OUTPUT/0000.hdr $OUTPUT 0000
# Post processing
/opt/gimp/gimp.sh persp $OUTPUT/0000.png /opt/gimp/gimp_update1651.gmic $OUTPUT/0000.png
elif [ $type = "PANO_MAX" ] || [ $type = "PANO_MIN" ]; then
$tm_sh pano $OUTPUT/0000.png $OUTPUT/0000.hdr $OUTPUT 0000
/opt/gimp/gimp.sh pano $OUTPUT/0000.png /opt/gimp/gimp_update1651.gmic $OUTPUT/0000.png
fi
# Create pano2vr for pano
if [ $type = "PANO_MAX" ] ; then
$pano2vr_sh $OUTPUT/0000.png 0000 max
elif [ $type = "PANO_MIN" ]; then
$pano2vr_sh $OUTPUT/0000.png 0000 min
fi
# Create artifacts for jenkins
if [ "X$WORKSPACE" != "X" ]; then
mkdir -p $WORKSPACE/output
cp $OUTPUT/* $WORKSPACE/output
fi
noty "finished"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment