Exemple #1
0
    def test_issue_349(self):
        test_file = os.path.join(TEMPDIR, "cask_test_issue_349.abc")

        # create a new archive and some objects
        a = cask.Archive()
        xf = a.top.children["renderCamXform"] = cask.Xform()
        cam = xf.children["renderCamShape"] = cask.Camera()

        # add some sample data
        for i in range(24):
            samp = alembic.AbcGeom.XformSample()
            samp.setTranslation(imath.V3d(i, 2.0, 3.0))
            xf.set_sample(samp)

        # export it
        a.write_to_file(test_file)
        a.close()

        # read the test archive back in and verify results
        a = cask.Archive(test_file)
        xform = a.top.children["renderCamXform"]
        self.assertEqual(len(a.timesamplings), 2)
        self.assertEqual(xform.time_sampling_id, 1)
        self.assertEqual(len(xform.samples), 24)
        self.assertEqual(a.start_frame(), 0)
        self.assertEqual(a.end_frame(), 23)
Exemple #2
0
 def test_equivalency(self):
     # test empty archive equivalency
     a = cask.Archive()
     b = a
     self.assertEqual(a, b)
     self.assertEqual(a.top.parent, a)
     self.assertEqual(a.top.archive(), a)
     
     # reassign 'b' to a new empty archive
     b = cask.Archive()
     self.assertNotEqual(a, b)
Exemple #3
0
    def test_child_bounds(self):
        filename_1 = os.path.join(TEMPDIR, "cask_child_bounds_1.abc")
        filename_2 = os.path.join(TEMPDIR, "cask_child_bounds_2.abc")
        filename_3 = os.path.join(TEMPDIR, "cask_child_bounds_3.abc")

        # create initial archive with initial value
        bounds = imath.Box3d(
            imath.V3d(1, 1, 1), imath.V3d(1, 1, 1)
        )
        a = cask.Archive()
        x = a.top.children["foo"] = cask.Xform()
        p = x.properties[".xform/.childBnds"] = cask.Property()
        p.set_value(bounds)
        self.assertEqual(p.values[0], bounds)
        a.write_to_file(filename_1)
        a.close()

        # verify export / value
        b = cask.Archive(filename_1)
        p = b.top.children["foo"].properties[".xform/.childBnds"]
        self.assertEqual(len(p.values), 1)
        self.assertEqual(p.values[0], bounds)
        self.assertEqual(p.metadata.get("interpretation"), "box")
        
        # set a new child bounds value and export
        bounds = imath.Box3d(
            imath.V3d(-5, -5, -5), imath.V3d(5, 5, 5)
        )
        p.values[0] = bounds
        self.assertEqual(p.values[0], bounds)
        b.write_to_file(filename_2)
        b.close()

        # verify the updated value in the export
        c = cask.Archive(filename_2)
        p = c.top.children["foo"].properties[".xform/.childBnds"]
        self.assertEqual(len(p.values), 1)
        self.assertEqual(p.values[0], bounds)
        self.assertEqual(p.metadata.get("interpretation"), "box")

        # reinitialize the property and export
        p = c.top.children["foo"].properties[".xform/.childBnds"] = cask.Property()
        p.set_value(bounds)
        c.write_to_file(filename_3)
        c.close()

        # re-verify the updated value in the export
        d = cask.Archive(filename_3)
        p = d.top.children["foo"].properties[".xform/.childBnds"]
        self.assertEqual(len(p.values), 1)
        self.assertEqual(p.values[0], bounds)
        self.assertEqual(p.metadata.get("interpretation"), "box")
