Blender V5.0
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_path_utils.hh"
8#include "BLI_string.h"
9
10#include "BKE_main.hh"
11#include "BKE_object.hh"
12#include "BKE_volume.hh"
13
14#include "DNA_object_types.h"
15#include "DNA_volume_types.h"
16
17#include <pxr/usd/usdVol/openVDBAsset.h>
18#include <pxr/usd/usdVol/volume.h>
19
20namespace blender::io::usd {
21
23{
24 Volume *volume = BKE_volume_add(bmain, name_.c_str());
25
27 object_->data = volume;
28}
29
30void USDVolumeReader::read_object_data(Main *bmain, const pxr::UsdTimeCode time)
31{
32 Volume *volume = static_cast<Volume *>(object_->data);
33
34 pxr::UsdVolVolume::FieldMap fields = volume_.GetFieldPaths();
35
36 for (pxr::UsdVolVolume::FieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it) {
37
38 pxr::UsdPrim fieldPrim = prim_.GetStage()->GetPrimAtPath(it->second);
39
40 if (!fieldPrim.IsA<pxr::UsdVolOpenVDBAsset>()) {
41 continue;
42 }
43
44 pxr::UsdVolOpenVDBAsset fieldBase(fieldPrim);
45
46 pxr::UsdAttribute filepathAttr = fieldBase.GetFilePathAttr();
47
48 if (filepathAttr.IsAuthored()) {
49 pxr::SdfAssetPath fp;
50 filepathAttr.Get(&fp, time);
51
52 const std::string filepath = fp.GetResolvedPath();
53 STRNCPY(volume->filepath, filepath.c_str());
54
55 if (import_params_.relative_path && !BLI_path_is_rel(volume->filepath)) {
57 }
58
59 if (filepathAttr.ValueMightBeTimeVarying()) {
60 std::vector<double> filePathTimes;
61 filepathAttr.GetTimeSamples(&filePathTimes);
62
63 if (!filePathTimes.empty()) {
64 const int start = int(filePathTimes.front());
65 const int end = int(filePathTimes.back());
66 const int offset = BLI_path_sequence_decode(
67 volume->filepath, nullptr, 0, nullptr, 0, nullptr);
68
69 volume->is_sequence = char(true);
70 volume->frame_start = start;
71 volume->frame_duration = (end - start) + 1;
72 volume->frame_offset = offset - 1;
73 }
74 }
75 }
76 }
77
79}
80
81} // namespace blender::io::usd
const char * BKE_main_blendfile_path_from_global()
Definition main.cc:892
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.
Volume * BKE_volume_add(Main *bmain, const char *name)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
int BLI_path_sequence_decode(const char *path, char *head, size_t head_maxncpy, char *tail, size_t tail_maxncpy, unsigned short *r_digits_len)
Definition path_utils.cc:58
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:693
Object is a sort of wrapper for general info.
@ OB_VOLUME
const USDImportParams & import_params_
void create_object(Main *bmain) override
void read_object_data(Main *bmain, pxr::UsdTimeCode time) override
void read_object_data(Main *bmain, pxr::UsdTimeCode time) override
int frame_duration
char filepath[1024]
char is_sequence