[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3263] trunk/py/scripts/addons: Some clean up in coding.

John Phan darkneter at gmail.com
Sat Apr 14 18:29:50 CEST 2012


Revision: 3263
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3263
Author:   darknet
Date:     2012-04-14 16:29:49 +0000 (Sat, 14 Apr 2012)
Log Message:
-----------
Some clean up in coding. Fixed merge meshes.  Fixed error and fail message that will display.

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

Modified: trunk/py/scripts/addons/io_export_unreal_psk_psa.py
===================================================================
--- trunk/py/scripts/addons/io_export_unreal_psk_psa.py	2012-04-14 16:24:46 UTC (rev 3262)
+++ trunk/py/scripts/addons/io_export_unreal_psk_psa.py	2012-04-14 16:29:49 UTC (rev 3263)
@@ -114,7 +114,7 @@
 # TODO: remove this 1am hack
 nbone = 0
 exportmessage = "Export Finish" 
-
+exportfile = True
 ########################################################################
 # Generic Object->Integer mapping
 # the object must be usable as a dictionary key
@@ -631,36 +631,33 @@
 # http://en.wikibooks.org/wiki/Blender_3D:_Blending_Into_Python/Cookbook#Triangulate_NMesh
 #blender 2.63 format using the Operators/Commands to convert the mesh to tri mesh
 def triangulateNMesh(object):
-    print("Converting quad to tri mesh...")
+    print("Converting quad to tri mesh...",object.name)
     scene = bpy.context.scene
     bpy.ops.object.mode_set(mode='OBJECT')
     for i in scene.objects: i.select = False #deselect all objects
     object.select = True
     scene.objects.active = object #set the mesh object to current
-    bpy.ops.object.mode_set(mode='OBJECT')
-    me_da = object.data.copy() #copy data
-    me_ob = object.copy() #copy object
-    #note two copy two types else it will use the current data or mesh
-    me_ob.data = me_da
-    scene = bpy.context.scene
-    bpy.context.scene.objects.link(me_ob)#link the object to the scene #current object location
-    for i in scene.objects: i.select = False #deselect all objects
-    me_ob.select = True
-    scene.objects.active = me_ob #set the mesh object to current
     bpy.ops.object.mode_set(mode='EDIT') #Operators
     bpy.ops.mesh.select_all(action='SELECT')#select all the face/vertex/edge
     bpy.ops.mesh.quads_convert_to_tris() #Operators
     bpy.context.scene.update()
     bpy.ops.object.mode_set(mode='OBJECT') # set it in object
     print("Triangulate Mesh Done!")
-    return me_ob
+    return object
 
 #Texture not working still find a way to get it work
 # Actual object parsing functions
 def parse_meshes(blender_meshes, psk_file):	
-    global exportmessage
+    global exportmessage, exportfile
     print("Number of Object Meshes:",len(blender_meshes))
     for current_obj in blender_meshes: #number of mesh that should be one mesh here
+        if current_obj.parent != None:
+            print("Armature Found!")
+        else:
+            exportmessage = "Mesh is not parent to Armature!"
+            bpy.context.scene.objects.unlink(current_obj)
+            exportfile = False
+            return
         #material
         if len(current_obj.material_slots) > 0:
             counter = 0
@@ -681,8 +678,6 @@
                 counter += 1
                 print("PSK INDEX:",matdata.TextureIndex)
                 
-                
-                
         points = ObjMap()
         wedges = ObjMap()
         discarded_face_count = 0
@@ -690,19 +685,13 @@
         faceUV = None
         scene = bpy.context.scene #get current scene
         EXPORT_APPLY_MODIFIERS = True
-        currentmeshobject = current_obj;
-        
-        current_obj = triangulateNMesh(currentmeshobject) #convert tri incase
-        bpy.context.scene.objects.unlink(currentmeshobject)
+        current_obj = triangulateNMesh(current_obj) #convert tri incase
         me = current_obj.to_mesh(scene, EXPORT_APPLY_MODIFIERS, 'PREVIEW') #apply modified mesh and write mesh
-        
-        #print(dir(me))
-        
         faceuv = len(me.uv_textures) > 0 #check if has uv texture
         if faceuv:
             uv_layer = me.tessface_uv_textures.active.data[:]
         else:
-            
+            print("No UV Texture is added and will be ignore!")
             has_UV = False
         
         for face in me.tessfaces:
@@ -715,13 +704,13 @@
             if len(face.vertices) != 3:
                 #raise RuntimeError("Non-triangular face (%i)" % len(face.vertices))
                 exportmessage = "MESH IS NOT TRIANGLE (Alt + T)"
+                exportfile = False
                 return
             
             if not is_1d_face(face,me):#face , Mesh
                 wedge_list = []
                 vect_list = []
                 
-                
                 for i in range(3): #UV TEXTURE, VERTICES
                     vert_index = face.vertices[i]
                     vert = me.vertices[vert_index]
@@ -807,25 +796,19 @@
                     me.vertices[dindex0].select = True
                     me.vertices[dindex1].select = True
                     me.vertices[dindex2].select = True
