[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4653] trunk/py/scripts/addons/ io_scene_fbx: initial FBX importer, work in progress but can load...
Campbell Barton
ideasman42 at gmail.com
Thu Aug 8 11:59:12 CEST 2013
Revision: 4653
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4653
Author: campbellbarton
Date: 2013-08-08 09:59:12 +0000 (Thu, 08 Aug 2013)
Log Message:
-----------
initial FBX importer, work in progress but can load...
- binary fbx files only
- version 7.1 or newer
- meshes, uvs, materials, textures
- support for blender-internal and cycles materials (depends on engine selected)
note - yes, this cant load fbx files exported by blender, for that to work we would need to update the exporter.
Modified Paths:
--------------
trunk/py/scripts/addons/io_scene_fbx/__init__.py
trunk/py/scripts/addons/io_scene_fbx/export_fbx.py
Added Paths:
-----------
trunk/py/scripts/addons/io_scene_fbx/import_fbx.py
trunk/py/scripts/addons/io_scene_fbx/parse_fbx.py
Modified: trunk/py/scripts/addons/io_scene_fbx/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/__init__.py 2013-08-08 06:59:06 UTC (rev 4652)
+++ trunk/py/scripts/addons/io_scene_fbx/__init__.py 2013-08-08 09:59:12 UTC (rev 4653)
@@ -35,6 +35,8 @@
if "bpy" in locals():
import imp
+ if "import_fbx" in locals():
+ imp.reload(import_fbx)
if "export_fbx" in locals():
imp.reload(export_fbx)
@@ -46,12 +48,79 @@
EnumProperty,
)
-from bpy_extras.io_utils import (ExportHelper,
+from bpy_extras.io_utils import (ImportHelper,
+ ExportHelper,
path_reference_mode,
axis_conversion,
)
+class ImportFBX(bpy.types.Operator, ImportHelper):
+ """Load a FBX geometry file"""
+ bl_idname = "import_scene.fbx"
+ bl_label = "Import FBX"
+ bl_options = {'UNDO'}
+ directory = StringProperty()
+
+ filename_ext = ".fbx"
+ filter_glob = StringProperty(default="*.fbx", options={'HIDDEN'})
+
+ use_image_search = BoolProperty(
+ name="Image Search",
+ description="Search subdirs for any associated images "
+ "(Warning, may be slow)",
+ default=True,
+ )
+
+ axis_forward = EnumProperty(
+ name="Forward",
+ items=(('X', "X Forward", ""),
+ ('Y', "Y Forward", ""),
+ ('Z', "Z Forward", ""),
+ ('-X', "-X Forward", ""),
+ ('-Y', "-Y Forward", ""),
+ ('-Z', "-Z Forward", ""),
+ ),
+ default='-Z',
+ )
+ axis_up = EnumProperty(
+ name="Up",
+ items=(('X', "X Up", ""),
+ ('Y', "Y Up", ""),
+ ('Z', "Z Up", ""),
+ ('-X', "-X Up", ""),
+ ('-Y', "-Y Up", ""),
+ ('-Z', "-Z Up", ""),
+ ),
+ default='Y',
+ )
+ global_scale = FloatProperty(
+ name="Scale",
+ min=0.001, max=1000.0,
+ default=1.0,
+ )
+
+ def execute(self, context):
+ from mathutils import Matrix
+
+ keywords = self.as_keywords(ignore=("axis_forward",
+ "axis_up",
+ "global_scale",
+ "filter_glob",
+ "directory",
+ ))
+
+ global_matrix = (Matrix.Scale(self.global_scale, 4) *
+ axis_conversion(from_forward=self.axis_forward,
+ from_up=self.axis_up,
+ ).to_4x4())
+ keywords["global_matrix"] = global_matrix
+ keywords["use_cycles"] = (context.scene.render.engine == 'CYCLES')
+
+ from . import import_fbx
+ return import_fbx.load(self, context, **keywords)
+
+
class ExportFBX(bpy.types.Operator, ExportHelper):
"""Selection to an ASCII Autodesk FBX"""
bl_idname = "export_scene.fbx"
@@ -74,7 +143,7 @@
description=("Scale all data "
"(Some importers do not support scaled armatures!)"),
min=0.01, max=1000.0,
- soft_min=0.01, soft_max=1000.0,
+ soft_min=0.001, soft_max=1000.0,
default=1.0,
)
axis_forward = EnumProperty(
@@ -174,11 +243,6 @@
description="Disable global rotation, for XNA compatibility",
default=False,
)
- xna_validate = BoolProperty(
- name="XNA Strict Options",
- description="Make sure options are compatible with Microsoft XNA",
- default=False,
- )
batch_mode = EnumProperty(
name="Batch Mode",
items=(('OFF', "Off", "Active scene to file"),
@@ -197,69 +261,26 @@
options={'HIDDEN'},
)
- # Validate that the options are compatible with XNA (JCB)
- def _validate_xna_options(self):
- if not self.xna_validate:
- return False
- changed = False
- if not self.use_rotate_workaround:
- changed = True
- self.use_rotate_workaround = True
- if self.global_scale != 1.0:
- changed = True
- self.global_scale = 1.0
- if self.mesh_smooth_type != 'OFF':
- changed = True
- self.mesh_smooth_type = 'OFF'
- if self.use_anim_optimize:
- changed = True
- self.use_anim_optimize = False
- if self.use_mesh_edges:
- changed = True
- self.use_mesh_edges = False
- if self.use_default_take:
- changed = True
- self.use_default_take = False
- if self.object_types & {'CAMERA', 'LAMP', 'EMPTY'}:
- changed = True
- self.object_types -= {'CAMERA', 'LAMP', 'EMPTY'}
- if self.path_mode != 'STRIP':
- changed = True
- self.path_mode = 'STRIP'
- return changed
-
@property
def check_extension(self):
return self.batch_mode == 'OFF'
- def check(self, context):
- is_def_change = super().check(context)
- is_xna_change = self._validate_xna_options()
- return (is_xna_change or is_def_change)
-
def execute(self, context):
from mathutils import Matrix
if not self.filepath:
raise Exception("filepath not set")
- global_matrix = Matrix()
- global_matrix[0][0] = \
- global_matrix[1][1] = \
- global_matrix[2][2] = self.global_scale
+ global_matrix = (Matrix.Scale(self.global_scale, 4) *
+ axis_conversion(to_forward=self.axis_forward,
+ to_up=self.axis_up,
+ ).to_4x4())
- if not self.use_rotate_workaround:
- global_matrix = (global_matrix *
- axis_conversion(to_forward=self.axis_forward,
- to_up=self.axis_up,
- ).to_4x4())
-
keywords = self.as_keywords(ignore=("axis_forward",
"axis_up",
"global_scale",
"check_existing",
"filter_glob",
- "xna_validate",
))
keywords["global_matrix"] = global_matrix
@@ -268,20 +289,26 @@
return export_fbx.save(self, context, **keywords)
-def menu_func(self, context):
+def menu_func_import(self, context):
+ self.layout.operator(ImportFBX.bl_idname, text="Autodesk FBX (.fbx)")
+
+
+def menu_func_export(self, context):
self.layout.operator(ExportFBX.bl_idname, text="Autodesk FBX (.fbx)")
def register():
bpy.utils.register_module(__name__)
- bpy.types.INFO_MT_file_export.append(menu_func)
+ bpy.types.INFO_MT_file_import.append(menu_func_import)
+ bpy.types.INFO_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_module(__name__)
- bpy.types.INFO_MT_file_export.remove(menu_func)
+ bpy.types.INFO_MT_file_import.remove(menu_func_import)
+ bpy.types.INFO_MT_file_export.remove(menu_func_export)
if __name__ == "__main__":
register()
Modified: trunk/py/scripts/addons/io_scene_fbx/export_fbx.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/export_fbx.py 2013-08-08 06:59:06 UTC (rev 4652)
+++ trunk/py/scripts/addons/io_scene_fbx/export_fbx.py 2013-08-08 09:59:12 UTC (rev 4653)
@@ -3050,19 +3050,6 @@
# Please update the lists for UDK, Unity, XNA etc. on the following web page:
# http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Import-Export/UnifiedFBX
-# XNA FBX Requirements (JCB 29 July 2011)
-# - Armature must be parented to the scene
-# - Armature must be a 'Limb' never a 'null'. This is in several places.
-# - First bone must be parented to the armature.
-# - Rotation must be completely disabled including
-# always returning the original matrix in In object_tx().
-# It is the animation that gets distorted during rotation!
-# - Lone edges cause intermittent errors in the XNA content pipeline!
-# I have added a warning message and excluded them.
-# - Bind pose must be included with the 'MESH'
-# Typical settings for XNA export
-# No Cameras, No Lamps, No Edges, No face smoothing, No Default_Take, Armature as bone, Disable rotation
-
# NOTE TO Campbell -
# Can any or all of the following notes be removed because some have been here for a long time? (JCB 27 July 2011)
# NOTES (all line numbers correspond to original export_fbx.py (under release/scripts)
Added: trunk/py/scripts/addons/io_scene_fbx/import_fbx.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/import_fbx.py (rev 0)
+++ trunk/py/scripts/addons/io_scene_fbx/import_fbx.py 2013-08-08 09:59:12 UTC (rev 4653)
@@ -0,0 +1,566 @@
+# ##### 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 2
+# 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, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+# Script copyright (C) Blender Foundation
+
+# FBX 7.1.0 -> 7.3.0 loader for Blender
+
+import bpy
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list