diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-03 06:09:59 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-03 06:09:59 +0400 |
commit | 83068cf62a6d98280b7ab79405c84556f331e118 (patch) | |
tree | 0d1ed31ea7fc1b6ae8c543a3bea9806a8f4c4e40 | |
parent | f3d111886556aa4a1dde37152e3aeea86dff244e (diff) |
minor cleanup for c3d and acclaim addons.
- no need to use self.properties
- close the file (py3.3 reports resource leak)
- dont use camel case for property names
- use property definition formatting like other scripts in trunk.
-rw-r--r-- | io_anim_acclaim/__init__.py | 113 | ||||
-rw-r--r-- | io_anim_c3d/__init__.py | 119 |
2 files changed, 147 insertions, 85 deletions
diff --git a/io_anim_acclaim/__init__.py b/io_anim_acclaim/__init__.py index f345511a..640d9b5d 100644 --- a/io_anim_acclaim/__init__.py +++ b/io_anim_acclaim/__init__.py @@ -30,9 +30,9 @@ bl_info = { 'api': 41226, 'location': "File > Import", 'description': "Imports Acclaim Skeleton and Motion Capture Files", - 'wiki_url': "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\ + 'wiki_url': "http://wiki.blender.org/index.php/Extensions:2.5/Py/" "Scripts/Import-Export/Acclaim_Importer", - 'tracker_url': "http://projects.blender.org/tracker/index.php?"\ + 'tracker_url': "http://projects.blender.org/tracker/index.php?" "func=detail&aid=27127&group_id=153&atid=467", 'category': 'Import-Export'} @@ -40,8 +40,12 @@ bl_info = { import re import bpy from mathutils import Vector, Matrix -from math import radians as rad, degrees -from bpy.props import StringProperty, BoolProperty, FloatProperty, IntProperty +from math import radians, degrees +from bpy.props import (StringProperty, + BoolProperty, + FloatProperty, + IntProperty, + ) class DataStructure: @@ -87,7 +91,8 @@ class DataStructure: if k == 'axis': rot = Matrix() for ang, basis in zip(s[:3], s[3].upper()): - rot = Matrix.Rotation(rad(float(ang)), 4, basis) * rot + rot = Matrix.Rotation(radians(float(ang)), + 4, basis) * rot bd['axis'] = rot elif k == 'direction': bd[k] = Vector([float(n) for n in s]) @@ -137,10 +142,11 @@ class DataStructure: vs = vs[3:] rot = Matrix() for dof, ang in zip(self.bones[b[0]]['dof'], vs): - rot = Matrix.Rotation(rad(ang), 4, dof) * rot + rot = Matrix.Rotation(radians(ang), 4, dof) * rot self.pose_def[b[0]] = rot pose = self.calculate_pose(Matrix.Translation(loc)) yield(frame / skip + 1, pose) + amc.close() def calculate_pose(self, parent, bone='root'): """ @@ -249,7 +255,7 @@ class StructureBuilder(DataStructure): constr.use_limit_y = True constr.use_limit_z = True if dof: - limits = (rad(float(v)) for v in bone_def['limits']) + limits = (radians(float(v)) for v in bone_def['limits']) if 'X' in dof: constr.min_x = next(limits) constr.max_x = next(limits) @@ -261,7 +267,7 @@ class StructureBuilder(DataStructure): constr.max_y = next(limits) bpy.ops.object.mode_set(mode='EDIT') - def load_motion_capture(self, filename, frame_skip=5, useFrameNo=False): + def load_motion_capture(self, filename, frame_skip=5, use_frame_no=False): """ Create the keyframes for a motion capture file """ @@ -272,10 +278,12 @@ class StructureBuilder(DataStructure): bpy.ops.pose.loc_clear() self.rest = {} for b in self.object.pose.bones: - self.rest[b.name] = (b, b.matrix.to_3x3(), - b.matrix.to_3x3().inverted()) + self.rest[b.name] = (b, + b.matrix.to_3x3(), + b.matrix.to_3x3().inverted(), + ) self.fno = 0 - self.useFrameNo = useFrameNo + self.use_frame_no = use_frame_no self.motion = iter(self.scan_motion_capture(filename, frame_skip)) def apply_next_frame(self): @@ -283,7 +291,7 @@ class StructureBuilder(DataStructure): frame, bones = next(self.motion) except StopIteration: return False - regframe = frame if self.useFrameNo else self.fno + regframe = frame if self.use_frame_no else self.fno self.fno += 1 for name, w, l in bones: b, P, Pi = self.rest[name] @@ -303,37 +311,56 @@ class AsfImporter(bpy.types.Operator): bl_idname = "import_anim.asf" bl_label = "Import ASF" - filepath = StringProperty(name="File Path", maxlen=1024, default="", - description="Path to the ASF file") - armature_name = StringProperty(name="Armature Name", maxlen=32, - default="Skeleton", - description="Name of the new object") - use_limits = BoolProperty(name="Use Limits", default=False, - description="Create bone constraints for limits") - scale = FloatProperty(name="Scale", default=1., - description="Scale the armature by this value", - min=0.0001, max=1000000.0, - soft_min=0.001, soft_max=100.0) - from_inches = BoolProperty(name="Convert from inches to metric", - default=False, description="Scale by 2.54/100") - rotX = BoolProperty(name="Rotate X 90 degrees", default=False, - description="Correct orientation") - rotZ = BoolProperty(name="Rotate Z 90 degrees", default=False, - description="Correct orientation") + filepath = StringProperty( + name="File Path", + maxlen=1024, default="", + description="Path to the ASF file", + ) + armature_name = StringProperty( + name="Armature Name", maxlen=32, + default="Skeleton", + description="Name of the new object", + ) + use_limits = BoolProperty( + name="Use Limits", default=False, + description="Create bone constraints for limits", + ) + scale = FloatProperty( + name="Scale", + default=1.0, + description="Scale the armature by this value", + min=0.0001, max=1000000.0, + soft_min=0.001, soft_max=100.0, + ) + from_inches = BoolProperty( + name="Convert from inches to metric", + default=False, description="Scale by 2.54/100", + ) + use_rot_x = BoolProperty( + name="Rotate X 90 degrees", + default=False, + description="Correct orientation", + ) + use_rot_z = BoolProperty( + name="Rotate Z 90 degrees", + default=False, + description="Correct orientation", + ) + filter_glob = StringProperty(default="*.asf", options={'HIDDEN'}) def execute(self, context): - uscale = (0.0254 if self.properties.from_inches else 1.) - sb = StructureBuilder( - self.properties.filepath, - self.properties.armature_name, - self.properties.scale * uscale) + uscale = (0.0254 if self.from_inches else 1.0) + sb = StructureBuilder(self.filepath, + self.armature_name, + self.scale * uscale, + ) sb.create_armature() - sb.build_structure(self.properties.use_limits) - if self.properties.rotX: - bpy.ops.transform.rotate(value=(rad(90.),), axis=(1, 0, 0)) - if self.properties.rotZ: - bpy.ops.transform.rotate(value=(rad(90.),), axis=(0, 0, 1)) + sb.build_structure(self.use_limits) + if self.use_rot_x: + bpy.ops.transform.rotate(value=(radians(90.0),), axis=(1, 0, 0)) + if self.use_rot_z: + bpy.ops.transform.rotate(value=(radians(90.0),), axis=(0, 0, 1)) return {'FINISHED'} def invoke(self, context, event): @@ -385,7 +412,7 @@ class AmcImporter(bpy.types.Operator): frame_skip = IntProperty(name="Fps divisor", default=4, # usually the sample rate is 120, so the default 4 gives you 30fps description="Frame supersampling factor", min=1) - useFrameNo = BoolProperty(name="Use frame numbers", default=False, + use_frame_no = BoolProperty(name="Use frame numbers", default=False, description="Offset start of animation according to the source") filter_glob = StringProperty(default="*.amc", options={'HIDDEN'}) @@ -404,9 +431,9 @@ class AmcImporter(bpy.types.Operator): ob.name, ob['source_scale']) sb.load_armature(ob) - sb.load_motion_capture(self.properties.filepath, - self.properties.frame_skip, - self.properties.useFrameNo) + sb.load_motion_capture(self.filepath, + self.frame_skip, + self.use_frame_no) AmcAnimator.sb = sb bpy.ops.import_anim.amc_animate() return {'FINISHED'} diff --git a/io_anim_c3d/__init__.py b/io_anim_c3d/__init__.py index d4453f95..2a460bea 100644 --- a/io_anim_c3d/__init__.py +++ b/io_anim_c3d/__init__.py @@ -30,10 +30,10 @@ bl_info = { 'api': 41226, 'location': "File > Import", 'description': "Imports C3D Graphics Lab Motion Capture files", - 'wiki_url': ("http://wiki.blender.org/index.php/Extensions:2.5/Py/" - "Scripts/Import-Export/C3D_Importer"), - 'tracker_url': ("http://projects.blender.org/tracker/?func=detail&atid=467" - "&aid=29061&group_id=153"), + 'wiki_url': "http://wiki.blender.org/index.php/Extensions:2.5/Py/" + "Scripts/Import-Export/C3D_Importer", + 'tracker_url': "http://projects.blender.org/tracker/?func=detail&atid=467" + "&aid=29061&group_id=153", 'category': 'Import-Export'} @@ -71,7 +71,7 @@ class C3DAnimateCloud(bpy.types.Operator): if self.curframe > self.markerset.endFrame: return self.cancel(context) fno = self.curframe - if not self.useFrameNo: + if not self.use_frame_no: fno = (self.curframe - self.markerset.startFrame) / self.fskip for i in range(self.fskip): self.markerset.readNextFrameData() @@ -104,38 +104,73 @@ class C3DImporter(bpy.types.Operator): bl_idname = "import_anim.c3d" bl_label = "Import C3D" - filepath = StringProperty(name="File Path", maxlen=1024, default="", - description="Path to the C3D file") - from_inches = BoolProperty(name="Convert from inches to metric", - default=False, description="Scale by 2.54/100") - scale = FloatProperty(name="Scale", default=1., - description="Scale the positions by this value", - min=0.0001, max=1000000.0, - soft_min=0.001, soft_max=100.0) - auto_scale = BoolProperty(name="Adjust scale automatically", default=False, - description="Guess correct scale factor") - auto_magnitude = BoolProperty(name="Adjust scale magnitude", default=True, - description="Automatically adjust scale magnitude") - size = FloatProperty(name="Empty Size", default=.03, - description="The size of each empty", - min=0.0001, max=1000000.0, - soft_min=0.001, soft_max=100.0) - x_ray = BoolProperty(name="Use X-Ray", default=True, - description="Show the empties over other objects") - frame_skip = IntProperty(name="Fps divisor", default=4, - # usually the sample rate is 120, so the default 4 gives you 30fps - description="Frame supersampling factor", min=1) - useFrameNo = BoolProperty(name="Use frame numbers", default=False, - description="Offset start of animation according to the source") - show_names = BoolProperty(name="Show Names", default=False, - description="Show the markers' name") - prefix = StringProperty(name="Name Prefix", maxlen=1024, default="", - description="Prefix object names with this") - confidence = FloatProperty(name="Minimum Confidence Level", default=0, - description="Only consider markers with at least " - "this confidence level", - min=-1., max=1000000.0, - soft_min=-1., soft_max=100.0) + filepath = StringProperty( + name="File Path", + maxlen=1024, + description="Path to the C3D file", + ) + from_inches = BoolProperty( + name="Convert from inches to metric", + default=False, + description="Scale by 2.54/100", + ) + scale = FloatProperty( + name="Scale", + default=1.0, + description="Scale the positions by this value", + min=0.0001, max=1000000.0, + soft_min=0.001, soft_max=100.0, + ) + auto_scale = BoolProperty( + name="Adjust scale automatically", + default=False, + description="Guess correct scale factor", + ) + auto_magnitude = BoolProperty( + name="Adjust scale magnitude", + default=True, + description="Automatically adjust scale magnitude", + ) + size = FloatProperty( + name="Empty Size", + default=.03, + description="The size of each empty", + min=0.0001, max=1000000.0, + soft_min=0.001, soft_max=100.0, + ) + x_ray = BoolProperty( + name="Use X-Ray", + default=True, + description="Show the empties over other objects", + ) + frame_skip = IntProperty( + name="Fps divisor", + default=4, + # usually the sample rate is 120, so the default 4 gives you 30fps + description="Frame supersampling factor", + min=1, + ) + use_frame_no = BoolProperty( + name="Use frame numbers", + default=False, + description="Offset start of animation according to the source", + ) + show_names = BoolProperty( + name="Show Names", default=False, + description="Show the markers' name", + ) + prefix = StringProperty( + name="Name Prefix", maxlen=32, + description="Prefix object names with this", + ) + confidence = FloatProperty( + name="Minimum Confidence Level", default=0, + description="Only consider markers with at least " + "this confidence level", + min=-1., max=1000000.0, + soft_min=-1., soft_max=100.0, + ) + filter_glob = StringProperty(default="*.c3d;*.csv", options={'HIDDEN'}) def find_height(self, ms): @@ -165,11 +200,11 @@ class C3DImporter(bpy.types.Operator): def adjust_scale(self, height, scale): factor = height * scale / 1.75 # normalize - if factor < .5: - scale /= 10 - factor *= 10 + if factor < 0.5: + scale /= 10.0 + factor *= 10.0 cmu_factors = [(1.0, 1.0), (1.1, 1.45), (1.6, 1.6), (2.54, 2.54)] - sqerr, fix = min(((cf[0] - factor) ** 2, 1 / cf[1]) + sqerr, fix = min(((cf[0] - factor) ** 2.0, 1.0 / cf[1]) for cf in cmu_factors) #print('height * scale: {:.2f}'.format(height * scale)) #print(factor, fix) @@ -213,7 +248,7 @@ class C3DImporter(bpy.types.Operator): C3DAnimateCloud.scale = scale C3DAnimateCloud.fskip = self.properties.frame_skip C3DAnimateCloud.prefix = self.properties.prefix - C3DAnimateCloud.useFrameNo = self.properties.useFrameNo + C3DAnimateCloud.use_frame_no = self.properties.use_frame_no C3DAnimateCloud.confidence = self.properties.confidence C3DAnimateCloud.curframe = ms.startFrame bpy.ops.import_anim.c3danim() |