-                    
-                    #raise RuntimeError("normal vector coplanar with face! points:", me.vertices[dindex0].co, current_mesh.vertices[dindex1].co, current_mesh.vertices[dindex2].co)
+                    print("normal vector coplanar with face! points:", me.vertices[dindex0].co, current_mesh.vertices[dindex1].co, current_mesh.vertices[dindex2].co)
                     exportmessage = "One of the face is dot or period or line, coplanar with the face"
+                    exportfile = False
+                    bpy.context.scene.objects.unlink(current_obj)
                     return 
                 #print(dir(current_face))
-                face.select = True
-                #print("smooth:",(current_face.use_smooth))
-                #not sure if this right
-                #tri.SmoothingGroups
-                print(face.use_smooth)
+                #face.select = True
+                
                 if face.use_smooth == True:
                     tri.SmoothingGroups = 0
                 else:
                     tri.SmoothingGroups = 1
-                #tri.SmoothingGroups = face.use_smooth
-                #tri.SmoothingGroups = hex(face.use_smooth)
-                #print(hex(True))
-                print(hex(face.use_smooth))
-                #tri.SmoothingGroups = 1
+                
                 tri.MatIndex = object_material_index
                 #print(tri)
                 psk_file.AddFace(tri)                
@@ -835,8 +818,14 @@
         print (" -- Dumping Mesh Points -- LEN:",len(points.dict))
         for point in points.items():
             psk_file.AddPoint(point)
-        #if len(points.dict) > 32767:
+        if len(points.dict) > 32767:
             #raise RuntimeError("Vertex point reach max limited 32767 in pack data. Your",len(points.dict))
+            print("Vertex point reach max limited 32767 in pack data. Your",len(points.dict))
+            exportmessage = "You have went over the limit on your Vectices/Vertex points. Limit is 32767."
+            exportfile = False
+            bpy.context.scene.objects.unlink(current_obj)
+            return
+            
         print (" -- Dumping Mesh Wedge -- LEN:",len(wedges.dict))
         
         for wedge in wedges.items():
@@ -989,6 +978,7 @@
         parse_bone(current_child_bone, psk_file, psa_file, my_id, 0, mainparent, parent_root)
 
 def parse_armature(blender_armature, psk_file, psa_file):
+    global exportmessage, exportfile
     print ("----- parsing armature -----")
     print ('blender_armature length: %i' % (len(blender_armature)))
     
@@ -1014,9 +1004,15 @@
         #will ingore this part of the ocde
         """
         if len(current_armature.bones) == 0:
-            raise RuntimeError("Warning add two bones else it will crash the unreal editor.")
+            #raise RuntimeError("Warning add two bones else it will crash the unreal editor.")
+            exportmessage = "Warning add two bones else it will crash the unreal editor."
+            exportfile = False
+            return
         if len(current_armature.bones) == 1:
-            raise RuntimeError("Warning add one more bone else it will crash the unreal editor.")
+            #raise RuntimeError("Warning add one more bone else it will crash the unreal editor.")
+            exportmessage = "Warning add one more bone else it will crash the unreal editor."
+            exportfile = False
+            return
 
         mainbonecount = 0;
         for current_bone in current_armature.bones: #list the bone. #note this will list all the bones.
@@ -1024,8 +1020,11 @@
                 mainbonecount += 1
         print("Main Bone",mainbonecount)
         if mainbonecount > 1:
-            #print("Warning there no main bone.")
-            raise RuntimeError("There too many Main bones. Number main bones:",mainbonecount)
+            print("Warning there no main bone.")
+            #raise RuntimeError("There too many Main bones. Number main bones:",mainbonecount)
+            exportmessage = "There no Main Bone!"
+            exportfile = False
+            return
         for current_bone in current_armature.bones: #list the bone. #note this will list all the bones.
             if(current_bone.parent is None):
                 parse_bone(current_bone, psk_file, psa_file, 0, 0, current_obj.matrix_local, None)
@@ -1468,7 +1467,7 @@
     
 def fs_callback(filename, context):
     #this deal with repeat export and the reset settings
-    global nbone, exportmessage
+    global nbone, exportmessage, exportfile
     nbone = 0
     
     start_time = time.clock()
@@ -1520,8 +1519,11 @@
     #if there 1 mesh in scene add to the array
     if len(blender_meshes) == 1:
         mesh = blender_meshes[0]
+        print("MESH NAME",blender_meshes[0].name)
         blender_meshes = []
-        blender_meshes.append(mesh.copy())
+        copymesh = mesh.copy()
+        bpy.context.scene.objects.link(copymesh)
+        blender_meshes.append(copymesh)
         print(" - One Mesh Scene")
     #if there more than one mesh and one mesh select add to array
     elif (len(blender_meshes) > 1) and (len(selectmesh) == 1):
@@ -1529,6 +1531,7 @@
             exportmessage = "Error, Mesh Object not Center right should be (0,0,0)."
             for mesh in selectmesh:#remove object
                 bpy.context.scene.objects.unlink(mesh)
+            exportfile = False
             return
         blender_meshes = []
         copymesh = selectmesh[0]
@@ -1562,6 +1565,7 @@
     else:
         print(" - Too Many Meshes!")
         exportmessage = " - Select Mesh(s) For Export!"
+        exportfile = False
         print(" - Select One Mesh Object!")
         bmesh = False
         return
@@ -1586,6 +1590,7 @@

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list