Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HYDRA-600 : Add filtering scene index interface to flow viewport tool… #21

Merged
merged 6 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/flowViewport/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ set(HEADERS
fvpInformationInterface.h
fvpInformationClient.h
fvpDataProducerSceneIndexInterface.h
fvpFilteringSceneIndexClient.h
fvpFilteringSceneIndexClientFwd.h
fvpFilteringSceneIndexInterface.h
fvpViewportAPITokens.h
)

# -----------------------------------------------------------------------------
Expand Down
13 changes: 4 additions & 9 deletions lib/flowViewport/API/fvpDataProducerSceneIndexInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

//Local headers
#include "flowViewport/api.h"
#include "flowViewport/API/fvpViewportAPITokens.h"

//Hydra headers
#include <pxr/imaging/hd/sceneIndex.h>
Expand All @@ -38,12 +39,6 @@ namespace FVP_NS_DEF
/// Interface accessor
static FVP_API DataProducerSceneIndexInterface& get();

/// Use this string in the viewport identifier parameters, named "hydraViewportId" in this class, to apply the data producer scene index to all viewports.
static FVP_API const std::string allViewports;

/// Use this string in the AddDataProducerSceneIndex method for the "rendererNames" parameter to apply to all renderers.
static FVP_API const std::string allRenderers;

/**
* @brief Adds a custom data producer scene index.
*
Expand Down Expand Up @@ -77,8 +72,8 @@ namespace FVP_NS_DEF
*/
virtual bool addDataProducerSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& customDataProducerSceneIndex,
void* dccNode = nullptr,
const std::string& hydraViewportId = allViewports,
const std::string& rendererNames = allRenderers,
const std::string& hydraViewportId = PXR_NS::FvpViewportAPITokens->allViewports,
const std::string& rendererNames = PXR_NS::FvpViewportAPITokens->allRenderers,
const PXR_NS::SdfPath& customDataProducerSceneIndexRootPathForInsertion = PXR_NS::SdfPath::AbsoluteRootPath()
) = 0;

Expand All @@ -94,7 +89,7 @@ namespace FVP_NS_DEF
*/
virtual void removeViewportDataProducerSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& customDataProducerSceneIndex,
const std::string& hydraViewportId = allViewports
const std::string& hydraViewportId = PXR_NS::FvpViewportAPITokens->allViewports
) = 0;
};

Expand Down
157 changes: 157 additions & 0 deletions lib/flowViewport/API/fvpFilteringSceneIndexClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
//
// Copyright 2023 Autodesk, Inc. All rights reserved.
//
// 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.
//


/// Is the definition of a customer Hydra client to register a set of callbacks for a Hydra viewport.
#ifndef FLOW_VIEWPORT_API_FILTERING_SCENE_INDEX_CLIENT_H
#define FLOW_VIEWPORT_API_FILTERING_SCENE_INDEX_CLIENT_H

#include "flowViewport/api.h"
#include "flowViewport/API/fvpViewportAPITokens.h"

#include <pxr/imaging/hd/sceneIndex.h>

