[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4382] contrib/py/scripts/addons/ io_scene_x: - Added vertex color support
Chris Foster
cdbfoster at gmail.com
Sun Mar 17 19:23:59 CET 2013
Revision: 4382
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4382
Author: kiravakaan
Date: 2013-03-17 18:23:59 +0000 (Sun, 17 Mar 2013)
Log Message:
-----------
- Added vertex color support
- Added verbose logging
- Better code documentation/pep8 compliance
This rewrite is done! Moving to trunk soon.
Modified Paths:
--------------
contrib/py/scripts/addons/io_scene_x/__init__.py
contrib/py/scripts/addons/io_scene_x/export_x.py
Modified: contrib/py/scripts/addons/io_scene_x/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_scene_x/__init__.py 2013-03-16 18:36:34 UTC (rev 4381)
+++ contrib/py/scripts/addons/io_scene_x/__init__.py 2013-03-17 18:23:59 UTC (rev 4382)
@@ -46,6 +46,8 @@
bl_label = "Export DirectX"
filepath = StringProperty(subtype='FILE_PATH')
+
+ # Export options
SelectedOnly = BoolProperty(
name="Export Selected Objects Only",
@@ -57,7 +59,6 @@
description="Apply object modifiers before export",
default=False)
- # XXX Change this stuff to property groups if possible
ExportMeshes = BoolProperty(
name="Export Meshes",
description="Export mesh objects",
@@ -78,10 +79,10 @@
description="Export material properties and reference image textures",
default=True)
- #ExportVertexColors = BoolProperty(
- # name=" Export Vertex Colors",
- # description="Export mesh vertex colors, if any",
- # default=False)
+ ExportVertexColors = BoolProperty(
+ name=" Export Vertex Colors",
+ description="Export mesh vertex colors, if any",
+ default=False)
ExportSkinWeights = BoolProperty(
name=" Export Skin Weights",
@@ -135,7 +136,7 @@
import export_x
Exporter = export_x.DirectXExporter(self, context)
- Exporter.Export() # XXX Rename this
+ Exporter.Export()
return {'FINISHED'}
def invoke(self, context, event):
Modified: contrib/py/scripts/addons/io_scene_x/export_x.py
===================================================================
--- contrib/py/scripts/addons/io_scene_x/export_x.py 2013-03-16 18:36:34 UTC (rev 4381)
+++ contrib/py/scripts/addons/io_scene_x/export_x.py 2013-03-17 18:23:59 UTC (rev 4382)
@@ -29,6 +29,8 @@
self.Config = Config
self.context = context
+ self.Log("Begin verbose logging ----------\n")
+
self.File = File(self.Config.filepath)
self.Log("Setting up coordinate system...")
@@ -44,44 +46,49 @@
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?
+ ExportMap = {}
for Object in ExportList:
if Object.type == 'EMPTY':
- self.ExportMap[Object] = EmptyExportObject(self.Config, self, Object)
+ ExportMap[Object] = EmptyExportObject(self.Config, self, Object)
elif Object.type == 'MESH':
- self.ExportMap[Object] = MeshExportObject(self.Config, self,
+ ExportMap[Object] = MeshExportObject(self.Config, self,
Object)
elif Object.type == 'ARMATURE':
- self.ExportMap[Object] = ArmatureExportObject(self.Config, 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()
+ self.RootExportList = [Object for Object in ExportMap.values()
if Object.BlenderObject.parent not in ExportList]
self.RootExportList = Util.SortByNameField(self.RootExportList)
- self.ExportList = Util.SortByNameField(self.ExportMap.values())
+ self.ExportList = Util.SortByNameField(ExportMap.values())
# Determine each object's children from the pool of ExportObjects
- for Object in self.ExportMap.values():
+ for Object in ExportMap.values():
Children = Object.BlenderObject.children
Object.Children = []
for Child in Children:
- if Child in self.ExportMap:
- Object.Children.append(self.ExportMap[Child])
+ if Child in ExportMap:
+ Object.Children.append(ExportMap[Child])
self.Log("Done")
self.AnimationWriter = None
if self.Config.ExportAnimation:
+ self.Log("Gathering animation data...")
+
+ # Collect all animated object data
AnimationGenerators = self.__GatherAnimationGenerators()
+ # Split the data up into animation sets based on user options
if self.Config.ExportActionsAsSets:
self.AnimationWriter = SplitSetAnimationWriter(self.Config,
self, AnimationGenerators)
else:
self.AnimationWriter = JoinedSetAnimationWriter(self.Config,
self, AnimationGenerators)
+ self.Log("Done")
# "Public" Interface
@@ -89,6 +96,7 @@
self.Log("Exporting to {}".format(self.File.FilePath),
MessageVerbose=False)
+ # Export everything
self.Log("Opening file...")
self.File.Open()
self.Log("Done")
@@ -104,16 +112,20 @@
self.Log("Writing objects...")
for Object in self.RootExportList:
Object.Write()
- self.Log("Done")
+ self.Log("Done writing objects")
self.Log("Closing Root frame...")
self.__CloseRootFrame()
self.Log("Done")
if self.AnimationWriter is not None:
+ self.Log("Writing animation set(s)...")
self.AnimationWriter.WriteAnimationSets()
+ self.Log("Done writing animation set(s)")
+ self.Log("Closing file...")
self.File.Close()
+ self.Log("Done")
def Log(self, String, MessageVerbose=True):
if self.Config.Verbose is True or MessageVerbose == False:
@@ -124,6 +136,8 @@
def __WriteHeader(self):
self.File.Write("xof 0303txt 0032\n\n")
+ # Write the headers that are required by some engines as needed
+
if self.Config.IncludeFrameRate:
self.File.Write("template AnimTicksPerSecond {\n\
<9E415A43-7BA6-4a73-8743-B73D47E88476>\n\
@@ -152,7 +166,11 @@
self.File.Write("FrameTransformMatrix {\n")
self.File.Indent()
+
+ # Write the matrix that will convert Blender's coordinate space into
+ # DirectX's.
Util.WriteMatrix(self.File, self.SystemMatrix)
+
self.File.Unindent()
self.File.Write("}\n")
@@ -163,7 +181,9 @@
def __GatherAnimationGenerators(self):
Generators = []
+ # If all animation data is to be lumped into one AnimationSet,
if not self.Config.ExportActionsAsSets:
+ # Build the appropriate generators for each object's type
for Object in self.ExportList:
if Object.BlenderObject.type == 'ARMATURE':
Generators.append(ArmatureAnimationGenerator(self.Config,
@@ -171,7 +191,10 @@
else:
Generators.append(GenericAnimationGenerator(self.Config,
None, Object))
+ # Otherwise,
else:
+ # Keep track of which objects have no action. These will be
+ # lumped together in a Default_Action AnimationSet.
ActionlessObjects = []
for Object in self.ExportList:
@@ -183,16 +206,22 @@
ActionlessObjects.append(Object)
continue
+ # If an object has an action, build its appropriate generator
if Object.BlenderObject.type == 'ARMATURE':
Generators.append(ArmatureAnimationGenerator(self.Config,
- Util.SafeName(Object.BlenderObject.animation_data.action.name),
+ Util.SafeName(
+ Object.BlenderObject.animation_data.action.name),
Object))
else:
Generators.append(GenericAnimationGenerator(self.Config,
- Util.SafeName(Object.BlenderObject.animation_data.action.name),
+ Util.SafeName(
+ Object.BlenderObject.animation_data.action.name),
Object))
+ # If we should export unused actions as if the first armature was
+ # using them,
if self.Config.AttachToFirstArmature:
+ # Find the first armature
FirstArmature = None
for Object in self.ExportList:
if Object.BlenderObject.type == 'ARMATURE':
@@ -200,41 +229,54 @@
break
if FirstArmature is not None:
+ # Determine which actions are not used
UsedActions = [BlenderObject.animation_data.action
for BlenderObject in bpy.data.objects
if BlenderObject.animation_data is not None]
FreeActions = [Action for Action in bpy.data.actions
if Action not in UsedActions]
+ # If the first armature has no action, remove it from the
+ # actionless objects so it doesn't end up in Default_Action
if FirstArmature in ActionlessObjects and len(FreeActions):
ActionlessObjects.remove(FirstArmature)
+ # Keep track of the first armature's animation data so we
+ # can restore it after export
OldAction = None
NoData = False
if FirstArmature.BlenderObject.animation_data is not None:
- OldAction = FirstArmature.BlenderObject.animation_data.action
+ OldAction = \
+ FirstArmature.BlenderObject.animation_data.action
else:
NoData = True
FirstArmature.BlenderObject.animation_data_create()
+ # Build a generator for each unused action
for Action in FreeActions:
- FirstArmature.BlenderObject.animation_data.action = Action
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list