Skip to content

Commit 83864a1

Browse files
authored
Merge pull request #1452 from johnhaddon/usdAnimationFixes
USDScene animation fixes
2 parents d4569e5 + 0a75d21 commit 83864a1

File tree

3 files changed

+60
-15
lines changed

3 files changed

+60
-15
lines changed

Changes

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
10.5.x.x (relative to 10.5.12.0)
2+
========
3+
4+
Fixes
5+
-----
6+
7+
- USDScene :
8+
- Fixed timecodes used when writing animated attributes.
9+
- Fixed timecodes used when writing animated bounds.
10+
111
10.5.12.0 (relative to 10.5.11.0)
212
========
313

contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ class USDScene::IO : public RefCounted
711711
return m_stage;
712712
}
713713

714-
pxr::UsdTimeCode getTime( double timeSeconds ) const
714+
pxr::UsdTimeCode timeCode( double timeSeconds ) const
715715
{
716716
return timeSeconds * m_timeCodesPerSecond;
717717
}
@@ -937,7 +937,7 @@ Imath::Box3d USDScene::readBound( double time ) const
937937
}
938938

939939
pxr::VtArray<pxr::GfVec3f> extents;
940-
attr.Get( &extents, m_root->getTime( time ) );
940+
attr.Get( &extents, m_root->timeCode( time ) );
941941

942942
// When coming from UsdGeomModelAPI, `extents` may contain several bounds,
943943
// on a per-purpose basis. Take the union, since the SceneInterface API only
@@ -965,12 +965,12 @@ ConstDataPtr USDScene::readTransform( double time ) const
965965

966966
Imath::M44d USDScene::readTransformAsMatrix( double time ) const
967967
{
968-
return localTransform( m_location->prim, m_root->getTime( time ) );
968+
return localTransform( m_location->prim, m_root->timeCode( time ) );
969969
}
970970

971971
ConstObjectPtr USDScene::readObject( double time, const Canceller *canceller ) const
972972
{
973-
return ObjectAlgo::readObject( m_location->prim, m_root->getTime( time ), canceller );
973+
return ObjectAlgo::readObject( m_location->prim, m_root->timeCode( time ), canceller );
974974
}
975975

976976
SceneInterface::Name USDScene::name() const
@@ -1008,7 +1008,7 @@ void USDScene::writeBound( const Imath::Box3d &bound, double time )
10081008
extent.push_back( DataAlgo::toUSD( Imath::V3f( bound.max ) ) );
10091009

10101010
pxr::UsdAttribute extentAttr = boundable.CreateExtentAttr();
1011-
extentAttr.Set( pxr::VtValue( extent ) );
1011+
extentAttr.Set( pxr::VtValue( extent ), m_root->timeCode( time ) );
10121012
}
10131013

