Skip to content

Commit 11d80d2

Browse files
committed
AlembicScene : Account for visibility in attributes hash
This fixes the failure to load animated visibility demonstrated in #944.
1 parent 264fd2b commit 11d80d2

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

contrib/IECoreAlembic/src/IECoreAlembic/AlembicScene.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,12 +850,26 @@ class AlembicScene::AlembicReader : public AlembicIO
850850
const IXformSchema &schema = m_xform.getSchema();
851851
ICompoundProperty compoundProperty = schema.getUserProperties();
852852

853+
bool haveAttributes = false;
854+
bool haveAnimation = false;
855+
853856
if( compoundProperty.valid() )
857+
{
858+
haveAttributes = true;
859+
haveAnimation = haveAnimation || isAnimated( compoundProperty );
860+
}
861+
862+
if( auto visibilityReader = scalarPropertyReader( visibilityName ) )
863+
{
864+
haveAttributes = true;
865+
haveAnimation = haveAnimation || !visibilityReader->isConstant();
866+
}
867+
868+
if( haveAttributes )
854869
{
855870
h.append( fileName() );
856871
h.append( m_xform ? m_xform.getFullName() : "/" );
857-
858-
if( isAnimated( compoundProperty ) )
872+
if( haveAnimation )
859873
{
860874
h.append( time );
861875
}

contrib/IECoreAlembic/test/IECoreAlembic/AlembicSceneTest.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,24 +1964,46 @@ def testVisibilityAttribute( self ) :
19641964

19651965
fileName = os.path.join( self.temporaryDirectory(), "visibilityAttribute.abc" )
19661966
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Write )
1967+
19671968
root.createChild( "withoutAttribute" )
1968-
child = root.createChild( "withAttribute" )
1969+
1970+
child = root.createChild( "withAnimatedAttribute" )
19691971
child.writeAttribute( "scene:visible", IECore.BoolData( True ), 0 )
19701972
child.writeAttribute( "scene:visible", IECore.BoolData( False ), 1 )
19711973

1974+
child = root.createChild( "withStaticAttribute" )
1975+
child.writeAttribute( "scene:visible", IECore.BoolData( True ), 0 )
1976+
19721977
del child, root
19731978

19741979
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
19751980

1976-
child = root.child( "withAttribute" )
1981+
child = root.child( "withoutAttribute" )
1982+
self.assertNotIn( "scene:visible", child.attributeNames() )
1983+
self.assertFalse( child.hasAttribute( "scene:visible" ) )
1984+
withoutHash = child.hash( IECoreScene.SceneInterface.HashType.AttributesHash, 0 )
1985+
1986+
child = root.child( "withAnimatedAttribute" )
19771987
self.assertIn( "scene:visible", child.attributeNames() )
19781988
self.assertTrue( child.hasAttribute( "scene:visible" ) )
19791989
self.assertEqual( child.readAttribute( "scene:visible", 0 ), IECore.BoolData( True ) )
19801990
self.assertEqual( child.readAttribute( "scene:visible", 1 ), IECore.BoolData( False ) )
1991+
animatedFrame1Hash = child.hash( IECoreScene.SceneInterface.HashType.AttributesHash, 1 )
1992+
self.assertNotEqual( child.hash( IECoreScene.SceneInterface.HashType.AttributesHash, 0 ), animatedFrame1Hash )
1993+
self.assertNotEqual( child.hash( IECoreScene.SceneInterface.HashType.AttributesHash, 0 ), withoutHash )
1994+
self.assertNotEqual( animatedFrame1Hash, withoutHash )
19811995

1982-
child = root.child( "withoutAttribute" )
1983-
self.assertNotIn( "scene:visible", child.attributeNames() )
1984-
self.assertFalse( child.hasAttribute( "scene:visible" ) )
1996+
child = root.child( "withStaticAttribute" )
1997+
self.assertIn( "scene:visible", child.attributeNames() )
1998+
self.assertTrue( child.hasAttribute( "scene:visible" ) )
1999+
self.assertEqual( child.readAttribute( "scene:visible", 0 ), IECore.BoolData( True ) )
2000+
self.assertEqual( child.readAttribute( "scene:visible", 1 ), IECore.BoolData( True ) )
2001+
self.assertEqual(
2002+
child.hash( IECoreScene.SceneInterface.HashType.AttributesHash, 0 ),
2003+
child.hash( IECoreScene.SceneInterface.HashType.AttributesHash, 1 ),
2004+
)
2005+
self.assertNotEqual( child.hash( IECoreScene.SceneInterface.HashType.AttributesHash, 1 ), animatedFrame1Hash )
2006+
self.assertNotEqual( child.hash( IECoreScene.SceneInterface.HashType.AttributesHash, 1 ), withoutHash )
19852007

19862008
if __name__ == "__main__":
19872009
unittest.main()

0 commit comments

Comments
 (0)