Exemple #4
0
    def test_add_child(self):
        """Creates a simple cache with one mesh, then moves and copies it. 
        Resulting abc cache should look like this:

        ABC                                                                                                                                        
         |--x1
         |--x2
         |    `--meshy
         `--x3
             `--meshy
        """
        filename = os.path.join(TEMPDIR, "cask_add_child.abc")
        
        a = cask.Archive(mesh_out())
        meshy = a.top.children["meshy"]
        x1 = a.top.children["x1"] = cask.Xform()
        x2 = a.top.children["x2"] = cask.Xform()
        x3 = a.top.children["x3"] = cask.Xform()

        # test moving it and copying it
        x1.add_child(meshy)
        x2.add_child(meshy)
        x3.add_child(cask.copy(meshy))

        # export to a new filename
        a.write_to_file(filename)
        a.close()

        # test the new file
        a = cask.Archive(filename)
        self.assertEqual(set(a.top.children.keys()), set(["x1", "x2", "x3"]))
        
        x1 = a.top.children["x1"]
        x2 = a.top.children["x2"]
        x3 = a.top.children["x3"]
        
        # meshy should have been moved from x1->x2, and copied to x3
        self.assertEqual(len(x1.children), 0)
        self.assertEqual(len(x2.children), 1)
        self.assertEqual(len(x3.children), 1)

        m2 = x2.children["meshy"]
        m3 = x3.children["meshy"]

        # basic check to see if mesh points are the same
        self.assertEqual(m2.type(), "PolyMesh")
        self.assertEqual(m3.type(), "PolyMesh")
        self.assertEqual(m2.properties[".geom/P"].values,
                m3.properties[".geom/P"].values)
        a.close()
Exemple #5
0
    def test_issue_23(self):
        """github issue #23: preserve user properties"""

        test_file = os.path.join(TEMPDIR, "cask_test_issue_23.abc")
        test_file_2 = os.path.join(TEMPDIR, "cask_test_issue_23_2.abc")

        a = cask.Archive()
        x = a.top.children["x"] = cask.Xform()
        x.properties[".xform"] = cask.Property()

        # create the .userProperties compound prop
        up = x.properties[".xform"].properties[".userProperties"] = cask.Property()
        
        # create some user properties
        p1 = up.properties["foo"] = cask.Property()
        p1.set_value("bar")
        p2 = up.properties["bar"] = cask.Property()
        p2.set_value(1.0)

        # export it
        a.write_to_file(test_file)
        a.close()

        # read it back in and check for the user properties
        a = cask.Archive(test_file)
        x = a.top.children["x"]
        self.assertEqual(x.properties.keys(), [".xform"])
        self.assertEqual(x.properties[".xform"].properties.keys(), 
            [".userProperties"])
        up = x.properties[".xform/.userProperties"]

        # assert the values are the same
        self.assertEqual(len(up.properties), 2)
        self.assertEqual(up.properties["foo"].values[0], "bar")
        self.assertEqual(up.properties["bar"].values[0], 1.0)

        # use the alembic python api directly
        ph = a.top.children["x"].schema.getUserProperties().propertyheaders
        self.assertEqual(len(ph), 2)
        self.assertEqual(ph[0].getName(), "foo")
        self.assertEqual(ph[1].getName(), "bar")

        # recreate these properties and re-export
        # (test for AttributeError: 'OObject' object has no attribute 'getSchema')
        p1 = up.properties["foo"] = cask.Property()
        p2 = up.properties["bar"] = cask.Property()
        p1.set_value("baz")
        p2.set_value(2.0)
        a.write_to_file(test_file_2)
Exemple #6
0
    def test_find(self):
        filename = os.path.join(TEMPDIR, "cask_write_mesh.abc")
        a = cask.Archive(filename)
        
        r = cask.find(a.top, name="meshy")
        self.assertEqual(len(r), 1)
        self.assertEqual(r[0].name, "meshy")
        self.assertEqual(r[0].type(), "PolyMesh")

        r = cask.find(a.top, name=".*hy")
        self.assertEqual(len(r), 1)
        self.assertEqual(r[0].name, "meshy")
        self.assertEqual(r[0].type(), "PolyMesh")

        r = cask.find(a.top, types=["PolyMesh"])
        self.assertEqual(len(r), 1)
        self.assertEqual(r[0].name, "meshy")
        self.assertEqual(r[0].type(), "PolyMesh")

        a.close()

        filename = os.path.join(TEMPDIR, "cask_deep_dict.abc")
        a = cask.Archive(filename)

        r = cask.find(a.top, types=["Xform"])
        self.assertEqual(len(r), 15)

        r = cask.find(a.top, types=["Light"])
        self.assertEqual(len(r), 0)

        r = cask.find(a.top, name="J")
        self.assertEqual(len(r), 1)

        r = cask.find(a.top, name="D")
        self.assertEqual(len(r), 2)
        self.assertEqual(r[0].name, "D")
        self.assertEqual(r[0].type(), "Xform")

        r = cask.find(a.top, name="nurby")
        self.assertEqual(len(r), 1)
        self.assertEqual(r[0].name, "nurby")
        self.assertEqual(r[0].type(), "NuPatch")

        r = cask.find(a.top, types=["NuPatch"])
        self.assertEqual(len(r), 1)
        self.assertEqual(r[0].name, "nurby")
        self.assertEqual(r[0].type(), "NuPatch")
        
        a.close()
