Skip to content

Commit

Permalink
Build process updates .blend files in a special directory.
Browse files Browse the repository at this point in the history
This means that updating the Blender version doesn't mess up
version control of the files. Also, the build process has been
cleaned up a little to make better use of make's ability to
recognise files that have changed.
  • Loading branch information
Alex Fraser committed Feb 13, 2014
1 parent 3395e3b commit 16d8ead
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -22,4 +22,4 @@ OutdoorsBase_grass.blend

*~
build
VERSION.txt
dist
82 changes: 59 additions & 23 deletions Makefile
@@ -1,24 +1,59 @@
SHELL=/bin/bash

# Path to blender executable.
# Override this if you want to use a version of Blender that is not on the
# system path, e.g. a special build. You can override it by starting the build
# like this:
#
# make BLENDER=~/local/blender-2.69-6d8f76c-linux-glibc211-x86_64/blender
#
BLENDER := `which blender`

VERSION := $(shell git describe --tags)
GAME_NAME := cargo
ASSETS := ../game/assets
DOCS := ../readme.html ../readme_files ../VERSION.txt
ASSETS := ../build/assets
DOCS := ../readme.html ../readme_files \
../build/VERSION.txt ../build/BLENDER_VERSION.txt
BLEND_FILES := $(addprefix build/, $(shell cd game; find . -name \*.blend))


.PHONY: dist
dist: dist-osx dist-win dist-lin build compile

.PHONY: build
build: build-osx build-win build-lin

# Compile any generated game files.
.PHONY: compile
compile:
$(MAKE) -C game/assets


# Copy relevant files over to build directory. Note that .blend files are done
# individually using Blender.
.PHONY: build
build: RSYNC_EXCLUDE := \
--exclude-from=.gitignore \
--exclude \*.blend \
--exclude .git\* \
--exclude BScripts \
--exclude pyextra
build: $(BLEND_FILES)
mkdir -p build
rsync $(RSYNC_EXCLUDE) -av game/ build/
echo "$(VERSION)" > build/VERSION.txt
$(BLENDER) -v > build/BLENDER_VERSION.txt


# Updates the files to the current Blender version. If this is not done, Blender
# may crash when loading linked assets, because the linked files are not
# converted automatically when being opened. Only an issue in blenderplayer.
build/%.blend: game/%.blend
@mkdir -p $(dir $@)
$(BLENDER) -b $< -P game/assets/BScripts/update_version.py -- $@


# Package distribution files.
package = \
@test -n "$(ARCHIVES)" || { echo "Error: no archive files. Download Blender archives and put them in the blender/ directory. See http://www.blender.org/download/get-blender/"; false; }; \
echo "$(VERSION)" > VERSION.txt; \
mkdir -p build; \
cd build; \
mkdir -p dist; \
cd dist; \
for archive in $(ARCHIVES); do \
echo Building from $$archive; \
../package_bge_runtime/package_bge_runtime.py \
Expand All @@ -27,25 +62,26 @@ package = \
if [ $$? -ne 0 ]; then exit $$?; fi \
done

.PHONY: build-osx
build-osx: ARCHIVES := $(wildcard blender/*OSX*.zip)
build-osx: MAINFILE := ../game/cargo_w.blend
build-osx:
.PHONY: dist-osx
dist-osx: ARCHIVES := $(wildcard blender/*OSX*.zip)
dist-osx: MAINFILE := ../build/cargo_w.blend
dist-osx:
$(call package)

.PHONY: build-win
build-win: ARCHIVES := $(wildcard blender/*win*.zip)
build-win: MAINFILE := ../game/cargo.blend
build-win:
.PHONY: dist-win
dist-win: ARCHIVES := $(wildcard blender/*win*.zip)
dist-win: MAINFILE := ../build/cargo.blend
dist-win:
$(call package)

.PHONY: build-lin
build-lin: ARCHIVES := $(wildcard blender/*linux*.tar.bz2)
build-lin: MAINFILE := ../game/cargo.blend
build-lin:
.PHONY: dist-lin
dist-lin: ARCHIVES := $(wildcard blender/*linux*.tar.bz2)
dist-lin: MAINFILE := ../build/cargo.blend
dist-lin:
$(call package)

.PHONY : clean

.PHONY : clean
clean:
rm -r build
rm -rf build dist build/VERSION.txt build/BLENDER_VERSION.txt
$(MAKE) -C game/assets clean
12 changes: 10 additions & 2 deletions game/assets/BScripts/update_version.py
@@ -1,5 +1,13 @@
import sys

import bpy

bpy.ops.wm.save_mainfile(filepath=bpy.context.blend_data.filepath)
bpy.ops.wm.quit_blender()
try:
arg_separator = sys.argv.index('--')
output_path = sys.argv[arg_separator + 1]
except ValueError:
print('Saving over current file')
output_path = bpy.context.blend_data.filepath

bpy.ops.wm.save_mainfile(filepath=output_path)
bpy.ops.wm.quit_blender()
46 changes: 19 additions & 27 deletions game/assets/Makefile
Expand Up @@ -7,45 +7,37 @@
#
BLENDER := `which blender`

all: updateversion foliage
all: foliage


# Foliage is compiled: particle system object instances are made real, then
# organised as a KD-tree. See BScripts/BlendKDTree.py
foliage: OutdoorsBase_flowers.blend OutdoorsBase_grass.blend

OutdoorsBase_grass.blend: OutdoorsBase.blend GrassBlade.blend BScripts/BlendKDTree.py
$(BLENDER) --factory-startup -b OutdoorsBase.blend -P BScripts/BlendKDTree.py -- Grass_LOD OutdoorsBase_grass.blend
$(BLENDER) --factory-startup -b \
OutdoorsBase.blend -P BScripts/BlendKDTree.py -- \
Grass_LOD OutdoorsBase_grass.blend

OutdoorsBase_flowers.blend: OutdoorsBase.blend GrassBlade.blend BScripts/BlendKDTree.py
$(BLENDER) --factory-startup -b OutdoorsBase.blend -P BScripts/BlendKDTree.py -- Flowers_LOD OutdoorsBase_flowers.blend

SCRIPT_CACHE=bxt/*.pyc\
bxt/__pycache__\
Scripts/*.pyc\
Scripts/__pycache__\
BScripts/*.pyc\
BScripts/__pycache__\
__pycache__\
*.pyc\
$(BLENDER) --factory-startup -b \
OutdoorsBase.blend -P BScripts/BlendKDTree.py -- \
Flowers_LOD OutdoorsBase_flowers.blend


clean: SCRIPT_CACHE=bxt/*.pyc \
bxt/__pycache__ \
Scripts/*.pyc \
Scripts/__pycache__ \
BScripts/*.pyc \
BScripts/__pycache__ \
__pycache__ \
*.pyc \
*~

# Updates the files to the current Blender version. If this is not done, Blender
# may crash when loading linked assets, because the linked files are not
# converted automatically when being opened.
updateversion:
@echo Updating files using $(BLENDER)
@for f in *.blend bat/*.blend ../*.blend; \
do \
echo -n "$$f ... "; \
$(BLENDER) -b "$$f" -P BScripts/update_version.py; \
echo done; \
done
@echo Storing current version in BLENDER_VERSION.txt
@$(BLENDER) -v > BLENDER_VERSION.txt

clean:
rm -rf $(SCRIPT_CACHE)
rm -f *.blend?
rm -f OutdoorsBase_flowers.blend OutdoorsBase_grass.blend

distclean: clean
rm -f *.bgeconf
Expand Down

0 comments on commit 16d8ead

Please sign in to comment.