[Bf-blender-cvs] [14caaa8c9f5] usd-importer-T81257-merge: USD import: Clang-Tidy warning fixes.

makowalski noreply at git.blender.org
Wed Jul 21 19:31:17 CEST 2021


Commit: 14caaa8c9f5ab66103641ab943193f5fe9d7a54c
Author: makowalski
Date:   Wed Jul 21 13:18:49 2021 -0400
Branches: usd-importer-T81257-merge
https://developer.blender.org/rB14caaa8c9f5ab66103641ab943193f5fe9d7a54c

USD import: Clang-Tidy warning fixes.

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

M	source/blender/io/usd/intern/usd_capi_import.cc
M	source/blender/io/usd/intern/usd_reader_curve.cc
M	source/blender/io/usd/intern/usd_reader_material.cc
M	source/blender/io/usd/intern/usd_reader_mesh.cc
M	source/blender/io/usd/intern/usd_reader_nurbs.cc
M	source/blender/io/usd/intern/usd_reader_prim.cc
M	source/blender/io/usd/intern/usd_reader_xform.cc
M	source/blender/io/usd/usd.h

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

diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc
index 8507c10d9ae..bbb0922bd69 100644
--- a/source/blender/io/usd/intern/usd_capi_import.cc
+++ b/source/blender/io/usd/intern/usd_capi_import.cc
@@ -172,7 +172,7 @@ static void import_startjob(void *customdata, short *stop, short *do_update, flo
     DEG_id_tag_update(&import_collection->id, ID_RECALC_COPY_ON_WRITE);
     DEG_relations_tag_update(data->bmain);
 
-    WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+    WM_main_add_notifier(NC_SCENE | ND_LAYER, nullptr);
 
     data->view_layer->active_collection = BKE_layer_collection_first_from_scene_collection(
         data->view_layer, import_collection);
@@ -248,8 +248,8 @@ static void import_startjob(void *customdata, short *stop, short *do_update, flo
 
     USDPrimReader *parent = reader->parent();
 
-    if (parent == NULL) {
-      ob->parent = NULL;
+    if (parent == nullptr) {
+      ob->parent = nullptr;
     }
     else {
       ob->parent = parent->object();
@@ -381,7 +381,7 @@ bool USD_import(struct bContext *C,
   job->settings.sequence_len = params->sequence_len;
   job->error_code = USD_NO_ERROR;
   job->was_canceled = false;
-  job->archive = NULL;
+  job->archive = nullptr;
 
   job->params = *params;
 
@@ -399,7 +399,7 @@ bool USD_import(struct bContext *C,
     /* setup job */
     WM_jobs_customdata_set(wm_job, job, import_freejob);
     WM_jobs_timer(wm_job, 0.1, NC_SCENE, NC_SCENE);
-    WM_jobs_callbacks(wm_job, import_startjob, NULL, NULL, import_endjob);
+    WM_jobs_callbacks(wm_job, import_startjob, nullptr, nullptr, import_endjob);
 
     WM_jobs_start(CTX_wm_manager(C), wm_job);
   }
@@ -429,23 +429,23 @@ static USDPrimReader *get_usd_reader(CacheReader *reader, Object * /* ob */, con
 
   if (!iobject.IsValid()) {
     *err_str = "Invalid object: verify object path";
-    return NULL;
+    return nullptr;
   }
 
   return usd_reader;
 }
 
-Mesh *USD_read_mesh(CacheReader *reader,
-                    Object *ob,
-                    Mesh *existing_mesh,
-                    const float time,
-                    const char **err_str,
-                    const int read_flag)
+struct Mesh *USD_read_mesh(struct CacheReader *reader,
+                           struct Object *ob,
+                           struct Mesh *existing_mesh,
+                           const float time,
+                           const char **err_str,
+                           const int read_flag)
 {
   USDGeomReader *usd_reader = dynamic_cast<USDGeomReader *>(get_usd_reader(reader, ob, err_str));
 
-  if (usd_reader == NULL) {
-    return NULL;
+  if (usd_reader == nullptr) {
+    return nullptr;
   }
 
   return usd_reader->read_mesh(existing_mesh, time, read_flag, err_str);
@@ -456,7 +456,7 @@ bool USD_mesh_topology_changed(
 {
   USDGeomReader *usd_reader = dynamic_cast<USDGeomReader *>(get_usd_reader(reader, ob, err_str));
 
-  if (usd_reader == NULL) {
+  if (usd_reader == nullptr) {
     return false;
   }
 
@@ -493,9 +493,9 @@ CacheReader *CacheReader_open_usd_object(CacheArchiveHandle *handle,
   /* TODO(makowalski): The handle does not have the proper import params or settings. */
   USDPrimReader *usd_reader = archive->create_reader(prim);
 
-  if (usd_reader == NULL) {
+  if (usd_reader == nullptr) {
     /* This object is not supported */
-    return NULL;
+    return nullptr;
   }
   usd_reader->object(object);
   usd_reader->incref();
diff --git a/source/blender/io/usd/intern/usd_reader_curve.cc b/source/blender/io/usd/intern/usd_reader_curve.cc
index 675e2a4c17d..c84b768bd36 100644
--- a/source/blender/io/usd/intern/usd_reader_curve.cc
+++ b/source/blender/io/usd/intern/usd_reader_curve.cc
@@ -100,7 +100,7 @@ void USDCurvesReader::read_curve_sample(Curve *cu, const double motionSampleTime
 
   /* If normals, extrude, else bevel.
    * Perhaps to be replaced by Blender/USD Schema. */
-  if (usdNormals.size() > 0) {
+  if (!usdNormals.empty()) {
     // Set extrusion to 1.0f.
     curve_->ext1 = 1.0f;
   }
@@ -161,8 +161,9 @@ void USDCurvesReader::read_curve_sample(Curve *cu, const double motionSampleTime
       bp->weight = weight;
 
       float radius = curve_->width;
-      if (idx < usdWidths.size())
+      if (idx < usdWidths.size()) {
         radius = usdWidths[idx];
+      }
 
       bp->radius = radius;
     }
diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc
index 0a2f487f9c9..a99e65f5792 100644
--- a/source/blender/io/usd/intern/usd_reader_material.cc
+++ b/source/blender/io/usd/intern/usd_reader_material.cc
@@ -260,7 +260,7 @@ Material *USDMaterialReader::add_material(const pxr::UsdShadeMaterial &usd_mater
     return nullptr;
   }
 
-  std::string mtl_name = usd_material.GetPrim().GetName().GetString().c_str();
+  std::string mtl_name = usd_material.GetPrim().GetName().GetString();
 
   /* Create the material. */
   Material *mtl = BKE_material_add(bmain_, mtl_name.c_str());
@@ -293,12 +293,12 @@ void USDMaterialReader::import_usd_preview(Material *mtl,
    * and output shaders. */
 
   /* Add the node tree. */
-  bNodeTree *ntree = ntreeAddTree(NULL, "Shader Nodetree", "ShaderNodeTree");
+  bNodeTree *ntree = ntreeAddTree(nullptr, "Shader Nodetree", "ShaderNodeTree");
   mtl->nodetree = ntree;
   mtl->use_nodes = true;
 
   /* Create the Principled BSDF shader node. */
-  bNode *principled = add_node(NULL, ntree, SH_NODE_BSDF_PRINCIPLED, 0.0f, 300.0f);
+  bNode *principled = add_node(nullptr, ntree, SH_NODE_BSDF_PRINCIPLED, 0.0f, 300.0f);
 
   if (!principled) {
     std::cerr << "ERROR: Couldn't create SH_NODE_BSDF_PRINCIPLED node for USD shader "
@@ -307,7 +307,7 @@ void USDMaterialReader::import_usd_preview(Material *mtl,
   }
 
   /* Create the material output node. */
-  bNode *output = add_node(NULL, ntree, SH_NODE_OUTPUT_MATERIAL, 300.0f, 300.0f);
+  bNode *output = add_node(nullptr, ntree, SH_NODE_OUTPUT_MATERIAL, 300.0f, 300.0f);
 
   if (!output) {
     std::cerr << "ERROR: Couldn't create SH_NODE_OUTPUT_MATERIAL node for USD shader "
@@ -513,7 +513,7 @@ void USDMaterialReader::follow_connection(const pxr::UsdShadeInput &usd_input,
       float locy = 0.0f;
       compute_node_loc(column + 1, locx, locy, r_ctx);
 
-      bNode *normal_map = add_node(NULL, ntree, SH_NODE_NORMAL_MAP, locx, locy);
+      bNode *normal_map = add_node(nullptr, ntree, SH_NODE_NORMAL_MAP, locx, locy);
 
       // Currently, the Normal Map node has Tangent Space as the default,
       // which is what we need, so we don't need to explicitly set it.
@@ -553,7 +553,7 @@ void USDMaterialReader::convert_usd_uv_texture(const pxr::UsdShadeShader &usd_sh
   compute_node_loc(column, locx, locy, r_ctx);
 
   // Create the Texture Image node.
-  bNode *tex_image = add_node(NULL, ntree, SH_NODE_TEX_IMAGE, locx, locy);
+  bNode *tex_image = add_node(nullptr, ntree, SH_NODE_TEX_IMAGE, locx, locy);
 
   if (!tex_image) {
     std::cerr << "ERROR: Couldn't create SH_NODE_TEX_IMAGE for node input " << dest_socket_name
@@ -658,7 +658,7 @@ void USDMaterialReader::convert_usd_primvar_reader_float2(
   compute_node_loc(column, locx, locy, r_ctx);
 
   // Create the UV Map node.
-  bNode *uv_map = add_node(NULL, ntree, SH_NODE_UVMAP, locx, locy);
+  bNode *uv_map = add_node(nullptr, ntree, SH_NODE_UVMAP, locx, locy);
 
   if (!uv_map) {
     std::cerr << "ERROR: Couldn't create SH_NODE_UVMAP for node input " << dest_socket_name
diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc
index 1238e13941f..f5f47396809 100644
--- a/source/blender/io/usd/intern/usd_reader_mesh.cc
+++ b/source/blender/io/usd/intern/usd_reader_mesh.cc
@@ -63,7 +63,7 @@ static void build_mat_map(const Main *bmain, std::map<std::string, Material *> &
 
   for (; material; material = static_cast<Material *>(material->id.next)) {
     // We have to do this because the stored material name is coming directly from usd
-    mat_map[pxr::TfMakeValidIdentifier(material->id.name + 2).c_str()] = material;
+    mat_map[pxr::TfMakeValidIdentifier(material->id.name + 2)] = material;
   }
 }
 
@@ -155,19 +155,19 @@ static void *add_customdata_cb(Mesh *mesh, const char *name, const int data_type
 
   /* unsupported custom data type -- don't do anything. */
   if (!ELEM(cd_data_type, CD_MLOOPUV, CD_MLOOPCOL)) {
-    return NULL;
+    return nullptr;
   }
 
   loopdata = &mesh->ldata;
   cd_ptr = CustomData_get_layer_named(loopdata, cd_data_type, name);
-  if (cd_ptr != NULL) {
+  if (cd_ptr != nullptr) {
     /* layer already exists, so just return it. */
     return cd_ptr;
   }
 
   /* Create a new layer. */
   numloops = mesh->totloop;
-  cd_ptr = CustomData_add_layer_named(loopdata, cd_data_type, CD_DEFAULT, NULL, numloops, name);
+  cd_ptr = CustomData_add_layer_named(loopdata, cd_data_type, CD_DEFAULT, nullptr, numloops, name);
   return cd_ptr;
 }
 
@@ -199,7 +199,7 @@ void USDMeshReader::read_object_data(Main *bmain, const double motionSampleTime)
   Mesh *mesh = (Mesh *)object_->data;
 
   is_initial_load_ = true;
-  Mesh *read_mesh = this->read_mesh(mesh, motionSampleTime, import_params_.global_read_flag, NULL);
+  Mesh *read_mesh = this->read_mesh(mesh, motionSampleTime, import_params_.global_read_flag, nullptr);
 
   is_initial_load_ = false;
   if (read_mesh != mesh) {
@@ -337,8 +337,9 @@ void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bo
         uv_token = pxr::TfToken(layer_name);
         uv_token_map_.insert(std::make_pair(layer_name, uv_token));
       }
-      else
+      else {
         uv_token = uv_token_map_.at(layer_name);
+      }
 
       // Early out if no token found, this should never happen
       if (uv_token.IsEmpty()) {
@@ -686,7 +687,7 @@ void USDMeshReader::assign_facesets_to_mpoly(double motionSampleTime,
       mesh_prim_);
 
   int current_mat = 0;
-  if (subsets.size() > 0) {
+  if (!subsets.empty()) {
     for (const pxr::UsdGeomSubset &subset : subsets) {
       pxr::UsdShadeMaterialBindingAPI subset_api = pxr::UsdShadeMaterialBindingAPI(
           subset.GetPrim());
diff --git a/source/blender/io/usd/intern/usd_reader_nurbs.cc b

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list