[Bf-blender-cvs] [4271ae24716] sybren-usd: USD: only write timeSamples when we write animated data

Sybren A. Stüvel noreply at git.blender.org
Thu Jun 27 12:25:17 CEST 2019


Commit: 4271ae24716f23a4a98a880b3d6700f8184c320c
Author: Sybren A. Stüvel
Date:   Wed Jun 26 11:55:33 2019 +0200
Branches: sybren-usd
https://developer.blender.org/rB4271ae24716f23a4a98a880b3d6700f8184c320c

USD: only write timeSamples when we write animated data

By using the default timecode USD won't even write a single `timeSample`
for non-animated data. Instead, it writes it as non-timesampled. This makes
the USD file more explicit of our intent, and allows for read-time
optimisations.

===================================================================

M	source/blender/usd/intern/usd_exporter_context.h
M	source/blender/usd/intern/usd_hierarchy_iterator.cc
M	source/blender/usd/intern/usd_writer_abstract.cc
M	source/blender/usd/intern/usd_writer_abstract.h
M	source/blender/usd/intern/usd_writer_mesh.cc
M	source/blender/usd/intern/usd_writer_transform.cc

===================================================================

diff --git a/source/blender/usd/intern/usd_exporter_context.h b/source/blender/usd/intern/usd_exporter_context.h
index 5483d6f49ed..598103765af 100644
--- a/source/blender/usd/intern/usd_exporter_context.h
+++ b/source/blender/usd/intern/usd_exporter_context.h
@@ -1,6 +1,8 @@
 #ifndef __USD__USD_EXPORTER_CONTEXT_H__
 #define __USD__USD_EXPORTER_CONTEXT_H__
 
+#include "../usd.h"
+
 #include <pxr/usd/sdf/path.h>
 #include <pxr/usd/usd/common.h>
 
@@ -13,6 +15,7 @@ struct USDExporterContext {
   pxr::UsdStageRefPtr stage;
   pxr::SdfPath usd_path;
   USDHierarchyIterator *hierarchy_iterator;
+  const USDExportParams &export_params;
 };
 
 #endif /* __USD__USD_EXPORTER_CONTEXT_H__ */
