[Bf-blender-cvs] [a400935d29f] tmp-dynamic-usd: Merge branch 'tmp-vfx-platform-2023' into tmp-dynamic-usd

Michael Kowalski noreply at git.blender.org
Tue Nov 8 01:38:49 CET 2022


Commit: a400935d29f54b9bd821d093873eb4643a279e59
Author: Michael Kowalski
Date:   Mon Nov 7 19:37:51 2022 -0500
Branches: tmp-dynamic-usd
https://developer.blender.org/rBa400935d29f54b9bd821d093873eb4643a279e59

Merge branch 'tmp-vfx-platform-2023' into tmp-dynamic-usd

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



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

diff --cc source/blender/io/usd/CMakeLists.txt
index 6973c181981,745a1c69dce..1cbec8c471f
--- a/source/blender/io/usd/CMakeLists.txt
+++ b/source/blender/io/usd/CMakeLists.txt
@@@ -178,10 -145,10 +178,11 @@@ if(WIN32
    set_property(TARGET bf_usd APPEND_STRING PROPERTY INTERFACE_LINK_OPTIONS "$<$<CONFIG:MinSizeRel>:/WHOLEARCHIVE:${USD_RELEASE_LIB}>")
  endif()
  
- # Source: https://github.com/PixarAnimationStudios/USD/blob/master/BUILDING.md#linking-whole-archives
+ # Source:
+ # https://github.com/PixarAnimationStudios/USD/blob/master/BUILDING.md#linking-whole-archives
  if(WIN32)
    target_link_libraries(bf_usd INTERFACE ${USD_LIBRARIES})
 +  target_compile_options(bf_usd PRIVATE /w34101)
  elseif(APPLE)
    target_link_libraries(bf_usd INTERFACE -Wl,-force_load ${USD_LIBRARIES})
  elseif(UNIX)
diff --cc source/blender/io/usd/intern/usd_capi_export.cc
index 8df13fd0dcd,28da9e388c5..72c20f28b62
--- a/source/blender/io/usd/intern/usd_capi_export.cc
+++ b/source/blender/io/usd/intern/usd_capi_export.cc
@@@ -58,15 -40,8 +58,15 @@@ struct ExportJobData 
    wmWindowManager *wm;
  
    char filepath[FILE_MAX];
 +  char usdz_filepath[FILE_MAX];
 +  bool is_usdz_export;
    USDExportParams params;
  
-   short *stop;
-   short *do_update;
++  bool *stop;
++  bool *do_update;
 +  float *progress;
 +
 +  bool was_canceled;
    bool export_ok;
    timeit::TimePoint start_time;
  };
