@@ -47,10 +47,12 @@ class SceneShapeTest( IECoreMaya.TestCase ) :
4747 __testPlugFile = "test/testPlug.scc"
4848 __testPlugAnimFile = "test/testPlugAnim.scc"
4949 __testPlugAttrFile = "test/testPlugAttr.scc"
50+ __testLinkFile = "test/test.lscc"
5051
5152 def setUp ( self ):
5253 super ( SceneShapeTest , self ).setUp ()
53- self ._node = maya .cmds .createNode ( "ieSceneShape" )
54+ self ._shapeType = "ieSceneShape"
55+ self ._node = maya .cmds .createNode ( self ._shapeType )
5456
5557 def writeSCC ( self , file , rotation = imath .V3d ( 0 , 0 , 0 ), time = 0 ) :
5658
@@ -550,10 +552,113 @@ def testLinkedLiveSceneTags( self ) :
550552 self .assertEqual ( sorted ([ str (x ) for x in child2 .readTags () ]), ["ObjectType:MeshPrimitive" ,"b" ] )
551553 self .assertEqual ( sorted ([ str (x ) for x in child3 .readTags () ]), ["ObjectType:MeshPrimitive" ,"c" ] )
552554
555+ def testReadSceneShapeLink ( self ):
556+
557+ # Create an .lscc with three child locations that we will time remap once we have read it back into maya
558+ self .writeAnimSCC ( SceneShapeTest .__testFile )
559+
560+ sceneCache = IECoreScene .SceneCache ( SceneShapeTest .__testFile , IECore .IndexedIO .OpenMode .Read )
561+ linkedScene = IECoreScene .LinkedScene ( SceneShapeTest .__testLinkFile , IECore .IndexedIO .OpenMode .Write )
562+
563+ noRemapLocation = linkedScene .createChild ( "NoRemap" )
564+ noRemapLocation .writeLink ( sceneCache )
565+ remapLocation = linkedScene .createChild ( "Remap" )
566+ remapLocation .writeLink ( sceneCache )
567+ holdLocation = linkedScene .createChild ( "Hold" )
568+ holdLocation .writeLink ( sceneCache )
569+
570+ del noRemapLocation , remapLocation , holdLocation
571+ del linkedScene
572+
573+ # Create a root level scene shape node to read in the .lscc
574+ rootFn = IECoreMaya .FnSceneShape .create ( "Root" , shapeType = self ._shapeType )
575+ maya .cmds .setAttr ( rootFn .name () + ".file" , SceneShapeTest .__testLinkFile , type = "string" )
576+ maya .cmds .setAttr ( rootFn .name () + ".root" , "/" , type = "string" )
577+
578+ holdFn , noRemapFn , remapFn = rootFn .expandOnce ()
579+
580+ # check that we don't have any other value than global maya time
581+ mayaTime = maya .cmds .currentTime ( query = True )
582+ self .assertEqual ( maya .cmds .getAttr ( holdFn .name () + ".time" ), mayaTime )
583+ self .assertEqual ( maya .cmds .getAttr ( noRemapFn .name () + ".time" ), mayaTime )
584+ self .assertEqual ( maya .cmds .getAttr ( remapFn .name () + ".time" ), mayaTime )
585+
586+ # break the time connection to create a time hold
587+ maya .cmds .disconnectAttr ( rootFn .name () + ".outTime" , holdFn .name () + ".time" )
588+ maya .cmds .setAttr ( holdFn .name () + ".time" , 5.0 )
589+ self .assertEqual ( maya .cmds .getAttr ( holdFn .name () + ".time" ), 5.0 )
590+
591+ # add an offset to create a time remapping
592+ addNode = maya .cmds .createNode ( "addDoubleLinear" )
593+ maya .cmds .connectAttr ( "time1.outTime" , addNode + ".input1" )
594+ maya .cmds .setAttr ( addNode + ".input2" , 10.0 )
595+ maya .cmds .connectAttr ( addNode + ".output" , remapFn .name () + ".time" , force = True )
596+ self .assertEqual ( maya .cmds .getAttr ( remapFn .name () + ".time" ), 11.0 )
597+
598+ # set up the LiveScenes for actual testing
599+ holdFn .expandAll ()
600+ holdLiveScene = IECoreMaya .LiveScene ()
601+ holdLocation = holdLiveScene .child ( "|Root|Hold" )
602+ holdChild1 = holdLocation .child ( holdLocation .childNames ()[0 ] )
603+ holdChild2 = holdChild1 .child ( holdChild1 .childNames ()[0 ] )
604+ holdChild3 = holdChild2 .child ( holdChild2 .childNames ()[0 ] )
605+ holdLocations = [holdLocation , holdChild1 , holdChild2 , holdChild3 ]
606+
607+ noRemapFn .expandAll ()
608+ noRemapLiveScene = IECoreMaya .LiveScene ()
609+ noRemapLocation = noRemapLiveScene .child ( "|Root|NoRemap" )
610+ noRemapChild1 = noRemapLocation .child ( noRemapLocation .childNames ()[0 ] )
611+ noRemapChild2 = noRemapChild1 .child ( noRemapChild1 .childNames ()[0 ] )
612+ noRemapChild3 = noRemapChild2 .child ( noRemapChild2 .childNames ()[0 ] )
613+ noRemapLocations = [noRemapLocation , noRemapChild1 , noRemapChild2 , noRemapChild3 ]
614+
615+ remapFn .expandAll ()
616+ remapLiveScene = IECoreMaya .LiveScene ()
617+ remapLocation = remapLiveScene .child ( "|Root|Remap" )
618+ remapChild1 = remapLocation .child ( remapLocation .childNames ()[0 ] )
619+ remapChild2 = remapChild1 .child ( remapChild1 .childNames ()[0 ] )
620+ remapChild3 = remapChild2 .child ( remapChild2 .childNames ()[0 ] )
621+ remapLocations = [remapLocation , remapChild1 , remapChild2 , remapChild3 ]
622+
623+ # set up some constants used during testing
624+ FPS = 24
625+ TIME_HOLD = 5.0
626+ TIME_OFFSET = 10.0
627+
628+ for time in [1.0 , 5.0 , 10.0 , 50.0 , 100.0 ]:
629+
630+ maya .cmds .currentTime ( time , edit = True )
631+ mayaTime = maya .cmds .currentTime ( query = True )
632+ # check that we actually moved in time
633+ self .assertEqual ( mayaTime , time )
634+
635+ # test no time remap
636+ for location in noRemapLocations :
637+ nodeTime = maya .cmds .getAttr ( str (location .dagPath ()) + ".outTime" )
638+ linkAttr = location .readAttribute ( IECoreScene .LinkedScene .linkAttribute , mayaTime )
639+ self .assertFalse ( linkAttr .has_key ( "time" ) )
640+ self .assertEqual ( nodeTime , mayaTime )
641+
642+ # test time remap
643+ for location in remapLocations :
644+ linkAttr = location .readAttribute ( IECoreScene .LinkedScene .linkAttribute , mayaTime )
645+ self .assertTrue ( linkAttr .has_key ( "time" ) )
646+ self .assertEqual ( linkAttr ["time" ].value * FPS , mayaTime + TIME_OFFSET )
647+
648+ # test time hold
649+ for location in holdLocations :
650+ linkAttr = location .readAttribute ( IECoreScene .LinkedScene .linkAttribute , mayaTime )
651+ self .assertTrue ( linkAttr .has_key ( "time" ) )
652+ self .assertEqual ( linkAttr ["time" ].value * FPS , TIME_HOLD )
653+
553654
554655 def tearDown ( self ) :
555656
556- for f in [ SceneShapeTest .__testFile , SceneShapeTest .__testPlugFile , SceneShapeTest .__testPlugAnimFile , SceneShapeTest .__testPlugAttrFile ] :
657+ for f in [
658+ SceneShapeTest .__testFile , SceneShapeTest .__testPlugFile ,
659+ SceneShapeTest .__testPlugAnimFile , SceneShapeTest .__testPlugAttrFile ,
660+ SceneShapeTest .__testLinkFile
661+ ]:
557662 if os .path .exists ( f ) :
558663 os .remove ( f )
559664
0 commit comments