diff --git a/src/IECoreScene/CoordinateSystem.cpp b/src/IECoreScene/CoordinateSystem.cpp index e5e27833a6..86737e24f4 100644 --- a/src/IECoreScene/CoordinateSystem.cpp +++ b/src/IECoreScene/CoordinateSystem.cpp @@ -34,8 +34,12 @@ #include "IECoreScene/CoordinateSystem.h" +#include "IECore/SimpleTypedData.h" #include "IECore/MurmurHash.h" +#include "Imath/ImathMatrix.h" +#include "Imath/ImathMatrixAlgo.h" + using namespace IECore; using namespace IECoreScene; using namespace boost; @@ -104,6 +108,30 @@ void CoordinateSystem::load( LoadContextPtr context ) unsigned int v = m_ioVersion; ConstIndexedIOPtr container = context->container( staticTypeName(), v ); container->read( g_nameEntry, m_name ); + + // CoordinateSystem used to have a transform property, but that has + // been removed in favour of transforms being accessed independently + // of objects in SceneInterface (and Gaffer). If a legacy transform + // exists, load it and stash it as blind data for use by legacy tools. + + ConstIndexedIOPtr matrixTransformContainer = container; + for( auto name : { "transform", "data", "MatrixTransform", "data" } ) + { + matrixTransformContainer = matrixTransformContainer->subdirectory( name, IndexedIO::MissingBehaviour::NullIfMissing ); + if( !matrixTransformContainer ) + { + break; + } + } + + const IndexedIO::EntryID matrixEntry( "matrix" ); + if( matrixTransformContainer && matrixTransformContainer->hasEntry( matrixEntry ) ) + { + M44fDataPtr matrix = new M44fData; + float *f = matrix->writable().getValue(); + matrixTransformContainer->read( matrixEntry, f, 16 ); + blindData()->writable()["LegacyTransform"] = matrix; + } } void CoordinateSystem::hash( MurmurHash &h ) const diff --git a/test/IECoreScene/CoordinateSystemTest.py b/test/IECoreScene/CoordinateSystemTest.py index c02bdd6a6f..5bbe8ad1fc 100644 --- a/test/IECoreScene/CoordinateSystemTest.py +++ b/test/IECoreScene/CoordinateSystemTest.py @@ -87,6 +87,14 @@ def testEquality( self ) : self.assertNotEqual( c2, c1 ) c1.setName( "test" ) + def testLegacyTransform( self ) : + + c = IECore.ObjectReader( os.path.join( "test", "IECoreScene", "data", "coordinateSystemLegacyTransform.cob" ) ).read() + self.assertTrue( c.blindData().has_key( "LegacyTransform" ) ) + + expected = imath.M44f().translate( imath.V3f( 0, 2, 0 ) ) + self.assertEqual( c.blindData()["LegacyTransform"].value, expected ) + def tearDown( self ) : if os.path.exists( os.path.join( "test", "IECore", "data", "coordSys.cob" ) ) : diff --git a/test/IECoreScene/data/coordinateSystemLegacyTransform.cob b/test/IECoreScene/data/coordinateSystemLegacyTransform.cob new file mode 100644 index 0000000000..f46ca34193 Binary files /dev/null and b/test/IECoreScene/data/coordinateSystemLegacyTransform.cob differ