+class scene:
+ @staticmethod
+ def update(scene):
+ scene.update()
+
+
+class object:
+ @staticmethod
+ def createEmpty(name):
+ global SCENE
+ empty=bpy.data.objects.new(name, None)
+ SCENE.objects.link(empty)
+ return empty
+
+ @staticmethod
+ def each():
+ for o in SCENE.objects:
+ yield o
+
+ @staticmethod
+ def makeParent(parent, child):
+ child.parent=parent
+
+ @staticmethod
+ def duplicate(o):
+ global SCENE
+ bpy.ops.object.select_all(action='DESELECT')
+ o.select=True
+ SCENE.objects.active=o
+ bpy.ops.object.duplicate()
+ dumy=SCENE.objects.active
+ #bpy.ops.object.rotation_apply()
+ #bpy.ops.object.scale_apply()
+ #bpy.ops.object.location_apply()
+ return dumy.data, dumy
+
+ @staticmethod
+ def delete(o):
+ global SCENE
+ SCENE.objects.unlink(o)
+
+ @staticmethod
+ def getData(o):
+ return o.data
+
+ @staticmethod
+ def select(o):
+ o.select=True
+
+ @staticmethod
+ def activate(o):
+ global SCENE
+ o.select=True
+ SCENE.objects.active=o
+
+ @staticmethod
+ def getActive():
+ global SCENE
+ return SCENE.objects.active
+
+ @staticmethod
+ def deselectAll():
+ bpy.ops.object.select_all(action='DESELECT')
+
+ @staticmethod
+ def setLayerMask(object, layers):
+ layer=[]
+ for i in range(20):
+ try:
+ layer.append(True if layers[i]!=0 else False)
+ except IndexError:
+ layer.append(False)
+ object.layers=layer
+
+ @staticmethod
+ def isVisible(o):
+ return False if o.hide else True
+
+ @staticmethod
+ def getShapeKeys(o):
+ return o.data.shape_keys.keys
+
+ @staticmethod
+ def addShapeKey(o, name):
+ return o.add_shape_key(name)
+
+ @staticmethod
+ def hasShapeKey(o):
+ return o.data.shape_keys
+
+ @staticmethod
+ def pinShape(o, enable):
+ o.shape_key_lock=enable
+
+ @staticmethod
+ def setActivateShapeKey(o, index):
+ o.active_shape_key_index=index
+
+ @staticmethod
+ def getPose(o):
+ return o.pose
+
+ @staticmethod
+ def getVertexGroup(o, name):
+ indices=[]
+ for i, v in enumerate(o.data.verts):
+ for g in v.groups:
+ if o.vertex_groups[g.group].name==name:
+ indices.append(i)
+ return indices
+
+ @staticmethod
+ def getVertexGroupNames(o):
+ for g in o.vertex_groups:
+ yield g.name
+
+ @staticmethod
+ def addVertexGroup(o, name):
+ o.add_vertex_group(name)
+
+ @staticmethod
+ def assignVertexGroup(o, name, index, weight):
+ o.add_vertex_to_group(index,
+ o.vertex_groups[name], weight, 'ADD')
+
+ @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
+
+ @staticmethod
+ def boneGroups(o):
+ return object.getPose(o).bone_groups
+
+
+class modifier:
+ @staticmethod
+ def addMirror(mesh_object):
+ return mesh_object.modifiers.new("Modifier", "MIRROR")
+
+ @staticmethod
+ def addArmature(mesh_object, armature_object):
+ mod=mesh_object.modifiers.new("Modifier", "ARMATURE")
+ mod.object = armature_object
+ mod.use_bone_envelopes=False
+
+ @staticmethod
+ def hasType(mesh_object, type_name):
+ for mod in mesh_object.modifiers:
+ if mod.type==type_name.upper():
+ return True
+
+ @staticmethod
+ def isType(m, type_name):
+ return m.type==type_name.upper()
+
+ @staticmethod
+ def getArmatureObject(m):
+ return m.object
+
+
+class shapekey:
+ @staticmethod
+ def assign(shapeKey, index, pos):
+ shapeKey.data[index].co=pos
+
+ @staticmethod
+ def getByIndex(b, index):
+ return b.data[index].co
+
+ @staticmethod
+ def get(b):
+ for k in b.data:
+ yield k.co
+
+
+class texture:
+ @staticmethod
+ def create(path):
+ texture=bpy.data.textures.new(os.path.basename(path))
+ texture.type='IMAGE'
+ texture=texture.recast_type()
+ texture.mipmap=True
+ texture.interpolation=True
+ texture.use_alpha=True
+ try:
+ image=bpy.data.images.load(path)
+ except SystemError:
+ image=bpy.data.images.new('Image')
+ texture.image=image
+ return texture, image
+
+ @staticmethod
+ def getPath(t):
+ if t.type=="IMAGE":
+ image=t.image
+ if image:
+ return image.filepath
+
+
+class material:
+ @staticmethod
+ def create(name):
+ return bpy.data.materials.new(name)
+
+ @staticmethod
+ def get(material_name):
+ return bpy.data.materials[material_name]
+
+ @staticmethod
+ def addTexture(material, texture, enable=True):
+ # search free slot
+ index=None
+ for i, slot in enumerate(material.texture_slots):
+ if not slot:
+ index=i
+ break
+ if index==None:
+ return
+
+ if enable:
+ material.add_texture(texture, "UV", "COLOR")
+ slot=material.texture_slots[index]
+ slot.blend_type='MULTIPLY'
+ slot.map_alpha=True
+ else:
+ material.add_texture(texture)
+ material.use_textures[index]=False
+ return index
+
+ @staticmethod
+ def getTexture(m, index):
+ return m.texture_slots[index].texture
+
+ @staticmethod
+ def hasTexture(m):
+ return m.texture_slots[0]
+
+ @staticmethod
+ def setUseTexture(m, index, enable):
+ m.use_textures[index]=enable
+
+ @staticmethod
+ def eachTexturePath(m):
+ for slot in m.texture_slots:
+ if slot and slot.texture:
+ texture=slot.texture
+ if texture.type=="IMAGE":
+ image=texture.image
+ if not image:
+ continue
+ yield image.filepath
+
+ @staticmethod
+ def eachEnalbeTexturePath(m):
+ for i, slot in enumerate(m.texture_slots):
+ if m.use_textures[i] and slot and slot.texture:
+ texture=slot.texture
+ if texture.type=="IMAGE":
+ image=texture.image
+ if not image:
+ continue
+ yield image.filepath
+
+
+class mesh:
+ @staticmethod
+ def create(name):
+ global SCENE
+ mesh=bpy.data.meshes.new("Mesh")
+ mesh_object= bpy.data.objects.new(name, mesh)
+ SCENE.objects.link(mesh_object)
+ return mesh, mesh_object
+
+ @staticmethod
+ def addGeometry(mesh, vertices, faces):
+ mesh.from_pydata(vertices, [], faces)
+ """
+ mesh.add_geometry(len(vertices), 0, len(faces))
+ # add vertex
+ unpackedVertices=[]
+ for v in vertices:
+ unpackedVertices.extend(v)
+ mesh.verts.foreach_set("co", unpackedVertices)
+ # add face
+ unpackedFaces = []
+ for face in faces:
+ if len(face) == 4:
+ if face[3] == 0:
+ # rotate indices if the 4th is 0
+ face = [face[3], face[0], face[1], face[2]]
+ elif len(face) == 3:
+ if face[2] == 0:
+ # rotate indices if the 3rd is 0
+ face = [face[2], face[0], face[1], 0]
+ else:
+ face.append(0)
+ unpackedFaces.extend(face)
+ mesh.faces.foreach_set("verts_raw", unpackedFaces)
+ """
+ assert(len(vertices)==len(mesh.verts))
+ assert(len(faces)==len(mesh.faces))