示例#1
0
    def testWriteAnimatedBounds(self):

        aBound1 = imath.Box3d(imath.V3d(-2), imath.V3d(2))
        aBound2 = imath.Box3d(imath.V3d(0), imath.V3d(4))

        bBound1 = imath.Box3d(imath.V3d(-1), imath.V3d(1))
        bBound2 = imath.Box3d(imath.V3d(1), imath.V3d(3))

        a = IECoreAlembic.AlembicScene("/tmp/test.abc",
                                       IECore.IndexedIO.OpenMode.Write)
        a.writeBound(aBound1, 0)
        a.writeBound(aBound2, 1)

        b = a.createChild("b")
        b.writeBound(bBound1, 0)
        b.writeBound(bBound2, 1)

        del a, b

        a = IECoreAlembic.AlembicScene("/tmp/test.abc",
                                       IECore.IndexedIO.OpenMode.Read)
        self.assertEqual(a.numBoundSamples(), 2)
        self.assertEqual(a.readBoundAtSample(0), aBound1)
        self.assertEqual(a.readBoundAtSample(1), aBound2)
        self.assertEqual(a.readBound(0), aBound1)
        self.assertEqual(a.readBound(1), aBound2)

        b = a.child("b")
        self.assertEqual(b.numBoundSamples(), 2)
        self.assertEqual(b.readBoundAtSample(0), bBound1)
        self.assertEqual(b.readBoundAtSample(1), bBound2)
        self.assertEqual(b.readBound(0), bBound1)
        self.assertEqual(b.readBound(1), bBound2)
示例#2
0
    def testPerFrameWrite(self):
        fileName = "{}/testPerFrameWrite.scc".format(self.temporaryDirectory())
        frames = list(range(1, 25))
        for i in frames:
            stage = pxr.Usd.Stage.CreateInMemory()
            sphere = pxr.UsdGeom.Sphere.Define(stage, "/Sphere")
            attr = sphere.GetRadiusAttr()
            attr.Set(10, 1)
            attr.Set(100, 24)
            args = {
                "perFrameWrite": "1",
                "currentFrame": str(i),
                "firstFrame": str(frames[0]),
                "lastFrame": str(frames[-1]),
            }

            stage.Export(fileName, args=args)

        scene = IECoreScene.SharedSceneInterfaces.get(fileName)
        sphere = scene.child("Sphere")

        self.assertTrue(sphere)
        self.assertTrue(
            isinstance(sphere.readObject(0), IECoreScene.SpherePrimitive))

        self.assertEqual(sphere.readBound(0),
                         imath.Box3d(imath.V3d(-10), imath.V3d(10)))
        self.assertNotEqual(sphere.readBound(0.5), sphere.readBound(0))
        self.assertEqual(sphere.readBound(1),
                         imath.Box3d(imath.V3d(-100), imath.V3d(100)))
示例#3
0
    def testAnimatedBound(self):

        # Currently fails, because I'm pulling on the boundingBox plugs at arbitrary
        # times, and that doesn't work, although it kind of should!

        maya.cmds.polyCube(name="pCube1")
        maya.cmds.createNode("transform", name="pCube1Parent")

        maya.cmds.parent("pCube1", "pCube1Parent")

        maya.cmds.setKeyframe("pCube1", attribute="tx", t="0sec", v=0)
        maya.cmds.setKeyframe("pCube1", attribute="tx", t="1sec", v=-1)

        scene = IECoreMaya.LiveScene()
        transformChild = scene.child("pCube1Parent")

        maya.cmds.currentTime("0.0sec")
        self.assertEqual(
            transformChild.readBound(0.0),
            imath.Box3d(imath.V3d(-0.5, -0.5, -0.5), imath.V3d(0.5, 0.5, 0.5)))
        maya.cmds.currentTime("0.5sec")
        self.assertEqual(
            transformChild.readBound(0.5),
            imath.Box3d(imath.V3d(-1.0, -0.5, -0.5), imath.V3d(0.0, 0.5, 0.5)))
        maya.cmds.currentTime("1.0sec")
        self.assertEqual(
            transformChild.readBound(1.0),
            imath.Box3d(imath.V3d(-1.5, -0.5, -0.5), imath.V3d(-0.5, 0.5,
                                                               0.5)))
