Thomas Larsson - Введение в написание скриптов на Питоне для Блендера 2.5x. Примеры кода
- Название:Введение в написание скриптов на Питоне для Блендера 2.5x. Примеры кода
- Автор:
- Жанр:
- Издательство:неизвестно
- Год:неизвестен
- ISBN:нет данных
- Рейтинг:
- Избранное:Добавить в избранное
-
Отзывы:
-
Ваша оценка:
Thomas Larsson - Введение в написание скриптов на Питоне для Блендера 2.5x. Примеры кода краткое содержание
Третье издание, расширенное и обновлённое для Blender 2.57
Введение в написание скриптов на Питоне для Блендера 2.5x. Примеры кода - читать онлайн бесплатно полную версию (весь текст целиком)
Интервал:
Закладка:
bpy.ops.mesh.primitive_plane_add(location=origin)
emitter = bpy.context.object
bpy.ops.mesh.uv_texture_add()
return emitter
def createFire(emitter):
# Добавление первой системы частиц — огня
bpy.context.scene.objects.active = emitter
bpy.ops.object.particle_system_add()
fire = emitter.particle_systems[-1]
fire.name = 'Fire'
fset = fire.settings
# Эмиссия
fset.name = 'FireSettings'
fset.count = 100
fset.frame_start = 1
fset.frame_end = 200
fset.lifetime = 70
fset.lifetime_random = 0.2
fset.emit_from = 'FACE'
fset.use_render_emitter = False
fset.distribution = 'RAND'
fset.object_align_factor = (0,0,1)
# Скорость
fset.normal_factor = 0.55
fset.factor_random = 0.5
# Физика
fset.physics_type = 'NEWTON'
fset.mass = 1.0
fset.particle_size = 10.0
fset.use_multiply_size_mass = False
# Веса эффекторов
ew = fset.effector_weights
ew.gravity = 0.0 ew.wind = 1.0
# Отображение и рендер
fset.draw_percentage = 100
fset.draw_method = 'RENDER'
fset.material = 1
fset.particle_size = 0.3
fset.render_type = 'BILLBOARD'
fset.render_step = 3
# Дочерние частицы
fset.child_type = 'SIMPLE'
fset.rendered_child_count = 50
fset.child_radius = 1.1
fset.child_roundness = 0.5 return fire
def createSmoke(emitter):
# Добавление второй системы частиц — дыма
bpy.context.scene.objects.active = emitter
bpy.ops.object.particle_system_add()
smoke = emitter.particle_systems[-1]
smoke.name = 'Smoke' sset = smoke.settings
# Эмиссия
sset.name = 'FireSettings'
sset.count = 100
sset.frame_start = 1
sset.frame_end = 100
sset.lifetime = 70
sset.lifetime_random = 0.2
sset.emit_from = 'FACE'
sset.use_render_emitter = False
sset.distribution = 'RAND'
# Скорость
sset.normal_factor = 0.0
sset.factor_random = 0.5
# Физика
sset.physics_type = 'NEWTON'
sset.mass = 2.5
sset.particle_size = 0.3
sset.use_multiply_size_mass = True
# Веса эффекторов
ew = sset.effector_weights
ew.gravity = 0.0
ew.wind = 1.0
# Отображение и рендер
sset.draw_percentage = 100
sset.draw_method = 'RENDER'
sset.material = 2
sset.particle_size = 0.5
sset.render_type = 'BILLBOARD'
sset.render_step = 3
# Дочерние частицы
sset.child_type = 'SIMPLE'
sset.rendered_child_count = 50
sset.child_radius = 1.6 return smoke
def createWind(origin):
# Создание ветра
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
return wind
def createColorRamp(tex, values):
# Создание цветовой полосы
tex.use_color_ramp = True
ramp = tex.color_ramp
for n,value in enumerate(values):
elt = ramp.elements[n]
(pos, color) = value
elt.position = pos
elt.color = color
return
def createFlameTexture():
tex = bpy.data.textures.new('Flame', type = 'CLOUDS')
createColorRamp(tex, [(0.2, (1,0.5,0.1,1)), (0.8, (0.5,0,0,0))])
tex.noise_type = 'HARD_NOISE'
tex.noise_scale = 0.7
tex.noise_depth = 5
return tex
def createStencilTexture():
tex = bpy.data.textures.new('Stencil', type = 'BLEND')
tex.progression = 'SPHERICAL'
createColorRamp(tex, [(0.0, (0,0,0,0)), (0.85, (1,1,1,0.6))])
return tex
def createEmitTexture():
tex = bpy.data.textures.new('Emit',
type = 'BLEND')
tex.progression = 'LINEAR'
createColorRamp(tex, [(0.1, (1,1,0,1)), (0.3, (1,0,0,1))])
return tex
def createSmokeTexture():
tex = bpy.data.textures.new('Smoke', type = 'CLOUDS')
createColorRamp(tex, [(0.2, (0,0,0,1)), (0.6, (1,1,1,1))])
tex.noise_type = 'HARD_NOISE'
tex.noise_scale = 1.05
tex.noise_depth = 5
return tex
def createFireMaterial(textures, objects):
(flame, stencil, emit) = textures
(emitter, empty) = objects
mat = bpy.data.materials.new('Fire')
mat.specular_intensity = 0.0
mat.use_transparency = True
mat.transparency_method = 'Z_TRANSPARENCY'
mat.alpha = 0.0
mat.use_raytrace = False
mat.use_face_texture = True
mat.use_shadows = False
mat.use_cast_buffer_shadows = True
mtex = mat.texture_slots.add()
mtex.texture = emit
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = True
mtex = mat.texture_slots.add()
mtex.texture = stencil
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = False
mtex.use_map_emit = True
mtex.use_stencil = True
mtex = mat.texture_slots.add()
mtex.texture = flame
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = True
mtex.use_map_alpha = True
#mtex.object = empty
return mat
def createSmokeMaterial(textures, objects):
(smoke, stencil) = textures
(emitter, empty) = objects
mat = bpy.data.materials.new('Smoke')
mat.specular_intensity = 0.0
mat.use_transparency = True
mat.transparency_method = 'Z_TRANSPARENCY'
mat.alpha = 0.0
mat.use_raytrace = False
mat.use_face_texture = True
mat.use_shadows = True
mat.use_cast_buffer_shadows = True
mtex = mat.texture_slots.add()
mtex.texture = stencil
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = False
mtex.use_map_alpha = True
mtex.use_stencil = True
mtex = mat.texture_slots.add()
mtex.texture = smoke
mtex.texture_coords = 'OBJECT'
mtex.object = empty return mat
def run(origin):
emitter = createEmitter(origin)
#wind = createWind()
bpy.ops.object.add(type='EMPTY')
empty = bpy.context.object
fire = createFire(emitter)
flameTex = createFlameTexture()
stencilTex = createStencilTexture()
emitTex = createEmitTexture()
flameMat = createFireMaterial(
(flameTex, stencilTex, emitTex),
(emitter, empty))
emitter.data.materials.append(flameMat)
smoke = createSmoke(emitter
)
smokeTex = createSmokeTexture()
smokeMat = createSmokeMaterial(
(smokeTex, stencilTex), (emitter, empty))
emitter.data.materials.append(smokeMat)
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)
Эта программа создает симуляцию дыма и присваивает воксельный материал.

#----------------------------------------------------------
# File smoke.py
# Создание дыма и материала дыма.
# Вдохновлен этим учебником Эндрю Прайса:
# http://www.blenderguru.com/introduction-to-smoke-simulation/
#----------------------------------------------------------
import bpy, mathutils, math
from mathutils import Vector
from math import pi
def createDomain(origin):
# Добавление куба в качестве домена
bpy.ops.mesh.primitive_cube_add(location=origin
)
bpy.ops.transform.resize(value=(4, 4, 4))
domain = bpy.context.object domain.name = 'Domain'
# Добавление домену модификатора
dmod = domain.modifiers.new(name='Smoke', type='SMOKE')
dmod.smoke_type = 'DOMAIN'
dset = dmod.domain_settings
# Настройки домена
dset.resolution_max = 32
dset.alpha = -0.001
dset.beta = 2.0
dset.time_scale = 1.2
dset.vorticity = 2.0
dset.use_dissolve_smoke = True
dset.dissolve_speed = 80
dset.use_dissolve_smoke_log = True
dset.use_high_resolution = True
dset.show_high_resolution = True
# Веса эффекторов
ew = dset.effector_weights
ew.gravity = 0.4
ew.force = 0.8
Интервал:
Закладка: