OSDN Git Service

fix vertex key.
authorousttrue <ousttrue@gmail.com>
Mon, 14 Jun 2010 13:53:52 +0000 (22:53 +0900)
committerousttrue <ousttrue@gmail.com>
Mon, 14 Jun 2010 13:53:52 +0000 (22:53 +0900)
swig/blender/pmd_export.py

index d68f53a..c60bfde 100644 (file)
@@ -78,13 +78,14 @@ class VertexKey(object):
     重複頂点の検索キー
     """
     __slots__=[
-            'index',
+            'obj', 'index',
             'x', 'y', 'z', # 位置
             'nx', 'ny', 'nz', # 法線
             'u', 'v', # uv
             ]
 
-    def __init__(self, index, x, y, z, nx, ny, nz, u, v):
+    def __init__(self, obj, index, x, y, z, nx, ny, nz, u, v):
+        self.obj=obj
         self.index=index
         self.x=x
         self.y=y
@@ -107,7 +108,7 @@ class VertexKey(object):
         #return near(self.x, rhs.x) and near(self.y, rhs.y) and near(self.z, rhs.z) and near(self.nx, rhs.nx) and near(self.ny, rhs.ny) and near(self.nz, rhs.nz) and near(self.u, rhs.u) and near(self.v, rhs.v)
         #return near(self.x, rhs.x) and near(self.y, rhs.y) and near(self.z, rhs.z)
         #return self.x==rhs.x and self.y==rhs.y and self.z==rhs.z
-        return self.index==rhs.index
+        return self.obj==rhs.obj and self.index==rhs.index
 
 
 class VertexArray(object):
@@ -138,12 +139,12 @@ class VertexArray(object):
                 self.vertices, self.normals, self.uvs,
                 self.b0, self.b1, self.weight)
 
-    def __getIndex(self, base_index, pos, normal, uv, b0, b1, weight0):
+    def __getIndex(self, obj, base_index, pos, normal, uv, b0, b1, weight0):
         """
         頂点属性からその頂点のインデックスを得る
         """
         key=VertexKey(
-                base_index,
+                obj, base_index,
                 pos[0], pos[1], pos[2],
                 normal[0], normal[1], normal[2],
                 uv[0], uv[1])
@@ -174,7 +175,7 @@ class VertexArray(object):
         return self.indexMap[base_index]
 
     def addTriangle(self,
-            material,
+            obj, material,
             base_index0, base_index1, base_index2,
             pos0, pos1, pos2,
             n0, n1, n2,
@@ -186,9 +187,9 @@ class VertexArray(object):
         if not material in self.indexArrays:
             self.indexArrays[material]=[]
 
-        index0=self.__getIndex(base_index0, pos0, n0, uv0, b0_0, b1_0, weight0)
-        index1=self.__getIndex(base_index1, pos1, n1, uv1, b0_1, b1_1, weight1)
-        index2=self.__getIndex(base_index2, pos2, n2, uv2, b0_2, b1_2, weight2)
+        index0=self.__getIndex(obj, base_index0, pos0, n0, uv0, b0_0, b1_0, weight0)
+        index1=self.__getIndex(obj, base_index1, pos1, n1, uv1, b0_1, b1_1, weight1)
+        index2=self.__getIndex(obj, base_index2, pos2, n2, uv2, b0_2, b1_2, weight2)
 
         self.indexArrays[material]+=[index0, index1, index2]
 
@@ -223,11 +224,12 @@ class IKSolver(object):
 
 
 class OneSkinMesh(object):
-    __slots__=['scene', 'vertexArray', 'morphList']
+    __slots__=['obj_index', 'scene', 'vertexArray', 'morphList']
     def __init__(self, scene):
         self.vertexArray=VertexArray()
         self.morphList=[]
         self.scene=scene
+        self.obj_index=0
 
     def __str__(self):
         return "<OneSkinMesh %s, morph:%d>" % (
@@ -309,7 +311,7 @@ class OneSkinMesh(object):
             if faceVertexCount==3:
                 # triangle
                 self.vertexArray.addTriangle(
-                        material.name,
+                        self.obj_index, material.name,
                         v[0].index, v[1].index, v[2].index,
                         v[0].co, v[1].co, v[2].co,
                         # ToDo vertex normal
@@ -331,7 +333,7 @@ class OneSkinMesh(object):
             elif faceVertexCount==4:
                 # quadrangle
                 self.vertexArray.addTriangle(
-                        material.name,
+                        self.obj_index, material.name,
                         v[0].index, v[1].index, v[2].index,
                         v[0].co, v[1].co, v[2].co,
                         #v0.no, v1.no, v2.no,
@@ -350,7 +352,7 @@ class OneSkinMesh(object):
                         weightMap[v[2].index][1]
                         )
                 self.vertexArray.addTriangle(
-                        material.name,
+                        self.obj_index, material.name,
                         v[2].index, v[3].index, v[0].index,
                         v[2].co, v[3].co, v[0].co,
                         #v2.no, v3.no, v0.no,
@@ -369,6 +371,7 @@ class OneSkinMesh(object):
                         weightMap[v[0].index][1]
                         )
         bl.objectDelete(self.scene, copyObj)
+        self.obj_index+=1
 
     def __skin(self, obj):
         if not bl.objectHasShapeKey(obj):