diff --git a/pxr/usd/usdGeom/generatedSchema.usda b/pxr/usd/usdGeom/generatedSchema.usda index ab4e2d1776..59c7b8e196 100644 --- a/pxr/usd/usdGeom/generatedSchema.usda +++ b/pxr/usd/usdGeom/generatedSchema.usda @@ -2997,6 +2997,14 @@ class NurbsCurves "NurbsCurves" ( doc = """The primary geometry attribute for all PointBased primitives, describes points in (local) space.""" ) + double[] pointWeights ( + doc = """Optionally provides \"w\" components for each control point, + thus must be the same length as the points attribute. If authored, + the curve will be rational. If unauthored, the curve will be + polynomial, i.e. weight for all points is 1.0. + \\note Some DCC's pre-weight the points, but in this schema, + points are not pre-weighted.""" + ) color3f[] primvars:displayColor ( doc = '''It is useful to have an "official" colorSet that can be used as a display or modeling color, even in the absence of any specified diff --git a/pxr/usd/usdGeom/nurbsCurves.cpp b/pxr/usd/usdGeom/nurbsCurves.cpp index 01388f4e41..87a592be1d 100644 --- a/pxr/usd/usdGeom/nurbsCurves.cpp +++ b/pxr/usd/usdGeom/nurbsCurves.cpp @@ -154,6 +154,23 @@ UsdGeomNurbsCurves::CreateRangesAttr(VtValue const &defaultValue, bool writeSpar writeSparsely); } +UsdAttribute +UsdGeomNurbsCurves::GetPointWeightsAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->pointWeights); +} + +UsdAttribute +UsdGeomNurbsCurves::CreatePointWeightsAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->pointWeights, + SdfValueTypeNames->DoubleArray, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + namespace { static inline TfTokenVector _ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) @@ -174,6 +191,7 @@ UsdGeomNurbsCurves::GetSchemaAttributeNames(bool includeInherited) UsdGeomTokens->order, UsdGeomTokens->knots, UsdGeomTokens->ranges, + UsdGeomTokens->pointWeights, }; static TfTokenVector allNames = _ConcatenateAttributeNames( diff --git a/pxr/usd/usdGeom/nurbsCurves.h b/pxr/usd/usdGeom/nurbsCurves.h index fafb5b5abd..adac636e7e 100644 --- a/pxr/usd/usdGeom/nurbsCurves.h +++ b/pxr/usd/usdGeom/nurbsCurves.h @@ -245,6 +245,33 @@ class UsdGeomNurbsCurves : public UsdGeomCurves USDGEOM_API UsdAttribute CreateRangesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; +public: + // --------------------------------------------------------------------- // + // POINTWEIGHTS + // --------------------------------------------------------------------- // + /// Optionally provides "w" components for each control point, + /// thus must be the same length as the points attribute. If authored, + /// the curve will be rational. If unauthored, the curve will be + /// polynomial, i.e. weight for all points is 1.0. + /// \note Some DCC's pre-weight the \em points, but in this schema, + /// \em points are not pre-weighted. + /// + /// | || + /// | -- | -- | + /// | Declaration | `double[] pointWeights` | + /// | C++ Type | VtArray | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->DoubleArray | + USDGEOM_API + UsdAttribute GetPointWeightsAttr() const; + + /// See GetPointWeightsAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDGEOM_API + UsdAttribute CreatePointWeightsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + public: // ===================================================================== // // Feel free to add custom code below this line, it will be preserved by diff --git a/pxr/usd/usdGeom/schema.usda b/pxr/usd/usdGeom/schema.usda index 0738b5ea7c..099dfe243c 100644 --- a/pxr/usd/usdGeom/schema.usda +++ b/pxr/usd/usdGeom/schema.usda @@ -1678,6 +1678,15 @@ class NurbsCurves "NurbsCurves" ( knots['i'th curve slice][order[i]-1]. The maxium must be less than or equal to the last element's value in knots['i'th curve slice]. Range maps to (vmin, vmax) in the RenderMan spec.""") + + double[] pointWeights ( + doc = """Optionally provides "w" components for each control point, + thus must be the same length as the points attribute. If authored, + the curve will be rational. If unauthored, the curve will be + polynomial, i.e. weight for all points is 1.0. + \\note Some DCC's pre-weight the \\em points, but in this schema, + \\em points are not pre-weighted.""" + ) } class Points "Points" ( diff --git a/pxr/usd/usdGeom/testenv/testUsdGeomCurves.py b/pxr/usd/usdGeom/testenv/testUsdGeomCurves.py index 201fe99022..accd867d4c 100644 --- a/pxr/usd/usdGeom/testenv/testUsdGeomCurves.py +++ b/pxr/usd/usdGeom/testenv/testUsdGeomCurves.py @@ -68,6 +68,7 @@ def test_schema(self): assert 'curveVertexCounts' in self.schema.GetSchemaAttributeNames() assert 'knots' in self.schema.GetSchemaAttributeNames() assert 'order' in self.schema.GetSchemaAttributeNames() + assert 'pointWeights' in self.schema.GetSchemaAttributeNames() knots = self.schema.GetKnotsAttr() assert(knots) diff --git a/pxr/usd/usdGeom/tokens.h b/pxr/usd/usdGeom/tokens.h index 69c9b6d663..bfbab2152d 100644 --- a/pxr/usd/usdGeom/tokens.h +++ b/pxr/usd/usdGeom/tokens.h @@ -464,7 +464,7 @@ struct UsdGeomTokensType { const TfToken points; /// \brief "pointWeights" /// - /// UsdGeomNurbsPatch + /// UsdGeomNurbsPatch, UsdGeomNurbsCurves const TfToken pointWeights; /// \brief "positions" /// diff --git a/pxr/usd/usdGeom/wrapNurbsCurves.cpp b/pxr/usd/usdGeom/wrapNurbsCurves.cpp index 0087045387..fb174b53ce 100644 --- a/pxr/usd/usdGeom/wrapNurbsCurves.cpp +++ b/pxr/usd/usdGeom/wrapNurbsCurves.cpp @@ -69,6 +69,13 @@ _CreateRangesAttr(UsdGeomNurbsCurves &self, return self.CreateRangesAttr( UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Double2Array), writeSparsely); } + +static UsdAttribute +_CreatePointWeightsAttr(UsdGeomNurbsCurves &self, + object defaultVal, bool writeSparsely) { + return self.CreatePointWeightsAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->DoubleArray), writeSparsely); +} static std::string _Repr(const UsdGeomNurbsCurves &self) @@ -132,6 +139,13 @@ void wrapUsdGeomNurbsCurves() &_CreateRangesAttr, (arg("defaultValue")=object(), arg("writeSparsely")=false)) + + .def("GetPointWeightsAttr", + &This::GetPointWeightsAttr) + .def("CreatePointWeightsAttr", + &_CreatePointWeightsAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) .def("__repr__", ::_Repr) ; @@ -163,4 +177,4 @@ namespace { WRAP_CUSTOM { } -} // anonymous namespace +}