Введение в написание скриптов на Питоне для Блендера 2.5x. Примеры кода - страница 9
>
> mtex.texture = cTex
> mtex.texture_coords = 'UV'
> mtex.use_map_color_diffuse = True
> mtex.use_map_color_emission = True
> mtex.emission_color_factor = 0.5
> mtex.use_map_density = True
> mtex.mapping = 'FLAT'
> # Добавление текстурного слота для bump-текстуры
> mtex = mat.texture_slots.add()
> mtex.texture = sTex
> mtex.texture_coords = 'ORCO'
> mtex.use_map_color_diffuse = False
> mtex.use_map_normal = True
> #mtex.rgb_to_intensity = True
> # Добавление текстурного слота
> mtex = mat.texture_slots.add()
> mtex.texture = bTex
> mtex.texture_coords = 'UV'
> mtex.use_map_color_diffuse = True
> mtex.diffuse_color_factor = 1.0
> mtex.blend_type = 'MULTIPLY'
> # Создание нового куба и наложение на него UV-раскладки
> bpy.ops.mesh.primitive_cube_add(location=origin)
> bpy.ops.object.mode_set(mode='EDIT')
> bpy.ops.uv.smart_project()
> bpy.ops.object.mode_set(mode='OBJECT')
> # Добавление материала к текущему объекту
> ob = bpy.context.object
> me = ob.data
> me.materials.append(mat)
> return
>if __name__ == "__main__":
> run((0,0,0))
Эта программа добавляет три материала к одному мешу.
>#----------------------------------------------------------
># File multi_material.py
>#----------------------------------------------------------
>import bpy
>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)
> yellow = bpy.data.materials.new('Yellow')
> yellow.diffuse_color = (1,1,0)
> # Создание меша и назначение материалов
> bpy.ops.mesh.primitive_uv_sphere_add(
> segments = 16,
> ring_count = 8,
> location=origin)
> ob = bpy.context.object
> ob.name = 'MultiMatSphere'
> me = ob.data me.materials.append(red)
> me.materials.append(blue)
> me.materials.append(yellow)
> # Назначение материалов граням
> for f in me.faces:
> f.material_index = f.index % 3
> # Установка левой половины сферы в плавное затенение,
> # правой половины — в плоское затенение
> for f in me.faces:
> f.use_smooth = (f.center[0] < 0)
>if __name__ == "__main__":
> run((0,0,0))
Эта программа добавляет два UV-слоя к мешу.
>#----------------------------------------------------------
># File uvs.py
>#----------------------------------------------------------
>import bpy import os
>def createMesh(origin):
> # Создание меша и объекта
> me = bpy.data.meshes.new('TetraMesh')
> ob = bpy.data.objects.new('Tetra', me)
> ob.location = origin
> # Привязка объекта к сцене
> scn = bpy.context.scene
> scn.objects.link(ob)
> scn.objects.active = ob scn.update()
> # Списки вершин и граней
> verts = [
> (1.41936, 1.41936, -1),
> (0.589378, -1.67818, -1),
> (-1.67818, 0.58938, -1),
> (0, 0, 1)
> ]
> faces = [(1,0,3), (3,2,1), (3,0,2), (0,1,2)]
> # Создание меша из передаваемых списков вершин, рёбер, граней.
> # Или рёбра или грани должны быть [], или Вам нужны проблемы
> me.from_pydata(verts, [], faces)
> # Обновление меша с новыми данными
> me.update(calc_edges=True)
> # Первый текстурный слой: Главная UV текстура (UVMain)
> texFaces = [
> [(0.6,0.6), (1,1), (0,1)],
> [(0,1), (0.6,0), (0.6,0.6)],
> [(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