[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2084] trunk/py/scripts/addons/ io_export_directx_x.py: - File was somehow reverted to a ways back.

Chris Foster cdbfoster at gmail.com
Sun Jul 3 02:56:42 CEST 2011


Revision: 2084
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2084
Author:   kiravakaan
Date:     2011-07-03 00:56:42 +0000 (Sun, 03 Jul 2011)
Log Message:
-----------
- File was somehow reverted to a ways back.  Fixed now.
- Fix for relative texture paths that contain folders in them.

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

Modified: trunk/py/scripts/addons/io_export_directx_x.py
===================================================================
--- trunk/py/scripts/addons/io_export_directx_x.py	2011-07-03 00:14:01 UTC (rev 2083)
+++ trunk/py/scripts/addons/io_export_directx_x.py	2011-07-03 00:56:42 UTC (rev 2084)
@@ -16,13 +16,13 @@
 #  ***** GPL LICENSE BLOCK *****
 
 bl_info = {
-    "name": "Export DirectX Model Format (.x)",
+    "name": "DirectX Model Format (.x)",
     "author": "Chris Foster (Kira Vakaan)",
-    "version": (2, 1),
+    "version": (2, 1, 2),
     "blender": (2, 5, 8),
     "api": 37702,
-    "location": "File > Export",
-    "description": "Export to the DirectX Model Format (.x)",
+    "location": "File > Export > DirectX (.x)",
+    "description": "Export DirectX Model Format (.x)",
     "warning": "",
     "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
         "Scripts/Import-Export/DirectX_Exporter",
@@ -66,8 +66,15 @@
 
 
 def LegalName(Name):
-    NewName = Name.replace(".", "_")
-    NewName = NewName.replace(" ", "_")
+    
+    def ReplaceSet(String, OldSet, NewChar):
+        for OldChar in OldSet:
+            String = String.replace(OldChar, NewChar)
+        return String
+    
+    import string
+    
+    NewName = ReplaceSet(Name, string.punctuation, "_")
     if NewName[0].isdigit() or NewName in ["ARRAY",
                                            "DWORD",
                                            "UCHAR",
@@ -97,7 +104,7 @@
         print("Done")
 
     if Config.Verbose:
-        print("Generating Object list for export...")
+        print("Generating Object list for export... (Root parents only)")
     if Config.ExportMode == 1:
         Config.ExportList = [Object for Object in Config.context.scene.objects
                              if Object.type in ("ARMATURE", "EMPTY", "MESH")
@@ -108,7 +115,7 @@
         Config.ExportList = [Object for Object in ExportList
                              if Object.parent not in ExportList]
     if Config.Verbose:
-        print("Done")
+        print("  List: {}\nDone".format(Config.ExportList))
 
     if Config.Verbose:
         print("Setting up...")
@@ -146,6 +153,9 @@
     
     Config.Whitespace -= 1
     Config.File.write("{}}} //End of Root Frame\n".format("  " * Config.Whitespace))
+    
+    if Config.Verbose:
+        print("Objects Exported: {}".format(Config.ExportList))
 
     if Config.ExportAnimation:
         if Config.IncludeFrameRate:
@@ -189,7 +199,7 @@
         #Create a list of Textures that have type "IMAGE"
         ImageTextures = [Material.texture_slots[TextureSlot].texture for TextureSlot in Material.texture_slots.keys() if Material.texture_slots[TextureSlot].texture.type == "IMAGE"]
         #Refine a new list with only image textures that have a file source
-        ImageFiles = [os.path.basename(Texture.image.filepath) for Texture in ImageTextures if Texture.image.source == "FILE"]
+        ImageFiles = [os.path.basename(Texture.image.filepath[2:]) for Texture in ImageTextures if Texture.image.source == "FILE"]
         if ImageFiles:
             return ImageFiles[0]
     return None
@@ -256,8 +266,11 @@
             WriteArmatureBones(Config, Object, ParentList)
             if Config.Verbose:
                 print("    Done")
-
+        
         ChildList = GetObjectChildren(Object)
+        if Config.ExportMode == 2: #Selected Objects Only
+            ChildList = [Child for Child in ChildList
+                         if Child in Config.context.selected_objects]
         if Config.Verbose:
             print("    Writing Children...")
         WriteObjects(Config, ChildList)
@@ -274,11 +287,11 @@
                     Object2 = Object.copy()
                     for Modifier in [Modifier for Modifier in Object2.modifiers if Modifier.type == "ARMATURE"]:
                         Object2.modifiers.remove(Modifier)
-                    Mesh = Object2.create_mesh(bpy.context.scene, True, "PREVIEW")
+                    Mesh = Object2.to_mesh(bpy.context.scene, True, "PREVIEW")
                 else:
-                    Mesh = Object.create_mesh(bpy.context.scene, True, "PREVIEW")
+                    Mesh = Object.to_mesh(bpy.context.scene, True, "PREVIEW")
             else:
-                Mesh = Object.create_mesh(bpy.context.scene, False, "PREVIEW")
+                Mesh = Object.to_mesh(bpy.context.scene, False, "PREVIEW")
             if Config.Verbose:
                 print("    Done")
                 print("    Writing Mesh...")
@@ -489,20 +502,20 @@
         Config.File.write("{}Material {} {{\n".format("  " * Config.Whitespace, LegalName(Material.name)))
         Config.Whitespace += 1
 
-        Diffuse = list(Material.diffuse_color)
+        Diffuse = list(Vector(Material.diffuse_color) * Material.diffuse_intensity)
         Diffuse.append(Material.alpha)
-        Specularity = Material.specular_intensity
-        Specular = list(Material.specular_color)
+        Specularity = 1000 * (Material.specular_hardness - 1.0) / (511.0 - 1.0) # Map Blender's range of 1 - 511 to 0 - 1000
+        Specular = list(Vector(Material.specular_color) * Material.specular_intensity)
 
         Config.File.write("{}{:9f};{:9f};{:9f};{:9f};;\n".format("  " * Config.Whitespace, Diffuse[0], Diffuse[1], Diffuse[2], Diffuse[3]))
-        Config.File.write("{}{:9f};\n".format("  " * Config.Whitespace, 2 * (1.0 - Specularity)))
+        Config.File.write("{} {:9f};\n".format("  " * Config.Whitespace, Specularity))
         Config.File.write("{}{:9f};{:9f};{:9f};;\n".format("  " * Config.Whitespace, Specular[0], Specular[1], Specular[2]))
     else:
         Config.File.write("{}Material Default_Material {{\n".format("  " * Config.Whitespace))
         Config.Whitespace += 1
-        Config.File.write("{} 1.000000; 1.000000; 1.000000; 1.000000;;\n".format("  " * Config.Whitespace))
-        Config.File.write("{} 1.500000;\n".format("  " * Config.Whitespace))
-        Config.File.write("{} 1.000000; 1.000000; 1.000000;;\n".format("  " * Config.Whitespace))
+        Config.File.write("{} 0.800000; 0.800000; 0.800000; 0.800000;;\n".format("  " * Config.Whitespace))
+        Config.File.write("{} 96.078431;\n".format("  " * Config.Whitespace)) # 1000 * (50 - 1) / (511 - 1)
+        Config.File.write("{} 0.500000; 0.500000; 0.500000;;\n".format("  " * Config.Whitespace))
     Config.File.write("{} 0.000000; 0.000000; 0.000000;;\n".format("  " * Config.Whitespace))
     if Config.ExportTextures:
         Texture = GetMaterialTexture(Material)
@@ -1193,10 +1206,8 @@
     Verbose = BoolProperty(name="Verbose", description="Run the exporter in debug mode.  Check the console for output.", default=False)
 
     def execute(self, context):
-        #Append .x if needed
-        FilePath = self.filepath
-        if not FilePath.lower().endswith(".x"):
-            FilePath += ".x"
+        #Append .x
+        FilePath = os.path.splitext(self.filepath)[0] + ".x"
 
         Config = DirectXExporterSettings(context,
                                          FilePath,
@@ -1225,12 +1236,16 @@
 
 
 def register():
+    bpy.utils.register_module(__name__)
+
     bpy.types.INFO_MT_file_export.append(menu_func)
 
 
 def unregister():
+    bpy.utils.unregister_module(__name__)
+
     bpy.types.INFO_MT_file_export.remove(menu_func)
 
 
 if __name__ == "__main__":
-    register()
\ No newline at end of file
+    register()



More information about the Bf-extensions-cvs mailing list