Skip to content

Commit bbd4a07

Browse files
committed
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.
1 parent c49955a commit bbd4a07

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/IECoreScene/CoordinateSystem.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@
3434

3535
#include "IECoreScene/CoordinateSystem.h"
3636

37+
#include "IECore/SimpleTypedData.h"
3738
#include "IECore/MurmurHash.h"
3839

40+
#include "Imath/ImathMatrix.h"
41+
#include "Imath/ImathMatrixAlgo.h"
42+
3943
using namespace IECore;
4044
using namespace IECoreScene;
4145
using namespace boost;
@@ -104,6 +108,30 @@ void CoordinateSystem::load( LoadContextPtr context )
104108
unsigned int v = m_ioVersion;
105109
ConstIndexedIOPtr container = context->container( staticTypeName(), v );
106110
container->read( g_nameEntry, m_name );
111+
112+
// CoordinateSystem used to have a transform property, but that has
113+
// been removed in favour of transforms being accessed independently
114+
// of objects in SceneInterface (and Gaffer). If a legacy transform
115+
// exists, load it and stash it as blind data for use by legacy tools.
116+
117+
ConstIndexedIOPtr matrixTransformContainer = container;
118+
for( auto name : { "transform", "data", "MatrixTransform", "data" } )
119+
{
120+
matrixTransformContainer = matrixTransformContainer->subdirectory( name, IndexedIO::MissingBehaviour::NullIfMissing );
121+
if( !matrixTransformContainer )
122+
{
123+
break;
124+
}
125+
}
126+
127+
const IndexedIO::EntryID matrixEntry( "matrix" );
128+
if( matrixTransformContainer && matrixTransformContainer->hasEntry( matrixEntry ) )
129+
{
130+
M44fDataPtr matrix = new M44fData;
131+
float *f = matrix->writable().getValue();
132+
matrixTransformContainer->read( matrixEntry, f, 16 );
133+
blindData()->writable()["LegacyTransform"] = matrix;
134+
}
107135
}
108136

109137
void CoordinateSystem::hash( MurmurHash &h ) const

test/IECoreScene/CoordinateSystemTest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ def testEquality( self ) :
8787
self.assertNotEqual( c2, c1 )
8888
c1.setName( "test" )
8989

90+
def testLegacyTransform( self ) :
91+
92+
c = IECore.ObjectReader( os.path.join( "test", "IECoreScene", "data", "coordinateSystemLegacyTransform.cob" ) ).read()
93+
self.assertTrue( c.blindData().has_key( "LegacyTransform" ) )
94+
95+
expected = imath.M44f().translate( imath.V3f( 0, 2, 0 ) )
96+
self.assertEqual( c.blindData()["LegacyTransform"].value, expected )
97+
9098
def tearDown( self ) :
9199

92100
if os.path.exists( os.path.join( "test", "IECore", "data", "coordSys.cob" ) ) :
1.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)