Newer
Older
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
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program 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 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import sys, os
import subprocess
import bpy
from netrender.utils import *
BLENDER_PATH = sys.argv[0]
def reset(job):
main_file = job.files[0]
job_full_path = main_file.filepath
if os.path.exists(job_full_path + ".bak"):
os.remove(job_full_path) # repathed file
os.renames(job_full_path + ".bak", job_full_path)
def update(job):
paths = []
main_file = job.files[0]
job_full_path = main_file.filepath
path, ext = os.path.splitext(job_full_path)
new_path = path + ".remap" + ext
# Disable for now. Partial repath should work anyway
#all = main_file.filepath != main_file.original_path
all = False
for rfile in job.files[1:]:
if all or rfile.original_path != rfile.filepath:
paths.append(rfile.original_path)
paths.append(rfile.filepath)
# Only update if needed
if paths:
process = subprocess.Popen([BLENDER_PATH, "-b", "-noaudio", job_full_path, "-P", __file__, "--", new_path] + paths, stdout=sys.stdout, stderr=subprocess.STDOUT)
process.wait()
os.renames(job_full_path, job_full_path + ".bak")
os.renames(new_path, job_full_path)
def process(paths):
def processPointCache(ob, point_cache):
if not point_cache.use_disk_cache:
return
cache_name = cacheName(ob, point_cache)
new_path = path_map.get(cache_name, None)
if new_path:
point_cache.use_external = True
point_cache.filepath = new_path
point_cache.name = cache_name
def processFluid(fluid):
new_path = path_map.get(fluid.filepath, None)
if new_path:
fluid.path = new_path
path_map = {}
for i in range(0, len(paths), 2):
# special case for point cache
if paths[i].endswith(".bphys"):
path, filename = os.path.split(paths[i+1])
cache_name = filename.split("_")[0]
path_map[cache_name] = path
# special case for fluids
elif paths[i].endswith(".bobj.gz"):
path_map[os.path.split(paths[i])[0]] = os.path.split(paths[i+1])[0]
else:
path_map[os.path.split(paths[i])[1]] = paths[i+1]
# TODO original paths aren't really the original path, they are the normalized path
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
# so we repath using the filenames only.
###########################
# LIBRARIES
###########################
for lib in bpy.data.libraries:
file_path = bpy.path.abspath(lib.filepath)
new_path = path_map.get(os.path.split(file_path)[1], None)
if new_path:
lib.filepath = new_path
###########################
# IMAGES
###########################
for image in bpy.data.images:
if image.source == "FILE" and not image.packed_file:
file_path = bpy.path.abspath(image.filepath)
new_path = path_map.get(os.path.split(file_path)[1], None)
if new_path:
image.filepath = new_path
###########################
# FLUID + POINT CACHE
###########################
for object in bpy.data.objects:
for modifier in object.modifiers:
if modifier.type == 'FLUID_SIMULATION' and modifier.settings.type == "DOMAIN":
elif modifier.type == "SMOKE" and modifier.smoke_type == "DOMAIN":
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
processPointCache(modifier.domain_settings.point_cache_low)
if modifier.domain_settings.use_high_resolution:
processPointCache(modifier.domain_settings.point_cache_high)
elif modifier.type == "MULTIRES" and modifier.is_external:
file_path = bpy.path.abspath(modifier.filepath)
new_path = path_map.get(file_path, None)
if new_path:
modifier.filepath = new_path
# particles modifier are stupid and don't contain data
# we have to go through the object property
for psys in object.particle_systems:
processPointCache(psys.point_cache)
if __name__ == "__main__":
try:
i = sys.argv.index("--")
except:
i = 0
if i:
new_path = sys.argv[i+1]
args = sys.argv[i+2:]
process(args)
bpy.ops.wm.save_as_mainfile(filepath=new_path, check_existing=False)