From bbd4a07afedc6b347331d7573a3e818a510dfe54 Mon Sep 17 00:00:00 2001 From: Yannic Schoof Date: Thu, 4 Dec 2025 12:03:32 -0800 Subject: [PATCH] CoordinateSystem: Backwards compatibility CoordinateSystem used to have a transform property which has been removed in favour of accessing transforms independently of objects. We provide a way to retrieve this information from SceneInterfaces written prior to removal, as blind data. --- src/IECoreScene/CoordinateSystem.cpp | 28 ++++++++++++++++++ test/IECoreScene/CoordinateSystemTest.py | 8 +++++ .../data/coordinateSystemLegacyTransform.cob | Bin 0 -> 1948 bytes 3 files changed, 36 insertions(+) create mode 100644 test/IECoreScene/data/coordinateSystemLegacyTransform.cob 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 0000000000000000000000000000000000000000..f46ca3419334f638a2849ac459f48b75c0093cb9 GIT binary patch literal 1948 zcmah}O>Y}j6g@Nc*p3s&ANg{eq#m~gBLuN0@kfY|;v`OJCE}RIR6vp1i9M;O*fZ|T zn8s{qS+GQ9OOfb;MHeiB5EVFdbhT7KaZxKQ=3g$B^NU4}7mdys?bI7rt8drVcP?(KjlQAoHa&GoQ}e~urSfV~Q@5%Obt%78M5EnT zt434RR#Z(}EtXab+R4Ut$JV`5Shv@J;|<{Zb>1l;*CN{74SV0s?QOi3bB&vQ!)h9C z&NOmv+xFbtb;B|ovzhDa13lNbJk#qKEo|Dh(=sjHGxi3qXLO-4mqo3(SinHHEVJn% zBm=UP@jq4oVPZZ>TDr7?EI~q6K?Kzx0=`-7!Vf6|-*z0MNFh18j$#-i6@;@$N3xhm zN3&3{0i};}1pbdOh$sX}#tdBu zm+MH6iM+?zC1Z?B1V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