Skip to content

Commit 30ba213

Browse files
IECoreUSD::PointInstancerAlgo : Support inactive / invisible ids
1 parent fe784a7 commit 30ba213

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

Changes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
10.5.x.x (relative to 10.5.9.5)
22
========
33

4-
4+
Improvements
5+
------------
6+
- USDScene : PointInstancers are now loaded with invisibleIds and inactiveIds as primitive variables.
57

68
10.5.9.5 (relative to 10.5.9.4)
79
========

contrib/IECoreUSD/src/IECoreUSD/PointInstancerAlgo.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,28 @@ IECore::ObjectPtr readPointInstancer( pxr::UsdGeomPointInstancer &pointInstancer
8686
Canceller::check( canceller );
8787
PrimitiveAlgo::readPrimitiveVariable( pointInstancer.GetAngularVelocitiesAttr(), time, newPoints.get(), "angularVelocity" );
8888

89+
std::vector<double> times;
90+
pointInstancer.GetInvisibleIdsAttr().GetTimeSamples( &times );
91+
if( pointInstancer.GetInvisibleIdsAttr().HasAuthoredValue() )
92+
{
93+
DataPtr cortexInvisIds = DataAlgo::fromUSD( pointInstancer.GetInvisibleIdsAttr(), time, true );
94+
if( cortexInvisIds )
95+
{
96+
newPoints->variables["invisibleIds"] = IECoreScene::PrimitiveVariable(
97+
PrimitiveVariable::Constant, cortexInvisIds
98+
);
99+
}
100+
}
101+
102+
pxr::SdfInt64ListOp inactiveIdsListOp;
103+
if( pointInstancer.GetPrim().GetMetadata( pxr::UsdGeomTokens->inactiveIds, &inactiveIdsListOp ) )
104+
{
105+
newPoints->variables["inactiveIds"] = IECoreScene::PrimitiveVariable(
106+
PrimitiveVariable::Constant,
107+
new IECore::Int64VectorData( inactiveIdsListOp.GetExplicitItems() )
108+
);
109+
}
110+
89111
// Prototype paths
90112

91113
pxr::SdfPathVector targets;
@@ -120,6 +142,7 @@ bool pointInstancerMightBeTimeVarying( pxr::UsdGeomPointInstancer &instancer )
120142
instancer.GetVelocitiesAttr().ValueMightBeTimeVarying() ||
121143
instancer.GetAccelerationsAttr().ValueMightBeTimeVarying() ||
122144
instancer.GetAngularVelocitiesAttr().ValueMightBeTimeVarying() ||
145+
instancer.GetInvisibleIdsAttr().ValueMightBeTimeVarying() ||
123146
PrimitiveAlgo::primitiveVariablesMightBeTimeVarying(
124147
pxr::UsdGeomPrimvarsAPI( instancer )
125148
)

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3704,10 +3704,10 @@ def testPointInstancerPrimvars( self ) :
37043704

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

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

3723+
self.assertEqual( points.keys(), ['P', 'myColor', 'prototypeRoots'] )
3724+
37233725
self.assertIsInstance( points, IECoreScene.PointsPrimitive )
37243726
self.assertIn( "myColor", points )
37253727
self.assertEqual(
@@ -3729,6 +3731,21 @@ def testPointInstancerPrimvars( self ) :
37293731
self.assertEqual( points["myColor"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Vertex )
37303732
self.assertEqual( points["myColor"].indices, None )
37313733

3734+
# Now try deactivating some ids
3735+
3736+
pointInstancer.DeactivateIds( [ 0, 2 ] )
3737+
pointInstancer.InvisIds( [ 1, 4 ], 0 )
3738+
3739+
stage.GetRootLayer().Save()
3740+
3741+
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
3742+
points = root.child( "points" ).readObject( 0 )
3743+
3744+
self.assertEqual( points.keys(), ['P', 'inactiveIds', 'invisibleIds', 'myColor', 'prototypeRoots'] )
3745+
3746+
self.assertEqual( points["inactiveIds"], IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.Int64VectorData( [ 0, 2 ] ) ) )
3747+
self.assertEqual( points["invisibleIds"], IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.Int64VectorData( [ 1, 4 ] ) ) )
3748+
37323749
def testArnoldArrayInputs( self ) :
37333750

37343751
def assertExpectedArrayInputs( network ) :

0 commit comments

Comments
 (0)