Skip to content

Commit 2726082

Browse files
authored
Merge pull request #6075 from johnhaddon/arnoldInt64
Arnold ParameterAlgo : Support Int64Data and UInt64Data
2 parents 28d115d + 70ef46a commit 2726082

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

Changes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
1.4.x.x (relative to 1.4.14.0)
22
=======
33

4+
Improvements
5+
------------
6+
7+
- Arnold : Added support for Int64Data and UInt64Data custom attributes, allowing USD's `instanceId` to be used as a custom attribute in the Instancer node. Warnings are emitted if values are out of range for Arnold's 32 bit ints.
8+
49
Fixes
510
-----
611

python/IECoreArnoldTest/ParameterAlgoTest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,23 @@ def testVectorIntData( self ) :
144144
IECoreArnold.ParameterAlgo.setParameter( n, "customV3i", IECore.V3iData( imath.V3i( 3, 4, 5 ) ) )
145145
self.assertEqual( arnold.AiNodeGetVec( n, "customV3i" ), arnold.AtVector( 3, 4, 5 ) )
146146

147+
def testInt64Data( self ) :
148+
149+
with IECoreArnold.UniverseBlock( writable = True ) as universe :
150+
151+
n = arnold.AiNode( universe, "ginstance" )
152+
with IECore.CapturingMessageHandler() as mh :
153+
IECoreArnold.ParameterAlgo.setParameter( n, "customInt64", IECore.Int64Data( 1 ) )
154+
IECoreArnold.ParameterAlgo.setParameter( n, "customUInt64", IECore.UInt64Data( 2 ) )
155+
IECoreArnold.ParameterAlgo.setParameter( n, "customInt64OutOfRange", IECore.Int64Data( 2 ** 31 ) )
156+
IECoreArnold.ParameterAlgo.setParameter( n, "customUInt64OutOfRange", IECore.UInt64Data( 2 ** 32 ) )
157+
158+
self.assertEqual( arnold.AiNodeGetInt( n, "customInt64" ), 1 )
159+
self.assertEqual( arnold.AiNodeGetUInt( n, "customUInt64" ), 2 )
160+
161+
self.assertEqual( len( mh.messages ), 2 )
162+
self.assertEqual( mh.messages[0].message, 'Int64Data value 2147483648 is out of range for parameter "customInt64OutOfRange"' )
163+
self.assertEqual( mh.messages[1].message, 'UInt64Data value 4294967296 is out of range for parameter "customUInt64OutOfRange"' )
164+
147165
if __name__ == "__main__":
148166
unittest.main()

src/IECoreArnold/ParameterAlgo.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,37 @@ void setParameterInternal( AtNode *node, AtString name, int parameterType, bool
9090
switch( parameterType )
9191
{
9292
case AI_TYPE_INT :
93-
if( const IntData *data = dataCast<IntData>( name, value ) )
93+
if( const Int64Data *data = runTimeCast<const Int64Data>( value ) )
94+
{
95+
int i = static_cast<int>( data->readable() );
96+
if( i == data->readable() )
97+
{
98+
AiNodeSetInt( node, name, i );
99+
}
100+
else
101+
{
102+
msg( Msg::Warning, "setParameter", fmt::format( "Int64Data value {} is out of range for parameter \"{}\"", data->readable(), name ) );
103+
}
104+
}
105+
else if( const IntData *data = dataCast<IntData>( name, value ) )
94106
{
95107
AiNodeSetInt( node, name, data->readable() );
96108
}
97109
break;
98110
case AI_TYPE_UINT :
99-
if( const IntData *data = runTimeCast<const IntData>( value ) )
111+
if( const UInt64Data *data = runTimeCast<const UInt64Data>( value ) )
112+
{
113+
unsigned int i = static_cast<unsigned int>( data->readable() );
114+
if( i == data->readable() )
115+
{
116+
AiNodeSetUInt( node, name, i );
117+
}
118+
else
119+
{
120+
msg( Msg::Warning, "setParameter", fmt::format( "UInt64Data value {} is out of range for parameter \"{}\"", data->readable(), name ) );
121+
}
122+
}
123+
else if( const IntData *data = runTimeCast<const IntData>( value ) )
100124
{
101125
AiNodeSetUInt( node, name, std::max( 0, data->readable() ) );
102126
}
@@ -459,9 +483,11 @@ int parameterType( IECore::TypeId dataType, bool &array )
459483
// non-array types
460484

461485
case IntDataTypeId :
486+
case Int64DataTypeId :
462487
array = false;
463488
return AI_TYPE_INT;
464489
case UIntDataTypeId :
490+
case UInt64DataTypeId :
465491
array = false;
466492
return AI_TYPE_UINT;
467493
case FloatDataTypeId :

0 commit comments

Comments
 (0)