Dev:Py/Scripts/Cookbook/Code snippets/World view renderer
< Dev:Py | Scripts | Cookbook | Code snippets
2015年12月28日 (月) 04:24時点におけるwiki>Brechtによる版 (moved Dev:2.5/Py/Scripts/Cookbook/Code snippets/World view renderer to Dev:Py/Scripts/Cookbook/Code snippets/World view renderer: remove version namespace)
World, view and render
World
This program modifies the world settings. The picture is a rendering of the default cube with the default camera and lighting.
#--------------------------------------------------
# File world.py
#--------------------------------------------------
import bpy
def run():
world = bpy.context.scene.world
# World settings
world.use_sky_blend = True
world.ambient_color = (0.05, 0, 0)
world.horizon_color = (0, 0, 0.2)
world.zenith_color = (0.04, 0, 0.04)
# Stars
sset = world.star_settings
sset.use_stars = True
sset.average_separation = 17.8
sset.color_random = 1.0
sset.distance_min = 0.7
sset.size = 10
# Environment lighting
wset = world.light_settings
wset.use_environment_light = True
wset.use_ambient_occlusion = True
wset.ao_blend_type = 'MULTIPLY'
wset.ao_factor = 0.8
wset.gather_method = 'APPROXIMATE'
# Clouds texture
tex = bpy.data.textures.new('Clouds', type = 'CLOUDS')
tex.cloud_type = 'GREYSCALE'
tex.noise_type = 'SOFT_NOISE'
tex.noise_basis = 'ORIGINAL_PERLIN'
tex.noise_scale = 0.06
tex.noise_depth = 1
# Set texture as active world texture
world.active_texture = tex
# Retrieve texture slot
wtex = world.texture_slots[world.active_texture_index]
print(wtex, world.active_texture_index)
# Texture slot settings
wtex.use_map_blend = False
wtex.use_map_horizon = False
wtex.use_map_zenith_down = False
wtex.use_map_zenith_up = True
wtex.color = (1,1,1)
wtex.texture_coords = 'VIEW'
wtex.zenith_up_factor = 1.0
return
if __name__ == "__main__":
run()
View ad render
This program modifies the render settings, switches to the Default screen, and changes to Camera viewport. Finally the animation is started, unfortunately in the old view.
#----------------------------------------------------------
# File view.py
# Changes the view and render settings
#----------------------------------------------------------
import bpy
def setRenderSettings():
render = bpy.context.scene.render
render.resolution_x = 720
render.resolution_y = 576
render.resolution_percentage = 100
render.fps = 24
render.use_raytrace = False
render.use_color_management = True
render.use_sss = False
return
def setDefaultCameraView():
for scrn in bpy.data.screens:
if scrn.name == 'Default':
bpy.context.window.screen = scrn
for area in scrn.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
space.viewport_shade = 'SOLID'
reg = space.region_3d
reg.view_perspective = 'CAMERA'
break
return
def run():
setRenderSettings()
setDefaultCameraView()
# Start animation, unfortunately in the old view
bpy.ops.screen.animation_play(reverse=False, sync=False)
return
if __name__ == "__main__":
run()