@@ -1447,7 +1447,7 @@ def testNode( node ) :
1447
1447
testNode ( self .xform () )
1448
1448
testNode ( self .geometry () )
1449
1449
1450
- def writeAnimSCC ( self ) :
1450
+ def writeAnimSCC ( self , rotate = False ) :
1451
1451
1452
1452
scene = self .writeSCC ()
1453
1453
sc1 = scene .child ( str ( 1 ) )
@@ -1458,14 +1458,20 @@ def writeAnimSCC( self ) :
1458
1458
for time in [ 0.5 , 1 , 1.5 , 2 , 5 , 10 ] :
1459
1459
1460
1460
matrix = IECore .M44d .createTranslated ( IECore .V3d ( 1 , time , 0 ) )
1461
+ if rotate :
1462
+ matrix .rotate ( IECore .V3d ( time , 0 , 0 ) )
1461
1463
sc1 .writeTransform ( IECore .M44dData ( matrix ), time )
1462
1464
1463
1465
mesh ["Cs" ] = IECore .PrimitiveVariable ( IECore .PrimitiveVariable .Interpolation .Uniform , IECore .V3fVectorData ( [ IECore .V3f ( time , 1 , 0 ) ] * 6 ) )
1464
1466
sc2 .writeObject ( mesh , time )
1465
1467
matrix = IECore .M44d .createTranslated ( IECore .V3d ( 2 , time , 0 ) )
1468
+ if rotate :
1469
+ matrix .rotate ( IECore .V3d ( time , 0 , 0 ) )
1466
1470
sc2 .writeTransform ( IECore .M44dData ( matrix ), time )
1467
1471
1468
1472
matrix = IECore .M44d .createTranslated ( IECore .V3d ( 3 , time , 0 ) )
1473
+ if rotate :
1474
+ matrix .rotate ( IECore .V3d ( time , 0 , 0 ) )
1469
1475
sc3 .writeTransform ( IECore .M44dData ( matrix ), time )
1470
1476
1471
1477
return scene
@@ -2575,6 +2581,108 @@ def testTransformOverride( self ) :
2575
2581
self .assertEqual ( IECore .M44d ( list (b .parmTransform ().asTuple ()) ), IECore .M44d .createTranslated ( IECore .V3d ( 2 , time , 0 ) ) )
2576
2582
self .assertEqual ( IECore .M44d ( list (c .parmTransform ().asTuple ()) ), IECore .M44d .createTranslated ( IECore .V3d ( time , 0 , 0 ) ) )
2577
2583
2584
+ def testGeometryTypes ( self ) :
2585
+
2586
+ self .writeAnimSCC ()
2587
+ times = range ( 0 , 10 )
2588
+ halves = [ x + 0.5 for x in times ]
2589
+ quarters = [ x + 0.25 for x in times ]
2590
+ times .extend ( [ x + 0.75 for x in times ] )
2591
+ times .extend ( halves )
2592
+ times .extend ( quarters )
2593
+ times .sort ()
2594
+
2595
+ spf = 1.0 / hou .fps ()
2596
+
2597
+ node = self .sop ()
2598
+ node .parm ( "geometryType" ).set ( IECoreHoudini .SceneCacheNode .GeometryType .Cortex )
2599
+ for time in times :
2600
+ hou .setTime ( time - spf )
2601
+ prims = node .geometry ().prims ()
2602
+ self .assertEqual ( len (prims ), 3 )
2603
+ nameAttr = node .geometry ().findPrimAttrib ( "name" )
2604
+ self .assertEqual ( nameAttr .strings (), tuple ( [ '/1' , '/1/2' , '/1/2/3' ] ) )
2605
+ for name in nameAttr .strings () :
2606
+ self .assertEqual ( len ([ x for x in prims if x .attribValue ( "name" ) == name ]), 1 )
2607
+ self .assertEqual ( prims [0 ].vertices ()[0 ].point ().position (), hou .Vector3 ( 1.5 , time + 0.5 , 0.5 ) )
2608
+ self .assertEqual ( prims [1 ].vertices ()[0 ].point ().position (), hou .Vector3 ( 3.5 , time * 2 + 0.5 , 0.5 ) )
2609
+ self .assertEqual ( prims [2 ].vertices ()[0 ].point ().position (), hou .Vector3 ( 6.5 , time * 3 + 0.5 , 0.5 ) )
2610
+
2611
+ node .parm ( "geometryType" ).set ( IECoreHoudini .SceneCacheNode .GeometryType .Houdini )
2612
+ for time in times :
2613
+ hou .setTime ( time - spf )
2614
+ prims = node .geometry ().prims ()
2615
+ self .assertEqual ( len (prims ), 18 )
2616
+ nameAttr = node .geometry ().findPrimAttrib ( "name" )
2617
+ self .assertEqual ( nameAttr .strings (), tuple ( [ '/1' , '/1/2' , '/1/2/3' ] ) )
2618
+ for name in nameAttr .strings () :
2619
+ self .assertEqual ( len ([ x for x in prims if x .attribValue ( "name" ) == name ]), 6 )
2620
+ self .assertEqual ( prims [0 ].vertex ( 0 ).point ().position (), hou .Vector3 ( 1 , time , 0 ) )
2621
+ self .assertEqual ( prims [4 ].vertex ( 0 ).point ().position (), hou .Vector3 ( 2 , time + 1 , 1 ) )
2622
+ self .assertEqual ( prims [6 ].vertex ( 0 ).point ().position (), hou .Vector3 ( 3 , time * 2 , 0 ) )
2623
+ self .assertEqual ( prims [10 ].vertex ( 0 ).point ().position (), hou .Vector3 ( 4 , time * 2 + 1 , 1 ) )
2624
+ self .assertEqual ( prims [12 ].vertex ( 0 ).point ().position (), hou .Vector3 ( 6 , time * 3 , 0 ) )
2625
+ self .assertEqual ( prims [16 ].vertex ( 0 ).point ().position (), hou .Vector3 ( 7 , time * 3 + 1 , 1 ) )
2626
+
2627
+ node .parm ( "geometryType" ).set ( IECoreHoudini .SceneCacheNode .GeometryType .BoundingBox )
2628
+ for time in times :
2629
+ hou .setTime ( time - spf )
2630
+ prims = node .geometry ().prims ()
2631
+ self .assertEqual ( len (prims ), 18 )
2632
+ nameAttr = node .geometry ().findPrimAttrib ( "name" )
2633
+ self .assertEqual ( nameAttr .strings (), tuple ( [ '/1' , '/1/2' , '/1/2/3' ] ) )
2634
+ for name in nameAttr .strings () :
2635
+ self .assertEqual ( len ([ x for x in prims if x .attribValue ( "name" ) == name ]), 6 )
2636
+ self .assertEqual ( prims [0 ].vertex ( 0 ).point ().position (), hou .Vector3 ( 1 , time , 0 ) )
2637
+ self .assertEqual ( prims [4 ].vertex ( 0 ).point ().position (), hou .Vector3 ( 7 , time * 3 + 1 , 1 ) )
2638
+ self .assertEqual ( prims [6 ].vertex ( 0 ).point ().position (), hou .Vector3 ( 3 , time * 2 , 0 ) )
2639
+ self .assertEqual ( prims [10 ].vertex ( 0 ).point ().position (), hou .Vector3 ( 7 , time * 3 + 1 , 1 ) )
2640
+ self .assertEqual ( prims [12 ].vertex ( 0 ).point ().position (), hou .Vector3 ( 6 , time * 3 , 0 ) )
2641
+ self .assertEqual ( prims [16 ].vertex ( 0 ).point ().position (), hou .Vector3 ( 7 , time * 3 + 1 , 1 ) )
2642
+
2643
+ # re-write with rotation to prove point cloud basis vectors are accurate
2644
+ self .writeAnimSCC ( rotate = True )
2645
+
2646
+ scene = IECore .SharedSceneInterfaces .get ( TestSceneCache .__testFile )
2647
+ a = scene .child ( "1" )
2648
+ b = a .child ( "2" )
2649
+ c = b .child ( "3" )
2650
+
2651
+ node .parm ( "reload" ).pressButton ()
2652
+ node .parm ( "geometryType" ).set ( IECoreHoudini .SceneCacheNode .GeometryType .PointCloud )
2653
+ for time in times :
2654
+ hou .setTime ( time - spf )
2655
+ prims = node .geometry ().prims ()
2656
+ self .assertEqual ( len (prims ), 3 )
2657
+ nameAttr = node .geometry ().findPrimAttrib ( "name" )
2658
+ self .assertEqual ( nameAttr .strings (), tuple ( [ '/1' , '/1/2' , '/1/2/3' ] ) )
2659
+ for name in nameAttr .strings () :
2660
+ self .assertEqual ( len ([ x for x in prims if x .attribValue ( "name" ) == name ]), 1 )
2661
+
2662
+ aPoint = prims [0 ].vertices ()[0 ].point ()
2663
+ bPoint = prims [1 ].vertices ()[0 ].point ()
2664
+ cPoint = prims [2 ].vertices ()[0 ].point ()
2665
+
2666
+ aWorld = scene .readTransformAsMatrix ( time ) * a .readTransformAsMatrix ( time )
2667
+ bWorld = aWorld * b .readTransformAsMatrix ( time )
2668
+ cWorld = bWorld * c .readTransformAsMatrix ( time )
2669
+
2670
+ self .assertTrue ( IECore .V3d ( list (aPoint .position ()) ).equalWithAbsError ( aWorld .multVecMatrix ( a .readBound ( time ).center () ), 1e-6 ) )
2671
+ self .assertTrue ( IECore .V3d ( list (bPoint .position ()) ).equalWithAbsError ( bWorld .multVecMatrix ( b .readBound ( time ).center () ), 1e-6 ) )
2672
+ self .assertTrue ( IECore .V3d ( list (cPoint .position ()) ).equalWithAbsError ( cWorld .multVecMatrix ( c .readBound ( time ).center () ), 1e-6 ) )
2673
+
2674
+ self .assertTrue ( IECore .V3d ( list (aPoint .attribValue ( "basis1" )) ).equalWithAbsError ( IECore .V3d ( aWorld [(0 ,0 )], aWorld [(0 ,1 )], aWorld [(0 ,2 )] ), 1e-6 ) )
2675
+ self .assertTrue ( IECore .V3d ( list (aPoint .attribValue ( "basis2" )) ).equalWithAbsError ( IECore .V3d ( aWorld [(1 ,0 )], aWorld [(1 ,1 )], aWorld [(1 ,2 )] ), 1e-6 ) )
2676
+ self .assertTrue ( IECore .V3d ( list (aPoint .attribValue ( "basis3" )) ).equalWithAbsError ( IECore .V3d ( aWorld [(2 ,0 )], aWorld [(2 ,1 )], aWorld [(2 ,2 )] ), 1e-6 ) )
2677
+
2678
+ self .assertTrue ( IECore .V3d ( list (bPoint .attribValue ( "basis1" )) ).equalWithAbsError ( IECore .V3d ( bWorld [(0 ,0 )], bWorld [(0 ,1 )], bWorld [(0 ,2 )] ), 1e-6 ) )
2679
+ self .assertTrue ( IECore .V3d ( list (bPoint .attribValue ( "basis2" )) ).equalWithAbsError ( IECore .V3d ( bWorld [(1 ,0 )], bWorld [(1 ,1 )], bWorld [(1 ,2 )] ), 1e-6 ) )
2680
+ self .assertTrue ( IECore .V3d ( list (bPoint .attribValue ( "basis3" )) ).equalWithAbsError ( IECore .V3d ( bWorld [(2 ,0 )], bWorld [(2 ,1 )], bWorld [(2 ,2 )] ), 1e-6 ) )
2681
+
2682
+ self .assertTrue ( IECore .V3d ( list (cPoint .attribValue ( "basis1" )) ).equalWithAbsError ( IECore .V3d ( cWorld [(0 ,0 )], cWorld [(0 ,1 )], cWorld [(0 ,2 )] ), 1e-6 ) )
2683
+ self .assertTrue ( IECore .V3d ( list (cPoint .attribValue ( "basis2" )) ).equalWithAbsError ( IECore .V3d ( cWorld [(1 ,0 )], cWorld [(1 ,1 )], cWorld [(1 ,2 )] ), 1e-6 ) )
2684
+ self .assertTrue ( IECore .V3d ( list (cPoint .attribValue ( "basis3" )) ).equalWithAbsError ( IECore .V3d ( cWorld [(2 ,0 )], cWorld [(2 ,1 )], cWorld [(2 ,2 )] ), 1e-6 ) )
2685
+
2578
2686
def tearDown ( self ) :
2579
2687
2580
2688
for f in [ TestSceneCache .__testFile , TestSceneCache .__testOutFile , TestSceneCache .__testLinkedOutFile , TestSceneCache .__testHip , TestSceneCache .__testBgeo , TestSceneCache .__testBgeoGz , TestSceneCache .__testGeo ] :
0 commit comments