Шрифт:
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
# Добавление нового объекта и его активация