Skip to content

Commit 45e5018

Browse files
Merge branch 'RB-10.6'
2 parents 8232680 + f40127a commit 45e5018

File tree

7 files changed

+187
-4
lines changed

7 files changed

+187
-4
lines changed

Changes

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
10.7.x.x (relative to 10.7.0.0a2)
22
========
33

4+
Improvements
5+
------------
6+
7+
- ShaderNetworkAlgo : Added render adaptor API, allowing just-in-time modifications to
8+
ShaderNetworks during translation for rendering [^1].
9+
10+
Fixes
11+
-----
12+
13+
- CoordinateSystem : Added backwards compatibility for legacy transform [^1].
414

15+
[^1]: To be omitted from the notes for the final 10.7.0.0 release.
516

617
10.7.0.0a2 (relative to 10.7.0.0a1)
718
==========
@@ -31,11 +42,28 @@ Breaking Changes
3142
- Removed deprecated functions componentConnectionAdapterLabel, convertOSLComponentConnections, collapseSplineParameters, expandSplineParameters.
3243
- Switch support for Spline parameters to support for Ramp parameters.
3344

34-
10.6.x.x (relative to 10.6.2.1)
45+
10.6.x.x (relative to 10.6.3.0)
3546
========
3647

3748

3849

50+
10.6.3.0 (relative to 10.6.2.2)
51+
========
52+
53+
Improvements
54+
------------
55+
56+
- ShaderNetworkAlgo : Added render adaptor API, allowing just-in-time modifications to
57+
ShaderNetworks during translation for rendering.
58+
59+
10.6.2.2
60+
========
61+
62+
Fixes
63+
-----
64+
65+
- CoordinateSystem : Added backwards compatibility for legacy transform.
66+
3967
10.6.2.1 (relative to 10.6.2.0)
4068
========
4169

SConstruct

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,12 @@
4141
#
4242
##########################################################################
4343

44-
import SCons
45-
import shutil
4644
import glob
4745
import sys
4846
import os
4947
import re
5048
import subprocess
5149
import platform
52-
import distutils
5350

5451
EnsureSConsVersion( 3, 0, 2 ) # Substfile is a default builder as of 3.0.2
5552
SConsignFile()

include/IECoreScene/ShaderNetworkAlgo.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,39 @@ IECORESCENE_API void expandRamps( ShaderNetwork *network, std::string targetPref
137137
/// Used when dealing with SCC files written before Cortex 10.7, which used Spline*Data instead of Ramp*Data
138138
IECORESCENE_API void convertDeprecatedSplines( ShaderNetwork *network );
139139

140+
/// Render Adaptors
141+
/// ===============
142+
///
143+
/// Render adaptors are functions called to make "just in time" modifications to
144+
/// shader networks prior to rendering. They have access to a fully resolved
145+
/// attribute state, which can be used to drive the modifications. There is currently
146+
/// a single built-in adaptor, which uses `ShaderNetworkAlgo::applySubstitutions()`
147+
/// to allow strings such as texture paths to be substituted in from attributes that
148+
/// define them.
149+
///
150+
/// Adaptors are performance critical, so are deliberately not available via
151+
/// the Python API. They must be implemented in C++ only.
152+
153+
/// A function that adapts the shader network for rendering, given the full
154+
/// inherited `attributes` for an object. Must be threadsafe.
155+
using RenderAdaptorFunction = void (*)( ShaderNetwork *shaderNetwork, IECore::InternedString attributeName, const IECore::CompoundObject *attributes );
156+
/// A function that appends to `hash` to uniquely identify the work that will be
157+
/// performed by an AdaptorFunction. Particular attention must be paid to
158+
/// the performance of any such function, as it will be called frequently. If an
159+
/// adaptor will be a no-op, then nothing should be appended to the hash.
160+
/// Must be threadsafe.
161+
using RenderAdaptorHashFunction = void (*)( const ShaderNetwork *shaderNetwork, IECore::InternedString attributeName, const IECore::CompoundObject *attributes, IECore::MurmurHash &hash );
162+
163+
/// Registers an adaptor.
164+
IECORESCENE_API void registerRenderAdaptor( const std::string &name, RenderAdaptorHashFunction hashFunction, RenderAdaptorFunction adaptorFunction );
165+
/// Removes a previously registered adaptor with the specified name.
166+
IECORESCENE_API void deregisterRenderAdaptor( const std::string &name );
167+
168+
/// Hashes all the currently registered adaptors for `shaderNetwork`.
169+
IECORESCENE_API void hashRenderAdaptors( const ShaderNetwork *shaderNetwork, IECore::InternedString attributeName, const IECore::CompoundObject *attributes, IECore::MurmurHash &hash );
170+
/// Applies all the currently registered adaptors to `shaderNetwork`.
171+
IECORESCENE_API void applyRenderAdaptors( ShaderNetwork *shaderNetwork, IECore::InternedString attributeName, const IECore::CompoundObject *attributes );
172+
140173
} // namespace ShaderNetworkAlgo
141174