示例#4
0
    def testAnimatedMeshBound(self):

        # Currently fails, because I'm pulling on the boundingBox plugs at arbitrary
        # times, and that doesn't work, although it kind of should!

        maya.cmds.polyCube(name="pCube2")

        # create a skin cluster to animate vertex 0:
        maya.cmds.select(cl=True)
        maya.cmds.select("pCube2.vtx[0]", r=True)
        cluster = maya.mel.eval('newCluster "-envelope 1"')[1]

        maya.cmds.setKeyframe(cluster, attribute="tx", t="0sec")
        maya.cmds.setKeyframe(cluster, attribute="tx", t="1sec", v=-1)

        scene = IECoreMaya.LiveScene()
        transformChild = scene.child("pCube2")

        maya.cmds.currentTime("0.0sec")
        self.assertEqual(
            transformChild.readBound(0.0),
            imath.Box3d(imath.V3d(-0.5, -0.5, -0.5), imath.V3d(0.5, 0.5, 0.5)))
        maya.cmds.currentTime("0.5sec")
        self.assertEqual(
            transformChild.readBound(0.5),
            imath.Box3d(imath.V3d(-1.0, -0.5, -0.5), imath.V3d(0.5, 0.5, 0.5)))
        maya.cmds.currentTime("1.0sec")
        self.assertEqual(
            transformChild.readBound(1.0),
            imath.Box3d(imath.V3d(-1.5, -0.5, -0.5), imath.V3d(0.5, 0.5, 0.5)))
示例#5
0
    def testBound(self):
        fileName = "{}/testUSDBounds.scc".format(self.temporaryDirectory())
        self._writeScene(fileName)

        # root
        stage = pxr.Usd.Stage.Open(fileName)
        root = stage.GetPseudoRoot()
        prim = root.GetPrimAtPath("/t/s")

        extent = prim.GetAttribute("extent")
        self.assertEqual(
            extent.Get(24.0),
            pxr.Vt.Vec3fArray(2,
                              [pxr.Gf.Vec3f(0, 0, 0),
                               pxr.Gf.Vec3f(1, 1, 1)]))
        self.assertEqual(
            extent.Get(48.0),
            pxr.Vt.Vec3fArray(2,
                              [pxr.Gf.Vec3f(1, 1, 1),
                               pxr.Gf.Vec3f(2, 2, 2)]))

        # round trip
        exportPath = "{}/testUSDExportBounds.scc".format(
            self.temporaryDirectory())
        stage.Export(exportPath)

        scene = IECoreScene.SharedSceneInterfaces.get(exportPath)
        location = scene.scene(["t", "s"])

        self.assertEqual(location.readBound(1),
                         imath.Box3d(imath.V3d(0), imath.V3d(1)))
        self.assertEqual(location.readBound(2),
                         imath.Box3d(imath.V3d(1), imath.V3d(2)))
示例#6
0
    def testBound(self):

        a = IECoreScene.SceneInterface.create(
            os.path.dirname(__file__) + "/data/cube.abc",
            IECore.IndexedIO.OpenMode.Read)
        self.assertEqual(a.readBoundAtSample(0),
                         imath.Box3d(imath.V3d(-2), imath.V3d(2)))

        cs = a.child("group1").child("pCube1")
        self.assertEqual(cs.readBoundAtSample(0),
                         imath.Box3d(imath.V3d(-1), imath.V3d(1)))
示例#7
0
文件: testCask.py 项目: tanant/cask
    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")
示例#8
0
    def makeRandomBound(self):
        b1 = imath.V3d(random.random(), random.random(), random.random())
        b2 = imath.V3d(random.random(), random.random(), random.random())
        bound = imath.Box3d(b1)
        bound.extendBy(b2)

        return bound
示例#9
0
    def _get_bounds(self):
        #TODO: ugly code needs refactor
        if self.state.scenes:
            bounds = None
            for scene in self.state.scenes:
                if not scene.loaded:
                    continue
                if bounds is None or scene.bounds().max() > bounds.max():
                    bounds = scene.bounds()
                    min = bounds.min()
                    max = bounds.max()
                    if scene.properties.get("translate"):
                        max = max * imath.V3d(*scene.translate)
                        min = min * imath.V3d(*scene.translate)
                    if scene.properties.get("scale"):
                        max = max * imath.V3d(*scene.scale)
                        min = min * imath.V3d(*scene.scale)
                    bounds = imath.Box3d(min, max)

            if bounds is None:
                return self.__bounds_default
            self.__bounds = bounds
            return self.__bounds
        else:
            return self.__bounds_default
