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
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
mtex = mat.texture_slots.add()
mtex.texture = tex
mtex.texture_coords = 'ORCO'
mtex.use_map_density = True
mtex.use_map_emission = True
mtex.use_map_scatter = False
mtex.use_map_reflect = True
mtex.use_map_color_emission = True
mtex.use_map_color_transmission = True
mtex.use_map_color_reflection = True
mtex.density_factor = 1.0
mtex.emission_factor = 0.2
mtex.scattering_factor = 0.2
mtex.reflection_factor = 0.3
mtex.emission_color_factor = 0.9
mtex.transmission_color_factor = 0.5
mtex.reflection_color_factor = 0.6
return mat
def addFloor(origin):
# Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΏΠΎΠ»Π°, ΠΊΠΎΡΠΎΡΡΠΉ ΠΏΡΠΈΠ½ΠΈΠΌΠ°Π΅Ρ ΠΏΡΠΎΠ·ΡΠ°ΡΠ½ΡΠ΅ ΡΠ΅Π½ΠΈ
bpy.ops.mesh.primitive_plane_add(
location = origin,
rotation = (0, 0, pi/4))
bpy.ops.transform.resize(value=(4, 4, 4))
bpy.ops.transform.resize(value=(2, 2, 2),
constraint_axis=(True, False, False),
constraint_orientation='LOCAL')
floor = bpy.context.object
mat = bpy.data.materials.new('Floor')
mat.use_transparent_shadows = True
floor.data.materials.append(mat)
return
def setupWorld():
scn = bpy.context.scene
# Π‘ΠΈΠ½Π΅Π΅ blend (ΡΠΌΠ΅ΡΠ°Π½Π½ΠΎΠ΅) Π½Π΅Π±ΠΎ
scn.world.use_sky_blend = True
scn.world.horizon_color = (0.25, 0.3, 0.4)
scn.world.zenith_color = (0, 0, 0.7)
# PAL 4:3 render
scn.render.resolution_x = 720
scn.render.resolution_y = 567
return
def run(origin):
domain = createDomain(origin)
flow = createFlow(origin-Vector((0,0,3.5)))
vortex = createVortexEffector(origin)
tex = createVoxelTexture(domain)
mat = createVolumeMaterial(tex)
domain.data.materials.append(mat)
return
if __name__ == "__main__":
for ob in bpy.context.scene.objects:
bpy.context.scene.objects.unlink(ob)
addFloor(Vector((0,0,-4)))
setupWorld()
# ΠΡΠ²Π΅ΡΠ΅Π½ΠΈΠ΅ ΠΈ ΠΊΠ°ΠΌΠ΅ΡΠ°
bpy.ops.object.lamp_add( type = 'POINT', location=(4,6,1))
bpy.ops.object.lamp_add( type = 'POINT', location=(-7,-5,0))
bpy.ops.object.camera_add(location=Vector((8,-8,3)),
rotation=(pi/3, 0, pi/6))
run(Vector((0,0,0)))
bpy.ops.screen.animation_play()
ΠΡΠ° ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ° ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅Ρ ΠΈΠ³ΡΠΎΠ²ΠΎΠΉ Π΄Π²ΠΈΠΆΠΎΠΊ ΠΠ»Π΅Π½Π΄Π΅ΡΠ° Π΄Π»Ρ ΠΌΠΎΠ΄Π΅Π»ΠΈΡΠΎΠ²Π°Π½ΠΈΡ ΠΏΠ°Π΄Π΅Π½ΠΈΡ ΠΊΡΡΠΈ ΠΎΠ±ΡΠ΅ΠΊΡΠΎΠ² Π½Π° Π·Π΅ΠΌΠ»Ρ. ΠΠ½ΠΈΠΌΠ°ΡΠΈΠΈ Π·Π°ΠΏΠΈΡΡΠ²Π°ΡΡΡΡ ΠΈ Π²ΠΏΠΎΡΠ»Π΅Π΄ΡΡΠ²ΠΈΠΈ ΠΌΠΎΠ³ΡΡ Π±ΡΡΡ Π²ΠΎΡΠΏΡΠΎΠΈΠ·Π²Π΅Π΄Π΅Π½Ρ.
#----------------------------------------------------------
# File pile.py
#----------------------------------------------------------
import bpy, mathutils, math, random
from mathutils import Vector NObjects = 7Seed = 444