[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3260] trunk/py/scripts/addons/ io_export_unreal_psk_psa.py: Fixed merge meshes and message shows.

John Phan darkneter at gmail.com
Sat Apr 14 05:47:00 CEST 2012


Revision: 3260
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3260
Author:   darknet
Date:     2012-04-14 03:46:49 +0000 (Sat, 14 Apr 2012)
Log Message:
-----------
Fixed merge meshes and message shows.

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	2012-04-13 23:50:41 UTC (rev 3259)
+++ trunk/py/scripts/addons/io_export_unreal_psk_psa.py	2012-04-14 03:46:49 UTC (rev 3260)
@@ -113,7 +113,6 @@
 # ======================================================================
 # TODO: remove this 1am hack
 nbone = 0
-bDeleteMergeMesh = False
 exportmessage = "Export Finish" 
 
 ########################################################################
@@ -607,57 +606,59 @@
     mesh.vertices[v1].co == mesh.vertices[v2].co or \
     mesh.vertices[v2].co == mesh.vertices[v0].co)
     return False
+#blender 2.63 format using the Operators/Commands to merge the meshes into one
+def meshmerge(selectedobjects):
+    bpy.ops.object.mode_set(mode='OBJECT')
+    cloneobjects = []
+    if len(selectedobjects) > 1:
+        print("selectedobjects:",len(selectedobjects))
+        count = 0 #reset count
+        for count in range(len( selectedobjects)):
+            #print("Index:",count)
+            if selectedobjects[count] != None:
+                cloneobjects.append(selectedobjects[count])
+        for i in bpy.data.objects: i.select = False #deselect all objects
+        count = 0 #reset count
+        for count in range(len( cloneobjects)):
+            if count == 0:
+                bpy.context.scene.objects.active = cloneobjects[count]
+                print("Set Active Object:",cloneobjects[count].name)
+            cloneobjects[count].select = True
+        bpy.ops.object.join()
+        return cloneobjects[0]	
 
 ##################################################
 # http://en.wikibooks.org/wiki/Blender_3D:_Blending_Into_Python/Cookbook#Triangulate_NMesh
-#blender 2.50 format using the Operators/command convert the mesh to tri mesh
+#blender 2.63 format using the Operators/Commands to convert the mesh to tri mesh
 def triangulateNMesh(object):
-    global bDeleteMergeMesh
-    bneedtri = False
+    print("Converting quad to tri mesh...")
     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')
-    print("Checking mesh if needs to convert quad to Tri...")
-    for face in object.data.faces:
-        if (len(face.vertices) > 3):
-            bneedtri = True
-            break
-    
-    bpy.ops.object.mode_set(mode='OBJECT')
-    if bneedtri == True:
-        print("Converting quad to tri mesh...")
-        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
-        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
-        bpy.context.scene.unrealtriangulatebool = True
-        print("Triangulate Mesh Done!")
-        if bDeleteMergeMesh == True:
-            print("Remove Merge tmp Mesh [ " ,object.name, " ] from scene!" )
-            bpy.ops.object.mode_set(mode='OBJECT') # set it in object
-            bpy.context.scene.objects.unlink(object)
-    else:
-        bpy.context.scene.unrealtriangulatebool = False
-        print("No need to convert tri mesh.")
-        me_ob = 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
 
 #Texture not working still find a way to get it work
 # Actual object parsing functions
 def parse_meshes(blender_meshes, psk_file):	
-    global bDeleteMergeMesh, exportmessage
+    global exportmessage
     print("Number of Object Meshes:",len(blender_meshes))
     for current_obj in blender_meshes: #number of mesh that should be one mesh here
         #material
@@ -689,16 +690,23 @@
         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)
         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:
+            
             has_UV = False
         
         for face in me.tessfaces:
-            print("Vertices count:",len(face.vertices))
+            #print("Vertices count:",len(face.vertices))
             #get or create the current material
             object_material_index = face.material_index
             psk_file.GetMatByIndex(object_material_index)
