Last active
December 12, 2015 02:28
-
-
Save keot/4698900 to your computer and use it in GitHub Desktop.
Minecraft Blender parameters for automated rendering of chunks from jMc2Obj.
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, math | |
object_file = "%%OBJ%%" # complete path | |
output_file = "%%PNG%%" # use "//filename.ext" for local path | |
# Clean canvas | |
for object in bpy.data.objects: | |
object.select = True | |
bpy.ops.object.delete() | |
# Import the mc2obj file | |
bpy.ops.import_scene.obj(filepath = object_file) | |
bpy.data.objects["Mesh"].select = True | |
# Fix transparency of materials | |
for item in bpy.data.materials: | |
item.use_transparent_shadows = True | |
if (item.alpha < 1.0): | |
item.use_transparency = True | |
item.transparency_method = "RAYTRACE" | |
else: | |
item.use_transparency = False | |
# Fix textures (may return an error for some) | |
for item in bpy.data.textures: | |
if item.type == 'IMAGE': | |
item.filter_type = 'BOX' | |
item.filter_size = 0.1 | |
# Create emitters | |
half_lights = ["lava", "lava_flowing", "redstone_torch_on", "restone_dust_on", "redstone_wire_on", "rails_powered_on"] | |
full_lights = ["torch_flame", "fire", "redstone_lamp_on", "glowstone"] | |
for light in half_lights: | |
if light in bpy.data.materials: | |
bpy.data.materials[light].emit = 1.0 | |
for light in full_lights: | |
if light in bpy.data.materials: | |
bpy.data.materials[light].emit = 2.0 | |
# Add a camera to the scene | |
bpy.ops.object.camera_add(location = (-16, -16, 128), rotation = (math.pi / 12, 0, 0 - math.pi / 4) ) # radians | |
bpy.context.scene.camera = bpy.data.objects['Camera'] # set the camera otherwise you can't edit it | |
bpy.data.scenes["Scene"].camera.data.lens = 12 # 10 mm lens | |
# Configure lighting | |
#bpy.ops.object.lamp_add(type = "SUN", location = (96,-64,96) ) | |
#bpy.data.lamps['Sun'].energy = 0.5 | |
#bpy.data.lamps['Sun'].shadow_method = "RAY_SHADOW" | |
#bpy.data.lamps['Sun'].shadow_ray_samples = 8 # enough? | |
bpy.data.scenes["Scene"].world.light_settings.use_environment_light = True | |
bpy.data.scenes["Scene"].world.light_settings.environment_energy = 0.0625 | |
bpy.data.scenes["Scene"].world.light_settings.use_indirect_light = True | |
bpy.data.scenes["Scene"].world.light_settings.indirect_factor = 25.0 | |
bpy.data.scenes["Scene"].world.light_settings.indirect_bounces = 4 | |
bpy.data.scenes["Scene"].world.light_settings.gather_method = 'APPROXIMATE' | |
bpy.data.scenes["Scene"].world.light_settings.passes = 0 | |
bpy.data.scenes["Scene"].world.light_settings.use_falloff = True | |
bpy.data.scenes["Scene"].world.light_settings.falloff_strength = 0.0625 | |
# Configure the output | |
bpy.data.scenes["Scene"].render.resolution_x = 1920 | |
bpy.data.scenes["Scene"].render.resolution_y = 1080 | |
bpy.data.scenes["Scene"].render.resolution_percentage = 100 | |
bpy.data.scenes["Scene"].render.filepath = output_file | |
bpy.data.scenes["Scene"].render.use_antialiasing = True | |
bpy.data.scenes["Scene"].render.antialiasing_samples = '8' | |
# Depth of field | |
# Configure compositing nodes | |
bpy.data.scenes["Scene"].use_nodes = True | |
tree = bpy.context.scene.node_tree | |
# Add/reference the nodes | |
df = tree.nodes.new('DEFOCUS') | |
rendering = tree.nodes['Render Layers'] | |
compositing = tree.nodes['Composite'] | |
# Join them up | |
tree.links.new(rendering.outputs[0], df.inputs[0]) # Image | |
tree.links.new(rendering.outputs[2], df.inputs[1]) # Z | |
tree.links.new(df.outputs[0], compositing.inputs[0]) # Image | |
# Configure defocusing | |
bpy.data.scenes["Scene"].camera.data.dof_distance = 64 | |
df.bokeh = 'CIRCLE' | |
df.f_stop = 1.0 | |
df.use_zbuffer = True | |
df.use_preview = False | |
df.samples = 32 # preview sometimes ignored | |
# Do work | |
bpy.ops.render.render(write_still = True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Camera lens setting is failing, and for some reason the GUI displays angles in degrees, but the software works in radians. Conversion needed.