diff --git a/cask.py b/cask.py index df44d71..84c8a67 100644 --- a/cask.py +++ b/cask.py @@ -42,7 +42,7 @@ More information can be found at http://docs.alembic.io/python/cask.html """ -__version__ = "1.1.0" +__version__ = "1.1.1" import os import re @@ -239,6 +239,7 @@ def uint64(n): Int8: imath.SignedCharArray, Int16: imath.ShortArray, Int32: imath.IntArray, + Int64: imath.DoubleArray, Uint8: imath.UnsignedCharArray, Uint16: imath.UnsignedShortArray, Uint32: imath.UnsignedIntArray @@ -259,7 +260,8 @@ def uint64(n): Int64: (alembic.Util.POD.kInt64POD, -1), float: (alembic.Util.POD.kFloat64POD, -1), str: (alembic.Util.POD.kStringPOD, -1), - imath.V3f: (alembic.Util.POD.kFloat32POD, -1), + imath.V3f: (alembic.Util.POD.kFloat32POD, 3), + imath.V3d: (alembic.Util.POD.kFloat64POD, 3), imath.Color3c: (alembic.Util.POD.kUint8POD, -1), imath.Color3f: (alembic.Util.POD.kFloat32POD, -1), imath.Color4c: (alembic.Util.POD.kUint8POD, -1), @@ -273,6 +275,8 @@ def uint64(n): imath.StringArray: (alembic.Util.POD.kStringPOD, -1), imath.UnsignedCharArray: (alembic.Util.POD.kUint8POD, -1), imath.IntArray: (alembic.Util.POD.kInt32POD, -1), + imath.V3fArray: (alembic.Util.POD.kFloat32POD, 3), + imath.V3dArray: (alembic.Util.POD.kFloat64POD, 3), imath.FloatArray: (alembic.Util.POD.kFloat32POD, -1), imath.DoubleArray: (alembic.Util.POD.kFloat64POD, -1), } @@ -291,6 +295,8 @@ def get_simple_oprop_class(prop): value = prop.values[0] if len(prop.values) > 0 else [] if prop.iobject: is_array = prop.iobject.isArray() + elif type(value) in IMATH_ARRAYS_VALUES: + is_array = True else: is_array = type(value) in [list, set] and len(value) > 1 if is_array: @@ -331,6 +337,7 @@ def get_pod_extent(prop): pod, extent = POD_EXTENT.get(type(value0)) except TypeError as err: print "Error getting pod, extent from", prop, value0 + print err return (alembic.Util.POD.kUnknownPOD, 1) if extent <= 0: extent = (len(value0) @@ -1158,6 +1165,11 @@ def save(self): up._oobject = prop.object().oobject.getSchema().getUserProperties() up.properties[prop.name] = prop prop.parent = up + elif prop.parent.name == ".arbGeomParams": + up = Property() + up._oobject = prop.object().oobject.getSchema().getArbGeomParams() + up.properties[prop.name] = prop + prop.parent = up else: prop.parent = self prop.save() diff --git a/test/testCask.py b/test/testCask.py index ef436b9..5e01978 100644 --- a/test/testCask.py +++ b/test/testCask.py @@ -53,7 +53,6 @@ """ TODO - - more tests for getting and setting values/samples - test creating prototype schema objects - test name collisions when creating new objects and properties """ @@ -706,7 +705,7 @@ def test_pod_extent(self): something = foo.properties["something"] # assert pod, extent values - self.assertEqual(bar.extent(), 5) + self.assertEqual(bar.extent(), 1) self.assertEqual(bar.pod(), alembic.Util.POD.kUint8POD) self.assertEqual(bar.values[0], v) self.assertEqual(baz.extent(), 1) @@ -1346,8 +1345,26 @@ def test_issue_26(self): 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)) + p3 = a.top.children["foo"].properties["p3"] = cask.Property() + p4 = a.top.children["foo"].properties["p4"] = cask.Property() + + ca = imath.UnsignedCharArray(6) + for i in range(6): + ca[i] = i + p1.set_value(ca) + + da = imath.DoubleArray(12) + for i in range(12): + da[i] = i * 3.0 + p2.set_value(da) + + va = imath.V3fArray(3) + for i in range(3): + va[i] = imath.V3f(i, i*2.0, i*3.0) + p3.set_value(va) + + p4.set_value([imath.V3f(1, 2, 3), imath.V3f(4, 5, 6), imath.V3f(7, 8, 9)]) + a.write_to_file(test_file_1) a.close() @@ -1355,9 +1372,38 @@ def test_issue_26(self): 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()) + p3 = a.top.children["foo"].properties["p3"] + p4 = a.top.children["foo"].properties["p4"] + self.assertTrue(p1.iobject.isArray()) + self.assertTrue(p2.iobject.isArray()) + self.assertTrue(p3.iobject.isArray()) + self.assertTrue(p4.iobject.isArray()) + a.close() + + def test_issue_8(self): + """creating arbGeomParams on geom objects + https://github.com/alembic/cask/issues/8""" + + test_file_1 = os.path.join(TEMPDIR, "cask_test_issue_8.abc") + + a = cask.Archive() + m = a.top.children["meshy"] = cask.PolyMesh() + + p1 = m.properties[".geom/.arbGeomParams/test"] = cask.Property() + p1.set_value("somevalue") + + a.write_to_file(test_file_1) a.close() + a1 = cask.Archive(test_file_1) + m1 = a1.top.children["meshy"] + self.assertTrue("test" in m1.properties[".geom/.arbGeomParams"].properties) + + self.assertEqual(m1.properties[".geom/.arbGeomParams/test"].values[0], + "somevalue") + + a1.close() + + if __name__ == '__main__': unittest.main()