def main(source=None, target=None): # These channels show up as animated even if there are no keys on them. Not a reliable source to determin animation. forbidden_channels = ["localMatrix", "wposMatrix", "wrotMatrix", "wsclMatrix", "wpivPosMatrix", "wpivRotMatrix", "worldMatrix", "glstate", "crvGroup", "matrix", "wParentMatrix", "glsurf", "mesh"] scene = modo.Scene() if source is None or target is None: selected = bd_helpers.selected(2) source = selected[0] target = selected[1] source_channels = bd_helpers.get_channels(source, type="name", forbidden_channels=forbidden_channels, isAnimated=False) target_channels = bd_helpers.get_channels(target, type="name", forbidden_channels=forbidden_channels, isAnimated=False) differences = list(set(source_channels) - set(target_channels)) for difference in differences: forbidden_channels.append(difference) animated = False # First we copy the item's channels for channel in source.channels(): if channel.isAnimated: if channel.name not in forbidden_channels: if channel.envelope.keyframes.numKeys > 0: animated = True bd_helpers.channel_copy_paste(source.id, channel.name, cmd="copy") bd_helpers.channel_copy_paste(target.id, channel.name, cmd="paste") # Now we find any Transform items associated with the source item and copy those for source_transform in modo.item.LocatorSuperType(item=source).transforms: source_transform_type = source_transform.type exists = False for target_transform in modo.item.LocatorSuperType(item=target).transforms: if target_transform.type == source_transform_type: exists = True target_transform_id = target_transform.id if not exists: target_transform_id = target.transforms.insert(source_transform_type) target_transform_id = target_transform_id.id for channel in source_transform.channels(): if channel.isAnimated: if channel.name not in forbidden_channels: if channel.envelope.keyframes.numKeys > 0: animated = True bd_helpers.channel_copy_paste(source_transform.id, channel.name, cmd="copy") bd_helpers.channel_copy_paste(target_transform_id, channel.name, cmd="paste") if len(differences) != 0: warning = "The following channels could not be copied because they do not exist on the target item:\n{0}".format( differences) modo.dialogs.alert("Warning", warning, dtype='warning') return animated
def get_channels(source=None): if source is None: selected = bd_helpers.selected(1) source = selected[0] source_channels = bd_helpers.get_channels( source, type="name", forbidden_channels=forbidden_channels, isAnimated=False) sourceTag = bd_helpers.get_tags(source) animated = False item_anim = bd_helpers.QueryDict() # First we copy the item's channels for channel in source.channels(): if channel.isAnimated: if channel.name not in forbidden_channels: if channel.envelope.keyframes.numKeys > 0: animated = True item_anim[channel.name] = { 'name': channel.name, 'type': channel.storageType } item_anim[channel.name].update(get_keys(channel)) return animated, item_anim
def main(): scene = modo.Scene() selected = bd_helpers.selected(2) if selected is not None: sourceGroup = selected[0] targetGroup = selected[1] tagsSource = dict() for child in sourceGroup.children(recursive=True): tag = bd_helpers.get_tags(child) tagsSource[tag] = child tagsTarget = dict() for child in targetGroup.children(recursive=True): tag = bd_helpers.get_tags(child) tagsTarget[tag] = child tagMismatch = [] for tag in tagsSource: if tag in tagsTarget: reload(bd_transfer_anim) animated = bd_transfer_anim.main(source=tagsSource[tag], target=tagsTarget[tag]) if animated: print("{0} ({1}) → {2} ({3})".format( tagsSource[tag].name, tagsSource[tag].id, tagsTarget[tag].name, tagsTarget[tag].id)) else: tagMismatch.append(tagsSource[tag].name) if len(tagMismatch) > 0: message = "" for tag in tagMismatch: message = "{}\n{}".format(message, tag) modo.dialogs.alert( "Warning", "There were animated items that could not be matched to any items in the target.\n" "Check their anim tag. Maybe it is missing or there is a mismatch.\n" "{}".format(message), dtype='warning')
def main(): global scene global fps reload(bd_helpers) scene = modo.Scene() fps = scene.fps selected = bd_helpers.selected(1) if selected is not None: print("Starting Animation Export…") start = bd_helpers.timer() sourceGroup = selected[0] tagsSource = dict() noTagItems = [] noTag = False tag = bd_helpers.get_tags(sourceGroup) tagsSource[tag] = sourceGroup if tag is None and len(sourceGroup.children(recursive=True)) == 0: noTag = True noTagItems.append(sourceGroup.name) for child in sourceGroup.children(recursive=True): tag = bd_helpers.get_tags(child) tagsSource[tag] = child if tag is None: noTag = True noTagItems.append(child.name) if noTag: modo.dialogs.alert( "No Tags!", "Some items have animation, but are not tagged. Aborting…\n{}". format(noTagItems), dtype='info') else: items_anim = dict() items_anim = { "01 __description__": "This is an automated export of an animated hierarchy or rig.", "02 __URL__": "https://github.com/AlexKucera/babylondreams-modo", "items": {} } for tag in tagsSource: items_anim["items"][tag] = {"id": tagsSource[tag].id} animated_channels, item_channels = get_channels( source=tagsSource[tag]) if animated_channels: items_anim["items"][tag]["channels"] = item_channels animated_transforms, item_transforms = get_transforms( source=tagsSource[tag]) if animated_transforms: items_anim["items"][tag]["transforms"] = item_transforms if animated_channels or animated_transforms: print("Getting animation from {0} ({1})".format( tagsSource[tag].name, tagsSource[tag].id)) if len(items_anim) > 0: bd_helpers.save_json( items_anim, "anim_export_cache{}anim_export_".format(os.sep)) bd_helpers.timer(start, "Finished Animation Export")
def main(): global scene global fps scene = modo.Scene() fps = scene.fps selected = bd_helpers.selected(1) if selected is not None: start = bd_helpers.timer() print("\n\nStarting Animation transfer…") reload(bd_helpers) anim_data = bd_helpers.load_json() if anim_data is None: modo.dialogs.alert( "No Tags!", "The provided file contains no useable information", dtype='info') else: targetGroup = selected[0] tagsTarget = dict() tag = bd_helpers.get_tags(targetGroup) if tag is not None: tagsTarget[tag] = targetGroup for child in targetGroup.children(recursive=True): tag = bd_helpers.get_tags(child) if tag is not None: tagsTarget[tag] = child missingTags = [] for tag in anim_data["items"]: if tag in tagsTarget: print("Transferring animation from {} to {}".format( anim_data["items"][tag]["id"], tagsTarget[tag].name)) target = tagsTarget[tag] # First we paste the item's channels if "channels" in anim_data["items"][tag]: for channel in target.channels(): if channel.name in anim_data["items"][tag][ "channels"]: set_keys( channel, anim_data["items"][tag] ["channels"][channel.name], anim_data["items"][tag]["channels"][ channel.name]["type"]) # Now we find any Transform items associated with the source item and copy those if "transforms" in anim_data["items"][tag]: for transform in anim_data["items"][tag]["transforms"]: source_transform_type = anim_data["items"][tag][ "transforms"][transform]["type"] exists = False # check if the transform type already exists for target_transform in modo.item.LocatorSuperType( item=target).transforms: if target_transform.type == source_transform_type or target_transform.type == "translation" and source_transform_type == "position": exists = True target_transform_id = target_transform # if it does not create it if not exists: target_transform_id = target.transforms.insert( source_transform_type) for channel in target_transform_id.channels(): if channel.name in anim_data["items"][tag][ "transforms"][transform]: if channel.name == "type" or channel.name == "name": pass else: set_keys( channel, anim_data["items"][tag] ["transforms"][transform] [channel.name], anim_data["items"] [tag]["transforms"][transform][ channel.name]["type"]) else: missingTags.append("{} ({})".format( tag, anim_data["items"][tag]["id"])) print("{} has not corresponding tag in the target.".format( anim_data["items"][tag]["name"])) bd_helpers.timer(start, "Finished Animation Transfer") if missingTags: message = "" for missing in missingTags: message = "{}\n{}".format(message, missing) message = "The provided file contains tags that are missing in the target hierarchy.\n" \ "The following tags cannot be found:\n{}".format(message) modo.dialogs.alert("Missing Tags!", message, dtype='info') print(message)