[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3180] contrib/py/scripts/addons/ io_export_marmalade.py: clean-up to simplify maintenance: remove non optimized export.

Benoit Muller benoit.muller at laposte.net
Tue Mar 27 00:20:39 CEST 2012


Revision: 3180
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3180
Author:   benoitmuller
Date:     2012-03-26 22:20:23 +0000 (Mon, 26 Mar 2012)
Log Message:
-----------
clean-up to simplify maintenance: remove non optimized export. Clean to minimize changes that will be required by 2.63.

Modified Paths:
--------------
    contrib/py/scripts/addons/io_export_marmalade.py

Modified: contrib/py/scripts/addons/io_export_marmalade.py
===================================================================
--- contrib/py/scripts/addons/io_export_marmalade.py	2012-03-25 21:24:21 UTC (rev 3179)
+++ contrib/py/scripts/addons/io_export_marmalade.py	2012-03-26 22:20:23 UTC (rev 3180)
@@ -22,7 +22,7 @@
 bl_info = {
     "name": "Marmalade Cross-platform Apps (.group)",
     "author": "Benoit Muller",
-    "version": (0, 5, 3),
+    "version": (0, 5, 4),
     "blender": (2, 6, 0),
     "location": "File > Export > Marmalade cross-platform Apps (.group)",
     "description": "Export Marmalade Format files (.group)",
@@ -54,7 +54,6 @@
     def __init__(self,
                  context,
                  FilePath,
-                 Optimized=True,
                  CoordinateSystem=1,
                  FlipNormals=False,
                  ApplyModifiers=False,
@@ -71,7 +70,6 @@
                  Verbose=False):
         self.context = context
         self.FilePath = FilePath
-        self.Optimized = Optimized
         self.CoordinateSystem = int(CoordinateSystem)
         self.FlipNormals = FlipNormals
         self.ApplyModifiers = ApplyModifiers
@@ -98,10 +96,6 @@
     if Config.Verbose:
         print("Done")
 
-    if Config.MergeModes > 0:
-        # Merge mode only work with Optimised setting
-        Config.Optimized = True
-
     if Config.Verbose:
         print("writing group header")
 
@@ -162,14 +156,6 @@
             if Object.type in {'ARMATURE', 'EMPTY', 'MESH'}]
 
 
-#Returns the vertex count of Mesh in not optimized version, counting each vertex for every face.
-def GetNonOptimizedMeshVertexCount(Mesh):
-    VertexCount = 0
-    for Face in Mesh.faces:
-        VertexCount += len(Face.vertices)
-    return VertexCount
-
-
 #Returns the file path of first image texture from Material.
 def GetMaterialTextureFullPath(Config, Material):
     if Material:
@@ -290,8 +276,7 @@
             if Config.MergeModes == 0:
                 #one geo per Object, so use name of Object for the Geo file
                 geoFile, mtlFile = CreateGeoMtlFiles(Config, StripName(Object.name))
-                if Config.Optimized == True:
-                    GeoModel = CGeoModel(StripName(Object.name))  
+                GeoModel = CGeoModel(StripName(Object.name))  
                 
             # Write the Mesh in the Geo file   
             WriteMesh(Config, Object, Mesh, geoFile, mtlFile, GeoModel)
@@ -393,63 +378,29 @@
         print (" ERROR not geo file arguments in WriteMesh method")
         return
 
-    if Config.Optimized:
-        if GeoModel == None:
-            print (" ERROR not GeoModel arguments in WriteMesh method")
-            return
+    if GeoModel == None:
+        print (" ERROR not GeoModel arguments in WriteMesh method")
+        return
 
-        BuildOptimizedGeo(Config, Object, Mesh, GeoModel)
-        if Config.MergeModes == 0 or Config.MergeModes == 2:
-            #if we don't merge, or if we write several meshes into one file ... write the mesh everytime we do an object
-            GeoModel.PrintGeoMesh(geoFile)
+    BuildOptimizedGeo(Config, Object, Mesh, GeoModel)
+    if Config.MergeModes == 0 or Config.MergeModes == 2:
+        #if we don't merge, or if we write several meshes into one file ... write the mesh everytime we do an object
+        GeoModel.PrintGeoMesh(geoFile)
  
-    else:
-        #exports not optimized by face (duplicated vertex, normals might be better in rare cases)
-        if Config.Verbose:
-            print("      Writing Mesh Vertices and normals...")
-        WriteMeshVerticesAndNormals(Config, Object, Mesh, geoFile)
-        if Config.Verbose:
-            print("      Done\n      Writing Mesh Vertices and Normals...")
-        bVertexColors = False
-        if Config.ExportVertexColors and (len(Mesh.vertex_colors) > 0):
-            if Config.Verbose:
-                print("      Writing Mesh Vertices Colors...")
-            bVertexColors = WriteMeshVerticesColors(Config, Mesh, geoFile)
-            if Config.Verbose:
-                print("      Done")
-        bUVTextures = False
-        if Config.ExportTextures and (len(Mesh.uv_textures) > 0):
-            if Config.Verbose:
-                print("      Writing Mesh UV Coordinates...")
-            bUVTextures = WriteMeshUVCoordinates(Config, Mesh, geoFile)
-            if Config.Verbose:
-                print("      Done")
-        if Config.Verbose:
-            print("      Writing Poly QuadsTris...")
-        WriteMeshPoly(Config, Mesh, geoFile, bVertexColors, bUVTextures)
-        if Config.Verbose:
-            print("      Done")
     if Config.Verbose:
         print("      Done\n      Writing Mesh Materials...")
 
     if Config.MergeModes == 0:
         #No merge, so we can diretly write the Mtl file associated to this object
