-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
146 lines (116 loc) · 5.3 KB
/
Makefile
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# CC3_VERSION?=2_0_0
# BLENDER_VERSION?=4.0
CC3_VERSION?=1_1_6
BLENDER_VERSION?=3.6
BLENDER_ARCHIVE?=blender-$(BLENDER_VERSION).7-linux-x64.tar.xz
PYTHON_VERSION?=3.10
DOCKER_REPO?=hakanardo/blenderset
BLENDER_DIR?=build/blender
BLENDER?=$(BLENDER_DIR)/blender
export BLENDER_USER_SCRIPTS=$(BLENDER_DIR)/no_user_addons
.PHONY: fix_format
fix_format:
black .
release:
-rm blenderset.zip
zip -r blenderset.zip blenderset
interactive:
PWD=$(shell pwd) $(BLENDER) blank.blend
delfinensynth:
$(BLENDER) delfinensynth.blend
double-%:
$(MAKE) $* & $(MAKE) $*; wait
tripple-%:
$(MAKE) $* & $(MAKE) $*; wait
run: run-run
run-%:
$(BLENDER) -b --python $*.py
run-cuda:
$(BLENDER) -b --python run.py -- --cycles-device CUDA $(EXTRA_ARG)
run-optix:
$(BLENDER) -b --python run.py -- --cycles-device OPTIX $(EXTRA_ARG)
run-forever-%:
while true; do $(MAKE) run-$*; sleep 1; done
import_animations:
$(BLENDER) -b --python import_animation.py
.PHONY: sync_env
sync_env:
pip install --no-binary OpenEXR OpenEXR
pip install -r requirements/misc.txt
build/downloads/Python-$(PYTHON_VERSION).0.tar.xz:
wget -O $@ https://www.python.org/ftp/python/$(PYTHON_VERSION).0/Python-$(PYTHON_VERSION).0.tar.xz
build/downloads/$(BLENDER_ARCHIVE):
wget -O $@ https://mirrors.dotsrc.org/blender/release/Blender$(BLENDER_VERSION)/$(BLENDER_ARCHIVE)
build/downloads/cc3_blender_tools-$(CC3_VERSION).zip:
wget -O $@ https://github.com/soupday/cc3_blender_tools/archive/refs/tags/$(CC3_VERSION).zip
build/downloads/%:
@echo $@ must be downloaded manually
@exit 1
build/downloads:
-mkdir -p $@
build/downloads/_envoy: build/downloads build/downloads/$(BLENDER_ARCHIVE) build/downloads/cc3_blender_tools-$(CC3_VERSION).zip build/downloads/Python-$(PYTHON_VERSION).0.tar.xz
@touch $@
# TODO: Consider pointing blender to a config that is local to this project
$(BLENDER_DIR)/_envoy: build/downloads/_envoy
rm -rf $(@D) || :
mkdir -p $(@D)
tar \
--no-same-permissions \
--no-same-owner \
--strip 1 \
-xf $(<D)/$(BLENDER_ARCHIVE) -C $(@D)
tar \
--no-same-permissions \
--no-same-owner \
-xf $(<D)/Python-$(PYTHON_VERSION).0.tar.xz -C $(@D)
cd $(@D)/Python-$(PYTHON_VERSION).0 && ./configure
# Converting blender environment to venv...
-mkdir -p $(@D)/$(BLENDER_VERSION)/python/include/python$(PYTHON_VERSION)
mv $(@D)/Python-$(PYTHON_VERSION).0/Include/*.h $(@D)/$(BLENDER_VERSION)/python/include/python$(PYTHON_VERSION)/
mv $(@D)/Python-$(PYTHON_VERSION).0/pyconfig.h $(@D)/$(BLENDER_VERSION)/python/include/python$(PYTHON_VERSION)/
-mkdir $(@D)/$(BLENDER_VERSION)/python/include/python$(PYTHON_VERSION)/cpython/
mv $(@D)/Python-$(PYTHON_VERSION).0/Include/cpython/*.h $(@D)/$(BLENDER_VERSION)/python/include/python$(PYTHON_VERSION)/cpython/
mv $(@D)/$(BLENDER_VERSION)/python $(@D)/$(BLENDER_VERSION)/python.bak
$(@D)/$(BLENDER_VERSION)/python.bak/bin/python$(PYTHON_VERSION) -m venv --prompt blender $(@D)/$(BLENDER_VERSION)/python
rsync -rv $(@D)/$(BLENDER_VERSION)/python.bak/lib/ $(@D)/$(BLENDER_VERSION)/python/lib/
rsync -rv $(@D)/$(BLENDER_VERSION)/python.bak/include/ $(@D)/$(BLENDER_VERSION)/python/include/
# Installing first-party addon...
echo blenderset > $(@D)/addons_to_enable
ln -s `pwd`/blenderset $(@D)/$(BLENDER_VERSION)/scripts/addons/
# Installing third-party addons...
echo cc3_blender_tools-$(CC3_VERSION) >> $(@D)/addons_to_enable
unzip $(<D)/cc3_blender_tools-$(CC3_VERSION).zip -d $(@D)/$(BLENDER_VERSION)/scripts/addons/
-for zip in custom_addons/*.zip; do unzip $$zip -d $(@D)/custom_addons/; done
-ls $(@D)/custom_addons >> $(@D)/addons_to_enable
-mv $(@D)/custom_addons/* $(@D)/$(BLENDER_VERSION)/scripts/addons/
-mkdir -p $(BLENDER_USER_SCRIPTS)
# Install dependencies
ln -s $(BLENDER_VERSION) $(@D)/current
. build/blender/current/python/bin/activate && $(MAKE) sync_env
# Enable addons
$(BLENDER) -b --python enable_addons.py
@touch $@
constraints.txt: $(wildcard requirements/*.txt)
pip-compile --strip-extras --allow-unsafe --output-file $@ $^ $(SILENT)
docker-build:
docker build -t blenderset .
docker-push: docker-build
docker tag blenderset $(DOCKER_REPO)
docker push $(DOCKER_REPO)
docker-run: docker-run-run
k8s-run: k8s-run-run
ASSETS_DIR=$(shell python -c 'import json, pathlib; print(json.load(open(pathlib.Path.home() / ".config/blenderset/config.json")).get("assets_dir", "../blenderset-assets"))')
METADATA_DIR=$(shell python -c 'import json, pathlib; print(json.load(open(pathlib.Path.home() / ".config/blenderset/config.json")).get("metadata_dir", pathlib.Path.cwd().parent / "blenderset-metadata"))')
RENDERS_DIR=$(shell python -c 'import json, pathlib; print(json.load(open(pathlib.Path.home() / ".config/blenderset/config.json")).get("renders_dir", pathlib.Path.cwd() / "renders"))')
docker-run-%:
docker run --rm --privileged --gpus all -v /dev:/dev -ti -u `id -u` \
-v $(ASSETS_DIR):/blenderset-assets \
-v $(METADATA_DIR):/blenderset-metadata/ \
-v $(RENDERS_DIR):/workdir/renders \
blenderset make run-enable_addons run-$*
TORCHX_GPU?=GTX1080
TORCHX_REPLICAS?=4
torchx-run-%:
torchx run --scheduler kubernetes utils.sh -h $(TORCHX_GPU) --num_replicas $(TORCHX_REPLICAS) \
--mounts type=bind,src=$(ASSETS_DIR),dst=/blenderset-assets,readonly,type=bind,src=$(RENDERS_DIR),dst=/workdir/renders,type=bind,src=$(METADATA_DIR),dst=/blenderset-metadata \
make run-enable_addons run-$*