示例#10
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
示例#11
0
    def testBoundAtSample(self):

        a = IECoreScene.SceneInterface.create(
            os.path.dirname(__file__) + "/data/animatedCube.abc",
            IECore.IndexedIO.OpenMode.Read)
        self.assertEqual(a.readBoundAtSample(0),
                         imath.Box3d(imath.V3d(-0.5), imath.V3d(0.5)))
        self.assertEqual(
            a.readBoundAtSample(a.numBoundSamples() - 1),
            imath.Box3d(imath.V3d(0.5, -0.5, -0.5), imath.V3d(1.5, 2, 0.5)))

        t = a.child("pCube1")
        self.assertEqual(t.readBoundAtSample(0),
                         imath.Box3d(imath.V3d(-0.5), imath.V3d(0.5)))
        self.assertEqual(
            t.readBoundAtSample(t.numBoundSamples() - 1),
            imath.Box3d(imath.V3d(-0.5, -0.5, -0.5), imath.V3d(0.5, 2, 0.5)))
示例#12
0
	def testWriteExceptions( self ) :

		scene = IECoreMaya.LiveScene()

		self.assertRaises( RuntimeError, IECore.curry( scene.writeBound, imath.Box3d(), 0.0 ) )
		self.assertRaises( RuntimeError, IECore.curry( scene.writeTransform, IECore.M44dData( imath.M44d() ), 0.0 ) )
		self.assertRaises( RuntimeError, IECore.curry( scene.writeAttribute, "asdfs", IECore.BoolData( False ), 0.0 ) )
		self.assertRaises( RuntimeError, IECore.curry( scene.writeObject, IECoreScene.SpherePrimitive(), 0.0 ) )
示例#13
0
	def testBound( self ) :

		root = IECoreScene.SceneInterface.create( os.path.dirname( __file__ ) + "/data/cube.usda", IECore.IndexedIO.OpenMode.Read )
		cube = root.child( "pCube1" )

		bound = cube.readBound( 0.0 )

		self.assertEqual( bound, imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 0.5 ) ) )
示例#14
0
    def testCanReadBounds(self):
        bound = self.sceneInterface.readBound(0.0)

        expectedBound = imath.Box3d(
            imath.V3d([
                -33.809524536132812, -12.380952835083008, -26.190475463867188
            ]),
            imath.V3d(
                [19.047618865966797, 93.333335876464844, 27.142856597900391]))

        self.assertEqual(bound, expectedBound)
示例#15
0
	def testAlembicThreading( self ) :

		mesh = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) )
		fileName = self.temporaryDirectory() + "/test.abc"

		root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Write )
		root.writeBound( imath.Box3d( mesh.bound() ), 0 )
		for i in range( 0, 1000 ) :
			child = root.createChild( str( i ) )
			child.writeObject( mesh, 0 )
			child.writeBound( imath.Box3d( mesh.bound() ), 0 )

		del root, child

		sceneReader = GafferScene.SceneReader()
		sceneReader["fileName"].setValue( fileName )

		for i in range( 0, 20 ) :
			sceneReader["refreshCount"].setValue( sceneReader["refreshCount"].getValue() + 1 )
			GafferSceneTest.traverseScene( sceneReader["out"] )
示例#16
0
	def testReadBound( self ) :

		scene = self.buildScene()
		hou.node( "/obj/sub1" ).parmTuple( "t" ).set( [ 1, 1, 1 ] )
		hou.node( "/obj/sub1/torus1" ).parmTuple( "t" ).set( [ 2, 2, 2 ] )
		hou.node( "/obj/sub1/torus2" ).parmTuple( "t" ).set( [ -1, 0, 2 ] )
		hou.node( "/obj/box1" ).parmTuple( "t" ).set( [ -1, -1, -1 ] )
		# to make the bounds nice round numbers
		hou.node( "/obj/sub1/torus1/actualTorus" ).parm( "rows" ).set( 100 )
		hou.node( "/obj/sub1/torus1/actualTorus" ).parm( "cols" ).set( 100 )
		hou.node( "/obj/sub1/torus2/actualTorus" ).parm( "rows" ).set( 100 )
		hou.node( "/obj/sub1/torus2/actualTorus" ).parm( "cols" ).set( 100 )

		self.assertEqual( scene.child( "box2" ).readBound( 0 ), imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 0.5 ) ) )

		sub1 = scene.child( "sub1" )
		box1 = sub1.child( "box1" )
		self.assertEqual( box1.readBound( 0 ), imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 0.5 ) ) )

		torus1 = sub1.child( "torus1" )
		torus2 = torus1.child( "torus2" )
		self.assertEqual( torus2.readBound( 0 ), imath.Box3d( imath.V3d( -1.5, -0.5, -1.5 ), imath.V3d( 1.5, 0.5, 1.5 ) ) )
		self.assertEqual( torus1.readBound( 0 ), imath.Box3d( imath.V3d( -2.5, -0.5, -1.5 ), imath.V3d( 1.5, 0.5, 3.5 ) ) )
		self.assertEqual( sub1.readBound( 0 ), imath.Box3d( imath.V3d( -1.5 ), imath.V3d( 3.5, 2.5, 5.5 ) ) )
		self.assertEqual( scene.readBound( 0 ), imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 4.5, 3.5, 6.5 ) ) )
