rename IOHelperOrientation -> OrientationHelper
[blender-addons.git] / render_renderfarmfi / prepare.py
blob6777063500337d23969e1c0f1e76aa9e0771b718
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 import bpy
20 import os
22 def hasSSSMaterial():
23 for m in bpy.data.materials:
24 if m.subsurface_scattering.use:
25 return True
26 return False
28 def tuneParticles():
29 for p in bpy.data.particles:
30 if (p.type == 'EMITTER'):
31 bpy.particleBakeWarning = True
32 if (p.type == 'HAIR'):
33 if (p.child_type == 'SIMPLE'):
34 p.child_type = 'INTERPOLATED'
35 bpy.childParticleWarning = True
37 def hasParticleSystem():
38 if (len(bpy.data.particles) > 0):
39 print("Found particle system")
40 return True
41 return False
43 def hasSimulation(t):
44 for o in bpy.data.objects:
45 for m in o.modifiers:
46 if isinstance(m, t):
47 print("Found simulation: " + str(t))
48 return True
49 return False
51 def hasFluidSimulation():
52 return hasSimulation(bpy.types.FluidSimulationModifier)
54 def hasSmokeSimulation():
55 return hasSimulation(bpy.types.SmokeModifier)
57 def hasClothSimulation():
58 return hasSimulation(bpy.types.ClothModifier)
60 def hasCollisionSimulation():
61 return hasSimulation(bpy.types.CollisionModifier)
63 def hasSoftbodySimulation():
64 return hasSimulation(bpy.types.SoftBodyModifier)
66 def hasUnsupportedSimulation():
67 return hasSoftbodySimulation() or hasCollisionSimulation() or hasClothSimulation() or hasSmokeSimulation() or hasFluidSimulation()
69 def isFilterNode(node):
70 t = type(node)
71 return t==bpy.types.CompositorNodeBlur or t==bpy.types.CompositorNodeDBlur
73 def changeSettings():
75 sce = bpy.context.scene
76 rd = sce.render
77 ore = sce.ore_render
79 # Necessary settings for BURP
80 rd.resolution_x = ore.resox
81 rd.resolution_y = ore.resoy
82 sce.frame_start = ore.start
83 sce.frame_end = ore.end
84 rd.fps = ore.fps
86 bpy.file_format_warning = False
87 bpy.simulationWarning = False
88 bpy.texturePackError = False
89 bpy.particleBakeWarning = False
90 bpy.childParticleWarning = False
92 if (rd.image_settings.file_format == 'HDR'):
93 rd.image_settings.file_format = 'PNG'
94 bpy.file_format_warning = True
96 # Convert between Blender's image format and BURP's formats
97 if (rd.image_settings.file_format == 'PNG'):
98 ore.file_format = 'PNG_FORMAT'
99 elif (rd.image_settings.file_format == 'OPEN_EXR'):
100 ore.file_format = 'EXR_FORMAT'
101 elif (rd.image_settings.file_format == 'OPEN_EXR_MULTILAYER'):
102 ore.file_format = 'EXR_MULTILAYER_FORMAT'
103 elif (rd.image_settings.file_format == 'HDR'):
104 ore.file_format = 'PNG_FORMAT'
105 else:
106 ore.file_format = 'PNG_FORMAT'
108 if (ore.engine == 'cycles'):
109 bpy.context.scene.cycles.samples = ore.samples
111 if (ore.subsamples <= 0):
112 ore.subsamples = 1
114 if (ore.samples / ore.subsamples < 100.0):
115 ore.subsamples = float(ore.samples) / 100.0
117 # Multipart support doesn' work if SSS is used
118 if ((rd.use_sss == True and hasSSSMaterial()) and ore.parts > 1):
119 ore.parts = 1;
121 if (hasParticleSystem()):
122 tuneParticles()
123 else:
124 bpy.particleBakeWarning = False
125 bpy.childParticleWarning = False
127 if (hasUnsupportedSimulation()):
128 bpy.simulationWarning = True
129 else:
130 bpy.simulationWarning = False
132 def _prepare_scene():
133 changeSettings()
135 print("Packing external textures...")
136 try:
137 bpy.ops.file.pack_all()
138 bpy.texturePackError = False
139 except Exception as e:
140 bpy.texturePackError = True
141 print(e)
143 linkedData = bpy.utils.blend_paths()
144 if (len(linkedData) > 0):
145 print("Appending linked .blend files...")
146 try:
147 bpy.ops.object.make_local(type='ALL')
148 bpy.linkedFileError = False
149 except Exception as e:
150 bpy.linkedFileError = True
151 print(e)
152 else:
153 print("No external .blends used, skipping...")
155 # Save with a different name
156 print("Saving into a new file...")
157 try:
158 bpy.originalFileName = bpy.data.filepath
159 except:
160 bpy.originalFileName = 'untitled.blend'
161 print("Original path is " + bpy.originalFileName)
162 try:
163 # If the filename is empty, we'll make one from the path of the user's resource folder
164 if (len(bpy.originalFileName) == 0):
165 print("No existing file path found, saving to autosave directory")
166 savePath = bpy.utils.user_resource("AUTOSAVE")
167 try:
168 os.mkdir(savePath)
169 except Exception as ex:
170 print(ex)
171 try:
172 savePath = savePath + "_renderfarm"
173 except Exception as ex:
174 print(ex)
175 try:
176 bpy.ops.wm.save_mainfile(filepath=savePath)
177 except Exception as ex:
178 print(ex)
179 else:
180 print("Saving to current .blend directory")
181 savePath = bpy.originalFileName
182 savePath = savePath + "_renderfarm.blend"
183 bpy.ops.wm.save_mainfile(filepath=savePath)
184 except Exception as e:
185 print(e)
187 print(".blend prepared")