Exemple #7
0
    def test_extract_light(self):
        filename = os.path.join(TEMPDIR, "cask_exract_light.abc")

        # open light archive and create new empty archive
        a = cask.Archive(lights_out())
        b = cask.Archive()

        # find a light and assign it to b's hierarchy
        results = cask.find(a.top, "lightB")
        self.assertEqual(len(results), 1)
        b.top.children["lightB"] = results[0]

        # write new archive to disk
        b.write_to_file(filename)
        self.assertTrue(os.path.isfile(filename))
Exemple #8
0
    def test_verify_copy_mesh(self):
        filename = os.path.join(TEMPDIR, "cask_copy_mesh.abc")
        self.assertTrue(cask.is_valid(filename))

        # open the archive
        a = cask.Archive(filename)
        p = a.top.children.values()[0]

        # verify timesamplings were copied
        self.assertEqual(len(a.timesamplings), 1)

        # verify the hierarchy
        self.assertEqual(p.name, "meshy")

        # check the global matrix of the polymesh object
        self.assertEqual(
            p.global_matrix(),
            imath.M44d((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)))

        geom = p.properties[".geom"]
        self.assertEqual(len(geom.properties[".faceCounts"].values), 10)
        self.assertEqual(geom.properties[".faceCounts"].values[0][0], 4)
        self.assertEqual(geom.properties["P"].values[0][0],
                         imath.V3f(-1, -1, -1))
        self.assertEqual(geom.properties["N"].values[0][0],
                         imath.V3f(-1, 0, 0))
Exemple #9
0
    def test_new_property(self):
        filename = os.path.join(TEMPDIR, "cask_new_property.abc")

        # create a new property
        a = cask.Archive(mesh_out())
        t = a.top

        # create simple property
        f = t.properties["foo"] = cask.Property()
        self.assertEqual(f.name, "foo")
        self.assertEqual(f, t.properties["foo"])
        self.assertEqual(f.parent, t)
        self.assertEqual(f.object(), t)

        # create new object
        l = t.children["spot"] = cask.Light()
        self.assertEqual(a.top.children["spot"], l)
        self.assertEqual(l.name, "spot")
        self.assertEqual(t.children["spot"].name, "spot")
        self.assertEqual(l.parent, t)
        self.assertEqual(l.children, {})

        # change name in place
        t.children["spot"].name = "point"
        self.assertEqual(l.name, "point")

        a.write_to_file(filename)
Exemple #10
0
    def _rename_abc_top_group(self, publish_path_temp, publish_path, rename_to):
        """
        This function renames the "top" group of the alembic heirarchy.

        :param string publish_path: Path of the alembic file to be modified.
        :param string rename_to: The new name that you would want to assign to the top group.
        """
        if not os.path.exists(publish_path_temp):
            self.logger.error("Invalid Alembic path : {0}. Not renaming the top group.".format(
                publish_path_temp))
            return

        # Loading the alembic archive
        abc_archive = cask.Archive(publish_path_temp)

        try:
            abc_archive.top.children.values()[0].name = rename_to
            abc_archive.write_to_file(publish_path, asOgawa=True)
        except Exception as err:
            import traceback
            self.logger.error(
                "Unhandled exceptions encountered.",
                extra={
                    "action_show_more_info": {
                        "label": "Show Traceback",
                        "tooltip": "Show complete traceback",
                        "text": traceback.format_exc()
                    }
                })

            raise err
        finally:
            abc_archive.close()
