def _add(instance, representation_id, loaders, namespace, root="|"): """Add an item from the package Args: instance (dict): representation_id (str): loaders (list): namespace (str): Returns: str: The created Avalon container. """ from pype.hosts.maya.lib import get_container_transforms # Process within the namespace with namespaced(namespace, new=False) as namespace: # Get the used loader Loader = next((x for x in loaders if x.__name__ == instance['loader']), None) if Loader is None: log.warning("Loader is missing: %s. Skipping %s", instance['loader'], instance) raise RuntimeError("Loader is missing.") container = api.load(Loader, representation_id, namespace=instance['namespace']) # Get the root from the loaded container loaded_root = get_container_transforms({"objectName": container}, root=True) # Apply matrix to root node (if any matrix edits) matrix = instance.get("matrix", None) if matrix: cmds.xform(loaded_root, objectSpace=True, matrix=matrix) # Parent into the setdress hierarchy # Namespace is missing from parent node(s), add namespace # manually parent = root + to_namespace(instance["parent"], namespace) cmds.parent(loaded_root, parent, relative=True) return container
def effect_loader(self, representation): """ Gets Loader plugin for effects Arguments: representation (dict): avalon db entity """ context = representation["context"] loader_name = "LoadLuts" loader_plugin = None for Loader in api.discover(api.Loader): if Loader.__name__ != loader_name: continue loader_plugin = Loader return api.load(Loader=loader_plugin, representation=representation["_id"])
def load_look(look, overload=False): """Load look subset if it's not been loaded """ representation = io.find_one({ "type": "representation", "parent": look["versionId"], "name": "LookDev" }) representation_id = str(representation["_id"]) is_loaded = False for container in lib.lsAttrs({ "id": AVALON_CONTAINER_ID, "loader": "LookLoader", "representation": representation_id }): if overload: is_loaded = True log.info("Overload look ..") break log.info("Reusing loaded look ..") return parse_container(container) if not is_loaded: # Not loaded log.info("Using look for the first time ..") loaders = api.loaders_from_representation(api.discover(api.Loader), representation_id) Loader = next((i for i in loaders if i.__name__ == "LookLoader"), None) if Loader is None: raise RuntimeError("Could not find LookLoader, this is a bug") container = api.load(Loader, representation, options={"overload": overload}) return container
def read_loader(self, representation): """ Gets Loader plugin for image sequence or mov Arguments: representation (dict): avalon db entity """ context = representation["context"] loader_name = "LoadSequence" if "mov" in context["representation"]: loader_name = "LoadMov" loader_plugin = None for Loader in api.discover(api.Loader): if Loader.__name__ != loader_name: continue loader_plugin = Loader return api.load(Loader=loader_plugin, representation=representation["_id"])
def load(self, context, name, namespace, options): from avalon import api, pipeline from avalon.unreal import lib from avalon.unreal import pipeline as unreal_pipeline import unreal # Create directory for asset and avalon container root = "/Game/Avalon/Assets" asset = context.get('asset').get('name') suffix = "_CON" tools = unreal.AssetToolsHelpers().get_asset_tools() asset_dir, container_name = tools.create_unique_asset_name( "{}/{}".format(root, asset), suffix="") container_name += suffix unreal.EditorAssetLibrary.make_directory(asset_dir) libpath = self.fname with open(libpath, "r") as fp: data = json.load(fp) all_loaders = api.discover(api.Loader) for element in data: reference = element.get('_id') loaders = api.loaders_from_representation(all_loaders, reference) loader = None for l in loaders: if l.__name__ == "AnimationFBXLoader": loader = l break if not loader: continue instance_name = element.get('instance_name') api.load(loader, reference, namespace=instance_name, options=element) # Create Asset Container lib.create_avalon_container(container=container_name, path=asset_dir) data = { "schema": "openpype:container-2.0", "id": pipeline.AVALON_CONTAINER_ID, "asset": asset, "namespace": asset_dir, "container_name": container_name, "loader": str(self.__class__.__name__), "representation": context["representation"]["_id"], "parent": context["representation"]["parent"], "family": context["representation"]["context"]["family"] } unreal_pipeline.imprint("{}/{}".format(asset_dir, container_name), data) asset_content = unreal.EditorAssetLibrary.list_assets( asset_dir, recursive=True, include_folder=True) return asset_content
def swap_to_published_model(*args): """Hide the working model and load the published version of it This is for the case that artist was working on model and lookDev all together, while publishing turntable require the model to be published version. Using this tool could load the latest version via the instance that was used to publish this model. """ MSG = "Please select '|ROOT' node, and '|ROOT' node only." selection = cmds.ls(selection=True, long=True, type="transform") assert len(selection) == 1, MSG root = selection[0] assert root.endswith("|ROOT"), MSG instances = lib.lsAttrs({ "id": "pyblish.avalon.instance", "family": "reveries.model" }) project = api.Session.get("AVALON_PROJECT") asset = None subset = None for set_ in cmds.listSets(object=root) or []: if set_ in instances: asset = cmds.getAttr(set_ + ".asset") subset = cmds.getAttr(set_ + ".subset") break assert project is not None, "Project undefined, this is not right." assert asset and subset, "Model instance not found." assert len(instances) == 1, "Too many model instances in scene." representation = io.locate([project, asset, subset, -1, "mayaBinary"]) Loaders = api.discover(api.Loader) Loader = next( (loader for loader in Loaders if loader.__name__ == "ModelLoader"), None) assert Loader is not None, "ModelLoader not found, this is a bug." assert representation is not None, "Representation not found." container = api.load(Loader, representation) group = pipeline.get_group_from_container(container["objectName"]) parent = cmds.listRelatives(root, parent=True) if parent: cmds.parent(group, parent) # Re-assign shaders nodes = cmds.listRelatives(root, allDescendents=True, fullPath=True) shader_by_id = lib.serialise_shaders(nodes) lib.apply_shaders(shader_by_id) # Hide unpublished model cmds.setAttr(root + ".visibility", False)
def _process(self, libpath, layout_container, container_name, representation, actions, parent): with open(libpath, "r") as fp: data = json.load(fp) scene = bpy.context.scene layout_collection = bpy.data.collections.new(container_name) scene.collection.children.link(layout_collection) all_loaders = api.discover(api.Loader) avalon_container = bpy.data.collections.get( blender.pipeline.AVALON_CONTAINERS) for element in data: reference = element.get('reference') family = element.get('family') loaders = api.loaders_from_representation(all_loaders, reference) loader = self._get_loader(loaders, family) if not loader: continue instance_name = element.get('instance_name') element_container = api.load(loader, reference, namespace=instance_name) if not element_container: continue avalon_container.children.unlink(element_container) layout_container.children.link(element_container) element_metadata = element_container.get( blender.pipeline.AVALON_PROPERTY) # Unlink the object's collection from the scene collection and # link it in the layout collection element_collection = element_metadata.get('obj_container') scene.collection.children.unlink(element_collection) layout_collection.children.link(element_collection) objects = element_metadata.get('objects') element_metadata['instance_name'] = instance_name objects_to_transform = [] creator_plugin = get_creator_by_name(self.animation_creator_name) if not creator_plugin: raise ValueError("Creator plugin \"{}\" was not found.".format( self.animation_creator_name)) if family == 'rig': for o in objects: if o.type == 'ARMATURE': objects_to_transform.append(o) # Create an animation subset for each rig o.select_set(True) asset = api.Session["AVALON_ASSET"] c = api.create(creator_plugin, name="animation_" + element_collection.name, asset=asset, options={"useSelection": True}, data={"dependencies": representation}) scene.collection.children.unlink(c) parent.children.link(c) o.select_set(False) break elif family == 'model': objects_to_transform = objects for o in objects_to_transform: self.set_transform(o, element.get('transform')) if actions: if o.type == 'ARMATURE': action = actions.get(instance_name, None) if action: if o.animation_data is None: o.animation_data_create() o.animation_data.action = action return layout_collection