Skip to content

Commit

Permalink
Merge pull request #3347 from dj-mcg/pr/Rename_Instancer_Primvars
Browse files Browse the repository at this point in the history
Renaming internal instancer primvars
  • Loading branch information
seando-adsk authored Oct 4, 2023
2 parents 2779e5c + 6b1baee commit 853fb1b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 46 deletions.
66 changes: 38 additions & 28 deletions lib/mayaUsd/render/vp2RenderDelegate/instancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@

PXR_NAMESPACE_OPEN_SCOPE

// Define local tokens for the names of the primvars the instancer
// consumes.
// XXX: These should be hydra tokens...
// clang-format off
TF_DEFINE_PRIVATE_TOKENS(
_tokens,

(instanceTransform)
(rotate)
(scale)
(translate)
);
// clang-format on

/*! \brief Constructor.
\param delegate The scene delegate backing this instancer's data.
Expand Down Expand Up @@ -148,8 +134,11 @@ VtMatrix4dArray HdVP2Instancer::ComputeInstanceTransforms(SdfPath const& prototy

// The transforms for this level of instancer are computed by:
// foreach(index : indices) {
// instancerTransform * translate(index) * rotate(index) *
// scale(index) * instanceTransform(index)
// instancerTransform
// * hydra:translate(index)
// * hydra:rotate(index)
// * hydra:scale(index)
// * hydra:instanceTransform(index)
// }
// If any transform isn't provided, it's assumed to be the identity.

Expand All @@ -161,9 +150,14 @@ VtMatrix4dArray HdVP2Instancer::ComputeInstanceTransforms(SdfPath const& prototy
transforms[i] = instancerTransform;
}

// "translate" holds a translation vector for each index.
if (_primvarMap.count(_tokens->translate) > 0) {
HdVP2BufferSampler sampler(*_primvarMap[_tokens->translate]);
// "hydra:instanceTranslations" holds a translation vector for each index.
#if HD_API_VERSION < 56
if (_primvarMap.count(HdInstancerTokens->translate) > 0) {
HdVP2BufferSampler sampler(*_primvarMap[HdInstancerTokens->translate]);
#else
if (_primvarMap.count(HdInstancerTokens->instanceTranslations) > 0) {
HdVP2BufferSampler sampler(*_primvarMap[HdInstancerTokens->instanceTranslations]);
#endif
for (size_t i = 0; i < instanceIndices.size(); ++i) {
GfVec3f translate;
if (sampler.Sample(instanceIndices[i], &translate)) {
Expand All @@ -174,9 +168,15 @@ VtMatrix4dArray HdVP2Instancer::ComputeInstanceTransforms(SdfPath const& prototy
}
}

// "rotate" holds a quaternion in <real, i, j, k> format for each index.
if (_primvarMap.count(_tokens->rotate) > 0) {
HdVP2BufferSampler sampler(*_primvarMap[_tokens->rotate]);
// "hydra:instanceRotations" holds a quaternion in <real, i, j, k> format
// for each index.
#if HD_API_VERSION < 56
if (_primvarMap.count(HdInstancerTokens->rotate) > 0) {
HdVP2BufferSampler sampler(*_primvarMap[HdInstancerTokens->rotate]);
#else
if (_primvarMap.count(HdInstancerTokens->instanceRotations) > 0) {
HdVP2BufferSampler sampler(*_primvarMap[HdInstancerTokens->instanceRotations]);
#endif
for (size_t i = 0; i < instanceIndices.size(); ++i) {
GfQuath quath;
if (sampler.Sample(instanceIndices[i], &quath)) {
Expand All @@ -194,9 +194,14 @@ VtMatrix4dArray HdVP2Instancer::ComputeInstanceTransforms(SdfPath const& prototy
}
}

// "scale" holds an axis-aligned scale vector for each index.
if (_primvarMap.count(_tokens->scale) > 0) {
HdVP2BufferSampler sampler(*_primvarMap[_tokens->scale]);
// "hydra:instanceScales" holds an axis-aligned scale vector for each index.
#if HD_API_VERSION < 56
if (_primvarMap.count(HdInstancerTokens->scale) > 0) {
HdVP2BufferSampler sampler(*_primvarMap[HdInstancerTokens->scale]);
#else
if (_primvarMap.count(HdInstancerTokens->instanceScales) > 0) {
HdVP2BufferSampler sampler(*_primvarMap[HdInstancerTokens->instanceScales]);
#endif
for (size_t i = 0; i < instanceIndices.size(); ++i) {
GfVec3f scale;
if (sampler.Sample(instanceIndices[i], &scale)) {
Expand All @@ -207,9 +212,14 @@ VtMatrix4dArray HdVP2Instancer::ComputeInstanceTransforms(SdfPath const& prototy
}
}

// "instanceTransform" holds a 4x4 transform matrix for each index.
if (_primvarMap.count(_tokens->instanceTransform) > 0) {
HdVP2BufferSampler sampler(*_primvarMap[_tokens->instanceTransform]);
// "hydra:instanceTransforms" holds a 4x4 transform matrix for each index.
#if HD_API_VERSION < 56
if (_primvarMap.count(HdInstancerTokens->instanceTransform) > 0) {
HdVP2BufferSampler sampler(*_primvarMap[HdInstancerTokens->instanceTransform]);
#else
if (_primvarMap.count(HdInstancerTokens->instanceTransforms) > 0) {
HdVP2BufferSampler sampler(*_primvarMap[HdInstancerTokens->instanceTransforms]);
#endif
for (size_t i = 0; i < instanceIndices.size(); ++i) {
GfMatrix4d instanceTransform;
if (sampler.Sample(instanceIndices[i], &instanceTransform)) {
Expand Down
33 changes: 15 additions & 18 deletions lib/usd/hdMaya/adapters/dagAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ PXR_NAMESPACE_OPEN_SCOPE

TF_REGISTRY_FUNCTION(TfType) { TfType::Define<HdMayaDagAdapter, TfType::Bases<HdMayaAdapter>>(); }

// clang-format off
TF_DEFINE_PRIVATE_TOKENS(
_tokens,

(translate)
(rotate)
(scale)
(instanceTransform)
(instancer)
);
// clang-format on

namespace {

void _TransformNodeDirty(MObject& node, MPlug& plug, void* clientData)
Expand Down Expand Up @@ -116,9 +104,14 @@ void _InstancerNodeDirty(MObject& node, MPlug& plug, void* clientData)
| HdChangeTracker::DirtyPrimvar);
}

const auto _instancePrimvarDescriptors = HdPrimvarDescriptorVector {
{ _tokens->instanceTransform, HdInterpolationInstance, HdPrimvarRoleTokens->none },
};
const auto _instancePrimvarDescriptors = HdPrimvarDescriptorVector { {
#if HD_API_VERSION < 56
HdInstancerTokens->instanceTransform
#else
HdInstancerTokens->instanceTransforms,
#endif
HdInterpolationInstance,
HdPrimvarRoleTokens->none } };

} // namespace

Expand Down Expand Up @@ -213,7 +206,7 @@ void HdMayaDagAdapter::RemovePrim()
}
GetDelegate()->RemoveRprim(GetID());
if (_isInstanced) {
GetDelegate()->RemoveInstancer(GetID().AppendProperty(_tokens->instancer));
GetDelegate()->RemoveInstancer(GetID().AppendProperty(HdInstancerTokens->instancer));
}
_isPopulated = false;
}
Expand Down Expand Up @@ -290,7 +283,7 @@ SdfPath HdMayaDagAdapter::GetInstancerID() const
return {};
}

return GetID().AppendProperty(_tokens->instancer);
return GetID().AppendProperty(HdInstancerTokens->instancer);
}

HdPrimvarDescriptorVector
Expand All @@ -307,7 +300,11 @@ bool HdMayaDagAdapter::_GetVisibility() const { return GetDagPath().isVisible();

VtValue HdMayaDagAdapter::GetInstancePrimvar(const TfToken& key)
{
if (key == _tokens->instanceTransform) {
#if HD_API_VERSION < 56
if (key == HdInstancerTokens->instanceTransform) {
#else
if (key == HdInstancerTokens->instanceTransforms) {
#endif
MDagPathArray dags;
if (!MDagPath::getAllPathsTo(GetDagPath().node(), dags)) {
return {};
Expand Down

0 comments on commit 853fb1b

Please sign in to comment.