[Bf-blender-cvs] [ed6fa3529d8] temp-sybren-usd-patch-01: USD: Introducing USD support

Sybren A. Stüvel noreply at git.blender.org
Tue Nov 26 18:21:24 CET 2019


Commit: ed6fa3529d836b3edb4e7d595a80ca4acf7eabdb
Author: Sybren A. Stüvel
Date:   Thu Jun 20 14:32:29 2019 +0200
Branches: temp-sybren-usd-patch-01
https://developer.blender.org/rBed6fa3529d836b3edb4e7d595a80ca4acf7eabdb

USD: Introducing USD support

This commit introduces an exporter to Pixar's Universal Scene
Description (USD) format.

- The USD libraries are expected to be in /opt/usd/, not yet built by
  install_deps.sh. I'll work on that while this patch is under review.
- Only experimental support for instancing; by default all duplicated
  objects are made real in the USD file. This is fine for exporting a
  linked-in posed character, not so much for thousands of pebbles etc.
- This patch contains LazyDodo's fixes for building on Windows in D5359.

== Meshes ==

USD seems to support neither per-material nor per-face-group
double-sidedness, so we just use the flag from the first non-empty
material slot. If there is no material we default to double-sidedness.

Each UV map is stored on the mesh in a separate primvar. Materials can
refer to these UV maps, but this is not yet exported by Blender. The
primvar name is the same as the UV Map name. This is to allow the
standard name "st" for texture coordinates by naming the UV Map as such,
without having to guess which UV Map is the "standard" one.

Face-varying mesh normals are written to USD. When the mesh has custom
loop normals those are written. Otherwise the poly flag `ME_SMOOTH` is
inspected to determine the normals.

The UV maps and mesh normals take up a significant amount of space, so
exporting them is optional. They're still enabled by default, though.
For comparison: a shot of Spring (03_035_A) 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.

The mesh subdivision scheme isn't using the default value 'Catmull
Clark', but uses 'None', indicating we're exporting a polygonal mesh.
This is necessary for USD to understand our normals; otherwise the mesh
is always rendered smooth. In the future we may want to expose this
choice of subdivision scheme to the user, or auto-detect it when we
actually support exporting pre-subdivision meshes.

A possible optimisation could be to inspect whether all polygons are
smooth or flat, and mark the USD mesh as such. This can be added when
needed.

== Animation ==

Mesh and transform animation are now written when passing
`animation=True` to the export operator. There is no inspection of
whether an object is actually animated or not; USD can handle
deduplication of static values for us.

The administration of which timecode to use for the export is left to
the file-format-specific concrete subclasses of
`AbstractHierarchyIterator`; the abstract iterator itself doesn't know
anything about the passage of time. This will allow subclasses for the
frame-based USD format and time-based Alembic format.

== support for simple preview materials ==

Very simple versions of the materials are now exported, using only the
viewport diffuse RGB, metallic, and roughness.

When there are multiple materials, the mesh faces are stored as geometry
subset and each material is assigned to the appropriate subset. If there
is only one material this is skipped.

The first material if any) is always applied to the mesh itself
(regardless of the existence of geometry subsets), because the Hydra
viewport doesn't support materials on subsets. See
https://github.com/PixarAnimationStudios/USD/issues/542 for more info.

Note that the geometry subsets are not yet time-sampled, so it may break
when an animated mesh changes topology.

== Hair ==

Only the parent strands are exported, and only with a constant colour.
No UV coordinates, no information about the normals.

== Camera ==

Only perspective cameras are supported for now.

== Particles ==

Particles are only written when they are alive, which means that they
are always visible (there is currently no code that deals with marking
them as invisible outside their lifespan).

Particle-system-instanced objects are exported by suffixing the object
name with the particle's persistent ID, giving each particle XForm a
unique name.

== Instancing/referencing ==

This exporter has experimental support for instancing/referencing.

Dupli-object meshes are now written to USD as references to the original
mesh. This is still very limited in correctness, as there are issues
referencing to materials from a referenced mesh.

I am still committing this, as it gives us a place to start when
continuing the quest for proper instancing in USD.

