Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2020-08-14 17:48:39 +0300
committerSybren A. Stüvel <sybren@blender.org>2020-08-17 18:56:05 +0300
commit108f3284a7311068e3bb7742f813b4612c70dd03 (patch)
tree914ac8b6bf08e4c2f340ed4fe16198a93f6f4ee1 /source/blender/io
parent271361e31f9e4bdd222b78833a42a5b268da3e89 (diff)
USD: Allow exporting of invisible objects
The fix for T75936 made it possible to export invisible objects to Alembic. This commit applies the same approach to the USD exporter. The USD and Alembic code is slightly different in terms of where in the exported file the visibility attribute is stored. In USD the visibility is used to prune the scene graph, and thus there are only two options: "hidden" and "inherited". Setting the visiblity of a node in the scene graph to "hidden" immediately hides all its children. To allow hidden parents with visible children, the visibility is stored on the object data (so the geometry/camera/lamp/etc) instead.
Diffstat (limited to 'source/blender/io')
-rw-r--r--source/blender/io/usd/intern/usd_capi.cc7
-rw-r--r--source/blender/io/usd/intern/usd_writer_abstract.cc14
-rw-r--r--source/blender/io/usd/intern/usd_writer_abstract.h4
-rw-r--r--source/blender/io/usd/intern/usd_writer_mesh.cc9
-rw-r--r--source/blender/io/usd/usd.h1
5 files changed, 33 insertions, 2 deletions
diff --git a/source/blender/io/usd/intern/usd_capi.cc b/source/blender/io/usd/intern/usd_capi.cc
index 98aef62f38e..a7c5ff1a305 100644
--- a/source/blender/io/usd/intern/usd_capi.cc
+++ b/source/blender/io/usd/intern/usd_capi.cc
@@ -76,7 +76,12 @@ static void export_startjob(void *customdata,
// Construct the depsgraph for exporting.
Scene *scene = DEG_get_input_scene(data->depsgraph);
ViewLayer *view_layer = DEG_get_input_view_layer(data->depsgraph);
- DEG_graph_build_from_view_layer(data->depsgraph, data->bmain, scene, view_layer);
+ if (data->params.visible_objects_only) {
+ DEG_graph_build_from_view_layer(data->depsgraph, data->bmain, scene, view_layer);
+ }
+ else {
+ DEG_graph_build_for_all_objects(data->depsgraph, data->bmain, scene, view_layer);
+ }
BKE_scene_graph_update_tagged(data->depsgraph, data->bmain);
*progress = 0.0f;
diff --git a/source/blender/io/usd/intern/usd_writer_abstract.cc b/source/blender/io/usd/intern/usd_writer_abstract.cc
index a416941fb4d..4910b7f11dd 100644
--- a/source/blender/io/usd/intern/usd_writer_abstract.cc
+++ b/source/blender/io/usd/intern/usd_writer_abstract.cc
@@ -114,6 +114,20 @@ pxr::UsdShadeMaterial USDAbstractWriter::ensure_usd_material(Material *material)
return usd_material;
}
+void USDAbstractWriter::write_visibility(const HierarchyContext &context,
+ const pxr::UsdTimeCode timecode,
+ pxr::UsdGeomImageable &usd_geometry)
+{
+ pxr::UsdAttribute attr_visibility = usd_geometry.CreateVisibilityAttr(pxr::VtValue(), true);
+
+ const bool is_visible = context.is_object_visible(
+ usd_export_context_.export_params.evaluation_mode);
+ const pxr::TfToken visibility = is_visible ? pxr::UsdGeomTokens->inherited :
+ pxr::UsdGeomTokens->invisible;
+
+ usd_value_writer_.SetAttribute(attr_visibility, pxr::VtValue(visibility), timecode);
+}
+
} // namespace usd
} // namespace io
} // namespace blender
diff --git a/source/blender/io/usd/intern/usd_writer_abstract.h b/source/blender/io/usd/intern/usd_writer_abstract.h
index a689deaf0d8..248bdd22a3b 100644
--- a/source/blender/io/usd/intern/usd_writer_abstract.h
+++ b/source/blender/io/usd/intern/usd_writer_abstract.h
@@ -72,6 +72,10 @@ class USDAbstractWriter : public AbstractHierarchyWriter {
pxr::UsdTimeCode get_export_time_code() const;
pxr::UsdShadeMaterial ensure_usd_material(Material *material);
+
+ void write_visibility(const HierarchyContext &context,
+ const pxr::UsdTimeCode timecode,
+ pxr::UsdGeomImageable &usd_geometry);
};
} // namespace usd
diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc
index b27c68a41f6..75d1ca605d4 100644
--- a/source/blender/io/usd/intern/usd_writer_mesh.cc
+++ b/source/blender/io/usd/intern/usd_writer_mesh.cc
@@ -42,6 +42,8 @@
#include "DNA_object_fluidsim_types.h"
#include "DNA_particle_types.h"
+#include <iostream>
+
namespace blender {
namespace io {
namespace usd {
@@ -52,7 +54,10 @@ USDGenericMeshWriter::USDGenericMeshWriter(const USDExporterContext &ctx) : USDA
bool USDGenericMeshWriter::is_supported(const HierarchyContext *context) const
{
- return context->is_object_visible(usd_export_context_.export_params.evaluation_mode);
+ if (usd_export_context_.export_params.visible_objects_only) {
+ return context->is_object_visible(usd_export_context_.export_params.evaluation_mode);
+ }
+ return true;
}
void USDGenericMeshWriter::do_write(HierarchyContext &context)
@@ -149,6 +154,8 @@ void USDGenericMeshWriter::write_mesh(HierarchyContext &context, Mesh *mesh)
const pxr::SdfPath &usd_path = usd_export_context_.usd_path;
pxr::UsdGeomMesh usd_mesh = pxr::UsdGeomMesh::Define(stage, usd_path);
+ write_visibility(context, timecode, usd_mesh);
+
USDMeshData usd_mesh_data;
get_geometry_data(mesh, usd_mesh_data);
diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h
index f2826cd1d7c..b9ea90736ff 100644
--- a/source/blender/io/usd/usd.h
+++ b/source/blender/io/usd/usd.h
@@ -35,6 +35,7 @@ struct USDExportParams {
bool export_normals;
bool export_materials;
bool selected_objects_only;
+ bool visible_objects_only;
bool use_instancing;
enum eEvaluationMode evaluation_mode;
};