Beispiel #1
0
def test_modeling_to_rigging():
    transform, generator = cmds.polyCube(name="body_PLY")
    group = cmds.group(transform, name="ROOT")

    cmds.select(group, replace=True)
    maya.create(name="modelDefault",
                asset=ASSET_NAME,
                family="mindbender.model",
                options={"useSelection": True})

    # Comply with save validator
    cmds.file(save=True)

    publish()

    cmds.file(new=True, force=True)

    representation = io.locate(
        [PROJECT_NAME, ASSET_NAME, "modelDefault", 1, "ma"])

    container = maya.load(representation)
    nodes = cmds.sets(container, query=True)
    assembly = cmds.ls(nodes, assemblies=True)[0]
    assert_equals(assembly, "Bruce_01_:modelDefault")

    # Rig it
    mesh = cmds.ls(nodes, type="mesh")
    transform = cmds.listRelatives(mesh, parent=True)[0]
    ctrl = cmds.circle(name="main_CTL")
    cmds.parentConstraint(ctrl, transform)

    cmds.select([assembly] + ctrl, replace=True)
    group = cmds.group(name="ROOT")

    cmds.select(mesh, replace=True)

    out_set = cmds.sets(name="out_SET")

    cmds.select(ctrl)
    controls_set = cmds.sets(name="controls_SET")

    cmds.select([group, out_set, controls_set], noExpand=True)
    maya.create(
        name="rigDefault",
        asset=os.environ["AVALON_ASSET"],
        family="mindbender.rig",
        options={"useSelection": True},
    )

    cmds.file(rename="temp.ma")
    cmds.file(save=True)

    publish()

    cmds.file(new=True, force=True)

    representation = io.locate(
        [PROJECT_NAME, ASSET_NAME, "rigDefault", 1, "ma"])

    container = maya.load(representation)
    nodes = cmds.sets(container, query=True)
    assembly = cmds.ls(nodes, assemblies=True)[0]
    assert_equals(assembly, "Bruce_01_:rigDefault")
Beispiel #2
0
def main():
    projects = []
    objects = []

    for project in gazu.project.all_projects():
        assets = gazu.asset.all_assets_for_project(project)
        shots = gazu.shot.all_shots_for_project(project)

        for assets, silo in ((assets, "assets"), (shots, "shots")):
            for asset in assets:
                objects.append({
                    "schema": "avalon-core:asset-2.0",
                    "name": asset["name"].replace(" ", ""),  # remove spaces
                    "silo": silo,
                    "data": {},
                    "type": "asset",
                    "parent": project["name"],
                })

        projects.append({
            "schema": "avalon-core:project-2.0",
            "type": "project",
            "name": project["name"],
            "data": {},
            "parent": None,
            "config": {
                "schema": "avalon-core:config-1.0",
                "apps": [
                    {
                        "name": "maya2015",
                        "label": "Autodesk Maya 2015"
                    },
                    {
                        "name": "maya2016",
                        "label": "Autodesk Maya 2016"
                    },
                    {
                        "name": "maya2017",
                        "label": "Autodesk Maya 2017"
                    },
                    {
                        "name": "nuke10",
                        "label": "The Foundry Nuke 10.0"
                    }
                ],
                "tasks": [
                    {"name": task["name"]}
                    for task in gazu.task.all_task_types()
                ],
                "template": {
                    "work":
                        "{root}/{project}/{silo}/{asset}/work/"
                        "{task}/{app}",
                    "publish":
                        "{root}/{project}/{silo}/{asset}/publish/"
                        "{subset}/v{version:0>3}/{subset}.{representation}"
                }
            }
        })

    print("Found:")
    print("- %d projects" % len(projects))
    print("- %d assets" % len(objects))

    os.environ["AVALON_PROJECTS"] = r""
    os.environ["AVALON_PROJECT"] = "temp"
    os.environ["AVALON_ASSET"] = "bruce"
    os.environ["AVALON_SILO"] = "assets"
    os.environ["AVALON_CONFIG"] = "polly"
    os.environ["AVALON_MONGO"] = "mongodb://192.168.99.100:27017"

    existing_projects = {}
    existing_assets = {}

    print("Fetching Avalon data..")
    avalon.install()
    for project in avalon.projects():
        existing_projects[project["name"]] = project

    for asset in avalon.find({"type": "asset"}):
        existing_assets[asset["name"]] = asset

    print("Synchronising..")
    for project in projects:
        if project["name"] in existing_projects:
            continue

        print("Installing project: %s" % project["name"])
        os.environ["AVALON_PROJECT"] = project["name"]
        avalon.uninstall()
        avalon.install()

        avalon.insert_one(project)

    for asset in objects:
        if asset["name"] in existing_assets:
            continue

        asset["parent"] = avalon.locate([asset["parent"]])
        print("Installing asset: %s" % asset["name"])
        avalon.insert_one(asset)

    print("Success")