10141014
void USDScene::writeTransform( const Data *transform, double time )
@@ -1023,7 +1023,7 @@ void USDScene::writeTransform( const Data *transform, double time )
10231023
if( xformable )
10241024
{
10251025
pxr::UsdGeomXformOp transformOp = xformable.MakeMatrixXform();
1026-
const pxr::UsdTimeCode timeCode = m_root->getTime( time );
1026+
const pxr::UsdTimeCode timeCode = m_root->timeCode( time );
10271027
transformOp.Set( DataAlgo::toUSD( m44->readable() ), timeCode );
10281028
}
10291029
}
@@ -1182,7 +1182,7 @@ ConstObjectPtr USDScene::readAttribute( const SceneInterface::Name &name, double
11821182
{
11831183
return nullptr;
11841184
}
1185-
pxr::TfToken value; attr.Get( &value, m_root->getTime( time ) );
1185+
pxr::TfToken value; attr.Get( &value, m_root->timeCode( time ) );
11861186
if( value == pxr::UsdGeomTokens->inherited )
11871187
{
11881188
return new BoolData( true );
@@ -1227,15 +1227,15 @@ ConstObjectPtr USDScene::readAttribute( const SceneInterface::Name &name, double
12271227
{
12281228
pxr::UsdAttribute attr = pxr::UsdGeomGprim( m_location->prim ).GetDoubleSidedAttr();
12291229
bool doubleSided;
1230-
if( attr.HasAuthoredValue() && attr.Get( &doubleSided, m_root->getTime( time ) ) )
1230+
if( attr.HasAuthoredValue() && attr.Get( &doubleSided, m_root->timeCode( time ) ) )
12311231
{
12321232
return new BoolData( doubleSided );
12331233
}
12341234
return nullptr;
12351235
}
12361236
else if( pxr::UsdAttribute attribute = AttributeAlgo::findUSDAttribute( m_location->prim, name.string() ) )
12371237
{
1238-
return DataAlgo::fromUSD( attribute, m_root->getTime( time ) );
1238+
return DataAlgo::fromUSD( attribute, m_root->timeCode( time ) );
12391239
}
12401240
else
12411241
{
@@ -1260,7 +1260,7 @@ void USDScene::writeAttribute( const SceneInterface::Name &name, const Object *a
12601260
pxr::UsdGeomImageable imageable( m_location->prim );
12611261
imageable.GetVisibilityAttr().Set(
12621262
data->readable() ? pxr::UsdGeomTokens->inherited : pxr::UsdGeomTokens->invisible,
1263-
m_root->getTime( time )
1263+
m_root->timeCode( time )
12641264
);
12651265
}
12661266
}
@@ -1293,7 +1293,7 @@ void USDScene::writeAttribute( const SceneInterface::Name &name, const Object *a
12931293
pxr::UsdGeomGprim gprim( m_location->prim );
12941294
if( gprim )
12951295
{
1296-
gprim.GetDoubleSidedAttr().Set( data->readable(), m_root->getTime( time ) );
1296+
gprim.GetDoubleSidedAttr().Set( data->readable(), m_root->timeCode( time ) );
12971297
}
12981298
else
12991299
{
@@ -1341,7 +1341,7 @@ void USDScene::writeAttribute( const SceneInterface::Name &name, const Object *a
13411341
pxr::TfToken( g.first.string().substr( 10 ) ),
13421342
DataAlgo::valueTypeName( d )
13431343
);
1344-
globalAttribute.Set( DataAlgo::toUSD( d ) );
1344+
globalAttribute.Set( DataAlgo::toUSD( d ), m_root->timeCode( time ) );
13451345
}
13461346
}
13471347
}
@@ -1357,14 +1357,14 @@ void USDScene::writeAttribute( const SceneInterface::Name &name, const Object *a
13571357
pxr::UsdGeomPrimvar usdPrimvar = primvarsAPI.CreatePrimvar(
13581358
usdName.name, DataAlgo::valueTypeName( data ), pxr::UsdGeomTokens->constant
13591359
);
1360-
usdPrimvar.Set( DataAlgo::toUSD( data ), time );
1360+
usdPrimvar.Set( DataAlgo::toUSD( data ), m_root->timeCode( time ) );
13611361
}
13621362
else
13631363
{
13641364
pxr::UsdAttribute newAttribute = m_location->prim.CreateAttribute(
13651365
usdName.name, DataAlgo::valueTypeName( data )
13661366
);
1367-
newAttribute.Set( DataAlgo::toUSD( data ), time );
1367+
newAttribute.Set( DataAlgo::toUSD( data ), m_root->timeCode( time ) );
13681368
}
13691369
}
13701370
}
@@ -1488,7 +1488,7 @@ PrimitiveVariableMap USDScene::readObjectPrimitiveVariables( const std::vector<I
14881488

14891489
void USDScene::writeObject( const Object *object, double time )
14901490
{
1491-
if( !ObjectAlgo::writeObject( object, m_root->getStage(), m_location->prim.GetPath(), m_root->getTime( time ) ) )
1491+
if( !ObjectAlgo::writeObject( object, m_root->getStage(), m_location->prim.GetPath(), m_root->timeCode( time ) ) )
14921492
{
14931493
IECore::msg(
14941494
IECore::Msg::Warning, "USDScene::writeObject",

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

+35
Original file line numberDiff line numberDiff line change
@@ -2809,6 +2809,41 @@ def testAttributeBadPrefix( self ):
28092809
self.assertEqual( set( root.child( "loc" ).attributeNames() ), set( ['ai:testAttribute' ] ) )
28102810
self.assertEqual( root.child( "loc" ).readAttribute( 'ai:testAttribute', 0 ), IECore.FloatData( 9 ) )
28112811

2812+
def testWriteAnimatedAttribute( self ) :
2813+
2814+
fileName = os.path.join( self.temporaryDirectory(), "test.usda" )
2815+
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Write )
2816+
child = root.createChild( "child" )
2817+
2818+
for t in ( 0.0, 0.5, 1.0 ) :
2819+
child.writeAttribute( "user:test", IECore.FloatData( t ), t )
2820+
2821+
del child, root
2822+
2823+
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
2824+
child = root.child( "child" )
2825+
2826+
for t in ( 0.0, 0.5, 1.0 ) :
2827+
self.assertEqual( child.readAttribute( "user:test", t ), IECore.FloatData( t ) )
2828+
2829+
def testWriteAnimatedBound( self ) :
2830+
2831+
fileName = os.path.join( self.temporaryDirectory(), "test.usda" )
2832+
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Write )
2833+
child = root.createChild( "child" )
2834+
2835+
for t in ( 1.0, 1.5, 2.0 ) :
2836+
child.writeObject( IECoreScene.SpherePrimitive( t ), t )
2837+
child.writeBound( imath.Box3d( imath.V3d( -t ), imath.V3d( t ) ), t )
2838+
2839+
del child, root
2840+
2841+
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
2842+
child = root.child( "child" )
2843+
2844+
for t in ( 1.0, 1.5, 2.0 ) :
2845+
self.assertEqual( child.readBound( t ), imath.Box3d( imath.V3d( -t ), imath.V3d( t ) ) )
2846+
28122847
def testShaders( self ) :
28132848

28142849
# Write shaders

0 commit comments

Comments
 (0)