示例#17
0
    def testReadBound(self):

        # create some cubes:
        maya.cmds.polyCube(name="pCube1")
        maya.cmds.polyCube(name="pCube2")
        maya.cmds.polyCube(name="pCube3")
        maya.cmds.polyCube(name="pCube4")

        maya.cmds.parent("pCube2", "pCube1")
        maya.cmds.parent("pCube3", "pCube1")

        maya.cmds.setAttr("pCube4.tx", 3)
        maya.cmds.setAttr("pCube4.ty", 3)
        maya.cmds.setAttr("pCube4.tz", 3)

        maya.cmds.setAttr("pCube2.tx", 1)
        maya.cmds.setAttr("pCube2.ty", 1)
        maya.cmds.setAttr("pCube2.tz", 1)

        maya.cmds.setAttr("pCube3.tx", -1)
        maya.cmds.setAttr("pCube3.ty", -1)
        maya.cmds.setAttr("pCube3.tz", -1)

        scene = IECoreMaya.LiveScene()
        cube4Transform = scene.child("pCube4")
        cube1Transform = scene.child("pCube1")

        maya.cmds.currentTime("0.0sec")
        self.assertEqual(
            scene.readBound(0.0),
            imath.Box3d(imath.V3d(-1.5, -1.5, -1.5), imath.V3d(3.5, 3.5, 3.5)))

        self.assertEqual(
            cube4Transform.readBound(0.0),
            imath.Box3d(imath.V3d(-0.5, -0.5, -0.5), imath.V3d(0.5, 0.5, 0.5)))

        # check it's including its children:
        self.assertEqual(
            cube1Transform.readBound(0.0),
            imath.Box3d(imath.V3d(-1.5, -1.5, -1.5), imath.V3d(1.5, 1.5, 1.5)))

        maya.cmds.setAttr("pCube1.tx", 1)
        maya.cmds.setAttr("pCube1.ty", 1)
        maya.cmds.setAttr("pCube1.tz", 1)

        # should be in object space!!!
        self.assertEqual(
            cube1Transform.readBound(0.0),
            imath.Box3d(imath.V3d(-1.5, -1.5, -1.5), imath.V3d(1.5, 1.5, 1.5)))

        cube2Transform = cube1Transform.child("pCube2")
        self.assertEqual(
            cube2Transform.readBound(0.0),
            imath.Box3d(imath.V3d(-0.5, -0.5, -0.5), imath.V3d(0.5, 0.5, 0.5)))

        cube3Transform = cube1Transform.child("pCube3")
        self.assertEqual(
            cube3Transform.readBound(0.0),
            imath.Box3d(imath.V3d(-0.5, -0.5, -0.5), imath.V3d(0.5, 0.5, 0.5)))
示例#18
0
 def testUserData(self):
     compound = IECore.CompoundObject()
     compound["first"] = IECore.IntData()
     compound["second"] = IECore.QuatfData()
     compound["third"] = IECore.StringData("test")
     p = IECore.Box3dParameter("name",
                               "description",
                               imath.Box3d(),
                               userData=compound)
     self.assertEqual(p.userData(), compound)
     self.assertTrue(not p.userData().isSame(compound))
     data = p.userData()
     data["fourth"] = IECore.CharData('1')
     data["first"] = data["fourth"]