== Lights ==

USD does not directly support spot lights, so those aren't exported yet.
It's possible to add this in the future via the UsdLuxShapingAPI. The
units used for the light intensity are also still a bit of a mystery.

== Fluid vertex velocities ==

Currently only fluid simulations (not meshes in general) have explicit
vertex velocities. This is the most important case for exporting
velocities, though, as the baked mesh changes topology all the time, and
thus computing the velocities at import time in a post-processing step
is hard.

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

M	CMakeLists.txt
A	build_files/cmake/Modules/FindUSD.cmake
M	release/scripts/startup/bl_ui/space_topbar.py
M	source/blender/CMakeLists.txt
M	source/blender/depsgraph/DEG_depsgraph_query.h
M	source/blender/editors/io/CMakeLists.txt
M	source/blender/editors/io/io_ops.c
A	source/blender/editors/io/io_usd.c
A	source/blender/editors/io/io_usd.h
M	source/blender/editors/space_file/filelist.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/python/intern/CMakeLists.txt
M	source/blender/python/intern/bpy_app_build_options.c
A	source/blender/usd/CMakeLists.txt
A	source/blender/usd/intern/abstract_hierarchy_iterator.cc
A	source/blender/usd/intern/abstract_hierarchy_iterator.h
A	source/blender/usd/intern/usd_capi.cc
A	source/blender/usd/intern/usd_exporter_context.h
A	source/blender/usd/intern/usd_hierarchy_iterator.cc
A	source/blender/usd/intern/usd_hierarchy_iterator.h
A	source/blender/usd/intern/usd_writer_abstract.cc
A	source/blender/usd/intern/usd_writer_abstract.h
A	source/blender/usd/intern/usd_writer_camera.cc
A	source/blender/usd/intern/usd_writer_camera.h
A	source/blender/usd/intern/usd_writer_hair.cc
A	source/blender/usd/intern/usd_writer_hair.h
A	source/blender/usd/intern/usd_writer_light.cc
A	source/blender/usd/intern/usd_writer_light.h
A	source/blender/usd/intern/usd_writer_mesh.cc
A	source/blender/usd/intern/usd_writer_mesh.h
A	source/blender/usd/intern/usd_writer_transform.cc
A	source/blender/usd/intern/usd_writer_transform.h
A	source/blender/usd/usd.h
M	source/creator/CMakeLists.txt

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index aeec259c3b7..b3dbb44297b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -335,6 +335,10 @@ option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd
 option(WITH_ALEMBIC             "Enable Alembic Support" OFF)
 option(WITH_ALEMBIC_HDF5        "Enable Legacy Alembic Support (not officially supported)" OFF)
 
+# Universal Scene Description support
+option(WITH_USD                 "Enable Universal Scene Description (USD) Support" OFF)
+set(USD_PATH "/opt/usd" CACHE STRING "Universal Scene Description (USD) installation path")
+
 # 3D format support
 # Disable opencollada when we don't have precompiled libs
 option(WITH_OPENCOLLADA   "Enable OpenCollada Support (http://www.opencollada.org)" ${_init_OPENCOLLADA})
@@ -1800,6 +1804,7 @@ if(FIRST_RUN)
   info_cfg_option(WITH_OPENVDB)
   info_cfg_option(WITH_ALEMBIC)
   info_cfg_option(WITH_QUADRIFLOW)
+  info_cfg_option(WITH_USD)
 
   info_cfg_text("Compiler Options:")
   info_cfg_option(WITH_BUILDINFO)
