Читаем Введение в написание скриптов на Питоне для Блендера 2.5x. Примеры кода полностью

def run(origin):

    # Удаление всех камер и ламп

    scn = bpy.context.scene

    for ob in scn.objects:

        if ob.type == 'CAMERA' or ob.type == 'LAMP':

            scn.objects.unlink(ob)


    # Добавление пустышки в середине всех визуализируемых объектов

    midpoint = findMidPoint()

    bpy.ops.object.add(

        type='EMPTY',

        location=midpoint),

    target = bpy.context.object

    target.name = 'Target'


    createCamera(origin+Vector((50,90,50)), target)

    createLamps(origin, target)

    return


if __name__ == "__main__":

    run(Vector((0,0,0)))



Мир, вид и рендер

Мир

Эта программа модифицирует настройки Мира. Изображение является рендером куба по-умолчанию со встроенной камерой и освещением.



#--------------------------------------------------

# File world.py

#--------------------------------------------------

import bpy 


def run():

    world = bpy.context.scene.world


    # Настройки Мира

    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)


    # Звёзды

    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


    # Окружающее освещение

    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)

    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


    # Установка текстуры как активной текстуры Мира

    world.active_texture = tex


    # Retrieve texture slot

    wtex = world.texture_slots[world.active_texture_index]

    print(wtex, world.active_texture_index)


    # Настройки текстурного слота

    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()


Вид и рендер

Эта программа модифицирует настройки рендера, переключается на экран по-умолчанию, и изменяет камеру в 3D-виде. В конце стартует анимация, к несчастью, в старом виде.


#----------------------------------------------------------

# File view.py

# Изменяет вид и настройки рендера

#----------------------------------------------------------

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

Перейти на страницу:

Похожие книги