[Bf-blender-cvs] [1134a406ab5] sybren-usd: USD: be more selective about what to export each frame
Sybren A. Stüvel
noreply at git.blender.org
Thu Jun 27 12:25:15 CEST 2019
Commit: 1134a406ab5c65ed0b306d29739b245dcc791781
Author: Sybren A. Stüvel
Date: Tue Jun 25 16:02:07 2019 +0200
Branches: sybren-usd
https://developer.blender.org/rB1134a406ab5c65ed0b306d29739b245dcc791781
USD: be more selective about what to export each frame
To prevent too large USD files, we now have a bit of a framework to only
write data on the first frame for non-animated objects. This needs more
work, though, as it can be made more selective.
===================================================================
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_transform.cc
M source/blender/usd/intern/usd_writer_transform.h
===================================================================
diff --git a/source/blender/usd/intern/usd_writer_abstract.cc b/source/blender/usd/intern/usd_writer_abstract.cc
index 1177000ae61..aed49df9665 100644
--- a/source/blender/usd/intern/usd_writer_abstract.cc
+++ b/source/blender/usd/intern/usd_writer_abstract.cc
@@ -2,11 +2,20 @@
#include <pxr/base/tf/stringUtils.h>
+extern "C" {
+#include "BKE_animsys.h"
+#include "BKE_key.h"
+
+#include "DNA_modifier_types.h"
+}
+
USDAbstractWriter::USDAbstractWriter(const USDExporterContext &usd_export_context)
: depsgraph(usd_export_context.depsgraph),
stage(usd_export_context.stage),
usd_path_(usd_export_context.usd_path),
- hierarchy_iterator(usd_export_context.hierarchy_iterator)
+ hierarchy_iterator(usd_export_context.hierarchy_iterator),
+ frame_has_been_written_(false),
+ is_animated_(false)
{
}
@@ -21,9 +30,49 @@ bool USDAbstractWriter::is_supported() const
void USDAbstractWriter::write(HierarchyContext &context)
{
- // TODO(Sybren): deal with animatedness of objects and only calling do_write() when this is
- // either the first call or the object is animated.
+ if (frame_has_been_written_) {
+ if (!is_animated_) {
+ return;
+ }
+ }
+ else {
+ is_animated_ = 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(),
+ is_animated_ ? "true" : "false");
+ }
+
do_write(context);
+
+ frame_has_been_written_ = true;
+}
+
+bool USDAbstractWriter::check_is_animated(Object *object) const
+{
+ if (object->data != nullptr) {
+ AnimData *adt = BKE_animdata_from_id(static_cast<ID *>(object->data));
+ /* TODO(Sybren): make this check more strict, as the AnimationData may
+ * actually be empty (no fcurves, drivers, etc.) and thus effectively
+ * have no animation at all. */
+ if (adt != nullptr) {
+ return true;
+ }
+ }
+ if (BKE_key_from_object(object) != nullptr) {
+ return true;
+ }
+
+ /* Test modifiers. */
+ ModifierData *md = static_cast<ModifierData *>(object->modifiers.first);
+ while (md) {
+ if (md->type != eModifierType_Subsurf) {
+ return true;
+ }
+ md = md->next;
+ }
+
+ return false;
}
const pxr::SdfPath &USDAbstractWriter::usd_path() const
diff --git a/source/blender/usd/intern/usd_writer_abstract.h b/source/blender/usd/intern/usd_writer_abstract.h
index 7bb3185a54c..c6f0a603aa0 100644
--- a/source/blender/usd/intern/usd_writer_abstract.h
+++ b/source/blender/usd/intern/usd_writer_abstract.h
@@ -20,6 +20,8 @@ class USDAbstractWriter : public AbstractHierarchyWriter {
pxr::UsdStageRefPtr stage;
pxr::SdfPath usd_path_;
USDHierarchyIterator *const hierarchy_iterator;
+ bool frame_has_been_written_;
+ bool is_animated_;
public:
USDAbstractWriter(const USDExporterContext &usd_export_context);
@@ -35,6 +37,7 @@ class USDAbstractWriter : public AbstractHierarchyWriter {
protected:
virtual void do_write(HierarchyContext &context) = 0;
+ virtual bool check_is_animated(Object *object) const;
};
#endif /* __USD__USD_WRITER_ABSTRACT_H__ */
diff --git a/source/blender/usd/intern/usd_writer_transform.cc b/source/blender/usd/intern/usd_writer_transform.cc
index f6aeb3cb4cb..4969ac1c0f3 100644
--- a/source/blender/usd/intern/usd_writer_transform.cc
+++ b/source/blender/usd/intern/usd_writer_transform.cc
@@ -5,7 +5,11 @@
#include <pxr/usd/usdGeom/xform.h>
extern "C" {
+#include "BKE_animsys.h"
+
#include "BLI_math_matrix.h"
+
+#include "DNA_layer_types.h"
}
USDTransformWriter::USDTransformWriter(const USDExporterContext &ctx) : USDAbstractWriter(ctx)
@@ -28,6 +32,32 @@ 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());
}
+
+bool USDTransformWriter::check_is_animated(Object *object) const
+{
+ /* We should also check the animation state of parents that aren't part of the export hierarchy
+ * (that is, when the animated parent is not instanced by the duplicator of the current object).
+ * For now, just assume duplis are transform-animated. */
+ // if (object->base_flag & BASE_FROM_DUPLI) {
+ // return true;
+ // }
+ return true;
+
+ AnimData *adt = BKE_animdata_from_id(&object->id);
+ /* TODO(Sybren): make this check more strict, as the AnimationData may
+ * actually be empty (no fcurves, drivers, etc.) and thus effectively
+ * have no animation at all. */
+ if (adt != nullptr) {
+ return true;
+ };
+
+ if (object->constraints.first != nullptr) {
+ return true;
+ }
+
+ return false;
+}
diff --git a/source/blender/usd/intern/usd_writer_transform.h b/source/blender/usd/intern/usd_writer_transform.h
index 949cad79917..e1b521dc066 100644
--- a/source/blender/usd/intern/usd_writer_transform.h
+++ b/source/blender/usd/intern/usd_writer_transform.h
@@ -14,6 +14,7 @@ class USDTransformWriter : public USDAbstractWriter {
protected:
void do_write(HierarchyContext &context) override;
+ bool check_is_animated(Object *object) const override;
};
#endif /* __USD__USD_WRITER_TRANSFORM_H__ */
More information about the Bf-blender-cvs
mailing list