def houSetAttr(self, nap_file_name=None, houdini_nodes=[], houdini_node_attribute=None, map_file_name=None, offset_value=0, start_frame=None, end_frame=None, attribute_map=None): """ This function will get all curve data from a map and channel file then those data will be applied to proper nodes :param nap_file_name: User must pass a file where he want to write out curves and make sure you supply a .nap or .xml file format :type nap_file_name: string :param houdini_nodes: list of houdini objects :type houdini_nodes: list :param houdini_node_attribute: if you want to replace attribute from the map file then you can specify the override attribute here :type houdini_node_attribute: string :param map_file_name: Filepath of napalm channel data :type map_file_name: string :param offset_value: Animation key offset value :type offset_value: int :param start_frame: start frame to capture :type start_frame: int :param end_frame: end frame to capture :type end_frame: int :param attribute_map: This a template object from template module :type attribute_map: list of tuple Example >>> import kip_houdini.convert as kh >>> reload(kh) >>> khpr=kh.HoudiniReader() >>> import kip.template as template >>> attr_mp = template.KipTemplates() >>> attr_mp.ATTRMAP={"t1.cutatt1":"/obj/geo1/xform1.ottr_1","t1.cutatt2":"/obj/geo1/xform1.ottr_2","t2.cutatt1":"/obj/geo1/xform1.ottr_3","t2.cutatt2":"/obj/geo1/xform1.ottr_4"} >>> a = attr_mp.ATTRMAP >>> khpr.houSetAttr(nap_file_name="/tmp/single_maya_test.nap",houdini_nodes="/obj/geo1/xform1",attribute_map=a) """ if nap_file_name: if not map_file_name: map_file_name = kip_reader.build_map_file_name(nap_file_name) header_info = kip_reader.header(map_file_name) array_index = kip_reader.find_software_index( header_info["client_software"]) houdini_node_list = houdini_nodes knob_read = kip_reader.ReadCurve() get_curve_class = knob_read.getCurves(nap_file_name = nap_file_name, \ map_file_name = map_file_name, offset_value = offset_value) for each_node in get_curve_class: node_key = get_curve_class.index(each_node) current_node_curve = each_node[2] curent_source_node = each_node[0] for each_curve in current_node_curve: curve_attr = each_curve[1] current_key_dict = each_curve[2] time_keys = current_key_dict["time"] key_value = current_key_dict["key_value"] in_angle = current_key_dict["in_angle"] out_angle = current_key_dict["out_angle"] in_weight = current_key_dict["in_weight"] out_weight = current_key_dict["out_weight"] in_tan_type = current_key_dict["in_tan_type"] out_tan_type = current_key_dict["out_tan_type"] in_slope = current_key_dict["in_slope"] out_slope = current_key_dict["out_slope"] try: for time in time_keys: if houdini_node_attribute: curve_attr = houdini_node_attribute else: if attribute_map: temp_attr_keys = attribute_map.keys() for each_template in temp_attr_keys: source_details = each_template.split(".") current_node_attr = "%s.%s" % (curent_source_node, \ each_curve[1]) if current_node_attr == each_template: destenation_details = attribute_map[each_template]\ .split(".") curve_attr = destenation_details[1] current_houdini_node = destenation_details[ 0] current_houdini_node = hou.node( current_houdini_node) break else: current_houdini_node = hou.node( houdini_node_list[node_key]) if start_frame and end_frame: if time in range(start_frame, end_frame + 1): key_index = time_keys.index(time) else: print "%s not in range not applying the key" % time continue else: key_index = time_keys.index(time) in_tan_v = in_tan_type[key_index] if self.nuke_tan_types.has_key(in_tan_v): in_tan_v = self.nuke_tan_types[in_tan_v] else: in_tan_v = "bezier()" hkey = hou.Keyframe() hkey.setTime((time_keys[key_index] / GLOBAL_FPS)) hkey.setValue(key_value[key_index]) hkey.setExpression("bezier()") hkey.setExpression("spline()") hkey.setInAccel(in_weight[key_index]) hkey.setAccel(out_weight[key_index]) hkey.setInSlope(in_slope[key_index]) hkey.setSlope(out_slope[key_index]) this_node_attr = curve_attr if self.channel_match.has_key(curve_attr): this_node_attr = self.channel_match[curve_attr] hou_nod = current_houdini_node.parm( this_node_attr).setKeyframe(hkey) except: traceback.print_exc() raise KipBaseError("No objects found in node list!") rodin_logger.info("Aniamtion curve trasfer is finished !") return True
def houSetAttr(self, nap_file_name = None, houdini_nodes = [], houdini_node_attribute = None, map_file_name = None, offset_value = 0, start_frame = None, end_frame = None, attribute_map = None): """ This function will get all curve data from a map and channel file then those data will be applied to proper nodes :param nap_file_name: User must pass a file where he want to write out curves and make sure you supply a .nap or .xml file format :type nap_file_name: string :param houdini_nodes: list of houdini objects :type houdini_nodes: list :param houdini_node_attribute: if you want to replace attribute from the map file then you can specify the override attribute here :type houdini_node_attribute: string :param map_file_name: Filepath of napalm channel data :type map_file_name: string :param offset_value: Animation key offset value :type offset_value: int :param start_frame: start frame to capture :type start_frame: int :param end_frame: end frame to capture :type end_frame: int :param attribute_map: This a template object from template module :type attribute_map: list of tuple Example >>> import kip_houdini.convert as kh >>> reload(kh) >>> khpr=kh.HoudiniReader() >>> import kip.template as template >>> attr_mp = template.KipTemplates() >>> attr_mp.ATTRMAP={"t1.cutatt1":"/obj/geo1/xform1.ottr_1","t1.cutatt2":"/obj/geo1/xform1.ottr_2","t2.cutatt1":"/obj/geo1/xform1.ottr_3","t2.cutatt2":"/obj/geo1/xform1.ottr_4"} >>> a = attr_mp.ATTRMAP >>> khpr.houSetAttr(nap_file_name="/tmp/single_maya_test.nap",houdini_nodes="/obj/geo1/xform1",attribute_map=a) """ if nap_file_name: if not map_file_name: map_file_name = kip_reader.build_map_file_name(nap_file_name) header_info = kip_reader.header(map_file_name) array_index = kip_reader.find_software_index(header_info["client_software"]) houdini_node_list = houdini_nodes knob_read = kip_reader.ReadCurve() get_curve_class = knob_read.getCurves(nap_file_name = nap_file_name, \ map_file_name = map_file_name, offset_value = offset_value) for each_node in get_curve_class: node_key = get_curve_class.index(each_node) current_node_curve = each_node[2] curent_source_node = each_node[0] for each_curve in current_node_curve: curve_attr = each_curve[1] current_key_dict = each_curve[2] time_keys = current_key_dict["time"] key_value = current_key_dict["key_value"] in_angle = current_key_dict["in_angle"] out_angle = current_key_dict["out_angle"] in_weight = current_key_dict["in_weight"] out_weight = current_key_dict["out_weight"] in_tan_type = current_key_dict["in_tan_type"] out_tan_type = current_key_dict["out_tan_type"] in_slope = current_key_dict["in_slope"] out_slope = current_key_dict["out_slope"] try: for time in time_keys: if houdini_node_attribute: curve_attr = houdini_node_attribute else: if attribute_map: temp_attr_keys = attribute_map.keys() for each_template in temp_attr_keys: source_details = each_template.split(".") current_node_attr = "%s.%s" % (curent_source_node, \ each_curve[1]) if current_node_attr == each_template: destenation_details = attribute_map[each_template]\ .split(".") curve_attr = destenation_details[1] current_houdini_node = destenation_details[0] current_houdini_node = hou.node(current_houdini_node) break else: current_houdini_node = hou.node(houdini_node_list[node_key]) if start_frame and end_frame: if time in range(start_frame, end_frame + 1): key_index = time_keys.index(time) else: print "%s not in range not applying the key" % time continue else: key_index = time_keys.index(time) in_tan_v = in_tan_type[key_index] if self.nuke_tan_types.has_key(in_tan_v): in_tan_v = self.nuke_tan_types[in_tan_v] else: in_tan_v = "bezier()" hkey = hou.Keyframe() hkey.setTime((time_keys[key_index]/GLOBAL_FPS)) hkey.setValue(key_value[key_index]) hkey.setExpression("bezier()") hkey.setExpression("spline()") hkey.setInAccel(in_weight[key_index]) hkey.setAccel(out_weight[key_index]) hkey.setInSlope(in_slope[key_index]) hkey.setSlope(out_slope[key_index]) this_node_attr = curve_attr if self.channel_match.has_key(curve_attr): this_node_attr = self.channel_match[curve_attr] hou_nod = current_houdini_node.parm(this_node_attr).setKeyframe(hkey) except: traceback.print_exc() raise KipBaseError("No objects found in node list!") rodin_logger.info("Aniamtion curve trasfer is finished !") return True
def mayaSetAttr(self, nap_file_name=None, maya_nodes=[], maya_node_attribute=None, map_file_name=None, offset_value=0, start_frame=None, end_frame=None, attribute_map=None): """ This function will get all curve data from a map and channel file then those data will be applied to proper nodes :param nap_file_name: User must pass a file where he want to write out curves and make sure you supply a .nap or .xml file format :type nap_file_name: string :param maya_nodes: list of maya objects :type maya_nodes: list :param maya_node_attribute: if you want to replace attribute from the map file then you can specify the override attribute here :type maya_node_attribute: string :param map_file_name: Filepath of napalm channel data :type map_file_name: string :param offset_value: Animation key offset value :type offset_value: int :param start_frame: start frame to capture :type start_frame: int :param end_frame: end frame to capture :type end_frame: int :param attribute_map: This a template object from template module :type attribute_map: list of tuple Example >>> import kip_maya.convert as km >>> reload(km) >>> kpr=km.MayaReader() >>> import kip.template as template >>> attr_mp = template.KipTemplates() >>> attr_mp.ATTRMAP={"t1.cutatt1":"o1.ottr_1","t1.cutatt2":"o1.ottr_2","t2.cutatt1":"o1.ottr_3","t2.cutatt2":"o1.ottr_4"} >>> a = attr_mp.ATTRMAP >>> kpr.mayaSetAttr(nap_file_name = "/tmp/single_maya_test.nap",maya_nodes=["o1"],attribute_map=a) >>> # Object based transfer >>> kpr.mayaSetAttr(nap_file_name = "/tmp/maya_kip_test.nap",maya_nodes=["pSphere2"]) """ if nap_file_name: if not map_file_name: map_file_name = kip_reader.build_map_file_name(nap_file_name) header_info = kip_reader.header(map_file_name) array_index = kip_reader.find_software_index( header_info["client_software"]) maya_node_list = maya_nodes knob_read = kip_reader.ReadCurve() get_curve_class = knob_read.getCurves(nap_file_name = nap_file_name, \ map_file_name = map_file_name, offset_value = offset_value) if maya_node_list: for each_node in get_curve_class: node_key = get_curve_class.index(each_node) current_node_curve = each_node[2] curent_source_node = each_node[0] for each_curve in current_node_curve: curve_attr = each_curve[1] current_key_dict = each_curve[2] time_keys = current_key_dict["time"] key_value = current_key_dict["key_value"] in_angle = current_key_dict["in_angle"] out_angle = current_key_dict["out_angle"] in_weight = current_key_dict["in_weight"] out_weight = current_key_dict["out_weight"] in_tan_type = current_key_dict["in_tan_type"] out_tan_type = current_key_dict["out_tan_type"] if maya_node_attribute: curve_attr = maya_node_attribute else: if attribute_map: current_maya_node = None temp_attr_keys = attribute_map.keys() for each_template in temp_attr_keys: source_details = each_template.split(".") current_node_attr = "%s.%s" % ( curent_source_node, curve_attr) if current_node_attr == each_template: destenation_details = attribute_map[each_template].split\ (".") curve_attr = destenation_details[1] current_maya_node = destenation_details[ 0] break if not current_maya_node: break else: current_maya_node = maya_node_list[node_key] if not cmds.attributeQuery(curve_attr, node = current_maya_node, \ exists = True): continue for time in time_keys: if start_frame and end_frame: if time in range(start_frame, end_frame + 1): key_index = time_keys.index(time) else: print "%s not in range not applying the key" % time continue else: key_index = time_keys.index(time) key_curve = cmds.setKeyframe(current_maya_node, \ v=key_value[key_index], at=curve_attr, time=time ) cmds.keyTangent(current_maya_node, edit=True, time = (time, time), \ attribute = curve_attr, ia = in_angle[key_index], \ oa = out_angle[key_index], iw= in_weight[key_index], \ ow = out_weight[key_index]) else: traceback.print_exc() raise KipBaseError("No objects found in node list!") rodin_logger.info("Aniamtion curve trasfer is finished !") return True
def mayaSetAttr(self, nap_file_name = None, maya_nodes = [], maya_node_attribute = None, map_file_name = None, offset_value = 0, start_frame = None, end_frame = None, attribute_map = None): """ This function will get all curve data from a map and channel file then those data will be applied to proper nodes :param nap_file_name: User must pass a file where he want to write out curves and make sure you supply a .nap or .xml file format :type nap_file_name: string :param maya_nodes: list of maya objects :type maya_nodes: list :param maya_node_attribute: if you want to replace attribute from the map file then you can specify the override attribute here :type maya_node_attribute: string :param map_file_name: Filepath of napalm channel data :type map_file_name: string :param offset_value: Animation key offset value :type offset_value: int :param start_frame: start frame to capture :type start_frame: int :param end_frame: end frame to capture :type end_frame: int :param attribute_map: This a template object from template module :type attribute_map: list of tuple Example >>> import kip_maya.convert as km >>> reload(km) >>> kpr=km.MayaReader() >>> import kip.template as template >>> attr_mp = template.KipTemplates() >>> attr_mp.ATTRMAP={"t1.cutatt1":"o1.ottr_1","t1.cutatt2":"o1.ottr_2","t2.cutatt1":"o1.ottr_3","t2.cutatt2":"o1.ottr_4"} >>> a = attr_mp.ATTRMAP >>> kpr.mayaSetAttr(nap_file_name = "/tmp/single_maya_test.nap",maya_nodes=["o1"],attribute_map=a) >>> # Object based transfer >>> kpr.mayaSetAttr(nap_file_name = "/tmp/maya_kip_test.nap",maya_nodes=["pSphere2"]) """ if nap_file_name: if not map_file_name: map_file_name = kip_reader.build_map_file_name(nap_file_name) header_info = kip_reader.header(map_file_name) array_index = kip_reader.find_software_index(header_info["client_software"]) maya_node_list = maya_nodes knob_read = kip_reader.ReadCurve() get_curve_class = knob_read.getCurves(nap_file_name = nap_file_name, \ map_file_name = map_file_name, offset_value = offset_value) if maya_node_list: for each_node in get_curve_class: node_key = get_curve_class.index(each_node) current_node_curve = each_node[2] curent_source_node = each_node[0] for each_curve in current_node_curve: curve_attr = each_curve[1] current_key_dict = each_curve[2] time_keys = current_key_dict["time"] key_value = current_key_dict["key_value"] in_angle = current_key_dict["in_angle"] out_angle = current_key_dict["out_angle"] in_weight = current_key_dict["in_weight"] out_weight = current_key_dict["out_weight"] in_tan_type = current_key_dict["in_tan_type"] out_tan_type = current_key_dict["out_tan_type"] if maya_node_attribute: curve_attr = maya_node_attribute else: if attribute_map: current_maya_node = None temp_attr_keys = attribute_map.keys() for each_template in temp_attr_keys: source_details = each_template.split(".") current_node_attr = "%s.%s" % (curent_source_node, curve_attr) if current_node_attr == each_template: destenation_details = attribute_map[each_template].split\ (".") curve_attr = destenation_details[1] current_maya_node = destenation_details[0] break if not current_maya_node: break else: current_maya_node = maya_node_list[node_key] if not cmds.attributeQuery(curve_attr, node = current_maya_node, \ exists = True): continue for time in time_keys: if start_frame and end_frame: if time in range(start_frame, end_frame + 1): key_index = time_keys.index(time) else: print "%s not in range not applying the key" % time continue else: key_index = time_keys.index(time) key_curve = cmds.setKeyframe(current_maya_node, \ v=key_value[key_index], at=curve_attr, time=time ) cmds.keyTangent(current_maya_node, edit=True, time = (time, time), \ attribute = curve_attr, ia = in_angle[key_index], \ oa = out_angle[key_index], iw= in_weight[key_index], \ ow = out_weight[key_index]) else: traceback.print_exc() raise KipBaseError("No objects found in node list!") rodin_logger.info("Aniamtion curve trasfer is finished !") return True
def nukeSetAttr(self, nap_file_name = None, nuke_node_attribute = None, nuke_nodes = [], stereo=False, left_eys = [], right_eys = [], map_file_name = None, offset_value = 0, start_frame = None, end_frame = None, attribute_map = None): """ This function will get all curve data from a map and channel file then those data will be applied to proper nodes :param nap_file_name: User must pass a file where he want to write out curves and make sure you supply a .nap or .xml file format :type nap_file_name: string :param nuke_nodes: list of nuke objects :type nuke_nodes: list :param nuke_node_attribute: if you want to replace attribute from the map file then you can specify the override attribute here :type nuke_node_attribute: string :param map_file_name: Filepath of napalm channel data :type map_file_name: string :param left_eyes: Left eye objects :type left_eyes: list :param right_eyes: Right eye objects :type right_eyes: list :param stereo: This will enable stereo curve apply for nodes :type stereo: bool :param offset_value: Animation key offset value :type offset_value: int :param start_frame: start frame to capture :type start_frame: int :param end_frame: end frame to capture :type end_frame: int :param attribute_map: This a template object from template module :type attribute_map: list of tuple Example >>> import nuke >>> import kip_nuke.convert as knc >>> reload(knc) >>> knr = knc.NukeReader() >>> import kip.template as template >>> attr_mp = template.KipTemplates() >>> attr_mp.ATTRMAP={"o1.ottr_1":"Transform1.rotate","o1.ottr_2":"Transform1.motionblur","o1.ottr_2":"Transform1.scale","o1.ottr_3":"Transform1.skew","o1.ottr_4":"Transform1.shutter"} >>> a = attr_mp.ATTRMAP >>> knr.nukeSetAttr(nap_file_name="/tmp/single_maya_test.nap",nuke_nodes=["Transform1"],attribute_map=a) >>> # Stereo transfer >>> knr.nukeSetAttr(nap_file_name="/tmp/maya_kip_test_s.nap",nuke_nodes=["Sphere1"],stereo=True) >>> # Object based transfer >>> knr.nukeSetAttr(nap_file_name="/tmp/maya_kip_test.nap",nuke_nodes=["Sphere1"]) """ if nap_file_name and os.path.exists(nap_file_name): if not map_file_name: map_file_name = kip_reader.build_map_file_name(nap_file_name) header_info = kip_reader.header(map_file_name) array_index = kip_reader.find_software_index(header_info["client_software"]) nuke_node_list = nuke_nodes knob_read = kip_reader.ReadCurve() get_curve_class = knob_read.getCurves(nap_file_name = nap_file_name, \ map_file_name = map_file_name, offset_value = offset_value) curve_attr_index = 0 if nuke_nodes or attribute_map: if stereo: eye_dict_main = {} if not left_eys or right_eyes: curve_count = len(get_curve_class) for each_e_curve in get_curve_class: eye_dict_main.update({each_e_curve[0]:each_e_curve[1]}) curve_count = len(get_curve_class) object_count = len(nuke_node_list) for cnt in range(0, object_count): right_curve = get_curve_class[cnt] left_curve = get_curve_class[cnt+1] view_dict_key = {"right":right_curve, "left":left_curve} for each_curve in view_dict_key: base_curve_control = view_dict_key[each_curve][-1] for each_sub_curve in base_curve_control: curve_type = each_sub_curve[0] curve_attr = each_sub_curve[1][-1] current_key_dict = each_sub_curve[-1] time_keys = current_key_dict["time"] key_value = current_key_dict["key_value"] in_angle = current_key_dict["in_angle"] out_angle = current_key_dict["out_angle"] in_weight = current_key_dict["in_weight"] out_weight = current_key_dict["out_weight"] in_tan_type = current_key_dict["in_tan_type"] out_tan_type = current_key_dict["out_tan_type"] in_slope = current_key_dict["in_slope"] out_slope = current_key_dict["out_slope"] try: if attribute_map: temp_attr_keys = attribute_map.keys() for each_template in temp_attr_keys: source_details = each_template.split(".") current_node_attr = "%s.%s" % (curent_source_node, \ each_curve[1]) if current_node_attr == each_template: destenation_details = attribute_map[each_template].\ split(".") curve_type = destenation_details[1] current_node_name = destenation_details[0] current_node_name = nuke.toNode(current_node_name) break else: current_node_name = nuke_node_list[cnt] current_node_name = nuke.toNode(current_node_name) if curve_attr in self.curve_attr_temp.keys(): curve_attr_index = self.curve_attr_temp[curve_attr] try: list_all_knobs = current_node_name.knobs() if curve_type.lower() in list_all_knobs: current_knob = current_node_name[curve_type.lower()] current_knob.splitView(each_curve) nuke_anim_curve = current_knob.setAnimated\ (view=each_curve) nuke_anim_curve = current_knob.animations\ (view=each_curve)[curve_attr_index] for each_key in time_keys: if start_frame and end_frame: if each_key in range(start_frame, \ end_frame + 1): key_index = time_keys.index(each_key) else: print "%s not in range not applying the"\ " key" % each_key continue else: key_index = time_keys.index(each_key) current_key = nuke_anim_curve.setKey(time_keys\ [key_index], key_value[key_index]) keys_from_node = nuke_anim_curve.keys() self.apply_key_controls(keys_from_node, time_keys, \ key_value, in_angle, out_angle, in_weight, \ out_weight, in_tan_type, out_tan_type, \ in_slope, out_slope, nuke_anim_curve, \ start_frame = start_frame,\ end_frame = end_frame) except AttributeError: traceback.print_exc() raise KipAttrubiteError("Animation transfer failed") except IndexError: print "%s dont have %s in this % index!" % \ (current_node_name.name(),curve_attr,curve_attr_index) pass return True for each_node in get_curve_class: node_key = get_curve_class.index(each_node) current_node_curve = each_node[2] curent_source_node = each_node[0] for each_curve in current_node_curve: current_key_dict = each_curve[2] curve_type = each_curve[0] curve_attr = each_curve[1][-1] time_keys = current_key_dict["time"] key_value = current_key_dict["key_value"] in_angle = current_key_dict["in_angle"] out_angle = current_key_dict["out_angle"] in_weight = current_key_dict["in_weight"] out_weight = current_key_dict["out_weight"] in_tan_type = current_key_dict["in_tan_type"] out_tan_type = current_key_dict["out_tan_type"] in_slope = current_key_dict["in_slope"] out_slope = current_key_dict["out_slope"] if nuke_node_attribute: curve_type = nuke_node_attribute else: if attribute_map: temp_attr_keys = attribute_map.keys() for each_template in temp_attr_keys: source_details = each_template.split(".") current_node_attr = "%s.%s" % (curent_source_node, \ each_curve[1]) if current_node_attr == each_template: destenation_details = attribute_map[each_template].\ split(".") curve_type = destenation_details[1] current_node_name = destenation_details[0] current_nuke_node = nuke.toNode(current_node_name) break else: current_node_name = nuke_node_list[node_key] current_nuke_node = nuke.toNode(current_node_name) if curve_attr in self.curve_attr_temp.keys(): curve_attr_index = self.curve_attr_temp[curve_attr] try: list_all_knobs = current_nuke_node.knobs() if curve_type.lower() in list_all_knobs: nuke_anim_curve = current_nuke_node[curve_type.lower()]\ .setAnimated() nuke_anim_curve = current_nuke_node[curve_type.lower()]\ .animations()[curve_attr_index] for each_key in time_keys: if start_frame and end_frame: if each_key in range(start_frame, end_frame + 1): key_index = time_keys.index(each_key) else: print "%s not in range not applying the key" % each_key continue else: key_index = time_keys.index(each_key) current_key = nuke_anim_curve.setKey(time_keys[key_index], \ key_value[key_index]) keys_from_node = nuke_anim_curve.keys() self.apply_key_controls(keys_from_node, time_keys, key_value, \ in_angle, out_angle, in_weight, out_weight, in_tan_type, \ out_tan_type, in_slope, out_slope, nuke_anim_curve, \ start_frame = start_frame, end_frame = end_frame) except AttributeError: traceback.print_exc() raise KipAttrubiteError("Animation transfer failed") else: raise KipBaseError("No nodes passed for applying the keyframe") rodin_logger.info("Aniamtion curve trasfer is finished !") return True