diff --git a/source/blender/usd/intern/usd_hierarchy_iterator.cc b/source/blender/usd/intern/usd_hierarchy_iterator.cc
index b04e7756379..b0587e5ed54 100644
--- a/source/blender/usd/intern/usd_hierarchy_iterator.cc
+++ b/source/blender/usd/intern/usd_hierarchy_iterator.cc
@@ -68,14 +68,14 @@ AbstractHierarchyWriter *USDHierarchyIterator::create_xform_writer(const Hierarc
   //     context.export_path.c_str());
 
   USDExporterContext usd_export_context = {
-      depsgraph, stage, pxr::SdfPath(context.export_path), this};
+      depsgraph, stage, pxr::SdfPath(context.export_path), this, params};
   return new USDTransformWriter(usd_export_context);
 }
 
 AbstractHierarchyWriter *USDHierarchyIterator::create_data_writer(const HierarchyContext &context)
 {
   USDExporterContext usd_export_context = {
-      depsgraph, stage, pxr::SdfPath(context.export_path), this};
+      depsgraph, stage, pxr::SdfPath(context.export_path), this, params};
   USDAbstractWriter *data_writer = nullptr;
 
   switch (context.object->type) {
diff --git a/source/blender/usd/intern/usd_writer_abstract.cc b/source/blender/usd/intern/usd_writer_abstract.cc
index aed49df9665..c430207ae38 100644
--- a/source/blender/usd/intern/usd_writer_abstract.cc
+++ b/source/blender/usd/intern/usd_writer_abstract.cc
@@ -1,4 +1,5 @@
 #include "usd_writer_abstract.h"
+#include "usd_hierarchy_iterator.h"
 
 #include <pxr/base/tf/stringUtils.h>
 
@@ -14,6 +15,7 @@ USDAbstractWriter::USDAbstractWriter(const USDExporterContext &usd_export_contex
       stage(usd_export_context.stage),
       usd_path_(usd_export_context.usd_path),
       hierarchy_iterator(usd_export_context.hierarchy_iterator),
+      export_params(usd_export_context.export_params),
       frame_has_been_written_(false),
       is_animated_(false)
 {
@@ -28,6 +30,17 @@ bool USDAbstractWriter::is_supported() const
   return true;
 }
 
+pxr::UsdTimeCode USDAbstractWriter::get_export_time_code() const
+{
+  if (is_animated_) {
+    return hierarchy_iterator->get_export_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.
+  static pxr::UsdTimeCode default_timecode = pxr::UsdTimeCode::Default();
+  return default_timecode;
+}
+
 void USDAbstractWriter::write(HierarchyContext &context)
 {
   if (frame_has_been_written_) {
@@ -36,7 +49,7 @@ void USDAbstractWriter::write(HierarchyContext &context)
     }
   }
   else {
-    is_animated_ = check_is_animated(context.object);
+    is_animated_ = export_params.do_animation && check_is_animated(context.object);
     printf("%sANIMATION\033[0m: %20s: %s\n",
            is_animated_ ? "\033[32;1m" : "\033[31;1m",
            context.export_path.c_str(),
diff --git a/source/blender/usd/intern/usd_writer_abstract.h b/source/blender/usd/intern/usd_writer_abstract.h
index c6f0a603aa0..3f463bc0047 100644
--- a/source/blender/usd/intern/usd_writer_abstract.h
+++ b/source/blender/usd/intern/usd_writer_abstract.h
@@ -20,6 +20,7 @@ class USDAbstractWriter : public AbstractHierarchyWriter {
   pxr::UsdStageRefPtr stage;
   pxr::SdfPath usd_path_;
   USDHierarchyIterator *const hierarchy_iterator;
+  const USDExportParams &export_params;
   bool frame_has_been_written_;
   bool is_animated_;
 
@@ -38,6 +39,7 @@ class USDAbstractWriter : public AbstractHierarchyWriter {
  protected:
   virtual void do_write(HierarchyContext &context) = 0;
   virtual bool check_is_animated(Object *object) const;
+  pxr::UsdTimeCode get_export_time_code() const;
 };
 
 #endif /* __USD__USD_WRITER_ABSTRACT_H__ */
diff --git a/source/blender/usd/intern/usd_writer_mesh.cc b/source/blender/usd/intern/usd_writer_mesh.cc
index 7879e32acaa..3ab72fbf723 100644
--- a/source/blender/usd/intern/usd_writer_mesh.cc
+++ b/source/blender/usd/intern/usd_writer_mesh.cc
@@ -50,7 +50,7 @@ void USDGenericMeshWriter::free_export_mesh(struct Mesh *mesh)
 
 void USDGenericMeshWriter::write_mesh(struct Mesh *mesh)
 {
-  pxr::UsdTimeCode timecode = hierarchy_iterator->get_export_time_code();
+  pxr::UsdTimeCode timecode = get_export_time_code();
   // printf("USD-\033[32mexporting\033[0m mesh  %s → %s  mesh = %p\n",
   //        mesh->id.name,
   //        usd_path_.GetString().c_str(),
diff --git a/source/blender/usd/intern/usd_writer_transform.cc b/source/blender/usd/intern/usd_writer_transform.cc
index 4969ac1c0f3..97c3ef2b31f 100644
--- a/source/blender/usd/intern/usd_writer_transform.cc
+++ b/source/blender/usd/intern/usd_writer_transform.cc
@@ -32,9 +32,7 @@ void USDTransformWriter::do_write(HierarchyContext &context)
   if (!xformOp_) {
     xformOp_ = xform.AddTransformOp();
   }
-  // TODO(Sybren): when not animated, write to the default timecode instead.
-  xformOp_.Set(pxr::GfMatrix4d(parent_relative_matrix),
-               hierarchy_iterator->get_export_time_code());
+  xformOp_.Set(pxr::GfMatrix4d(parent_relative_matrix), get_export_time_code());
 }
 
 bool USDTransformWriter::check_is_animated(Object *object) const



More information about the Bf-blender-cvs mailing list