Вход/Регистрация
Введение в написание скриптов на Питоне для Блендера 2.5x. Примеры кода
вернуться

Larsson Thomas

Шрифт:

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

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

  • Читать дальше
  • 1
  • ...
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • ...

Ебукер (ebooker) – онлайн-библиотека на русском языке. Книги доступны онлайн, без утомительной регистрации. Огромный выбор и удобный дизайн, позволяющий читать без проблем. Добавляйте сайт в закладки! Все произведения загружаются пользователями: если считаете, что ваши авторские права нарушены – используйте форму обратной связи.

Полезные ссылки

  • Моя полка

Контакты

  • chitat.ebooker@gmail.com

Подпишитесь на рассылку: