OSDN Git Service

update bone group export.
[meshio/meshio.git] / swig / blender / bl25.py
index 2389b80..71f6636 100755 (executable)
@@ -239,6 +239,10 @@ class object:
         g.name=name
         g.color_set=color_set
 
+    @staticmethod
+    def boneGroups(o):
+        return object.getPose(o).bone_groups
+
 
 class modifier:
     @staticmethod
@@ -305,17 +309,39 @@ class material:
         return bpy.data.materials[material_name]
 
     @staticmethod
-    def addTexture(material, texture):
-        material.add_texture(texture, "UV", "COLOR")
-        slot=material.texture_slots[material.active_texture_index]
-        slot.blend_type='MULTIPLY'
-        slot.map_alpha=True
+    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(material, index):
+        return material.texture_slots[index].texture
 
     @staticmethod
     def hasTexture(material):
         return material.texture_slots[0]
 
     @staticmethod
+    def setUseTexture(material, index, enable):
+        material.use_textures[index]=enable
+
+    @staticmethod
     def eachTexturePath(m):
         for slot in m.texture_slots:
             if slot and slot.texture:
@@ -378,18 +404,21 @@ class mesh:
 
     @staticmethod
     def hasFaceUV(mesh, i, face):
-        return mesh.active_uv_texture.data[i]
+        return mesh.active_uv_texture and mesh.active_uv_texture.data[i]
 
     @staticmethod
     def getFaceUV(mesh, i, faces, count=3):
-        uvFace=mesh.active_uv_texture.data[i]
-        if count==3:
-            return (uvFace.uv1, uvFace.uv2, uvFace.uv3)
-        elif count==4:
-            return (uvFace.uv1, uvFace.uv2, uvFace.uv3, uvFace.uv4)
+        if mesh.active_uv_texture and mesh.active_uv_texture.data[i]:
+            uvFace=mesh.active_uv_texture.data[i]
+            if count==3:
+                return (uvFace.uv1, uvFace.uv2, uvFace.uv3)
+            elif count==4:
+                return (uvFace.uv1, uvFace.uv2, uvFace.uv3, uvFace.uv4)
+            else:
+                print(count)
+                assert(False)
         else:
-            print(count)
-            assert(False)
+            return ((0, 0), (0, 0), (0, 0), (0, 0))
 
     @staticmethod
     def setFaceUV(mesh, i, face, uv_array, image):