示例#1
0
def cube_out(name="cask_test_cube.abc", force=False):
    filename = os.path.join(TEMPDIR, name)
    if not force and (os.path.exists(filename) and cask.is_valid(filename)):
        return filename

    tvec = alembic.AbcCoreAbstract.TimeVector()
    tvec[:] = [1, 2, 3]

    timePerCycle = 3.0
    numSamplesPerCycle = len(tvec)

    tst = alembic.AbcCoreAbstract.TimeSamplingType(numSamplesPerCycle,
                                                   timePerCycle)
    ts = alembic.AbcCoreAbstract.TimeSampling(tst, tvec)

    top = alembic.Abc.OArchive(filename).getTop()
    tsidx = top.getArchive().addTimeSampling(ts)

    # create the top xform
    xform = alembic.AbcGeom.OXform(top, 'cube1', tsidx)
    xsamp = alembic.AbcGeom.XformSample()
    xform.getSchema().set(xsamp)

    # the mesh shape
    meshObj = alembic.AbcGeom.OPolyMesh(xform, 'cube1Shape')
    mesh = meshObj.getSchema()
    mesh_samp = alembic.AbcGeom.OPolyMeshSchemaSample(meshData.points,
                                                      meshData.faceIndices,
                                                      meshData.faceCounts)
    mesh_samp.setSelfBounds(meshData.selfBnds)
    mesh.set(mesh_samp)

    return filename
示例#2
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))
示例#3
0
def cube_out(name="cask_test_cube.abc", force=False):
    filename = os.path.join(TEMPDIR, name)
    if not force and (os.path.exists(filename) and cask.is_valid(filename)):
        return filename

    tvec = alembic.AbcCoreAbstract.TimeVector()
    tvec[:] = [1, 2, 3]

    timePerCycle = 3.0
    numSamplesPerCycle = len(tvec)

    tst = alembic.AbcCoreAbstract.TimeSamplingType(numSamplesPerCycle, timePerCycle)
    ts = alembic.AbcCoreAbstract.TimeSampling(tst, tvec)

    top = alembic.Abc.OArchive(filename).getTop()
    tsidx = top.getArchive().addTimeSampling(ts)

    # create the top xform
    xform = alembic.AbcGeom.OXform(top, 'cube1', tsidx)
    xsamp = alembic.AbcGeom.XformSample()
    xform.getSchema().set(xsamp)

    # the mesh shape
    meshObj = alembic.AbcGeom.OPolyMesh(xform, 'cube1Shape')
    mesh = meshObj.getSchema()
    mesh_samp = alembic.AbcGeom.OPolyMeshSchemaSample(
        meshData.points, meshData.faceIndices, meshData.faceCounts
    )
    mesh_samp.setSelfBounds(meshData.selfBnds)
    mesh.set(mesh_samp)

    return filename
示例#4
0
def mesh_out(name="cask_test_mesh.abc", force=False):
    filename = os.path.join(TEMPDIR, name)
    if not force and (os.path.exists(filename) and cask.is_valid(filename)):
        return filename

    oarch = alembic.Abc.OArchive(filename)
    meshyObj = alembic.AbcGeom.OPolyMesh(oarch.getTop(), 'meshy')
    mesh = meshyObj.getSchema()

    uvsamp = alembic.AbcGeom.OV2fGeomParamSample(meshData.uvs,
                                                 kFacevaryingScope)
    nsamp = alembic.AbcGeom.ON3fGeomParamSample(meshData.normals,
                                                kFacevaryingScope)
    mesh_samp = alembic.AbcGeom.OPolyMeshSchemaSample(meshData.verts,
                                                      meshData.indices,
                                                      meshData.counts, uvsamp,
                                                      nsamp)

    cbox = imath.Box3d()
    cbox.extendBy(imath.V3d(1.0, -1.0, 0.0))
    cbox.extendBy(imath.V3d(-1.0, 1.0, 3.0))

    for i in range(10):
        mesh.getChildBoundsProperty().setValue(cbox)
        mesh.set(mesh_samp)

    del oarch
    return filename
示例#5
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)
示例#6
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)
示例#7
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)
示例#8
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)
示例#9
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)
示例#10
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)
示例#11
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)
示例#12
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)
示例#13
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())
示例#14
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)
示例#15
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)
示例#16
0
def deep_out():
    filename = os.path.join(TEMPDIR, "cask_test_deep.abc")
    if os.path.exists(filename) and cask.is_valid(filename):
        return filename

    obj = alembic.Abc.OArchive(filename).getTop()
    for i in range(10):
        obj = alembic.AbcGeom.OXform(obj, string.uppercase[i])
        p = obj.getProperties()
        for i in range(3):
            p = alembic.Abc.OCompoundProperty(p, string.lowercase[i])
        p = alembic.Abc.OStringProperty(p, "myprop")
        p.setValue("foo")

    return filename
