Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IECoreUSD::PointInstancerAlgo : Support inactive / invisible ids #1437

Open
wants to merge 1 commit into
base: RB-10.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading