Blender  V3.3
hydra/volume.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2022 NVIDIA Corporation
3  * Copyright 2022 Blender Foundation */
4 
5 #include "hydra/volume.h"
6 #include "hydra/field.h"
7 #include "hydra/geometry.inl"
8 #include "scene/volume.h"
9 
11 
12 // clang-format off
14  (openvdbAsset)
15 );
16 // clang-format on
17 
18 HdCyclesVolume::HdCyclesVolume(const SdfPath &rprimId
19 #if PXR_VERSION < 2102
20  ,
21  const SdfPath &instancerId
22 #endif
23  )
24  : HdCyclesGeometry(rprimId
25 #if PXR_VERSION < 2102
26  ,
27  instancerId
28 #endif
29  )
30 {
31 }
32 
34 {
35 }
36 
38 {
39  HdDirtyBits bits = HdCyclesGeometry::GetInitialDirtyBitsMask();
40  bits |= HdChangeTracker::DirtyVolumeField;
41  return bits;
42 }
43 
44 void HdCyclesVolume::Populate(HdSceneDelegate *sceneDelegate, HdDirtyBits dirtyBits, bool &rebuild)
45 {
46  Scene *const scene = (Scene *)_geom->get_owner();
47 
48  if (dirtyBits & HdChangeTracker::DirtyVolumeField) {
49  for (const HdVolumeFieldDescriptor &field :
50  sceneDelegate->GetVolumeFieldDescriptors(GetId())) {
51  if (const auto openvdbAsset = static_cast<HdCyclesField *>(
52  sceneDelegate->GetRenderIndex().GetBprim(_tokens->openvdbAsset, field.fieldId))) {
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  Attribute *const attr = (std != ATTR_STD_NONE) ?
79  _geom->attributes.add(std) :
80  _geom->attributes.add(
81  name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL);
82  attr->data_voxel() = openvdbAsset->GetImageHandle();
83  }
84  }
85  }
86 
87  rebuild = true;
88  }
89 }
90 
ImageHandle & data_voxel()
static const char * standard_name(AttributeStandard std)
PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override
Definition: geometry.inl:48
HdCyclesVolume(const PXR_NS::SdfPath &rprimId, const PXR_NS::SdfPath &instancerId={})
PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override
~HdCyclesVolume() override
Scene scene
#define HDCYCLES_NAMESPACE_CLOSE_SCOPE
Definition: hydra/config.h:17
HDCYCLES_NAMESPACE_OPEN_SCOPE TF_DEFINE_PRIVATE_TOKENS(_tokens,(openvdbAsset))
AttributeStandard
Definition: kernel/types.h:612
@ ATTR_STD_VOLUME_TEMPERATURE
Definition: kernel/types.h:637
@ ATTR_STD_NONE
Definition: kernel/types.h:613
@ ATTR_STD_VOLUME_DENSITY
Definition: kernel/types.h:633
@ ATTR_STD_VOLUME_FLAME
Definition: kernel/types.h:635
@ ATTR_STD_VOLUME_VELOCITY
Definition: kernel/types.h:638
@ ATTR_STD_VOLUME_COLOR
Definition: kernel/types.h:634
@ ATTR_STD_VOLUME_HEAT
Definition: kernel/types.h:636
@ ATTR_ELEMENT_VOXEL
Definition: kernel/types.h:609