Blender V4.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 "scene/volume.h"
10
12
13// clang-format off
15 (openvdbAsset)
16);
17// clang-format on
18
19HdCyclesVolume::HdCyclesVolume(const SdfPath &rprimId
20#if PXR_VERSION < 2102
21 ,
22 const SdfPath &instancerId
23#endif
24 )
25 : HdCyclesGeometry(rprimId
26#if PXR_VERSION < 2102
27 ,
28 instancerId
29#endif
30 )
31{
32}
33
35
37{
39 bits |= HdChangeTracker::DirtyVolumeField;
40 return bits;
41}
42
43void HdCyclesVolume::Populate(HdSceneDelegate *sceneDelegate, HdDirtyBits dirtyBits, bool &rebuild)
44{
45 Scene *const scene = (Scene *)_geom->get_owner();
46
47 if (dirtyBits & HdChangeTracker::DirtyVolumeField) {
48 for (const HdVolumeFieldDescriptor &field : sceneDelegate->GetVolumeFieldDescriptors(GetId()))
49 {
50 if (const auto openvdbAsset = static_cast<HdCyclesField *>(
51 sceneDelegate->GetRenderIndex().GetBprim(_tokens->openvdbAsset, field.fieldId)))
52 {
53 const ustring name(field.fieldName.GetString());
54
58 }
61 }
64 }
67 }
70 }
73 }
74
75 // Skip attributes that are not needed
76 if ((std != ATTR_STD_NONE && _geom->need_attribute(scene, std)) ||
77 _geom->need_attribute(scene, name))
78 {
79 Attribute *const attr = (std != ATTR_STD_NONE) ?
80 _geom->attributes.add(std) :
81 _geom->attributes.add(
82 name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL);
83 attr->data_voxel() = openvdbAsset->GetImageHandle();
84 }
85 }
86 }
87
88 rebuild = true;
89 }
90}
91
static const char * standard_name(AttributeStandard std)
ImageHandle & data_voxel()
void add(const float &f)
PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override
Definition geometry.inl:49
HdCyclesVolume(const PXR_NS::SdfPath &rprimId, const PXR_NS::SdfPath &instancerId={})
PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override
~HdCyclesVolume() override
#define HDCYCLES_NAMESPACE_CLOSE_SCOPE
HDCYCLES_NAMESPACE_OPEN_SCOPE TF_DEFINE_PRIVATE_TOKENS(_tokens,(openvdbAsset))
AttributeStandard
@ ATTR_STD_VOLUME_TEMPERATURE
@ ATTR_STD_NONE
@ ATTR_STD_VOLUME_DENSITY
@ ATTR_STD_VOLUME_FLAME
@ ATTR_STD_VOLUME_VELOCITY
@ ATTR_STD_VOLUME_COLOR
@ ATTR_STD_VOLUME_HEAT
@ ATTR_ELEMENT_VOXEL