@@ -712,13 +720,14 @@
             if not is_1d_face(face,me):#face , Mesh
                 wedge_list = []
                 vect_list = []
-                faceUV = uv_layer[face.index]#UV TEXTURE
                 
+                
                 for i in range(3): #UV TEXTURE, VERTICES
                     vert_index = face.vertices[i]
                     vert = me.vertices[vert_index]
                     uv = []
                     if (has_UV):
+                        faceUV = uv_layer[face.index]#UV TEXTURE
                         if len(faceUV.uv) != 3:
                             print ("WARNING: Current face is missing UV coordinates - writing 0,0...")
                             print ("WARNING: Face has more than 3 UVs - writing 0,0...")
@@ -807,10 +816,15 @@
                 #print("smooth:",(current_face.use_smooth))
                 #not sure if this right
                 #tri.SmoothingGroups
+                print(face.use_smooth)
                 if face.use_smooth == True:
-                    tri.SmoothingGroups = 1
-                else:
                     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)
@@ -864,30 +878,9 @@
             #bone name, [point id and wieght]
             #print("Add Vertex Group:",obvgroup.name, " No. Points:",len(vert_list))
             psk_file.VertexGroups[obvgroup.name] = vert_list
+        #unlink copy of object from scene
+        bpy.context.scene.objects.unlink(current_obj)
         
-        #unrealtriangulatebool #this will remove the mesh from the scene
-        '''
-        if (bpy.context.scene.unrealtriangulatebool == True) and (bDeleteMergeMesh == True):
-            #if bDeleteMergeMesh == True:
-            #    print("Removing merge mesh.")
-            print("Remove tmp Mesh [ " ,current_obj.name, " ] from scene >"  ,(bpy.context.scene.unrealtriangulatebool ))
-            bpy.ops.object.mode_set(mode='OBJECT') # set it in object
-            bpy.context.scene.objects.unlink(current_obj)
-        el
-        '''
-        #if bDeleteMergeMesh == True:
-            #print("Remove Merge tmp Mesh [ " ,current_obj.name, " ] from scene >"  ,(bpy.context.scene.unrealtriangulatebool ))
-            #bpy.ops.object.mode_set(mode='OBJECT') # set it in object
-            #bpy.context.scene.objects.unlink(current_obj)
-        #elif bpy.context.scene.unrealtriangulatebool == True:
-            #print("Remove tri tmp Mesh [ " ,current_obj.name, " ] from scene >"  ,(bpy.context.scene.unrealtriangulatebool ))
-            #bpy.ops.object.mode_set(mode='OBJECT') # set it in object
-            #bpy.context.scene.objects.unlink(current_obj)
-        #if bDeleteMergeMesh == True:
-            #print("Remove merge Mesh [ " ,current_obj.name, " ] from scene")
-            #bpy.ops.object.mode_set(mode='OBJECT') # set it in object
-            #bpy.context.scene.objects.unlink(current_obj)    
-        
 def make_fquat(bquat):
     quat = FQuat()
     #flip handedness for UT = set x,y,z to negative (rotate in other direction)
@@ -1473,37 +1466,9 @@
                 print("---- Action End ----")
                 print("==== Finish Action Build ====")
     
-def meshmerge(selectedobjects):
-    bpy.ops.object.mode_set(mode='OBJECT')
-    cloneobjects = []
-    if len(selectedobjects) > 1:
-        print("selectedobjects:",len(selectedobjects))
-        count = 0 #reset count
-        for count in range(len( selectedobjects)):
-            #print("Index:",count)
-            if selectedobjects[count] != None:
-                me_da = selectedobjects[count].data.copy() #copy data
-                me_ob = selectedobjects[count].copy() #copy object
-                #note two copy two types else it will use the current data or mesh
-                me_ob.data = me_da
-                bpy.context.scene.objects.link(me_ob)#link the object to the scene #current object location
-                print("Index:",count,"clone object",me_ob.name)

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list