Выбрать главу

    # Физика

    pset1.physics_type = 'NEWTON'

    pset1.mass = 2.5

    pset1.particle_size = 0.3

    pset1.use_multiply_size_mass = True  

    # Веса эффекторов

    ew = pset1.effector_weights

    ew.gravity = 1.0

    ew.wind = 1.0 

    # Дочерние частицы

    pset1.child_nbr = 10

    pset1.rendered_child_count = 10

    pset1.child_type = 'SIMPLE'  

    # Отображение и рендер

    pset1.draw_percentage = 100

    pset1.draw_method = 'CROSS'

    pset1.material = 1

    pset1.particle_size = 0.1

    pset1.render_type = 'HALO'

    pset1.render_step = 3 

    # ------------ Эффектор ветра ----- 

    # Добавление эффектора ветра

    bpy.ops.object.effector_add(

        type='WIND',

        enter_editmode=False,

        location = origin - Vector((0,3,0)),

        rotation = (-pi/2, 0, 0))

    wind = bpy.context.object  

    # Настройки полей

    fld = wind.field

    fld.strength = 2.3

    fld.noise = 3.2

    fld.flow = 0.3  

    # --- Система частиц 2: Обезьяны на ветру ---- 

    # Добавление обезьяны, используемой как объект размножения

    # Скрытие обезьяны в слое 2

    layers = 20*[False]

    layers[1] = True

    bpy.ops.mesh.primitive_monkey_add(

         location=origin+Vector((0,5,0)),

         rotation = (pi/2, 0, 0),

         layers = layers)

    monkey = bpy.context.object  

    #Добавление второй системы частиц

    bpy.context.scene.objects.active = emitter

    bpy.ops.object.particle_system_add()

    psys2 = emitter.particle_systems[-1]

    psys2.name = 'Monkeys'

    pset2 = psys2.settings

    pset2.name = 'MonkeySettings'  

    # Эмиссия, испускание

    pset2.count = 4

    pset2.frame_start = 1

    pset2.frame_end = 50

    pset2.lifetime = 250

    pset2.emit_from = 'FACE'

    pset2.use_render_emitter = True  

    # Скорость

    pset2.factor_random = 0.5  

    # Физика

    pset2.physics_type = 'NEWTON'

    pset2.brownian_factor = 0.5  

    # Веса эффекторов

    ew = pset2.effector_weights

    ew.gravity = 0

    ew.wind = 0.2 

    # Дочерние частицы

    pset2.child_nbr = 1

    pset2.rendered_child_count = 1

    pset2.child_size = 3

    pset2.child_type = 'SIMPLE'  

    # Отображение и рендер

    pset2.draw_percentage = 1

    pset2.draw_method = 'RENDER'

    pset2.dupli_object = monkey

    pset2.material = 1

    pset2.particle_size = 0.1

    pset2.render_type = 'OBJECT'

    pset2.render_step = 3

    return 

if __name__ == "__main__":

    bpy.ops.object.select_by_type(type='MESH')

    bpy.ops.object.delete()

    run((0,0,0))

    bpy.ops.screen.animation_play(reverse=False, sync=False)

Волосы

Эта программа добавляет сферу с волосами. Для волос строится шейдер типа strand.

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

# File hair.py

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

import bpy 

def createHead(origin):

# Добавление меша эмиттера

bpy.ops.mesh.primitive_ico_sphere_add(location=origin)

 ob = bpy.context.object

 bpy.ops.object.shade_smooth()  

    # Создание группы вершин scalp (скальп), а также добавление вершин и весов

    scalp = ob.vertex_groups.new('Scalp')

    for v in ob.data.vertices:

        z = v.co[2]

        y = v.co[1]

        if z > 0.3 or y > 0.3:

             w = 2*(z-0.3)

             if w > 1:

                 w = 1

             scalp.add([v.index], w, 'REPLACE')

    return ob 

def createMaterials(ob):

    # Некоторый материал для кожи

    skinmat = bpy.data.materials.new('Skin')

    skinmat.diffuse_color = (0.6,0.3,0)  

    # Материал strand для волос

    hairmat = bpy.data.materials.new('Strand')

    hairmat.diffuse_color = (0.2,0.04,0.0)

    hairmat.specular_intensity = 0  

    # Прозрачность

    hairmat.use_transparency = True

    hairmat.transparency_method = 'Z_TRANSPARENCY'

    hairmat.alpha = 0 

    # Strand. Нужно включить use Blender units перед заданием размеров.

    strand = hairmat.strand

    strand.use_blender_units = True

    strand.root_size = 0.01

    strand.tip_size = 0.0025

    strand.size_min = 0.001

    #strand.use_surface_diffuse = True # read-only

    strand.use_tangent_shading = True  

    # Текстура

    tex = bpy.data.textures.new('Blend', type = 'BLEND')

    tex.progression = 'LINEAR'

    tex.use_flip_axis = 'HORIZONTAL'  

    # Создание цветовой полосы для цвета и альфа-канала

    tex.use_color_ramp = True

    tex.color_ramp.interpolation = 'B_SPLINE'

    # Точки на цветовой полосе: (pos, rgba)

    # Не знаю, как добавлять точки на полосу

    rampTable = [

        (0.0, (0.23,0.07,0.03,0.75)),