Чтение онлайн

ЖАНРЫ

Введение в написание скриптов на Питоне для Блендера 2.5x. Примеры кода

Larsson Thomas

Шрифт:

[(0,1), (0,0), (0.6,0)],

[(1,1), (0.6,0.6), (0.6,0)]

]

uvMain = createTextureLayer("UVMain", me, texFaces)

# Второй текстурный слой: проекция спереди (UVFront)

texFaces = [

[(0.732051,0), (1,0), (0.541778,1)],

[(0.541778,1), (0,0), (0.732051,0)],

[(0.541778,1), (1,0), (0,0)],

[(1,0), (0.732051,0), (0,0)]

]

uvFront = createTextureLayer("UVFront", me, texFaces)

#
Третий текстурный слой: Умная проекция

bpy.ops.mesh.uv_texture_add

uvCyl = me.uv_textures.active

uvCyl.name = 'UVCyl'

bpy.ops.object.mode_set(mode='EDIT')

bpy.ops.uv.cylinder_project

bpy.ops.object.mode_set(mode='OBJECT')

# Хотим сделать Главный слой активным, но, кажется, это не работает - TBF

me.uv_textures.active = uvMain

me.uv_texture_clone = uvMain

uvMain.active_render = True

uvFront.active_render = False

uvCyl.active_render = False

return ob

def createTextureLayer(name, me, texFaces):

uvtex = me.uv_textures.new

uvtex.name = name

for n,tf in enumerate(texFaces):

datum = uvtex.data[n]

datum.uv1 = tf[0]

datum.uv2 = tf[1]

datum.uv3 = tf[2]

return uvtex

def createMaterial:

# Создание текстуры image из картинки. Измените здесь, если

# каталог snippet расположен не в Вашем домашнем каталоге.

realpath = os.path.expanduser('~/snippets/textures/color.png')

tex = bpy.data.textures.new('ColorTex', type = 'IMAGE')

tex.image = bpy.data.images.load(realpath)

tex.use_alpha = True 

# Создание незатеняемого материала и MTex

mat = bpy.data.materials.new('TexMat')

mat.use_shadeless = True

mtex = mat.texture_slots.add

mtex.texture = tex

mtex.texture_coords = 'UV'

mtex.use_map_color_diffuse = True

return mat

def run(origin):

ob = createMesh(origin)

mat = createMaterial

ob.data.materials.append(mat)

return

if __name__ == "__main__":

run((0,0,0))

Действия (Actions)

и управляющие элементы (drivers)

Действие объекта

Прыгающий мяч.

#--------------------------------------------------

# File ob_action.py

#--------------------------------------------------

import bpy import math

def run(origin):

# Установка начала и конца анимации

scn = bpy.context.scene

scn.frame_start = 11

scn.frame_end = 200

# Создание ico-сферы

bpy.ops.mesh.primitive_ico_sphere_add(location=origin)

ob = bpy.context.object

# Вставка ключевых кадров с operator code (кодом оператора ???)

# Объект должен быть выбранным автоматически

z = 10

t = 1

for n in range(5):

t += 10

bpy.ops.anim.change_frame(frame = t)

bpy.ops.transform.translate(value=(2, 0, z))

bpy.ops.anim.keyframe_insert_menu(type='Location')

t += 10

bpy.ops.anim.change_frame(frame = t)

bpy.ops.transform.translate(value=(2, 0, -z))

bpy.ops.anim.keyframe_insert_menu(type='Location')

z *= 0.67

action = ob.animation_data.action

# Создание словаря с графиком FCurves типа location (позиция)

fcus = {}

for fcu in action.fcurves:

if fcu.data_path == 'location':

fcus[fcu.array_index] = fcu

print(fcus.items)

# Добавление новых ключевых точек к x и z

kpts_x = fcus[0].keyframe_points

kpts_z = fcus[2].keyframe_points

(x0,y0,z0) = origin

omega = 2*math.pi/20

z *= 0.67

for t in range(101, 201):

xt = 20 + 0.2*(t-101)

Поделиться с друзьями: