red.specular_hardness = 200
rmir = red.raytrace_mirror
rmir.use = True
rmir.distance = 0.001
rmir.fade_to = 'FADE_TO_MATERIAL'
rmir.distance = 0.0
rmir.reflect_factor = 0.7
rmir.gloss_factor = 0.4
grey = bpy.data.materials.new('Grey')
grey.diffuse_color = (0.5,0.5,0.5)
# ----------- ΠΡΠ»Ρ β ΠΌΠ°Π»Π΅Π½ΡΠΊΠ°Ρ ΡΡΠ΅ΡΠ°
bullet = addSphere('Bullet', 0.2, origin)
bullet.data.materials.append(grey)
# ΠΠ½ΠΈΠΌΠ°ΡΠΈΡ ΠΏΡΠ»ΠΈ
scn = bpy.context.scene
scn.frame_current = 51
bullet.location = origin
bpy.ops.anim.keyframe_insert_menu(type='Location')
bullet.location = origin+Vector((0,30,0))
scn.frame_current = 251
bpy.ops.anim.keyframe_insert_menu(type='Location')
scn.frame_current = 1
action = bullet.animation_data.action
for fcu in action.fcurves:
fcu.extrapolation = 'LINEAR'
for kp in fcu.keyframe_points:
kp.interpolation = 'LINEAR'
# Π‘ΠΈΡΡΠ΅ΠΌΠ° ΡΠ°ΡΡΠΈΡ Trail (ΡΠ»Π΅Π΄) Π΄Π»Ρ ΠΏΡΠ»ΠΈ
bpy.ops.object.particle_system_add()
trail = bullet.particle_systems[0]
trail.name = 'Trail'
fset = trail.settings
# ΠΠΌΠΈΡΡΠΈΡ
fset.name = 'TrailSettings'
fset.count = 1000 fset.frame_start = 1
fset.frame_end = 250
fset.lifetime = 25
fset.emit_from = 'FACE'
fset.use_render_emitter = True
# Π‘ΠΊΠΎΡΠΎΡΡΡ
fset.normal_factor = 1.0
fset.factor_random = 0.5
# Π€ΠΈΠ·ΠΈΠΊΠ°
fset.physics_type = 'NEWTON'
fset.mass = 0
# Π£ΡΡΠ°Π½ΠΎΠ²ΠΊΠ° Π²ΡΠ΅Ρ ΡΡΡΠ΅ΠΊΡΠΎΡΠ½ΡΡ Π²Π΅ΡΠΎΠ² Π² Π½ΠΎΠ»Ρ
ew = fset.effector_weights
ew.gravity = 0.0
# ΠΠ΅ ΡΠ΅Π½Π΄Π΅ΡΠΈΡΡ
fset.draw_method = 'DOT'
fset.render_type = 'NONE'
# -------------- Π¨Π°Ρ
ball = addSphere('Ball', 1.0, origin)
ball.data.materials.append(red)
# Π‘ΠΈΡΡΠ΅ΠΌΠ° ΡΠ°ΡΡΠΈΡ
bpy.ops.object.particle_system_add()
react = ball.particle_systems[0]
react.name = 'React'
fset = react.settings
# ΠΠΌΠΈΡΡΠΈΡ
fset.name = 'TrailSettings'
fset.count = 50
fset.frame_start = 47
fset.frame_end = 57
fset.lifetime = 250
fset.emit_from = 'FACE'
fset.use_render_emitter = True
# Π‘ΠΊΠΎΡΠΎΡΡΡ
fset.normal_factor = 5.0
fset.factor_random = 2.5
# Π€ΠΈΠ·ΠΈΠΊΠ°
fset.physics_type = 'NEWTON'
fset.mass = 1.0
# ΠΠ΅ ΡΠ΅Π½Π΄Π΅ΡΠΈΡΡ
fset.draw_method = 'CROSS'
fset.render_type = 'NONE'
# ΠΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΎΡ Explode
mod = ball.modifiers.new(name='Explode', type='EXPLODE')
mod.use_edge_cut = True
mod.show_unborn = True
mod.show_alive = True
mod.show_dead = True
mod.use_size = False
# ---- Π‘ΠΊΡΡΡΡΠΉ ΠΏΠΎΠ» Ρ ΠΌΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΎΡΠΎΠΌ collision (ΡΡΠΎΠ»ΠΊΠ½ΠΎΠ²Π΅Π½ΠΈΡ)
hidden = addFloor('Hidden', origin+Vector((0,0,-3.9)), True)
mod = hidden.modifiers.new(name='Collision', type='COLLISION')
mset = mod.settings
mset.permeability = 0.01
mset.stickness = 0.1
mset.use_particle_kill = False
mset.damping_factor = 0.6
mset.damping_random = 0.2
mset.friction_factor = 0.3
mset.friction_random = 0.1
addFloor('Floor', Vector((0,0,-4)), False)
return
if __name__ == "__main__":
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
# ΠΠ°ΠΌΠ΅ΡΠ°, ΠΎΡΠ²Π΅ΡΠ΅Π½ΠΈΠ΅
bpy.ops.object.camera_add(
location = Vector((12,-12,4)),
rotation = Vector((70,0,45))*math.pi/180)
cam = bpy.context.object.data
cam.lens = 35
bpy.ops.object.lamp_add(type='POINT',
location = Vector((11,-7,6)))
bpy.ops.object.lamp_add(type='POINT',
location =Vector((-7,-10,2)))
run(Vector((0,0,0)))
ΠΡΠ° ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ° Π΄ΠΎΠ±Π°Π²Π»ΡΠ΅Ρ Π΄Π²Π΅ ΡΠΈΡΡΠ΅ΠΌΡ ΡΠ°ΡΡΠΈΡ Π΄Π»Ρ ΠΎΠ³Π½Ρ ΠΈ Π΄ΡΠΌΠ°. Π§Π°ΡΡΠΈΡΡ ΠΎΡΠΎΠ±ΡΠ°ΠΆΠ°ΡΡΡΡ Π² Π²ΠΈΠ΄Π΅ Π±ΠΈΠ»Π±ΠΎΡΠ΄ΠΎΠ² Ρ ΠΏΡΠΎΡΠ΅Π΄ΡΡΠ½ΡΠΌΠΈ ΡΠ΅ΠΊΡΡΡΡΠ°ΠΌΠΈ.
#---------------------------------------------------
# File fire.py
#---------------------------------------------------
import bpy, mathutils, math
from mathutils import Vector, Matrix
from math import pi
def createEmitter(origin):
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'