else:
INTERNAL_ENCODING=FS_ENCODING
+def to_internal_encoding(fn):
+ '''
+ decorator for fix string encoding
+ '''
+ def newfn(*args):
+ return fn(*[
+ v.encode(INTERNAL_ENCODING) if isinstance(v, unicode) else v
+ for v in args])
+ return newfn
+
+
SCENE=None
def initialize(name, scene):
global SCENE
#if mode_edit:
# Blender.Window.EditMode(1)
+@to_internal_encoding
def message(msg):
res=Blender.Draw.PupMenu(msg + "%t|OK")
print(res)
def enterEditMode():
Blender.Window.EditMode(1)
-def exitEditMode():
+def enterObjectMode():
Blender.Window.EditMode(0)
+def enterPoseMode():
+ Blender.Window.PoseMode(1)
+
def createVector(x, y, z):
return Mathutils.Vector(x, y, z)
self.progress=float(progress)
self._print(message)
+ @to_internal_encoding
def _print(self, message):
- print(message)
+ print(message.decode(INTERNAL_ENCODING))
message="%s: %s" % (self.base, message)
- if message.__class__ is unicode:
- message=message.encode(FS_ENCODING)
Blender.Window.DrawProgressBar(self.progress, message)
def finish(self):
class object:
@staticmethod
+ @to_internal_encoding
def createEmpty(name):
global SCENE
empty=SCENE.objects.new("Empty")
return o.getData(mesh=True).key.blocks
@staticmethod
+ @to_internal_encoding
def addShapeKey(o, name):
mesh=o.getData(mesh=True)
mesh.insertKey()
block=mesh.key.blocks[-1]
- block.name=name.encode(INTERNAL_ENCODING)
+ block.name=name
return block
@staticmethod
return o.getPose()
@staticmethod
+ @to_internal_encoding
def addVertexGroup(o, name):
o.getData(mesh=True).addVertGroup(name)
@staticmethod
+ @to_internal_encoding
def assignVertexGroup(o, name, index, weight):
o.getData(mesh=True).assignVertsToGroup(name,
[index], weight, Blender.Mesh.AssignModes.ADD)
return o.getData(mesh=True).getVertGroupNames()
@staticmethod
+ @to_internal_encoding
def getVertexGroup(o, name):
indices=[]
for index in o.getData(mesh=True).getVertsFromGroup(name):
indices.append(index)
return indices
+ @staticmethod
+ def createBoneGroup(o, name, color_set='DEFAULT'):
+ # create group
+ object.activate(o)
+ enterPoseMode()
+ bpy.ops.pose.group_add()
+ # set name
+ pose=object.getPose(o)
+ g=pose.active_bone_group
+ g.name=name
+ g.color_set=color_set
+
class modifier:
@staticmethod
class texture:
@staticmethod
+ @to_internal_encoding
def create(path):
- image = Blender.Image.Load(path.encode(INTERNAL_ENCODING))
- texture = Blender.Texture.New(path.encode(INTERNAL_ENCODING))
+ try:
+ image = Blender.Image.Load(path)
+ except IOError:
+ image = None
+ texture = Blender.Texture.New(path)
texture.type = Blender.Texture.Types.IMAGE
texture.image = image
texture.imageFlags|=Blender.Texture.ImageFlags.USEALPHA
class material:
@staticmethod
+ @to_internal_encoding
def create(name):
m = Blender.Material.New(name)
return m
return len(material.getTextures())>0
@staticmethod
- def getTexturePath(m, dirname):
- tex=""
- aplane=""
- # texture
+ def eachTexturePath(m, dirname):
for texture in m.getTextures():
if texture and texture.tex and texture.tex.getImage():
image=texture.tex.getImage()
if not image:
continue
- imagePath=Blender.sys.expandpath(image.getFilename())
- if len(dirname)>0 and imagePath.startswith(dirname):
- # 相対パスに変換する
- imagePath=imagePath[len(dirname)+1:len(imagePath)]
- if texture.mtCol>0:
- tex=" tex(\"%s\")" % imagePath
- elif texture.mtAlpha>0:
- aplane=" aplane(\"%s\")" % imagePath
- return tex, aplane
+ yield image.getFilename()
class mesh:
@staticmethod
+ @to_internal_encoding
def create(name):
global SCENE
m=Blender.Mesh.New()
- o=SCENE.objects.new(m, name.encode(INTERNAL_ENCODING))
+ o=SCENE.objects.new(m, name)
return m, o
@staticmethod
return constraint
@staticmethod
+ @to_internal_encoding
def createBone(armature_object, name):
bone=Blender.Armature.Editbone()
- bone.name=name.encode(INTERNAL_ENCODING)
+ bone.name=name
armature_object.bones[name]=bone
return bone