@@@ -208,119 -54,6 +208,119 @@@ static void report_job_duration(const E
    std::cout << '\n';
  }
  
 +static void process_usdz_textures(const ExportJobData *data, const char *path) {
 +  const eUSDZTextureDownscaleSize enum_value = data->params.usdz_downscale_size;
 +  if (enum_value == USD_TEXTURE_SIZE_KEEP) {
 +    return;
 +  }
 +
 +  int image_size = (
 +      (enum_value == USD_TEXTURE_SIZE_CUSTOM ? data->params.usdz_downscale_custom_size : enum_value)
 +  );
 +
 +  image_size = image_size < 128 ? 128 : image_size;
 +
 +  char texture_path[4096];
 +  BLI_strcpy_rlen(texture_path, path);
 +  BLI_path_append(texture_path, 4096, "textures");
-   BLI_path_slash_ensure(texture_path);
++  BLI_path_slash_ensure(texture_path, 4096);
 +
 +  struct direntry *entries;
 +  unsigned int num_files = BLI_filelist_dir_contents(texture_path, &entries);
 +
 +  for (int index = 0; index < num_files; index++) {
 +    /* We can skip checking extensions as this folder is only created
 +     * when we're doing a USDZ export. */
 +    if (!BLI_is_dir(entries[index].path)) {
 +      Image *im = BKE_image_load_ex(data->bmain, entries[index].path, LIB_ID_CREATE_NO_MAIN);
 +      if (!im) {
 +        std::cerr << "-- Unable to open file for downscaling: " << entries[index].path << std::endl;
 +        continue;
 +      }
 +
 +      int width, height;
 +      BKE_image_get_size(im, NULL, &width, &height);
 +      const int longest = width >= height ? width : height;
 +      const float scale = 1.0 / ((float)longest / (float)image_size);
 +
 +      if (longest > image_size) {
 +        const int width_adjusted  = (float)width * scale;
 +        const int height_adjusted = (float)height * scale;
 +        BKE_image_scale(im, width_adjusted, height_adjusted);
 +
 +        ImageSaveOptions opts;
 +
 +        if (BKE_image_save_options_init(&opts, data->bmain, data->scene, im, NULL, false, false)) {
 +          bool result = BKE_image_save(NULL, data->bmain, im, NULL, &opts);
 +          if (!result) {
 +            std::cerr << "-- Unable to resave " << data->filepath << " (new size: "
 +                      << width_adjusted << "x" << height_adjusted << ")" << std::endl;
 +          }
 +          else {
 +            std::cout << "Downscaled " << entries[index].path << " to "
 +                      << width_adjusted << "x" << height_adjusted << std::endl;
 +          }
 +        }
 +
 +        BKE_image_save_options_free(&opts);
 +      }
 +
 +      /* Make sure to free the image so it doesn't stick
 +       * around in the library of the open file. */
 +      BKE_id_free(data->bmain, (void*)im);
 +    }
 +  }
 +
 +  BLI_filelist_free(entries, num_files);
 +}
 +
 +static bool perform_usdz_conversion(const ExportJobData *data)
 +{
 +  char usdc_temp_dir[FILE_MAX], usdc_file[FILE_MAX];
 +  BLI_split_dirfile(data->filepath, usdc_temp_dir, usdc_file, FILE_MAX, FILE_MAX);
 +
 +  char usdz_file[FILE_MAX];
 +  BLI_split_file_part(data->usdz_filepath, usdz_file, FILE_MAX);
 +
 +  char original_working_dir[FILE_MAX];
 +  BLI_current_working_dir(original_working_dir, FILE_MAX);
 +  BLI_change_working_dir(usdc_temp_dir);
 +
 +  process_usdz_textures(data, usdc_temp_dir);
 +
 +  if (data->params.usdz_is_arkit) {
 +    std::cout << "USDZ Export: Creating ARKit Asset" << std::endl;
 +    pxr::UsdUtilsCreateNewARKitUsdzPackage(pxr::SdfAssetPath(usdc_file), usdz_file);
 +  }
 +  else {
 +    pxr::UsdUtilsCreateNewUsdzPackage(pxr::SdfAssetPath(usdc_file), usdz_file);
 +  }
 +  BLI_change_working_dir(original_working_dir);
 +
 +  char usdz_temp_dirfile[FILE_MAX];
 +  BLI_path_join(usdz_temp_dirfile, FILE_MAX, usdc_temp_dir, usdz_file);
 +
 +  int result = 0;
 +  if (BLI_exists(data->usdz_filepath)) {
 +    result = BLI_delete(data->usdz_filepath, false, false);
 +    if (result != 0) {
 +      WM_reportf(
 +          RPT_ERROR, "USD Export: Unable to delete existing usdz file %s", data->usdz_filepath);
 +      return false;
 +    }
 +  }
 +  result = BLI_rename(usdz_temp_dirfile, data->usdz_filepath);
 +  if (result != 0) {
 +    WM_reportf(RPT_ERROR,
 +               "USD Export: Couldn't move new usdz file from temporary location %s to %s",
 +               usdz_temp_dirfile,
 +               data->usdz_filepath);
 +    return false;
 +  }
 +
 +  return true;
 +}
 +
  static void export_startjob(void *customdata,
                              /* Cannot be const, this function implements wm_jobs_start_callback.
                               * NOLINTNEXTLINE: readability-non-const-parameter. */
diff --cc source/blender/io/usd/intern/usd_reader_mesh.cc
index 9c0c76a50c1,8138f38fcad..75d9330392f
--- a/source/blender/io/usd/intern/usd_reader_mesh.cc
+++ b/source/blender/io/usd/intern/usd_reader_mesh.cc
@@@ -34,9 -33,9 +34,10 @@@
  #include <pxr/base/vt/value.h>
  #include <pxr/usd/sdf/types.h>
  #include <pxr/usd/usdGeom/mesh.h>
+ #include <pxr/usd/usdGeom/primvarsAPI.h>
  #include <pxr/usd/usdGeom/subset.h>
  #include <pxr/usd/usdShade/materialBindingAPI.h>
 +#include <pxr/usd/usdSkel/bindingAPI.h>
  
  #include <iostream>
  
@@@ -492,37 -466,22 +496,39 @@@ void USDMeshReader::read_colors(Mesh *m
      return;
    }
  
-   std::vector<pxr::UsdGeomPrimvar> primvars = mesh_prim_.GetPrimvars();
 -  /* Early out if we read the display color before and if this attribute isn't animated. */
 -  if (primvar_varying_map_.find(usdtokens::displayColor) != primvar_varying_map_.end() &&
 -      !primvar_varying_map_.at(usdtokens::displayColor)) {
 -    return;
 -  }
++  pxr::UsdGeomPrimvarsAPI primvarsAPI(mesh_prim_.GetPrim());
+ 
 -  pxr::UsdGeomPrimvar color_primvar = mesh_prim_.GetDisplayColorPrimvar();
++  std::vector<pxr::UsdGeomPrimvar> primvars = primvarsAPI.GetPrimvars();
  
 -  if (!color_primvar.HasValue()) {
 -    return;
 -  }
 +  /* Convert all color primvars to custom layer data. */
 +  for (pxr::UsdGeomPrimvar pv : primvars) {
  
 -  pxr::TfToken interp = color_primvar.GetInterpolation();
 +    pxr::SdfValueTypeName type = pv.GetTypeName();
 +
 +    if (!ELEM(type,
 +              pxr::SdfValueTypeNames->Color3hArray,
 +              pxr::SdfValueTypeNames->Color3fArray,
 +              pxr::SdfValueTypeNames->Color3dArray)) {
 +      continue;
 +    }
 +
 +    pxr::TfToken name = pv.GetPrimvarName();
 +
 +    /* Skip if we read this primvar before and it isn't animated. */
 +    if (primvar_varying_map_.find(name) != primvar_varying_map_.end() &&
 +        !primvar_varying_map_.at(name)) {
 +        continue;
 +    }
 +
 +    read_colors(mesh, pv, motionSampleTime);
 +  }
 +}
  
 -  if (interp == pxr::UsdGeomTokens->varying) {
 -    std::cerr << "WARNING: Unsupported varying interpolation for display colors\n" << std::endl;
 +void USDMeshReader::read_colors(Mesh *mesh,
 +                                pxr::UsdGeomPrimvar &color_primvar,
 +                                double motionSampleTime)
 +{
 +  if (!(mesh && color_primvar && color_primvar.HasValue())) {
      return;
    }
  
diff --cc source/blender/io/usd/intern/usd_writer_hair.cc
index ae0e68ee8b1,8ec1447b505..7fbe68f9d25
--- a/source/blender/io/usd/intern/usd_writer_hair.cc
+++ b/source/blender/io/usd/intern/usd_writer_hair.cc
@@@ -21,28 -16,8 +21,28 @@@ USDHairWriter::USDHairWriter(const USDE
  {
  }
  
 +// This was copied from source/intern/cycles/blender/blender_curves.cpp
 +static float shaperadius(float shape, float root, float tip, float time)
 +{
 +  assert(time >= 0.0f);
 +  assert(time <= 1.0f);
 +  float radius = 1.0f - time;
 +
 +  if (shape != 0.0f) {
 +    if (shape < 0.0f)
 +      radius = powf(radius, 1.0f + shape);
 +    else
 +      radius = powf(radius, 1.0f / (1.0f - shape));
 +  }
 +  return (radius * (root - tip)) + tip;
 +}
 +
  void USDHairWriter::do_write(HierarchyContext &context)
  {
 +  /* Get untransformed vertices, there's a xform under the hair. */
 +  float inv_mat[4][4];
-   invert_m4_m4_safe(inv_mat, context.object->obmat);
++  invert_m4_m4_safe(inv_mat, context.object->object_to_world);
 +
    ParticleSystem *psys = context.particle_system;
    ParticleCacheKey **cache = psys->pathcache;
    if (cache == nullptr) {
diff --cc source/blender/io/usd/intern/usd_writer_mesh.cc
index 3d2aacb2d42,e7d79e888e4..ac0501588cf
--- a/source/blender/io/usd/intern/usd_writer_mesh.cc
+++ b/source/blender/io/usd/intern/usd_writer_mesh.cc
@@@ -222,337 -104,108 +222,342 @@@ struct USDMeshData 
    pxr::VtFloatArray corner_sharpnesses;
  };
  
 -void USDGenericMeshWriter::write_uv_maps(const Mesh *mesh, pxr::UsdGeomMesh usd_mesh)
 +void USDGenericMeshWriter::write_custom_data(const Mesh *mesh, pxr::UsdGeomMesh usd_mesh)
  {
 -  pxr::UsdTimeCode timecode = get_export_time_code();
 +  const CustomData *ldata = &mesh->ldata;
  
 -  pxr::UsdGeomPrimvarsAPI primvarsAPI(usd_mesh.GetPrim());
 +  /* Index of the UV layer to be renamed "st", s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list