Skip to content

Commit 2a57b9c

Browse files
committed
CoordinateSystem: Backwards compatibility
CoordinateSystem used to derive from the deprecated and removed StateRenderable holding additional transform information for the renderer. A better approach that is also used in Gaffer, the transform information is better stored as separate transform information. Cortex 10.6 also removed all DCC integrations, i.e. IECoreMaya, which stored, for example Locator transformation on the CoordinateSystem. We provide a way to still retrieve this information from old SceneCaches, although not fully transparent and backwards compatible. Clients of CoordinateSystem will need to be adjusted if needed. The `M44fData` is stored as `LegacyTransform` in the `BlindData` of the CoordinateSystem
1 parent c49955a commit 2a57b9c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/IECoreScene/CoordinateSystem.cpp

Lines changed: 44 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,46 @@ 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 derive from the deprecated and removed StateRenderable
113+
// holding additional transform information for the renderer. A better approach that is also
114+
// used in Gaffer, the transform information is better stored as separate transform information.
115+
// Cortex 10.6 also removed all DCC integrations, i.e. IECoreMaya, which stored, for example
116+
// Locator transformation on the CoordinateSystem. We provide a way to still retrieve this
117+
// information from old SceneCaches, although not fully transparent and backwards compatible.
118+
// Clients of CoordinateSystem will need to be adjusted if needed.
119+
120+
// We look for a matrix entry somewhere underneath the CoordinateSystem, directly read it from
121+
// there instead of loading an object and stash it in the BlindData.
122+
const IndexedIO::EntryID matrixEntry( "matrix" );
123+
Imath::M44f matrix;
124+
125+
std::function<void(ConstIndexedIOPtr)> findMatrixEntry = [&]( ConstIndexedIOPtr directory )
126+
{
127+
if( directory->hasEntry( matrixEntry ) )
128+
{
129+
float *f = matrix.getValue();
130+
directory->read( matrixEntry, f, 16 );
131+
}
132+
133+
IndexedIO::EntryIDList levelDirectories;
134+
directory->entryIds( levelDirectories, IndexedIO::EntryType::Directory );
135+
136+
for ( auto levelDirectory : levelDirectories )
137+
{
138+
ConstIndexedIOPtr subdirectory = directory->subdirectory( levelDirectory, IndexedIO::MissingBehaviour::NullIfMissing );
139+
if( subdirectory )
140+
{
141+
findMatrixEntry( subdirectory );
142+
}
143+
}
144+
};
145+
146+
findMatrixEntry( container );
147+
if( matrix != Imath::identity44f )
148+
{
149+
blindData()->writable()["LegacyTransform"] = new IECore::M44fData( matrix );
150+
}
107151
}
108152

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

0 commit comments

Comments
 (0)