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)
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))
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)
def test_write_geom(self): filename = os.path.join(TEMPDIR, "cask_write_geom.abc") # create empty archive and put some objects in it a = cask.Archive() # create one of each geom class a.top.children["xform"] = cask.Xform() a.top.children["polymesh"] = cask.PolyMesh() a.top.children["subd"] = cask.SubD() a.top.children["faceset"] = cask.FaceSet() a.top.children["curve"] = cask.Curve() a.top.children["camera"] = cask.Camera() a.top.children["nupatch"] = cask.NuPatch() a.top.children["material"] = cask.Material() a.top.children["light"] = cask.Light() a.top.children["points"] = cask.Points() # export the archive a.write_to_file(filename) self.assertTrue(os.path.isfile(filename))
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 nodes do not exist try: x = t.children["A/foo/C/D/bar"] = cask.Xform() foo = x.properties[".xform/.userProperties/foo"] = cask.Property() foo.set_value(1.0) except KeyError: raise # assert that the created nodes are Xforms self.assertEqual(t.children["A/foo"].type(), "Xform") self.assertEqual(t.children["A/foo/C/D/bar"].type(), "Xform") self.assertEqual(foo.type(), "Property") self.assertEqual(foo.values[0], 1.0) # assert "a" still exists in "A" self.assertTrue("a" in t.children["A"].properties.keys()) # write the archive a.write_to_file(filename) # re-open and create add'l properties a = cask.Archive(filename) x = a.top.children["A/foo/C/D/bar"] # create new user property bar = x.properties[".xform/.userProperties/bar"] = cask.Property() bar.set_value(2.0) self.assertTrue("bar" in x.properties[".xform/.userProperties"].properties) # assert that "foo" was not clobbered when we created "bar" self.assertTrue("foo" in x.properties[".xform/.userProperties"].properties) foo = x.properties[".xform/.userProperties/foo"] self.assertEqual(foo.values[0], 1.0)