Last active
July 25, 2018 10:51
-
-
Save iCyP/5908789 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blender用スクリプト。使用したこと等による損害等一切無保証、自己責任でどうぞ | |
使い方 | |
1 .下記スクリプトのresolution,frames,outPutPassesをよしなに書き換える | |
※とりあえず 初期のまま、デスクトップにでもuntitle.blendを保存して、それで試して見ることをおすすめします。 | |
以下a,b好きな方で | |
2a. cmdなりPowerShellなりBashなりZshなりで ./blender.exe -b <ここにレンダリングしたい*.blendのパス> -P resourceRenderScript.py (->このスクリプトのあるパス) | |
2b. blenderでレンダリングしたい *.blend を開いて、blenderのテキストエディタにこれを貼り付けてAlt+P | |
3. *.blendと同じフォルダに、同じ名前でフォルダが作られ、その中に結果が入ります。 | |
注意 | |
2.67で書いたので、他では動作しない可能性(特により古いバージョンで) | |
ノードの"Render Layers"の名前や中身が変わってると多分動作しません->'Render Layers'とかを書き換えたら動くかも | |
レンダーレイヤーも同じく名前が変わってると動作しないです。ー>'RenderLayer'を任意の文字列を' 'でくくったやつで置き換えると良いかも | |
拡張子は.blend依存・・・気が向けばどうにかするかも、 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import os | |
# write with version 2.79b' | |
####### please change here ########### | |
resolution = ( | |
(400,300),#1st resolution (x,y) | |
(800,600), #2nd resolution (x,y) | |
(400,800) #3rd resolution (x,y) | |
) | |
frames = ( | |
(0,10),#1st renderFrame (start,end) | |
(10,20),#2nd renderFrame | |
(0,15) #3rd ry | |
) | |
outputPasses = ( | |
#for c&p | |
#"Combined" "Z" "Vector" "Normal" "UV" "Mist" "Object Index" "Material Index" | |
#"Color" "Diffuse" "Specular" "Shadow" "Emit" "AO" "Environment" "Indirect" "Reflection" "Refraction" | |
("Combined","Color"), #1st renderPass("foo","bar","hoge") | |
("Normal","Vector","AO"), #2nd renderPass, | |
("Combined","Z","Vector","Normal","UV","Mist","Object Index","Material Index", | |
"Color","Diffuse","Specular","Shadow","Emit","AO","Environment","Indirect","Reflection","Refraction" | |
)#3rd renderPass-allPasses | |
) | |
############don't touch!################## | |
def passSwitcher(passNode,layer): | |
if passNode == "Combined": | |
layer.use_pass_combined = True | |
if passNode == "Z": | |
layer.use_pass_z = True | |
if passNode == "Vector": | |
layer.use_pass_vector = True | |
if passNode == "Normal": | |
layer.use_pass_normal = True | |
if passNode == "UV": | |
layer.use_pass_uv = True | |
if passNode == "Mist": | |
layer.use_pass_mist = True | |
if passNode == "Object Index": | |
layer.use_pass_object_index = True | |
if passNode == "Material Index": | |
layer.use_pass_material_index = True | |
if passNode == "Color": | |
layer.use_pass_color = True | |
if passNode == "Diffuse": | |
layer.use_pass_diffuse = True | |
if passNode == "Specular": | |
layer.use_pass_specular = True | |
if passNode == "Shadow": | |
layer.use_pass_shadow = True | |
if passNode == "Emit": | |
layer.use_pass_emit = True | |
if passNode == "AO": | |
layer.use_pass_ambient_occlusion = True | |
if passNode == "Environment": | |
layer.use_pass_environment = True | |
if passNode == "Indirect": | |
layer.use_pass_indirect = True | |
if passNode == "Reflection": | |
layer.use_pass_reflection = True | |
if passNode == "Refraction": | |
layer.use_pass_refraction = True | |
def passInitializer(layer): | |
layer.use_pass_combined = False | |
layer.use_pass_z = False | |
layer.use_pass_vector = False | |
layer.use_pass_normal = False | |
layer.use_pass_uv = False | |
layer.use_pass_mist = False | |
layer.use_pass_object_index = False | |
layer.use_pass_material_index = False | |
layer.use_pass_color = False | |
layer.use_pass_diffuse = False | |
layer.use_pass_specular = False | |
layer.use_pass_shadow = False | |
layer.use_pass_emit = False | |
layer.use_pass_ambient_occlusion = False | |
layer.use_pass_environment = False | |
layer.use_pass_indirect = False | |
layer.use_pass_reflection = False | |
layer.use_pass_refraction = False | |
def replacer(input): | |
if input == "Combined": | |
return "Image" | |
elif input =="Z": | |
return "Depth" | |
elif input =="Specular": | |
return "Spec" | |
elif input == "Reflection": | |
return "Reflect" | |
elif input == "Refraction": | |
return "Refract" | |
elif input == "Object Index": | |
return "IndexOB" | |
elif input == "Material Index": | |
return "IndexMA" | |
elif input == "Environment": | |
return "Env" | |
else : | |
return input | |
def passRouter(needPath,filePath): | |
renderLayer = bpy.context.scene.render.layers['RenderLayer'] | |
fileOutNodes = [] | |
passInitializer(renderLayer) | |
for i in needPath: | |
passSwitcher(i,renderLayer) | |
fileoutNode = bpy.context.scene.node_tree.nodes.new("CompositorNodeOutputFile") | |
#right causes bug so write under bpy.ops.node.output_file_add_socket(file_path= filePath +"/"+ i) | |
fileoutNode.base_path = os.path.join(filePath,i) | |
fileoutNode.file_slots[0].path = i | |
fileOutNodes.append(fileoutNode) | |
i = replacer(i) | |
render = bpy.context.scene.node_tree.nodes['Render Layers'].outputs[i] | |
bpy.context.scene.node_tree.links.new(render,fileoutNode.inputs[0]) | |
return fileOutNodes | |
def flushNodes(outputNodes): | |
for n in outputNodes: | |
bpy.context.scene.node_tree.nodes.remove(n) | |
def main(): | |
fileName = bpy.path.display_name_from_filepath( bpy.data.filepath) | |
fileDir = os.path.dirname(bpy.data.filepath) | |
saveDir = os.path.join(fileDir,fileName) | |
if not os.path.exists(saveDir): | |
os.mkdir(saveDir) | |
this_scene = bpy.context.scene | |
this_scene.render.resolution_percentage = 100 | |
this_scene.use_nodes = True | |
for r,f,o in zip(resolution,frames,outputPasses): | |
#set render settings | |
this_scene.render.resolution_x = r[0] | |
this_scene.render.resolution_y = r[1] | |
this_scene.frame_start = f[0] | |
this_scene.frame_end = f[1] | |
saveName = fileName + str(r[0]) + "x"+ str(r[1])+"_" | |
savePath = os.path.join(saveDir, saveName) | |
this_scene.render.filepath = savePath +os.sep | |
#set resources setting | |
resourcePath = os.path.join(saveDir, fileName + str(r[0]) + "x"+ str(r[1]) ) | |
outputNodes = passRouter(o,resourcePath) | |
#start rendering | |
bpy.ops.render.render(animation=True) | |
flushNodes(outputNodes) | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment