def reloadOp(): n = hou.node(".") type = n.evalParm("__opType") ver = n.evalParm("__opVersion") if type=="" or ver=="": return ver = int(ver) fn = IECoreHoudini.FnOpHolder(n) IECore.ClassLoader.defaultOpLoader().refresh() cl = IECoreHoudini.op( type, ver ) # cache our existing parameters parms = fn.getParameterised().parameters().values() saved_parms = {} for p in parms: saved_parms[p.name] = p.getValue().value # reload parameter interface fn.setParameterised(cl) # restore parameter values for p in saved_parms.keys(): hparm = n.parm("parm_%s" % p) if hparm: hparm.set( saved_parms[p] )
def __createHoudiniQGLWidget( cls, format ) : try : import hou except ImportError : # we're not in houdini - createQGLWidget() will just make a # normal widget. return None import IECoreHoudini if hasattr( IECoreHoudini, "sharedGLWidget" ) : # In Houdini 14 and 15, Qt is the native UI, and we can access # Houdini's shared QGLWidget directly. return QtOpenGL.QGLWidget( format, shareWidget = GafferUI._qtObject( IECoreHoudini.sharedGLWidget(), QtOpenGL.QGLWidget ) ) # While Qt is the native UI in Houdini 16.0, they have moved away # from QGLWidgets for their Qt5 builds, so we need to force the # Houdini GL context to be current, and share it. IECoreHoudini.makeMainGLContextCurrent() return cls.__createHostedQGLWidget( format )
def testAnimatingGeometry(self): obj = hou.node("/obj") geo = obj.createNode("geo", run_init_scripts=False) torus = geo.createNode("torus") facet = geo.createNode("facet") facet.parm("postnml").set(True) mountain = geo.createNode("mountain") if hou.applicationVersion()[0] >= 16: mountain.parm("offsetx").setExpression("$FF") else: mountain.parm("offset1").setExpression("$FF") facet.setInput(0, torus) mountain.setInput(0, facet) converter = IECoreHoudini.FromHoudiniPolygonsConverter(mountain) hou.setFrame(1) mesh1 = converter.convert() hou.setFrame(2) converter = IECoreHoudini.FromHoudiniPolygonsConverter(mountain) mesh2 = converter.convert() self.assertNotEqual(mesh1["P"].data, mesh2["P"].data) self.assertNotEqual(mesh1, mesh2)
def testObjectWasDeleted(self): obj = hou.node("/obj") geo = obj.createNode("geo", run_init_scripts=False) torus = geo.createNode("torus") converter = IECoreHoudini.FromHoudiniPolygonsConverter(torus) g1 = converter.convert() torus.destroy() g2 = converter.convert() self.assertEqual(g2, g1) self.assertRaises( RuntimeError, IECore.curry(IECoreHoudini.FromHoudiniPolygonsConverter, torus))
def testNameAttributeExistsButSomeValuesAreEmpty(self): merge = self.buildScene() values = [] namers = [ x for x in merge.parent().children() if x.type().name() == "name" ] for namer in namers: values.append(namer.parm("name1").eval()) if namer.parm("name1").eval() == "torusBGroup": namer.bypass(True) values[-1] = "" converter = IECoreHoudini.FromHoudiniGroupConverter(merge) converter["groupingMode"].setTypedValue( IECoreHoudini.FromHoudiniGroupConverter.GroupingMode.NameAttribute) result = converter.convert() self.failUnless(result.isInstanceOf(IECore.TypeId.Group)) self.assertEqual(len(result.children()), 5) self.assertEqual( set([x.typeId() for x in result.children()]), set([ IECore._IECore.TypeId.CurvesPrimitive, IECore._IECore.TypeId.MeshPrimitive, IECore._IECore.TypeId.PointsPrimitive ])) names = [ "", "curveBoxGroup", "curveBoxGroup", "pointsGroup", "torusAGroup" ] expectedTypes = [ IECore.TypeId.MeshPrimitive, IECore.TypeId.MeshPrimitive, IECore.TypeId.CurvesPrimitive, IECore.TypeId.PointsPrimitive, IECore.TypeId.MeshPrimitive ] self.assertEqual(result.blindData(), IECore.CompoundData()) for i in range(0, len(result.children())): child = result.children()[i] self.failUnless(child.arePrimitiveVariablesValid()) self.failUnless("name" not in child) self.assertTrue(child.isInstanceOf(expectedTypes[i])) blindData = IECore.CompoundData( ) if names[i] == "" else IECore.CompoundData({"name": names[i]}) self.assertEqual(child.blindData(), blindData) null = merge.parent().createNode("null") self.failUnless( IECoreHoudini.ToHoudiniGeometryConverter.create(result).convert( null)) for prim in null.geometry().prims(): self.failUnless(prim.stringAttribValue("name") in values)
def testConvertGroupedCurves(self): curve = self.curve() name = curve.createOutputNode("name") name.parm("name1").set("curvesGroup") result = IECoreHoudini.FromHoudiniGroupConverter(name).convert() self.failUnless(result.isInstanceOf(IECore.TypeId.Group)) self.assertEqual(len(result.children()), 1) self.assertEqual(result.blindData(), IECore.CompoundData()) self.failUnless(result.children()[0].isInstanceOf( IECore.TypeId.CurvesPrimitive)) self.assertEqual(result.children()[0].blindData(), IECore.CompoundData({"name": "curvesGroup"}))
def testVertAttribsCantBeConverted(self): points = self.points() points["floatVert"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.FaceVarying, IECore.FloatVectorData(1)) sop = self.emptySop() self.assertNotEqual( IECoreHoudini.FromHoudiniPointsConverter(sop).convert(), points) self.assert_( IECoreHoudini.ToHoudiniPointsConverter(points).convert(sop)) allAttribs = [x.name() for x in sop.geometry().globalAttribs()] allAttribs.extend([x.name() for x in sop.geometry().pointAttribs()]) allAttribs.extend([x.name() for x in sop.geometry().primAttribs()]) allAttribs.extend([x.name() for x in sop.geometry().vertexAttribs()]) self.assert_("floatVert" not in allAttribs) del points["floatVert"] self.comparePrimAndSop(points, sop)
def testCreateToHoudiniConverter(self) : obj = hou.node("/obj") geo = obj.createNode("geo", run_init_scripts=False) op = geo.createNode( "ieOpHolder" ) cl = IECore.ClassLoader.defaultOpLoader().load( "cobReader", 1)() cl['filename'] = "test/IECoreHoudini/data/torus.cob" fn = IECoreHoudini.FnOpHolder(op) fn.setParameterised(cl) IECoreHoudini.Utils.syncSopParametersWithOp(op) op.cook() self.assertEqual( cl.resultParameter().getValue().typeId(), IECore.TypeId.MeshPrimitive ) return (op, fn)
def testInterpretation( self ) : merge = self.buildScene() converter = IECoreHoudini.FromHoudiniGroupConverter( merge ) result = converter.convert() for child in result.children() : self.assertTrue( child.isInstanceOf( IECore.TypeId.Primitive ) ) self.assertEqual( sorted(child.keys()), ['Cs', 'P', 'accel', 'born', 'event', 'generator', 'generatorIndices', 'id', 'life', 'nextid', 'parent', 'pstate', 'source', 'v', 'varmap'] ) self.assertEqual( child["P"].data.getInterpretation(), IECore.GeometricData.Interpretation.Point ) self.assertEqual( child["accel"].data.getInterpretation(), IECore.GeometricData.Interpretation.Vector ) self.assertEqual( child["life"].data.getInterpretation(), IECore.GeometricData.Interpretation.Numeric ) self.assertEqual( child["v"].data.getInterpretation(), IECore.GeometricData.Interpretation.Vector )
def testName(self): curves = self.createCurves(4) name = curves.createOutputNode("name") name.parm("name1").set("curvesA") curves2 = self.createCurve(parent=curves.parent()) name2 = curves2.createOutputNode("name") name2.parm("name1").set("curvesB") merge = name.createOutputNode("merge") merge.setInput(1, name2) converter = IECoreHoudini.FromHoudiniCurvesConverter(merge) result = converter.convert() # names are not stored on the object at all self.assertEqual(result.blindData(), IECore.CompoundData()) self.assertFalse("name" in result) # all curves were converted as one CurvesPrimitive self.assertEqual( result.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Uniform), 5) self.assertTrue(result.arePrimitiveVariablesValid()) converter = IECoreHoudini.FromHoudiniGeometryConverter.create( merge, "curvesA") self.assertTrue( converter.isInstanceOf( IECore.TypeId( IECoreHoudini.TypeId.FromHoudiniCurvesConverter))) result = converter.convert() # names are not stored on the object at all self.assertEqual(result.blindData(), IECore.CompoundData()) self.assertFalse("name" in result) # only the named curves were converted self.assertEqual( result.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Uniform), 4) self.assertTrue(result.arePrimitiveVariablesValid()) converter = IECoreHoudini.FromHoudiniGeometryConverter.create( merge, "curvesB") self.assertTrue( converter.isInstanceOf( IECore.TypeId( IECoreHoudini.TypeId.FromHoudiniCurvesConverter))) result = converter.convert() # names are not stored on the object at all self.assertEqual(result.blindData(), IECore.CompoundData()) self.assertFalse("name" in result) # only the named curves were converted self.assertEqual( result.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Uniform), 1) self.assertTrue(result.arePrimitiveVariablesValid())
def testName(self): points = self.createPoints() particles = points.createOutputNode("add") particles.parm("addparticlesystem").set(True) name = particles.createOutputNode("name") name.parm("name1").set("testName") group = particles.createOutputNode("group") group.parm("crname").set("testGroup") particles.bypass(True) result = IECoreHoudini.FromHoudiniPointsConverter(name).convert() self.assertEqual(result.blindData(), IECore.CompoundData()) result = IECoreHoudini.FromHoudiniPointsConverter(group).convert() self.assertEqual(result.blindData(), IECore.CompoundData()) particles.bypass(False) result = IECoreHoudini.FromHoudiniPointsConverter(name).convert() self.assertEqual(result.blindData()['name'].value, "testName") result = IECoreHoudini.FromHoudiniPointsConverter(group).convert() self.assertEqual(result.blindData()['name'].value, "testGroup")
def testSplineConversion( self ) : sop = self.emptySop() spline = IECore.CubicBasisf.bSpline() curves = self.curves( basis=spline ) self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop ) ) self.compareOpenSplinePrimAndSop( curves, sop ) curves = self.curves( basis=spline, periodic=True ) self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop ) ) self.comparePrimAndSop( curves, sop ) curves = self.curves( basis=spline, numCurves=1 ) self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop ) ) self.compareOpenSplinePrimAndSop( curves, sop ) curves = self.curves( basis=spline, periodic=True, numCurves=1 ) self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop ) ) self.comparePrimAndSop( curves, sop ) curves = self.curves( basis=spline, numCurves=100 ) self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop ) ) self.compareOpenSplinePrimAndSop( curves, sop ) curves = self.curves( basis=spline, periodic=True, numCurves=100 ) self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop ) ) self.comparePrimAndSop( curves, sop )
def testLinearConversion( self ) : sop = self.emptySop() curves = self.curves() self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop ) ) self.comparePrimAndSop( curves, sop ) curves = self.curves( periodic=True ) self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop ) ) self.comparePrimAndSop( curves, sop ) curves = self.curves( numCurves=1 ) self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop ) ) self.comparePrimAndSop( curves, sop ) curves = self.curves( periodic=True, numCurves=1 ) self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop ) ) self.comparePrimAndSop( curves, sop ) curves = self.curves( numCurves=100 ) self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop ) ) self.comparePrimAndSop( curves, sop ) curves = self.curves( periodic=True, numCurves=100 ) self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop ) ) self.comparePrimAndSop( curves, sop )
def testWireTogether(self): obj = hou.node("/obj") geo = obj.createNode("geo", run_init_scripts=False) v1_op = geo.createNode("ieOpHolder", node_name="vector1") fn = IECoreHoudini.FnOpHolder(v1_op) fn.setOp("vectors/V3fVectorCreator", 1) v1_op.parm("parm_size").set(3) v1_op.parmTuple("parm_value").set((1, 2, 3)) v2_op = geo.createNode("ieOpHolder", node_name="vector2") fn = IECoreHoudini.FnOpHolder(v2_op) fn.setOp("vectors/V3fVectorCreator", 1) v2_op.parm("parm_size").set(3) v2_op.parmTuple("parm_value").set((4, 5, 6)) add_op = geo.createNode("ieOpHolder", node_name="add_vectors") fn = IECoreHoudini.FnOpHolder(add_op) fn.setOp("vectors/V3fVectorAdder", 1) print_op = geo.createNode("ieOpHolder", node_name="print_values") fn = IECoreHoudini.FnOpHolder(print_op) fn.setOp("objectDebug", 1) print_op.parm("parm_quiet").set(True) # connect our ops together add_op.setInput(0, v1_op) add_op.setInput(1, v2_op) print_op.setInput(0, add_op) # cook and check our output print_op.cook() fn = IECoreHoudini.FnOpHolder(print_op) result = fn.getParameterised().resultParameter().getValue() self.assertEqual( result, IECore.V3fVectorData( [imath.V3f(5, 7, 9), imath.V3f(5, 7, 9), imath.V3f(5, 7, 9)]))
def testObjectPrefixAndSuffix(self): cache = self.cacheSop() group = cache.inputs()[0] group.parm("crname").set("rus") result = IECoreHoudini.FromHoudiniPolygonsConverter(cache).convert() self.assert_("Cs" not in result) cache.parm("objectFixes1").set("to") result = IECoreHoudini.FromHoudiniPolygonsConverter(cache).convert() self.assert_("Cs" in result) cache.parm("objectFixes1").set("") group.parm("crname").set("to") result = IECoreHoudini.FromHoudiniPolygonsConverter(cache).convert() self.assert_("Cs" not in result) cache.parm("objectFixes2").set("rus") result = IECoreHoudini.FromHoudiniPolygonsConverter(cache).convert() self.assert_("Cs" in result) cache.parm("objectFixes1").set("") cache.parm("objectFixes2").set("") group.parm("crname").set("oru") result = IECoreHoudini.FromHoudiniPolygonsConverter(cache).convert() self.assert_("Cs" not in result) cache.parm("objectFixes1").set("t") cache.parm("objectFixes2").set("s") result = IECoreHoudini.FromHoudiniPolygonsConverter(cache).convert() self.assert_("Cs" in result)
def testSaveLoadWithLockedSop( self ) : hou.hipFile.clear( suppress_save_prompt=True ) mesh = self.mesh() meshNumPoints = mesh.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Vertex ) sop = self.meshSop() sopPath = sop.path() orig = IECoreHoudini.FromHoudiniPolygonsConverter( sop ).convert() origNumPoints = orig.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Vertex ) self.assertNotEqual( orig, mesh ) sop.setHardLocked( True ) self.assert_( sop.isHardLocked() ) self.assert_( IECoreHoudini.ToHoudiniPolygonsConverter( mesh ).convert( sop, True ) ) self.assert_( sop.isHardLocked() ) self.comparePrimAndAppendedSop( mesh, sop, orig ) result = IECoreHoudini.FromHoudiniPolygonsConverter( sop ).convert() resultNumPoints = result.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Vertex ) self.assertEqual( resultNumPoints, origNumPoints + meshNumPoints ) for i in range( 0, mesh["P"].data.size() ) : self.assertEqual( result["P"].data[ origNumPoints + i ], mesh["P"].data[i] ) hou.hipFile.save( TestToHoudiniPolygonsConverter.__testScene ) hou.hipFile.clear( suppress_save_prompt=True ) hou.hipFile.load( TestToHoudiniPolygonsConverter.__testScene ) newSop = hou.node( sopPath ) self.assert_( newSop.isHardLocked() ) self.comparePrimAndAppendedSop( mesh, newSop, orig ) result = IECoreHoudini.FromHoudiniPolygonsConverter( newSop ).convert() resultNumPoints = result.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Vertex ) self.assertEqual( resultNumPoints, origNumPoints + meshNumPoints ) for i in range( 0, mesh["P"].data.size() ) : self.assertEqual( result["P"].data[ origNumPoints + i ], mesh["P"].data[i] )
def testStandardAttributeConversion( self ) : sop = self.emptySop() mesh = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) IECoreScene.TriangulateOp()( input=mesh, copyInput=False ) IECoreScene.MeshNormalsOp()( input=mesh, copyInput=False ) mesh["Cs"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.FaceVarying, IECore.V3fVectorData( [ imath.V3f( 1, 0, 0 ) ] * 6, IECore.GeometricData.Interpretation.Color ) ) mesh["width"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData( [ 1 ] * 4 ) ) mesh["Pref"] = mesh["P"] self.assertTrue( mesh.arePrimitiveVariablesValid() ) converter = IECoreHoudini.ToHoudiniPolygonsConverter( mesh ) self.assertTrue( converter.convert( sop ) ) geo = sop.geometry() self.assertItemsEqual( [ x.name() for x in geo.pointAttribs() ], TestToHoudiniPolygonsConverter.PointPositionAttribs + ['N', 'pscale', 'rest'] ) self.assertEqual( sorted([ x.name() for x in geo.primAttribs() ]), ['ieMeshInterpolation'] ) self.assertEqual( sorted([ x.name() for x in geo.vertexAttribs() ]), ['Cd', 'uv'] ) self.assertEqual( sorted([ x.name() for x in geo.globalAttribs() ]), [] ) uvData = mesh["uv"].data uvs = geo.findVertexAttrib( "uv" ) i = 0 for prim in geo.prims() : verts = list(prim.vertices()) verts.reverse() for vert in verts : uvValues = vert.attribValue( uvs ) self.assertAlmostEqual( uvValues[0], uvData[i][0] ) self.assertAlmostEqual( uvValues[1], uvData[i][1] ) i += 1 converter["convertStandardAttributes"].setTypedValue( False ) self.assertTrue( converter.convert( sop ) ) geo = sop.geometry() self.assertItemsEqual( [ x.name() for x in geo.pointAttribs() ], TestToHoudiniPolygonsConverter.PointPositionAttribs + ['N', 'Pref', 'width'] ) self.assertEqual( sorted([ x.name() for x in geo.primAttribs() ]), ['ieMeshInterpolation', ] ) self.assertEqual( sorted([ x.name() for x in geo.vertexAttribs() ]), ['Cs', 'uv'] ) self.assertEqual( sorted([ x.name() for x in geo.globalAttribs() ]), [] ) uvs = geo.findVertexAttrib( "uv" ) i = 0 for prim in geo.prims() : verts = list(prim.vertices()) verts.reverse() for vert in verts : uvValues = vert.attribValue( uvs ) self.assertAlmostEqual( uvValues[0], uvData[i][0] ) self.assertAlmostEqual( uvValues[1], uvData[i][1] ) i += 1
def testConvertGroupedCurvesAndPolygons(self): result = IECoreHoudini.FromHoudiniGroupConverter( self.curveBox()).convert() self.failUnless(result.isInstanceOf(IECore.TypeId.Group)) self.assertEqual(len(result.children()), 2) self.assertEqual(result.children()[0].blindData()["name"].value, "curveBoxGroup") self.failUnless(result.children()[0].isInstanceOf( IECore.TypeId.MeshPrimitive)) self.assertEqual(result.children()[1].blindData()["name"].value, "curveBoxGroup") self.failUnless(result.children()[1].isInstanceOf( IECore.TypeId.CurvesPrimitive))
def testConvertGroupedMesh(self): null = self.emptySop() group = IECoreScene.Group() group.addChild(self.mesh()) self.failUnless( IECoreHoudini.ToHoudiniGroupConverter(group).convert(null)) geo = null.geometry() nameAttr = geo.findPrimAttrib("name") self.assertEqual(nameAttr.strings(), tuple(["meshGroupA"])) self.assertEqual( len([ x for x in geo.prims() if x.attribValue("name") == "meshGroupA" ]), 6)
def testRaising(self): self.assertEqual(hou.updateModeSetting(), hou.updateMode.AutoUpdate) try: with IECoreHoudini.UpdateMode(hou.updateMode.Manual): raise RuntimeError, "This error is intentional" except RuntimeError: self.assertEqual(hou.updateModeSetting(), hou.updateMode.AutoUpdate)
def __createHoudiniQGLWidget( cls, format ) : try : import hou except ImportError : # we're not in houdini - createQGLWidget() will just make a # normal widget. return None import IECoreHoudini # Prior to Houdini 14 we are running embedded on the hou.ui idle loop, # so we needed to force the Houdini GL context to be current, and share # it, similar to how we do this in Maya. if hou.applicationVersion()[0] < 14 : IECoreHoudini.makeMainGLContextCurrent() return cls.__createHostedQGLWidget( format ) # In Houdini 14 and beyond, Qt is the native UI, and we can access # Houdini's shared QGLWidget directly, provided we are using a recent # Cortex version. return QtOpenGL.QGLWidget( format, shareWidget = GafferUI._qtObject( IECoreHoudini.sharedGLWidget(), QtOpenGL.QGLWidget ) )
def __createHoudiniQGLWidget( cls, format ) : try : import hou except ImportError : # we're not in houdini - createQGLWidget() will just make a # normal widget. return None import IECoreHoudini # Prior to Houdini 14 we are running embedded on the hou.ui idle loop, # so we needed to force the Houdini GL context to be current, and share # it, similar to how we do this in Maya. if hou.applicationVersion()[0] < 14 : IECoreHoudini.makeMainGLContextCurrent() return cls.__createHostedQGLWidget( format ) # In Houdini 14 and beyond, Qt is the native UI, and we can access # Houdini's shared QGLWidget directly, provided we are using a recent # Cortex version. return QtOpenGL.QGLWidget( format, shareWidget = GafferUI._qtObject( IECoreHoudini.sharedGLWidget(), QtOpenGL.QGLWidget ) )
def testInterpolation(self): torus = self.createTorus() result = IECoreHoudini.FromHoudiniPolygonsConverter(torus).convert() self.assertTrue("ieMeshInterpolation" not in result.keys()) self.assertEqual(result.interpolation, "linear") attr = torus.createOutputNode("attribcreate", node_name="interpolation", exact_type_name=True) attr.parm("name").set("ieMeshInterpolation") attr.parm("class").set(1) # prim attr.parm("type").set(3) # string attr.parm("string").set("subdiv") result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert() self.assertTrue("ieMeshInterpolation" not in result.keys()) self.assertEqual(result.interpolation, "catmullClark") attr.parm("string").set("poly") result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert() self.assertTrue("ieMeshInterpolation" not in result.keys()) self.assertEqual(result.interpolation, "linear")
def testConvertMesh( self ) : torus = self.createTorus() converter = IECoreHoudini.FromHoudiniPointsConverter( torus ) result = converter.convert() self.assertEqual( result.typeId(), IECore.PointsPrimitive.staticTypeId() ) bbox = result.bound() self.assertEqual( bbox.min.x, -2.0 ) self.assertEqual( bbox.max.x, 2.0 ) self.assertEqual( result.numPoints, 100 ) for i in range( result.numPoints ) : self.assert_( result["P"].data[i].x >= bbox.min.x ) self.assert_( result["P"].data[i].x <= bbox.max.x )
def testSetTake(self): take = "take1" hou.hscript("takeadd %s" % take) self.assert_(take in IECoreHoudini.ActiveTake.ls()) self.assertNotEqual(take, IECoreHoudini.ActiveTake.name()) with IECoreHoudini.ActiveTake(take): self.assertEqual(take, IECoreHoudini.ActiveTake.name()) self.assertNotEqual(take, IECoreHoudini.ActiveTake.name())
def testConvertUngroupedMultiPolygons(self): merge = self.twoTorii() merge.inputs()[0].bypass(True) merge.inputs()[1].bypass(True) result = IECoreHoudini.FromHoudiniGroupConverter(merge).convert() self.failUnless(result.isInstanceOf(IECore.TypeId.Group)) self.assertEqual(len(result.children()), 1) self.assertEqual(result.blindData(), IECore.CompoundData()) self.failUnless(result.children()[0].isInstanceOf( IECore.TypeId.MeshPrimitive)) self.assertEqual(result.children()[0].blindData(), IECore.CompoundData()) self.assertEqual(result.children()[0]["P"].data.size(), 200)
def testTransformAttribute(self): cache = self.cacheSop() hou.setFrame(2) orig = IECoreHoudini.FromHoudiniPolygonsConverter(cache).convert() cache.parm("transformAttribute").set("transform") result = IECoreHoudini.FromHoudiniPolygonsConverter(cache).convert() self.assertNotEqual(orig, result) self.assertNotEqual(orig['P'], result['P']) self.assertEqual(orig['P'].data.size(), result['P'].data.size()) self.assertEqual(orig['Cs'], result['Cs']) self.assertEqual(orig['pointId'], result['pointId']) i = IECore.InterpolatedCache( cache.parm("cacheSequence").eval(), IECore.InterpolatedCache.Interpolation.Linear, IECore.OversamplesCalculator(24, 1)) matrix = i.read(2, "torus", "transform").value.transform origP = orig["P"].data resultP = result["P"].data for i in range(0, origP.size()): self.assertNotEqual(resultP[i], origP[i]) self.assertEqual(resultP[i], matrix.multVecMatrix(origP[i]))
def testSaveLoad( self ) : hou.hipFile.clear( suppress_save_prompt=True ) curves = self.curves() curvesNumPoints = curves.variableSize( IECore.PrimitiveVariable.Interpolation.Vertex ) sop = self.curvesSop() sopPath = sop.path() orig = IECoreHoudini.FromHoudiniCurvesConverter( sop ).convert() origNumPoints = orig.variableSize( IECore.PrimitiveVariable.Interpolation.Vertex ) self.assertNotEqual( orig, curves ) self.assert_( not sop.isHardLocked() ) self.assert_( IECoreHoudini.ToHoudiniCurvesConverter( curves ).convert( sop, True ) ) self.assert_( sop.isHardLocked() ) self.comparePrimAndAppendedSop( curves, sop, orig ) result = IECoreHoudini.FromHoudiniCurvesConverter( sop ).convert() resultNumPoints = result.variableSize( IECore.PrimitiveVariable.Interpolation.Vertex ) self.assertEqual( resultNumPoints, origNumPoints + curvesNumPoints ) for i in range( 0, curves["P"].data.size() ) : self.assertEqual( result["P"].data[ origNumPoints + i ], curves["P"].data[i] ) hou.hipFile.save( TestToHoudiniCurvesConverter.__testScene ) hou.hipFile.clear( suppress_save_prompt=True ) hou.hipFile.load( TestToHoudiniCurvesConverter.__testScene ) newSop = hou.node( sopPath ) self.assert_( newSop.isHardLocked() ) self.comparePrimAndAppendedSop( curves, newSop, orig ) result = IECoreHoudini.FromHoudiniCurvesConverter( newSop ).convert() resultNumPoints = result.variableSize( IECore.PrimitiveVariable.Interpolation.Vertex ) self.assertEqual( resultNumPoints, origNumPoints + curvesNumPoints ) for i in range( 0, curves["P"].data.size() ) : self.assertEqual( result["P"].data[ origNumPoints + i ], curves["P"].data[i] )
def testCreateConverter(self): converter = IECoreHoudini.ToHoudiniCompoundObjectConverter( self.compound()) self.assertTrue( converter.isInstanceOf( IECore.TypeId( IECoreHoudini.TypeId.ToHoudiniCompoundObjectConverter))) self.assertRaises( Exception, IECore.curry(IECoreHoudini.ToHoudiniCompoundObjectConverter, self.mesh()))
def testSaveLoadWithLockedSop(self): hou.hipFile.clear(suppress_save_prompt=True) points = self.points() sop = self.pointsSop() sopPath = sop.path() orig = IECoreHoudini.FromHoudiniPointsConverter(sop).convert() self.assertNotEqual(orig, points) sop.setHardLocked(True) self.assert_(sop.isHardLocked()) self.assert_( IECoreHoudini.ToHoudiniPointsConverter(points).convert(sop, True)) self.assert_(sop.isHardLocked()) self.comparePrimAndAppendedSop(points, sop, orig) result = IECoreHoudini.FromHoudiniPointsConverter(sop).convert() self.assertEqual(result.numPoints, orig.numPoints + points.numPoints) for i in range(0, points["P"].data.size()): self.assertEqual(result["P"].data[orig.numPoints + i], points["P"].data[i]) hou.hipFile.save(TestToHoudiniPointsConverter.__testScene) hou.hipFile.clear(suppress_save_prompt=True) hou.hipFile.load(TestToHoudiniPointsConverter.__testScene) newSop = hou.node(sopPath) self.assert_(newSop.isHardLocked()) self.comparePrimAndAppendedSop(points, newSop, orig) result = IECoreHoudini.FromHoudiniPointsConverter(newSop).convert() self.assertEqual(result.numPoints, orig.numPoints + points.numPoints) for i in range(0, points["P"].data.size()): self.assertEqual(result["P"].data[orig.numPoints + i], points["P"].data[i])
def testMultipleConversions( self ) : obj = self.compound() sop = self.meshSop() orig = IECoreHoudini.FromHoudiniPolygonsConverter( sop ).convert() self.assertNotEqual( orig, obj ) converter = IECoreHoudini.ToHoudiniCompoundObjectConverter( obj ) self.assertTrue( converter.convert( sop, True ) ) self.assertTrue( sop.isHardLocked() ) self.verifyAppendedSop( sop, obj, orig ) self.assertTrue( sop.isHardLocked() ) self.assertTrue( converter.convert( sop, True ) ) self.assertTrue( sop.isHardLocked() ) self.verifyAppendedSop( sop, obj, orig, numAppends = 2 ) self.assertTrue( sop.isHardLocked() ) self.assertTrue( converter.convert( sop, True ) ) self.assertTrue( sop.isHardLocked() ) self.verifyAppendedSop( sop, obj, orig, numAppends = 3 )
def testConvertGroupedPointsAndPolygons(self): null = self.emptySop() self.failUnless( IECoreHoudini.ToHoudiniGroupConverter( self.pointTwoBox()).convert(null)) geo = null.geometry() nameAttr = geo.findPrimAttrib("name") self.assertEqual(nameAttr.strings(), tuple(["curveBoxGroup"])) self.assertEqual( len([ x for x in geo.prims() if x.attribValue("name") == "curveBoxGroup" ]), 12)
def testAppendingIntoExistingSop(self): obj = self.compound() sop = self.meshSop() orig = IECoreHoudini.FromHoudiniPolygonsConverter(sop).convert() self.assertNotEqual(orig, obj) self.assertTrue(not sop.isHardLocked()) converter = IECoreHoudini.ToHoudiniCompoundObjectConverter(obj) self.assertTrue(converter.convert(sop, True)) self.assertTrue(sop.isHardLocked()) self.verifyAppendedSop(sop, obj, orig) sop.setHardLocked(False) converter = IECoreHoudini.FromHoudiniGeometryConverter.create(sop) self.assertTrue( converter.isInstanceOf( IECore.TypeId( IECoreHoudini.TypeId.FromHoudiniPolygonsConverter))) self.assertEqual(orig, converter.convert())