#----------------------------------------------------------
# File cloth.py
#----------------------------------------------------------
import bpy, mathutils, math from mathutils import Vector
def run(origin):
side = 4
diagonal = side/math.sqrt(2)
hoopRad = 0.1
eps = 0.75
nDivs = 40
scn = bpy.context.scene
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΡΡΠ΅ΡΡ, Π²ΡΡΡΡΠΏΠ°ΡΡΠ΅ΠΉ Π² ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ ΠΎΠ±ΡΠ΅ΠΊΡΠ° ΡΡΠΎΠ»ΠΊΠ½ΠΎΠ²Π΅Π½ΠΈΡ
bpy.ops.mesh.primitive_ico_sphere_add(location=origin)
sphere = bpy.context.object
bpy.ops.object.shade_smooth()
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΌΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΎΡΠ° collision ΠΊ ΡΡΠ΅ΡΠ΅
bpy.ops.object.modifier_add(type='COLLISION')
cset = sphere.modifiers[0].settings
cset.thickness_outer = 0.2
cset.thickness_inner = 0.5
cset.permeability = 0.2
cset.stickness = 0.2
bpy.ops.object.modifier_add(type='SUBSURF')
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΊΠΎΠ»ΡΡΠ°
center = origin+Vector((0,0,2))
bpy.ops.mesh.primitive_torus_add(
major_radius= diagonal + hoopRad,
minor_radius= hoopRad,
location=center,
rotation=(0, 0, 0))
bpy.ops.object.shade_smooth()
ring = bpy.context.object
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΏΠ»ΠΎΡΠΊΠΎΡΡΠΈ Π½Π°Π΄ ΡΡΠ΅ΡΠΎΠΉ ΠΈ ΠΏΡΠΈΠ²ΡΠ·ΠΊΠ° Π΅Ρ ΠΊ ΠΊΠΎΠ»ΡΡΡ
bpy.ops.mesh.primitive_plane_add(location=(0,0,0))
bpy.ops.transform.resize(value=(side/2,side/2,1))
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.subdivide(number_cuts=nDivs)
bpy.ops.object.mode_set(mode='OBJECT')
plane = bpy.context.object
plane.parent = ring
me = plane.data
# Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ Π³ΡΡΠΏΠΏΡ Π²Π΅ΡΡΠΈΠ½. ΠΠ±ΡΠ΅ΠΊΡ Π½Π΅ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±ΡΡΡ Π°ΠΊΡΠΈΠ²Π½ΡΠΌ?
scn.objects.active = None
grp = plane.vertex_groups.new('Group')
for v in plane.data.vertices:
r = v.co - center
x = r.length/diagonal
w = 3*(x-eps)/(1-eps)
if w > 1:
w = 1
if w > 0:
grp.add([v.index], w, 'REPLACE')
# ΠΠΊΡΠΈΠ²Π°ΡΠΈΡ ΠΏΠ»ΠΎΡΠΊΠΎΡΡΠΈ ΡΠ½ΠΎΠ²Π°
scn.objects.active = plane
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΌΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΎΡΠ° cloth (ΡΠΊΠ°Π½Ρ)
cloth = plane.modifiers.new(name='Cloth', type='CLOTH')
cset = cloth.settings
cset.use_pin_cloth = True
cset.vertex_group_mass = 'Group'
# ΠΠ°ΡΡΡΠΎΠΉΠΊΠΈ ΡΡΠ»ΠΊΠ°, ΡΠΊΠΎΠΏΠΈΡΠΎΠ²Π°Π½ΠΎ ΠΈΠ· "scripts/presets/cloth/silk.py"
cset.quality = 5
cset.mass = 0.150
cset.structural_stiffness = 5
cset.bending_stiffness = 0.05
cset.spring_damping = 0
cset.air_damping = 1
# Π‘Π³Π»Π°ΠΆΠ΅Π½Π½ΠΎΠ΅ Π·Π°ΡΠ΅Π½Π΅Π½ΠΈΠ΅
plane.select = True
bpy.ops.object.shade_smooth()
bpy.ops.object.modifier_add(type='SUBSURF')
# Π’Π΅ΠΊΡΡΡΡΠ° Blend
tex = bpy.data.textures.new('Blend', type = 'BLEND')
tex.progression = 'SPHERICAL'
tex.intensity = 1.0
tex.contrast = 1.0
tex.use_color_ramp = True
elts = tex.color_ramp.elements
elts[0].color = (0, 0, 0, 1)
elts[0].position = 0.56
elts[1].color = (1, 1, 1, 0)
elts[1].position = 0.63
# ΠΌΠ°ΡΠ΅ΡΠΈΠ°Π» Rubber (Π Π΅Π·ΠΈΠ½ΠΎΠ²ΡΠΉ)
mat = bpy.data.materials.new('Rubber')
mat.diffuse_color = (1,0,0)
mat.use_transparency = True
mat.alpha = 0.25
mtex = mat.texture_slots.add()
mtex.texture = tex
mtex.texture_coords = 'STRESS'
mtex.use_map_color_diffuse = True
mtex.diffuse_color_factor = 0.25
mtex.use_map_alpha = True
mtex.alpha_factor = 1.0
mtex.blend_type = 'ADD'
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΌΠ°ΡΠ΅ΡΠΈΠ°Π»Π° ΠΊ ΠΏΠ»ΠΎΡΠΊΠΎΡΡΠΈ
plane.data.materials.append(mat)
# ΠΠ½ΠΈΠΌΠ°ΡΠΈΡ ΠΊΠΎΠ»ΡΡΠ°
ring.location = center
ring.keyframe_insert('location', index=2, frame=1)
ring.location = origin - Vector((0,0,0.5))
ring.keyframe_insert('location', index=2, frame=20)
ring.location = center
return
if __name__ == "__main__":
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete()
run(Vector((0,0,0)))
scn = bpy.context.scene
scn.frame_current = 1
bpy.ops.screen.animation_play()
ΠΡΠ° ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ° Π΄ΠΎΠ±Π°Π²Π»ΡΠ΅Ρ ΠΊΠΎΠ½ΡΡ Ρ ΠΌΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΎΡΠΎΠΌ softbody (ΠΌΡΠ³ΠΊΠΎΠ΅ ΡΠ΅Π»ΠΎ) ΠΈ ΠΏΠ»ΠΎΡΠΊΠΎΡΡΡ-ΠΏΡΠ΅ΠΏΡΡΡΡΠ²ΠΈΠ΅.
#----------------------------------------------------------
# File softbody.py
#----------------------------------------------------------
import bpy
import mathutils
from mathutils import Vector
def run(origin):
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΌΠ°ΡΠ΅ΡΠΈΠ°Π»Π°
red = bpy.data.materials.new('Red')
red.diffuse_color = (1,0,0)
blue = bpy.data.materials.new('Blue')
blue.diffuse_color = (0,0,1)
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΊΠΎΠ½ΡΡΠ°
bpy.ops.mesh.primitive_cone_add(
vertices=4,
radius=1.5,
cap_end=True)
ob1 = bpy.context.object
me1 = ob1.data
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.subdivide(number_cuts=5, smoothness=1, fractal=1)
bpy.ops.object.mode_set(mode='OBJECT')
# Π‘ΡΡΠ°Π½Π½ΠΎ, Π½ΡΠΆΠ΅Π½ Π½ΠΎΠ²ΡΠΉ ΠΌΠ΅Ρ, ΠΊΠΎΡΠΎΡΡΠΉ ΡΠ²Π»ΡΠ΅ΡΡΡ ΠΊΠΎΠΏΠΈΠ΅ΠΉ
verts = []
faces = []
for v in me1.vertices:
verts.append(v.co)
for f in me1.faces:
faces.append(f.vertices)
me2 = bpy.data.meshes.new('Drop')
me2.from_pydata(verts, [], faces)
me2.update(calc_edges=True)
# Π£ΡΡΠ°Π½ΠΎΠ²ΠΊΠ° Π³Π»Π°Π΄ΠΊΠΎΡΡΠΈ Π³ΡΠ°Π½ΡΠΌ (smooth)
for f in me2.faces: f.use_smooth = True
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ Π½ΠΎΠ²ΠΎΠ³ΠΎ ΠΎΠ±ΡΠ΅ΠΊΡΠ° ΠΈ Π΅Π³ΠΎ Π°ΠΊΡΠΈΠ²Π°ΡΠΈΡ
ob2 = bpy.data.objects.new('Drop', me2)
scn = bpy.context.scene
scn.objects.link(ob2)
scn.objects.unlink(ob1)
scn.objects.active = ob2
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ Π³ΡΡΠΏΠΏ Π²Π΅ΡΡΠΈΠ½
top = ob2.vertex_groups.new('Top')
bottom = ob2.vertex_groups.new('Bottom')
for v in me2.vertices:
w = v.co[2] - 0.2
if w < 0:
if w < -1:
w = -1
bottom.add([v.index], -w, 'REPLACE')
elif w > 0:
if w > 1:
w = 1
top.add([v.index], w, 'REPLACE')
bpy.ops.object.mode_set(mode='OBJECT')
ob2.location = origin
me2.materials.append(blue)
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΌΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΎΡΠ° softbody
mod = ob2.modifiers.new(name='SoftBody', type='SOFT_BODY')
sbset = mod.settings
# ΠΡΠ³ΠΊΠΎΠ΅ ΡΠ΅Π»ΠΎ
sbset.friction = 0.6
sbset.speed = 0.4
sbset.mass = 8.1
# Π¦Π΅Π»Ρ
sbset.goal_default = 0.7
sbset.goal_spring = 0.3
sbset.goal_friction = 0.0
sbset.vertex_group_goal = 'Top'
# ΠΡΠ°Ρ ΠΌΡΠ³ΠΊΠΎΠ³ΠΎ ΡΠ΅Π»Π°
sbset.pull = 0.6
sbset.push = 0.1
sbset.bend = 0.1
sbset.aerodynamics_type = 'LIFT_FORCE'
sbset.aero = 0.5
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ Π²ΠΈΡ ΡΡ
bpy.ops.object.effector_add(
type='VORTEX',
location=origin+Vector((0,0,-4)))
vortex = bpy.context.object
fset = vortex.field
fset.strength = 4.5
fset.shape = 'PLANE'
fset.apply_to_location = False
fset.apply_to_rotation = True
fset.falloff_type = 'TUBE'
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΏΠ»ΠΎΡΠΊΠΎΡΡΠΈ ΡΡΠΎΠ»ΠΊΠ½ΠΎΠ²Π΅Π½ΠΈΡ
# ΠΡΠ΅Π΄ΡΠΏΡΠ΅ΠΆΠ΄Π΅Π½ΠΈΠ΅. Π‘ΡΠΎΠ»ΠΊΠ½ΠΎΠ²Π΅Π½ΠΈΠ΅ ΠΎΠ±ΡΠ΅ΠΊΡΠΎΠ² Π΄Π΅Π»Π°Π΅Ρ ΡΠΈΠΌΡΠ»ΡΡΠΈΡ ΠΎΡΠ΅Π½Ρ ΠΌΠ΅Π΄Π»Π΅Π½Π½ΠΎΠΉ!
bpy.ops.mesh.primitive_plane_add(
location=origin-Vector((0,0,1.7)))
bpy.ops.transform.resize(value=(4, 4, 4))
plane = bpy.context.object
plane.data.materials.append(red)
mod = plane.modifiers.new(name='Collision', type='COLLISION')
return
if __name__ == "__main__":
bpy.context.scene.frame_end = 600
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
run(Vector((0,0,6)))
bpy.ops.screen.animation_play()
#bpy.ops.render.opengl(animation=True)
ΠΡΠ° ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ° ΠΏΠΎΠΊΠ°Π·ΡΠ²Π°Π΅Ρ ΡΡΠΈ ΡΠ°Π·Π»ΠΈΡΠ½ΡΡ ΠΌΠ΅ΡΠΎΠ΄Π° ΡΠ°Π·ΠΌΠ°Ρ ΠΈΠ²Π°Π½ΠΈΡ ΡΠ»Π°Π³ΠΎΠΌ: ΠΌΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΎΡΠΎΠΌ ΡΠΊΠ°Π½ΠΈ, ΠΌΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΎΡΠΎΠΌ ΠΌΡΠ³ΠΊΠΈΡ ΡΠ΅Π», ΠΈ Ρ ΠΏΠΎΠΌΠΎΡΡΡ Π°Π½ΠΈΠΌΠΈΡΠΎΠ²Π°Π½Π½ΡΡ ΡΠ΅ΠΊΡΡΡΡ ΡΠΌΠ΅ΡΠ΅Π½ΠΈΡ.
#----------------------------------------------------------
# File flags.py
# Π‘ΠΎΠ·Π΄Π°Π΅Ρ ΡΠ»Π°Π³ ΠΈΠ· ΠΌΡΠ³ΠΊΠΎΠ³ΠΎ ΡΠ΅Π»Π° ΠΈ ΡΠ»Π°Π³ ΠΈΠ· ΡΠΊΠ°Π½ΠΈ Π½Π° Π²Π΅ΡΡΡ.
# Update to API rev. 36816
#----------------------------------------------------------
import bpy, mathutils, math
from mathutils import Vector
from math import pi
# Π Π°Π·ΠΌΠ΅Ρ ΡΠ»Π°Π³Π°, Π³Π»ΠΎΠ±Π°Π»ΡΠ½ΡΠ΅ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΡΠ΅
xmax = 40
zmax = 24
ds = 2.0/xmax
def makeFlag(name, origin, invert):
# ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ Π½ΠΎΠ²ΠΎΠ³ΠΎ ΠΌΠ΅ΡΠ°, ΠΊΠΎΡΠΎΡΡΠΉ Π±ΡΠ΄Π΅Ρ ΡΠ»Π°Π³ΠΎΠΌ