[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3346] contrib/py/scripts/addons: Rewrite of the DirectX exporter currently in trunk.
Chris Foster
cdbfoster at gmail.com
Fri May 4 05:52:44 CEST 2012
Revision: 3346
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3346
Author: kiravakaan
Date: 2012-05-04 03:52:40 +0000 (Fri, 04 May 2012)
Log Message:
-----------
Rewrite of the DirectX exporter currently in trunk. The goal is a better object-oriented/easily extensible solution with many improvements along the way.
Currently only non-textured meshes are supported, but already vertex and normal export has been optimized.
Added Paths:
-----------
contrib/py/scripts/addons/io_scene_x/
contrib/py/scripts/addons/io_scene_x/__init__.py
contrib/py/scripts/addons/io_scene_x/export_x.py
Added: contrib/py/scripts/addons/io_scene_x/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_scene_x/__init__.py (rev 0)
+++ contrib/py/scripts/addons/io_scene_x/__init__.py 2012-05-04 03:52:40 UTC (rev 3346)
@@ -0,0 +1,137 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 3
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# All rights reserved.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+bl_info = {
+ "name": "DirectX X Format",
+ "author": "Chris Foster",
+ "version": (3, 0, 0),
+ "blender": (2, 6, 3),
+ "location": "File > Export > DirectX (.x)",
+ "description": "Export mesh vertices, UV's, materials, textures, "\
+ "vertex colors, armatures, empties, and actions.",
+ "warning": "This script is a WIP!",
+ "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"\
+ "Scripts/Import-Export/DirectX_Exporter",
+ "tracker_url": "https://projects.blender.org/tracker/index.php?"\
+ "func=detail&aid=22795",
+ "category": "Import-Export"}
+
+import bpy
+from bpy.props import BoolProperty
+from bpy.props import EnumProperty
+from bpy.props import StringProperty
+
+
+class ExportDirectX(bpy.types.Operator):
+ '''Export selection to DirectX'''
+
+ bl_idname = "export_scene.x"
+ bl_label = "Export DirectX"
+
+ filepath = StringProperty(subtype='FILE_PATH')
+
+ SelectedOnly = BoolProperty(
+ name="Export Selected Objects Only",
+ description="Export only selected objects",
+ default=True)
+
+ ApplyModifiers = BoolProperty(
+ name="Apply Modifiers",
+ description="Apply object modifiers before export",
+ default=False)
+
+ ExportArmatures = BoolProperty(
+ name="Export Armatures",
+ description="Export the bones armatures",
+ default=False)
+
+ ExportTextures = BoolProperty(
+ name="Export Textures",
+ description="Reference external image files to be used by the model",
+ default=True)
+
+ ExportVertexColors = BoolProperty(
+ name="Export Vertex Colors",
+ description="Export mesh vertex colors, if any",
+ default=False)
+
+ IncludeFrameRate = BoolProperty(
+ name="Include Frame Rate",
+ description="Include the AnimTicksPerSecond template which is "\
+ "used by some engines to control animation speed",
+ default=False)
+
+ ExportAnimation = EnumProperty(
+ name="Animations",
+ description="Select the type of animations to export. Only object "\
+ "and armature bone animations can be exported. Full Animation "\
+ "exports every frame",
+ items=(
+ ('NONE', "None", ""),
+ ('KEYS', "Keyframes Only", ""),
+ ('FULL', "Full Animation", "")),
+ default='NONE')
+
+ ExportActionsAsSets = BoolProperty(
+ name="Export Actions as AnimationSets",
+ description="Export each action of each object as a separate "\
+ "AnimationSet. Otherwise all current actions are lumped "\
+ "together into a single set",
+ default=False)
+
+ Verbose = BoolProperty(
+ name="Verbose",
+ description="Run the exporter in debug mode. Check the console for "\
+ "output",
+ default=False)
+
+ def execute(self, context):
+ self.filepath = bpy.path.ensure_ext(self.filepath, ".x")
+
+ import export_x
+ Exporter = export_x.DirectXExporter(self, context)
+ Exporter.Export() # XXX CHANGE THIS
+ return {'FINISHED'}
+
+ def invoke(self, context, event):
+ if not self.filepath:
+ self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".x")
+ context.window_manager.fileselect_add(self)
+ return {'RUNNING_MODAL'}
+
+
+def menu_func(self, context):
+ self.layout.operator(ExportDirectX.bl_idname, text="DirectX (.x)")
+
+
+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
Added: contrib/py/scripts/addons/io_scene_x/export_x.py
===================================================================
--- contrib/py/scripts/addons/io_scene_x/export_x.py (rev 0)
+++ contrib/py/scripts/addons/io_scene_x/export_x.py 2012-05-04 03:52:40 UTC (rev 3346)
@@ -0,0 +1,392 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 3
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# All rights reserved.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+from math import radians
+
+import bpy
+from mathutils import *
+
+
+class DirectXExporter:
+ def __init__(self, Config, context):
+ self.Config = Config
+ self.context = context
+
+ self.File = File(self.Config.filepath)
+
+ self.Log("Setting up coordinate system...")
+ # SystemMatrix converts from right-handed, z-up to left-handed, y-up
+ self.SystemMatrix = (Matrix.Scale(-1, 4, Vector((0, 0, 1))) *
+ Matrix.Rotation(radians(-90), 4, 'X'))
+ self.Log("Done")
+
+ self.Log("Generating object lists for export...")
+ if self.Config.SelectedOnly:
+ ExportList = list(self.context.selected_objects)
+ else:
+ ExportList = list(self.context.scene.objects)
+
+ # ExportMap maps Blender objects to ExportObjects
+ self.ExportMap = {} # XXX Do we keep ExportMap around in self? Or should it be local?
+ for Object in ExportList:
+ if Object.type == 'EMPTY':
+ self.ExportMap[Object] = ExportObject(self.Config, self, Object)
+ elif Object.type == 'MESH':
+ self.ExportMap[Object] = MeshExportObject(self.Config, self,
+ Object)
+ elif Object.type == 'ARMATURE':
+ self.ExportMap[Object] = ArmatureExportObject(self.Config, self,
+ Object)
+
+ # Find the objects who do not have a parent or whose parent we are
+ # not exporting
+ self.RootExportList = [Object for Object in self.ExportMap.values()
+ if Object.BlenderObject.parent not in ExportList]
+
+ # Determine each object's children from the pool of ExportObjects
+ for Object in self.ExportMap.values():
+ Children = Object.BlenderObject.children
+ Object.Children = []
+ for Child in Children:
+ if Child in self.ExportMap:
+ Object.Children.append(self.ExportMap[Child])
+ self.Log("Done")
+
+ # "Public" Interface
+
+ def Export(self):
+ self.Log("Exporting to {}".format(self.File.FilePath),
+ MessageVerbose=False)
+
+ self.Log("Opening file...")
+ self.File.Open()
+ self.Log("Done")
+
+ self.Log("Writing header...")
+ self.__WriteHeader()
+ self.Log("Done")
+
+ self.Log("Opening Root frame...")
+ self.__OpenRootFrame()
+ self.Log("Done")
+
+ self.Log("Writing objects...")
+ for Object in self.RootExportList:
+ Object.Write()
+ self.Log("Done")
+
+ self.Log("Closing Root frame...")
+ self.__CloseRootFrame()
+ self.Log("Done")
+
+ self.File.Close()
+
+ def Log(self, String, MessageVerbose=True):
+ if self.Config.Verbose == True or MessageVerbose == False:
+ print(String)
+
+ # "Private" Methods
+
+ def __WriteHeader(self):
+ self.File.Write("xof 0303txt 0032\n\n")
+
+ if self.Config.IncludeFrameRate:
+ self.File.Write("template AnimTicksPerSecond {\n\
+ <9E415A43-7BA6-4a73-8743-B73D47E88476>\n\
+ DWORD AnimTicksPerSecond;\n\
+}\n\n")
+ if self.Config.ExportArmatures:
+ self.File.Write("template XSkinMeshHeader {\n\
+ <3cf169ce-ff7c-44ab-93c0-f78f62d172e2>\n\
+ WORD nMaxSkinWeightsPerVertex;\n\
+ WORD nMaxSkinWeightsPerFace;\n\
+ WORD nBones;\n\
+}\n\n\
+template SkinWeights {\n\
+ <6f0d123b-bad2-4167-a0d0-80224f25fabb>\n\
+ STRING transformNodeName;\n\
+ DWORD nWeights;\n\
+ array DWORD vertexIndices[nWeights];\n\
+ array float weights[nWeights];\n\
+ Matrix4x4 matrixOffset;\n\
+}\n\n")
+
+ # Start the Root frame and write its transform matrix
+ def __OpenRootFrame(self):
+ self.File.Write("Frame Root {\n")
+ self.File.Indent()
+
+ self.File.Write("FrameTransformMatrix {\n")
+ self.File.Indent()
+ Util.WriteMatrix(self.File, self.SystemMatrix)
+ self.File.Unindent()
+ self.File.Write("}\n")
+
+ def __CloseRootFrame(self):
+ self.File.Unindent()
+ self.File.Write("} // End of Root\n")
+
+
+class ExportObject:
+ def __init__(self, Config, Exporter, BlenderObject):
+ self.Config = Config
+ self.Exporter = Exporter
+ self.BlenderObject = BlenderObject
+
+ self.SafeName = Util.SafeName(self.BlenderObject.name)
+ self.Children = []
+
+ def __repr__(self):
+ return "[ExportObject: {}]".format(self.BlenderObject.name)
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list