[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31698] trunk/blender/release/scripts: finished moving importers and exporters into python packages ( as proposed on the mailing list).
Campbell Barton
ideasman42 at gmail.com
Wed Sep 1 14:11:34 CEST 2010
Revision: 31698
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31698
Author: campbellbarton
Date: 2010-09-01 14:11:34 +0200 (Wed, 01 Sep 2010)
Log Message:
-----------
finished moving importers and exporters into python packages (as proposed on the mailing list).
- made operator dir's into python packages
- lazy loading of module which do the actual import and export (faster blender load times)
- general maintanance and small fixes.
- bugfix for exporting x3d materials
- leak fix for exporting 3ds
Modified Paths:
--------------
trunk/blender/release/scripts/io/netrender/__init__.py
trunk/blender/release/scripts/modules/io_utils.py
trunk/blender/release/scripts/op/io_anim_bvh/import_bvh.py
trunk/blender/release/scripts/op/io_mesh_ply/export_ply.py
trunk/blender/release/scripts/op/io_scene_3ds/export_3ds.py
trunk/blender/release/scripts/op/io_scene_3ds/import_3ds.py
trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py
trunk/blender/release/scripts/op/io_scene_obj/export_obj.py
trunk/blender/release/scripts/op/io_scene_obj/import_obj.py
trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py
trunk/blender/release/scripts/op/io_shape_mdd/export_mdd.py
trunk/blender/release/scripts/op/io_shape_mdd/import_mdd.py
Added Paths:
-----------
trunk/blender/release/scripts/op/io_anim_bvh/__init__.py
trunk/blender/release/scripts/op/io_mesh_ply/__init__.py
trunk/blender/release/scripts/op/io_scene_3ds/__init__.py
trunk/blender/release/scripts/op/io_scene_fbx/__init__.py
trunk/blender/release/scripts/op/io_scene_obj/__init__.py
trunk/blender/release/scripts/op/io_scene_x3d/__init__.py
trunk/blender/release/scripts/op/io_shape_mdd/__init__.py
Modified: trunk/blender/release/scripts/io/netrender/__init__.py
===================================================================
--- trunk/blender/release/scripts/io/netrender/__init__.py 2010-09-01 11:16:11 UTC (rev 31697)
+++ trunk/blender/release/scripts/io/netrender/__init__.py 2010-09-01 12:11:34 UTC (rev 31698)
@@ -19,9 +19,7 @@
# This directory is a Python package.
# To support reload properly, try to access a package var, if it's there, reload everything
-try:
- init_data
-
+if "bpy" in locals():
reload(model)
reload(operators)
reload(client)
@@ -32,7 +30,7 @@
reload(balancing)
reload(ui)
reload(repath)
-except:
+else:
from netrender import model
from netrender import operators
from netrender import client
@@ -49,7 +47,6 @@
blacklist = []
init_file = ""
-init_data = True
init_address = True
def register():
Modified: trunk/blender/release/scripts/modules/io_utils.py
===================================================================
--- trunk/blender/release/scripts/modules/io_utils.py 2010-09-01 11:16:11 UTC (rev 31697)
+++ trunk/blender/release/scripts/modules/io_utils.py 2010-09-01 12:11:34 UTC (rev 31698)
@@ -42,6 +42,23 @@
return {'RUNNING_MODAL'}
+# limited replacement for BPyImage.comprehensiveImageLoad
+def load_image(imagepath, dirname):
+
+ if os.path.exists(imagepath):
+ return bpy.data.images.load(imagepath)
+
+ variants = [imagepath, os.path.join(dirname, imagepath), os.path.join(dirname, os.path.basename(imagepath))]
+
+ for filepath in variants:
+ for nfilepath in (filepath, bpy.path.resolve_ncase(filepath)):
+ if os.path.exists(nfilepath):
+ return bpy.data.images.load(nfilepath)
+
+ # TODO comprehensiveImageLoad also searched in bpy.config.textureDir
+ return None
+
+
# return a tuple (free, object list), free is True if memory should be freed later with free_derived_objects()
def create_derived_objects(scene, ob):
if ob.parent and ob.parent.dupli_type != 'NONE':
@@ -54,42 +71,16 @@
return False, [(ob, ob.matrix_world)]
-
def free_derived_objects(ob):
ob.free_dupli_list()
-# So 3ds max can open files, limit names to 12 in length
-# this is verry annoying for filenames!
-name_unique = []
-name_mapping = {}
-def sane_name(name):
- name_fixed = name_mapping.get(name)
- if name_fixed != None:
- return name_fixed
-
- if len(name) > 12:
- new_name = name[:12]
- else:
- new_name = name
-
- i = 0
-
- while new_name in name_unique:
- new_name = new_name[:-4] + '.%.3d' % i
- i+=1
-
- name_unique.append(new_name)
- name_mapping[name] = new_name
- return new_name
-
-
def unpack_list(list_of_tuples):
flat_list = []
flat_list_extend = flat_list.extend # a tich faster
for t in list_of_tuples:
flat_list_extend(t)
- return l
+ return flat_list
# same as above except that it adds 0 for triangle faces
def unpack_face_list(list_of_tuples):
Added: trunk/blender/release/scripts/op/io_anim_bvh/__init__.py
===================================================================
--- trunk/blender/release/scripts/op/io_anim_bvh/__init__.py (rev 0)
+++ trunk/blender/release/scripts/op/io_anim_bvh/__init__.py 2010-09-01 12:11:34 UTC (rev 31698)
@@ -0,0 +1,74 @@
+# ##### 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>
+
+# To support reload properly, try to access a package var, if it's there, reload everything
+if "bpy" in locals():
+ # only reload if we alredy loaded, highly annoying
+ import sys
+ reload(sys.modules.get("io_mesh_ply.export_ply", sys))
+
+
+import bpy
+from bpy.props import *
+from io_utils import ImportHelper
+
+
+class BvhImporter(bpy.types.Operator, ImportHelper):
+ '''Load a OBJ Motion Capture File'''
+ bl_idname = "import_anim.bvh"
+ bl_label = "Import BVH"
+
+ filename_ext = ".bvh"
+
+ scale = FloatProperty(name="Scale", description="Scale the BVH by this value", min=0.0001, max=1000000.0, soft_min=0.001, soft_max=100.0, default=0.1)
+ frame_start = IntProperty(name="Start Frame", description="Starting frame for the animation", default=1)
+ loop = BoolProperty(name="Loop", description="Loop the animation playback", default=False)
+ rotate_mode = EnumProperty(items=(
+ ('QUATERNION', "Quaternion", "Convert rotations to quaternions"),
+ ('NATIVE', "Euler (Native)", "Use the rotation order defined in the BVH file"),
+ ('XYZ', "Euler (XYZ)", "Convert rotations to euler XYZ"),
+ ('XZY', "Euler (XZY)", "Convert rotations to euler XZY"),
+ ('YXZ', "Euler (YXZ)", "Convert rotations to euler YXZ"),
+ ('YZX', "Euler (YZX)", "Convert rotations to euler YZX"),
+ ('ZXY', "Euler (ZXY)", "Convert rotations to euler ZXY"),
+ ('ZYX', "Euler (ZYX)", "Convert rotations to euler ZYX"),
+ ),
+ name="Rotation",
+ description="Rotation conversion.",
+ default='NATIVE')
+
+ def execute(self, context):
+ import io_anim_bvh.import_bvh
+ return io_anim_bvh.import_bvh.load(self, context, **self.properties)
+
+
+def menu_func(self, context):
+ self.layout.operator(BvhImporter.bl_idname, text="Motion Capture (.bvh)")
+
+
+def register():
+ bpy.types.INFO_MT_file_import.append(menu_func)
+
+
+def unregister():
+ bpy.types.INFO_MT_file_import.remove(menu_func)
+
+if __name__ == "__main__":
+ register()
Modified: trunk/blender/release/scripts/op/io_anim_bvh/import_bvh.py
===================================================================
--- trunk/blender/release/scripts/op/io_anim_bvh/import_bvh.py 2010-09-01 11:16:11 UTC (rev 31697)
+++ trunk/blender/release/scripts/op/io_anim_bvh/import_bvh.py 2010-09-01 12:11:34 UTC (rev 31698)
@@ -555,67 +555,24 @@
return arm_ob
-from bpy.props import *
-from io_utils import ImportHelper
+def load(operator, context, filepath="", rotate_mode='NATIVE', scale=1.0, use_cyclic=False, frame_start=1):
+ import time
+ t1 = time.time()
+ print('\tparsing bvh %r...' % filepath, end="")
+ bvh_nodes = read_bvh(context, filepath,
+ ROT_MODE=rotate_mode,
+ GLOBAL_SCALE=scale)
-class BvhImporter(bpy.types.Operator, ImportHelper):
- '''Load a OBJ Motion Capture File'''
- bl_idname = "import_anim.bvh"
- bl_label = "Import BVH"
-
- filename_ext = ".bvh"
+ print('%.4f' % (time.time() - t1))
+ t1 = time.time()
+ print('\timporting to blender...', end="")
- scale = FloatProperty(name="Scale", description="Scale the BVH by this value", min=0.0001, max=1000000.0, soft_min=0.001, soft_max=100.0, default=0.1)
- frame_start = IntProperty(name="Start Frame", description="Starting frame for the animation", default=1)
- loop = BoolProperty(name="Loop", description="Loop the animation playback", default=False)
- rotate_mode = EnumProperty(items=(
- ('QUATERNION', "Quaternion", "Convert rotations to quaternions"),
- ('NATIVE', "Euler (Native)", "Use the rotation order defined in the BVH file"),
- ('XYZ', "Euler (XYZ)", "Convert rotations to euler XYZ"),
- ('XZY', "Euler (XZY)", "Convert rotations to euler XZY"),
- ('YXZ', "Euler (YXZ)", "Convert rotations to euler YXZ"),
- ('YZX', "Euler (YZX)", "Convert rotations to euler YZX"),
- ('ZXY', "Euler (ZXY)", "Convert rotations to euler ZXY"),
- ('ZYX', "Euler (ZYX)", "Convert rotations to euler ZYX"),
- ),
- name="Rotation",
- description="Rotation conversion.",
- default='NATIVE')
+ bvh_node_dict2armature(context, bvh_nodes,
+ ROT_MODE=rotate_mode,
+ IMPORT_START_FRAME=frame_start,
+ IMPORT_LOOP=use_cyclic)
- def execute(self, context):
- # print("Selected: " + context.active_object.name)
- import time
- t1 = time.time()
- print('\tparsing bvh...', end="")
-
- bvh_nodes = read_bvh(context, self.properties.filepath,
- ROT_MODE=self.properties.rotate_mode,
- GLOBAL_SCALE=self.properties.scale)
-
- print('%.4f' % (time.time() - t1))
- t1 = time.time()
- print('\timporting to blender...', end="")
-
- bvh_node_dict2armature(context, bvh_nodes,
- ROT_MODE=self.properties.rotate_mode,
- IMPORT_START_FRAME=self.properties.frame_start,
- IMPORT_LOOP=self.properties.loop)
-
- print('Done in %.4f\n' % (time.time() - t1))
- return {'FINISHED'}
-
-
-def menu_func(self, context):
- self.layout.operator(BvhImporter.bl_idname, text="Motion Capture (.bvh)")
-
-
-def register():
- bpy.types.INFO_MT_file_import.append(menu_func)
-
-
-def unregister():
- bpy.types.INFO_MT_file_import.remove(menu_func)
-
-if __name__ == "__main__":
- register()
+ print('Done in %.4f\n' % (time.time() - t1))
+
+ return {'FINISHED'}
Added: trunk/blender/release/scripts/op/io_mesh_ply/__init__.py
===================================================================
--- trunk/blender/release/scripts/op/io_mesh_ply/__init__.py (rev 0)
+++ trunk/blender/release/scripts/op/io_mesh_ply/__init__.py 2010-09-01 12:11:34 UTC (rev 31698)
@@ -0,0 +1,76 @@
+# ##### 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
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list