import os, re, bpy, math, struct, os.path, mathutils from . import common # メインオペレーター class import_cm3d2_anm(bpy.types.Operator): bl_idname = 'import_anim.import_cm3d2_anm' bl_label = "CM3D2 Animation (.anm)" bl_description = "Loads a CM3D2 .anm file." bl_options = {'REGISTER'} filepath = bpy.props.StringProperty(subtype='FILE_PATH') filename_ext = ".anm" filter_glob = bpy.props.StringProperty(default="*.anm", options={'HIDDEN'}) scale = bpy.props.FloatProperty(name="Scale", default=5, min=0.1, max=100, soft_min=0.1, soft_max=100, step=100, precision=1, description="The scale at the time of import.") remove_pre_animation = bpy.props.BoolProperty(name="Remove previous Animation", default=True) set_frame = bpy.props.BoolProperty(name="Set Frame", default=True) ignore_automatic_bone = bpy.props.BoolProperty(name="Exclude Twister Bones", default=True) is_location = bpy.props.BoolProperty(name="Position", default=True) is_rotation = bpy.props.BoolProperty(name="Rotation", default=True) is_scale = bpy.props.BoolProperty(name="Bigger/Smaller", default=False) @classmethod def poll(cls, context): ob = context.active_object if ob: if ob.type == 'ARMATURE': return True return False def invoke(self, context, event): if common.preferences().anm_default_path: self.filepath = common.default_cm3d2_dir(common.preferences().anm_default_path, "", "anm") else: self.filepath = common.default_cm3d2_dir(common.preferences().anm_import_path, "", "anm") self.scale = common.preferences().scale context.window_manager.fileselect_add(self) return {'RUNNING_MODAL'} def draw(self, context): self.layout.prop(self, 'scale') box = self.layout.box() box.prop(self, 'remove_pre_animation', icon='DISCLOSURE_TRI_DOWN') box.prop(self, 'set_frame', icon='NEXT_KEYFRAME') box.prop(self, 'ignore_automatic_bone', icon='X') box = self.layout.box() box.label("Animation Information") column = box.column(align=True) column.prop(self, 'is_location', icon='MAN_TRANS') column.prop(self, 'is_rotation', icon='MAN_ROT') row = column.row() row.prop(self, 'is_scale', icon='MAN_SCALE') row.enabled = False def execute(self, context): common.preferences().anm_import_path = self.filepath try: file = open(self.filepath, 'rb') except: self.report(type={'ERROR'}, message="Failed to open the file. It's either inaccessible or the file does not exist") return {'CANCELLED'} # ヘッダー ext = common.read_str(file) if ext != 'CM3D2_ANIM': self.report(type={'ERROR'}, message="This is not a CM3D2 animation file.") return {'CANCELLED'} struct.unpack('