示例#19
0
    def __init__(self, parent=None, fps=24, state=None):
        """
        :param parent: parent Qt object
        :param fps: frames per second (default 24)
        :param state: GLState object (for shared states)
        """
        self.camera = None
        format = QtOpenGL.QGLFormat()
        format.setDirectRendering(True)
        format.setSampleBuffers(True)
        self.state = state or GLState()
        self.state.signal_state_change.connect(self.handle_state_change)
        super(GLWidget, self).__init__(format, parent)
        self.setAutoBufferSwap(True)
        self.setMouseTracking(True)
        self.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.setCursor(QtCore.Qt.OpenHandCursor)

        # save the parent object
        self._main = parent

        # frames per second value
        self.__time = 0
        self.__frame = 0
        self.__fps = fps
        self.__playing = False

        # various matrices and vectors
        self.__bounds_default = imath.Box3d((-5, -5, -5), (5, 5, 5))
        self.__bounds = None
        self.__radius = 5.0
        self.__last_pok = False
        self.__last_p2d = QtCore.QPoint()
        self.__last_p3d = [1.0, 0.0, 0.0]
        self.__rotating = False

        # for animated scenes
        self.timer = QtCore.QTimer(self)

        # default camera
        self.camera = GLCamera(self)
        self.state.add_camera(self.camera)

        self.frame()
示例#20
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
示例#21
0
    def testWriteTimeSamplesWitinFrameRange(self):
        fileName = "{}/testTimeSampleWithinFrameRange.scc".format(
            self.temporaryDirectory())
        frames = list(range(1, 25))
        stage = pxr.Usd.Stage.CreateInMemory()
        sphere = pxr.UsdGeom.Sphere.Define(stage, "/Sphere")
        attr = sphere.GetRadiusAttr()
        attr.Set(10, 1)
        attr.Set(100, 24)
        args = {
            "firstFrame": str(frames[0]),
            "lastFrame": "12",
        }

        stage.Export(fileName, args=args)

        scene = IECoreScene.SharedSceneInterfaces.get(fileName)
        sphere = scene.child("Sphere")

        self.assertEqual(sphere.readBound(0),
                         imath.Box3d(imath.V3d(-10), imath.V3d(10)))
        self.assertEqual(sphere.readBound(1), sphere.readBound(0.5))
示例#22
0
 def bounds(self):
     if self.bad:
         return imath.Box3d(imath.V3d(1, 1, 1), imath.V3d(1, 1, 1))
     return super(SceneWrapper, self).bounds()
示例#23
0
    def randomBox(self):

        min = imath.V3d(random.random(), random.random(), random.random())
        max = min + imath.V3d(random.random(), random.random(),
                              random.random())
        return imath.Box3d(min, max)
示例#24
0
def createBox3d(value):
    return imath.Box3d(imath.V3d(value))
示例#25
0
文件: testCask.py 项目: tanant/cask
    def test_pod_extent(self):
        filename = os.path.join(TEMPDIR, "cask_pod_extent.abc")

        extent = 5
        v = imath.UnsignedCharArray(extent)
        for i in range(0, extent):
            v[i] = i

        a = cask.Archive()

        # create test properties
        foo = a.top.children["foo"] = cask.Xform()
        bar = foo.properties["bar"] = cask.Property()
        baz = foo.properties["baz"] = cask.Property()
        qux = foo.properties["qux"] = cask.Property()
        quux = foo.properties["quux"] = cask.Property()
        garply = foo.properties["garply"] = cask.Property()
        waldo = foo.properties["waldo"] = cask.Property()
        fred = foo.properties["fred"] = cask.Property()
        color = foo.properties["color"] = cask.Property()
        color.metadata["interpretation"] = "rgb"
        
        # set test values
        v = imath.UnsignedCharArray(5)
        for i in range(0, 5):
            v[i] = i
        bar.set_value(v)
        baz.set_value(["a", "b", "c"])
        qux.set_value(imath.Box3d())
        quux.set_value(imath.M33d())
        garply.set_value(imath.M44d())
        waldo.set_value(1)
        fred.set_value([1, 2, 3, 4])
        color.set_value(imath.Color3f(1, 2, 3))
       
        # export
        a.write_to_file(filename)
        a.close()

        # reimport the test file
        a = cask.Archive(filename)

        # recover the test properties
        foo = a.top.children["foo"]
        bar = foo.properties["bar"]
        baz = foo.properties["baz"]
        qux = foo.properties["qux"]
        quux = foo.properties["quux"]
        garply = foo.properties["garply"]
        waldo = foo.properties["waldo"]
        fred = foo.properties["fred"]
        color = foo.properties["color"]
        
        # assert pod, extent values
        self.assertEqual(bar.extent(), 5)
        self.assertEqual(bar.pod(), alembic.Util.POD.kUint8POD)
        self.assertEqual(bar.values[0], v)
        self.assertEqual(baz.extent(), 1)
        self.assertEqual(baz.pod(), alembic.Util.POD.kStringPOD)
        self.assertEqual(list(baz.values[0]), ["a", "b", "c"])
        self.assertEqual(qux.extent(), 6)
        self.assertEqual(qux.pod(), alembic.Util.POD.kFloat64POD)
        self.assertEqual(qux.values[0], imath.Box3d())
        self.assertEqual(quux.extent(), 9)
        self.assertEqual(quux.pod(), alembic.Util.POD.kFloat64POD)
        self.assertEqual(quux.values[0], imath.M33d())
        self.assertEqual(garply.extent(), 16)
        self.assertEqual(garply.pod(), alembic.Util.POD.kFloat64POD)
        self.assertEqual(garply.values[0], imath.M44d())
        self.assertEqual(waldo.extent(), 1)
        self.assertEqual(waldo.pod(), alembic.Util.POD.kInt32POD)
        self.assertEqual(waldo.values[0], 1)
        self.assertEqual(fred.extent(), 1)
        self.assertEqual(fred.pod(), alembic.Util.POD.kInt32POD)
        self.assertEqual(list(fred.values[0]), [1, 2, 3, 4])
        self.assertEqual(color.extent(), 3)
        self.assertEqual(color.pod(), alembic.Util.POD.kFloat32POD)
        self.assertEqual(color.metadata["interpretation"], "rgb")
        self.assertEqual(color.values[0], imath.Color3f(1, 2, 3))
