[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1844] trunk/py/scripts/addons/ io_export_unreal_psk_psa.py: clean and fixed up vertex groups.

John Phan darkneter at gmail.com
Sun Apr 17 21:59:41 CEST 2011


Revision: 1844
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1844
Author:   darknet
Date:     2011-04-17 19:59:41 +0000 (Sun, 17 Apr 2011)
Log Message:
-----------
clean and fixed up vertex groups.

Modified Paths:
--------------
    trunk/py/scripts/addons/io_export_unreal_psk_psa.py

Modified: trunk/py/scripts/addons/io_export_unreal_psk_psa.py
===================================================================
--- trunk/py/scripts/addons/io_export_unreal_psk_psa.py	2011-04-17 17:58:48 UTC (rev 1843)
+++ trunk/py/scripts/addons/io_export_unreal_psk_psa.py	2011-04-17 19:59:41 UTC (rev 1844)
@@ -83,12 +83,13 @@
 import datetime
 import bpy
 import mathutils
+import random
 import operator
 import sys
 
+
 from struct import pack, calcsize
 
-
 # REFERENCE MATERIAL JUST IN CASE:
 # 
 # U = x / sqrt(x^2 + y^2 + z^2)
@@ -112,6 +113,12 @@
 SIZE_VTRIANGLE = 12
 MaterialName = []
 
+# ======================================================================
+# TODO: remove this 1am hack
+nbone = 0
+bDeleteMergeMesh = False
+exportmessage = "Export Finish" 
+
 ########################################################################
 # Generic Object->Integer mapping
 # the object must be usable as a dictionary key
@@ -609,7 +616,6 @@
 
 ##################################################
 # http://en.wikibooks.org/wiki/Blender_3D:_Blending_Into_Python/Cookbook#Triangulate_NMesh
-bDeleteMergeMesh = False
 #blender 2.50 format using the Operators/command convert the mesh to tri mesh
 def triangulateNMesh(object):
     global bDeleteMergeMesh
@@ -654,46 +660,10 @@
         me_ob = object
     return me_ob
 
-#Blender Bone Index
-class BBone:
-    def __init__(self):
-        self.bone = ""
-        self.index = 0
-bonedata = []
-BBCount = 0    
-#deal with mesh bones groups vertex point
-def BoneIndex(bone):
-    global BBCount, bonedata
-    #print("//==============")
-    #print(bone.name , "ID:",BBCount)
-    BB = BBone()
-    BB.bone = bone.name
-    BB.index = BBCount
-    bonedata.append(BB)
-    BBCount += 1
-    for current_child_bone in bone.children:
-        BoneIndex(current_child_bone)
-
-def BoneIndexArmature(blender_armature):
-    global BBCount
-    #print("\n Buildng bone before mesh \n")
-    #objectbone = blender_armature.pose #Armature bone
-    #print(blender_armature)
-    objectbone = blender_armature[0].pose 
-    #print(dir(ArmatureData))
-    
-    for bone in objectbone.bones:
-        if(bone.parent is None):
-            BoneIndex(bone)
-            #BBCount += 1
-            break
-    
-
 # Actual object parsing functions
 def parse_meshes(blender_meshes, psk_file):
     #this is use to call the bone name and the index array for group index matches
-    global bonedata,bDeleteMergeMesh
-    #print("BONE DATA",len(bonedata))
+    global bDeleteMergeMesh
     print ("----- parsing meshes -----")
     print("Number of Object Meshes:",len(blender_meshes))
     for current_obj in blender_meshes: #number of mesh that should be one mesh here
@@ -888,11 +858,8 @@
                     tri.SmoothingGroups = 0
                 
                 tri.MatIndex = object_material_index
-                
-                
                 #print(tri)
-                psk_file.AddFace(tri)
-                
+                psk_file.AddFace(tri)                
             else:
                 discarded_face_count = discarded_face_count + 1
                 
@@ -902,7 +869,7 @@
         if len(points.dict) > 32767:
            raise RuntimeError("Vertex point reach max limited 32767 in pack data. Your",len(points.dict))
         print (" -- Dumping Mesh Wedge -- LEN:",len(wedges.dict))
-        		
+        
         for wedge in wedges.items():
             psk_file.AddWedge(wedge)
             
@@ -919,16 +886,17 @@
         #verts to bones for influences by having the VertexGroup named the same thing as
         #the bone
 
-        #vertex group.
-        for bonegroup in bonedata:
-            #print("bone gourp build:",bonegroup.bone)
+        #vertex group
+        for obvgroup in current_obj.vertex_groups:
+            #print("bone gourp build:",obvgroup.name)#print bone name
+            #print(dir(obvgroup))
             vert_list = []
             for current_vert in current_mesh.vertices:
                 #print("INDEX V:",current_vert.index)
                 vert_index = current_vert.index
                 for vgroup in current_vert.groups:#vertex groupd id
                     vert_weight = vgroup.weight
-                    if(bonegroup.index == vgroup.group):
+                    if(obvgroup.index == vgroup.group):
                         p = VPoint()
                         vpos = current_vert.co * current_obj.matrix_local
                         p.Point.X = vpos.x
