Skip to content

Commit

Permalink
add pointWeights attribute to NurbsCurves in usdGeom
Browse files Browse the repository at this point in the history
Fixes #1554

(Internal change: 2261283)
  • Loading branch information
matthewcpp authored and pixar-oss committed Jan 31, 2023
1 parent 5b2d6b2 commit bb4da14
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pxr/usd/usdGeom/generatedSchema.usda
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions pxr/usd/usdGeom/nurbsCurves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -174,6 +191,7 @@ UsdGeomNurbsCurves::GetSchemaAttributeNames(bool includeInherited)
UsdGeomTokens->order,
UsdGeomTokens->knots,
UsdGeomTokens->ranges,
UsdGeomTokens->pointWeights,
};
static TfTokenVector allNames =
_ConcatenateAttributeNames(
Expand Down
27 changes: 27 additions & 0 deletions pxr/usd/usdGeom/nurbsCurves.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> |
/// | \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
Expand Down
9 changes: 9 additions & 0 deletions pxr/usd/usdGeom/schema.usda
Original file line number Diff line number Diff line change
Expand Up @@ -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" (
Expand Down
1 change: 1 addition & 0 deletions pxr/usd/usdGeom/testenv/testUsdGeomCurves.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pxr/usd/usdGeom/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ struct UsdGeomTokensType {
const TfToken points;
/// \brief "pointWeights"
///
/// UsdGeomNurbsPatch
/// UsdGeomNurbsPatch, UsdGeomNurbsCurves
const TfToken pointWeights;
/// \brief "positions"
///
Expand Down
16 changes: 15 additions & 1 deletion pxr/usd/usdGeom/wrapNurbsCurves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
;
Expand Down Expand Up @@ -163,4 +177,4 @@ namespace {
WRAP_CUSTOM {
}

} // anonymous namespace
}

0 comments on commit bb4da14

Please sign in to comment.