Skip to content

Commit 7851175

Browse files
committed
IECoreUSD : Load primvars from UsdGeomPointInstancers
1 parent dda4cb3 commit 7851175

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

contrib/IECoreUSD/src/IECoreUSD/PointInstancerAlgo.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ IECore::ObjectPtr readPointInstancer( pxr::UsdGeomPointInstancer &pointInstancer
125125

126126
newPoints->variables["prototypeRoots"] = IECoreScene::PrimitiveVariable( IECoreScene::PrimitiveVariable::Constant, prototypeRootsData );
127127

128+
// Primitive variables
129+
130+
PrimitiveAlgo::readPrimitiveVariables( pxr::UsdGeomPrimvarsAPI( pointInstancer ), time, newPoints.get(), canceller );
131+
128132
return newPoints;
129133
}
130134

@@ -140,7 +144,10 @@ bool pointInstancerMightBeTimeVarying( pxr::UsdGeomPointInstancer &instancer )
140144
#if USD_VERSION >= 1911
141145
instancer.GetAccelerationsAttr().ValueMightBeTimeVarying() ||
142146
#endif
143-
instancer.GetAngularVelocitiesAttr().ValueMightBeTimeVarying()
147+
instancer.GetAngularVelocitiesAttr().ValueMightBeTimeVarying() ||
148+
PrimitiveAlgo::primitiveVariablesMightBeTimeVarying(
149+
pxr::UsdGeomPrimvarsAPI( instancer )
150+
)
144151
;
145152
}
146153

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,5 +3106,36 @@ def testColor4fShaderParameterComponentConnections( self ) :
31063106
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
31073107
self.assertEqual( root.child( "object" ).readAttribute( "ai:surface", 0 ), network )
31083108

3109+
def testPointInstancerPrimvars( self ) :
3110+
3111+
# Use the USD API to author a point instancer with primvars on it.
3112+
3113+
fileName = os.path.join( self.temporaryDirectory(), "pointInstancePrimvars.usda" )
3114+
stage = pxr.Usd.Stage.CreateNew( fileName )
3115+
points = pxr.UsdGeom.PointInstancer.Define( stage, "/points" )
3116+
points.CreatePositionsAttr( [ ( v, v, v ) for v in range( 0, 5 ) ] )
3117+
3118+
primvars = pxr.UsdGeom.PrimvarsAPI( points )
3119+
primvar = primvars.CreatePrimvar( "myColor", pxr.Sdf.ValueTypeNames.Color3fArray, "vertex" )
3120+
primvar.Set(
3121+
[ ( c, c, c ) for c in range( 1, 6 ) ]
3122+
)
3123+
3124+
stage.GetRootLayer().Save()
3125+
3126+
# Check we can load the primvar via a SceneInterface.
3127+
3128+
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
3129+
points = root.child( "points" ).readObject( 0 )
3130+
3131+
self.assertIsInstance( points, IECoreScene.PointsPrimitive )
3132+
self.assertIn( "myColor", points )
3133+
self.assertEqual(
3134+
points["myColor"].data,
3135+
IECore.Color3fVectorData( [ imath.Color3f( c ) for c in range( 1, 6 ) ] )
3136+
)
3137+
self.assertEqual( points["myColor"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Vertex )
3138+
self.assertEqual( points["myColor"].indices, None )
3139+
31093140
if __name__ == "__main__":
31103141
unittest.main()

0 commit comments

Comments
 (0)