Exemple #11
0
    def test_rename(self):
        filename = os.path.join(TEMPDIR, "cask_test_rename.abc")

        a = cask.Archive()
        t = a.top

        # create a new object and property
        t.children["foo"] = cask.Xform()
        t.properties["some"] = cask.Property()
        f = t.children.values()[0]
        p = t.properties.values()[0]
        self.assertEqual(f.name, "foo")
        self.assertEqual(p.name, "some")

        # rename them
        f.name = "bar"
        self.assertEqual(f.name, "bar")
        self.assertEqual(t.children.values()[0].name, "bar")
        p.name = "thing"
        self.assertEqual(p.name, "thing")
        self.assertEqual(t.properties.values()[0].name, "thing")

        # test for accessor updates
        self.assertEqual(t.children["bar"], f)
        self.assertRaises(KeyError, t.children.__getitem__, "foo")
        self.assertEqual(t.properties["thing"], p)
        self.assertRaises(KeyError, t.properties.__getitem__, "some")

        # write to a file
        a.write_to_file(filename)
Exemple #12
0
    def test_deep_dict(self):
        filename = os.path.join(TEMPDIR, "cask_deep_dict.abc")

        # read in a simple scene with several shapes
        a = cask.Archive(deep_out())
        t = a.top

        # deep dict access
        self.assertEqual(t.children["A"].name, "A")
        self.assertEqual(t.children["A/B/C/D"].name, "D")
        self.assertEqual(t.children["A"].properties["a"].name, "a")
        self.assertEqual(t.children["A/B/C/D"].properties["a/b/c"].name, "c")
        self.assertRaises(KeyError, t.children.__getitem__, "A/B/C/Z")

        # property accessors
        x = t.children.values()[0]
        self.assertEqual(x.name, "A")
        self.assertEqual(x.properties["a/b/c/myprop"].values[0], "foo")

        # test deep set item on leaf node
        p = t.children["A/B/C/D/meshy"] = cask.PolyMesh()
        self.assertEqual(p.name, "meshy")
        self.assertEqual(p.type(), "PolyMesh")
        self.assertEqual(p.parent, t.children["A/B/C/D"])
        self.assertTrue("meshy" in t.children["A/B/C/D"].children.keys())
        self.assertEqual(len(p.children.keys()), 0)

        # another test
        patch = cask.NuPatch()
        t.children["A/B/C/D/patch"] = patch
        self.assertEqual(patch.name, "patch")
        self.assertEqual(patch.parent, t.children["A/B/C/D"])
        self.assertTrue("patch" in t.children["A/B/C/D"].children.keys())
        self.assertFalse("patch" in t.children.keys())
        self.assertEqual(len(patch.children.keys()), 0)

        # rename test
        patch.name = "nurby"
        self.assertFalse("patch" in t.children["A/B/C/D"].children.keys())
        self.assertTrue("nurby" in t.children["A/B/C/D"].children.keys())
        self.assertEqual(patch.parent, t.children["A/B/C/D"])
        self.assertEqual(t.children["A/B/C/D/nurby"], patch)
        self.assertRaises(KeyError, t.children.__getitem__, "A/B/C/D/patch")

        # test deep dict reassignment
        t.children["A/B/C/D/meshy"] = cask.Xform()
        p2 = t.children["A/B/C/D/meshy"]
        self.assertEqual(p2.name, "meshy")
        self.assertEqual(p2.parent, t.children["A/B/C/D"])
        self.assertFalse(p2.name in t.children.keys())
        self.assertEqual(len(p2.children.values()), 0)
        self.assertEqual(t.children["A/B/C/D/meshy"].type(), "Xform")
        self.assertEqual(p2.type(), "Xform")

        # test deep set item when middle node does not exist
        self.assertRaises(KeyError, t.children.__setitem__, "A/foo/C/D/bar",
                          cask.Xform())

        # write the archive
        a.write_to_file(filename)
Exemple #13
0
    def test_copy_mesh(self):
        filename = os.path.join(TEMPDIR, "cask_copy_mesh.abc")

        # walks hierarchy and dupes each object and property as-is
        a = cask.Archive(mesh_out())
        a.write_to_file(filename)
        self.assertTrue(os.path.isfile(filename))
