Skip to content

Commit

Permalink
IECoreUSD::PointInstancerAlgo : Support inactive / invisible ids
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldresser-ie committed Oct 9, 2024
1 parent fe784a7 commit 30ba213
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
10.5.x.x (relative to 10.5.9.5)
========


Improvements
------------
- USDScene : PointInstancers are now loaded with invisibleIds and inactiveIds as primitive variables.

10.5.9.5 (relative to 10.5.9.4)
========
Expand Down
23 changes: 23 additions & 0 deletions contrib/IECoreUSD/src/IECoreUSD/PointInstancerAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,28 @@ IECore::ObjectPtr readPointInstancer( pxr::UsdGeomPointInstancer &pointInstancer
Canceller::check( canceller );
PrimitiveAlgo::readPrimitiveVariable( pointInstancer.GetAngularVelocitiesAttr(), time, newPoints.get(), "angularVelocity" );

std::vector<double> times;
pointInstancer.GetInvisibleIdsAttr().GetTimeSamples( &times );
if( pointInstancer.GetInvisibleIdsAttr().HasAuthoredValue() )
{
DataPtr cortexInvisIds = DataAlgo::fromUSD( pointInstancer.GetInvisibleIdsAttr(), time, true );
if( cortexInvisIds )
{
newPoints->variables["invisibleIds"] = IECoreScene::PrimitiveVariable(
PrimitiveVariable::Constant, cortexInvisIds
);
}
}

pxr::SdfInt64ListOp inactiveIdsListOp;
if( pointInstancer.GetPrim().GetMetadata( pxr::UsdGeomTokens->inactiveIds, &inactiveIdsListOp ) )
{
newPoints->variables["inactiveIds"] = IECoreScene::PrimitiveVariable(
PrimitiveVariable::Constant,
new IECore::Int64VectorData( inactiveIdsListOp.GetExplicitItems() )
);
}

// Prototype paths

pxr::SdfPathVector targets;
Expand Down Expand Up @@ -120,6 +142,7 @@ bool pointInstancerMightBeTimeVarying( pxr::UsdGeomPointInstancer &instancer )
instancer.GetVelocitiesAttr().ValueMightBeTimeVarying() ||
instancer.GetAccelerationsAttr().ValueMightBeTimeVarying() ||
instancer.GetAngularVelocitiesAttr().ValueMightBeTimeVarying() ||
instancer.GetInvisibleIdsAttr().ValueMightBeTimeVarying() ||
PrimitiveAlgo::primitiveVariablesMightBeTimeVarying(
pxr::UsdGeomPrimvarsAPI( instancer )
)
Expand Down
23 changes: 20 additions & 3 deletions contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3704,10 +3704,10 @@ def testPointInstancerPrimvars( self ) :

fileName = os.path.join( self.temporaryDirectory(), "pointInstancePrimvars.usda" )
stage = pxr.Usd.Stage.CreateNew( fileName )
points = pxr.UsdGeom.PointInstancer.Define( stage, "/points" )
points.CreatePositionsAttr( [ ( v, v, v ) for v in range( 0, 5 ) ] )
pointInstancer = pxr.UsdGeom.PointInstancer.Define( stage, "/points" )
pointInstancer.CreatePositionsAttr( [ ( v, v, v ) for v in range( 0, 5 ) ] )

primvars = pxr.UsdGeom.PrimvarsAPI( points )
primvars = pxr.UsdGeom.PrimvarsAPI( pointInstancer )
primvar = primvars.CreatePrimvar( "myColor", pxr.Sdf.ValueTypeNames.Color3fArray, "vertex" )
primvar.Set(
[ ( c, c, c ) for c in range( 1, 6 ) ]
Expand All @@ -3720,6 +3720,8 @@ def testPointInstancerPrimvars( self ) :
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
points = root.child( "points" ).readObject( 0 )

self.assertEqual( points.keys(), ['P', 'myColor', 'prototypeRoots'] )

self.assertIsInstance( points, IECoreScene.PointsPrimitive )
self.assertIn( "myColor", points )
self.assertEqual(
Expand All @@ -3729,6 +3731,21 @@ def testPointInstancerPrimvars( self ) :
self.assertEqual( points["myColor"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Vertex )
self.assertEqual( points["myColor"].indices, None )

# Now try deactivating some ids

pointInstancer.DeactivateIds( [ 0, 2 ] )
pointInstancer.InvisIds( [ 1, 4 ], 0 )

stage.GetRootLayer().Save()

root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
points = root.child( "points" ).readObject( 0 )

self.assertEqual( points.keys(), ['P', 'inactiveIds', 'invisibleIds', 'myColor', 'prototypeRoots'] )

self.assertEqual( points["inactiveIds"], IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.Int64VectorData( [ 0, 2 ] ) ) )
self.assertEqual( points["invisibleIds"], IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.Int64VectorData( [ 1, 4 ] ) ) )

def testArnoldArrayInputs( self ) :

def assertExpectedArrayInputs( network ) :
Expand Down

0 comments on commit 30ba213

Please sign in to comment.