[Bf-blender-cvs] [27eea5e69ec] universal-scene-description: Merge branch 'master' into universal-scene-description

Michael Kowalski noreply at git.blender.org
Wed Dec 14 01:49:36 CET 2022


Commit: 27eea5e69ecabfeec912e30923f26835de0f420c
Author: Michael Kowalski
Date:   Tue Dec 13 18:40:08 2022 -0500
Branches: universal-scene-description
https://developer.blender.org/rB27eea5e69ecabfeec912e30923f26835de0f420c

Merge branch 'master' into universal-scene-description

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



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

diff --cc source/blender/io/usd/CMakeLists.txt
index 455bda271e7,ebd292782c0..ece12f5fe7e
--- a/source/blender/io/usd/CMakeLists.txt
+++ b/source/blender/io/usd/CMakeLists.txt
@@@ -156,7 -123,7 +156,8 @@@ set(LI
  
  list(APPEND LIB
    ${BOOST_LIBRARIES}
 +  ${PYTHON_LINKFLAGS}
+   ${BOOST_PYTHON_LIBRARIES}
    ${PYTHON_LIBRARIES}
  )
  
@@@ -179,10 -146,10 +180,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 85335172533,28da9e388c5..8c724e6c0be
--- a/source/blender/io/usd/intern/usd_capi_export.cc
+++ b/source/blender/io/usd/intern/usd_capi_export.cc
@@@ -60,15 -40,8 +60,13 @@@ struct ExportJobData 
    wmWindowManager *wm;
  
    char filepath[FILE_MAX];
 +  char usdz_filepath[FILE_MAX];
 +  bool is_usdz_export;
    USDExportParams params;
  
-   short *stop;
-   short *do_update;
 +  float *progress;
 +
 +  bool was_canceled;
    bool export_ok;
    timeit::TimePoint start_time;
  };
@@@ -241,119 -54,6 +239,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, sizeof(texture_path));
 +
 +  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. */
@@@ -362,11 -62,7 +360,9 @@@
                              float *progress)
  {
    ExportJobData *data = static_cast<ExportJobData *>(customdata);
 -  data->export_ok = false;
 +
-   data->stop = stop;
-   data->do_update = do_update;
 +  data->progress = progress;
 +  data->was_canceled = false;
    data->start_time = timeit::Clock::now();
  
    G.is_rendering = true;
diff --cc source/blender/io/usd/intern/usd_reader_mesh.cc
index 9c0c76a50c1,52cd3b32b49..b07d72985e3
--- 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 = pxr::UsdGeomPrimvarsAPI(mesh_prim_);
+ 
 -  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_material.cc
index 39d56e6cb44,98cd4036fd0..703078bbe10
--- a/source/blender/io/usd/intern/usd_writer_material.cc
+++ b/source/bl

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list