Exemple #14
0
    def test_light_shader(self):
        filename = os.path.join(TEMPDIR, "cask_light_shader.abc")

        a = cask.Archive()

        # create light and material
        light = a.top.children["spotlight"] = cask.Light()
        mat = light.properties[".materials"] = cask.Property()

        # set shader name
        names = mat.properties[".shaderNames"] = cask.Property()
        names.set_value(["prman.light", "spot_lgt"])

        # set shader values
        shader = mat.properties["prman.light.params"] = cask.Property()
        p1 = shader.properties["exposure"] = cask.Property()
        p1.set_value(1.0)
        p2 = shader.properties["specular"] = cask.Property()
        p2.set_value(0.1)
        p3 = shader.properties["color"] = cask.Property()
        p3.set_value(imath.Color3f(0.1, 0.2, 0.3))
        p3.metadata["interpretation"] = "rgb"

        # set light camera data
        samp = alembic.AbcGeom.CameraSample(-0.35, 0.75, 0.1, 0.5)
        light.set_sample(samp)
        samp.setNearClippingPlane(0.0)
        samp.setFarClippingPlane(1000.0)
        samp.setHorizontalAperture(2.8)
        samp.setVerticalAperture(2.8)
        samp.setFocalLength(50)
        light.set_sample(samp)

        # export
        a.write_to_file(filename)
Exemple #15
0
    def test_write_mesh(self):
        filename = os.path.join(TEMPDIR, "cask_write_mesh.abc")
        
        # create empty archive, xform and polymesh
        a = cask.Archive()
        x = cask.Xform()
        p = cask.PolyMesh()

        # hierarchy assignment
        a.top.children["foo"] = x
        x.children["meshy"] = p

        # set sample values using wrapped sample methods
        x.set_scale(imath.V3d(1, 2, 3))

        # create alembic polymesh sample and set it on our polymesh
        uvsamp = alembic.AbcGeom.OV2fGeomParamSample(meshData.uvs, kFacevaryingScope) 
        nsamp = alembic.AbcGeom.ON3fGeomParamSample(meshData.normals, kFacevaryingScope)
        s = alembic.AbcGeom.OPolyMeshSchemaSample(meshData.verts, meshData.indices, 
                meshData.counts, uvsamp, nsamp)
        p.set_sample(s)

        # write to disk
        a.write_to_file(filename)
        self.assertTrue(os.path.isfile(filename))
Exemple #16
0
def namespace_from_abc(abc):
    archive = cask.Archive(abc)

    for child in archive.top.children.values():
        if ':' in child.name:
            namespace = (child.name).split(':')[0]
            return namespace
Exemple #17
0
    def test_verify_frame_range(self):
        filename = os.path.join(TEMPDIR, "cask_frame_range.abc")
        self.assertTrue(cask.is_valid(filename))

        a = cask.Archive(filename)

        # verify the frame range
        self.assertEqual(a.start_time(), 1001 / float(a.fps))
        self.assertEqual(a.start_frame(), 1001)
        self.assertEqual(a.end_frame(), 1024)
Exemple #18
0
    def test_reassign(self):
        filename = os.path.join(TEMPDIR, "cask_test_reassign.abc")

        a = cask.Archive()
        t = a.top
        t.children["xform"] = cask.Xform()
        t.properties["prop"] = cask.Property()
        self.assertEqual(t.children["xform"].type(), "Xform")
        self.assertEqual(t.properties["prop"].type(), "Property")

        # reassign object
        t.children["xform"] = cask.PolyMesh()
        self.assertEqual(t.children["xform"].type(), "PolyMesh")

        # rename object
        x = t.children["xform"]
        x.name = "meshy"
        self.assertRaises(KeyError, t.children.__getitem__, "xform")
        self.assertTrue("meshy" in t.children.keys())
        self.assertEqual(t.children["meshy"], x)

        # rename property
        p = t.properties["prop"]
        p.name = "new"
        self.assertRaises(KeyError, t.properties.__getitem__, "prop")
        self.assertEqual(t.properties.values()[0].name, "new")
        self.assertEqual(t.properties["new"], p)

        # another rename test
        x = cask.Xform()
        t.children["foo"] = x
        self.assertTrue("foo" in t.children.keys())
        self.assertEqual(x.path(), "/foo")
        x.name = "bar"
        self.assertEqual(x.path(), "/bar")
        self.assertFalse("foo" in t.children.keys())
        self.assertTrue("bar" in t.children.keys())
        self.assertEqual(x.archive(), a)

        # child of child rename/reassign test
        baz = x.children["baz"] = cask.Xform()
        self.assertEqual(baz.path(), "/bar/baz")
        baz.name = "zap"
        self.assertFalse("zap" in t.children.keys())
        self.assertEqual(baz.path(), "/bar/zap")
        self.assertTrue("zap" in x.children.keys())
        self.assertEqual(baz.type(), "Xform")

        # reassign child obj to PolyMesh
        x.children["zap"] = cask.PolyMesh()
        self.assertEqual(x.children["zap"].type(), "PolyMesh")

        # write to a file
        a.write_to_file(filename)
