[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2247] trunk/py/scripts/addons/ io_anim_bvh: bvh export
Campbell Barton
ideasman42 at gmail.com
Mon Aug 15 13:56:36 CEST 2011
Revision: 2247
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2247
Author: campbellbarton
Date: 2011-08-15 11:56:36 +0000 (Mon, 15 Aug 2011)
Log Message:
-----------
bvh export
- add option to export root transform only (may help with secondlife compatibility)
- operators are now pep8 compliant.
- frame is set back to the original when export is done.
Modified Paths:
--------------
trunk/py/scripts/addons/io_anim_bvh/__init__.py
trunk/py/scripts/addons/io_anim_bvh/export_bvh.py
Modified: trunk/py/scripts/addons/io_anim_bvh/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_anim_bvh/__init__.py 2011-08-15 04:59:35 UTC (rev 2246)
+++ trunk/py/scripts/addons/io_anim_bvh/__init__.py 2011-08-15 11:56:36 UTC (rev 2247)
@@ -16,7 +16,7 @@
#
# ##### END GPL LICENSE BLOCK #####
-# <pep8 compliant>
+# <pep8-80 compliant>
bl_info = {
"name": "BioVision Motion Capture (BVH) format",
@@ -26,13 +26,12 @@
"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",
+ "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():
@@ -41,7 +40,12 @@
imp.reload(export_bvh)
import bpy
-from bpy.props import StringProperty, FloatProperty, IntProperty, BoolProperty, EnumProperty
+from bpy.props import (StringProperty,
+ FloatProperty,
+ IntProperty,
+ BoolProperty,
+ EnumProperty,
+ )
from bpy_extras.io_utils import ImportHelper, ExportHelper
@@ -62,26 +66,45 @@
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')
+ 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(
+ name="Rotation",
+ description="Rotation conversion.",
+ 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"),
+ ),
+ default='NATIVE',
+ )
def execute(self, context):
+ keywords = self.as_keywords(ignore=("filter_glob",))
+
from . import import_bvh
- return import_bvh.load(self, context, **self.as_keywords(ignore=("filter_glob",)))
+ return import_bvh.load(self, context, **keywords)
class ExportBVH(bpy.types.Operator, ExportHelper):
@@ -90,25 +113,48 @@
bl_label = "Export BVH"
filename_ext = ".bvh"
- filter_glob = StringProperty(default="*.bvh", options={'HIDDEN'})
+ 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)
+ 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,
+ )
+ rotate_mode = EnumProperty(
+ name="Rotation",
+ description="Rotation conversion.",
+ items=(('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"),
+ ),
+ default='NATIVE',
+ )
+ root_transform_only = BoolProperty(
+ name="Root Transform Only",
+ description="Only write out transform channels for the root bone",
+ default=False,
+ )
- rotate_mode = EnumProperty(items=(
- ('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')
-
@classmethod
def poll(cls, context):
obj = context.object
@@ -125,8 +171,10 @@
self.frame_start = context.scene.frame_start
self.frame_end = context.scene.frame_end
+ keywords = self.as_keywords(ignore=("check_existing", "filter_glob"))
+
from . import export_bvh
- return export_bvh.save(self, context, **self.as_keywords(ignore=("check_existing", "filter_glob")))
+ return export_bvh.save(self, context, **keywords)
def menu_func_import(self, context):
Modified: trunk/py/scripts/addons/io_anim_bvh/export_bvh.py
===================================================================
--- trunk/py/scripts/addons/io_anim_bvh/export_bvh.py 2011-08-15 04:59:35 UTC (rev 2246)
+++ trunk/py/scripts/addons/io_anim_bvh/export_bvh.py 2011-08-15 11:56:36 UTC (rev 2247)
@@ -30,6 +30,7 @@
frame_end,
global_scale=1.0,
rotate_mode='NATIVE',
+ root_transform_only=False,
):
def ensure_rot_order(rot_order_str):
@@ -93,7 +94,7 @@
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:
+ if (bone.use_connect or root_transform_only) and bone.parent:
file.write("%s\tCHANNELS 3 %srotation %srotation %srotation\n" % (indent_str, rot_order_str[0], rot_order_str[1], rot_order_str[2]))
else:
file.write("%s\tCHANNELS 6 Xposition Yposition Zposition %srotation %srotation %srotation\n" % (indent_str, rot_order_str[0], rot_order_str[1], rot_order_str[2]))
@@ -153,7 +154,7 @@
"rest_arm_imat", # rest_arm_mat inverted
"rest_local_imat", # rest_local_mat inverted
"prev_euler", # last used euler to preserve euler compability in between keyframes
- "connected", # is the bone connected to the parent bone?
+ "skip_position", # is the bone disconnected to the parent bone?
"rot_order",
"rot_order_str",
)
@@ -164,7 +165,8 @@
'YXZ': (1, 0, 2),
'YZX': (1, 2, 0),
'ZXY': (2, 0, 1),
- 'ZYX': (2, 1, 0)}
+ 'ZYX': (2, 1, 0),
+ }
def __init__(self, bone_name):
self.name = bone_name
@@ -191,7 +193,7 @@
self.parent = None
self.prev_euler = Euler((0.0, 0.0, 0.0), self.rot_order_str)
- self.connected = (self.rest_bone.use_connect and self.rest_bone.parent)
+ self.skip_position = ((self.rest_bone.use_connect or root_transform_only) and self.rest_bone.parent)
def update_posedata(self):
self.pose_mat = self.pose_bone.matrix
@@ -218,6 +220,7 @@
# finish assigning parents
scene = bpy.context.scene
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list