[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1398] trunk/py/scripts/addons: scripts from bf-blender which are now maintained in bf-extensions.
Campbell Barton
ideasman42 at gmail.com
Fri Jan 14 18:33:40 CET 2011
Revision: 1398
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1398
Author: campbellbarton
Date: 2011-01-14 17:33:39 +0000 (Fri, 14 Jan 2011)
Log Message:
-----------
scripts from bf-blender which are now maintained in bf-extensions.
Added Paths:
-----------
trunk/py/scripts/addons/io_anim_bvh/
trunk/py/scripts/addons/io_anim_bvh/__init__.py
trunk/py/scripts/addons/io_anim_bvh/export_bvh.py
trunk/py/scripts/addons/io_anim_bvh/import_bvh.py
trunk/py/scripts/addons/io_mesh_ply/
trunk/py/scripts/addons/io_mesh_ply/__init__.py
trunk/py/scripts/addons/io_mesh_ply/export_ply.py
trunk/py/scripts/addons/io_mesh_ply/import_ply.py
trunk/py/scripts/addons/io_scene_3ds/
trunk/py/scripts/addons/io_scene_3ds/__init__.py
trunk/py/scripts/addons/io_scene_3ds/export_3ds.py
trunk/py/scripts/addons/io_scene_3ds/import_3ds.py
trunk/py/scripts/addons/io_scene_fbx/
trunk/py/scripts/addons/io_scene_fbx/__init__.py
trunk/py/scripts/addons/io_scene_fbx/export_fbx.py
trunk/py/scripts/addons/io_scene_obj/
trunk/py/scripts/addons/io_scene_obj/__init__.py
trunk/py/scripts/addons/io_scene_obj/export_obj.py
trunk/py/scripts/addons/io_scene_obj/import_obj.py
trunk/py/scripts/addons/io_scene_x3d/
trunk/py/scripts/addons/io_scene_x3d/__init__.py
trunk/py/scripts/addons/io_scene_x3d/export_x3d.py
trunk/py/scripts/addons/io_scene_x3d/import_x3d.py
Added: trunk/py/scripts/addons/io_anim_bvh/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_anim_bvh/__init__.py (rev 0)
+++ trunk/py/scripts/addons/io_anim_bvh/__init__.py 2011-01-14 17:33:39 UTC (rev 1398)
@@ -0,0 +1,133 @@
+# ##### 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>
+
+bl_info = {
+ "name": "BioVision Motion Capture (BVH) format",
+ "author": "Campbell Barton",
+ "location": "File > Import-Export",
+ "description": "Import-Export BVH from armature objects",
+ "warning": "",
+ "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
+ "Scripts/Import-Export/MotionCapture_BVH",
+ "tracker_url": "",
+ "support": 'OFFICIAL',
+ "category": "Import-Export"}
+
+# To support reload properly, try to access a package var, if it's there, reload everything
+if "bpy" in locals():
+ import imp
+ if "import_bvh" in locals():
+ imp.reload(import_bvh)
+
+
+import bpy
+from bpy.props import *
+from io_utils import ImportHelper, ExportHelper
+
+
+class ImportBVH(bpy.types.Operator, ImportHelper):
+ '''Load a BVH motion capture file'''
+ bl_idname = "import_anim.bvh"
+ bl_label = "Import BVH"
+
+ filename_ext = ".bvh"
+ filter_glob = StringProperty(default="*.bvh", options={'HIDDEN'})
+
+ target = EnumProperty(items=(
+ ('ARMATURE', "Armature", ""),
+ ('OBJECT', "Object", ""),
+ ),
+ name="Target",
+ description="Import target type.",
+ default='ARMATURE')
+
+ global_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=1.0)
+ frame_start = IntProperty(name="Start Frame", description="Starting frame for the animation", default=1)
+ use_cyclic = 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):
+ from . import import_bvh
+ return import_bvh.load(self, context, **self.as_keywords(ignore=("filter_glob",)))
+
+
+class ExportBVH(bpy.types.Operator, ExportHelper):
+ '''Save a BVH motion capture file from an armature'''
+ bl_idname = "export_anim.bvh"
+ bl_label = "Export BVH"
+
+ filename_ext = ".bvh"
+ filter_glob = StringProperty(default="*.bvh", options={'HIDDEN'})
+
+ global_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=1.0)
+ frame_start = IntProperty(name="Start Frame", description="Starting frame to export", default=0)
+ frame_end = IntProperty(name="End Frame", description="End frame to export", default=0)
+
+ @classmethod
+ def poll(cls, context):
+ obj = context.object
+ return obj and obj.type == 'ARMATURE'
+
+ def invoke(self, context, event):
+ self.frame_start = context.scene.frame_start
+ self.frame_end = context.scene.frame_end
+
+ return super().invoke(context, event)
+
+ def execute(self, context):
+ if self.frame_start == 0 and self.frame_end == 0:
+ self.frame_start = context.scene.frame_start
+ self.frame_end = context.scene.frame_end
+
+ from . import export_bvh
+ return export_bvh.save(self, context, **self.as_keywords(ignore=("check_existing", "filter_glob")))
+
+
+def menu_func_import(self, context):
+ self.layout.operator(ImportBVH.bl_idname, text="Motion Capture (.bvh)")
+
+
+def menu_func_export(self, context):
+ self.layout.operator(ExportBVH.bl_idname, text="Motion Capture (.bvh)")
+
+
+def register():
+ bpy.types.INFO_MT_file_import.append(menu_func_import)
+ bpy.types.INFO_MT_file_export.append(menu_func_export)
+
+
+def unregister():
+ bpy.types.INFO_MT_file_import.remove(menu_func_import)
+ bpy.types.INFO_MT_file_export.remove(menu_func_export)
+
+if __name__ == "__main__":
+ register()
Added: trunk/py/scripts/addons/io_anim_bvh/export_bvh.py
===================================================================
--- trunk/py/scripts/addons/io_anim_bvh/export_bvh.py (rev 0)
+++ trunk/py/scripts/addons/io_anim_bvh/export_bvh.py 2011-01-14 17:33:39 UTC (rev 1398)
@@ -0,0 +1,245 @@
+# ##### 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) Campbell Barton
+# fixes from Andrea Rugliancich
+
+import bpy
+
+
+def write_armature(context, filepath, frame_start, frame_end, global_scale=1.0):
+
+ from mathutils import Matrix, Vector, Euler
+ from math import degrees
+
+ file = open(filepath, "w")
+
+ obj = context.object
+ arm = obj.data
+
+ # Build a dictionary of children.
+ # None for parentless
+ children = {None: []}
+
+ # initialize with blank lists
+ for bone in arm.bones:
+ children[bone.name] = []
+
+ for bone in arm.bones:
+ children[getattr(bone.parent, "name", None)].append(bone.name)
+
+ # sort the children
+ for children_list in children.values():
+ children_list.sort()
+
+ # bone name list in the order that the bones are written
+ serialized_names = []
+
+ node_locations = {}
+
+ file.write("HIERARCHY\n")
+
+ def write_recursive_nodes(bone_name, indent):
+ my_children = children[bone_name]
+
+ indent_str = "\t" * indent
+
+ bone = arm.bones[bone_name]
+ loc = bone.head_local
+ node_locations[bone_name] = loc
+
+ # make relative if we can
+ if bone.parent:
+ loc = loc - node_locations[bone.parent.name]
+
+ if indent:
+ file.write("%sJOINT %s\n" % (indent_str, bone_name))
+ else:
+ file.write("%sROOT %s\n" % (indent_str, bone_name))
+
+ file.write("%s{\n" % indent_str)
+ file.write("%s\tOFFSET %.6f %.6f %.6f\n" % (indent_str, loc.x * global_scale, loc.y * global_scale, loc.z * global_scale))
+ if bone.use_connect and bone.parent:
+ file.write("%s\tCHANNELS 3 Xrotation Yrotation Zrotation\n" % indent_str)
+ else:
+ file.write("%s\tCHANNELS 6 Xposition Yposition Zposition Xrotation Yrotation Zrotation\n" % indent_str)
+
+ if my_children:
+ # store the location for the children
+ # to het their relative offset
+
+ # Write children
+ for child_bone in my_children:
+ serialized_names.append(child_bone)
+ write_recursive_nodes(child_bone, indent + 1)
+
+ else:
+ # Write the bone end.
+ file.write("%s\tEnd Site\n" % indent_str)
+ file.write("%s\t{\n" % indent_str)
+ loc = bone.tail_local - node_locations[bone_name]
+ file.write("%s\t\tOFFSET %.6f %.6f %.6f\n" % (indent_str, loc.x * global_scale, loc.y * global_scale, loc.z * global_scale))
+ file.write("%s\t}\n" % indent_str)
+
+ file.write("%s}\n" % indent_str)
+
+ if len(children[None]) == 1:
+ key = children[None][0]
+ serialized_names.append(key)
+ indent = 0
+
+ write_recursive_nodes(key, indent)
+
+ else:
+ # Write a dummy parent node
+ file.write("ROOT %s\n" % key)
+ file.write("{\n")
+ file.write("\tOFFSET 0.0 0.0 0.0\n")
+ file.write("\tCHANNELS 0\n") # Xposition Yposition Zposition Xrotation Yrotation Zrotation
+ key = None
+ indent = 1
+
+ write_recursive_nodes(key, indent)
+
+ file.write("}\n")
+
+ # redefine bones as sorted by serialized_names
+ # so we can write motion
+
+ class decorated_bone(object):
+ __slots__ = (\
+ "name", # bone name, used as key in many places
+ "parent", # decorated bone parent, set in a later loop
+ "rest_bone", # blender armature bone
+ "pose_bone", # blender pose bone
+ "pose_mat", # blender pose matrix
+ "rest_arm_mat", # blender rest matrix (armature space)
+ "rest_local_mat", # blender rest batrix (local space)
+ "pose_imat", # pose_mat inverted
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list