def getAnimationProperty(self, anim_trans, index): debugPrint("{}".format(anim_trans)) for at in anim_trans: debugPrint("{}".format(at)) for key in at.keys(): if at[key] == index: return key raise ValueError("Cant find the key: {} ".format(index))
def setSettings(self, scene, result): res = {} result["settings"] = res for _setting in BLENDER_SETTINGS: for key in _setting.keys(): debugPrint(key) prop_value = self.getProperty(_setting[key], scene) if prop_value != None: self.addProperty(key, res) self.setProperty(key, _setting[key], scene, res, False)
def translate(self, value, isRotation): if isinstance(value, int) or isinstance(value, float) or isinstance(value, bool) or value == None or isinstance(value, str): if isRotation == True: if isinstance(value, int) or isinstance(value, float): return math.radians(value) return value if isRotation == False: return [f for f in value] debugPrint("translate : {}".format(value)) list = [] for f in value: debugPrint("f: {}".format(f)) list.append(math.radians(f)) return list
def translate(self, value, isRotation): if isinstance(value, int) or isinstance(value, float) or isinstance( value, bool) or value == None or isinstance(value, str): if isRotation == True: if isinstance(value, int) or isinstance(value, float): return math.radians(value) return value if isRotation == False: return [f for f in value] debugPrint("translate : {}".format(value)) list = [] for f in value: debugPrint("f: {}".format(f)) list.append(math.radians(f)) return list
def setPropertyValue(self, key , value, result , isRotation): debugPrint("key: {}, value: {}, result: {}, isRotation".format(key, value, result, isRotation)) split_key = key.split(".") temp = result for sk in split_key: if sk in temp: if temp[sk] == None: if sk in KEYPOINT_OVERRIDE: temp[sk] = KEYPOINT_OVERRIDE[sk] else: temp[sk] = self.translate(value, isRotation) else: temp = temp[sk] else: raise ValueError("Missing key in dictionary.")
def setPropertyValue(self, key, value, result, isRotation): debugPrint("key: {}, value: {}, result: {}, isRotation".format( key, value, result, isRotation)) split_key = key.split(".") temp = result for sk in split_key: if sk in temp: if temp[sk] == None: if sk in KEYPOINT_OVERRIDE: temp[sk] = KEYPOINT_OVERRIDE[sk] else: temp[sk] = self.translate(value, isRotation) else: temp = temp[sk] else: raise ValueError("Missing key in dictionary.")
def setScenes(self, scenes, result): _scenes = [] result["scenes"] = _scenes for scene in scenes: _scene = {} for scene_setting in SCENE_SETTINGS: for key in scene_setting.keys(): self.addProperty(key, _scene) self.setProperty(key, scene_setting[key], scene, _scene, False) objects = [] keyframes = [] _scene["objects"] = objects debugPrint("read cameras") self.readCameras(scene, objects, keyframes) self.readSelectedObjects(scene, objects, keyframes) _scene["keyframes"] = keyframes _scenes.append(_scene)
def readKeyFrames(self, obj, keyframes): if hasattr(obj.animation_data, "action"): for f in obj.animation_data.action.fcurves: for k in f.keyframe_points: fr = k.co[0] bpy.context.scene.frame_set(fr) frame = {} frame["frame"] = fr keyframes.append(frame) objects = [] frame["objects"] = objects object = {} debugPrint("get name") object["name"] = obj.name objects.append(object) self.setObjectKeyFrame(object, k, f, obj) debugPrint("set object key frame") else: debugPrint("no actions")
def readKeyFrames(self, obj, keyframes): if hasattr(obj.animation_data, "action"): for f in obj.animation_data.action.fcurves: for k in f.keyframe_points: fr = k.co[0] bpy.context.scene.frame_set(fr) frame = {} frame["frame"] = fr keyframes.append(frame) objects = [] frame["objects"] = objects object = { } debugPrint("get name") object["name"] = obj.name objects.append(object) self.setObjectKeyFrame(object, k, f, obj) debugPrint("set object key frame") else: debugPrint("no actions")
def setProperty(self, key, settings_key, scene, result, isRotation): prop_value = self.getProperty(settings_key, scene) debugPrint("getProperty") self.setPropertyValue(key, prop_value, result, isRotation) debugPrint("setPropertyValue")
def setObjectKeyFrame(self, object, keyframe_point, fcurve, scene_obj): debugPrint("get animation translation") animation_trans = self.getAnimationTranslation(fcurve.data_path) debugPrint("get animation prop") anim_property = self.getAnimationProp(fcurve.data_path) debugPrint("get animation property") prop = self.getAnimationProperty(animation_trans, fcurve.array_index) debugPrint("animation_trans {} anim_property {} prop {}".format( animation_trans, anim_property, prop)) if anim_property not in object: object[anim_property] = {} value = self.getProperty(fcurve.data_path + "." + prop, scene_obj) if fcurve.data_path == "rotation_euler": debugPrint("value : {}".format(value)) value = value * 360 / (math.pi * 2) object[anim_property][prop] = value _keyframe_point = {"co": [f for f in keyframe_point.co]} object[anim_property][prop + "_keyframe_point"] = _keyframe_point for kfp in KEYPOINT_SETTINGS: debugPrint("{}".format(kfp)) for key in kfp.keys(): self.addProperty(key, _keyframe_point) debugPrint("add property") self.setProperty(key, kfp[key], keyframe_point, _keyframe_point, False) debugPrint("set property")
def setObjectKeyFrame(self, object, keyframe_point, fcurve, scene_obj): debugPrint("get animation translation") animation_trans = self.getAnimationTranslation(fcurve.data_path) debugPrint("get animation prop") anim_property = self.getAnimationProp(fcurve.data_path) debugPrint("get animation property") prop = self.getAnimationProperty(animation_trans, fcurve.array_index) debugPrint("animation_trans {} anim_property {} prop {}".format(animation_trans, anim_property, prop)) if anim_property not in object: object[anim_property] = {} value = self.getProperty(fcurve.data_path + "." + prop, scene_obj) if fcurve.data_path == "rotation_euler": debugPrint("value : {}".format(value)) value = value * 360 / (math.pi*2) object[anim_property][prop] = value _keyframe_point = { "co": [f for f in keyframe_point.co] } object[anim_property][prop+"_keyframe_point"] = _keyframe_point for kfp in KEYPOINT_SETTINGS: debugPrint("{}".format(kfp)) for key in kfp.keys(): self.addProperty(key, _keyframe_point) debugPrint("add property") self.setProperty(key, kfp[key], keyframe_point, _keyframe_point, False) debugPrint("set property")