Exemple #19
0
def fix_abc_deformed(abc_path):
    tmp_file = tempfile.mktemp()
    logger.debug(tmp_file)
    shutil.copy2(abc_path, tmp_file)
    # parse abc
    abc_archive = cask.Archive(tmp_file)
    walk(abc_archive.top)
    abc_archive.write_to_file(abc_path)
    # delete temp file
    try:
        os.remove(tmp_file)
    except:pass
Exemple #20
0
    def test_verify_write_basic(self):
        filename = os.path.join(TEMPDIR, "cask_write_basic.abc")
        self.assertTrue(cask.is_valid(filename))
        
        a = cask.Archive(filename)
        self.assertEqual(len(a.top.children), 1)
        self.assertEqual(a.top.children.values()[0].name, "foo")
        self.assertEqual(type(a.top.children.values()[0]), cask.Xform)
        self.assertEqual(len(a.top.children.values()[0].properties), 3)

        self.assertEqual(a.top.children.values()[0].properties["bar"].get_value(), "hello")
        self.assertEqual(a.top.children.values()[0].properties["baz"].get_value(), 42.0)
Exemple #21
0
def import_xforms(abcfile, transform_names, parent_under, update):
    """
    Imports and optionally, updates transforms from an alembic file.

    Params:
        abcfile : (str) the filepath of the alembic file
        transform_names : (list) a list of transform names to import / update
        parent_under : (str) the dag path to alembicHolder
        update : (bool) update previously imported transforms
    """
    archive = cask.Archive(abcfile)
    update_data = []

    for tr in transform_names:

        data = {}
        data['transform'] = tr
        data['dag_path'] = get_future_dag_path(tr, parent_under, archive)
        data['exists'] = cmds.objExists(data['dag_path'])

        if not data['exists']:
            update_data.append(data)
        elif data['exists'] and update:
            update_data.append(data)

    if get_previously_imported_transforms(abcfile, parent_under) == []:

        # this doesnt use the -ct and -crt flags, which will cause the import to fail if root nodes are not present
        if update and update_data != []:
            cmd = 'AbcImport "%s" -d -rpr "%s" -ft "%s" -eft "Shape"' % (
                abcfile, parent_under, ' '.join(
                    [i['transform'] for i in update_data]))

            try:
                mel.eval(cmd)
                MGlobal.displayInfo(cmd)
            except Exception as e:
                message = "Error running import transforms : %s" % e
                MGlobal.displayError(message)
        return

    # conntect type AbcImport
    if update and update_data != []:
        cmd = 'AbcImport "%s" -d -rpr "%s" -ft "%s" -ct "%s" -crt -eft "Shape"' % (
            abcfile, parent_under, ' '.join(
                [i['transform'] for i in update_data]), parent_under)

        try:
            mel.eval(cmd)
            MGlobal.displayInfo(cmd)
        except Exception as e:
            message = "Error running import transforms : %s" % e
            MGlobal.displayError(message)
Exemple #22
0
    def test_verify_selective_update(self):
        filename = os.path.join(TEMPDIR, "cask_selective_update.abc")
        self.assertTrue(cask.is_valid(filename))

        # verify our name change
        a = cask.Archive(filename)
        self.assertTrue("lightC" in a.top.children.keys())
        l = a.top.children["lightC"]

        # verify our translate update
        p = l.properties["shader/prman.light.params/exposure"]
        self.assertAlmostEqual(p.values[0], 1.0)
        self.assertAlmostEqual(p.values[5], 0.5)