示例#26
0
	def testAnimatedBound( self ) :

		scene = self.buildScene()
		hou.node( "/obj/sub1" ).parmTuple( "t" ).set( [ 1, 1, 1 ] )
		hou.node( "/obj/sub1/torus1" ).parm( "tx" ).setExpression( "$T+(1.0/$FPS)" )
		hou.node( "/obj/sub1/torus1" ).parm( "ty" ).setExpression( "$T+(1.0/$FPS)" )
		hou.node( "/obj/sub1/torus1" ).parm( "tz" ).setExpression( "$T+(1.0/$FPS)" )
		hou.node( "/obj/sub1/torus2" ).parmTuple( "t" ).set( [ -1, 0, 2 ] )
		hou.node( "/obj/box1" ).parm( "tx" ).setExpression( "-($T+(1.0/$FPS))" )
		hou.node( "/obj/box1" ).parm( "ty" ).setExpression( "-($T+(1.0/$FPS))" )
		hou.node( "/obj/box1" ).parm( "tz" ).setExpression( "-($T+(1.0/$FPS))" )
		# to make the bounds nice round numbers
		hou.node( "/obj/sub1/torus1/actualTorus" ).parm( "rows" ).set( 100 )
		hou.node( "/obj/sub1/torus1/actualTorus" ).parm( "cols" ).set( 100 )
		hou.node( "/obj/sub1/torus2/actualTorus" ).parm( "rows" ).set( 100 )
		hou.node( "/obj/sub1/torus2/actualTorus" ).parm( "cols" ).set( 100 )

		self.assertEqual( scene.child( "box2" ).readBound( 0 ), imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 0.5 ) ) )

		sub1 = scene.child( "sub1" )
		box1 = sub1.child( "box1" )
		self.assertEqual( box1.readBound( 0 ), imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 0.5 ) ) )

		torus1 = sub1.child( "torus1" )
		torus2 = torus1.child( "torus2" )
		self.assertEqual( torus2.readBound( 0 ), imath.Box3d( imath.V3d( -1.5, -0.5, -1.5 ), imath.V3d( 1.5, 0.5, 1.5 ) ) )
		self.assertEqual( torus1.readBound( 0 ), imath.Box3d( imath.V3d( -2.5, -0.5, -1.5 ), imath.V3d( 1.5, 0.5, 3.5 ) ) )
		self.assertEqual( sub1.readBound( 0 ), imath.Box3d( imath.V3d( -2.5, -0.5, -1.5 ), imath.V3d( 1.5, 0.5, 3.5 ) ) )
		self.assertEqual( scene.readBound( 0 ), imath.Box3d( imath.V3d( -1.5, -0.5, -0.5 ), imath.V3d( 2.5, 1.5, 4.5 ) ) )

		# time 1
		self.assertEqual( box1.readBound( 1 ), imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 0.5 ) ) )
		self.assertEqual( torus2.readBound( 1 ), imath.Box3d( imath.V3d( -1.5, -0.5, -1.5 ), imath.V3d( 1.5, 0.5, 1.5 ) ) )
		self.assertEqual( torus1.readBound( 1 ), imath.Box3d( imath.V3d( -2.5, -0.5, -1.5 ), imath.V3d( 1.5, 0.5, 3.5 ) ) )
		self.assertEqual( sub1.readBound( 1 ), imath.Box3d( imath.V3d( -1.5 ), imath.V3d( 2.5, 1.5, 4.5 ) ) )
		self.assertEqual( scene.readBound( 1 ), imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 3.5, 2.5, 5.5 ) ) )

		# time 1.5
		self.assertEqual( box1.readBound( 1.5 ), imath.Box3d( imath.V3d( -0.5 ), imath.V3d( 0.5 ) ) )
		self.assertEqual( torus2.readBound( 1.5 ), imath.Box3d( imath.V3d( -1.5, -0.5, -1.5 ), imath.V3d( 1.5, 0.5, 1.5 ) ) )
		self.assertEqual( torus1.readBound( 1.5 ), imath.Box3d( imath.V3d( -2.5, -0.5, -1.5 ), imath.V3d( 1.5, 0.5, 3.5 ) ) )
		self.assertEqual( sub1.readBound( 1.5 ), imath.Box3d( imath.V3d( -2 ), imath.V3d( 3, 2, 5 ) ) )
		self.assertEqual( scene.readBound( 1.5 ), imath.Box3d( imath.V3d( -1 ), imath.V3d( 4, 3, 6 ) ) )
