Skip to content

Commit

Permalink
adds light/isLight bool and light/materialSyncMode data sources for i…
Browse files Browse the repository at this point in the history
…dentifying presence and behavior of LightAPI on non-light types (i.e. mesh light)

(Internal change: 2248046)
  • Loading branch information
stevelavietes authored and pixar-oss committed Sep 7, 2022
1 parent 1618739 commit f450728
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions pxr/usdImaging/usdImaging/lightAPIAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@

PXR_NAMESPACE_OPEN_SCOPE

// XXX currently private while experimenting with this convention.
TF_DEFINE_PRIVATE_TOKENS(
_tokens,
(isLight)
(materialSyncMode)
);


TF_REGISTRY_FUNCTION(TfType)
{
typedef UsdImagingLightAPIAdapter Adapter;
Expand Down Expand Up @@ -64,16 +72,15 @@ _IsQueryTrivial(UsdCollectionAPI::MembershipQuery const& query)
ruleMap.begin()->second == UsdTokens->expandPrims;
}

class _LightDataSource : public HdContainerDataSource
class _LightDataSource final : public HdContainerDataSource
{
public:
HD_DECLARE_DATASOURCE(_LightDataSource);


bool
Has(const TfToken & name) override
{
for (const TfToken &n : GetNames()) {
for (const TfToken &n : _GetNames()) {
if (name == n) {
return true;
}
Expand All @@ -84,14 +91,7 @@ class _LightDataSource : public HdContainerDataSource
TfTokenVector
GetNames() override
{
static const TfTokenVector names = {
HdTokens->filters,
HdTokens->lightLink,
HdTokens->shadowLink,
//HdTokens->lightFilterLink,
};

return names;
return _GetNames();
}

HdDataSourceBaseHandle
Expand Down Expand Up @@ -129,12 +129,35 @@ class _LightDataSource : public HdContainerDataSource
// collection.
return HdRetainedTypedSampledDataSource<TfToken>::New(
c.GetCollectionPath().GetToken());
} else if (name == _tokens->isLight) {
return HdRetainedTypedSampledDataSource<bool>::New(true);
} else if (name == _tokens->materialSyncMode) {
if (UsdAttribute attr = _lightApi.GetMaterialSyncModeAttr()) {
TfToken v;
if (attr.Get(&v)) {
return HdRetainedTypedSampledDataSource<TfToken>::New(v);
}
}
}

return nullptr;
}

private:

static const TfTokenVector & _GetNames()
{
static const TfTokenVector names = {
HdTokens->filters,
HdTokens->lightLink,
HdTokens->shadowLink,
_tokens->isLight,
_tokens->materialSyncMode,
};

return names;
}

_LightDataSource(const UsdLuxLightAPI &lightApi)
: _lightApi(lightApi)
{}
Expand Down

0 comments on commit f450728

Please sign in to comment.