-
Notifications
You must be signed in to change notification settings - Fork 4
/
kicad_animation.sh
executable file
·65 lines (55 loc) · 1.78 KB
/
kicad_animation.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
#!/bin/bash
#
# Original by: arturo182
# gist: https://gist.github.com/arturo182/57ab066e6a4a36ee22979063e4d5cce1
#
extract_project_name() {
echo "$1" | rev | cut -d '/' -f 1 | rev | sed -e "s/.kicad_pcb//g"
}
extract_output_path() {
echo "$1" | sed -e "s/[^\/]*\.kicad_pcb//g"
}
OUTPUT_FILE=""
if [[ -z "$3" ]]; then
path=$(extract_output_path "$2")
name=$(extract_project_name "$2")
OUTPUT_FILE="${path}${name}"
echo "OUTPUT_FILE: $OUTPUT_FILE"
else
OUTPUT_FILE="$3/rotating"
fi
FORMAT="$1"
OUTPUT_DIR="${3:-/pwd}"
FRAME_DIR="/tmp/render"
INPUT_FILE="$2"
ZOOM=0.7
WIDTH=300
HEIGHT=300
ROTATE_X=0
ROTATE_Z=45
ROTATION=360 # Total rotation angle
STEP=3 # Rotation step in degrees
FRAMERATE=30 # Framerate for the final video
KICAD_CLI=$(which kicad-cli || which kicad-cli-nightly)
mkdir -p $OUTPUT_DIR
mkdir -p $FRAME_DIR
let FRAMES=ROTATION/STEP
for ((i = 0; i < FRAMES; i++)); do
ROTATE_Y=-$(($i * STEP))
OUTPUT_PATH="$FRAME_DIR/frame$i.png"
echo "Rendering frame $i ($ROTATE_Y degrees) to $OUTPUT_PATH"
$KICAD_CLI pcb render --rotate "$ROTATE_X,$ROTATE_Y,$ROTATE_Z" --zoom $ZOOM -w $WIDTH -h $HEIGHT --background opaque -o $OUTPUT_PATH "$INPUT_FILE" > /dev/null
done
# Combine frames into an MP4 with the specified framerate
if [[ $FORMAT == "mp4" ]]; then
echo "Combining frames into an MP4..."
ffmpeg -y -framerate $FRAMERATE -i "$FRAME_DIR/frame%d.png" -c:v libx264 -r 30 -pix_fmt yuv420p "$OUTPUT_FILE.mp4"
echo "MP4 created successfully."
elif [[ $FORMAT == "gif" ]]; then
echo "Combining frames into an GIF..."
ffmpeg -y -framerate $FRAMERATE -i "$FRAME_DIR/frame%d.png" "$OUTPUT_FILE.gif"
echo "GIF created successfully."
else
# TODO: this should be vaildated before rendering anything
echo first argument must be mp4 or gif
fi