示例#27
0
    def makeBound(self):
        b1 = imath.V3d(-1, -1, -1)
        b2 = imath.V3d(1, 1, 1)
        bound = imath.Box3d(b1, b2)

        return bound
示例#28
0
def buildTestAttributes():
    attributes_map = {
        "0": {
            "agentType":
            IECore.StringData("atomsRobot"),
            "boundingBox":
            IECore.Box3dData(imath.Box3d(imath.V3d(-1.0), imath.V3d(1.0))),
            "metadata": {
                "testData": IECore.IntData(2)
            },
            "hash":
            IECore.UInt64Data(0),
            "rootMatrix":
            IECore.M44dData(imath.M44d().translate(imath.V3d(0.0, 0.0, 0.0))),
            "poseNormalWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
            "poseWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
        },
        "1": {
            "agentType":
            IECore.StringData("atomsRobot"),
            "boundingBox":
            IECore.Box3dData(imath.Box3d(imath.V3d(-1.0), imath.V3d(1.0))),
            "metadata": {
                "testData": IECore.IntData(2)
            },
            "hash":
            IECore.UInt64Data(0),
            "rootMatrix":
            IECore.M44dData(imath.M44d().translate(imath.V3d(1.0, 0.0, 0.0))),
            "poseNormalWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
            "poseWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
        },
        "2": {
            "agentType":
            IECore.StringData("atomsRobot"),
            "boundingBox":
            IECore.Box3dData(imath.Box3d(imath.V3d(-1.0), imath.V3d(1.0))),
            "metadata": {
                "testData": IECore.IntData(2)
            },
            "hash":
            IECore.UInt64Data(0),
            "rootMatrix":
            IECore.M44dData(imath.M44d().translate(imath.V3d(2.0, 0.0, 0.0))),
            "poseNormalWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
            "poseWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
        },
        "3": {
            "agentType":
            IECore.StringData("atomsRobot"),
            "boundingBox":
            IECore.Box3dData(imath.Box3d(imath.V3d(-1.0), imath.V3d(1.0))),
            "metadata": {
                "testData": IECore.IntData(2)
            },
            "hash":
            IECore.UInt64Data(0),
            "rootMatrix":
            IECore.M44dData(imath.M44d().translate(imath.V3d(3.0, 0.0, 0.0))),
            "poseNormalWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
            "poseWorldMatrices":
            IECore.M44dVectorData([imath.M44d()]),
        },
        "frameOffset": IECore.FloatData(0),
    }

    return {"atoms:agents": IECore.BlindDataHolder(attributes_map)}