Exemple #23
0
    def test_issue_26(self):
        """github issue #26: verify .ops and .vals pod and extent"""
        
        test_file_1 = os.path.join(TEMPDIR, "cask_test_issue_26.abc")

        # create some scalar properties with array values
        a = cask.Archive()
        a.top.children["foo"] = cask.Xform()
        p1 = a.top.children["foo"].properties["p1"] = cask.Property()
        p2 = a.top.children["foo"].properties["p2"] = cask.Property()
        p1.set_value(imath.UnsignedCharArray(6))
        p2.set_value(imath.DoubleArray(12))
        a.write_to_file(test_file_1)
        a.close()

        # open the exported file and assert properties are scalar
        a = cask.Archive(test_file_1)
        p1 = a.top.children["foo"].properties["p1"]
        p2 = a.top.children["foo"].properties["p2"]
        self.assertTrue(p1.iobject.isScalar())
        self.assertTrue(p2.iobject.isScalar())
        a.close()
Exemple #24
0
    def test_issue_346(self):
        """google code issue #346"""

        filename_1 = "cask_test_issue_346_1.abc"
        filename_2 = "cask_test_issue_346_2.abc"

        # create a test file with 1 time sampling object
        test_file_1 = mesh_out(filename_1)
        test_file_2 = os.path.join(TEMPDIR, filename_2)

        a = cask.Archive(test_file_1)
        a.write_to_file(test_file_2)
        b = cask.Archive(test_file_2)

        # compare test1 and test2
        self.assertEqual(len(a.timesamplings), len(b.timesamplings))
        self.assertEqual(a.time_range(), b.time_range())
        tst_1 = a.timesamplings[0].getTimeSamplingType()
        tst_2 = b.timesamplings[0].getTimeSamplingType()
        self.assertEqual(str(tst_1), str(tst_2))

        filename_3 = "cask_test_issue_346_3.abc"
        filename_4 = "cask_test_issue_346_4.abc"

        # create another test with 2 time sampling objects
        test_file_3 = cube_out(filename_3)
        test_file_4 = os.path.join(TEMPDIR, filename_4)

        c = cask.Archive(test_file_3)
        c.write_to_file(test_file_4)
        d = cask.Archive(test_file_4)

        # compare test3 and test4
        self.assertEqual(len(c.timesamplings), len(d.timesamplings))
        self.assertEqual(c.time_range(), d.time_range())
        tst_3 = c.timesamplings[0].getTimeSamplingType()
        tst_4 = d.timesamplings[0].getTimeSamplingType()
        self.assertEqual(str(tst_3), str(tst_4))
Exemple #25
0
    def test_verify_deep_dict(self):
        filename = os.path.join(TEMPDIR, "cask_deep_dict.abc")
        self.assertTrue(cask.is_valid(filename))

        # get some objects
        a = cask.Archive(filename)
        t = a.top
        d = t.children["A/B/C/D"]

        # verify writes
        self.assertTrue("meshy" in d.children.keys())
        self.assertTrue("nurby" in d.children.keys())
        self.assertEqual(type(d.children["meshy"]), cask.Xform)
        self.assertEqual(type(d.children["nurby"]), cask.NuPatch)
Exemple #26
0
    def test_paths(self):
        filepath = lights_out()
        a = cask.Archive(filepath)
        t = a.top
    
        # get some objects to test
        lightA = t.children["lightA"]
        lightB = t.children["lightB"]
        
        # test paths on objects
        self.assertEqual(a.path(), filepath)
        self.assertEqual(t.path(), "/")
        self.assertEqual(lightA.path(), "/lightA")
        self.assertEqual(lightB.path(), "/lightB")
        self.assertEqual(t.children[lightA.path()], lightA)

        # test paths on properties
        self.assertEqual(lightB.properties[".geom/.camera/.core"].path(), 
                            "/lightB/.geom/.camera/.core")

        # test paths on empty archive
        a = cask.Archive()
        t = a.top
        x = t.children["x"] = cask.Xform()
        y = x.children["y"] = cask.Xform()
        z = y.children["z"] = cask.Xform()
        p = z.properties["p"] = cask.Property()
        self.assertEqual(a.path(), None)
        self.assertEqual(t.path(), "/")
        self.assertEqual(x.path(), "/x")
        self.assertEqual(y.path(), "/x/y")
        self.assertEqual(z.path(), "/x/y/z")
        self.assertEqual(p.path(), "/x/y/z/p")

        # test reparenting
        p.parent = x
        self.assertEqual(p.path(), "/x/p")
