OSDN Git Service

implement createMaterials.
[meshio/meshio.git] / swig / blender / bl24.py
1 # coding: utf-8
2 import sys
3 import os
4 import Blender
5
6\e$B%U%!%$%k%7%9%F%`$NJ8;z%3!<%I\e(B
7\e$B2~B$HG$H$N6&MQ$N$?$a\e(B
8 FS_ENCODING=sys.getfilesystemencoding()
9 if os.path.exists(os.path.dirname(sys.argv[0])+"/utf8"):
10     INTERNAL_ENCODING='utf-8'
11 else:
12     INTERNAL_ENCODING=FS_ENCODING
13
14 def createEmptyObject(scene, name):
15     empty=scene.objects.new("Empty")
16     empty.setName(name)
17     return empty
18
19 def createMaterial(m):
20     material = Blender.Material.New(m.getName().encode(INTERNAL_ENCODING))
21     material.mode |= Blender.Material.Modes.SHADELESS
22     material.rgbCol = [m.color.r, m.color.g, m.color.b]
23     material.alpha = m.color.a
24     material.amb = m.ambient
25     material.spec = m.specular
26     material.hard = int(255 * m.power)
27     return material
28
29 def createTexture(path):
30     image = Blender.Image.Load(path.encode(INTERNAL_ENCODING))
31     texture = Blender.Texture.New(path.encode(INTERNAL_ENCODING))
32     texture.type = Blender.Texture.Types.IMAGE
33     texture.image = image
34     return texture, image
35
36 def materialAddTexture(material, texture):
37     material.mode = material.mode | Blender.Material.Modes.TEXFACE
38     material.setTexture(0, texture, Blender.Texture.TexCo.UV)
39