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
#----------------------------------------------------------