Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/IECoreScene/CoordinateSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/IECoreScene/CoordinateSystemTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) ) :
Expand Down
Binary file not shown.
Loading