Commit: 4d1d7af43ccd44ce80380871d760ce9a4de11d65 Author: makowalski Date: Mon Jun 21 22:01:29 2021 -0400 Branches: usd-importer-T81257-merge https://developer.blender.org/rB4d1d7af43ccd44ce80380871d760ce9a4de11d65
USDVolumeReader improvements. Fixed Volume reference counting error (incorrect call to id_us_min()). Fixed error reading fieldName attribute, which was incorrectly being read as a string rather than a token. Avoiding use of auto and unneeded declararions. Logically grouping related code. Now invoking attribute Get() functions with the given time. =================================================================== M source/blender/io/usd/intern/usd_reader_volume.cc =================================================================== diff --git a/source/blender/io/usd/intern/usd_reader_volume.cc b/source/blender/io/usd/intern/usd_reader_volume.cc index 175e541927d..b69a6fc751c 100644 --- a/source/blender/io/usd/intern/usd_reader_volume.cc +++ b/source/blender/io/usd/intern/usd_reader_volume.cc @@ -52,12 +52,17 @@ #include <iostream> +namespace usdtokens { + +static const pxr::TfToken density("density", pxr::TfToken::Immortal); + +} + namespace blender::io::usd { void USDVolumeReader::create_object(Main *bmain, const double /* motionSampleTime */) { Volume *volume = (Volume *)BKE_volume_add(bmain, name_.c_str()); - id_us_min(&volume->id); object_ = BKE_object_add_only_object(bmain, OB_VOLUME, name_.c_str()); object_->data = volume; @@ -69,54 +74,59 @@ void USDVolumeReader::read_object_data(Main *bmain, const double motionSampleTim return; } - pxr::UsdVolVolume::FieldMap fields = volume_.GetFieldPaths(); + Volume *volume = static_cast<Volume *>(object_->data); - std::string filepath; + if (!volume) { + return; + } - Volume *volume = static_cast<Volume *>(object_->data); + pxr::UsdVolVolume::FieldMap fields = volume_.GetFieldPaths(); - for (auto it = fields.begin(); it != fields.end(); ++it) { + for (pxr::UsdVolVolume::FieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it) { pxr::UsdPrim fieldPrim = prim_.GetStage()->GetPrimAtPath(it->second); - if (fieldPrim.IsA<pxr::UsdVolOpenVDBAsset>()) { - pxr::UsdVolOpenVDBAsset fieldBase(fieldPrim); + if (!fieldPrim.IsA<pxr::UsdVolOpenVDBAsset>()) { + continue; + } - pxr::UsdAttribute filepathAttr = fieldBase.GetFilePathAttr(); - pxr::UsdAttribute fieldNameAttr = fieldBase.GetFieldNameAttr(); + pxr::UsdVolOpenVDBAsset fieldBase(fieldPrim); - std::string fieldName = "density"; + pxr::UsdAttribute fieldNameAttr = fieldBase.GetFieldNameAttr(); - if (fieldNameAttr.IsAuthored()) { - fieldNameAttr.Get(&fieldName, 0.0); + if (fieldNameAttr.IsAuthored()) { + pxr::TfToken fieldName; + fieldNameAttr.Get(&fieldName, motionSampleTime); - // A Blender volume creates density by default - if (fieldName != "density") { - BKE_volume_grid_add(volume, fieldName.c_str(), VOLUME_GRID_FLOAT); - } + /* A Blender volume creates density by default. */ + if (fieldName != usdtokens::density) { + BKE_volume_grid_add(volume, fieldName.GetString().c_str(), VOLUME_GRID_FLOAT); } + } - if (filepathAttr.IsAuthored()) { + pxr::UsdAttribute filepathAttr = fieldBase.GetFilePathAttr(); - pxr::SdfAssetPath fp; - filepathAttr.Get(&fp, 0.0); + if (filepathAttr.IsAuthored()) { + pxr::SdfAssetPath fp; + filepathAttr.Get(&fp, motionSampleTime); - if (filepathAttr.ValueMightBeTimeVarying()) { - std::vector<double> filePathTimes; - filepathAttr.GetTimeSamples(&filePathTimes); + if (filepathAttr.ValueMightBeTimeVarying()) { + std::vector<double> filePathTimes; + filepathAttr.GetTimeSamples(&filePathTimes); - int start = (int)filePathTimes.front(); - int end = (int)filePathTimes.back(); + if (!filePathTimes.empty()) { + int start = static_cast<int>(filePathTimes.front()); + int end = static_cast<int>(filePathTimes.back()); - volume->is_sequence = (char)true; + volume->is_sequence = static_cast<char>(true); volume->frame_start = start; volume->frame_duration = (end - start) + 1; } + } - filepath = fp.GetResolvedPath(); + std::string filepath = fp.GetResolvedPath(); - strcpy(volume->filepath, filepath.c_str()); - } + strcpy(volume->filepath, filepath.c_str()); } } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs