def test_TimeSampled(self): extents = { '/capsule': Vt.Vec3fArray( 2, (Gf.Vec3f(-4.0, -4.0, -6.0), Gf.Vec3f(4.0, 4.0, 6.0))), '/cone': Vt.Vec3fArray( 2, (Gf.Vec3f(-4.0, -4.0, -3.0), Gf.Vec3f(4.0, 4.0, 3.0))), '/cube': Vt.Vec3fArray( 2, (Gf.Vec3f(-3.0, -3.0, -3.0), Gf.Vec3f(3.0, 3.0, 3.0))), '/cylinder': Vt.Vec3fArray( 2, (Gf.Vec3f(-4.0, -4.0, -3.0), Gf.Vec3f(4.0, 4.0, 3.0))), '/sphere': Vt.Vec3fArray( 2, (Gf.Vec3f(-4.0, -4.0, -4.0), Gf.Vec3f(4.0, 4.0, 4.0))) } testFile = "test.usda" s = Usd.Stage.Open(testFile) for primpath in self.primpaths: p = s.GetPrimAtPath(primpath) b = UsdGeom.Boundable(p) tc = Usd.TimeCode(2.0) e = UsdGeom.Boundable.ComputeExtentFromPlugins(b, tc) print primpath, e self.assertEqual(extents[primpath], e)
def test_ComputeExtentPlugin(self): """Tests plugin for computing extents on a UsdSkelRoot.""" testFile = "root.usda" stage = Usd.Stage.Open(testFile) boundable = UsdGeom.Boundable(stage.GetPrimAtPath("/Root")) for time in range(int(stage.GetStartTimeCode()), int(stage.GetEndTimeCode())+1): UsdGeom.Boundable.ComputeExtentFromPlugins(boundable, time) stage.GetRootLayer().Export("root.computedExtents.usda")
def testComputeExtent(self): # Create a stage. stage = Usd.Stage.CreateInMemory() # Define a Triangle. triangle = UsdTri.Triangle.Define(stage, "/triangle") self.assertTrue(triangle) self.assertEqual(triangle.GetSideLengthAttr().Get(), 1) # Compute extent & validate. boundable = UsdGeom.Boundable(triangle.GetPrim()) self.assertTrue(boundable) extent = UsdGeom.Boundable.ComputeExtentFromPlugins( boundable, Usd.TimeCode.Default()) expectedExtent = Vt.Vec3fArray( ((0.5, -0.28867513, 0), (0.5, 0.57735026, 0))) for actualValue, expectedValue in zip(extent, expectedExtent): self.assertTrue(Gf.IsClose(actualValue, expectedValue, 1e-5))
def TestUsd4957(): """ Tests the case in which a prim has an xform directly on it and its bounding box relative to one of its ancestors is computed using ComputeRelativeBound(). """ s = Usd.Stage.Open("testUSD4957.usda") b = s.GetPrimAtPath("/A/B") c = s.GetPrimAtPath("/A/B/C") bc = UsdGeom.BBoxCache(Usd.TimeCode.Default(), ['default', 'render']) # Call the function being tested relativeBbox = bc.ComputeRelativeBound(c, b) # Compare the result with the bbox of C in its local space cExtent = UsdGeom.Boundable(c).GetExtentAttr().Get() cRange = Gf.Range3d(Gf.Vec3d(cExtent[0]), Gf.Vec3d(cExtent[1])) cLocalXform = UsdGeom.Xformable(c).GetLocalTransformation() cBbox = Gf.BBox3d(cRange, cLocalXform) AssertBBoxesClose(relativeBbox, cBbox, "ComputeRelativeBound produced a wrong bbox.")
def test_LightExtentAndBBox(self): # Test extent and bbox computations for the boundable lights. time = Usd.TimeCode.Default() # Helper for computing the extent and bounding boxes for a light and # comparing against an expect extent pair. def _VerifyExtentAndBBox(light, expectedExtent): self.assertEqual( UsdGeom.Boundable.ComputeExtentFromPlugins(light, time), expectedExtent) self.assertEqual( light.ComputeLocalBound(time, "default"), Gf.BBox3d( Gf.Range3d( Gf.Vec3d(expectedExtent[0]), Gf.Vec3d(expectedExtent[1])), Gf.Matrix4d(1.0))) # Create a prim of each boundable light type. stage = Usd.Stage.CreateInMemory() rectLight = UsdLux.RectLight.Define(stage, "/RectLight") self.assertTrue(rectLight) diskLight = UsdLux.DiskLight.Define(stage, "/DiskLight") self.assertTrue(diskLight) cylLight = UsdLux.CylinderLight.Define(stage, "/CylLight") self.assertTrue(cylLight) sphereLight = UsdLux.SphereLight.Define(stage, "/SphereLight") self.assertTrue(sphereLight) # Verify the extent and bbox computations for each light given its # fallback attribute values. _VerifyExtentAndBBox(rectLight, [(-0.5, -0.5, 0.0), (0.5, 0.5, 0.0)]) _VerifyExtentAndBBox(diskLight, [(-0.5, -0.5, 0.0), (0.5, 0.5, 0.0)]) _VerifyExtentAndBBox(cylLight, [(-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)]) _VerifyExtentAndBBox(sphereLight, [(-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)]) # Change the size related attribute of each light and verify the extents # and bounding boxes are updated. rectLight.CreateWidthAttr(4.0) rectLight.CreateHeightAttr(6.0) _VerifyExtentAndBBox(rectLight, [(-2.0, -3.0, 0.0), (2.0, 3.0, 0.0)]) diskLight.CreateRadiusAttr(5.0) _VerifyExtentAndBBox(diskLight, [(-5.0, -5.0, 0.0), (5.0, 5.0, 0.0)]) cylLight.CreateRadiusAttr(4.0) cylLight.CreateLengthAttr(10.0) _VerifyExtentAndBBox(cylLight, [(-4.0, -4.0, -5.0), (4.0, 4.0, 5.0)]) sphereLight.CreateRadiusAttr(3.0) _VerifyExtentAndBBox(sphereLight, [(-3.0, -3.0, -3.0), (3.0, 3.0, 3.0)]) # Special case for portal light. Portal lights don't have any attributes # that affect their extent, but they do have a constant extent defined # for a unit rectangle in the XY plane. portalLight = UsdLux.PortalLight.Define(stage, "/PortalLight") self.assertTrue(portalLight) self.assertIsNone( UsdGeom.Boundable.ComputeExtentFromPlugins(portalLight, time)) self.assertEqual( portalLight.ComputeLocalBound(time, "default"), Gf.BBox3d( Gf.Range3d(Gf.Vec3d(-0.5, -0.5, 0.0), Gf.Vec3d(0.5, 0.5, 0.0)), Gf.Matrix4d(1.0))) # For completeness verify that distant and dome lights are not # boundable. domeLight = UsdLux.DomeLight.Define(stage, "/DomeLight") self.assertTrue(domeLight) self.assertFalse(UsdGeom.Boundable(domeLight)) distLight = UsdLux.DistantLight.Define(stage, "/DistLight") self.assertTrue(distLight) self.assertFalse(UsdGeom.Boundable(distLight))