4242
4343IECORE_PUSH_DEFAULT_VISIBILITY
4444#include " pxr/usd/usdGeom/basisCurves.h"
45+ #include " pxr/usd/usdGeom/nurbsCurves.h"
4546IECORE_POP_DEFAULT_VISIBILITY
4647
4748using namespace IECore ;
@@ -55,13 +56,37 @@ using namespace IECoreUSD;
5556namespace
5657{
5758
58- IECore::ObjectPtr readCurves ( pxr::UsdGeomBasisCurves &curves, pxr::UsdTimeCode time, const Canceller *canceller )
59+ IECore::ObjectPtr readCurves ( pxr::UsdGeomCurves &curves, pxr::UsdTimeCode time, const IECore::CubicBasisf &basis, bool periodic , const Canceller *canceller )
5960{
6061 Canceller::check ( canceller );
6162 pxr::VtIntArray vertexCountsArray;
6263 curves.GetCurveVertexCountsAttr ().Get ( &vertexCountsArray, time );
6364 IECore::IntVectorDataPtr countData = DataAlgo::fromUSD ( vertexCountsArray );
6465
66+ Canceller::check ( canceller );
67+ IECoreScene::CurvesPrimitivePtr newCurves = new IECoreScene::CurvesPrimitive ( countData, basis, periodic );
68+ PrimitiveAlgo::readPrimitiveVariables ( curves, time, newCurves.get (), canceller );
69+
70+ Canceller::check ( canceller );
71+ PrimitiveAlgo::readPrimitiveVariable (
72+ curves.GetWidthsAttr (), time, newCurves.get (), " width" , PrimitiveAlgo::fromUSD ( curves.GetWidthsInterpolation () )
73+ );
74+
75+ return newCurves;
76+ }
77+
78+ bool curvesMightBeTimeVarying ( pxr::UsdGeomCurves &curves )
79+ {
80+ return
81+ curves.GetCurveVertexCountsAttr ().ValueMightBeTimeVarying () ||
82+ curves.GetWidthsAttr ().ValueMightBeTimeVarying () ||
83+ PrimitiveAlgo::primitiveVariablesMightBeTimeVarying ( curves )
84+ ;
85+ }
86+
87+ IECore::ObjectPtr readBasisCurves ( pxr::UsdGeomBasisCurves &curves, pxr::UsdTimeCode time, const Canceller *canceller )
88+ {
89+
6590 // Basis
6691 Canceller::check ( canceller );
6792 IECore::CubicBasisf basis = CubicBasisf::linear ();
@@ -103,32 +128,44 @@ IECore::ObjectPtr readCurves( pxr::UsdGeomBasisCurves &curves, pxr::UsdTimeCode
103128 IECore::msg ( IECore::Msg::Warning, " USDScene" , boost::format ( " Unsupported wrap \" %1%\" " ) % wrap );
104129 }
105130
106- // Curves and primvars
131+ return readCurves ( curves, time, basis, periodic, canceller );
132+ }
107133
108- IECoreScene::CurvesPrimitivePtr newCurves = new IECoreScene::CurvesPrimitive ( countData, basis, periodic );
109- PrimitiveAlgo::readPrimitiveVariables ( curves, time, newCurves.get (), canceller );
134+ bool basisCurvesMightBeTimeVarying ( pxr::UsdGeomBasisCurves &curves )
135+ {
136+ return
137+ curvesMightBeTimeVarying ( curves ) ||
138+ curves.GetTypeAttr ().ValueMightBeTimeVarying () ||
139+ curves.GetBasisAttr ().ValueMightBeTimeVarying () ||
140+ curves.GetWrapAttr ().ValueMightBeTimeVarying ()
141+ ;
142+ }
143+
144+ IECore::ObjectPtr readNurbsCurves ( pxr::UsdGeomNurbsCurves &curves, pxr::UsdTimeCode time, const Canceller *canceller )
145+ {
146+ IECore::CubicBasisf basis = IECore::CubicBasisf::linear ();
110147
111148 Canceller::check ( canceller );
112- PrimitiveAlgo::readPrimitiveVariable (
113- curves.GetWidthsAttr (), time, newCurves.get (), " width" , PrimitiveAlgo::fromUSD ( curves.GetWidthsInterpolation () )
114- );
149+ pxr::VtIntArray order;
150+ curves.GetOrderAttr ().Get ( &order, time );
151+ if ( std::all_of ( order.begin (), order.end (), [] ( int o ) { return o == 4 ; } ) )
152+ {
153+ basis = CubicBasisf::bSpline ();
154+ }
115155
116- return newCurves ;
156+ return readCurves ( curves, time, basis, false , canceller ) ;
117157}
118158
119- bool curvesMightBeTimeVarying ( pxr::UsdGeomBasisCurves &curves )
159+ bool nurbsCurvesMightBeTimeVarying ( pxr::UsdGeomNurbsCurves &curves )
120160{
121161 return
122- curves.GetCurveVertexCountsAttr ().ValueMightBeTimeVarying () ||
123- curves.GetTypeAttr ().ValueMightBeTimeVarying () ||
124- curves.GetBasisAttr ().ValueMightBeTimeVarying () ||
125- curves.GetWrapAttr ().ValueMightBeTimeVarying () ||
126- curves.GetWidthsAttr ().ValueMightBeTimeVarying () ||
127- PrimitiveAlgo::primitiveVariablesMightBeTimeVarying ( curves )
162+ curvesMightBeTimeVarying ( curves ) ||
163+ curves.GetOrderAttr ().ValueMightBeTimeVarying ()
128164 ;
129165}
130166
131- ObjectAlgo::ReaderDescription<pxr::UsdGeomBasisCurves> g_curvesReaderDescription ( pxr::TfToken( " BasisCurves" ), readCurves, curvesMightBeTimeVarying );
167+ ObjectAlgo::ReaderDescription<pxr::UsdGeomBasisCurves> g_curvesReaderDescription ( pxr::TfToken( " BasisCurves" ), readBasisCurves, basisCurvesMightBeTimeVarying );
168+ ObjectAlgo::ReaderDescription<pxr::UsdGeomNurbsCurves> g_nurbsCurvesReaderDescription ( pxr::TfToken( " NurbsCurves" ), readNurbsCurves, nurbsCurvesMightBeTimeVarying );
132169
133170} // namespace
134171
0 commit comments