def testUserSuppliedHash( self ) : with IECoreArnold.UniverseBlock( writable = True ) : c = IECoreArnold.InstancingConverter() m1 = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) m2 = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -2 ), imath.V2f( 2 ) ) ) h1 = IECore.MurmurHash() h2 = IECore.MurmurHash() h1.append( 10 ) h2.append( 10 ) am1a = c.convert( m1, h1, "testMesh" ) self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( am1a ) ), "polymesh" ) am1b = c.convert( m1, h1, "testInstance" ) self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( am1b ) ), "ginstance" ) self.assertEqual( arnold.AiNodeGetPtr( am1b, "node" ), ctypes.addressof( am1a.contents ) ) am2a = c.convert( m2, h2, "testMesh" ) self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( am2a ) ), "polymesh" ) am2b = c.convert( m2, h2, "testInstance" ) self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( am2b ) ), "ginstance" ) self.assertEqual( arnold.AiNodeGetPtr( am2b, "node" ), ctypes.addressof( am2a.contents ) )
def test(self): with IECoreArnold.UniverseBlock(writable=True): c = IECoreArnold.InstancingConverter() m1 = IECore.MeshPrimitive.createPlane( IECore.Box2f(IECore.V2f(-1), IECore.V2f(1))) m2 = m1.copy() m3 = IECore.MeshPrimitive.createPlane( IECore.Box2f(IECore.V2f(-2), IECore.V2f(2))) am1 = c.convert(m1) self.assertEqual( arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(am1)), "polymesh") am2 = c.convert(m2) self.assertEqual( arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(am2)), "ginstance") self.assertEqual(arnold.AiNodeGetPtr(am2, "node"), ctypes.addressof(am1.contents)) am3 = c.convert(m3) self.assertEqual( arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(am3)), "polymesh")
def testThreading(self): with IECoreArnold.UniverseBlock(writable=True): converter = IECoreArnold.InstancingConverter() meshes = [] for i in range(0, 1000): meshes.append( IECore.MeshPrimitive.createPlane( IECore.Box2f(IECore.V2f(-i), IECore.V2f(i)))) def f(nodeList): for i in range(0, 10000): nodeList.append( converter.convert(random.choice(meshes), "testMesh")) nodeLists = [] threads = [] for i in range(0, 10): nodeList = [] nodeLists.append(nodeList) t = threading.Thread(target=f, args=(nodeList, )) threads.append(t) t.start() for t in threads: t.join() numPolyMeshNodes = 0 numInstanceNodes = 0 polyMeshAddresses = set() instancedNodeAddresses = [] for nodeList in nodeLists: self.assertEqual(len(nodeList), 10000) for node in nodeList: nodeType = arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry(node)) self.failUnless(nodeType in ("ginstance", "polymesh")) if nodeType == "ginstance": numInstanceNodes += 1 instancedNodeAddresses.append( arnold.AiNodeGetPtr(node, "node")) else: numPolyMeshNodes += 1 polyMeshAddresses.add(ctypes.addressof(node.contents)) self.assertEqual(numInstanceNodes + numPolyMeshNodes, 10000 * 10) for address in instancedNodeAddresses: self.failUnless(address in polyMeshAddresses)
def testMotion(self): with IECoreArnold.UniverseBlock(writable=True): c = IECoreArnold.InstancingConverter() m1 = IECore.MeshPrimitive.createPlane( IECore.Box2f(IECore.V2f(-1), IECore.V2f(1))) m2 = IECore.MeshPrimitive.createPlane( IECore.Box2f(IECore.V2f(-2), IECore.V2f(2))) n1 = c.convert([m1, m2], -0.25, 0.25, "testMesh") self.assertEqual( arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n1)), "polymesh") self.assertEqual( arnold.AiArrayGetNumKeys( arnold.AiNodeGetArray(n1, "vlist").contents), 2) n2 = c.convert([m1, m2], -0.25, 0.25, "testInstance") self.assertEqual( arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n2)), "ginstance") self.assertEqual(arnold.AiNodeGetPtr(n2, "node"), ctypes.addressof(n1.contents)) n3 = c.convert([m2, m1], -0.25, 0.25, "testMesh") self.assertEqual( arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n1)), "polymesh") self.assertEqual( arnold.AiArrayGetNumKeys( arnold.AiNodeGetArray(n1, "vlist").contents), 2) n4 = c.convert([m1, m2], -0.5, 0.5, "testInstance") self.assertEqual( arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n1)), "polymesh") self.assertEqual( arnold.AiArrayGetNumKeys( arnold.AiNodeGetArray(n1, "vlist").contents), 2)