def makeQuad(self): verticesPerFace = IECore.IntVectorData([4]) vertexIds = IECore.IntVectorData([0, 1, 2, 3]) p = IECore.V3fVectorData([ IECore.V3f(0, 0, 0), IECore.V3f(1, 0, 0), IECore.V3f(1, 1, 0), IECore.V3f(0, 1, 0) ]) a = IECore.FloatVectorData([0, 1, 2, 3]) b = IECore.FloatVectorData([4, 5, 6, 7]) c = IECore.FloatData(42) mesh = IECoreScene.MeshPrimitive(verticesPerFace, vertexIds, "linear", p) mesh["a"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.FaceVarying, a) mesh["b"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.FaceVarying, b) mesh["c"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, c) self.assertTrue(mesh.arePrimitiveVariablesValid()) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(mesh) return objectToScene
def testDuplicateIds(self): points = IECoreScene.PointsPrimitive( IECore.V3fVectorData([imath.V3f(x, 0, 0) for x in range(6)])) points["id"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData([0, 0, 2, 2, 4, 4]), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(points) sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput(objectToScene["out"]) instancer["instances"].setInput(sphere["out"]) instancer["parent"].setValue("/object") instancer["id"].setValue("id") self.assertSceneValid(instancer["out"]) self.assertEqual( instancer["out"].childNames("/object/instances/sphere"), IECore.InternedStringVectorData(["0", "2", "4"])) self.assertEqual( instancer["out"].transform("/object/instances/sphere/0"), imath.M44f().translate(imath.V3f(0, 0, 0))) self.assertEqual( instancer["out"].transform("/object/instances/sphere/2"), imath.M44f().translate(imath.V3f(2, 0, 0))) self.assertEqual( instancer["out"].transform("/object/instances/sphere/4"), imath.M44f().translate(imath.V3f(4, 0, 0)))
def makeRectangleFromTwoSquaresScene(self): verticesPerFace = IECore.IntVectorData([4, 4]) vertexIds = IECore.IntVectorData([0, 1, 4, 3, 1, 2, 5, 4]) p = IECore.V3fVectorData([ IECore.V3f(0, 0, 0), IECore.V3f(1, 0, 0), IECore.V3f(2, 0, 0), IECore.V3f(0, 1, 0), IECore.V3f(1, 1, 0), IECore.V3f(2, 1, 0) ]) deleteData = IECore.IntVectorData([0, 1]) mesh = IECoreScene.MeshPrimitive(verticesPerFace, vertexIds, "linear", p) mesh["deleteFaces"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, deleteData) mesh["uniform"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.IntVectorData([10, 11])) mesh["vertex"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData([100, 101, 102, 103, 104, 105])) mesh["faceVarying"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.FaceVarying, IECore.IntVectorData([20, 21, 22, 23, 24, 25, 26, 27])) self.assertTrue(mesh.arePrimitiveVariablesValid()) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(mesh) return objectToScene
def testMismatchedInputSizes(self): points = IECoreScene.PointsPrimitive( IECore.V3fVectorData([imath.V3f(0)] * 2)) points["axis"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData([imath.V3f(1, 0, 0)] * 2)) points["angle"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData([0, 0, 0])) pointsNode = GafferScene.ObjectToScene() pointsNode["object"].setValue(points) filter = GafferScene.PathFilter() filter["paths"].setValue(IECore.StringVectorData(["/object"])) orientation = GafferScene.Orientation() orientation["in"].setInput(pointsNode["out"]) orientation["filter"].setInput(filter["out"]) orientation["inMode"].setValue(orientation.Mode.AxisAngle) with self.assertRaises(RuntimeError) as cm: orientation["out"].object("/object") self.assertIn( "Primitive variable \"angle\" has wrong size (3, but should be 2 to match \"axis\")", str(cm.exception))
def makeTriangleScene( self ) : verticesPerFace = IECore.IntVectorData( [3] ) vertexIds = IECore.IntVectorData( [0, 1, 2] ) p = IECore.V3fVectorData( [IECore.V3f( 0, 0, 0 ), IECore.V3f( 1, 0, 0 ), IECore.V3f( 0, 1, 0 )] ) prefData = IECore.V3fVectorData( [IECore.V3f( 0, 0, 0 ), IECore.V3f( 0, -1, 0 ), IECore.V3f( 1, 0, 0 )] ) mesh = IECoreScene.MeshPrimitive( verticesPerFace, vertexIds, "linear", p ) mesh["uv"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.FaceVarying, IECore.V2fVectorData( [ IECore.V2f( 0, 0 ), IECore.V2f( 1, 0 ), IECore.V2f( 0, 1 ) ], IECore.GeometricData.Interpretation.UV ) ) mesh["foo"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.FaceVarying, IECore.V2fVectorData( [ IECore.V2f( 0, 0 ), IECore.V2f( 0, 1 ), IECore.V2f( 1, 0 ) ], IECore.GeometricData.Interpretation.UV ) ) mesh["Pref"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, prefData ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue( mesh ) return objectToScene
def testWrite(self): s = GafferTest.SphereNode() o = GafferScene.ObjectToScene() o["__inputSource"].setInput(s["out"]) g = GafferScene.Group() g["in"].setInput(o["out"]) g["transform"]["translate"]["x"].setValue(5) g["transform"]["translate"]["z"].setValue(2) script = Gaffer.ScriptNode() writer = GafferScene.SceneWriter() script["writer"] = writer writer["in"].setInput(g["out"]) writer["fileName"].setValue(self.__testFile) writer.execute() sc = IECore.SceneCache(self.__testFile, IECore.IndexedIO.OpenMode.Read) t = sc.child("group") self.assertEqual(t.readTransformAsMatrix(0), IECore.M44d.createTranslated(IECore.V3d(5, 0, 2)))
def testFileInput(self): fileName = os.path.expandvars( "$GAFFER_ROOT/python/GafferTest/cobs/pSphereShape1.cob") read = Gaffer.ObjectReader() read["fileName"].setValue(fileName) object = IECore.Reader.create(fileName).read() objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setInput(read["out"]) self.assertEqual(objectToScene["out"].bound("/"), object.bound()) self.assertEqual(objectToScene["out"].transform("/"), IECore.M44f()) self.assertEqual(objectToScene["out"].object("/"), IECore.NullObject()) self.assertEqual(objectToScene["out"].childNames("/"), IECore.InternedStringVectorData(["object"])) self.assertEqual(objectToScene["out"].bound("/object"), object.bound()) self.assertEqual(objectToScene["out"].transform("/object"), IECore.M44f()) self.assertEqual(objectToScene["out"].object("/object"), object) self.assertEqual(objectToScene["out"].childNames("/object"), IECore.InternedStringVectorData()) self.assertSceneValid(objectToScene["out"])
def testFaceVaryingUVsWithoutIndices(self): plane = IECoreScene.MeshPrimitive.createPlane( imath.Box2f(imath.V2f(-1), imath.V2f(1)), divisions=imath.V2i(2, 1)) uv = plane["uv"] uv.data = uv.expandedData() uv.indices = None plane["uv"] = uv objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(plane) filter = GafferScene.PathFilter() filter["paths"].setValue(IECore.StringVectorData(["/object"])) wireframe = GafferScene.Wireframe() wireframe["in"].setInput(objectToScene["out"]) wireframe["filter"].setInput(filter["out"]) wireframe["position"].setValue("uv") self.assertSceneValid(wireframe["out"]) # Because we removed the indices, there is no connectivity information, # and therefore no shared edges, so we expect to see 8 curves. curves = wireframe["out"].object("/object") self.assertEqual(len(curves.verticesPerCurve()), 8)
def testProceduralInput( self ) : p = IECore.ReadProcedural() s = GafferScene.ObjectToScene() s["object"].setValue( p, _copy = False ) self.failUnless( isinstance( s["out"].object( "/object" ), IECore.ParameterisedProcedural ) ) self.assertTrue( s["out"].object( "/object", _copy=False ).isSame( p ) )
def testNegativeIdsAndIndices(self): points = IECoreScene.PointsPrimitive( IECore.V3fVectorData([imath.V3f(x, 0, 0) for x in range(0, 2)])) points["id"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData([-10, -5]), ) points["index"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData([-1, -2]), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(points) sphere = GafferScene.Sphere() cube = GafferScene.Cube() instances = GafferScene.Parent() instances["in"].setInput(sphere["out"]) instances["child"].setInput(cube["out"]) instances["parent"].setValue("/") instancer = GafferScene.Instancer() instancer["in"].setInput(objectToScene["out"]) instancer["instances"].setInput(instances["out"]) instancer["parent"].setValue("/object") instancer["index"].setValue("index") instancer["id"].setValue("id") self.assertEqual(instancer["out"].childNames("/object/instances"), IECore.InternedStringVectorData(["sphere", "cube"])) self.assertEqual( instancer["out"].childNames("/object/instances/sphere"), IECore.InternedStringVectorData(["-5"])) self.assertEqual(instancer["out"].childNames("/object/instances/cube"), IECore.InternedStringVectorData(["-10"])) self.assertEqual( instancer["out"].childNames("/object/instances/sphere/-5"), IECore.InternedStringVectorData()) self.assertEqual( instancer["out"].childNames("/object/instances/cube/-10"), IECore.InternedStringVectorData()) self.assertEqual(instancer["out"].object("/object/instances"), IECore.NullObject.defaultNullObject()) self.assertEqual(instancer["out"].object("/object/instances/sphere"), IECore.NullObject.defaultNullObject()) self.assertEqual(instancer["out"].object("/object/instances/cube"), IECore.NullObject.defaultNullObject()) self.assertEqual( instancer["out"].object("/object/instances/sphere/-5"), sphere["out"].object("/sphere")) self.assertEqual(instancer["out"].object("/object/instances/cube/-10"), cube["out"].object("/cube")) self.assertSceneValid(instancer["out"])
def test( self ) : ## \todo - this test just needs an arbitrary mesh with normals. # We should maybe have a more concise way of achieving this. How about a cow primitive? fileName = os.path.expandvars( "$GAFFER_ROOT/python/GafferTest/cobs/pSphereShape1.cob" ) read = Gaffer.ObjectReader() read["fileName"].setValue( fileName ) object = IECore.Reader.create( fileName ).read() p = GafferScene.ObjectToScene() p["object"].setInput( read["out"] ) m = GafferScene.MeshType() m["in"].setInput( p["out"] ) # Test unchanged settings. self.assertEqual( m["meshType"].getValue(), "" ) # do nothing self.assertEqual( p["out"].object( "/object" ), m["out"].object( "/object" ) ) self.assertScenesEqual( p["out"], m["out"] ) # Test converting poly to poly ( shouldn't do anything ) m["meshType"].setValue( "linear" ) self.assertEqual( p["out"].object( "/object" ), m["out"].object( "/object" ) ) self.assertScenesEqual( p["out"], m["out"] ) self.failUnless( "P" in m["out"].object( "/object" ) ) self.failUnless( "N" in m["out"].object( "/object" ) ) # Test converting poly to subdiv m["meshType"].setValue( "catmullClark" ) self.assertNotEqual( p["out"].object( "/object" ), m["out"].object( "/object" ) ) self.assertSceneHashesEqual( p["out"], m["out"], childPlugNames = ( "attributes", "bound", "transform", "globals", "childNames" ) ) self.assertScenesEqual( p["out"], m["out"], pathsToIgnore = ( "/object", ) ) self.assertEqual( m["out"].object( "/object" ).interpolation, "catmullClark" ) self.failUnless( "N" not in m["out"].object( "/object" ) ) # Test converting back to poly m2 = GafferScene.MeshType() m2["in"].setInput( m["out"] ) m2["meshType"].setValue( "linear" ) self.assertEqual( m2["out"].object( "/object" ).interpolation, "linear" ) self.assertTrue( "N" not in m2["out"].object( "/object" ) ) m2["calculatePolygonNormals"].setValue( True ) self.failUnless( "N" in m2["out"].object( "/object" ) )
def testIds( self ) : points = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( x, 0, 0 ) for x in range( 0, 4 ) ] ) ) points["id"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData( [ 10, 100, 111, 5 ] ), ) points["index"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData( [ 0, 1, 0, 1 ] ), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue( points ) sphere = GafferScene.Sphere() cube = GafferScene.Cube() instances = GafferScene.Parent() instances["in"].setInput( sphere["out"] ) instances["child"].setInput( cube["out"] ) instances["parent"].setValue( "/" ) instancer = GafferScene.Instancer() instancer["in"].setInput( objectToScene["out"] ) instancer["instances"].setInput( instances["out"] ) instancer["parent"].setValue( "/object" ) instancer["index"].setValue( "index" ) instancer["id"].setValue( "id" ) self.assertEqual( instancer["out"].childNames( "/object/instances" ), IECore.InternedStringVectorData( [ "sphere", "cube" ] ) ) self.assertEqual( instancer["out"].childNames( "/object/instances/sphere" ), IECore.InternedStringVectorData( [ "10", "111" ] ) ) self.assertEqual( instancer["out"].childNames( "/object/instances/cube" ), IECore.InternedStringVectorData( [ "100", "5" ] ) ) self.assertEqual( instancer["out"].childNames( "/object/instances/sphere/10" ), IECore.InternedStringVectorData() ) self.assertEqual( instancer["out"].childNames( "/object/instances/sphere/111" ), IECore.InternedStringVectorData() ) self.assertEqual( instancer["out"].childNames( "/object/instances/cube/100" ), IECore.InternedStringVectorData() ) self.assertEqual( instancer["out"].childNames( "/object/instances/cube/5" ), IECore.InternedStringVectorData() ) self.assertEqual( instancer["out"].object( "/object/instances" ), IECore.NullObject.defaultNullObject() ) self.assertEqual( instancer["out"].object( "/object/instances/sphere" ), IECore.NullObject.defaultNullObject() ) self.assertEqual( instancer["out"].object( "/object/instances/cube" ), IECore.NullObject.defaultNullObject() ) self.assertEqual( instancer["out"].object( "/object/instances/sphere/10" ), sphere["out"].object( "/sphere" ) ) self.assertEqual( instancer["out"].object( "/object/instances/sphere/111" ), sphere["out"].object( "/sphere" ) ) self.assertEqual( instancer["out"].object( "/object/instances/cube/100" ), cube["out"].object( "/cube" ) ) self.assertEqual( instancer["out"].object( "/object/instances/cube/5" ), cube["out"].object( "/cube" ) ) self.assertEqual( instancer["out"].transform( "/object/instances" ), imath.M44f() ) self.assertEqual( instancer["out"].transform( "/object/instances/sphere" ), imath.M44f() ) self.assertEqual( instancer["out"].transform( "/object/instances/cube" ), imath.M44f() ) self.assertEqual( instancer["out"].transform( "/object/instances/sphere/10" ), imath.M44f() ) self.assertEqual( instancer["out"].transform( "/object/instances/sphere/111" ), imath.M44f().translate( imath.V3f( 2, 0, 0 ) ) ) self.assertEqual( instancer["out"].transform( "/object/instances/cube/100" ), imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) ) self.assertEqual( instancer["out"].transform( "/object/instances/cube/5" ), imath.M44f().translate( imath.V3f( 3, 0, 0 ) ) ) self.assertSceneValid( instancer["out"] )
def testColor4fInput(self): # PointsPrimitive with Color4fVectorData primitive variable points = IECoreScene.PointsPrimitive( IECore.V3fVectorData([imath.V3f(0), imath.V3f(1)])) points["myColor4"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.Color4fVectorData( [imath.Color4f(1, 2, 3, 4), imath.Color4f(5, 6, 7, 8)])) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(points) self.assertSceneValid(objectToScene["out"]) # Shading network to read primitive variable in and copy to Color3fVectorData Cs inColor = GafferOSL.OSLShader() inColor.loadShader("ObjectProcessing/InColor") inColor["parameters"]["name"].setValue("myColor4") outColor = GafferOSL.OSLShader() outColor.loadShader("ObjectProcessing/OutColor") outColor["parameters"]["value"].setInput(inColor["out"]["value"]) outObject = GafferOSL.OSLShader() outObject.loadShader("ObjectProcessing/OutObject") outObject["parameters"]["in0"].setInput( outColor["out"]["primitiveVariable"]) # OSLObject node to apply network filter = GafferScene.PathFilter() filter["paths"].setValue(IECore.StringVectorData(["/object"])) oslObject = GafferOSL.OSLObject() oslObject["in"].setInput(objectToScene["out"]) oslObject["filter"].setInput(filter["out"]) oslObject["shader"].setInput(outObject["out"]["out"]) # Assertions outPoints = oslObject["out"].object("/object") self.assertIn("Cs", outPoints) self.assertEqual(outPoints["Cs"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Vertex) self.assertEqual( outPoints["Cs"].data, IECore.Color3fVectorData( [imath.Color3f(1, 2, 3), imath.Color3f(5, 6, 7)]))
def test(self): # Input is a plane stretched in X plane = IECoreScene.MeshPrimitive.createPlane( imath.Box2f(imath.V2f(-1), imath.V2f(1)), imath.V2i(10)) plane["Pref"] = plane["P"] plane["P"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [p * imath.V3f(2, 1, 1) for p in plane["P"].data])) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(plane) # Node should do nothing without a filter applied. meshDistortion = GafferScene.MeshDistortion() meshDistortion["in"].setInput(objectToScene["out"]) self.assertScenesEqual(objectToScene["out"], meshDistortion["out"]) self.assertSceneHashesEqual(objectToScene["out"], meshDistortion["out"]) mesh = meshDistortion["out"].object("/object") self.assertNotIn("distortion", mesh) self.assertNotIn("uvDistortion", mesh) # Applying a filter should kick it into action. f = GafferScene.PathFilter() f["paths"].setValue(IECore.StringVectorData(["/object"])) meshDistortion["filter"].setInput(f["out"]) mesh = meshDistortion["out"].object("/object") self.assertIn("distortion", mesh) self.assertIn("uvDistortion", mesh) self.assertIsInstance(mesh["distortion"].data, IECore.FloatVectorData) self.assertIsInstance(mesh["uvDistortion"].data, IECore.V2fVectorData) # We should be able to request only one sort of distortion, # or redirect the values to a different primitive variable. meshDistortion["distortion"].setValue("") mesh = meshDistortion["out"].object("/object") self.assertNotIn("distortion", mesh) self.assertIn("uvDistortion", mesh) meshDistortion["uvDistortion"].setValue("D") mesh = meshDistortion["out"].object("/object") self.assertNotIn("distortion", mesh) self.assertNotIn("uvDistortion", mesh) self.assertIn("D", mesh)
def testEditAttributes( self ) : points = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( x, 0, 0 ) for x in range( 0, 2 ) ] ) ) points["testFloat"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData( [ 0, 1 ] ), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue( points ) sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput( objectToScene["out"] ) instancer["instances"].setInput( sphere["out"] ) instancer["parent"].setValue( "/object" ) instancer["attributes"].setValue( "test*" ) self.assertEqual( instancer["out"].attributes( "/object/instances/sphere/0" ), IECore.CompoundObject( { "testFloat" : IECore.FloatData( 0.0 ), } ) ) self.assertEqual( instancer["out"].attributes( "/object/instances/sphere/1" ), IECore.CompoundObject( { "testFloat" : IECore.FloatData( 1.0 ), } ) ) points["testFloat"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData( [ 1, 2 ] ), ) objectToScene["object"].setValue( points ) self.assertEqual( instancer["out"].attributes( "/object/instances/sphere/0" ), IECore.CompoundObject( { "testFloat" : IECore.FloatData( 1.0 ), } ) ) self.assertEqual( instancer["out"].attributes( "/object/instances/sphere/1" ), IECore.CompoundObject( { "testFloat" : IECore.FloatData( 2.0 ), } ) )
def testMeshInput( self ) : p = GafferScene.ObjectToScene() p["object"].setValue( IECoreScene.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -1 ), IECore.V2f( 1 ) ) ) ) self.assertSceneValid( p["out"] ) self.assertEqual( p["out"].object( "/object" ), IECoreScene.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -1 ), IECore.V2f( 1 ) ) ) ) p["object"].setValue( IECoreScene.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -2 ), IECore.V2f( 2 ) ) ) ) self.assertSceneValid( p["out"] ) self.assertEqual( p["out"].object( "/object" ), IECoreScene.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -2 ), IECore.V2f( 2 ) ) ) )
def testCanShadeIndexedPrimVar(self): points = IECoreScene.PointsPrimitive(4096) points["P"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData([imath.V3f(1, 2, 3), imath.V3f(4, 5, 6)]), IECore.IntVectorData([1, 0] * 2048)) objectToScene = GafferScene.ObjectToScene() objectToScene['object'].setValue(points) oslObject = GafferOSL.OSLObject() oslObject['in'].setInput(objectToScene["out"]) inPoint = GafferOSL.OSLShader("InPoint") inPoint.loadShader("ObjectProcessing/InPoint") outPoint = GafferOSL.OSLShader("OutPoint") outPoint.loadShader("ObjectProcessing/OutPoint") outObject = GafferOSL.OSLShader("OutObject") outObject.loadShader("ObjectProcessing/OutObject") oslObject["shader"].setInput(outObject["out"]["out"]) outPoint["parameters"]["value"].setInput(inPoint["out"]["value"]) outPoint["parameters"]["value"]["x"].setInput( inPoint["out"]["value"]["x"]) outPoint["parameters"]["value"]["y"].setInput( inPoint["out"]["value"]["y"]) outPoint["parameters"]["value"]["z"].setInput( inPoint["out"]["value"]["z"]) outObject["parameters"]["in0"].setInput( outPoint["out"]["primitiveVariable"]) filter = GafferScene.PathFilter() filter["paths"].setValue(IECore.StringVectorData(["/object"])) oslObject["filter"].setInput(filter["out"]) processedPoints = oslObject['out'].object("/object") # currently the P should be expanded. self.assertEqual( processedPoints["P"].data, IECore.V3fVectorData( [imath.V3f(4, 5, 6), imath.V3f(1, 2, 3)] * 2048, IECore.GeometricData.Interpretation.Point)) self.assertEqual(processedPoints["P"].indices, None)
def testTransform( self ) : point = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( 4, 0, 0 ) ] ) ) point["orientation"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.QuatfVectorData( [ imath.Quatf().setAxisAngle( imath.V3f( 0, 1, 0 ), math.pi / 2.0 ) ] ) ) point["scale"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 2, 3, 4 ) ] ) ) point["uniformScale"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData( [ 10 ] ) ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue( point ) sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput( objectToScene["out"] ) instancer["instances"].setInput( sphere["out"] ) instancer["parent"].setValue( "/object" ) self.assertEqual( instancer["out"].transform( "/object/instances/sphere/0" ), imath.M44f().translate( imath.V3f( 4, 0, 0 ) ) ) instancer["orientation"].setValue( "orientation" ) self.assertTrue( imath.V3f( 4, 0, -1 ).equalWithAbsError( imath.V3f( 1, 0, 0 ) * instancer["out"].transform( "/object/instances/sphere/0" ), 0.00001 ) ) instancer["scale"].setValue( "scale" ) self.assertTrue( imath.V3f( 4, 0, -2 ).equalWithAbsError( imath.V3f( 1, 0, 0 ) * instancer["out"].transform( "/object/instances/sphere/0" ), 0.00001 ) ) instancer["scale"].setValue( "uniformScale" ) self.assertTrue( imath.V3f( 4, 0, -10 ).equalWithAbsError( imath.V3f( 1, 0, 0 ) * instancer["out"].transform( "/object/instances/sphere/0" ), 0.00001 ) )
def testSets( self ) : points = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( x, 0, 0 ) for x in range( 0, 4 ) ] ) ) points["index"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData( [ 0, 1, 1, 0 ] ), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue( points ) sphere = GafferScene.Sphere() sphere["sets"].setValue( "sphereSet" ) cube = GafferScene.Cube() cube["sets"].setValue( "cubeSet" ) cubeGroup = GafferScene.Group() cubeGroup["name"].setValue( "cubeGroup" ) cubeGroup["in"][0].setInput( cube["out"] ) instances = GafferScene.Parent() instances["in"].setInput( sphere["out"] ) instances["child"].setInput( cubeGroup["out"] ) instances["parent"].setValue( "/" ) instancer = GafferScene.Instancer() instancer["in"].setInput( objectToScene["out"] ) instancer["instances"].setInput( instances["out"] ) instancer["parent"].setValue( "/object" ) instancer["index"].setValue( "index" ) self.assertEqual( instancer["out"]["setNames"].getValue(), IECore.InternedStringVectorData( [ "sphereSet", "cubeSet" ] ) ) self.assertEqual( set( instancer["out"].set( "sphereSet" ).value.paths() ), { "/object/instances/sphere/0", "/object/instances/sphere/3", } ) self.assertEqual( set( instancer["out"].set( "cubeSet" ).value.paths() ), { "/object/instances/cubeGroup/1/cube", "/object/instances/cubeGroup/2/cube", } )
def testProceduralInput(self): p = Gaffer.ProceduralHolder() classSpec = GafferTest.ParameterisedHolderTest.classSpecification( "read", "IECORE_PROCEDURAL_PATHS")[:-1] p.setProcedural(*classSpec) s = GafferScene.ObjectToScene() s["object"].setInput(p["output"]) self.failUnless( isinstance(s["out"].object("/object"), IECore.ParameterisedProcedural)) p = s["out"].object("/object")
def makeCurves(self): testObject = IECore.CurvesPrimitive( IECore.IntVectorData([7, 7]), IECore.CubicBasisf.bezier(), False, IECore.V3fVectorData([ IECore.V3f(0, 0, 0), IECore.V3f(0, 1, 0), IECore.V3f(1, 1, 0), IECore.V3f(1, 0, 0), IECore.V3f(1, -1, 0), IECore.V3f(2, -1, 0), IECore.V3f(2, 0, 0), IECore.V3f(0, 0, 0), IECore.V3f(0, 0, 1), IECore.V3f(1, 0, 1), IECore.V3f(1, 0, 0), IECore.V3f(1, 0, -1), IECore.V3f(2, 0, -1), IECore.V3f(2, 0, 0) ])) testObject["a"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Constant, IECore.FloatData(0.5)) testObject["b"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData(range(0, 14))) testObject["c"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Uniform, IECore.FloatVectorData(range(0, 2))) testObject["d"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Varying, IECore.FloatVectorData(range(0, 6))) testObject["e"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.FaceVarying, IECore.FloatVectorData(range(0, 6))) testObject["deleteCurves"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Uniform, IECore.IntVectorData([0, 1])) self.assertTrue(testObject.arePrimitiveVariablesValid()) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(testObject) return objectToScene
def __init__(self, name="_ObjectPreview"): Gaffer.Node.__init__(self, name) self["fileName"] = Gaffer.StringPlug(defaultValue="") self["fileName"].setFlags(Gaffer.Plug.Flags.PerformsSubstitutions, False) self["frameRate"] = Gaffer.FloatPlug(defaultValue=24.0) self["samplesPerFrame"] = Gaffer.IntPlug(defaultValue=1, minValue=1) # single object scenes using Reader ops behind the scenes? self["ObjectReader"] = Gaffer.ObjectReader() self["ObjectReaderExpression"] = Gaffer.Expression("Expression") self["ObjectReaderExpression"]["expression"].setValue(''' import IECore fileName = parent['fileName'] try : sequence = IECore.FileSequence( fileName ) calc = IECore.OversamplesCalculator( frameRate = parent["frameRate"], samplesPerFrame = parent["samplesPerFrame"] ) if isinstance( sequence.frameList, IECore.FrameRange ) and sequence.frameList.step == 1 : calc.setTicksPerSecond( 24 ) result = sequence.fileNameForFrame( calc.framesToTicks( context['frame'] ) ) except : result = fileName parent['ObjectReader']['fileName'] = result ''') self["ObjectReader"]["fileName"].setInput( self["ObjectReaderExpression"]["out"]) self["ObjectToScene"] = GafferScene.ObjectToScene("ObjectToScene") self["ObjectToScene"]["object"].setInput(self["ObjectReader"]["out"]) self["out"] = GafferScene.ScenePlug( direction=Gaffer.Plug.Direction.Out) self["out"].setInput(self["ObjectToScene"]["out"])
def makeTriangleScene( self ) : verticesPerFace = IECore.IntVectorData( [3] ) vertexIds = IECore.IntVectorData( [0, 1, 2] ) p = IECore.V3fVectorData( [IECore.V3f( 0, 0, 0 ), IECore.V3f( 1, 0, 0 ), IECore.V3f( 0, 1, 0 )] ) prefData = IECore.V3fVectorData( [IECore.V3f( 0, 0, 0 ), IECore.V3f( 0, -1, 0 ), IECore.V3f( 1, 0, 0 )] ) s = IECore.FloatVectorData( [0, 1, 0] ) t = IECore.FloatVectorData( [0, 0, 1] ) mesh = IECore.MeshPrimitive( verticesPerFace, vertexIds, "linear", p ) mesh["s"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.FaceVarying, s ) mesh["t"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.FaceVarying, t ) mesh["foo_s"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.FaceVarying, IECore.FloatVectorData( [0, 0, 1] ) ) mesh["foo_t"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.FaceVarying, IECore.FloatVectorData( [0, 1, 0] ) ) mesh["Pref"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Vertex, prefData ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue( mesh ) return objectToScene
def testEmptyAttributesHaveConstantHash( self ) : points = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( x, 0, 0 ) for x in range( 0, 2 ) ] ) ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue( points ) sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput( objectToScene["out"] ) instancer["instances"].setInput( sphere["out"] ) instancer["parent"].setValue( "/object" ) self.assertEqual( instancer["out"].attributesHash( "/object/instances/sphere/0" ), instancer["out"].attributesHash( "/object/instances/sphere/1" ), ) self.assertEqual( instancer["out"].attributes( "/object/instances/sphere/0" ), instancer["out"].attributes( "/object/instances/sphere/1" ), )
def makePoints(self): testObject = IECoreScene.PointsPrimitive( IECore.V3fVectorData([ IECore.V3f(0, 0, 0), IECore.V3f(0, 1, 0), IECore.V3f(1, 1, 0), IECore.V3f(1, 0, 0) ]), IECore.FloatVectorData(range(0, 4))) testObject["deletePoints"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData([0, 1, 0, 1])) testObject["deletePoints2"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData([1, 1, 0, 0])) self.assertTrue(testObject.arePrimitiveVariablesValid()) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(testObject) return objectToScene
def testInvalidPrimitiveThrowsException(self): nurbsPrimitive = IECoreScene.NURBSPrimitive() nurbsPrimitive["a"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData([0, 1, 2, 3])) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(nurbsPrimitive) resample = GafferScene.ResamplePrimitiveVariables() pathFilter = GafferScene.PathFilter("PathFilter") pathFilter["paths"].setValue(IECore.StringVectorData(['/object'])) resample["in"].setInput(objectToScene["out"]) resample["filter"].setInput(pathFilter["out"]) resample["interpolation"].setValue( IECoreScene.PrimitiveVariable.Interpolation.Invalid) # invalid resample['names'].setValue("a") self.assertRaises(RuntimeError, lambda: resample["out"].object("/object"))
def test(self): curvesPrimitive = IECoreScene.CurvesPrimitive( IECore.IntVectorData([2, 2]), IECore.CubicBasisf.linear(), False, IECore.V3fVectorData([ imath.V3f(0), imath.V3f(1, 0, 0), imath.V3f(0), imath.V3f(0, 1, 0) ])) curves = GafferScene.ObjectToScene() curves["object"].setValue(curvesPrimitive) curves["name"].setValue("curves") points = GafferScene.ObjectToScene() points["name"].setValue("points") pointsFilter = GafferScene.PathFilter() pointsFilter["paths"].setValue(IECore.StringVectorData(["/points"])) sampler = GafferScene.CurveSampler() sampler["in"].setInput(points["out"]) sampler["source"].setInput(curves["out"]) sampler["filter"].setInput(pointsFilter["out"]) sampler["sourceLocation"].setValue("/curves") sampler["primitiveVariables"].setValue("P") sampler["status"].setValue("status") sampler["curveIndex"].setValue("curveIndex") sampler["v"].setValue("v") def __sampleCurves(curveIndex, v): pointsPrimitive = IECoreScene.PointsPrimitive( IECore.V3fVectorData([imath.V3f(0)])) pointsPrimitive["curveIndex"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData([curveIndex]), ) pointsPrimitive["v"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData([v]), ) points["object"].setValue(pointsPrimitive) sampledPoints = sampler["out"].object("/points") return sampledPoints["P"].data[0], sampledPoints["status"].data[0] self.assertEqual(__sampleCurves(0, 0.5), (imath.V3f(0.5, 0, 0), True)) self.assertEqual(__sampleCurves(1, 0.5), (imath.V3f(0, 0.5, 0), True)) self.assertEqual( __sampleCurves(-1, 0.5), # Curve index out of range (imath.V3f(0, 0, 0), False)) self.assertEqual( __sampleCurves(2, 0.5), # Curve index out of range (imath.V3f(0, 0, 0), False)) self.assertEqual( __sampleCurves(0, -0.01), # v out of range (imath.V3f(0, 0, 0), False)) self.assertEqual( __sampleCurves(0, 1.01), # v out of range (imath.V3f(0, 0, 0), False))
def testAttributes(self): points = IECoreScene.PointsPrimitive( IECore.V3fVectorData([imath.V3f(x, 0, 0) for x in range(0, 2)])) points["testFloat"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData([0, 1]), ) points["testColor"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.Color3fVectorData( [imath.Color3f(1, 0, 0), imath.Color3f(0, 1, 0)]), ) points["testPoint"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [imath.V3f(0, 0, 0), imath.V3f(1, 1, 1)], IECore.GeometricData.Interpretation.Point), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(points) sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput(objectToScene["out"]) instancer["instances"].setInput(sphere["out"]) instancer["parent"].setValue("/object") self.assertEqual(instancer["out"].attributes("/object/instances"), IECore.CompoundObject()) self.assertEqual( instancer["out"].attributes("/object/instances/sphere"), IECore.CompoundObject()) self.assertEqual( instancer["out"].attributes("/object/instances/sphere/0"), IECore.CompoundObject()) instancer["attributes"].setValue("testFloat testColor testPoint") self.assertEqual( instancer["out"].attributes("/object/instances/sphere/0"), IECore.CompoundObject({ "testFloat": IECore.FloatData(0.0), "testColor": IECore.Color3fData(imath.Color3f(1, 0, 0)), "testPoint": IECore.V3fData(imath.V3f(0), IECore.GeometricData.Interpretation.Point) })) self.assertEqual( instancer["out"].attributes("/object/instances/sphere/1"), IECore.CompoundObject({ "testFloat": IECore.FloatData(1.0), "testColor": IECore.Color3fData(imath.Color3f(0, 1, 0)), "testPoint": IECore.V3fData(imath.V3f(1), IECore.GeometricData.Interpretation.Point) }))
def test(self): points = IECoreScene.PointsPrimitive(1) points["P"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData([imath.V3f(1, 2, 3)], IECore.GeometricData.Interpretation.Point), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(points) group = GafferScene.Group() group["in"][0].setInput(objectToScene["out"]) filter = GafferScene.PathFilter() filter["paths"].setValue(IECore.StringVectorData(["/group/object"])) pointsType = GafferScene.PointsType() pointsType["in"].setInput(group["out"]) pointsType["filter"].setInput(filter["out"]) def assertExpectedOutput(type, unchanged): self.assertSceneValid(pointsType["out"]) if type is not None: self.assertEqual( pointsType["out"].object("/group/object") ["type"].data.value, type) else: self.assertFalse( "type" in pointsType["out"].object("/group/object")) if unchanged: self.assertScenesEqual(pointsType["out"], group["out"]) self.assertEqual(pointsType["out"].object("/group/object"), group["out"].object("/group/object")) self.assertTrue(pointsType["out"].object( "/group/object", _copy=False).isSame(group["out"].object("/group/object", _copy=False))) # Test unchanged settings (no type on input points). assertExpectedOutput(type=None, unchanged=True) # Test unchanged settings. points["type"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.StringData("particles")) objectToScene["object"].setValue(points) assertExpectedOutput(type="particles", unchanged=True) # Test converting particles to particles ( shouldn't do anything ) pointsType["type"].setValue("particles") assertExpectedOutput(type="particles", unchanged=True) # Test converting particles to sphere pointsType["type"].setValue("sphere") assertExpectedOutput(type="sphere", unchanged=False) # Test converting particles to patches pointsType["type"].setValue("patch") self.assertEqual( pointsType["out"].object("/group/object")["type"].data.value, "patch")
def test(self): # Prepare some points with a variety of primitive # variables specifying the same random orientations. points = IECoreScene.PointsPrimitive( IECore.V3fVectorData([imath.V3f(0)] * 100)) points["euler"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData()) points["quaternion"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.QuatfVectorData()) points["axis"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData()) points["angle"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData()) random.seed(0) for i in range(0, points["P"].data.size()): radians = imath.Eulerf(random.uniform(0, math.pi / 2), random.uniform(0, math.pi / 2), random.uniform(0, math.pi / 2)) degrees = 180.0 * radians / math.pi q = radians.toQuat() points["euler"].data.append(degrees) points["quaternion"].data.append(q) points["axis"].data.append(q.axis()) points["angle"].data.append(q.angle()) pointsNode = GafferScene.ObjectToScene() pointsNode["object"].setValue(points) # No filter is applied, so should be a no-op orientation = GafferScene.Orientation() orientation["in"].setInput(pointsNode["out"]) self.assertScenesEqual(orientation["out"], orientation["in"]) self.assertSceneHashesEqual(orientation["out"], orientation["in"]) # Apply a filter filter = GafferScene.PathFilter() filter["paths"].setValue(IECore.StringVectorData(["/object"])) orientation["filter"].setInput(filter["out"]) # Test euler -> euler round tripping self.assertEqual(orientation["inMode"].getValue(), orientation.Mode.Euler) orientation["inEuler"].setValue("euler") orientation["outMode"].setValue(orientation.Mode.Euler) orientation["outEuler"].setValue("outEuler") for order in [ imath.Eulerf.XYZ, imath.Eulerf.XZY, imath.Eulerf.YZX, imath.Eulerf.YXZ, imath.Eulerf.ZXY, imath.Eulerf.ZYX, ]: orientation["inOrder"].setValue(order) orientation["outOrder"].setValue(order) self.__assertVectorDataAlmostEqual( orientation["in"].object("/object")["euler"].data, orientation["out"].object("/object")["outEuler"].data, delta=0.01) # Test euler -> quaternion orientation["inOrder"].setValue(imath.Eulerf.XYZ) orientation["outMode"].setValue(orientation.Mode.Quaternion) orientation["outQuaternion"].setValue("outQuaternion") self.__assertVectorDataAlmostEqual( orientation["in"].object("/object")["quaternion"].data, orientation["out"].object("/object")["outQuaternion"].data, ) # Test euler -> axis angle orientation["outMode"].setValue(orientation.Mode.AxisAngle) orientation["outAxis"].setValue("outAxis") orientation["outAngle"].setValue("outAngle") self.__assertVectorDataAlmostEqual( orientation["in"].object("/object")["axis"].data, orientation["out"].object("/object")["outAxis"].data, ) self.__assertVectorDataAlmostEqual( orientation["in"].object("/object")["angle"].data, orientation["out"].object("/object")["outAngle"].data, )