def animation_rig_hierarchy_test(self): #import file and export hierarchy prefix = 'walk_cycle' cmds.file(get_app_file(KIKO_APP_NAME, 'walk_cycle.ma'), i=True, typ="mayaAscii", iv=True, ra=True, mnc=False, options="v=0;", rpr=prefix) cmds.select(prefix + '_rig', r=True) self._manager.export_to_file(self._kiko_file, hierarchy=True) #import file with namespace cmds.file(get_app_file(KIKO_APP_NAME, 'walk_cycle.ma'), i=True, namespace=prefix, typ="mayaAscii", iv=True, mnc=False, ra=True, options="v=0;", rnn=True) #delete animation new_controls = cmds.sets(prefix + ":controls", q=True) for c in new_controls: attrs = list( set(cmds.listAttr(c, keyable=True) or []) | set(cmds.listAttr(c, channelBox=True) or [])) for a in attrs: all_keys = cmds.keyframe(c, query=True, indexValue=True, at=a) if all_keys: all_keys.sort() all_keys.reverse() for k in all_keys: cmds.cutKey(c, attribute=a, index=(k, k), clear=True) cmds.select(prefix + ':rig', r=True) self._manager.import_from_file( self._kiko_file, import_obj_method=IMPORT_METHODS.OBJECT.HIERARCHY, ignore_item_chunks=True) #compare self._compare_children(prefix + '_rig', prefix + ':rig', repl=((prefix + "_", prefix + ":"), ))
def export_import_simple_test(self): nuke.scriptOpen(get_app_file(KIKO_APP_NAME, 'simple_axis.nk')) node1 = nuke.toNode("Axis1") node1.setSelected(True) self._manager.export_to_file(self._kb_file) node2 = nuke.createNode('Axis') obj_mapping = {node1.name(): node2.name()} self._manager.import_from_file(self._kb_file, objects=[node2.name()], obj_mapping=obj_mapping, ignore_item_chunks=True) min, max = self._facade.get_active_frame_range() channels = ['translate', 'rotate'] for i in range(int(min), int(max)): self._facade.move_to_frame(i) for c in channels: k1 = node1.knob(c) k2 = node2.knob(c) for ci in range(3): assert_true( floats_equal(k1.valueAt(i, ci), k2.valueAt(i, ci)))
def export_hierchy_import_single_item_for_world_space_operator_test(self): cmds.file(get_app_file(KIKO_APP_NAME, 'locators_hierarchy.ma'), force=True, open=True, options='v=0;') cmds.select("parent") wo_name = worldspaceoperator.WorldSpaceOperator.name() self._manager.export_to_file(self._kiko_file, objects=['parent'], hierarchy=True, operators=(wo_name, )) l = cmds.spaceLocator() obj_mapping = {'childBB': l[0]} self._manager.import_from_file(self._kiko_file, objects=l, obj_mapping=obj_mapping) c1 = 'childBB' c2 = l[0] min = cmds.playbackOptions(q=True, minTime=True) max = cmds.playbackOptions(q=True, maxTime=True) for i in range(int(min), int(max)): cmds.currentTime(i) x1 = cmds.xform(c1, ws=True, m=True, q=True) x2 = cmds.xform(c2, ws=True, m=True, q=True) for i in range(len(x1)): assert_true(floats_equal(x1[i], x2[i], places=12))
def _export_import_simple_file_test_shared(self, file_): cmds.file(get_app_file(KIKO_APP_NAME, 'simple_locator.ma'), force=True, open=True, options='v=0;') cmds.select("locator1") self._manager.export_to_file(file_) l = cmds.spaceLocator() obj_mapping = {'locator1': l[0]} self._manager.import_from_file(file_, objects=l, obj_mapping=obj_mapping, ignore_item_chunks=True) min = cmds.playbackOptions(q=True, minTime=True) max = cmds.playbackOptions(q=True, maxTime=True) for i in range(int(min), int(max)): cmds.currentTime(i) for attr in TRANSFORM_ATTR: assert_true( floats_equal(cmds.getAttr("locator1" + attr), cmds.getAttr(l[0] + attr)))
def _export_and_duplicate_hierarchy(self, file_, rename_children=False): cmds.file(get_app_file(KIKO_APP_NAME, 'locators_hierarchy.ma'), force=True, open=True, options='v=0;') cmds.select("parent") self._manager.export_to_file(file_, objects=['parent'], hierarchy=True) if rename_children: cmds.duplicate(rr=True, renameChildren=True) else: cmds.duplicate(rr=True)
def export_hierchy_import_anim_single_item_for_world_space_operator_test( self): cmds.file(get_app_file(KIKO_APP_NAME, 'locators_hierarchy.ma'), force=True, open=True, options='v=0;') cmds.select("parent") wo_name = worldspaceoperator.WorldSpaceOperator.name() self._manager.export_to_file(self._kiko_file, objects=['parent'], hierarchy=True, operators=(wo_name, )) l = cmds.spaceLocator() obj_mapping = {'childBB': l[0]} min = cmds.playbackOptions(q=True, minTime=True) max = cmds.playbackOptions(q=True, maxTime=True) channels = [".tx", ".ty", ".tz", ".rx", ".ry", ".rz"] for i in range(10): frame = random.randint(min, max) value = random.randint(-100, 100) attr = random.choice(channels) cmds.setKeyframe(l[0] + attr, v=value, time=frame) for i in range(10): value = random.randint(-100, 100) cmds.setKeyframe(l[0] + ".tx", v=value, time=max + i + 1) self._manager.import_from_file(self._kiko_file, objects=l, obj_mapping=obj_mapping) c1 = 'childBB' c2 = l[0] for i in range(int(min), int(max)): cmds.currentTime(i) x1 = cmds.xform(c1, ws=True, m=True, q=True) x2 = cmds.xform(c2, ws=True, m=True, q=True) for i in range(len(x1)): assert_true(floats_equal(x1[i], x2[i], places=12)) for attr in channels: assert_equal(cmds.keyframe(l[0] + attr, q=True, kc=True), 120)
def op_priority_test(self): cmds.file(get_app_file(KIKO_APP_NAME, 'locators_hierarchy.ma'), force=True, open=True, options='v=0;') cmds.select("parent") t = cmds.currentTime(q=True) self._manager.export_to_file(self._kiko_file, objects=['parent'], hierarchy=True, force_op_evaluation=True) cmds.duplicate(rr=True) children = cmds.listRelatives("parent1", ad=True, f=True, typ='transform') for c in children: for a in TRANSFORM_ATTR: cmds.setAttr(c + a, 0) stn = staticoperator.StaticOperator.name() bkn = bakeoperator.BakeOperator.name() cmds.delete( cmds.listRelatives("parent1", ad=True, f=True, typ='constraint') or []) self._manager.import_from_file( self._kiko_file, objects=['parent1'], import_obj_method=IMPORT_METHODS.OBJECT.HIERARCHY, ignore_item_chunks=True, channel_op_priority=[stn, bkn]) children = cmds.listRelatives("parent1", ad=True, f=True, typ='transform') cmds.currentTime(t) for c in children: for a in TRANSFORM_ATTR: assert_true(cmds.keyframe(c + a, q=True, kc=True) == 0) other_c = c.replace('parent1', 'parent') assert_true( floats_equal(cmds.getAttr(c + a), cmds.getAttr(other_c + a)))
def export_force_all_chunks_test(self): cmds.file(get_app_file(KIKO_APP_NAME, 'locators_hierarchy.ma'), force=True, open=True, options='v=0;') cmds.select("parent") self._manager.export_to_file(self._kiko_file, objects=['parent'], hierarchy=True, force_op_evaluation=True) root = self._manager.get_root_from_file(self._kiko_file, flatten_hierarchy=True) item_op_num = len( OperatorsFactory().get_item_operator_names(KIKO_APP_NAME)) for item in root.iter_children(): assert_equal(item.num_chunks, item_op_num) for c in item.iter_channels(): assert_greater(c.num_chunks, 1)
def export_one_operator_test(self): cmds.file(get_app_file(KIKO_APP_NAME, 'locators_hierarchy.ma'), force=True, open=True, options='v=0;') cmds.select("parent") wo_name = worldspaceoperator.WorldSpaceOperator.name() st_name = staticoperator.StaticOperator.name() self._manager.export_to_file(self._kb_file, objects=['parent'], hierarchy=True, force_op_evaluation=True, operators=[wo_name, st_name]) root = self._manager.get_root_from_file(self._kb_file, flatten_hierarchy=True) for item in root.iter_children(): assert_equal(item.num_chunks, 1) for c in item.iter_channels(): assert_equal(c.num_chunks, 1)
def apply_animation_and_break_all_connections_test(self): cmds.file(get_app_file(KIKO_APP_NAME, 'locators_hierarchy.ma'), force=True, open=True, options='v=0;') self._manager.export_to_file(self._kiko_file, objects=['parent'], hierarchy=True) min = int(cmds.playbackOptions(q=True, minTime=True)) max = int(cmds.playbackOptions(q=True, maxTime=True)) MayaPreferences.reset() MayaPreferences.break_all_connections_in_apply_mode = True children = cmds.listRelatives('parent', ad=True, f=True, typ='transform') cache = {} for c in children: if 'constraint' in cmds.nodeType(c, i=True): continue values = {} for attr in TRANSFORM_ATTR: val = [] for i in range(min, max): cmds.currentTime(i) val.append(cmds.getAttr(c + attr)) values[attr] = val cache[c] = values self._manager.import_from_file( self._kiko_file, objects=['parent'], import_obj_method=IMPORT_METHODS.OBJECT.HIERARCHY, ignore_item_chunks=True) #constraints should have been deleted assert_false( bool([ c for c in cmds.listConnections( '|parent|childD', s=True, d=False) if 'constraint' in cmds.nodeType(c, i=True) ])) #checking values are the same for c in children: if 'constraint' in cmds.nodeType(c, i=True): continue for attr in TRANSFORM_ATTR: index = 0 for i in range(min, max): cmds.currentTime(i) assert_true( floats_equal(cmds.getAttr(c + attr), cache[c][attr][index])) index += 1 MayaPreferences.reset()
def animation_rig_by_name_test(self): #test with names, remove namespace prefix = 'walk_cycle' cmds.file(get_app_file(KIKO_APP_NAME, 'walk_cycle.ma'), i=True, typ="mayaAscii", iv=True, ra=True, mnc=False, options="v=0;", rpr=prefix) controls = cmds.sets(prefix + "_controls", q=True) self._manager.export_to_file(self._kiko_file, objects=controls) cmds.file(get_app_file(KIKO_APP_NAME, 'walk_cycle.ma'), i=True, namespace=prefix, typ="mayaAscii", iv=True, mnc=False, ra=True, options="v=0;", rnn=True) #deleting the animation from the imported rig new_controls = cmds.sets(prefix + ":controls", q=True) for c in new_controls: attrs = list( set(cmds.listAttr(c, keyable=True) or []) | set(cmds.listAttr(c, channelBox=True) or [])) for a in attrs: all_keys = cmds.keyframe(c, query=True, indexValue=True, at=a) if all_keys: all_keys.sort() all_keys.reverse() for k in all_keys: cmds.cutKey(c, attribute=a, index=(k, k), clear=True) #import cmds.select(new_controls, r=True) self._manager.import_from_file(self._kiko_file, prefix_to_add=prefix + ":", str_replacements={prefix + '_': ''}, ignore_item_chunks=True) #compare min = cmds.playbackOptions(q=True, minTime=True) max = cmds.playbackOptions(q=True, maxTime=True) for i in range(int(min), int(max)): cmds.currentTime(i) for c in controls: attrs = list( set(cmds.listAttr(c, keyable=True) or []) | set(cmds.listAttr(c, channelBox=True) or [])) other_c = prefix + ":" + c.replace(prefix + "_", "") for a in attrs: val = cmds.getAttr(c + '.' + a) if isinstance(val, float): assert_true( floats_equal(val, cmds.getAttr(other_c + '.' + a))) else: assert_equal(val, cmds.getAttr(other_c + '.' + a))