-
Notifications
You must be signed in to change notification settings - Fork 0
/
pictures.sh
executable file
·101 lines (84 loc) · 3.19 KB
/
pictures.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
#
# GPLv3 License
#
# Copyright (c) 2019-2022 Jean-Sebastien CONAN
#
# This file is part of jsconan/whoop-box.
#
# jsconan/whoop-box is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# jsconan/whoop-box is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with jsconan/whoop-box. If not, see <http://www.gnu.org/licenses/>.
#
#
# Generates the pictures for the documentation of the project.
#
# @author jsconan
#
# script config
scriptpath="$(dirname $0)"
project="$(pwd)"
srcpath="${project}/pictures"
dstpath="${project}/dist/pictures"
tmppath="${project}/tmp"
configpath="${project}/config"
# include libs
source "${scriptpath}/lib/camelSCAD/scripts/utils.sh"
# options
mask="*.${scadext}"
imgext="png"
vidext="gif"
framerate=15
imgstep=3
imgwidth=320
imgheight=240
theme="Starnight"
# prepate the output folder
createpath "${dstpath}" "output"
createpath "${tmppath}" "tmp"
# make sure the config exists
distfile "${configpath}/config.scad"
distfile "${configpath}/presets.scad"
# list the pictures to render
printmessage "Processing rendering from ${C_SEL}${srcpath}${C_RST}..."
foldermustcontain "${srcpath}" "${mask}" "render"
list=($(find "${srcpath}" -maxdepth 1 -name "${mask}"))
for filename in "${list[@]}"; do
name=$(basename "${filename%.*}" )
showsteps="${tmppath}/${name}.${echoext}"
picture=
# get the number of steps
scadecho "${filename}" "${tmppath}" "" "" showSteps=1 > /dev/null
step=$(sed 's/[^0-9]*//g' "${showsteps}")
if [ "$step" != "" ]; then
picture="${dstpath}/${name}.${vidext}"
# compute the number of images to render
length=$((${step} * ${imgstep}))
# generate each image of the amimation
printmessage "${C_RST}Will render ${C_SEL}${length}${C_RST} frames from ${C_SEL}${filename}${C_RST}"
scadpreview "${filename}" "${tmppath}" "${imgext}" "" "" --quiet --animate ${length} --projection p --colorscheme "${theme}" --imgsize ${imgwidth},${imgheight}
# produce the video
printmessage "${C_RST}Will render a video of ${C_SEL}${length}${C_RST} frames with a rate of ${C_SEL}${framerate}${C_RST} images per seconds"
ffmpeg -framerate ${framerate} -i "${tmppath}/${name}%5d.${imgext}" "${picture}" -y
else
picture="${dstpath}/${name}.${imgext}"
# generate a single image
printmessage "${C_RST}Will render a picture from ${C_SEL}${filename}${C_RST}"
scadpreview "${filename}" "${dstpath}" "${imgext}" "" "" --quiet --projection p --colorscheme "${theme}" --imgsize ${imgwidth},${imgheight}
fi
# clean up the place
rm "${tmppath}/${name}"*."${imgext}" 2> /dev/null
rm "${showsteps}" 2> /dev/null
if [ -f "${picture}" ]; then
printmessage "${C_RST}Picture rendered at ${C_SEL}${picture}${C_RST}"
fi
done