示例#17
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())
示例#18
0
def deep_out():
    filename = os.path.join(TEMPDIR, "cask_test_deep.abc")
    if os.path.exists(filename) and cask.is_valid(filename):
        return filename

    obj = alembic.Abc.OArchive(filename).getTop()
    for i in range(10):
        obj = alembic.AbcGeom.OXform(obj, string.uppercase[i])
        p = obj.getProperties()
        for i in range(3):
            p = alembic.Abc.OCompoundProperty(p, string.lowercase[i])
        p = alembic.Abc.OStringProperty(p, "myprop")
        p.setValue("foo")

    return filename
示例#19
0
    def test_verify_write_mesh(self):
        filename = os.path.join(TEMPDIR, "cask_write_mesh.abc")
        self.assertTrue(cask.is_valid(filename))

        # get the objects
        a = cask.Archive(filename)
        x = a.top.children.values()[0]
        p = x.children.values()[0]

        # verify the hierarchy
        self.assertEqual(x.name, "foo")
        self.assertEqual(type(x), cask.Xform)
        self.assertEqual(p.name, "meshy")
        self.assertEqual(type(p), cask.PolyMesh)

        # check one of the properties
        vals = x.properties.values()[0].properties[".vals"]
        self.assertEqual(vals.values[0], imath.V3d(1, 2, 3))
示例#20
0
    def test_verify_copy_lights(self):
        filename = os.path.join(TEMPDIR, "cask_copy_lights.abc")
        self.assertTrue(cask.is_valid(filename))

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

        # examine a lights properties
        lightA = a.top.children["lightA"]
        lightB = a.top.children["lightB"]
        self.assertEqual(type(lightA), cask.Light)
        self.assertEqual(type(lightB), cask.Light)

        self.assertEqual(len(lightA.properties), 1)
        self.assertEqual(len(lightB.properties), 2)
        self.assertAlmostEqual(lightB.properties["shader/prman.light.params/exposure"].get_value(), 1.0)
        self.assertAlmostEqual(lightB.properties["shader/prman.light.params/specular"].get_value(), 0.1)
示例#21
0
    def test_verify_copy_lights(self):
        filename = os.path.join(TEMPDIR, "cask_copy_lights.abc")
        self.assertTrue(cask.is_valid(filename))

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

        # examine a lights properties
        lightA = a.top.children["lightA"]
        lightB = a.top.children["lightB"]
        self.assertEqual(type(lightA), cask.Light)
        self.assertEqual(type(lightB), cask.Light)

        self.assertEqual(len(lightA.properties), 1)
        self.assertEqual(len(lightB.properties), 2)
        self.assertAlmostEqual(lightB.properties["shader/prman.light.params/exposure"].get_value(), 1.0)
        self.assertAlmostEqual(lightB.properties["shader/prman.light.params/specular"].get_value(), 0.1)
示例#22
0
    def test_verify_write_mesh(self):
        filename = os.path.join(TEMPDIR, "cask_write_mesh.abc")
        self.assertTrue(cask.is_valid(filename))

        # get the objects
        a = cask.Archive(filename)
        x = a.top.children.values()[0]
        p = x.children.values()[0]

        # verify the hierarchy
        self.assertEqual(x.name, "foo")
        self.assertEqual(type(x), cask.Xform)
        self.assertEqual(p.name, "meshy")
        self.assertEqual(type(p), cask.PolyMesh)

        # check one of the properties
        vals = x.properties.values()[0].properties[".vals"]
        self.assertEqual(vals.values[0], imath.V3d(1, 2, 3))