namespace FVP_NS_DEF
{
///Subclass this to create a callbacks FilteringSceneIndexClient and register it through the FilteringSceneIndexInterface class
class FilteringSceneIndexClient
{
public:
/**
* A Category is a container in which you want your filtering scene index or scene index chain to go to.
* The filtering scene indices inside a Category don't have any specific priority when they are called.
*/
enum class Category
{
/// kSelectionHighlighting is to register a filtering scene index to do custom selection highlighting (still a WIP)
kSelectionHighlighting,
/** kSceneFiltering is to register a filtering scene index applied to the primitives from the scene,
* including usd stages, DCC native objects and custom data producer scene indices primitives.
*/
kSceneFiltering,
};

/**
* @brief Callback function to append a scene index.
*
* This callback function gets called for you to append a scene index to a Hydra viewport scene index, like a filtering scene index.
* A typical case is when a new Hydra viewport is created, after some internal managment of this scene index, we call this function so you can append one scene index
* or a chain of scene indices and return the last element of the chain.
* The returned value of this function is the last custom scene index of a a chain that you want to append to this scene index,
* or just return the input scene index passed if you don't want to append any scene index.
*
* @param[in] displayName is a display name to be associated with your plugin.
* @param[in] category is the container in which you want your filtering scene index (or filtering scene index chain) to go into.
* @param[in] rendererNames is the names of the renderers you want this client to be associated to.
* If there are several, separate them with for example a coma, like "GL, Arnold", we actually look for the renderer name in this string.
* If you want your client to work on any renderer please use FvpViewportAPITokens->allRenderers.
* @param[in] dccNode is a MObject* for Maya, if you provide the pointer value, then we automatically track some events such as visibility changed,
* node deleted/undeleted and we remove/add automatically your filtering scene indices from the viewport. Meaning if the maya node is visible your filtering
* scene indices are applied to the scene, if the node is not visible (or deleted) your filtering scene indices are removed from the scene.
* If it is a nullptr, your filtering scene indices will stay applied to the viewport(s) until you remove them.
*
* @param[in] inputArgs is a container data source handle to deal with the possibility to send custom data from our Hydra viewport plugin for the creation of your scene index.
* This parameter is currently not used by the Hydra viewport plugin but is left for possible future use.
*/
FilteringSceneIndexClient(const std::string& displayName, const Category category, const std::string& rendererNames, void* dccNode):
_displayName{displayName}, _category{category}, _rendererNames{rendererNames}, _dccNode{dccNode}
{}

/**
* @brief Callback function to append a scene index.
*
* This callback function gets called for you to append a scene index to a Hydra viewport scene index, like a filtering scene index.
* A typical case is when a new Hydra viewport is created, after some internal managment of this scene index, we call this function so you can append one scene index
* or a chain of scene indices and return the last element of the chain.
* The returned value of this function is the last custom scene index of a a chain that you want to append to this scene index,
* or just return the input scene index passed if you don't want to append any scene index.
*
* @param[in] inputSceneIndex is a HdSceneIndexBaseRefPtr which was created by our Hydra viewport plugin. This could be the Hydra viewport scene index or it could be some appended
* scene index, as a chain of scene indices is appended to the Hydra viewport scene index if several filtering scene index clients are registered.
* So don't assume it's the Hydra viewport scene index.
* @param[in] inputArgs is a container data source handle to deal with the possibility to send custom data from our Hydra viewport plugin for the creation of your scene index.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of data? Why should it be in the form of an HdContainerDataSourceHandle? There are more flexible ways to do this, e.g. a VtDictionary:
https://openusd.org/release/api/class_vt_dictionary.html

* This parameter is currently not used by the Hydra viewport plugin but is left for possible future use.
*
* @return If you don't want to append a scene index, just return _inputSceneIndex.
* If you want to append a scene index or a scene indices chain, you should return the last scene index of the scene indices chain to append.
*/
virtual PXR_NS::HdSceneIndexBaseRefPtr appendSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, const PXR_NS::HdContainerDataSourceHandle& inputArgs) = 0;

/// Destructor
virtual ~FilteringSceneIndexClient() = default;

/**
* @brief Get the display name.
* @return the display name.
*/
const std::string& getDisplayName() const {return _displayName;}

/**
* @brief Get the Category.
* @return the Category.
*/
const Category getCategory() const {return _category;}

/**
* @brief Get the renderer names.
* @return the renderer names.
*/
const std::string& getRendererNames() const {return _rendererNames;}

/**
* @brief Set the dcc node.
*/
void setDccNode(void* dccNode) {_dccNode = dccNode;}

/**
* @brief Get the dcc node.
* @return the dcc node.
*/
void* getDccNode() const {return _dccNode;}

bool operator == (const FilteringSceneIndexClient& other)const
{
return _displayName == other._displayName &&
_category == other._category &&
_rendererNames == other._rendererNames &&
_dccNode == other._dccNode;
}

protected:
/**_displayName is a display name to be associated with your plugin.
*/
const std::string _displayName {"Unnamed"};

/**_category is the container in which you want your filtering scene index (or filtering scene index chain) to go into.
*/
const Category _category {Category::kSceneFiltering};

/**_rendererNames is the names of the renderers you want this client to be associated to.
* If there are several, separate them with comas, like "GL, Arnold"
* If you want your client to work on any renderer please use FvpViewportAPITokens->allRenderers.
*/
const std::string _rendererNames = PXR_NS::FvpViewportAPITokens->allRenderers;

/**_dccNode is a MObject* for Maya, if you provide the pointer value, then we automatically track some events such as visibility changed,
* node deleted/undeleted and we remove/add automatically your filtering scene indices from the viewport. Meaning if the maya node is visible your filtering
* scene indices are applied to the scene, if the node is not visible (or deleted) your filtering scene indices are removed from the scene.
* If it is a nullptr, your filtering scene indices will stay applied to the viewport(s) until you remove them.
*/
void* _dccNode = nullptr;
};
}//end of namespace

#endif //FLOW_VIEWPORT_API_FILTERING_SCENE_INDEX_CLIENT_H
35 changes: 35 additions & 0 deletions lib/flowViewport/API/fvpFilteringSceneIndexClientFwd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Copyright 2023 Autodesk, Inc. All rights reserved.
//
// 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.
//


/// Is the forward declaration of a FilteringSceneIndexClient

#ifndef FLOW_VIEWPORT_API_FILTERING_SCENE_INDEX_CLIENT_FWD_H
#define FLOW_VIEWPORT_API_FILTERING_SCENE_INDEX_CLIENT_FWD_H

#include "flowViewport/api.h"

#include <memory>

//Is the forward declaration of the FilteringSceneIndexClient class and FilteringSceneIndexClientPtr
namespace FVP_NS_DEF
{
class FilteringSceneIndexClient;
using FilteringSceneIndexClientPtr = std::shared_ptr<FilteringSceneIndexClient>;

}//end of namespace