diff --git a/build_files/cmake/Modules/FindUSD.cmake b/build_files/cmake/Modules/FindUSD.cmake
new file mode 100644
index 00000000000..65716e97c66
--- /dev/null
+++ b/build_files/cmake/Modules/FindUSD.cmake
@@ -0,0 +1,70 @@
+# - Find Universal Scene Description (USD) library
+# Find the native USD includes and libraries
+# This module defines
+#  USD_INCLUDE_DIRS, where to find USD headers, Set when
+#                        USD_INCLUDE_DIR is found.
+#  USD_LIBRARIES, libraries to link against to use USD.
+#  USD_ROOT_DIR, The base directory to search for USD.
+#                    This can also be an environment variable.
+#  USD_FOUND, If false, do not try to use USD.
+#
+
+#=============================================================================
+# Copyright 2019 Blender Foundation.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+
+# If USD_ROOT_DIR was defined in the environment, use it.
+IF(NOT USD_ROOT_DIR AND NOT $ENV{USD_ROOT_DIR} STREQUAL "")
+  SET(USD_ROOT_DIR $ENV{USD_ROOT_DIR})
+ENDIF()
+
+SET(_usd_SEARCH_DIRS
+  ${USD_ROOT_DIR}
+  /usr/local
+  /sw # Fink
+  /opt/local # DarwinPorts
+  /opt/lib/usd
+  /opt/usd
+)
+
+FIND_PATH(USD_INCLUDE_DIR
+  NAMES
+    pxr/usd/usd/api.h
+  HINTS
+    ${_usd_SEARCH_DIRS}
+  PATH_SUFFIXES
+    include
+)
+
+FIND_LIBRARY(USD_LIBRARY
+  NAMES
+  usd
+  HINTS
+    ${_usd_SEARCH_DIRS}
+  PATH_SUFFIXES
+    lib64 lib lib/static
+)
+
+# handle the QUIETLY and REQUIRED arguments and set USD_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(USD DEFAULT_MSG USD_LIBRARY USD_INCLUDE_DIR)
+
+IF(USD_FOUND)
+  SET(USD_LIBRARIES ${USD_LIBRARY})
+  SET(USD_INCLUDE_DIRS ${USD_INCLUDE_DIR})
+ENDIF(USD_FOUND)
+
+MARK_AS_ADVANCED(
+  USD_INCLUDE_DIR
+  USD_LIBRARY
+)
+
+UNSET(_usd_SEARCH_DIRS)
diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index fef0e095099..5c010ef38c0 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -400,6 +400,8 @@ class TOPBAR_MT_file_export(Menu):
             self.layout.operator("wm.collada_export", text="Collada (Default) (.dae)")
         if bpy.app.build_options.alembic:
             self.layout.operator("wm.alembic_export", text="Alembic (.abc)")
+        if bpy.app.build_options.usd:
+            self.layout.operator("wm.usd_export", text="Universal Scene Description (.usdc, .usda)")
 
 
 class TOPBAR_MT_file_external_data(Menu):
diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index 62923d18b70..68d7b6d9b2d 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -158,3 +158,6 @@ endif()
 if(WIN32)
   add_subdirectory(blendthumb)
 endif()
+if(WITH_USD)
+  add_subdirectory(usd)
+endif()
diff --git a/source/blender/depsgraph/DEG_depsgraph_query.h b/source/blender/depsgraph/DEG_depsgraph_query.h
index fb456611b15..c8ddffa57c7 100644
--- a/source/blender/depsgraph/DEG_depsgraph_query.h
+++ b/source/blender/depsgraph/DEG_depsgraph_query.h
@@ -26,6 +26,8 @@
 #ifndef __DEG_DEPSGRAPH_QUERY_H__
 #define __DEG_DEPSGRAPH_QUERY_H__
 
+#include "BLI_iterator.h"
+
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_build.h"
 
diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt
index 5a35b251d0c..5afe348158f 100644
--- a/source/blender/editors/io/CMakeLists.txt
+++ b/source/blender/editors/io/CMakeLists.txt
@@ -26,6 +26,7 @@ set(INC
   ../../depsgraph
   ../../makesdna
   ../../makesrna
+  ../../usd
   ../../windowmanager
   ../../../../intern/guardedalloc
 )
