diff options
Diffstat (limited to 'source/blender/io/usd')
20 files changed, 95 insertions, 87 deletions
diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt index 1205ae74e6f..06a0f12c571 100644 --- a/source/blender/io/usd/CMakeLists.txt +++ b/source/blender/io/usd/CMakeLists.txt @@ -20,13 +20,14 @@ add_definitions(-DTBB_SUPPRESS_DEPRECATED_MESSAGES=1) # add a USD_HAS_IMAGING define so code can dynamically detect this. # Cleanup of this variable is done at the end of the file since # test code further down uses it to add imaging tests. -FIND_FILE(USD_IMAGING_HEADERS +find_file( + USD_IMAGING_HEADERS NAMES capsuleAdapter.h PATHS - ${USD_INCLUDE_DIRS} + ${USD_INCLUDE_DIRS} PATH_SUFFIXES - pxr/usdImaging/usdImaging/ + pxr/usdImaging/usdImaging/ NO_DEFAULT_PATH ) @@ -142,7 +143,8 @@ 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}) elseif(APPLE) @@ -162,7 +164,7 @@ if(WITH_GTESTS) tests/usd_tests_common.h ) if(USD_IMAGING_HEADERS) - LIST(APPEND TEST_SRC tests/usd_imaging_test.cc) + list(APPEND TEST_SRC tests/usd_imaging_test.cc) endif() set(TEST_INC @@ -173,6 +175,6 @@ if(WITH_GTESTS) blender_add_test_lib(bf_io_usd_tests "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}") endif() -# In cmake version 3.21 and up, we can instead use the NO_CACHE option for -# find_file so we don't need to clear it from the cache here. +# In CMAKE version 3.21 and up, we can instead use the `NO_CACHE` option for +# `find_file` so we don't need to clear it from the cache here. unset(USD_IMAGING_HEADERS CACHE) diff --git a/source/blender/io/usd/intern/usd_capi_export.cc b/source/blender/io/usd/intern/usd_capi_export.cc index 1033f85181c..bf25c03fb7a 100644 --- a/source/blender/io/usd/intern/usd_capi_export.cc +++ b/source/blender/io/usd/intern/usd_capi_export.cc @@ -57,8 +57,8 @@ static void report_job_duration(const ExportJobData *data) static void export_startjob(void *customdata, /* Cannot be const, this function implements wm_jobs_start_callback. * NOLINTNEXTLINE: readability-non-const-parameter. */ - short *stop, - short *do_update, + bool *stop, + bool *do_update, float *progress) { ExportJobData *data = static_cast<ExportJobData *>(customdata); @@ -96,8 +96,7 @@ static void export_startjob(void *customdata, } usd_stage->SetMetadata(pxr::UsdGeomTokens->upAxis, pxr::VtValue(pxr::UsdGeomTokens->z)); - usd_stage->SetMetadata(pxr::UsdGeomTokens->metersPerUnit, - static_cast<double>(scene->unit.scale_length)); + usd_stage->SetMetadata(pxr::UsdGeomTokens->metersPerUnit, double(scene->unit.scale_length)); usd_stage->GetRootLayer()->SetDocumentation(std::string("Blender v") + BKE_blender_version_string()); @@ -120,7 +119,7 @@ static void export_startjob(void *customdata, } /* Update the scene for the next frame to render. */ - scene->r.cfra = static_cast<int>(frame); + scene->r.cfra = int(frame); scene->r.subframe = frame - scene->r.cfra; BKE_scene_graph_update_for_newframe(data->depsgraph); @@ -206,7 +205,7 @@ bool USD_export(bContext *C, } else { /* Fake a job context, so that we don't need NULL pointer checks while exporting. */ - short stop = 0, do_update = 0; + bool stop = false, do_update = false; float progress = 0.0f; blender::io::usd::export_startjob(job, &stop, &do_update, &progress); diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index 03af3aed2d0..680e9c758d3 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -126,8 +126,8 @@ struct ImportJobData { USDStageReader *archive; - short *stop; - short *do_update; + bool *stop; + bool *do_update; float *progress; char error_code; @@ -144,7 +144,7 @@ static void report_job_duration(const ImportJobData *data) std::cout << '\n'; } -static void import_startjob(void *customdata, short *stop, short *do_update, float *progress) +static void import_startjob(void *customdata, bool *stop, bool *do_update, float *progress) { ImportJobData *data = static_cast<ImportJobData *>(customdata); @@ -230,7 +230,7 @@ static void import_startjob(void *customdata, short *stop, short *do_update, flo *data->do_update = true; *data->progress = 0.2f; - const float size = static_cast<float>(archive->readers().size()); + const float size = float(archive->readers().size()); size_t i = 0; /* Sort readers by name: when creating a lot of objects in Blender, @@ -310,14 +310,14 @@ static void import_endjob(void *customdata) else if (data->archive) { Base *base; LayerCollection *lc; + const Scene *scene = data->scene; ViewLayer *view_layer = data->view_layer; - BKE_view_layer_base_deselect_all(view_layer); + BKE_view_layer_base_deselect_all(scene, view_layer); lc = BKE_layer_collection_get_active(view_layer); - /* Add all objects to the collection (don't do sync for each object). */ - BKE_layer_collection_resync_forbid(); + /* Add all objects to the collection. */ for (USDPrimReader *reader : data->archive->readers()) { if (!reader) { continue; @@ -329,9 +329,8 @@ static void import_endjob(void *customdata) BKE_collection_object_add(data->bmain, lc->collection, ob); } - /* Sync the collection, and do view layer operations. */ - BKE_layer_collection_resync_allow(); - BKE_main_collection_sync(data->bmain); + /* Sync and do the view layer operations. */ + BKE_view_layer_synced_ensure(scene, view_layer); for (USDPrimReader *reader : data->archive->readers()) { if (!reader) { continue; @@ -431,7 +430,7 @@ bool USD_import(struct bContext *C, } else { /* Fake a job context, so that we don't need NULL pointer checks while importing. */ - short stop = 0, do_update = 0; + bool stop = false, do_update = false; float progress = 0.0f; import_startjob(job, &stop, &do_update, &progress); diff --git a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc index 51261c4d91e..fbfda975055 100644 --- a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc +++ b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc @@ -141,7 +141,7 @@ AbstractHierarchyWriter *USDHierarchyIterator::create_hair_writer(const Hierarch } AbstractHierarchyWriter *USDHierarchyIterator::create_particle_writer( - const HierarchyContext *UNUSED(context)) + const HierarchyContext * /*context*/) { return nullptr; } diff --git a/source/blender/io/usd/intern/usd_reader_camera.cc b/source/blender/io/usd/intern/usd_reader_camera.cc index 7f1e9fef89d..da51787e437 100644 --- a/source/blender/io/usd/intern/usd_reader_camera.cc +++ b/source/blender/io/usd/intern/usd_reader_camera.cc @@ -71,7 +71,7 @@ void USDCameraReader::read_object_data(Main *bmain, const double motionSampleTim bcam->clip_end = clippingRangeVal.UncheckedGet<pxr::GfVec2f>()[1]; bcam->dof.focus_distance = focalDistanceVal.Get<float>(); - bcam->dof.aperture_fstop = static_cast<float>(fstopVal.Get<float>()); + bcam->dof.aperture_fstop = float(fstopVal.Get<float>()); if (bcam->type == CAM_ORTHO) { bcam->ortho_scale = max_ff(verAp.Get<float>(), horAp.Get<float>()); diff --git a/source/blender/io/usd/intern/usd_reader_curve.cc b/source/blender/io/usd/intern/usd_reader_curve.cc index 0d3c2feb8f3..ca48f3c2391 100644 --- a/source/blender/io/usd/intern/usd_reader_curve.cc +++ b/source/blender/io/usd/intern/usd_reader_curve.cc @@ -139,9 +139,9 @@ void USDCurvesReader::read_curve_sample(Curve *cu, const double motionSampleTime BPoint *bp = nu->bp; for (int j = 0; j < nu->pntsu; j++, bp++, idx++) { - bp->vec[0] = (float)usdPoints[idx][0]; - bp->vec[1] = (float)usdPoints[idx][1]; - bp->vec[2] = (float)usdPoints[idx][2]; + bp->vec[0] = float(usdPoints[idx][0]); + bp->vec[1] = float(usdPoints[idx][1]); + bp->vec[2] = float(usdPoints[idx][2]); bp->vec[3] = weight; bp->f1 = SELECT; bp->weight = weight; diff --git a/source/blender/io/usd/intern/usd_reader_curve.h b/source/blender/io/usd/intern/usd_reader_curve.h index 1e9330b81f1..48fb2c5e2d1 100644 --- a/source/blender/io/usd/intern/usd_reader_curve.h +++ b/source/blender/io/usd/intern/usd_reader_curve.h @@ -27,7 +27,7 @@ class USDCurvesReader : public USDGeomReader { bool valid() const override { - return static_cast<bool>(curve_prim_); + return bool(curve_prim_); } void create_object(Main *bmain, double motionSampleTime) override; diff --git a/source/blender/io/usd/intern/usd_reader_light.cc b/source/blender/io/usd/intern/usd_reader_light.cc index 55b9557dfb5..7204ea91896 100644 --- a/source/blender/io/usd/intern/usd_reader_light.cc +++ b/source/blender/io/usd/intern/usd_reader_light.cc @@ -203,7 +203,7 @@ void USDLightReader::read_object_data(Main *bmain, const double motionSampleTime if (pxr::UsdAttribute cone_angle_attr = shaping_api.GetShapingConeAngleAttr()) { float cone_angle = 0.0f; if (cone_angle_attr.Get(&cone_angle, motionSampleTime)) { - blight->spotsize = cone_angle * ((float)M_PI / 180.0f) * 2.0f; + blight->spotsize = cone_angle * (float(M_PI) / 180.0f) * 2.0f; } } @@ -226,7 +226,7 @@ void USDLightReader::read_object_data(Main *bmain, const double motionSampleTime if (pxr::UsdAttribute angle_attr = distant_light.GetAngleAttr()) { float angle = 0.0f; if (angle_attr.Get(&angle, motionSampleTime)) { - blight->sun_angle = angle * (float)M_PI / 180.0f; + blight->sun_angle = angle * float(M_PI) / 180.0f; } } } diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index 3546beb022c..d1af4553083 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -562,7 +562,7 @@ void USDMaterialReader::follow_connection(const pxr::UsdShadeInput &usd_input, /* For now, only convert UsdUVTexture and UsdPrimvarReader_float2 inputs. */ if (shader_id == usdtokens::UsdUVTexture) { - if (strcmp(dest_socket_name, "Normal") == 0) { + if (STREQ(dest_socket_name, "Normal")) { /* The normal texture input requires creating a normal map node. */ float locx = 0.0f; diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 7cb4c65f166..8138f38fcad 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -33,6 +33,7 @@ #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> @@ -275,7 +276,7 @@ void USDMeshReader::read_object_data(Main *bmain, const double motionSampleTime) bool USDMeshReader::valid() const { - return static_cast<bool>(mesh_prim_); + return bool(mesh_prim_); } bool USDMeshReader::topology_changed(const Mesh *existing_mesh, const double motionSampleTime) @@ -287,11 +288,13 @@ bool USDMeshReader::topology_changed(const Mesh *existing_mesh, const double mot mesh_prim_.GetFaceVertexCountsAttr().Get(&face_counts_, motionSampleTime); mesh_prim_.GetPointsAttr().Get(&positions_, motionSampleTime); + pxr::UsdGeomPrimvarsAPI primvarsAPI(mesh_prim_); + /* TODO(makowalski): Reading normals probably doesn't belong in this function, * as this is not required to determine if the topology has changed. */ /* If 'normals' and 'primvars:normals' are both specified, the latter has precedence. */ - pxr::UsdGeomPrimvar primvar = mesh_prim_.GetPrimvar(usdtokens::normalsPrimvar); + pxr::UsdGeomPrimvar primvar = primvarsAPI.GetPrimvar(usdtokens::normalsPrimvar); if (primvar.HasValue()) { primvar.ComputeFlattened(&normals_, motionSampleTime); normal_interpolation_ = primvar.GetInterpolation(); @@ -342,9 +345,9 @@ void USDMeshReader::read_mpolys(Mesh *mesh) void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bool load_uvs) { - unsigned int loop_index = 0; - unsigned int rev_loop_index = 0; - unsigned int uv_index = 0; + uint loop_index = 0; + uint rev_loop_index = 0; + uint uv_index = 0; const CustomData *ldata = &mesh->ldata; @@ -355,6 +358,8 @@ void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bo std::vector<UVSample> uv_primvars(ldata->totlayer); + pxr::UsdGeomPrimvarsAPI primvarsAPI(mesh_prim_); + if (has_uvs_) { for (int layer_idx = 0; layer_idx < ldata->totlayer; layer_idx++) { const CustomDataLayer *layer = &ldata->layers[layer_idx]; @@ -385,11 +390,11 @@ void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bo } /* Early out if mesh doesn't have primvar. */ - if (!mesh_prim_.HasPrimvar(uv_token)) { + if (!primvarsAPI.HasPrimvar(uv_token)) { continue; } - if (pxr::UsdGeomPrimvar uv_primvar = mesh_prim_.GetPrimvar(uv_token)) { + if (pxr::UsdGeomPrimvar uv_primvar = primvarsAPI.GetPrimvar(uv_token)) { uv_primvar.ComputeFlattened(&uv_primvars[layer_idx].uvs, motionSampleTime); uv_primvars[layer_idx].interpolation = uv_primvar.GetInterpolation(); } @@ -422,9 +427,9 @@ void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bo const UVSample &sample = uv_primvars[layer_idx]; - if (!(ELEM(sample.interpolation, - pxr::UsdGeomTokens->faceVarying, - pxr::UsdGeomTokens->vertex))) { + if (!ELEM(sample.interpolation, + pxr::UsdGeomTokens->faceVarying, + pxr::UsdGeomTokens->vertex)) { std::cerr << "WARNING: unexpected interpolation type " << sample.interpolation << " for uv " << layer->name << std::endl; continue; @@ -601,7 +606,7 @@ void USDMeshReader::process_normals_vertex_varying(Mesh *mesh) MutableSpan vert_normals{(float3 *)BKE_mesh_vertex_normals_for_write(mesh), mesh->totvert}; BLI_STATIC_ASSERT(sizeof(normals_[0]) == sizeof(float3), "Expected float3 normals size"); - vert_normals.copy_from({(float3 *)normals_.data(), static_cast<int64_t>(normals_.size())}); + vert_normals.copy_from({(float3 *)normals_.data(), int64_t(normals_.size())}); BKE_mesh_vertex_normals_clear_dirty(mesh); } @@ -804,8 +809,8 @@ void USDMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, const double mot std::map<pxr::SdfPath, int> mat_map; bke::MutableAttributeAccessor attributes = mesh->attributes_for_write(); - bke::SpanAttributeWriter<int> material_indices = - attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE); + bke::SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_span<int>( + "material_index", ATTR_DOMAIN_FACE); this->assign_facesets_to_material_indices(motionSampleTime, material_indices.span, &mat_map); material_indices.finish(); /* Build material name map if it's not built yet. */ @@ -835,12 +840,14 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, is_left_handed_ = true; } + pxr::UsdGeomPrimvarsAPI primvarsAPI(mesh_prim_); + std::vector<pxr::TfToken> uv_tokens; /* Currently we only handle UV primvars. */ if (read_flag & MOD_MESHSEQ_READ_UV) { - std::vector<pxr::UsdGeomPrimvar> primvars = mesh_prim_.GetPrimvars(); + std::vector<pxr::UsdGeomPrimvar> primvars = primvarsAPI.GetPrimvars(); for (pxr::UsdGeomPrimvar p : primvars) { @@ -865,7 +872,7 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, pxr::TfToken interp = p.GetInterpolation(); - if (!(ELEM(interp, pxr::UsdGeomTokens->faceVarying, pxr::UsdGeomTokens->vertex))) { + if (!ELEM(interp, pxr::UsdGeomTokens->faceVarying, pxr::UsdGeomTokens->vertex)) { continue; } @@ -914,7 +921,7 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, std::map<pxr::SdfPath, int> mat_map; bke::MutableAttributeAccessor attributes = active_mesh->attributes_for_write(); bke::SpanAttributeWriter<int> material_indices = - attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE); + attributes.lookup_or_add_for_write_span<int>("material_index", ATTR_DOMAIN_FACE); assign_facesets_to_material_indices(motionSampleTime, material_indices.span, &mat_map); material_indices.finish(); } diff --git a/source/blender/io/usd/intern/usd_reader_nurbs.cc b/source/blender/io/usd/intern/usd_reader_nurbs.cc index d0a5dc1c4b4..0a7058fb100 100644 --- a/source/blender/io/usd/intern/usd_reader_nurbs.cc +++ b/source/blender/io/usd/intern/usd_reader_nurbs.cc @@ -33,7 +33,7 @@ static bool set_knots(const pxr::VtDoubleArray &knots, float *&nu_knots) nu_knots = static_cast<float *>(MEM_callocN(num_knots * sizeof(float), __func__)); for (size_t i = 0; i < num_knots; i++) { - nu_knots[i] = (float)knots[i]; + nu_knots[i] = float(knots[i]); } return true; @@ -117,7 +117,7 @@ void USDNurbsReader::read_curve_sample(Curve *cu, const double motionSampleTime) nu->pntsv = 1; if (i < orders.size()) { - nu->orderu = static_cast<short>(orders[i]); + nu->orderu = short(orders[i]); } else { nu->orderu = 4; @@ -141,9 +141,9 @@ void USDNurbsReader::read_curve_sample(Curve *cu, const double motionSampleTime) BPoint *bp = nu->bp; for (int j = 0; j < nu->pntsu; j++, bp++, idx++) { - bp->vec[0] = (float)usdPoints[idx][0]; - bp->vec[1] = (float)usdPoints[idx][1]; - bp->vec[2] = (float)usdPoints[idx][2]; + bp->vec[0] = float(usdPoints[idx][0]); + bp->vec[1] = float(usdPoints[idx][1]); + bp->vec[2] = float(usdPoints[idx][2]); bp->vec[3] = weight; bp->f1 = SELECT; bp->weight = weight; diff --git a/source/blender/io/usd/intern/usd_reader_nurbs.h b/source/blender/io/usd/intern/usd_reader_nurbs.h index a5441aad3cf..aa3940dc540 100644 --- a/source/blender/io/usd/intern/usd_reader_nurbs.h +++ b/source/blender/io/usd/intern/usd_reader_nurbs.h @@ -27,7 +27,7 @@ class USDNurbsReader : public USDGeomReader { bool valid() const override { - return static_cast<bool>(curve_prim_); + return bool(curve_prim_); } void create_object(Main *bmain, double motionSampleTime) override; diff --git a/source/blender/io/usd/intern/usd_reader_volume.cc b/source/blender/io/usd/intern/usd_reader_volume.cc index 13044de5002..fc25dda53b9 100644 --- a/source/blender/io/usd/intern/usd_reader_volume.cc +++ b/source/blender/io/usd/intern/usd_reader_volume.cc @@ -65,10 +65,10 @@ void USDVolumeReader::read_object_data(Main *bmain, const double motionSampleTim filepathAttr.GetTimeSamples(&filePathTimes); if (!filePathTimes.empty()) { - int start = static_cast<int>(filePathTimes.front()); - int end = static_cast<int>(filePathTimes.back()); + int start = int(filePathTimes.front()); + int end = int(filePathTimes.back()); - volume->is_sequence = static_cast<char>(true); + volume->is_sequence = char(true); volume->frame_start = start; volume->frame_duration = (end - start) + 1; } diff --git a/source/blender/io/usd/intern/usd_reader_volume.h b/source/blender/io/usd/intern/usd_reader_volume.h index 350fae6ada0..923c3d140c9 100644 --- a/source/blender/io/usd/intern/usd_reader_volume.h +++ b/source/blender/io/usd/intern/usd_reader_volume.h @@ -23,7 +23,7 @@ class USDVolumeReader : public USDXformReader { bool valid() const override { - return static_cast<bool>(volume_); + return bool(volume_); } void create_object(Main *bmain, double motionSampleTime) override; diff --git a/source/blender/io/usd/intern/usd_writer_hair.cc b/source/blender/io/usd/intern/usd_writer_hair.cc index 478a9e26274..8ec1447b505 100644 --- a/source/blender/io/usd/intern/usd_writer_hair.cc +++ b/source/blender/io/usd/intern/usd_writer_hair.cc @@ -64,7 +64,7 @@ void USDHairWriter::do_write(HierarchyContext &context) } } -bool USDHairWriter::check_is_animated(const HierarchyContext &UNUSED(context)) const +bool USDHairWriter::check_is_animated(const HierarchyContext & /*context*/) const { return true; } diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 6862f3835cf..75abae79519 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -380,7 +380,7 @@ static void export_in_memory_texture(Image *ima, BKE_image_path_ensure_ext_from_imformat(file_name, &imageFormat); char export_path[FILE_MAX]; - BLI_path_join(export_path, FILE_MAX, export_dir.c_str(), file_name, nullptr); + BLI_path_join(export_path, FILE_MAX, export_dir.c_str(), file_name); if (!allow_overwrite && BLI_exists(export_path)) { return; @@ -455,7 +455,7 @@ static bNode *traverse_channel(bNodeSocket *input, const short target_type) static bNode *find_bsdf_node(Material *material) { LISTBASE_FOREACH (bNode *, node, &material->nodetree->nodes) { - if (node->type == SH_NODE_BSDF_PRINCIPLED || node->type == SH_NODE_BSDF_DIFFUSE) { + if (ELEM(node->type, SH_NODE_BSDF_PRINCIPLED, SH_NODE_BSDF_DIFFUSE)) { return node; } } @@ -576,7 +576,7 @@ static std::string get_tex_image_asset_path(bNode *node, BLI_split_file_part(path.c_str(), file_path, FILE_MAX); if (export_params.relative_paths) { - BLI_path_join(exp_path, FILE_MAX, ".", "textures", file_path, nullptr); + BLI_path_join(exp_path, FILE_MAX, ".", "textures", file_path); } else { /* Create absolute path in the textures directory. */ @@ -588,7 +588,7 @@ static std::string get_tex_image_asset_path(bNode *node, char dir_path[FILE_MAX]; BLI_split_dir_part(stage_path.c_str(), dir_path, FILE_MAX); - BLI_path_join(exp_path, FILE_MAX, dir_path, "textures", file_path, nullptr); + BLI_path_join(exp_path, FILE_MAX, dir_path, "textures", file_path); } BLI_str_replace_char(exp_path, '\\', '/'); return exp_path; @@ -645,7 +645,7 @@ static void copy_tiled_textures(Image *ima, BLI_split_file_part(src_tile_path, dest_filename, sizeof(dest_filename)); char dest_tile_path[FILE_MAX]; - BLI_path_join(dest_tile_path, FILE_MAX, dest_dir.c_str(), dest_filename, nullptr); + BLI_path_join(dest_tile_path, FILE_MAX, dest_dir.c_str(), dest_filename); if (!allow_overwrite && BLI_exists(dest_tile_path)) { continue; @@ -680,7 +680,7 @@ static void copy_single_file(Image *ima, const std::string &dest_dir, const bool BLI_split_file_part(source_path, file_name, FILE_MAX); char dest_path[FILE_MAX]; - BLI_path_join(dest_path, FILE_MAX, dest_dir.c_str(), file_name, nullptr); + BLI_path_join(dest_path, FILE_MAX, dest_dir.c_str(), file_name); if (!allow_overwrite && BLI_exists(dest_path)) { return; @@ -707,7 +707,7 @@ static void export_texture(bNode *node, const pxr::UsdStageRefPtr stage, const bool allow_overwrite) { - if (node->type != SH_NODE_TEX_IMAGE && node->type != SH_NODE_TEX_ENVIRONMENT) { + if (!ELEM(node->type, SH_NODE_TEX_IMAGE, SH_NODE_TEX_ENVIRONMENT)) { return; } @@ -726,7 +726,7 @@ static void export_texture(bNode *node, BLI_split_dir_part(stage_path.c_str(), usd_dir_path, FILE_MAX); char tex_dir_path[FILE_MAX]; - BLI_path_join(tex_dir_path, FILE_MAX, usd_dir_path, "textures", SEP_STR, nullptr); + BLI_path_join(tex_dir_path, FILE_MAX, usd_dir_path, "textures", SEP_STR); BLI_dir_create_recursive(tex_dir_path); diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index a39f74c6420..e7d79e888e4 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -4,6 +4,7 @@ #include "usd_hierarchy_iterator.h" #include <pxr/usd/usdGeom/mesh.h> +#include <pxr/usd/usdGeom/primvarsAPI.h> #include <pxr/usd/usdShade/material.h> #include <pxr/usd/usdShade/materialBindingAPI.h> @@ -107,6 +108,8 @@ void USDGenericMeshWriter::write_uv_maps(const Mesh *mesh, pxr::UsdGeomMesh usd_ { pxr::UsdTimeCode timecode = get_export_time_code(); + pxr::UsdGeomPrimvarsAPI primvarsAPI(usd_mesh.GetPrim()); + const CustomData *ldata = &mesh->ldata; for (int layer_idx = 0; layer_idx < ldata->totlayer; layer_idx++) { const CustomDataLayer *layer = &ldata->layers[layer_idx]; @@ -119,7 +122,7 @@ void USDGenericMeshWriter::write_uv_maps(const Mesh *mesh, pxr::UsdGeomMesh usd_ * for texture coordinates by naming the UV Map as such, without having to guess which UV Map * is the "standard" one. */ pxr::TfToken primvar_name(pxr::TfMakeValidIdentifier(layer->name)); - pxr::UsdGeomPrimvar uv_coords_primvar = usd_mesh.CreatePrimvar( + pxr::UsdGeomPrimvar uv_coords_primvar = primvarsAPI.CreatePrimvar( primvar_name, pxr::SdfValueTypeNames->TexCoord2fArray, pxr::UsdGeomTokens->faceVarying); MLoopUV *mloopuv = static_cast<MLoopUV *>(layer->data); @@ -283,25 +286,22 @@ static void get_loops_polys(const Mesh *mesh, USDMeshData &usd_mesh_data) static void get_edge_creases(const Mesh *mesh, USDMeshData &usd_mesh_data) { - const float factor = 1.0f / 255.0f; + const float *creases = static_cast<const float *>(CustomData_get_layer(&mesh->edata, CD_CREASE)); + if (!creases) { + return; + } const Span<MEdge> edges = mesh->edges(); - float sharpness; for (const int i : edges.index_range()) { - const MEdge &edge = edges[i]; - if (edge.crease == 0) { + const float crease = creases[i]; + if (crease == 0.0f) { continue; } - if (edge.crease == 255) { - sharpness = pxr::UsdGeomMesh::SHARPNESS_INFINITE; - } - else { - sharpness = static_cast<float>(edge.crease) * factor; - } + const float sharpness = crease >= 1.0f ? pxr::UsdGeomMesh::SHARPNESS_INFINITE : crease; - usd_mesh_data.crease_vertex_indices.push_back(edge.v1); - usd_mesh_data.crease_vertex_indices.push_back(edge.v2); + usd_mesh_data.crease_vertex_indices.push_back(edges[i].v1); + usd_mesh_data.crease_vertex_indices.push_back(edges[i].v2); usd_mesh_data.crease_lengths.push_back(2); usd_mesh_data.crease_sharpnesses.push_back(sharpness); } diff --git a/source/blender/io/usd/intern/usd_writer_volume.cc b/source/blender/io/usd/intern/usd_writer_volume.cc index 12db6d73901..c6a27c5f663 100644 --- a/source/blender/io/usd/intern/usd_writer_volume.cc +++ b/source/blender/io/usd/intern/usd_writer_volume.cc @@ -145,14 +145,14 @@ std::optional<std::string> USDVolumeWriter::construct_vdb_file_path(const Volume BLI_strncpy(vdb_file_name, volume->id.name + 2, FILE_MAXFILE); const pxr::UsdTimeCode timecode = get_export_time_code(); if (!timecode.IsDefault()) { - const int frame = (int)timecode.GetValue(); + const int frame = int(timecode.GetValue()); const int num_frame_digits = frame == 0 ? 1 : integer_digits_i(abs(frame)); BLI_path_frame(vdb_file_name, frame, num_frame_digits); } strcat(vdb_file_name, ".vdb"); char vdb_file_path[FILE_MAX]; - BLI_path_join(vdb_file_path, sizeof(vdb_file_path), vdb_directory_path, vdb_file_name, nullptr); + BLI_path_join(vdb_file_path, sizeof(vdb_file_path), vdb_directory_path, vdb_file_name); return vdb_file_path; } diff --git a/source/blender/io/usd/tests/usd_imaging_test.cc b/source/blender/io/usd/tests/usd_imaging_test.cc index 5cd3c042e59..80c232ad099 100644 --- a/source/blender/io/usd/tests/usd_imaging_test.cc +++ b/source/blender/io/usd/tests/usd_imaging_test.cc @@ -42,8 +42,8 @@ TEST_F(USDImagingTest, CapsuleAdapterTest) } pxr::UsdImagingCapsuleAdapter capsule_adapter; - pxr::VtValue points_value = pxr::UsdImagingCapsuleAdapter::GetMeshPoints( - capsule.GetPrim(), pxr::UsdTimeCode::Default()); + pxr::VtValue points_value = capsule_adapter.GetPoints(capsule.GetPrim(), + pxr::UsdTimeCode::Default()); if (!points_value.IsHolding<pxr::VtArray<pxr::GfVec3f>>()) { FAIL() << "Mesh points value holding unexpected type."; return; @@ -52,7 +52,8 @@ TEST_F(USDImagingTest, CapsuleAdapterTest) pxr::VtArray<pxr::GfVec3f> points = points_value.Get<pxr::VtArray<pxr::GfVec3f>>(); EXPECT_FALSE(points.empty()); - pxr::VtValue topology_value = pxr::UsdImagingCapsuleAdapter::GetMeshTopology(); + pxr::VtValue topology_value = capsule_adapter.GetTopology( + capsule.GetPrim(), pxr::SdfPath(), pxr::UsdTimeCode::Default()); if (!topology_value.IsHolding<pxr::HdMeshTopology>()) { FAIL() << "Mesh topology value holding unexpected type."; diff --git a/source/blender/io/usd/tests/usd_tests_common.cc b/source/blender/io/usd/tests/usd_tests_common.cc index 9f18a289433..ea4e704006d 100644 --- a/source/blender/io/usd/tests/usd_tests_common.cc +++ b/source/blender/io/usd/tests/usd_tests_common.cc @@ -29,7 +29,7 @@ std::string register_usd_plugins_for_tests() } const size_t path_len = BLI_path_join( - usd_datafiles_dir, FILE_MAX, release_dir.c_str(), "datafiles", "usd", nullptr); + usd_datafiles_dir, FILE_MAX, release_dir.c_str(), "datafiles", "usd"); /* #BLI_path_join removes trailing slashes, but the USD library requires one in order to * recognize the path as directory. */ |