示例#23
0
def lights_out():
    filename = os.path.join(TEMPDIR, "cask_test_lights.abc")
    if os.path.exists(filename) and cask.is_valid(filename):
        return filename

    os.system("rm -f %s" % filename)
    archive = alembic.Abc.OArchive(filename)
    lightA = alembic.AbcGeom.OLight(archive.getTop(), "lightA")
    lightB = alembic.AbcGeom.OLight(archive.getTop(), "lightB")

    samp = alembic.AbcGeom.CameraSample()
    lightB.getSchema().setCameraSample(samp)

    # camera data
    samp = alembic.AbcGeom.CameraSample(-0.35, 0.75, 0.1, 0.5)
    lightB.getSchema().getChildBoundsProperty().setValue(
        imath.Box3d(imath.V3d(0.0, 0.1, 0.2), imath.V3d(0.3, 0.4, 0.5 )))
    samp.setNearClippingPlane(0.0)
    samp.setFarClippingPlane(1000.0)
    samp.setHorizontalAperture(2.8)
    samp.setVerticalAperture(2.8)
    samp.setFocalLength(50)
    lightB.getSchema().setCameraSample(samp)

    # material data
    mat = alembic.AbcMaterial.addMaterial(lightB, "shader")
    mat.setShader("prman", "light", "materialB")

    exposure = set_float(mat, "prman", "light", "exposure", 1.0)
    spec = set_float(mat, "prman", "light", "specular", 0.1)

    for i in range(10):
        exposure.setValue(1.0)
        spec.setValue(0.1 + i/10.0)

    # user properties
    user = lightB.getSchema().getUserProperties()
    test = alembic.Abc.OFloatProperty(user, "test")
    test.setValue(10)

    return filename
示例#24
0
def lights_out():
    filename = os.path.join(TEMPDIR, "cask_test_lights.abc")
    if os.path.exists(filename) and cask.is_valid(filename):
        return filename

    os.system("rm -f %s" % filename)
    archive = alembic.Abc.OArchive(filename)
    lightA = alembic.AbcGeom.OLight(archive.getTop(), "lightA")
    lightB = alembic.AbcGeom.OLight(archive.getTop(), "lightB")

    samp = alembic.AbcGeom.CameraSample()
    lightB.getSchema().setCameraSample(samp)

    # camera data
    samp = alembic.AbcGeom.CameraSample(-0.35, 0.75, 0.1, 0.5)
    lightB.getSchema().getChildBoundsProperty().setValue(
        imath.Box3d(imath.V3d(0.0, 0.1, 0.2), imath.V3d(0.3, 0.4, 0.5 )))
    samp.setNearClippingPlane(0.0)
    samp.setFarClippingPlane(1000.0)
    samp.setHorizontalAperture(2.8)
    samp.setVerticalAperture(2.8)
    samp.setFocalLength(50)
    lightB.getSchema().setCameraSample(samp)

    # material data
    mat = alembic.AbcMaterial.addMaterial(lightB, "shader")
    mat.setShader("prman", "light", "materialB")

    exposure = set_float(mat, "prman", "light", "exposure", 1.0)
    spec = set_float(mat, "prman", "light", "specular", 0.1)

    for i in range(10):
        exposure.setValue(1.0)
        spec.setValue(0.1 + i/10.0)

    # user properties
    user = lightB.getSchema().getUserProperties()
    test = alembic.Abc.OFloatProperty(user, "test")
    test.setValue(10)

    return filename
示例#25
0
def mesh_out():
    filename = os.path.join(TEMPDIR, "cask_test_mesh.abc")
    if os.path.exists(filename) and cask.is_valid(filename):
        return filename

    meshyObj = alembic.AbcGeom.OPolyMesh(alembic.Abc.OArchive(filename).getTop(), 
                                         'meshy')
    mesh = meshyObj.getSchema()

    uvsamp = alembic.AbcGeom.OV2fGeomParamSample(meshData.uvs, kFacevaryingScope) 
    nsamp  = alembic.AbcGeom.ON3fGeomParamSample(meshData.normals, kFacevaryingScope)
    mesh_samp = alembic.AbcGeom.OPolyMeshSchemaSample(
            meshData.verts, meshData.indices, meshData.counts, uvsamp, nsamp)

    cbox = imath.Box3d()
    cbox.extendBy(imath.V3d(1.0, -1.0, 0.0))
    cbox.extendBy(imath.V3d(-1.0, 1.0, 3.0))
   
    for i in range(10):
        mesh.getChildBoundsProperty().setValue(cbox)
        mesh.set(mesh_samp)
    
    return filename
示例#26
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))
示例#27
0
 def test_read_mesh(self):
     filepath = mesh_out()
     self.assertTrue(cask.is_valid(filepath))
     a = cask.Archive(filepath)
     t = a.top
示例#28
0
 def test_read_mesh(self):
     filepath = mesh_out()
     self.assertTrue(cask.is_valid(filepath))
     a = cask.Archive(filepath)
     t = a.top