mirror of
https://github.com/blender/blender
synced 2026-10-25 03:07:01 +03:00
The 1.0 API is deprecated (though not yet removed) in OpenUSD 26.xx releases. So it's time to migrate. Use of the HdSceneDelegate is mostly removed, except for retrieving the prims. Specific properties of prims are retrieved through schemas rather than querying the scene delegate. The full replacement of HdSceneDelegate is still ongoing in USD itself. In the very latest 26.05 only HdPrman has an experimental option for using the scene index directly, but for example HdStorm does not use it yet. So removing it's use with the current 25.08 in Blender is not expected to be stable enough. Additionally HdRenderer is supposed to replace HdRenderDelegate and its handling of tasks. However even in 26.05 that is only a stub implementation so there is no actual alternative to migrate to. Note that OpenUSD provides a compatibility layer so 1.0 and 2.0 hosts and render delegates can work together. Which means ideally everything keeps working the same, but there are likely some differences anyway. Support for OpenUSD version 23.xx and older was dropped. Pull Request: https://projects.blender.org/blender/blender/pulls/158456
109 lines
2.8 KiB
C++
109 lines
2.8 KiB
C++
/* SPDX-FileCopyrightText: 2022 NVIDIA Corporation
|
|
* SPDX-FileCopyrightText: 2022 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
|
|
|
#include "hydra/field.h"
|
|
#include "hydra/util.h"
|
|
|
|
#include "util/log.h"
|
|
|
|
#ifdef WITH_OPENVDB
|
|
# include "hydra/session.h"
|
|
# include "scene/image_vdb.h"
|
|
# include "scene/scene.h"
|
|
#endif
|
|
|
|
#include <pxr/imaging/hd/sceneDelegate.h>
|
|
#include <pxr/imaging/hd/volumeFieldSchema.h>
|
|
#include <pxr/usd/sdf/assetPath.h>
|
|
|
|
HDCYCLES_NAMESPACE_OPEN_SCOPE
|
|
|
|
#ifdef WITH_OPENVDB
|
|
class HdCyclesVolumeLoader : public VDBImageLoader {
|
|
public:
|
|
HdCyclesVolumeLoader(const std::string &filePath, const std::string &gridName)
|
|
: VDBImageLoader(gridName)
|
|
{
|
|
/* Disable delay loading and file copying, this has poor performance on network drives. */
|
|
const bool delay_load = false;
|
|
try {
|
|
openvdb::io::File file(filePath);
|
|
# ifdef OPENVDB_USE_DELAYED_LOADING
|
|
file.setCopyMaxBytes(0);
|
|
# endif
|
|
if (file.open(delay_load)) {
|
|
grid = file.readGrid(gridName);
|
|
}
|
|
}
|
|
catch (const openvdb::IoError &e) {
|
|
LOG_ERROR << "Error loading OpenVDB file: " << e.what();
|
|
}
|
|
catch (...) {
|
|
LOG_ERROR << "Error loading OpenVDB file: Unknown error";
|
|
}
|
|
}
|
|
};
|
|
#endif
|
|
|
|
HdCyclesField::HdCyclesField(const SdfPath &bprimId, const TfToken & /*typeId*/) : HdField(bprimId)
|
|
{
|
|
}
|
|
|
|
HdCyclesField::~HdCyclesField() = default;
|
|
|
|
HdDirtyBits HdCyclesField::GetInitialDirtyBitsMask() const
|
|
{
|
|
return DirtyBits::DirtyParams;
|
|
}
|
|
|
|
void HdCyclesField::Sync(HdSceneDelegate *sceneDelegate,
|
|
HdRenderParam *renderParam,
|
|
HdDirtyBits *dirtyBits)
|
|
{
|
|
#ifdef WITH_OPENVDB
|
|
const SdfPath &id = GetId();
|
|
|
|
if (*dirtyBits & DirtyBits::DirtyParams) {
|
|
const HdSceneIndexPrim prim = GetPrim(sceneDelegate, id);
|
|
HdVolumeFieldSchema schema = HdVolumeFieldSchema::GetFromParent(prim.dataSource);
|
|
|
|
SdfAssetPath assetPath;
|
|
if (auto ds = schema.GetFilePath()) {
|
|
assetPath = ds->GetTypedValue(0.0f);
|
|
}
|
|
|
|
std::string filename = assetPath.GetResolvedPath();
|
|
if (filename.empty()) {
|
|
filename = assetPath.GetAssetPath();
|
|
}
|
|
|
|
if (!filename.empty()) {
|
|
TfToken fieldName;
|
|
if (auto ds = schema.GetFieldName()) {
|
|
fieldName = ds->GetTypedValue(0.0f);
|
|
}
|
|
|
|
if (!fieldName.IsEmpty()) {
|
|
unique_ptr<ImageLoader> loader = make_unique<HdCyclesVolumeLoader>(filename,
|
|
fieldName.GetString());
|
|
|
|
const SceneLock lock(renderParam);
|
|
|
|
ImageParams params;
|
|
params.frame = 0.0f;
|
|
|
|
_handle = lock.scene->image_manager->add_image(std::move(loader), params, false);
|
|
}
|
|
}
|
|
}
|
|
#else
|
|
(void)sceneDelegate;
|
|
(void)renderParam;
|
|
#endif
|
|
|
|
*dirtyBits = DirtyBits::Clean;
|
|
}
|
|
|
|
HDCYCLES_NAMESPACE_CLOSE_SCOPE
|