Exemple #27
0
    def test_read_lights(self):
        filepath = lights_out()
        a = cask.Archive(filepath)
        self.assertEqual(a.path(), filepath)
        self.assertEqual(a.name, os.path.basename(filepath))

        # test the top node
        t = a.top
        self.assertEqual(type(t), cask.Top)
        self.assertEqual(t.name, "ABC")
        self.assertEqual(t.parent, a)
        self.assertEqual(t.path(), "/")
        self.assertEqual(t.archive(), a)

        # child accessors
        l1 = t.children["lightA"]
        self.assertEqual(type(l1.parent), cask.Top)
        self.assertEqual(l1.name, "lightA")
        self.assertEqual(l1.archive(), a)
        self.assertEqual(type(l1), cask.Light)

        # get next child
        l2 = t.children["lightB"]
        self.assertEqual(type(l2), cask.Light)
        self.assertEqual(l2.name, "lightB")
        self.assertEqual(l2.archive(), a)
        self.assertEqual(type(l2.parent), cask.Top)

        # find lights (w/ deferred schemification)
        self.assertEqual(len(cask.find(a.top, "light.*")), 2)

        # schema accessor (schemifies object on demand)
        self.assertEqual(type(l2.iobject), alembic.Abc.IObject)
        self.assertEqual(len(l2.properties[".geom/.camera/.core"].properties),
                         0)
        self.assertEqual(
            len(l2.properties["shader/prman.light.params"].properties), 2)
        self.assertEqual(
            len(l2.properties["shader/prman.light.params/exposure"].values),
            11)
        self.assertEqual(
            len(l2.properties["shader/prman.light.params/specular"].values),
            11)
        self.assertAlmostEqual(
            l2.properties["shader/prman.light.params/exposure"].values[0], 1.0)
        self.assertAlmostEqual(
            l2.properties["shader/prman.light.params/specular"].values[0], 0.1)
        self.assertEqual(type(l2.schema), alembic.AbcGeom.ILightSchema)
        self.assertEqual(type(l2.iobject), alembic.AbcGeom.ILight)
Exemple #28
0
    def test_verify_insert_node(self):
        filename = os.path.join(TEMPDIR, "cask_insert_node.abc")
        self.assertTrue(cask.is_valid(filename))

        # get some objects
        a = cask.Archive(filename)
        r = a.top.children.values()[0]
        m = r.children.values()[0]
        
        # verify re-parenting
        self.assertEqual(r.name, "root")
        self.assertEqual(type(r), cask.Xform)
        self.assertEqual(m.name, "meshy")
        self.assertEqual(type(m), cask.PolyMesh)
        self.assertEqual(len(m.properties[".geom"].properties), 7)
Exemple #29
0
    def test_verify_extract_light(self):
        filename = os.path.join(TEMPDIR, "cask_exract_light.abc")
        self.assertTrue(cask.is_valid(filename))

        # open the archive
        a = cask.Archive(filename)
        self.assertEqual(len(a.top.children), 1)

        # verify the hierarchy
        l = a.top.children["lightB"]
        self.assertEqual(type(l), cask.Light)
        self.assertEqual(len(l.properties.keys()), 2)
        self.assertEqual(len(l.properties[".geom/.userProperties"].properties), 1)
        self.assertTrue("specular" in l.properties["shader/prman.light.params"].properties.keys())
        self.assertTrue("exposure" in l.properties["shader/prman.light.params"].properties.keys())
Exemple #30
0
    def test_insert_node(self):
        filename = os.path.join(TEMPDIR, "cask_insert_node.abc")

        # test inerting a node into the hierarchy at the top
        a = cask.Archive(mesh_out())
        
        # insert a new xform between two nodes
        r = cask.Xform()
        m = a.top.children["meshy"]
        a.top.children["root"] = r
        r.children["meshy"] = m

        # write to disk
        a.write_to_file(filename)
        self.assertTrue(os.path.isfile(filename))