@@ -1225,6 +1225,78 @@ def testLiveTags( self ) :
12251225 self .assertTrue ( scene .hasTag ( tag ) )
12261226 self .assertFalse ( scene .hasTag ( "notATag" ) )
12271227
1228+ def writeAttributeSCC ( self ) :
1229+
1230+ scene = self .writeSCC ()
1231+ sc1 = scene .child ( str ( 1 ) )
1232+ sc2 = sc1 .child ( str ( 2 ) )
1233+ sc3 = sc2 .child ( str ( 3 ) )
1234+ sc1 .writeAttribute ( "label" , IECore .StringData ( "a" ), 0 )
1235+ sc1 .writeAttribute ( "color" , IECore .Color3dData ( IECore .Color3d ( 0.5 ) ), 0 )
1236+ sc2 .writeAttribute ( "label" , IECore .StringData ( "b" ), 0 )
1237+ sc2 .writeAttribute ( "material" , IECore .StringData ( "rubber" ), 0 )
1238+ sc3 .writeAttribute ( "label" , IECore .StringData ( "c" ), 0 )
1239+ sc3 .writeAttribute ( "animColor" , IECore .Color3dData ( IECore .Color3d ( 0 ) ), 0 )
1240+ sc3 .writeAttribute ( "animColor" , IECore .Color3dData ( IECore .Color3d ( 0.5 ) ), 0.5 )
1241+ sc3 .writeAttribute ( "animColor" , IECore .Color3dData ( IECore .Color3d ( 1 ) ), 1 )
1242+
1243+ return scene
1244+
1245+ def testLiveAttributes ( self ) :
1246+
1247+ self .writeAttributeSCC ()
1248+
1249+ xform = self .xform ()
1250+ xform .parm ( "hierarchy" ).set ( IECoreHoudini .SceneCacheNode .Hierarchy .SubNetworks )
1251+ xform .parm ( "depth" ).set ( IECoreHoudini .SceneCacheNode .Depth .AllDescendants )
1252+
1253+ # its a link before it is expanded
1254+ scene = IECoreHoudini .HoudiniScene ( xform .path () )
1255+ self .assertEqual ( scene .attributeNames (), [ IECore .LinkedScene .linkAttribute ] )
1256+ self .assertTrue ( scene .hasAttribute ( IECore .LinkedScene .linkAttribute ) )
1257+ self .assertEqual (
1258+ scene .readAttribute ( IECore .LinkedScene .linkAttribute , 0 ),
1259+ IECore .CompoundData ( {
1260+ "time" : IECore .DoubleData ( 0 ),
1261+ "fileName" : IECore .StringData ( "test/test.scc" ),
1262+ "root" : IECore .InternedStringVectorData ( [] )
1263+ } )
1264+ )
1265+
1266+ # the link disapears once expanded
1267+ xform .parm ( "expand" ).pressButton ()
1268+ self .assertEqual ( scene .attributeNames (), [] )
1269+ self .assertFalse ( scene .hasAttribute ( IECore .LinkedScene .linkAttribute ) )
1270+ self .assertEqual ( scene .readAttribute ( IECore .LinkedScene .linkAttribute , 0 ), None )
1271+
1272+ # nodes expose their attributes
1273+ a = scene .child ( "1" )
1274+ self .assertEqual ( sorted (a .attributeNames ()), [ "color" , "label" , "sceneInterface:animatedObjectPrimVars" ] )
1275+ for attr in a .attributeNames () :
1276+ self .assertTrue ( a .hasAttribute ( attr ) )
1277+ self .assertFalse ( a .hasAttribute ( "material" ) )
1278+ self .assertEqual ( a .readAttribute ( "label" , 0 ), IECore .StringData ( "a" ) )
1279+ self .assertEqual ( a .readAttribute ( "color" , 0 ), IECore .Color3dData ( IECore .Color3d ( 0.5 ) ) )
1280+
1281+ b = a .child ( "2" )
1282+ self .assertEqual ( sorted (b .attributeNames ()), [ "label" , "material" , "sceneInterface:animatedObjectPrimVars" ] )
1283+ for attr in b .attributeNames () :
1284+ self .assertTrue ( b .hasAttribute ( attr ) )
1285+ self .assertFalse ( b .hasAttribute ( "color" ) )
1286+ self .assertEqual ( b .readAttribute ( "label" , 0 ), IECore .StringData ( "b" ) )
1287+ self .assertEqual ( b .readAttribute ( "material" , 0 ), IECore .StringData ( "rubber" ) )
1288+
1289+ c = b .child ( "3" )
1290+ self .assertEqual ( sorted (c .attributeNames ()), [ "animColor" , "label" , "sceneInterface:animatedObjectPrimVars" ] )
1291+ for attr in c .attributeNames () :
1292+ self .assertTrue ( c .hasAttribute ( attr ) )
1293+ self .assertFalse ( c .hasAttribute ( "color" ) )
1294+ self .assertFalse ( c .hasAttribute ( "material" ) )
1295+ self .assertEqual ( c .readAttribute ( "label" , 0 ), IECore .StringData ( "c" ) )
1296+ self .assertEqual ( c .readAttribute ( "animColor" , 0 ), IECore .Color3dData ( IECore .Color3d ( 0 ) ) )
1297+ self .assertEqual ( c .readAttribute ( "animColor" , 0.5 ), IECore .Color3dData ( IECore .Color3d ( 0.5 ) ) )
1298+ self .assertEqual ( c .readAttribute ( "animColor" , 1 ), IECore .Color3dData ( IECore .Color3d ( 1 ) ) )
1299+
12281300 def testReloadButton ( self ) :
12291301
12301302 def testNode ( node ) :
@@ -1410,6 +1482,19 @@ def compareScene( self, a, b, time = 0, bakedObjects = [], parentTransform = Non
14101482 self .assertTrue ( ab .min .equalWithAbsError ( bb .min , 1e-6 ) )
14111483 self .assertTrue ( ab .max .equalWithAbsError ( bb .max , 1e-6 ) )
14121484
1485+ aAttrs = a .attributeNames ()
1486+ bAttrs = b .attributeNames ()
1487+ # need to remove the animatedObjectPrimVars attribute since it doesn't exist in some circumstances
1488+ if "sceneInterface:animatedObjectPrimVars" in aAttrs :
1489+ aAttrs .remove ( "sceneInterface:animatedObjectPrimVars" )
1490+ if "sceneInterface:animatedObjectPrimVars" in bAttrs :
1491+ bAttrs .remove ( "sceneInterface:animatedObjectPrimVars" )
1492+ self .assertEqual ( aAttrs , bAttrs )
1493+ for attr in aAttrs :
1494+ self .assertTrue ( a .hasAttribute ( attr ) )
1495+ self .assertTrue ( b .hasAttribute ( attr ) )
1496+ self .assertEqual ( a .readAttribute ( attr , time ), b .readAttribute ( attr , time ) )
1497+
14131498 self .assertEqual ( a .hasObject (), b .hasObject () )
14141499 if a .hasObject () :
14151500 ma = a .readObject ( time )
@@ -1654,7 +1739,7 @@ def testRopLinked( self ) :
16541739
16551740 def testRopForceObjects ( self ) :
16561741
1657- s = self .writeSCC ()
1742+ s = self .writeAttributeSCC ()
16581743 d = s .child ( "1" ).createChild ( "4" )
16591744 e = d .createChild ( "5" )
16601745 box = IECore .MeshPrimitive .createBox (IECore .Box3f (IECore .V3f (0 ),IECore .V3f (1 )))
@@ -1693,14 +1778,15 @@ def testLinks( bakedObjects = None ) :
16931778 self .assertTrue ( b .hasAttribute ( IECore .LinkedScene .rootLinkAttribute ) )
16941779 self .assertEqual ( b .readAttribute ( IECore .LinkedScene .fileNameLinkAttribute , 0 ), IECore .StringData ( TestSceneCache .__testFile ) )
16951780 self .assertEqual ( b .readAttribute ( IECore .LinkedScene .rootLinkAttribute , 0 ), IECore .InternedStringVectorData ( [ "1" , "2" ] ) )
1696- self .assertEqual ( b .readAttribute ( IECore .LinkedScene .timeLinkAttribute , 0 ), IECore .DoubleData ( 1.0 / hou . fps () ) )
1781+ self .assertEqual ( b .readAttribute ( IECore .LinkedScene .timeLinkAttribute , 0 ), IECore .DoubleData ( 0 ) )
16971782 d = a .child ( "4" )
16981783 self .assertFalse ( d .hasAttribute ( IECore .LinkedScene .linkAttribute ) )
16991784 self .assertFalse ( d .hasAttribute ( IECore .LinkedScene .fileNameLinkAttribute ) )
17001785 self .assertFalse ( d .hasAttribute ( IECore .LinkedScene .rootLinkAttribute ) )
17011786 self .assertFalse ( d .hasAttribute ( IECore .LinkedScene .timeLinkAttribute ) )
17021787
17031788 # force b and below as links even though they are expanded
1789+ hou .setTime ( - 1.0 / hou .fps () )
17041790 xform = self .xform ()
17051791 xform .parm ( "expand" ).pressButton ()
17061792 rop = self .rop ( xform )
0 commit comments