예제 #1
0
def test_alembic_export():
    """Exporting Alembic works"""

    cube, generator = cmds.polyCube(name="myCube_GEO")
    transform = cmds.ls(selection=True)

    visibility_keys = [(10, True), (20, False), (30, True)]

    for time, value in visibility_keys:
        cmds.setKeyframe(transform,
                         time=time,
                         attribute="visibility",
                         value=value)

    maya.create(name="animationDefault",
                asset=ASSET_NAME,
                family="mindbender.animation",
                options={"useSelection": True})

    cmds.file(save=True)

    publish()

    # Import and test result
    cmds.file(new=True, force=True)

    asset = io.find_one({"type": "asset", "name": ASSET_NAME})

    subset = io.find_one({
        "parent": asset["_id"],
        "type": "subset",
        "name": "animationDefault"
    })

    version = io.find_one({
        "parent": subset["_id"],
        "type": "version",
        "name": 1
    })

    assert version

    representation = io.find_one({
        "parent": version["_id"],
        "type": "representation",
        "name": "abc"
    })

    assert representation is not None

    container = maya.load(representation)
    nodes = cmds.sets(container, query=True)
    print("Nodes: %s" % nodes)
    cube = cmds.ls(nodes, type="mesh")
    transform = cmds.listRelatives(cube, parent=True)[0]

    for time, value in visibility_keys:
        cmds.currentTime(time, edit=True)
        assert cmds.getAttr(transform + ".visibility") == value, (
            "Cached visibility did not match original visibility")
예제 #2
0
    def refresh(self, *args):
        self.pools.blockSignals(True)
        self.groups.blockSignals(True)
        self.pools.clear()
        self.groups.clear()
        self.pools.blockSignals(False)
        self.groups.blockSignals(False)

        exists = maya.lsattr("id", "avalon.renderglobals")
        assert len(exists) <= 1, (
            "More than one renderglobal exists, this is a bug")

        if exists:
            render_globals = exists[0]
        else:
            render_globals = maya.create(
                "renderGlobals",
                api.Session["AVALON_ASSET"],
                "mindbender.renderglobals"
            )

        # Store reference for editing
        self.render_globals = render_globals

        render_globals = maya.read(render_globals)
        current_pool = render_globals["pool"] or "none"
        current_group = render_globals["group"] or "none"

        url = api.Session["AVALON_DEADLINE"] + "/api/pools"
        module.log.debug("Requesting pools from %s.." % url)
        response = requests.get(url)
        pools = response.json()

        url = api.Session["AVALON_DEADLINE"] + "/api/groups"
        module.log.debug("Requesting groups from %s.." % url)
        response = requests.get(url)
        groups = response.json()

        valid_pool = False
        for index, pool in enumerate(pools):
            self.pools.insertItem(index, pool)

            if pool == current_pool:
                self.pools.setCurrentIndex(index)
                valid_pool = True

        valid_group = False
        for index, group in enumerate(groups):
            self.groups.insertItem(index, group)

            if group == current_group:
                self.groups.setCurrentIndex(index)
                valid_group = True

        if not valid_pool:
            cmds.warning("%s is not a valid pool" % current_pool)

        if not valid_group:
            cmds.warning("%s is not a valid pool" % current_group)
예제 #3
0
def test_update():
    """Updating works"""

    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()
    publish()
    publish()  # Version 3

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

    asset = io.find_one({"type": "asset", "name": ASSET_NAME})

    subset = io.find_one({
        "parent": asset["_id"],
        "type": "subset",
        "name": "modelDefault"
    })

    version = io.find_one({
        "parent": subset["_id"],
        "type": "version",
        "name": 2
    })

    assert version

    representation = io.find_one({
        "parent": version["_id"],
        "type": "representation",
        "name": "ma"
    })

    maya.load(representation["_id"])
    container = next(maya.ls())
    maya.update(container, 3)
예제 #4
0
    def _post_process(self, name, namespace, context, data):
        import os
        from maya import cmds
        from avalon import maya, io

        # Task-dependent post-process
        if os.getenv("AVALON_TASK") != "animate":
            return self.log.info(
                "No animation instance created due to task != animate")

        # Find associated rig to these curves
        try:
            dependency = context["representation"]["dependencies"][0]
        except (KeyError, IndexError):
            return self.log.warning("No dependencies found for %s" % name)

        dependency = io.find_one({"_id": io.ObjectId(dependency)})
        _, _, dependency, _ = io.parenthood(dependency)

        # TODO(marcus): We are hardcoding the name "out_SET" here.
        #   Better register this keyword, so that it can be used
        #   elsewhere, such as in the Integrator plug-in,
        #   without duplication.
        output = next((node for node in self if node.endswith("out_SET")),
                      None)
        controls = next(
            (node for node in self if node.endswith("controls_SET")), None)

        assert output, "No out_SET in rig, this is a bug."
        assert controls, "No controls_SET in rig, this is a bug."

        with maya.maintained_selection():
            cmds.select([output, controls], noExpand=True)

            dependencies = [context["representation"]["_id"]]
            name = "anim" + dependency["name"].title() + "_"

            # TODO(marcus): Hardcoding the family here, better separate this.
            maya.create(
                name=maya.unique_name(name, suffix="_SET"),
                family="ava.animation",
                options={"useSelection": True},
                data={"dependencies": " ".join(str(d) for d in dependencies)})
예제 #5
0
def test_modeling():
    """Modeling workflow is functional"""
    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()

    asset = io.find_one({"type": "asset", "name": ASSET_NAME})

    assert asset

    subset = io.find_one({
        "parent": asset["_id"],
        "type": "subset",
        "name": "modelDefault"
    })

    assert subset

    version = io.find_one({
        "parent": subset["_id"],
        "type": "version",
    })

    assert version

    assert io.find_one({
        "parent": version["_id"],
        "type": "representation",
        "name": "ma"
    }) is not None
예제 #6
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")