diff --git a/source/blender/io/usd/hydra/material.cc b/source/blender/io/usd/hydra/material.cc index fa2c698146b..aa97b4b4683 100644 --- a/source/blender/io/usd/hydra/material.cc +++ b/source/blender/io/usd/hydra/material.cc @@ -49,6 +49,7 @@ void MaterialData::init() /* Create temporary in memory stage. */ pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(); pxr::UsdTimeCode time = pxr::UsdTimeCode::Default(); + auto get_time_code = [time]() { return time; }; pxr::SdfPath material_library_path("/_materials"); pxr::SdfPath material_path = material_library_path.AppendChild( pxr::TfToken(prim_id.GetElementString())); @@ -63,7 +64,7 @@ void MaterialData::init() scene_delegate_->depsgraph, stage, material_library_path, - time, + get_time_code, export_params, image_cache_file_path()}; diff --git a/source/blender/io/usd/intern/usd_exporter_context.h b/source/blender/io/usd/intern/usd_exporter_context.h index b4a3176ea22..11a64f46796 100644 --- a/source/blender/io/usd/intern/usd_exporter_context.h +++ b/source/blender/io/usd/intern/usd_exporter_context.h @@ -8,6 +8,8 @@ #include #include +#include + struct Depsgraph; struct Main; @@ -20,7 +22,13 @@ struct USDExporterContext { Depsgraph *depsgraph; const pxr::UsdStageRefPtr stage; const pxr::SdfPath usd_path; - pxr::UsdTimeCode time_code; + /** + * Wrap a function which returns the current time code + * for export. This is necessary since the context + * may be used for exporting an animation over a sequece + * of frames. + */ + std::function get_time_code; const USDExportParams &export_params; std::string export_file_path; }; diff --git a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc index 5a1f6c54069..a132338bfa7 100644 --- a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc +++ b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc @@ -78,9 +78,10 @@ USDExporterContext USDHierarchyIterator::create_usd_export_context(const Hierarc * `pxr::UsdStage::CreateNew` function). */ const pxr::SdfLayerHandle root_layer = stage_->GetRootLayer(); const std::string export_file_path = root_layer->GetRealPath(); + auto get_time_code = [this]() { return this->export_time_; }; return USDExporterContext{ - bmain_, depsgraph_, stage_, path, export_time_, params_, export_file_path}; + bmain_, depsgraph_, stage_, path, get_time_code, params_, export_file_path}; } AbstractHierarchyWriter *USDHierarchyIterator::create_transform_writer( diff --git a/source/blender/io/usd/intern/usd_writer_abstract.cc b/source/blender/io/usd/intern/usd_writer_abstract.cc index d4d2b6ec358..f45dbe0925d 100644 --- a/source/blender/io/usd/intern/usd_writer_abstract.cc +++ b/source/blender/io/usd/intern/usd_writer_abstract.cc @@ -59,7 +59,8 @@ std::string USDAbstractWriter::get_export_file_path() const pxr::UsdTimeCode USDAbstractWriter::get_export_time_code() const { if (is_animated_) { - return usd_export_context_.time_code; + BLI_assert(usd_export_context_.get_time_code); + return usd_export_context_.get_time_code(); } /* By using the default timecode USD won't even write a single `timeSample` for non-animated * data. Instead, it writes it as non-timesampled. */