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
return domain
def createFlow(origin):
# Добавление плоскости как потока
bpy.ops.mesh.primitive_plane_add(location = origin)
bpy.ops.transform.resize(value=(2, 2, 2))
flow = bpy.context.object flow.name = 'Flow'
# Добавление системы частиц дыма
pmod = flow.modifiers.new(name='SmokeParticles', type='PARTICLE_SYSTEM')
pmod.name = 'SmokeParticles'
psys = pmod.particle_system
psys.seed = 4711
# Настройки частиц
pset = psys.settings
pset.type = 'EMITTER'
pset.lifetime = 1
pset.emit_from = 'VOLUME'
pset.use_render_emitter = False
pset.render_type = 'NONE'
pset.normal_factor = 8.0
# Добавление модификатора дыма
smod = flow.modifiers.new(name='Smoke',
type='SMOKE')
smod.smoke_type = 'FLOW'
sfset = smod.flow_settings
# Настройки потока
sfset.use_outflow = False
sfset.temperature = 0.7
sfset.density = 0.8
sfset.initial_velocity = True
sfset.particle_system = psys
return flow
def createVortexEffector(origin):
bpy.ops.object.effector_add(type='VORTEX', location=origin)
vortex = bpy.context.object
return vortex
def createVoxelTexture(domain):
tex = bpy.data.textures.new('VoxelTex', type = 'VOXEL_DATA')
voxdata = tex.voxel_data
voxdata.file_format = 'SMOKE'
voxdata.domain_object = domain
return tex
def createVolumeMaterial(tex):
mat = bpy.data.materials.new('VolumeMat')
mat.type = 'VOLUME'
vol = mat.volume
vol.density = 0.0
vol.density_scale = 8.0
vol.scattering = 6.0
vol.asymmetry = 0.3
vol.emission = 0.3
vol.emission_color = (1,1,1)
vol.transmission_color = (0.9,0.2,0)
vol.reflection = 0.7
vol.reflection_color = (0.8,0.9,0)
# Для удаления эффекта пикселизации
vol.step_size = 0.05
# Добавление текстуры Voxel data
Читать дальше