142175
} // namespace IECoreScene

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

src/IECoreScene/ShaderNetworkAlgo.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,3 +1423,92 @@ void ShaderNetworkAlgo::convertDeprecatedSplines( ShaderNetwork *network )
14231423

14241424
}
14251425
}
1426+
1427+
1428+
//////////////////////////////////////////////////////////////////////////
1429+
// Render Adaptors
1430+
//////////////////////////////////////////////////////////////////////////
1431+
1432+
namespace
1433+
{
1434+
1435+
struct RenderAdaptor
1436+
{
1437+
std::string name;
1438+
IECoreScene::ShaderNetworkAlgo::RenderAdaptorHashFunction hash;
1439+
IECoreScene::ShaderNetworkAlgo::RenderAdaptorFunction apply;
1440+
};
1441+
1442+
using RenderAdaptors = std::vector<RenderAdaptor>;
1443+
RenderAdaptors &renderAdaptors()
1444+
{
1445+
static RenderAdaptors g_renderAdaptors;
1446+
return g_renderAdaptors;
1447+
}
1448+
1449+
bool g_stringSubstitutionsRegistration = [] () {
1450+
1451+
IECoreScene::ShaderNetworkAlgo::registerRenderAdaptor(
1452+
"stringSubstitution",
1453+
// Hash
1454+
[] ( const IECoreScene::ShaderNetwork *shaderNetwork, InternedString attributeName, const IECore::CompoundObject *attributes, IECore::MurmurHash &hash ) {
1455+
shaderNetwork->hashSubstitutions( attributes, hash );
1456+
},
1457+
// Apply
1458+
[] ( IECoreScene::ShaderNetwork *shaderNetwork, InternedString attributeName, const IECore::CompoundObject *attributes ) {
1459+
shaderNetwork->applySubstitutions( attributes );
1460+
}
1461+
);
1462+
1463+
return true;
1464+
} ();
1465+
1466+
} // namespace
1467+
1468+
void ShaderNetworkAlgo::registerRenderAdaptor( const std::string &name, RenderAdaptorHashFunction hashFunction, RenderAdaptorFunction adaptorFunction )
1469+
{
1470+
// Replace existing adaptor if it exists.
1471+
RenderAdaptors &a = renderAdaptors();
1472+
for( auto &x : a )
1473+
{
1474+
if( x.name == name )
1475+
{
1476+
x.hash = hashFunction;
1477+
x.apply = adaptorFunction;
1478+
return;
1479+
}
1480+
}
1481+
// Otherwise add new adaptor.
1482+
a.push_back( { name, hashFunction, adaptorFunction } );
1483+
}
1484+
1485+
void ShaderNetworkAlgo::deregisterRenderAdaptor( const std::string &name )
1486+
{
1487+
RenderAdaptors &a = renderAdaptors();
1488+
a.erase(
1489+
std::remove_if(
1490+
a.begin(),
1491+
a.end(),
1492+
[&] ( const RenderAdaptor &x ) {
1493+
return x.name == name;
1494+
}
1495+
),
1496+
a.end()
1497+
);
1498+
}
1499+
1500+
void ShaderNetworkAlgo::hashRenderAdaptors( const IECoreScene::ShaderNetwork *shaderNetwork, InternedString attributeName, const IECore::CompoundObject *attributes, IECore::MurmurHash &hash )
1501+
{
1502+
for( const auto &x : renderAdaptors() )
1503+
{
1504+
x.hash( shaderNetwork, attributeName, attributes, hash );
1505+
}
1506+
}
1507+
1508+
void ShaderNetworkAlgo::applyRenderAdaptors( IECoreScene::ShaderNetwork *shaderNetwork, InternedString attributeName, const IECore::CompoundObject *attributes )
1509+
{
1510+
for( const auto &x : renderAdaptors() )
1511+
{
1512+
x.apply( shaderNetwork, attributeName, attributes );
1513+
}
1514+
}

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)