Blender V5.3
hydra/volume.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 NVIDIA Corporation
2 * SPDX-FileCopyrightText: 2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: Apache-2.0 */
5
6#include "hydra/volume.h"
7#include "hydra/field.h"
8#include "hydra/geometry.inl"
9#include "hydra/util.h"
10#include "scene/volume.h"
11
12#include <pxr/imaging/hd/volumeFieldBindingSchema.h>
13
15
16// clang-format off
18 (openvdbAsset)
19);
20// clang-format on
21
22HdCyclesVolume::HdCyclesVolume(const SdfPath &rprimId) : HdCyclesGeometry(rprimId) {}
23
25
27{
29 bits |= HdChangeTracker::DirtyVolumeField;
30 return bits;
31}
32
33void HdCyclesVolume::Populate(HdSceneDelegate *sceneDelegate, HdDirtyBits dirtyBits, bool &rebuild)
34{
35 Scene *const scene = (Scene *)_geom->get_owner();
36
37 /* USD/Hydra convention is that volume density is in object space. */
38 _geom->set_object_space(true);
39
40 if (dirtyBits & HdChangeTracker::DirtyVolumeField) {
41 const HdSceneIndexPrim prim = GetPrim(sceneDelegate, GetId());
42 HdVolumeFieldBindingSchema bindings = HdVolumeFieldBindingSchema::GetFromParent(
43 prim.dataSource);
44
45 for (const TfToken &fieldName : bindings.GetVolumeFieldBindingNames()) {
46 auto pathDs = bindings.GetVolumeFieldBinding(fieldName);
47 if (!pathDs) {
48 continue;
49 }
50 const SdfPath fieldId = pathDs->GetTypedValue(0.0f);
51
52 if (auto *const openvdbAsset = static_cast<HdCyclesField *>(
53 sceneDelegate->GetRenderIndex().GetBprim(_tokens->openvdbAsset, fieldId)))
54 {
55 const ustring name(fieldName.GetString());
56
58
59 // Skip attributes that are not needed
60 if ((std != ATTR_STD_NONE && _geom->need_attribute(scene, std)) ||
61 _geom->need_attribute(scene, name))
62 {
63 Attribute *const attr = (std != ATTR_STD_NONE) ?
64 _geom->attributes.add(std) :
65 _geom->attributes.add(name, TypeFloat, ATTR_ELEMENT_VOXEL);
66 attr->data_voxel_for_write() = openvdbAsset->GetImageHandle();
67 }
68 }
69 }
70
71 _geom->merge_grids(scene);
72
73 rebuild = true;
74 }
75}
76
ImageHandle & data_voxel_for_write()
static AttributeStandard name_volume_standard(ustring name)
HdCyclesGeometry(const PXR_NS::SdfPath &rprimId)
Definition geometry.inl:27
PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override
Definition geometry.inl:41
PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override
HdCyclesVolume(const PXR_NS::SdfPath &rprimId)
~HdCyclesVolume() override
Definition scene.h:133
#define HDCYCLES_NAMESPACE_CLOSE_SCOPE
TF_DEFINE_PRIVATE_TOKENS(_tokens,(visibleInPrimaryRay)(treatAsPoint)(falloff))
HDCYCLES_NAMESPACE_OPEN_SCOPE HdSceneIndexPrim GetPrim(HdSceneDelegate *delegate, const SdfPath &id)
@ ATTR_ELEMENT_VOXEL
AttributeStandard
@ ATTR_STD_NONE