@@ -39,11 +40,13 @@ set(SRC
   io_cache.c
   io_collada.c
   io_ops.c
+  io_usd.c
 
   io_alembic.h
   io_cache.h
   io_collada.h
   io_ops.h
+  io_usd.h
 )
 
 set(LIB
@@ -69,6 +72,13 @@ if(WITH_ALEMBIC)
   endif()
 endif()
 
+if(WITH_USD)
+  list(APPEND LIB
+    bf_usd
+  )
+  add_definitions(-DWITH_USD)
+endif()
+
 if(WITH_INTERNATIONAL)
   add_definitions(-DWITH_INTERNATIONAL)
 endif()
diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c
index e04fe4a20c0..acb511a414d 100644
--- a/source/blender/editors/io/io_ops.c
+++ b/source/blender/editors/io/io_ops.c
@@ -33,6 +33,10 @@
 #  include "io_alembic.h"
 #endif
 
+#ifdef WITH_USD
+#  include "io_usd.h"
+#endif
+
 #include "io_cache.h"
 
 void ED_operatortypes_io(void)
@@ -46,6 +50,9 @@ void ED_operatortypes_io(void)
   WM_operatortype_append(WM_OT_alembic_import);
   WM_operatortype_append(WM_OT_alembic_export);
 #endif
+#ifdef WITH_USD
+  WM_operatortype_append(WM_OT_usd_export);
+#endif
 
   WM_operatortype_append(CACHEFILE_OT_open);
   WM_operatortype_append(CACHEFILE_OT_reload);
diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
new file mode 100644
index 00000000000..901cddb342a
--- /dev/null
+++ b/source/blender/editors/io/io_usd.c
@@ -0,0 +1,227 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software  Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup editor/io
+ */
+
+#ifdef WITH_USD
+#  include "DNA_space_types.h"
+
+#  include "BKE_context.h"
+#  include "BKE_main.h"
+#  include "BKE_report.h"
+
+#  include "BLI_path_util.h"
+#  include "BLI_string.h"
+#  include "BLI_utildefines.h"
+
+#  include "RNA_access.h"
+#  include "RNA_define.h"
+
+#  include "UI_interface.h"
+#  include "UI_resources.h"
+
+#  include "WM_api.h"
+#  include "WM_types.h"
+
+#  include "DEG_depsgraph.h"
+
+#  include "io_usd.h"
+#  include "usd.h"
+
+const EnumPropertyItem rna_enum_usd_export_evaluation_mode_items[] = {
+    {DAG_EVAL_RENDER,
+     "RENDER",
+     0,
+     "Render",
+     "Use Render settings for object visibility, modifier settings, etc"},
+    {DAG_EVAL_VIEWPORT,
+     "VIEWPORT",
+     0,
+     "Viewport",
+     "Use Viewport settings for object visibility, modifier settings, etc"},
+    {0, NULL, 0, NULL, NULL},
+};
+
+/* Stored in the wmOperator's customdata field to indicate it should run as a background job.
+ * This is set when the operator is invoked, and not set when it is only executed. */
+#  define AS_BACKGROUND_JOB 1
+
+static int wm_usd_export_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+  /* Mark this operator call as 'invoked', so that it'll run as a background job. */
+  op->customdata = POINTER_FROM_INT(AS_BACKGROUND_JOB);
+
+  if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+    Main *bmain = CTX_data_main(C);
+    char filepath[FILE_MAX];
+
+    if (BKE_main_blendfile_path(bmain)[0] == '\0') {
+      BLI_strncpy(filepath, "untitled", sizeof(filepath));
+    }
+    else {
+      BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
+    }
+
+    BLI_path_extension_replace(filepath, sizeof(filepath), ".usdc");
+    RNA_string_set(op->ptr, "filepath", filepath);
+  }
+
+  WM_event_add_fileselect(C, op);
+
+  return OPERATOR_RUNNING_MODAL;
+
+  UNUSED_VARS(event);
+}
+
+static int wm_usd_export_exec(bContext *C, wmOperator *op)
+{
+  if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+    BKE_report(op->reports, RPT_ERROR, "No filename given");
+    return OPERATOR_CANCELLED;
+  }
+
+  char filename[FILE_MAX];
+  RNA_string_get(op->ptr, "filepath", filename);
+
+  const bool as_background_job = (POINTER_AS_INT(op->customdata) & AS_BACKGROUND_JOB) != 0;
+  const bool selected_objects_only = RNA_boolean_get(op->ptr, "selected_objects_only");
+  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 par

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list