Blender V4.3
usd_reader_volume.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Tangent Animation. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include "BLI_string.h"
8
9#include "BKE_object.hh"
10#include "BKE_volume.hh"
11
12#include "DNA_object_types.h"
13#include "DNA_volume_types.h"
14
15#include <pxr/usd/usdVol/openVDBAsset.h>
16#include <pxr/usd/usdVol/volume.h>
17
18namespace usdtokens {
19
20static const pxr::TfToken density("density", pxr::TfToken::Immortal);
21
22}
23
24namespace blender::io::usd {
25
26void USDVolumeReader::create_object(Main *bmain, const double /*motionSampleTime*/)
27{
28 Volume *volume = (Volume *)BKE_volume_add(bmain, name_.c_str());
29
31 object_->data = volume;
32}
33
34void USDVolumeReader::read_object_data(Main *bmain, const double motionSampleTime)
35{
36 if (!volume_) {
37 return;
38 }
39
40 Volume *volume = static_cast<Volume *>(object_->data);
41
42 if (!volume) {
43 return;
44 }
45
46 pxr::UsdVolVolume::FieldMap fields = volume_.GetFieldPaths();
47
48 for (pxr::UsdVolVolume::FieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it) {
49
50 pxr::UsdPrim fieldPrim = prim_.GetStage()->GetPrimAtPath(it->second);
51
52 if (!fieldPrim.IsA<pxr::UsdVolOpenVDBAsset>()) {
53 continue;
54 }
55
56 pxr::UsdVolOpenVDBAsset fieldBase(fieldPrim);
57
58 pxr::UsdAttribute filepathAttr = fieldBase.GetFilePathAttr();
59
60 if (filepathAttr.IsAuthored()) {
61 pxr::SdfAssetPath fp;
62 filepathAttr.Get(&fp, motionSampleTime);
63
64 if (filepathAttr.ValueMightBeTimeVarying()) {
65 std::vector<double> filePathTimes;
66 filepathAttr.GetTimeSamples(&filePathTimes);
67
68 if (!filePathTimes.empty()) {
69 int start = int(filePathTimes.front());
70 int end = int(filePathTimes.back());
71
72 volume->is_sequence = char(true);
73 volume->frame_start = start;
74 volume->frame_duration = (end - start) + 1;
75 }
76 }
77
78 std::string filepath = fp.GetResolvedPath();
79
80 STRNCPY(volume->filepath, filepath.c_str());
81 }
82 }
83
84 USDXformReader::read_object_data(bmain, motionSampleTime);
85}
86
87} // namespace blender::io::usd
General operations, lookup, etc. for blender objects.
Object * BKE_object_add_only_object(Main *bmain, int type, const char *name) ATTR_RETURNS_NONNULL
Volume data-block.
void * BKE_volume_add(Main *bmain, const char *name)
#define STRNCPY(dst, src)
Definition BLI_string.h:593
Object is a sort of wrapper for general info.
@ OB_VOLUME
void create_object(Main *bmain, double motionSampleTime) override
void read_object_data(Main *bmain, double motionSampleTime) override
void read_object_data(Main *bmain, double motionSampleTime) override
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
static const pxr::TfToken density("density", pxr::TfToken::Immortal)