@@ -939,8 +907,8 @@
                         v_item = (point_index, vert_weight)
                         vert_list.append(v_item)
             #bone name, [point id and wieght]
-            #print("Add Vertex Group:",bonegroup.bone, " No. Points:",len(vert_list))
-            psk_file.VertexGroups[bonegroup.bone] = vert_list
+            #print("Add Vertex Group:",obvgroup.name, " No. Points:",len(vert_list))
+            psk_file.VertexGroups[obvgroup.name] = vert_list
         
         #unrealtriangulatebool #this will remove the mesh from the scene
         '''
@@ -967,7 +935,6 @@
         
 def make_fquat(bquat):
     quat = FQuat()
-    
     #flip handedness for UT = set x,y,z to negative (rotate in other direction)
     quat.X = -bquat.x
     quat.Y = -bquat.y
@@ -986,9 +953,6 @@
     quat.W = bquat.w
     return quat
 
-# =================================================================================================
-# TODO: remove this 1am hack
-nbone = 0
 def parse_bone(blender_bone, psk_file, psa_file, parent_id, is_root_bone, parent_matrix, parent_root):
     global nbone     # look it's evil!
     #print '-------------------- Dumping Bone ---------------------- '
@@ -997,7 +961,6 @@
     if blender_bone.parent is None:
         parent_root = blender_bone
     
-    
     child_count = len(blender_bone.children)
     #child of parent
     child_parent = blender_bone.parent
@@ -1164,9 +1127,8 @@
     print ("Default FPS: 24" )
     
     cur_frame_index = 0
-    
-    if bpy.context.scene.unrealactionexportall :#if exporting all actions is ture then go do some work.
-        print("Exporting all action:",bpy.context.scene.unrealactionexportall)
+    if (bpy.context.scene.UEActionSetSettings == '1') or (bpy.context.scene.UEActionSetSettings == '2'):
+        print("Action Set(s) Settings Idx:",bpy.context.scene.UEActionSetSettings)
         print("[==== Action list Start====]")
         
         print("Number of Action set(s):",len(bpy.data.actions))
@@ -1186,7 +1148,8 @@
         
         for arm in blender_armatures:
             amatureobject = arm
-            
+        #print(dir(amatureobject))
+        collection = amatureobject.myCollectionUEA #collection of the object
         print("\n[==== Armature Object ====]")
         if amatureobject != None:
             print("Name:",amatureobject.name)
@@ -1196,6 +1159,20 @@
         print("[=========================]")
         
         for ActionNLA in bpy.data.actions:
+            FoundAction = True
+            if bpy.context.scene.UEActionSetSettings == '2':                
+                for c in collection:
+                    if c.name == ActionNLA.name:
+                        if c.mybool == True:
+                            FoundAction = True
+                        else:
+                            FoundAction = False
+                        break
+                if FoundAction == False:
+                    print("========================================")
+                    print("Skipping Action Set!",ActionNLA.name)
+                    print("========================================")
+                    #break
             print("\n==== Action Set ====")
             nobone = 0
             baction = True
@@ -1209,14 +1186,14 @@
                         break
             #if action groups matches the bones length and names matching the gourps do something
             if (len(ActionNLA.groups) == len(bonenames)) and (nobone == len(ActionNLA.groups)):
-                print("Action Set match: Pass")
+                #print("Action Set match: Pass")
                 baction = True
             else:
-                print("Action Set match: Fail")
-                print("Action Name:",ActionNLA.name)
+                #print("Action Set match: Fail")
+                #print("Action Name:",ActionNLA.name)
                 baction = False
             
-            if baction == True:
+            if (baction == True) and (FoundAction == True):
                 arm = amatureobject #set armature object
                 if not arm.animation_data:
                     print("======================================")
@@ -1231,7 +1208,10 @@
                     print("Armature has no animation, skipping...")
                     print("======================================")
                     break
+                print("Last Action Name:",arm.animation_data.action.name)
                 arm.animation_data.action = ActionNLA
+                print("Set Action Name:",arm.animation_data.action.name)
+                bpy.context.scene.update()
                 act = arm.animation_data.action
                 action_name = act.name
                 
@@ -1243,7 +1223,7 @@
                     
                 #this deal with action export control
                 if bHaveAction == True:
-                    
+                    print("------------------------------------")
                     print("Action Name:",action_name)
                     #look for min and max frame that current set keys
                     framemin, framemax = act.frame_range
@@ -1314,13 +1294,41 @@
                             head = pose_bone.head
                             
                             posebonemat = mathutils.Matrix(pose_bone.matrix)
+                            #print("quat",posebonemat)
+                            #
+                            # Error looop action get None in matrix
+                            # looping on each armature give invert and normalize for None
+                            #
                             parent_pose = pose_bone.parent
                             if parent_pose != None:
                                 parentposemat = mathutils.Matrix(parent_pose.matrix)
                                 #blender 2.4X it been flip around with new 2.50 (mat1 * mat2) should now be (mat2 * mat1)
+                                #print("posebonemat",posebonemat)

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list