-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tracking material assignments to shapes and resyncing material IDs if…
- Loading branch information
Showing
15 changed files
with
316 additions
and
14 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
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
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,78 @@ | ||
// Copyright 2021 Autodesk, Inc. | ||
// | ||
// 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. | ||
#include "material_tracker.h" | ||
|
||
#include "render_delegate.h" | ||
|
||
PXR_NAMESPACE_OPEN_SCOPE | ||
|
||
VtArray<SdfPath> HdArnoldMaterialTracker::GetCurrentMaterials(size_t newArraySize) | ||
{ | ||
auto currentMaterials = _materials; | ||
if (_materials.size() != newArraySize) { | ||
_materials.resize(newArraySize); | ||
} | ||
return currentMaterials; | ||
} | ||
|
||
void HdArnoldMaterialTracker::SetMaterial(const SdfPath& id, size_t arrayId) | ||
{ | ||
if (Ai_likely(_materials.size() > arrayId)) { | ||
// cdata is a simple way to access the data without triggering a copy. | ||
if (id != _materials.cdata()[arrayId]) { | ||
// Trigger detaching. | ||
_materials[arrayId] = id; | ||
} | ||
} | ||
} | ||
|
||
void HdArnoldMaterialTracker::TrackMaterialChanges( | ||
HdArnoldRenderDelegate* renderDelegate, const SdfPath& shapeId, const VtArray<SdfPath>& oldMaterials) | ||
{ | ||
if (!oldMaterials.IsIdentical(_materials)) { | ||
// All the VtArrays are shared, so we don't have to worry about duplicating data here. | ||
// Untracking the old materials. | ||
if (!oldMaterials.empty()) { | ||
renderDelegate->UntrackShapeMaterials(shapeId, oldMaterials); | ||
} | ||
// Tracking the new materials. | ||
renderDelegate->TrackShapeMaterials(shapeId, _materials); | ||
} | ||
} | ||
|
||
void HdArnoldMaterialTracker::TrackSingleMaterial( | ||
HdArnoldRenderDelegate* renderDelegate, const SdfPath& shapeId, const SdfPath& materialId) | ||
{ | ||
// Initial assignment. | ||
if (_materials.empty()) { | ||
_materials.assign(1, materialId); | ||
renderDelegate->TrackShapeMaterials(shapeId, _materials); | ||
// We already have a single material stored, check if it has changed. | ||
} else { | ||
if (_materials.cdata()[0] != materialId) { | ||
renderDelegate->UntrackShapeMaterials(shapeId, _materials); | ||
_materials[0] = materialId; | ||
renderDelegate->TrackShapeMaterials(shapeId, _materials); | ||
} | ||
} | ||
} | ||
|
||
void HdArnoldMaterialTracker::UntrackMaterials(HdArnoldRenderDelegate* renderDelegate, const SdfPath& shapeId) | ||
{ | ||
if (!_materials.empty()) { | ||
renderDelegate->UntrackShapeMaterials(shapeId, _materials); | ||
} | ||
} | ||
|
||
PXR_NAMESPACE_CLOSE_SCOPE |
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,76 @@ | ||
// Copyright 2021 Autodesk, Inc. | ||
// | ||
// 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. | ||
/// @file material_tracker.h | ||
/// | ||
/// Utilities for tracking material changes on shapes. | ||
#pragma once | ||
|
||
#include "api.h" | ||
|
||
#include <pxr/pxr.h> | ||
|
||
#include <pxr/base/vt/array.h> | ||
|
||
#include <pxr/usd/sdf/path.h> | ||
|
||
PXR_NAMESPACE_OPEN_SCOPE | ||
|
||
class HdArnoldRenderDelegate; | ||
|
||
/// Class to track material assignments to shapes. | ||
class HdArnoldMaterialTracker { | ||
public: | ||
/// Queries the list of current materials. | ||
/// | ||
/// @param newArraySize Size of the materials after querying the old array. | ||
/// @return A copy of the current materials. | ||
HDARNOLD_API | ||
VtArray<SdfPath> GetCurrentMaterials(size_t newArraySize); | ||
|
||
/// Check if a material has changed and store the new material. | ||
/// | ||
/// @param id Path to the new material. | ||
/// @param arrayId Index of the material. | ||
HDARNOLD_API | ||
void SetMaterial(const SdfPath& id, size_t arrayId); | ||
|
||
/// Track material changes if materials has been changed. | ||
/// | ||
/// @param renderDelegate Pointer to the Arnold Render Delegate. | ||
/// @param shapeId Id of the current shape. | ||
/// @param oldMaterials List of the materials assigned to the shape before assigning materials. | ||
HDARNOLD_API | ||
void TrackMaterialChanges( | ||
HdArnoldRenderDelegate* renderDelegate, const SdfPath& shapeId, const VtArray<SdfPath>& oldMaterials); | ||
|
||
/// Track material if there is only a single material assigned to the shape. | ||
/// | ||
/// @param renderDelegate Pointer to the Arnold Render Delegate. | ||
/// @param shapeId Id of the current shape. | ||
/// @param materialId The material assigned to the shape. | ||
HDARNOLD_API | ||
void TrackSingleMaterial(HdArnoldRenderDelegate* renderDelegate, const SdfPath& shapeId, const SdfPath& materialId); | ||
|
||
/// Untrack all materials assigned to the shape. Typically used when deleting the shape. | ||
/// | ||
/// @param renderDelegate Pointer to the Arnold Render Delegate. | ||
/// @param shapeId Id of the current shape. | ||
HDARNOLD_API | ||
void UntrackMaterials(HdArnoldRenderDelegate* renderDelegate, const SdfPath& shapeId); | ||
|
||
private: | ||
VtArray<SdfPath> _materials; ///< List of materials currently assigned. | ||
}; | ||
|
||
PXR_NAMESPACE_CLOSE_SCOPE |
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.