#endif //FLOW_VIEWPORT_API_FILTERING_SCENE_INDEX_CLIENT_FWD_H
65 changes: 65 additions & 0 deletions lib/flowViewport/API/fvpFilteringSceneIndexInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// Copyright 2023 Autodesk, Inc. All rights reserved.
//
// 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_API_FILTERING_SCENE_INDEX_INTERFACE_H
#define FLOW_VIEWPORT_API_FILTERING_SCENE_INDEX_INTERFACE_H

//Local headers
#include "flowViewport/api.h"
#include "flowViewport/sceneIndex/fvpRenderIndexProxyFwd.h"
#include "flowViewport/API/fvpFilteringSceneIndexClientFwd.h"

//Std headers
#include <string>

namespace FVP_NS_DEF
{
/**
* Interface to register a callbacks FilteringSceneIndexClient and append custom filtering scene indices to Hydra viewports scene indices.
* To get an instance of the FilteringSceneIndexInterface class, please use :
* Fvp::FilteringSceneIndexInterface& filteringSceneIndexInterface = Fvp::FilteringSceneIndexInterface::get();
*
* The filtering scene indices added to a hydra viewport will act on all kind of data : DCC native data, USD stages and custom primitives added by data producer scene indices.
*/
class FilteringSceneIndexInterface
{
public:

///Interface accessor
static FVP_API FilteringSceneIndexInterface& get();

/**
* @brief Register a callbacks SceneIndexClient instance
*
* @param[in] client is a FilteringSceneIndexClient.
*
* @return true if it succeded, false otherwise like the client if already registered.
*/
virtual bool registerFilteringSceneIndexClient(const std::shared_ptr<FilteringSceneIndexClient>& client) = 0;

/**
* @brief Unregister an SceneIndexClient instance
*
* Unregister an SceneIndexClient instance, to stop receiving notifications.
*
* @param[in] client is the FilteringSceneIndexClient to remove.
*/
virtual void unregisterFilteringSceneIndexClient(const std::shared_ptr<FilteringSceneIndexClient>& client)= 0;
};

}//end of namespace

#endif //FLOW_VIEWPORT_API_FILTERING_SCENE_INDEX_INTERFACE_H
11 changes: 9 additions & 2 deletions lib/flowViewport/API/fvpInformationInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,21 @@ namespace FVP_NS_DEF
: _viewportId(viewportId), _cameraName(cameraName) {}

///_viewportId is a Hydra viewport string identifier which is unique for all hydra viewports during a session
const std::string _viewportId;
std::string _viewportId;

///_cameraName is the name of the camera/viewport when the viewport was created, it is not updated if the camera's name has changed.
const std::string _cameraName;
std::string _cameraName;

///_rendererName is the Hydra viewport renderer name (example : "GL" for Storm or "Arnold" for the Arnold render delegate)
std::string _rendererName;

ViewportInformation& operator = (const ViewportInformation& other){
_viewportId = other._viewportId;
_cameraName = other._cameraName;
_rendererName = other._rendererName;
return *this;
}

bool operator ==(const ViewportInformation& other)const{
return _viewportId == other._viewportId &&
_cameraName == other._cameraName &&
Expand Down
42 changes: 42 additions & 0 deletions lib/flowViewport/API/fvpViewportAPITokens.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Copyright 2023 Autodesk, Inc. All rights reserved.
//
// 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.
//


/// Is the definition of a customer Hydra client to register a set of callbacks for a Hydra viewport.
#ifndef FLOW_VIEWPORT_API_VIEWPORT_API_TOKENS_H
#define FLOW_VIEWPORT_API_VIEWPORT_API_TOKENS_H

#include "flowViewport/api.h"

#include <pxr/base/tf/staticTokens.h>

// *** TODO / FIXME *** Figure out how to put tokens into non-Pixar namespace.

PXR_NAMESPACE_OPEN_SCOPE

// clang-format off
#define FVP_VIEWPORT_API_TOKENS\
/** Use this string in the viewport identifier parameters, named "hydraViewportId" in this class, to apply the data producer scene index to all viewports.*/\
(allViewports) \
/** Use this string for the "rendererNames" parameter to apply to all renderers.*/\
(allRenderers)
// clang-format on

TF_DECLARE_PUBLIC_TOKENS(FvpViewportAPITokens, FVP_API, FVP_VIEWPORT_API_TOKENS);

PXR_NAMESPACE_CLOSE_SCOPE

#endif //FLOW_VIEWPORT_API_VIEWPORT_API_TOKENS_H
2 changes: 2 additions & 0 deletions lib/flowViewport/API/interfacesImp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ target_sources(${TARGET_NAME}
fvpVersionInterfaceImp.cpp
fvpInformationInterfaceImp.cpp
fvpDataProducerSceneIndexInterfaceImp.cpp
fvpFilteringSceneIndexInterfaceImp.cpp
)

set(HEADERS
fvpSelectionInterfaceImp.h
fvpVersionInterfaceImp.h
fvpInformationInterfaceImp.h
fvpDataProducerSceneIndexInterfaceImp.h
fvpFilteringSceneIndexInterfaceImp.h
)

# -----------------------------------------------------------------------------
Expand Down
Loading