Skip to content

Instantly share code, notes, and snippets.

@marcosbitetti
Last active August 29, 2015 14:17
Show Gist options
  • Save marcosbitetti/cb9a6539476cb0741b77 to your computer and use it in GitHub Desktop.
Save marcosbitetti/cb9a6539476cb0741b77 to your computer and use it in GitHub Desktop.
shell to split a skycube generated in Blender to 6 files to use in skycube game environments
#!/bin/bash
#########################################################################
# crop_sky.sh #
#########################################################################
# This file is part of: #
# WILD WITCH PROJECT #
# http://www.wildwitchproject/ #
#########################################################################
# CC-BY-SA #
# Wild Witch Project by Marcos Augusto Bitetti is licensed under a #
# Creative Commons Attribution-ShareAlike 4.0 International License. #
# Based on a work at http://www.wildwitchproject.com/. #
# Permissions beyond the scope of this license may be available at #
# http://www.wildwitchproject.com/p/direitos-da-obra.html. #
#########################################################################
if [ ! $1 ]
then
echo Usage:
echo ./crop_sky.sh input_image_file
echo
echo Select a skybox cube generated in Blender \(3x2 images\) and put the six generated images into your project.
echo Ex.:
echo ./crop_sky.sh mycube.png
echo
echo Dependencies: imagemagick
echo sudo apt-get install imagemagick
exit 0
fi
WIDTH=$(convert $1 -print "%w" /dev/null )
HEIGHT=$(convert $1 -print "%h" /dev/null )
SIZE=$(expr $HEIGHT / 2)
COMMAND="convert $1 -crop "
COMMAND+=$SIZE
COMMAND+=x
COMMAND+=$SIZE
eval "$COMMAND+0+0 +repage -define png:color-type=2 left.png"
eval "$COMMAND+$SIZE+0 +repage -define png:color-type=2 front.png"
eval "$COMMAND+$HEIGHT+0 +repage -define png:color-type=2 right.png"
eval "$COMMAND+0+$SIZE +repage -define png:color-type=2 bottom.png"
eval "$COMMAND+$SIZE+$SIZE +repage -define png:color-type=2 top.png"
eval "$COMMAND+$HEIGHT+$SIZE +repage -define png:color-type=2 back.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment