[Bf-blender-cvs] [df1c90fed5e] sybren-usd: USD: Allow user to disable export of UV maps and mesh normals

Sybren A. Stüvel noreply at git.blender.org
Fri Jul 26 16:46:48 CEST 2019


Commit: df1c90fed5e232c5c5c8d1b047971e6537b2ffb0
Author: Sybren A. Stüvel
Date:   Fri Jul 26 16:46:38 2019 +0200
Branches: sybren-usd
https://developer.blender.org/rBdf1c90fed5e232c5c5c8d1b047971e6537b2ffb0

USD: Allow user to disable export of UV maps and mesh normals

The UV maps and mesh normals take up a significant amount of space, so
it's better to make them optional. They're still enabled by default,
though.

Comparison: a shot of Spring (03_035_A to be exact) is 1.2 GiB  when
exported with UVs and normals, and 262 MiB without. We probably have
room for optimisation of written UVs and normals.

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

M	source/blender/editors/io/io_usd.c
M	source/blender/usd/intern/usd_writer_mesh.cc
M	source/blender/usd/usd.h

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

diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index 71c65eef4f6..8d788b52e07 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -34,6 +34,9 @@
 #  include "RNA_access.h"
 #  include "RNA_define.h"
 
+#  include "UI_interface.h"
+#  include "UI_resources.h"
+
 #  include "WM_api.h"
 #  include "WM_types.h"
 
@@ -102,12 +105,18 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
   const bool visible_objects_only = RNA_boolean_get(op->ptr, "visible_objects_only");
   const bool export_animation = RNA_boolean_get(op->ptr, "export_animation");
   const bool export_hair = RNA_boolean_get(op->ptr, "export_hair");
+  const bool export_uvmaps = RNA_boolean_get(op->ptr, "export_uvmaps");
+  const bool export_normals = RNA_boolean_get(op->ptr, "export_normals");
+  const bool export_materials = RNA_boolean_get(op->ptr, "export_materials");
   const bool use_instancing = RNA_boolean_get(op->ptr, "use_instancing");
   const bool evaluation_mode = RNA_enum_get(op->ptr, "evaluation_mode");
 
   struct USDExportParams params = {
       export_animation,
       export_hair,
+      export_uvmaps,
+      export_normals,
+      export_materials,
       selected_objects_only,
       visible_objects_only,
       use_instancing,
@@ -119,6 +128,30 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
   return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
 }
 
+static void wm_usd_export_draw(bContext *UNUSED(C), wmOperator *op)
+{
+  uiLayout *layout = op->layout;
+  uiLayout *col;
+  struct PointerRNA *ptr = op->ptr;
+
+  uiLayoutSetPropSep(layout, true);
+
+  col = uiLayoutColumn(layout, true);
+  uiItemR(col, ptr, "selected_objects_only", 0, NULL, ICON_NONE);
+  uiItemR(col, ptr, "visible_objects_only", 0, NULL, ICON_NONE);
+
+  col = uiLayoutColumn(layout, true);
+  uiItemR(col, ptr, "export_animation", 0, NULL, ICON_NONE);
+  uiItemR(col, ptr, "export_hair", 0, NULL, ICON_NONE);
+  uiItemR(col, ptr, "export_uvmaps", 0, NULL, ICON_NONE);
+  uiItemR(col, ptr, "export_normals", 0, NULL, ICON_NONE);
+  uiItemR(col, ptr, "export_materials", 0, NULL, ICON_NONE);
+  uiItemR(col, ptr, "use_instancing", 0, NULL, ICON_NONE);
+
+  col = uiLayoutColumn(layout, true);
+  uiItemR(col, ptr, "evaluation_mode", 0, NULL, ICON_NONE);
+}
+
 void WM_OT_usd_export(struct wmOperatorType *ot)
 {
   ot->name = "Export USD";
@@ -128,6 +161,7 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
   ot->invoke = wm_usd_export_invoke;
   ot->exec = wm_usd_export_exec;
   ot->poll = WM_operator_winactive;
+  ot->ui = wm_usd_export_draw;
 
   WM_operator_properties_filesel(
       ot, 0, FILE_BLENDER, FILE_SAVE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
@@ -150,11 +184,29 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
                   "export_animation",
                   false,
                   "Export Animation",
-                  "When true, the render frame range is exported. When false, only the current "
+                  "When checked, the render frame range is exported. When false, only the current "
                   "frame is exported");
-
-  RNA_def_boolean(
-      ot->srna, "export_hair", false, "Export Hair", "When true, hair is exported as USD curves");
+  RNA_def_boolean(ot->srna,
+                  "export_hair",
+                  false,
+                  "Export Hair",
+                  "When checked, hair is exported as USD curves");
+  RNA_def_boolean(ot->srna,
+                  "export_uvmaps",
+                  true,
+                  "Export UV Maps",
+                  "When checked, all UV maps of exported meshes are included in the export");
+  RNA_def_boolean(ot->srna,
+                  "export_normals",
+                  true,
+                  "Export Normals",
+                  "When checked, normals of exported meshes are included in the export");
+  RNA_def_boolean(ot->srna,
+                  "export_materials",
+                  true,
+                  "Export Materials",
+                  "When checked, the viewport settings of materials are exported as USD preview "
+                  "materials, and material assignments are exported as geometry subsets");
 
   RNA_def_boolean(ot->srna,
                   "use_instancing",
diff --git a/source/blender/usd/intern/usd_writer_mesh.cc b/source/blender/usd/intern/usd_writer_mesh.cc
index 8cd7f049a5d..83de0a528e9 100644
--- a/source/blender/usd/intern/usd_writer_mesh.cc
+++ b/source/blender/usd/intern/usd_writer_mesh.cc
@@ -151,7 +151,9 @@ void USDGenericMeshWriter::write_mesh(HierarchyContext &context, Mesh *mesh)
     subtree pointed to by ref_path. As a result, the referenced data is not allowed to point out
     of its own subtree. It does work when we override the material with exactly the same path,
     though.*/
-    assign_materials(context, usd_mesh, usd_mesh_data.face_groups);
+    if (export_params.export_materials) {
+      assign_materials(context, usd_mesh, usd_mesh_data.face_groups);
+    }
     return;
   }
 
@@ -165,8 +167,12 @@ void USDGenericMeshWriter::write_mesh(HierarchyContext &context, Mesh *mesh)
     usd_mesh.CreateCreaseSharpnessesAttr().Set(usd_mesh_data.crease_sharpnesses, timecode);
   }
 
-  write_uv_maps(mesh, usd_mesh);
-  write_normals(mesh, usd_mesh);
+  if (export_params.export_uvmaps) {
+    write_uv_maps(mesh, usd_mesh);
+  }
+  if (export_params.export_normals) {
+    write_normals(mesh, usd_mesh);
+  }
   write_surface_velocity(context.object, mesh, usd_mesh);
 
   // TODO(Sybren): figure out what happens when the face groups change.
@@ -175,7 +181,10 @@ void USDGenericMeshWriter::write_mesh(HierarchyContext &context, Mesh *mesh)
   }
 
   usd_mesh.CreateSubdivisionSchemeAttr().Set(pxr::UsdGeomTokens->none);
-  assign_materials(context, usd_mesh, usd_mesh_data.face_groups);
+
+  if (export_params.export_materials) {
+    assign_materials(context, usd_mesh, usd_mesh_data.face_groups);
+  }
 }
 
 static void get_vertices(const Mesh *mesh, USDMeshData &usd_mesh_data)
diff --git a/source/blender/usd/usd.h b/source/blender/usd/usd.h
index 6feb1ca6a96..74dd01245d1 100644
--- a/source/blender/usd/usd.h
+++ b/source/blender/usd/usd.h
@@ -33,6 +33,9 @@ struct bContext;
 struct USDExportParams {
   bool export_animation;
   bool export_hair;
+  bool export_uvmaps;
+  bool export_normals;
+  bool export_materials;
   bool selected_objects_only;
   bool visible_objects_only;
   bool use_instancing;



More information about the Bf-blender-cvs mailing list