Beispiel #3
0
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)
Beispiel #4
0
def main():
    projects = {}
    objects = {}
    objects_count = 0
    tasks = [{"name": task["name"]} for task in gazu.task.all_task_types()]

    for project in gazu.project.all_projects():
        # Ensure project["code"] consistency.
        project_name = get_consistent_name(project["name"])
        if project["code"] != project_name:
            proj = {}
            proj["code"] = project_name
            proj["id"] = project["id"]
            project = gazu.project.update_project(proj)
            print("Updating Project Code...")

        # Collect assets.
        assets = []
        for asset in gazu.asset.all_assets_for_project(project):
            # Faking a parent for better hierarchy structure, until folders are
            # supported in Kitsu.
            asset["parents"] = ["assets"]
            assets.append(asset)

        # Collect shots and parents.
        episodes = []
        sequences = []
        shots = []
        for episode in (gazu.shot.all_episodes_for_project(project) or []):
            episode["code"] = get_consistent_name(episode["name"])
            episode["parent"] = project
            # Faking a parent for better hierarchy structure, until folders are
            # supported in Kitsu.
            episode["parents"] = ["episodes"]
            episodes.append(episode)
            for sequence in gazu.shot.all_sequences_for_episode(episode):
                sequence["code"] = get_consistent_name(sequence["name"])
                sequence["parent"] = episode
                sequence["parents"] = episode["parents"] + [episode["code"]]
                sequence["label"] = sequence["name"]
                sequence["name"] = "{0}_{1}".format(
                    episode["code"], sequence["code"]
                )
                sequence["visualParent"] = episode["name"]
                sequences.append(sequence)
                for shot in gazu.shot.all_shots_for_sequence(sequence):
                    shot["code"] = get_consistent_name(shot["name"])
                    shot["parent"] = sequence
                    shot["parents"] = sequence["parents"] + [sequence["code"]]
                    shot["label"] = shot["name"]
                    shot["name"] = "{0}_{1}_{2}".format(
                        episode["code"], sequence["code"], shot["code"]
                    )
                    shot["visualParent"] = sequence["name"]
                    shot["tasks"] = gazu.task.all_tasks_for_shot(shot)
                    shots.append(shot)

        silos = [
            [assets, "assets"],
            [episodes, "shots"],
            [sequences, "shots"],
            [shots, "shots"]
        ]
        entities = {}
        for assets, silo in silos:
            for asset in assets:
                entity_type = gazu.entity.get_entity_type(
                    asset["entity_type_id"]
                )

                data = {
                    "schema": "avalon-core:asset-2.0",
                    "name": get_consistent_name(asset["name"]),
                    "silo": silo,
                    "type": "asset",
                    "parent": project["code"],
                    "data": {
                        "label": asset.get("label", asset["name"]),
                        "group": entity_type["name"],
                        "parents": asset["parents"]
                    }
                }

                if asset.get("visualParent"):
                    data["data"]["visualParent"] = asset["visualParent"]

                if asset.get("tasks"):
                    data["data"]["tasks"] = [
                        task["task_type_name"] for task in asset["tasks"]
                    ]

                entities[data["name"]] = data

                objects_count += 1

        objects[project["code"]] = entities

        projects[project["code"]] = {
            "schema": "avalon-core:project-2.0",
            "type": "project",
            "name": project["code"],
            "data": {
                "label": project["name"],
                "code": project["code"]
            },
            "parent": None,
            "config": {
                "schema": "avalon-core:config-1.0",
                "apps": [
                    {
                        "name": "maya2015",
                        "label": "Autodesk Maya 2015"
                    },
                    {
                        "name": "maya2016",
                        "label": "Autodesk Maya 2016"
                    },
                    {
                        "name": "maya2017",
                        "label": "Autodesk Maya 2017"
                    },
                    {
                        "name": "nuke10",
                        "label": "The Foundry Nuke 10.0"
                    }
                ],
                "tasks": tasks,
                "template": {
                    "work":
                        "{root}/{project}/{silo}/{asset}/work/"
                        "{task}/{app}",
                    "publish":
                        "{root}/{project}/{silo}/{asset}/publish/"
                        "{subset}/v{version:0>3}/{subset}.{representation}"
                }
            }
        }

    print("Found:")
    print("- %d projects" % len(projects))
    print("- %d assets" % objects_count)

    os.environ["AVALON_PROJECTS"] = r""
    os.environ["AVALON_PROJECT"] = "temp"
    os.environ["AVALON_ASSET"] = "bruce"
    os.environ["AVALON_SILO"] = "assets"
    os.environ["AVALON_CONFIG"] = "polly"
    os.environ["AVALON_MONGO"] = os.environ.get(
        "AVALON_MONGO", "mongodb://127.0.0.1:27017"
    )

    print("Fetching Avalon data..")
    avalon.install()

    existing_projects = {}
    existing_objects = {}

    for project in avalon.projects():
        existing_projects[project["name"]] = project

        # Update project
        os.environ["AVALON_PROJECT"] = project["name"]
        avalon.uninstall()
        avalon.install()

        # Collect assets
        assets = {}
        for asset in avalon.find({"type": "asset"}):
            assets[asset["name"]] = asset

        existing_objects[project["name"]] = assets

    print("Synchronising..")
    for name, project in projects.items():
        if project["name"] in existing_projects:
            # Update task types
            existing_project = existing_projects[project["name"]]
            existing_project_task_types = existing_project["config"]["tasks"]
            if existing_project_task_types != tasks:
                print(
                    "Updating tasks types on \"{0}\" to:\n{1}".format(
                        project["name"], tasks
                    )
                )
                existing_project["config"]["tasks"] = tasks
                os.environ["AVALON_PROJECT"] = project["name"]
                avalon.uninstall()
                avalon.install()
                avalon.replace_one({"type": "project"}, existing_project)

            continue

        print("Installing project: %s" % project["name"])
        os.environ["AVALON_PROJECT"] = project["name"]
        avalon.uninstall()
        avalon.install()

        avalon.insert_one(project)

    for project["code"], assets in objects.items():
        os.environ["AVALON_PROJECT"] = project["code"]
        avalon.uninstall()
        avalon.install()

        for asset_name, asset in assets.items():
            if asset_name in existing_objects.get(project["code"], {}):
                # Update tasks
                if asset["data"].get("tasks"):
                    existing_project = existing_objects[project["code"]]
                    existing_asset = existing_project[asset_name]
                    existing_tasks = existing_asset["data"].get("tasks", [])
                    if existing_tasks != asset["data"]["tasks"]:
                        tasks = asset["data"]["tasks"]
                        print(
                            "Updating tasks on \"{0} / {1}\" to:\n{2}".format(
                                project["code"], asset_name, tasks
                            )
                        )
                        existing_asset["data"]["tasks"] = tasks
                        avalon.replace_one(
                            {"type": "asset", "name": asset_name},
                            existing_asset
                        )

                continue

            asset["parent"] = avalon.locate([asset["parent"]])

            if asset["data"].get("visualParent"):
                asset["data"]["visualParent"] = avalon.find_one(
                    {"type": "asset", "name": asset["data"]["visualParent"]}
                )["_id"]
            print(
                "Installing asset: \"{0} / {1}\"".format(
                    project["code"], asset_name
                )
            )
            avalon.insert_one(asset)

    print("Success")