-        if Config.Optimized == False:
-            WriteMeshMaterials(Config, Mesh, mtlFile)
-            geoFile.write("\t}\n")
-        else:
-            WriteMeshMaterialsForGeoModel(Config, mtlFile, GeoModel)
+        WriteMeshMaterialsForGeoModel(Config, mtlFile, GeoModel)
 
     if Config.Verbose:
         print("      Done")
   
     if Config.ExportArmatures:
         if Config.Verbose:
-            print("      Writing Mes Weights...")
-        if Config.Optimized:
-            WriteMeshSkinWeightsForGeoModel(Config, Object, Mesh, GeoModel)
-        else:
-            WriteMeshSkinWeights(Config, Object, Mesh)
+            print("      Writing Mesh Weights...")
+        WriteMeshSkinWeightsForGeoModel(Config, Object, Mesh, GeoModel)
         if Config.Verbose:
             print("      Done")
 
@@ -819,6 +770,7 @@
 
         GeoModel.EndPoly()
 
+
                               
 #############
 # Get the list of Material in use by the CGeoModel
@@ -828,283 +780,6 @@
         WriteMaterial(Config, mtlFile, Material)
 
 
-##################### Not Optimized Export, we use a Face export
-
-
-def WriteMeshVerticesAndNormals(Config,  Object, Mesh, geoFile):
-    # Not optimized, simply iterate Blender Face, and writes all face vertices
-    # Marmalade groups per material, and then groups per Tir and Quad.
-    # So generate vertices grouped together per Tri of the same material, and same quad of the same material
-    geoFile.write("\tCMesh\n")
-    geoFile.write("\t{\n")
-    geoFile.write("\t\tname \"%s\"\n" % (StripName(Object.name)))
-    geoFile.write("\t\tCVerts\n")
-    geoFile.write("\t\t{\n")
-    Index = 0
-    VertexCount = GetNonOptimizedMeshVertexCount(Mesh)
-    geoFile.write("\t\t\tnumVerts %d\n" % VertexCount)
-                
-    if Config.Verbose:
-            print("      Writing Mesh vertices...%d => %d" % (len(Mesh.vertices), VertexCount))
-    matCount =  len(Mesh.materials)
-    if matCount == 0:
-        matCount = 1  #No material defined for the Mesh !!!! => generate a default Material
-    for matIndex in range(0, matCount):
-        if Config.Verbose:
-            print("      Material Index: %d >" % matIndex)
-        for polyCount in range(3, 5):
-            faceCount = 0
-            for Face in Mesh.faces:
-                if Face.material_index == matIndex:
-                    if len(Face.vertices) == polyCount:
-                        Vertices = list(Face.vertices)
-                        faceCount = faceCount + 1                           
-                        if Config.CoordinateSystem == 1:
-                            Vertices = Vertices[::-1]
-                        for Vertex in [Mesh.vertices[Vertex] for Vertex in Vertices]:
-                            Position = Vertex.co
-                            geoFile.write("\t\t\tv { %.9f, %.9f, %.9f }\n" % (Position[0], Position[1], Position[2]))            
-            if Config.Verbose and polyCount == 3:
-                print("         Tri Poly count  Index: %d" % faceCount)
-            elif Config.Verbose and polyCount == 4:
-                print("         Quad Poly count  Index: %d" % faceCount)
-    geoFile.write("\t\t}\n")
-
-    #WriteMeshNormals
-    geoFile.write("\t\tCVertNorms\n")
-    geoFile.write("\t\t{\n")
-    geoFile.write("\t\t\tnumVertNorms  %d\n" % VertexCount)
-      
-    if Config.Verbose:
-            print("      Writing Mesh normals...")
-    matCount =  len(Mesh.materials)
-    if matCount == 0:
-        matCount = 1  # No material defined for the Mesh !!!! => generate a default Material
-    for matIndex in range(0, matCount):
-        if Config.Verbose:
-            print("      Material Index: %d >" % matIndex)
-        for polyCount in range(3, 5):
-            faceCount = 0
-            for Face in Mesh.faces:
-                 if Face.material_index == matIndex:
-                    if len(Face.vertices) == polyCount:
-                        Vertices = list(Face.vertices)
-                        faceCount = faceCount + 1
-                        if Config.CoordinateSystem == 1:
-                            Vertices = Vertices[::-1]
-                        for Vertex in [Mesh.vertices[Vertex] for Vertex in Vertices]:
-                            if Face.use_smooth:
-                                Normal = Vertex.normal
-                            else:
-                                Normal = Face.normal
-                            if Config.FlipNormals:
-                                Normal = -Normal
-                            geoFile.write("\t\t\tvn { %.9f, %.9f, %.9f }\n" % (Normal[0], Normal[1], Normal[2]))            
-            if Config.Verbose and polyCount == 3:
-                print("         Tri Poly count  Index: %d" % faceCount)
-            elif Config.Verbose and polyCount == 4:
-                print("         Quad Poly count  Index: %d" % faceCount)
-    geoFile.write("\t\t}\n")
-
-
-def WriteMeshVerticesColors (Config, Mesh, geoFile):
-    if len(Mesh.vertex_colors) > 0:
-        vertexColours = Mesh.vertex_colors[0].data
-        if len(vertexColours) > 0:
-            geoFile.write("\t\tCVertCols\n")
-            geoFile.write("\t\t{\n")
-            Index = 0
-            VertexCount = GetNonOptimizedMeshVertexCount(Mesh)
-            geoFile.write("\t\t\tnumVertCols %d\n" % VertexCount)
-                                
-            if Config.Verbose:
-                    print("      Writing Mesh vertices Colors...%d" % (len(Mesh.vertices)))
-                    
-            matCount =  len(Mesh.materials)
-            if matCount == 0:

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list