[Bf-blender-cvs] [6b2953e5b24] sybren-usd: Merge origin/master

Sybren A. Stüvel noreply at git.blender.org
Wed Oct 2 16:50:46 CEST 2019


Commit: 6b2953e5b24efae576f72ed8d900e8ea3903d4a3
Author: Sybren A. Stüvel
Date:   Wed Oct 2 16:50:33 2019 +0200
Branches: sybren-usd
https://developer.blender.org/rB6b2953e5b24efae576f72ed8d900e8ea3903d4a3

Merge origin/master

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



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

diff --cc CMakeLists.txt
index 3612f08bf28,cddb93dd7ab..bb30747c377
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@@ -1768,9 -1770,10 +1774,11 @@@ if(FIRST_RUN
    info_cfg_option(WITH_CYCLES)
    info_cfg_option(WITH_FREESTYLE)
    info_cfg_option(WITH_OPENCOLORIO)
+   info_cfg_option(WITH_OPENIMAGEDENOISE)
    info_cfg_option(WITH_OPENVDB)
    info_cfg_option(WITH_ALEMBIC)
 +  info_cfg_option(WITH_USD)
+   info_cfg_option(WITH_QUADRIFLOW)
  
    info_cfg_text("Compiler Options:")
    info_cfg_option(WITH_BUILDINFO)
diff --cc source/blender/CMakeLists.txt
index 2f00cce25b3,203543b0ef0..a13edce7541
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@@ -153,6 -153,7 +153,10 @@@ endif(
  if(WITH_ALEMBIC)
    add_subdirectory(alembic)
  endif()
 +if(WITH_USD)
 +  add_subdirectory(usd)
 +endif()
+ 
+ if(WIN32)
+   add_subdirectory(blendthumb)
+ endif()
diff --cc source/blender/editors/space_file/filelist.c
index c638de91968,27cccf6bab1..5cfd3ccd686
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@@ -2128,9 -2130,12 +2130,15 @@@ int ED_path_extension_type(const char *
    else if (BLI_path_extension_check(path, ".abc")) {
      return FILE_TYPE_ALEMBIC;
    }
 +  else if (BLI_path_extension_check_n(path, ".usda", ".usdb", ".usdc", ".usdz", NULL)) {
 +    return FILE_TYPE_USD;
 +  }
+   else if (BLI_path_extension_check(path, ".zip")) {
+     return FILE_TYPE_ARCHIVE;
+   }
+   else if (BLI_path_extension_check_n(path, ".obj", ".3ds", ".fbx", ".glb", ".gltf", NULL)) {
+     return FILE_TYPE_OBJECT_IO;
+   }
    else if (BLI_path_extension_check_array(path, imb_ext_image)) {
      return FILE_TYPE_IMAGE;
    }
diff --cc source/blender/makesdna/DNA_space_types.h
index 7976c255414,0f957a946d9..0a3204a78cc
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@@ -817,7 -834,8 +834,9 @@@ typedef enum eFileSel_File_Types 
    FILE_TYPE_OPERATOR = (1 << 14),
    FILE_TYPE_APPLICATIONBUNDLE = (1 << 15),
    FILE_TYPE_ALEMBIC = (1 << 16),
-   FILE_TYPE_USD = (1 << 17),
+   /** For all kinds of recognized import/export formats. No need for specialized types. */
+   FILE_TYPE_OBJECT_IO = (1 << 17),
++  FILE_TYPE_USD = (1 << 18),
  
    /** An FS directory (i.e. S_ISDIR on its path is true). */
    FILE_TYPE_DIR = (1 << 30),
diff --cc source/blender/usd/intern/usd_capi.cc
index ecf20b737ce,00000000000..ef5c56e95b8
mode 100644,000000..100644
--- a/source/blender/usd/intern/usd_capi.cc
+++ b/source/blender/usd/intern/usd_capi.cc
@@@ -1,230 -1,0 +1,230 @@@
 +/*
 + * 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.
 + */
 +
 +/** \file
 + * \ingroup USD
 + */
 +
 +#include "../usd.h"
 +#include "debug_timer.h"
 +#include "usd_hierarchy_iterator.h"
 +
 +#include <pxr/usd/usd/stage.h>
 +#include <pxr/usd/usdGeom/tokens.h>
 +
 +extern "C" {
 +#include "DEG_depsgraph.h"
 +#include "DEG_depsgraph_build.h"
 +#include "DEG_depsgraph_query.h"
 +
 +#include "DNA_scene_types.h"
 +
 +#include "BKE_blender_version.h"
 +#include "BKE_context.h"
 +#include "BKE_global.h"
 +#include "BKE_scene.h"
 +/* SpaceType struct has a member called 'new' which obviously conflicts with C++
 + * so temporarily redefining the new keyword to make it compile. */
 +#define new extern_new
 +#include "BKE_screen.h"
 +#undef new
 +
 +#include "BLI_fileops.h"
 +#include "BLI_string.h"
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "WM_api.h"
 +#include "WM_types.h"
 +}
 +
 +struct ExportJobData {
 +  ViewLayer *view_layer;
 +  Main *bmain;
 +  Depsgraph *depsgraph;
 +
 +  char filename[1024];
 +  USDExportParams params;
 +
 +  short *stop;
 +  short *do_update;
 +  float *progress;
 +
 +  bool was_canceled;
 +  bool export_ok;
 +};
 +
 +static void export_startjob(void *customdata, short *stop, short *do_update, float *progress)
 +{
 +  Timer timer_("Export to USD");
 +  ExportJobData *data = static_cast<ExportJobData *>(customdata);
 +
 +  data->stop = stop;
 +  data->do_update = do_update;
 +  data->progress = progress;
 +  data->was_canceled = false;
 +
 +  /* XXX annoying hack: needed to prevent data corruption when changing
 +   * scene frame in separate threads
 +   */
 +  G.is_rendering = true;
 +  BKE_spacedata_draw_locks(true);
 +  G.is_break = false;
 +
 +  // Construct the depsgraph for exporting.
 +  Scene *scene = DEG_get_input_scene(data->depsgraph);
 +  {
 +    Timer deg_build_timer_("Building depsgraph for USD export");
 +    ViewLayer *view_layer = DEG_get_input_view_layer(data->depsgraph);
 +    DEG_graph_build_from_view_layer(data->depsgraph, data->bmain, scene, view_layer);
 +    BKE_scene_graph_update_tagged(data->depsgraph, data->bmain);
 +  }
 +
 +  // Constructing & evaluating the depsgraph counts as 10% of the work.
 +  *progress = 0.1f;
 +  *do_update = true;
 +
 +  // For restoring the current frame after exporting animation is done.
 +  const int orig_frame = CFRA;
 +
 +  {
 +    Timer usd_write_timer_("Writing to USD");
 +
 +    // Create a stage and set up the metadata.
 +    pxr::UsdStageRefPtr usd_stage = pxr::UsdStage::CreateNew(data->filename);
 +    usd_stage->SetMetadata(pxr::UsdGeomTokens->upAxis, pxr::VtValue(pxr::UsdGeomTokens->z));
 +    usd_stage->SetMetadata(pxr::UsdGeomTokens->metersPerUnit,
 +                           pxr::VtValue(scene->unit.scale_length));
 +    usd_stage->GetRootLayer()->SetDocumentation(std::string("Blender ") + versionstr);
 +
 +    // Set up the stage for animated data.
 +    if (data->params.export_animation) {
 +      usd_stage->SetTimeCodesPerSecond(FPS);
 +      usd_stage->SetStartTimeCode(scene->r.sfra);
 +      usd_stage->SetEndTimeCode(scene->r.efra);
 +    }
 +
 +    USDHierarchyIterator iter(data->depsgraph, usd_stage, data->params);
 +
 +    if (data->params.export_animation) {
 +      // Writing the animated frames is 80% of the work.
 +      float progress_per_frame = 0.8f / std::max(1, (scene->r.efra - scene->r.sfra + 1));
 +
 +      for (float frame = scene->r.sfra; frame <= scene->r.efra; frame++) {
 +        if (G.is_break) {
 +          break;
 +        }
 +
 +        // Update the scene for the next frame to render.
 +        scene->r.cfra = static_cast<int>(frame);
 +        scene->r.subframe = frame - scene->r.cfra;
 +        BKE_scene_graph_update_for_newframe(data->depsgraph, data->bmain);
 +
 +        iter.set_export_frame(frame);
 +        iter.iterate();
 +
 +        *progress += progress_per_frame;
 +        *do_update = true;
 +      }
 +    }
 +    else {
 +      // If we're not animating, a single iteration over all objects is enough.
 +      iter.iterate();
 +    }
 +
 +    iter.release_writers();
 +
 +    // Writing the final file is the other 10% of the work.
 +    *progress = 0.9f;
 +    *do_update = true;
 +    usd_stage->GetRootLayer()->Save();
 +  }
 +
 +  *progress = 0.99f;
 +  *do_update = true;
 +
 +  if (CFRA != orig_frame) {
 +    CFRA = orig_frame;
 +    BKE_scene_graph_update_for_newframe(data->depsgraph, data->bmain);
 +  }
 +
 +  data->export_ok = !data->was_canceled;
 +
 +  *progress = 1.0f;
 +  *do_update = true;
 +}
 +
 +static void export_endjob(void *customdata)
 +{
 +  ExportJobData *data = static_cast<ExportJobData *>(customdata);
 +
 +  DEG_graph_free(data->depsgraph);
 +
 +  if (data->was_canceled && BLI_exists(data->filename)) {
 +    BLI_delete(data->filename, false, false);
 +  }
 +
 +  G.is_rendering = false;
 +  BKE_spacedata_draw_locks(false);
 +}
 +
 +bool USD_export(Scene *scene,
 +                bContext *C,
 +                const char *filepath,
 +                const struct USDExportParams *params,
 +                bool as_background_job)
 +{
 +  ExportJobData *job = static_cast<ExportJobData *>(
 +      MEM_mallocN(sizeof(ExportJobData), "ExportJobData"));
 +
 +  job->bmain = CTX_data_main(C);
 +  job->export_ok = false;
 +  BLI_strncpy(job->filename, filepath, 1024);
 +
 +  ViewLayer *view_layer = CTX_data_view_layer(C);
-   job->depsgraph = DEG_graph_new(scene, view_layer, params->evaluation_mode);
++  job->depsgraph = DEG_graph_new(job->bmain, scene, view_layer, params->evaluation_mode);
 +  job->params = *params;
 +
 +  bool export_ok = false;
 +  if (as_background_job) {
 +    wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
 +                                CTX_wm_window(C),
 +                                scene,
 +                                "USD Export",
 +                                WM_JOB_PROGRESS,
 +                                WM_JOB_TYPE_ALEMBIC);
 +
 +    /* setup job */
 +    WM_jobs_customdata_set(wm_job, job, MEM_freeN);
 +    WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_FRAME, NC_SCENE | ND_FRAME);
 +    WM_jobs_callbacks(wm_job, export_startjob, NULL, NULL, export_endjob);
 +
 +    WM_jobs_start(CTX_wm_manager(C), wm_job);
 +  }
 +  else {
 +    /* Fake a job context, so that we don't need NULL pointer checks while exporting. */
 +    short stop = 0, do_update = 0;
 +    float progress = 0.f;
 +
 +    export_startjob(job, &stop, &do_update, &progress);
 +    export_endjob(job);
 +    export_ok = job->export_ok;
 +
 +    MEM_freeN(job);
 +  }
 +
 +  return export_ok;
 +}



More information about the Bf-blender-cvs mailing list