[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4385] trunk/py/scripts/addons: - A ground-up rewrite of the DirectX . x exporter for better design and extensibility.
Chris Foster
cdbfoster at gmail.com
Sun Mar 17 20:27:11 CET 2013
Revision: 4385
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4385
Author: kiravakaan
Date: 2013-03-17 19:27:11 +0000 (Sun, 17 Mar 2013)
Log Message:
-----------
- A ground-up rewrite of the DirectX .x exporter for better design and extensibility.
- Optimized vertex, normal, and skin weight export where possible.
- Largely decoupled data gathering and data writing. This will make it much easier to provide binary file support in the future.
- Added animation option to export each action of each object as a separate AnimationSet and another option to export unused actions as if used by the first armature object.
- Added vertex color export support.
Added Paths:
-----------
trunk/py/scripts/addons/io_scene_x/
trunk/py/scripts/addons/io_scene_x/__init__.py
trunk/py/scripts/addons/io_scene_x/export_x.py
Removed Paths:
-------------
trunk/py/scripts/addons/io_export_directx_x.py
Deleted: trunk/py/scripts/addons/io_export_directx_x.py
===================================================================
--- trunk/py/scripts/addons/io_export_directx_x.py 2013-03-17 19:14:46 UTC (rev 4384)
+++ trunk/py/scripts/addons/io_export_directx_x.py 2013-03-17 19:27:11 UTC (rev 4385)
@@ -1,1299 +0,0 @@
-# ***** 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.
-# ***** GPL LICENSE BLOCK *****
-
-bl_info = {
- "name": "DirectX Model Format (.x)",
- "author": "Chris Foster (Kira Vakaan)",
- "version": (2, 1, 3),
- "blender": (2, 63, 0),
- "location": "File > Export > DirectX (.x)",
- "description": "Export DirectX Model Format (.x)",
- "warning": "",
- "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 os
-from math import radians
-
-import bpy
-from mathutils import *
-
-#Container for the exporter settings
-class DirectXExporterSettings:
- def __init__(self,
- context,
- FilePath,
- CoordinateSystem=1,
- RotateX=True,
- FlipNormals=False,
- ApplyModifiers=False,
- IncludeFrameRate=False,
- ExportTextures=True,
- ExportArmatures=False,
- ExportAnimation=0,
- ExportMode=1,
- Verbose=False):
- self.context = context
- self.FilePath = FilePath
- self.CoordinateSystem = int(CoordinateSystem)
- self.RotateX = RotateX
- self.FlipNormals = FlipNormals
- self.ApplyModifiers = ApplyModifiers
- self.IncludeFrameRate = IncludeFrameRate
- self.ExportTextures = ExportTextures
- self.ExportArmatures = ExportArmatures
- self.ExportAnimation = int(ExportAnimation)
- self.ExportMode = int(ExportMode)
- self.Verbose = Verbose
-
-
-def LegalName(Name):
-
- 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",
- "BINARY",
- "FLOAT",
- "ULONGLONG",
- "BINARY_RESOURCE",
- "SDWORD",
- "UNICODE",
- "CHAR",
- "STRING",
- "WORD",
- "CSTRING",
- "SWORD",
- "DOUBLE",
- "TEMPLATE"]:
- NewName = "_" + NewName
- return NewName
-
-
-def ExportDirectX(Config):
- print("----------\nExporting to {}".format(Config.FilePath))
- if Config.Verbose:
- print("Opening File...")
- Config.File = open(Config.FilePath, "w")
- if Config.Verbose:
- print("Done")
-
- if Config.Verbose:
- 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'}
- and Object.parent is None]
- else:
- ExportList = [Object for Object in Config.context.selected_objects
- if Object.type in {'ARMATURE', 'EMPTY', 'MESH'}]
- Config.ExportList = [Object for Object in ExportList
- if Object.parent not in ExportList]
- if Config.Verbose:
- print(" List: {}\nDone".format(Config.ExportList))
-
- if Config.Verbose:
- print("Setting up...")
- Config.SystemMatrix = Matrix()
- if Config.RotateX:
- Config.SystemMatrix *= Matrix.Rotation(radians(-90), 4, "X")
- if Config.CoordinateSystem == 1:
- Config.SystemMatrix *= Matrix.Scale(-1, 4, Vector((0, 1, 0)))
-
- if Config.ExportAnimation:
- CurrentFrame = bpy.context.scene.frame_current
- bpy.context.scene.frame_current = bpy.context.scene.frame_current
- if Config.Verbose:
- print("Done")
-
- if Config.Verbose:
- print("Writing Header...")
- WriteHeader(Config)
- if Config.Verbose:
- print("Done")
-
- Config.Whitespace = 0
- if Config.Verbose:
- print("Writing Root Frame...")
- WriteRootFrame(Config)
- if Config.Verbose:
- print("Done")
-
- Config.ObjectList = []
- if Config.Verbose:
- print("Writing Objects...")
- WriteObjects(Config, Config.ExportList)
- if Config.Verbose:
- print("Done")
-
- 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:
- if Config.Verbose:
- print("Writing Frame Rate...")
- Config.File.write("{}AnimTicksPerSecond {{\n".format(" " * Config.Whitespace))
- Config.Whitespace += 1
- Config.File.write("{}{};\n".format(" " * Config.Whitespace, int(bpy.context.scene.render.fps / bpy.context.scene.render.fps_base)))
- Config.Whitespace -= 1
- Config.File.write("{}}}\n".format(" " * Config.Whitespace))
- if Config.Verbose:
- print("Done")
- if Config.Verbose:
- print("Writing Animation...")
- if Config.ExportAnimation==1:
- WriteKeyedAnimationSet(Config)
- else:
- WriteFullAnimationSet(Config)
- bpy.context.scene.frame_current = CurrentFrame
- if Config.Verbose:
- print("Done")
-
- CloseFile(Config)
- print("Finished")
-
-
-def GetObjectChildren(Parent):
- return [Object for Object in Parent.children
- if Object.type in {'ARMATURE', 'EMPTY', 'MESH'}]
-
-#Returns the vertex count of Mesh, counting each vertex for every face.
-def GetMeshVertexCount(Mesh):
- VertexCount = 0
- for Polygon in Mesh.polygons:
- VertexCount += len(Polygon.vertices)
- return VertexCount
-
-#Returns the file path of first image texture from Material.
-def GetMaterialTextureFileName(Material):
- if Material:
- #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 = [bpy.path.basename(Texture.image.filepath) for Texture in ImageTextures if getattr(Texture.image, "source", "") == "FILE"]
- if ImageFiles:
- return ImageFiles[0]
- return None
-
-
-def WriteHeader(Config):
- Config.File.write("xof 0303txt 0032\n\n")
-
- if Config.IncludeFrameRate:
- Config.File.write("template AnimTicksPerSecond {\n\
- <9E415A43-7BA6-4a73-8743-B73D47E88476>\n\
- DWORD AnimTicksPerSecond;\n\
-}\n\n")
-
- if Config.ExportArmatures:
- Config.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")
-
-def WriteRootFrame(Config):
- Config.File.write("{}Frame Root {{\n".format(" " * Config.Whitespace))
- Config.Whitespace += 1
-
- Config.File.write("{}FrameTransformMatrix {{\n".format(" " * Config.Whitespace))
- Config.Whitespace += 1
- Config.File.write("{}{:9f},{:9f},{:9f},{:9f},\n".format(" " * Config.Whitespace, Config.SystemMatrix[0][0], Config.SystemMatrix[1][0], Config.SystemMatrix[2][0], Config.SystemMatrix[3][0]))
- Config.File.write("{}{:9f},{:9f},{:9f},{:9f},\n".format(" " * Config.Whitespace, Config.SystemMatrix[0][1], Config.SystemMatrix[1][1], Config.SystemMatrix[2][1], Config.SystemMatrix[3][1]))
- Config.File.write("{}{:9f},{:9f},{:9f},{:9f},\n".format(" " * Config.Whitespace, Config.SystemMatrix[0][2], Config.SystemMatrix[1][2], Config.SystemMatrix[2][2], Config.SystemMatrix[3][2]))
- Config.File.write("{}{:9f},{:9f},{:9f},{:9f};;\n".format(" " * Config.Whitespace, Config.SystemMatrix[0][3], Config.SystemMatrix[1][3], Config.SystemMatrix[2][3], Config.SystemMatrix[3][3]))
- Config.Whitespace -= 1
- Config.File.write("{}}}\n".format(" " * Config.Whitespace))
-
-def WriteObjects(Config, ObjectList):
- Config.ObjectList += ObjectList
-
- for Object in ObjectList:
- if Config.Verbose:
- print(" Writing Object: {}...".format(Object.name))
- Config.File.write("{}Frame {} {{\n".format(" " * Config.Whitespace, LegalName(Object.name)))
-
- Config.Whitespace += 1
- if Config.Verbose:
- print(" Writing Local Matrix...")
- WriteLocalMatrix(Config, Object)
- if Config.Verbose:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list