-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HYDRA-794 : Support maya lighting modes for USD and dome lights (#167)
* HYDRA-794 : Support maya lighting modes for USD and dome lights (all kind of lights actually) * Fix tests * Fix maya lighting modes tests * Add a missing texture for tests * Remove grid from test. * Fix an issue in C++ code found by linux build * Fixes from code review
- Loading branch information
1 parent
f90b636
commit 378f0f0
Showing
25 changed files
with
769 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
lib/flowViewport/sceneIndex/fvpLightsManagementSceneIndex.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// | ||
// Copyright 2024 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
//Local headers | ||
#include "fvpLightsManagementSceneIndex.h" | ||
|
||
//USD/Hydra headers | ||
#include <pxr/imaging/hd/tokens.h> | ||
#include <pxr/imaging/hd/retainedDataSource.h> | ||
#include <pxr/imaging/hd/overlayContainerDataSource.h> | ||
#include <pxr/imaging/hd/containerDataSourceEditor.h> | ||
#include <pxr/imaging/hd/sceneIndexPrimView.h> | ||
#include <pxr/imaging/hd/light.h> | ||
#include <pxr/imaging/hd/lightSchema.h> | ||
#include <pxr/imaging/glf/simpleLight.h> | ||
|
||
//ufe | ||
#include <ufe/globalSelection.h> | ||
#include <ufe/observableSelection.h> | ||
|
||
|
||
PXR_NAMESPACE_USING_DIRECTIVE | ||
|
||
namespace { | ||
|
||
void _DisableLight(HdSceneIndexPrim& prim) | ||
{ | ||
HdContainerDataSourceEditor editor(prim.dataSource); | ||
//We don't set the intensity to 0 as for domelights this makes the geometry disappear | ||
for (const auto& t : { HdLightTokens->ambient, HdLightTokens->diffuse, HdLightTokens->specular }) { | ||
editor.Set( | ||
HdLightSchema::GetDefaultLocator().Append(t), | ||
HdRetainedTypedSampledDataSource<float>::New(0.0f)); | ||
} | ||
|
||
prim.dataSource = editor.Finish(); | ||
} | ||
|
||
} // end of anonymous namespace | ||
|
||
/// This is a filtering scene index that manages lights primitives | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
LightsManagementSceneIndex::LightsManagementSceneIndex(const HdSceneIndexBaseRefPtr& inputSceneIndex, const PathInterface& pathInterface, const SdfPath& defaultLightPath) | ||
: ParentClass(inputSceneIndex), | ||
InputSceneIndexUtils(inputSceneIndex) | ||
,_defaultLightPath(defaultLightPath) | ||
, _pathInterface(pathInterface) | ||
{ | ||
} | ||
|
||
void LightsManagementSceneIndex::SetLightingMode(LightingMode lightingMode) | ||
{ | ||
if (_lightingMode == lightingMode){ | ||
return; | ||
} | ||
|
||
_lightingMode = lightingMode; | ||
_DirtyAllLightsPrims(); | ||
} | ||
|
||
void LightsManagementSceneIndex::_DirtyAllLightsPrims() | ||
{ | ||
HdSceneIndexObserver::DirtiedPrimEntries entries; | ||
for (const SdfPath& path : HdSceneIndexPrimView(GetInputSceneIndex())) { | ||
auto primType = GetInputSceneIndex()->GetPrim(path).primType; | ||
if (HdPrimTypeIsLight(primType)) { | ||
entries.push_back({ path, HdLightSchema::GetDefaultLocator() }); | ||
} | ||
} | ||
_SendPrimsDirtied(entries); | ||
} | ||
|
||
bool LightsManagementSceneIndex::_IsDefaultLight(const SdfPath& primPath)const | ||
{ | ||
return primPath == _defaultLightPath; | ||
} | ||
|
||
HdSceneIndexPrim LightsManagementSceneIndex::GetPrim(const SdfPath& primPath) const | ||
{ | ||
auto prim = GetInputSceneIndex()->GetPrim(primPath); | ||
auto primType = prim.primType; | ||
if (! HdPrimTypeIsLight(primType)) { | ||
return prim;//return any non light primitive | ||
} | ||
|
||
//This is a light | ||
switch (_lightingMode) { | ||
case LightingMode::kNoLighting: { | ||
_DisableLight(prim); | ||
return prim; | ||
} break; | ||
default: | ||
case LightingMode::kSceneLighting: { | ||
return prim; | ||
} break; | ||
case LightingMode::kDefaultLighting: { | ||
if (! _IsDefaultLight(primPath)){ | ||
_DisableLight(prim); | ||
} | ||
return prim; | ||
} break; | ||
case LightingMode::kSelectedLightsOnly: { | ||
const Ufe::Selection& ufeSelection = *Ufe::GlobalSelection::get(); | ||
if (ufeSelection.empty()) { | ||
// Nothing is selected | ||
_DisableLight(prim); | ||
return prim; | ||
} | ||
|
||
//Convert ufe selection to SdfPath | ||
SdfPathVector selectedLightsSdfPath; | ||
for (const auto& snItem : ufeSelection) { | ||
auto primSelections = _pathInterface.UfePathToPrimSelections(snItem->path()); | ||
for (const auto& primSelection : primSelections) { | ||
selectedLightsSdfPath.push_back(primSelection.primPath); | ||
} | ||
} | ||
const bool isSelected = selectedLightsSdfPath.end() | ||
!= std::find(selectedLightsSdfPath.begin(), | ||
selectedLightsSdfPath.end(), | ||
primPath); | ||
|
||
if (! isSelected) { | ||
_DisableLight(prim); | ||
} | ||
|
||
return prim; | ||
} break; | ||
} | ||
|
||
return prim; | ||
} | ||
|
||
}//end of namespace FVP_NS_DEF |
103 changes: 103 additions & 0 deletions
103
lib/flowViewport/sceneIndex/fvpLightsManagementSceneIndex.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// Copyright 2024 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#ifndef FLOW_VIEWPORT_SCENE_INDEX_FLOW_VIEWPORT_LIGHTS_MANAGEMENT_SCENE_INDEX_H | ||
#define FLOW_VIEWPORT_SCENE_INDEX_FLOW_VIEWPORT_LIGHTS_MANAGEMENT_SCENE_INDEX_H | ||
|
||
//Local headers | ||
#include "flowViewport/api.h" | ||
#include "flowViewport/sceneIndex/fvpSceneIndexUtils.h" | ||
#include "flowViewport/sceneIndex/fvpPathInterface.h" | ||
|
||
//Hydra headers | ||
#include <pxr/base/tf/declarePtrs.h> | ||
#include <pxr/imaging/hd/filteringSceneIndex.h> | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
class LightsManagementSceneIndex; | ||
typedef PXR_NS::TfRefPtr<LightsManagementSceneIndex> LightsManagementSceneIndexRefPtr; | ||
typedef PXR_NS::TfRefPtr<const LightsManagementSceneIndex> LightsManagementSceneIndexConstRefPtr; | ||
|
||
/// \class LightsManagementSceneIndex | ||
/// | ||
/// This is a filtering scene index that manages lights primitives | ||
/// | ||
class LightsManagementSceneIndex : public PXR_NS::HdSingleInputFilteringSceneIndexBase | ||
, public Fvp::InputSceneIndexUtils<LightsManagementSceneIndex> | ||
{ | ||
public: | ||
using ParentClass = PXR_NS::HdSingleInputFilteringSceneIndexBase; | ||
using PXR_NS::HdSingleInputFilteringSceneIndexBase::_GetInputSceneIndex; | ||
|
||
FVP_API | ||
static LightsManagementSceneIndexRefPtr New(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, const PathInterface& pathInterface, const PXR_NS::SdfPath& defaultLightPath){ | ||
return PXR_NS::TfCreateRefPtr(new LightsManagementSceneIndex(inputSceneIndex, pathInterface, defaultLightPath)); | ||
} | ||
|
||
// From HdSceneIndexBase | ||
FVP_API | ||
PXR_NS::HdSceneIndexPrim GetPrim(const PXR_NS::SdfPath& primPath) const override; | ||
|
||
FVP_API | ||
PXR_NS::SdfPathVector GetChildPrimPaths(const PXR_NS::SdfPath& primPath) const override{ | ||
return GetInputSceneIndex()->GetChildPrimPaths(primPath); | ||
} | ||
|
||
FVP_API | ||
~LightsManagementSceneIndex() override = default; | ||
|
||
enum class LightingMode{ | ||
kNoLighting, | ||
kSceneLighting,//All lights | ||
kDefaultLighting, | ||
kSelectedLightsOnly, | ||
}; | ||
|
||
FVP_API | ||
void SetLightingMode(LightingMode lightingMode); | ||
|
||
FVP_API | ||
LightingMode GetLightingMode()const {return _lightingMode;} | ||
|
||
protected: | ||
|
||
LightsManagementSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, const PathInterface& pathInterface, const PXR_NS::SdfPath& defaultLightPath); | ||
|
||
//From HdSingleInputFilteringSceneIndexBase | ||
void _PrimsAdded(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::AddedPrimEntries& entries) override{ | ||
if (!_IsObserved())return; | ||
_SendPrimsAdded(entries); | ||
} | ||
void _PrimsRemoved(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::RemovedPrimEntries& entries)override{ | ||
if (!_IsObserved())return; | ||
_SendPrimsRemoved(entries); | ||
} | ||
void _PrimsDirtied(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::DirtiedPrimEntries& entries)override{ | ||
if (!_IsObserved())return; | ||
_SendPrimsDirtied(entries); | ||
} | ||
|
||
void _DirtyAllLightsPrims(); | ||
bool _IsDefaultLight(const PXR_NS::SdfPath& primPath)const; | ||
|
||
LightingMode _lightingMode = LightingMode::kSceneLighting; | ||
PXR_NS::SdfPath _defaultLightPath; | ||
const PathInterface& _pathInterface; | ||
}; | ||
|
||
}//end of namespace FVP_NS_DEF | ||
|
||
#endif //FLOW_VIEWPORT_SCENE_INDEX_FLOW_VIEWPORT_LIGHTS_MANAGEMENT_SCENE_INDEX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.