diff options
author | makowalski <makowalski@nvidia.com> | 2021-03-11 08:19:11 +0300 |
---|---|---|
committer | makowalski <makowalski@nvidia.com> | 2021-03-11 08:19:11 +0300 |
commit | 3dcc54983689b020d03e907101c044215bb75dec (patch) | |
tree | 24516edd070237aa7578bff4906bbdb09adafa9b /source | |
parent | 0759e455413662d28278ed99cc25908830e72314 (diff) |
USD Import: naming convention fix.
To be consistent with the convention used in the USD exporter,
updated class member variables to consistently use snake case
and trailing underscores instead of the m_ prefix.
Diffstat (limited to 'source')
20 files changed, 317 insertions, 324 deletions
diff --git a/source/blender/io/usd/intern/usd_capi.cc b/source/blender/io/usd/intern/usd_capi.cc index 78ad13b9d88..ba0bc9bb886 100644 --- a/source/blender/io/usd/intern/usd_capi.cc +++ b/source/blender/io/usd/intern/usd_capi.cc @@ -163,7 +163,7 @@ static void set_instance_collection( static void create_proto_collections(Main *bmain, ViewLayer *view_layer, Collection *parent_collection, - const USDStageReader::ProtoReaderMap &proto_readers, + const ProtoReaderMap &proto_readers, const std::vector<USDPrimReader *> &readers) { Collection *all_protos_collection = create_collection(bmain, parent_collection, "prototypes"); diff --git a/source/blender/io/usd/intern/usd_reader_camera.cc b/source/blender/io/usd/intern/usd_reader_camera.cc index dc6a1082053..6c28763424f 100644 --- a/source/blender/io/usd/intern/usd_reader_camera.cc +++ b/source/blender/io/usd/intern/usd_reader_camera.cc @@ -50,17 +50,17 @@ namespace blender::io::usd { void USDCameraReader::create_object(Main *bmain, double motionSampleTime) { - Camera *bcam = static_cast<Camera *>(BKE_camera_add(bmain, m_name.c_str())); + Camera *bcam = static_cast<Camera *>(BKE_camera_add(bmain, name_.c_str())); - m_object = BKE_object_add_only_object(bmain, OB_CAMERA, m_name.c_str()); - m_object->data = bcam; + object_ = BKE_object_add_only_object(bmain, OB_CAMERA, name_.c_str()); + object_->data = bcam; } void USDCameraReader::read_object_data(Main *bmain, double motionSampleTime) { - Camera *bcam = (Camera *)m_object->data; + Camera *bcam = (Camera *)object_->data; - pxr::UsdGeomCamera cam_prim = pxr::UsdGeomCamera::Get(m_stage, m_prim.GetPath()); + pxr::UsdGeomCamera cam_prim = pxr::UsdGeomCamera::Get(stage_, prim_.GetPath()); pxr::VtValue val; cam_prim.GetFocalLengthAttr().Get(&val, motionSampleTime); diff --git a/source/blender/io/usd/intern/usd_reader_curve.cc b/source/blender/io/usd/intern/usd_reader_curve.cc index 6516870b41f..f2572021b7e 100644 --- a/source/blender/io/usd/intern/usd_reader_curve.cc +++ b/source/blender/io/usd/intern/usd_reader_curve.cc @@ -61,22 +61,22 @@ namespace blender::io::usd { void USDCurvesReader::create_object(Main *bmain, double motionSampleTime) { - m_curve = BKE_curve_add(bmain, m_name.c_str(), OB_CURVE); + curve_ = BKE_curve_add(bmain, name_.c_str(), OB_CURVE); - m_curve->flag |= CU_DEFORM_FILL | CU_3D; - m_curve->actvert = CU_ACT_NONE; - m_curve->resolu = 2; + curve_->flag |= CU_DEFORM_FILL | CU_3D; + curve_->actvert = CU_ACT_NONE; + curve_->resolu = 2; - m_object = BKE_object_add_only_object(bmain, OB_CURVE, m_name.c_str()); - m_object->data = m_curve; + object_ = BKE_object_add_only_object(bmain, OB_CURVE, name_.c_str()); + object_->data = curve_; } void USDCurvesReader::read_object_data(Main *bmain, double motionSampleTime) { - Curve *cu = (Curve *)m_object->data; + Curve *cu = (Curve *)object_->data; read_curve_sample(cu, motionSampleTime); - if (curve_prim.GetPointsAttr().ValueMightBeTimeVarying()) { + if (curve_prim_.GetPointsAttr().ValueMightBeTimeVarying()) { add_cache_modifier(); } @@ -85,11 +85,11 @@ void USDCurvesReader::read_object_data(Main *bmain, double motionSampleTime) void USDCurvesReader::read_curve_sample(Curve *cu, double motionSampleTime) { - curve_prim = pxr::UsdGeomBasisCurves::Get(m_stage, m_prim.GetPath()); + curve_prim_ = pxr::UsdGeomBasisCurves::Get(stage_, prim_.GetPath()); - pxr::UsdAttribute widthsAttr = curve_prim.GetWidthsAttr(); - pxr::UsdAttribute vertexAttr = curve_prim.GetCurveVertexCountsAttr(); - pxr::UsdAttribute pointsAttr = curve_prim.GetPointsAttr(); + pxr::UsdAttribute widthsAttr = curve_prim_.GetWidthsAttr(); + pxr::UsdAttribute vertexAttr = curve_prim_.GetCurveVertexCountsAttr(); + pxr::UsdAttribute pointsAttr = curve_prim_.GetPointsAttr(); pxr::VtIntArray usdCounts; @@ -102,30 +102,30 @@ void USDCurvesReader::read_curve_sample(Curve *cu, double motionSampleTime) pxr::VtFloatArray usdWidths; widthsAttr.Get(&usdWidths, motionSampleTime); - pxr::UsdAttribute basisAttr = curve_prim.GetBasisAttr(); + pxr::UsdAttribute basisAttr = curve_prim_.GetBasisAttr(); pxr::TfToken basis; basisAttr.Get(&basis, motionSampleTime); - pxr::UsdAttribute typeAttr = curve_prim.GetTypeAttr(); + pxr::UsdAttribute typeAttr = curve_prim_.GetTypeAttr(); pxr::TfToken type; typeAttr.Get(&type, motionSampleTime); - pxr::UsdAttribute wrapAttr = curve_prim.GetWrapAttr(); + pxr::UsdAttribute wrapAttr = curve_prim_.GetWrapAttr(); pxr::TfToken wrap; wrapAttr.Get(&wrap, motionSampleTime); pxr::VtVec3fArray usdNormals; - curve_prim.GetNormalsAttr().Get(&usdNormals, motionSampleTime); + curve_prim_.GetNormalsAttr().Get(&usdNormals, motionSampleTime); // If normals, extrude, else bevel // Perhaps to be replaced by Blender/USD Schema if (usdNormals.size() > 0) { // Set extrusion to 1.0f; - m_curve->ext1 = 1.0f; + curve_->ext1 = 1.0f; } else { // Set bevel depth to 1.0f; - m_curve->ext2 = 1.0f; + curve_->ext2 = 1.0f; } size_t idx = 0; @@ -179,7 +179,7 @@ void USDCurvesReader::read_curve_sample(Curve *cu, double motionSampleTime) bp->f1 = SELECT; bp->weight = weight; - float radius = m_curve->width; + float radius = curve_->width; if (idx < usdWidths.size()) radius = usdWidths[idx]; @@ -199,11 +199,11 @@ Mesh *USDCurvesReader::read_mesh(struct Mesh *existing_mesh, float vel_scale, const char **err_str) { - pxr::UsdGeomCurves curve_prim = pxr::UsdGeomCurves::Get(m_stage, m_prim.GetPath()); + pxr::UsdGeomCurves curve_prim_ = pxr::UsdGeomCurves::Get(stage_, prim_.GetPath()); - pxr::UsdAttribute widthsAttr = curve_prim.GetWidthsAttr(); - pxr::UsdAttribute vertexAttr = curve_prim.GetCurveVertexCountsAttr(); - pxr::UsdAttribute pointsAttr = curve_prim.GetPointsAttr(); + pxr::UsdAttribute widthsAttr = curve_prim_.GetWidthsAttr(); + pxr::UsdAttribute vertexAttr = curve_prim_.GetCurveVertexCountsAttr(); + pxr::UsdAttribute pointsAttr = curve_prim_.GetPointsAttr(); pxr::VtIntArray usdCounts; @@ -215,7 +215,7 @@ Mesh *USDCurvesReader::read_mesh(struct Mesh *existing_mesh, int vertex_idx = 0; int curve_idx; - Curve *curve = static_cast<Curve *>(m_object->data); + Curve *curve = static_cast<Curve *>(object_->data); const int curve_count = BLI_listbase_count(&curve->nurb); bool same_topology = curve_count == num_subcurves; @@ -263,7 +263,7 @@ Mesh *USDCurvesReader::read_mesh(struct Mesh *existing_mesh, } } - return BKE_mesh_new_nomain_from_curve(m_object); + return BKE_mesh_new_nomain_from_curve(object_); } } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_reader_curve.h b/source/blender/io/usd/intern/usd_reader_curve.h index c805e1b5188..a74562e9f5a 100644 --- a/source/blender/io/usd/intern/usd_reader_curve.h +++ b/source/blender/io/usd/intern/usd_reader_curve.h @@ -25,6 +25,9 @@ struct Curve; namespace blender::io::usd { class USDCurvesReader : public USDGeomReader { + protected: + pxr::UsdGeomBasisCurves curve_prim_; + Curve *curve_; public: USDCurvesReader(pxr::UsdStageRefPtr stage, @@ -45,10 +48,6 @@ class USDCurvesReader : public USDGeomReader { int read_flag, float vel_scale, const char **err_str) override; - - protected: - pxr::UsdGeomBasisCurves curve_prim; - Curve *m_curve; }; } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_reader_geom.cc b/source/blender/io/usd/intern/usd_reader_geom.cc index 8ea3e725391..ec131d4da95 100644 --- a/source/blender/io/usd/intern/usd_reader_geom.cc +++ b/source/blender/io/usd/intern/usd_reader_geom.cc @@ -91,21 +91,21 @@ Mesh *USDGeomReader::read_mesh(struct Mesh *existing_mesh, void USDGeomReader::add_cache_modifier() { ModifierData *md = BKE_modifier_new(eModifierType_MeshSequenceCache); - BLI_addtail(&m_object->modifiers, md); + BLI_addtail(&object_->modifiers, md); MeshSeqCacheModifierData *mcmd = reinterpret_cast<MeshSeqCacheModifierData *>(md); - mcmd->cache_file = m_settings->cache_file; + mcmd->cache_file = settings_->cache_file; id_us_plus(&mcmd->cache_file->id); - mcmd->read_flag = m_import_params.global_read_flag; + mcmd->read_flag = import_params_.global_read_flag; - BLI_strncpy(mcmd->object_path, m_prim.GetPath().GetString().c_str(), FILE_MAX); + BLI_strncpy(mcmd->object_path, prim_.GetPath().GetString().c_str(), FILE_MAX); } void USDGeomReader::add_subdiv_modifier() { ModifierData *md = BKE_modifier_new(eModifierType_Subsurf); - BLI_addtail(&m_object->modifiers, md); + BLI_addtail(&object_->modifiers, md); } } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_reader_instance.cc b/source/blender/io/usd/intern/usd_reader_instance.cc index 4aafd189492..23b9aba58b0 100644 --- a/source/blender/io/usd/intern/usd_reader_instance.cc +++ b/source/blender/io/usd/intern/usd_reader_instance.cc @@ -36,26 +36,26 @@ USDInstanceReader::USDInstanceReader(pxr::UsdStageRefPtr stage, bool USDInstanceReader::valid() const { - return m_prim.IsValid() && m_prim.IsInstance(); + return prim_.IsValid() && prim_.IsInstance(); } void USDInstanceReader::create_object(Main *bmain, double motionSampleTime) { - this->m_object = BKE_object_add_only_object(bmain, OB_EMPTY, m_name.c_str()); - this->m_object->data = nullptr; - this->m_object->transflag |= OB_DUPLICOLLECTION; + this->object_ = BKE_object_add_only_object(bmain, OB_EMPTY, name_.c_str()); + this->object_->data = nullptr; + this->object_->transflag |= OB_DUPLICOLLECTION; } void USDInstanceReader::set_instance_collection(Collection *coll) { - if (this->m_object) { - this->m_object->instance_collection = coll; + if (this->object_) { + this->object_->instance_collection = coll; } } pxr::SdfPath USDInstanceReader::proto_path() const { - if (pxr::UsdPrim master = m_prim.GetMaster()) { + if (pxr::UsdPrim master = prim_.GetMaster()) { return master.GetPath(); } diff --git a/source/blender/io/usd/intern/usd_reader_light.cc b/source/blender/io/usd/intern/usd_reader_light.cc index 8a69849a7fe..91bee43813f 100644 --- a/source/blender/io/usd/intern/usd_reader_light.cc +++ b/source/blender/io/usd/intern/usd_reader_light.cc @@ -60,38 +60,38 @@ namespace blender::io::usd { void USDLightReader::create_object(Main *bmain, double motionSampleTime) { - Light *blight = static_cast<Light *>(BKE_light_add(bmain, m_name.c_str())); + Light *blight = static_cast<Light *>(BKE_light_add(bmain, name_.c_str())); - m_object = BKE_object_add_only_object(bmain, OB_LAMP, m_name.c_str()); - m_object->data = blight; + object_ = BKE_object_add_only_object(bmain, OB_LAMP, name_.c_str()); + object_->data = blight; } void USDLightReader::read_object_data(Main *bmain, double motionSampleTime) { - Light *blight = (Light *)m_object->data; + Light *blight = (Light *)object_->data; - pxr::UsdLuxLight light_prim = pxr::UsdLuxLight::Get(m_stage, m_prim.GetPath()); + pxr::UsdLuxLight light_prim = pxr::UsdLuxLight::Get(stage_, prim_.GetPath()); pxr::UsdLuxShapingAPI shapingAPI(light_prim); // Set light type - if (m_prim.IsA<pxr::UsdLuxDiskLight>()) { + if (prim_.IsA<pxr::UsdLuxDiskLight>()) { blight->type = LA_AREA; blight->area_shape = LA_AREA_DISK; // Ellipse lights are not currently supported } - else if (m_prim.IsA<pxr::UsdLuxRectLight>()) { + else if (prim_.IsA<pxr::UsdLuxRectLight>()) { blight->type = LA_AREA; blight->area_shape = LA_AREA_RECT; } - else if (m_prim.IsA<pxr::UsdLuxSphereLight>()) { + else if (prim_.IsA<pxr::UsdLuxSphereLight>()) { blight->type = LA_LOCAL; if (shapingAPI.GetShapingConeAngleAttr().IsAuthored()) { blight->type = LA_SPOT; } } - else if (m_prim.IsA<pxr::UsdLuxDistantLight>()) { + else if (prim_.IsA<pxr::UsdLuxDistantLight>()) { blight->type = LA_SUN; } @@ -100,7 +100,7 @@ void USDLightReader::read_object_data(Main *bmain, double motionSampleTime) pxr::VtValue intensity; light_prim.GetIntensityAttr().Get(&intensity, motionSampleTime); - blight->energy = intensity.Get<float>() * this->m_import_params.light_intensity_scale; + blight->energy = intensity.Get<float>() * this->import_params_.light_intensity_scale; // TODO: Not currently supported // pxr::VtValue exposure; @@ -132,8 +132,8 @@ void USDLightReader::read_object_data(Main *bmain, double motionSampleTime) switch (blight->type) { case LA_AREA: - if (blight->area_shape == LA_AREA_RECT && m_prim.IsA<pxr::UsdLuxRectLight>()) { - pxr::UsdLuxRectLight rect_light = pxr::UsdLuxRectLight::Get(m_stage, m_prim.GetPath()); + if (blight->area_shape == LA_AREA_RECT && prim_.IsA<pxr::UsdLuxRectLight>()) { + pxr::UsdLuxRectLight rect_light = pxr::UsdLuxRectLight::Get(stage_, prim_.GetPath()); pxr::VtValue width; rect_light.GetWidthAttr().Get(&width, motionSampleTime); @@ -145,8 +145,8 @@ void USDLightReader::read_object_data(Main *bmain, double motionSampleTime) blight->area_sizey = height.Get<float>(); } - if (blight->area_shape == LA_AREA_DISK && m_prim.IsA<pxr::UsdLuxDiskLight>()) { - pxr::UsdLuxDiskLight disk_light = pxr::UsdLuxDiskLight::Get(m_stage, m_prim.GetPath()); + if (blight->area_shape == LA_AREA_DISK && prim_.IsA<pxr::UsdLuxDiskLight>()) { + pxr::UsdLuxDiskLight disk_light = pxr::UsdLuxDiskLight::Get(stage_, prim_.GetPath()); pxr::VtValue radius; disk_light.GetRadiusAttr().Get(&radius, motionSampleTime); @@ -155,9 +155,8 @@ void USDLightReader::read_object_data(Main *bmain, double motionSampleTime) } break; case LA_LOCAL: - if (m_prim.IsA<pxr::UsdLuxSphereLight>()) { - pxr::UsdLuxSphereLight sphere_light = pxr::UsdLuxSphereLight::Get(m_stage, - m_prim.GetPath()); + if (prim_.IsA<pxr::UsdLuxSphereLight>()) { + pxr::UsdLuxSphereLight sphere_light = pxr::UsdLuxSphereLight::Get(stage_, prim_.GetPath()); pxr::VtValue radius; sphere_light.GetRadiusAttr().Get(&radius, motionSampleTime); @@ -166,9 +165,8 @@ void USDLightReader::read_object_data(Main *bmain, double motionSampleTime) } break; case LA_SPOT: - if (m_prim.IsA<pxr::UsdLuxSphereLight>()) { - pxr::UsdLuxSphereLight sphere_light = pxr::UsdLuxSphereLight::Get(m_stage, - m_prim.GetPath()); + if (prim_.IsA<pxr::UsdLuxSphereLight>()) { + pxr::UsdLuxSphereLight sphere_light = pxr::UsdLuxSphereLight::Get(stage_, prim_.GetPath()); pxr::VtValue radius; sphere_light.GetRadiusAttr().Get(&radius, motionSampleTime); @@ -185,9 +183,9 @@ void USDLightReader::read_object_data(Main *bmain, double motionSampleTime) } break; case LA_SUN: - if (m_prim.IsA<pxr::UsdLuxDistantLight>()) { - pxr::UsdLuxDistantLight distant_light = pxr::UsdLuxDistantLight::Get(m_stage, - m_prim.GetPath()); + if (prim_.IsA<pxr::UsdLuxDistantLight>()) { + pxr::UsdLuxDistantLight distant_light = pxr::UsdLuxDistantLight::Get(stage_, + prim_.GetPath()); pxr::VtValue angle; distant_light.GetAngleAttr().Get(&angle, motionSampleTime); diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index acac2f49df2..0ad73d9feac 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -189,7 +189,7 @@ void compute_node_loc( } // namespace USDMaterialReader::USDMaterialReader(const USDImportParams ¶ms, Main *bmain) - : m_params(params), bmain_(bmain) + : params_(params), bmain_(bmain) { } @@ -205,7 +205,7 @@ Material *USDMaterialReader::add_material(const pxr::UsdShadeMaterial &usd_mater Material *mtl = BKE_material_add(bmain_, mtl_name.c_str()); /* Optionally, create shader nodes to represent a UsdPreviewSurface. */ - if (m_params.import_usd_preview) { + if (params_.import_usd_preview) { import_usd_preview(mtl, usd_material); } @@ -324,7 +324,7 @@ void USDMaterialReader::import_usd_preview(Material *mtl, // Optionally, set the material blend mode. - if (m_params.set_material_blend) { + if (params_.set_material_blend) { float opacity_threshold = 0.0f; if (needs_blend(usd_shader, opacity_threshold)) { if (opacity_threshold > 0.0f) { diff --git a/source/blender/io/usd/intern/usd_reader_material.h b/source/blender/io/usd/intern/usd_reader_material.h index 2ac87f1e482..ec55173aaae 100644 --- a/source/blender/io/usd/intern/usd_reader_material.h +++ b/source/blender/io/usd/intern/usd_reader_material.h @@ -69,7 +69,7 @@ struct NodePlacementContext { class USDMaterialReader { protected: - USDImportParams m_params; + USDImportParams params_; Main *bmain_; diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 4f207d49640..26b8de07a65 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -190,50 +190,50 @@ USDMeshReader::USDMeshReader(pxr::UsdStageRefPtr stage, const USDImportParams &import_params, ImportSettings &settings) : USDGeomReader(stage, object, import_params, settings), - m_isLeftHanded(false), - m_lastNumPositions(-1), - m_hasUVs(false), - m_isTimeVarying(false), - m_isInitialLoad(false) + is_left_handed_(false), + last_num_positions_(-1), + has_uvs_(false), + is_time_varying_(false), + is_initial_load_(false) { } void USDMeshReader::create_object(Main *bmain, double motionSampleTime) { - Mesh *mesh = BKE_mesh_add(bmain, m_name.c_str()); + Mesh *mesh = BKE_mesh_add(bmain, name_.c_str()); - m_object = BKE_object_add_only_object(bmain, OB_MESH, m_name.c_str()); - m_object->data = mesh; + object_ = BKE_object_add_only_object(bmain, OB_MESH, name_.c_str()); + object_->data = mesh; } void USDMeshReader::read_object_data(Main *bmain, double motionSampleTime) { - Mesh *mesh = (Mesh *)m_object->data; + Mesh *mesh = (Mesh *)object_->data; - m_isInitialLoad = true; + is_initial_load_ = true; Mesh *read_mesh = this->read_mesh( - mesh, motionSampleTime, m_import_params.global_read_flag, 1.0f, NULL); - m_isInitialLoad = false; + mesh, motionSampleTime, import_params_.global_read_flag, 1.0f, NULL); + is_initial_load_ = false; if (read_mesh != mesh) { /* XXX fixme after 2.80; mesh->flag isn't copied by BKE_mesh_nomain_to_mesh() */ /* read_mesh can be freed by BKE_mesh_nomain_to_mesh(), so get the flag before that happens. */ short autosmooth = (read_mesh->flag & ME_AUTOSMOOTH); - BKE_mesh_nomain_to_mesh(read_mesh, mesh, m_object, &CD_MASK_MESH, true); + BKE_mesh_nomain_to_mesh(read_mesh, mesh, object_, &CD_MASK_MESH, true); mesh->flag |= autosmooth; } readFaceSetsSample(bmain, mesh, motionSampleTime); - if (mesh_prim.GetPointsAttr().ValueMightBeTimeVarying()) - m_isTimeVarying = true; + if (mesh_prim_.GetPointsAttr().ValueMightBeTimeVarying()) + is_time_varying_ = true; - if (m_isTimeVarying) { + if (is_time_varying_) { add_cache_modifier(); } - if (m_import_params.import_subdiv) { + if (import_params_.import_subdiv) { pxr::TfToken subdivScheme; - mesh_prim.GetSubdivisionSchemeAttr().Get(&subdivScheme, motionSampleTime); + mesh_prim_.GetSubdivisionSchemeAttr().Get(&subdivScheme, motionSampleTime); if (subdivScheme == pxr::UsdGeomTokens->catmullClark) { add_subdiv_modifier(); @@ -245,46 +245,46 @@ void USDMeshReader::read_object_data(Main *bmain, double motionSampleTime) bool USDMeshReader::valid() const { - return mesh_prim.GetPrim().IsValid(); + return mesh_prim_.GetPrim().IsValid(); } bool USDMeshReader::topology_changed(Mesh *existing_mesh, double motionSampleTime) { - pxr::UsdAttribute faceVertCountsAttr = mesh_prim.GetFaceVertexCountsAttr(); - pxr::UsdAttribute faceVertIndicesAttr = mesh_prim.GetFaceVertexIndicesAttr(); - pxr::UsdAttribute pointsAttr = mesh_prim.GetPointsAttr(); - pxr::UsdAttribute normalsAttr = mesh_prim.GetNormalsAttr(); + pxr::UsdAttribute faceVertCountsAttr = mesh_prim_.GetFaceVertexCountsAttr(); + pxr::UsdAttribute faceVertIndicesAttr = mesh_prim_.GetFaceVertexIndicesAttr(); + pxr::UsdAttribute pointsAttr = mesh_prim_.GetPointsAttr(); + pxr::UsdAttribute normalsAttr = mesh_prim_.GetNormalsAttr(); - faceVertIndicesAttr.Get(&m_face_indices, motionSampleTime); - faceVertCountsAttr.Get(&m_face_counts, motionSampleTime); - pointsAttr.Get(&m_positions, motionSampleTime); + faceVertIndicesAttr.Get(&face_indices_, motionSampleTime); + faceVertCountsAttr.Get(&face_counts_, motionSampleTime); + pointsAttr.Get(&positions_, motionSampleTime); // If 'normals' and 'primvars:normals' are both specified, the latter has precedence. - pxr::UsdGeomPrimvar primvar = mesh_prim.GetPrimvar(usdtokens::normalsPrimvar); + pxr::UsdGeomPrimvar primvar = mesh_prim_.GetPrimvar(usdtokens::normalsPrimvar); if (primvar.HasValue()) { - primvar.ComputeFlattened(&m_normals, motionSampleTime); - m_normalInterpolation = primvar.GetInterpolation(); + primvar.ComputeFlattened(&normals_, motionSampleTime); + normal_interpolation_ = primvar.GetInterpolation(); } else { - mesh_prim.GetNormalsAttr().Get(&m_normals, motionSampleTime); - m_normalInterpolation = mesh_prim.GetNormalsInterpolation(); + mesh_prim_.GetNormalsAttr().Get(&normals_, motionSampleTime); + normal_interpolation_ = mesh_prim_.GetNormalsInterpolation(); } - if (m_lastNumPositions != m_positions.size()) { - m_lastNumPositions = m_positions.size(); + if (last_num_positions_ != positions_.size()) { + last_num_positions_ = positions_.size(); return true; } return false; } -void USDMeshReader::read_mpolys(Mesh *mesh, pxr::UsdGeomMesh mesh_prim, double motionSampleTime) +void USDMeshReader::read_mpolys(Mesh *mesh, pxr::UsdGeomMesh mesh_prim_, double motionSampleTime) { MPoly *mpolys = mesh->mpoly; MLoop *mloops = mesh->mloop; - pxr::UsdAttribute faceVertCountsAttr = mesh_prim.GetFaceVertexCountsAttr(); - pxr::UsdAttribute faceVertIndicesAttr = mesh_prim.GetFaceVertexIndicesAttr(); + pxr::UsdAttribute faceVertCountsAttr = mesh_prim_.GetFaceVertexCountsAttr(); + pxr::UsdAttribute faceVertIndicesAttr = mesh_prim_.GetFaceVertexIndicesAttr(); pxr::VtIntArray face_counts; faceVertCountsAttr.Get(&face_counts, motionSampleTime); @@ -310,7 +310,7 @@ void USDMeshReader::read_mpolys(Mesh *mesh, pxr::UsdGeomMesh mesh_prim, double m for (int f = 0; f < face_size; f++, loop_index++, rev_loop_index--) { MLoop &loop = mloops[loop_index]; - if (m_isLeftHanded) + if (is_left_handed_) loop.v = face_indices[rev_loop_index]; else loop.v = face_indices[loop_index]; @@ -321,7 +321,7 @@ void USDMeshReader::read_mpolys(Mesh *mesh, pxr::UsdGeomMesh mesh_prim, double m } void USDMeshReader::read_uvs(Mesh *mesh, - pxr::UsdGeomMesh mesh_prim, + pxr::UsdGeomMesh mesh_prim_, double motionSampleTime, bool load_uvs) { @@ -339,7 +339,7 @@ void USDMeshReader::read_uvs(Mesh *mesh, std::vector<UVSample> uv_primvars(ldata->totlayer); - if (m_hasUVs) { + if (has_uvs_) { for (int layer_idx = 0; layer_idx < ldata->totlayer; layer_idx++) { const CustomDataLayer *layer = &ldata->layers[layer_idx]; std::string layer_name = std::string(layer->name); @@ -350,29 +350,29 @@ void USDMeshReader::read_uvs(Mesh *mesh, pxr::TfToken uv_token; // If first time seeing uv token, store in map of <layer->uid, TfToken> - if (uv_token_map.find(layer_name) == uv_token_map.end()) { + if (uv_token_map_.find(layer_name) == uv_token_map_.end()) { uv_token = pxr::TfToken(layer_name); - uv_token_map.insert(std::make_pair(layer_name, uv_token)); + uv_token_map_.insert(std::make_pair(layer_name, uv_token)); } else - uv_token = uv_token_map.at(layer_name); + uv_token = uv_token_map_.at(layer_name); // Early out if no token found, this should never happen if (uv_token.IsEmpty()) { continue; } // Early out if not first load and uvs arent animated - if (!load_uvs && primvar_varying_map.find(uv_token) != primvar_varying_map.end() && - !primvar_varying_map.at(uv_token)) { + if (!load_uvs && primvar_varying_map_.find(uv_token) != primvar_varying_map_.end() && + !primvar_varying_map_.at(uv_token)) { continue; } // Early out if mesh doesn't have primvar - if (!mesh_prim.HasPrimvar(uv_token)) { + if (!mesh_prim_.HasPrimvar(uv_token)) { continue; } - if (pxr::UsdGeomPrimvar uv_primvar = mesh_prim.GetPrimvar(uv_token)) { + if (pxr::UsdGeomPrimvar uv_primvar = mesh_prim_.GetPrimvar(uv_token)) { uv_primvar.Get<pxr::VtVec2fArray>(&uv_primvars[layer_idx].uvs, motionSampleTime); uv_primvar.GetIndices(&uv_primvars[layer_idx].indices, motionSampleTime); uv_primvars[layer_idx].interpolation = uv_primvar.GetInterpolation(); @@ -380,8 +380,8 @@ void USDMeshReader::read_uvs(Mesh *mesh, } } - for (int i = 0; i < m_face_counts.size(); i++) { - const int face_size = m_face_counts[i]; + for (int i = 0; i < face_counts_.size(); i++) { + const int face_size = face_counts_[i]; rev_loop_index = loop_index + (face_size - 1); @@ -418,7 +418,7 @@ void USDMeshReader::read_uvs(Mesh *mesh, } MLoopUV *mloopuv = static_cast<MLoopUV *>(layer->data); - if (m_isLeftHanded) + if (is_left_handed_) uv_index = rev_loop_index; else uv_index = loop_index; @@ -431,11 +431,11 @@ void USDMeshReader::read_uvs(Mesh *mesh, } void USDMeshReader::read_attributes(Mesh *mesh, - pxr::UsdGeomMesh mesh_prim, + pxr::UsdGeomMesh mesh_prim_, double motionSampleTime) { CustomData *cd = &mesh->vdata; - std::vector<pxr::UsdGeomPrimvar> primvars = mesh_prim.GetPrimvars(); + std::vector<pxr::UsdGeomPrimvar> primvars = mesh_prim_.GetPrimvars(); for (pxr::UsdGeomPrimvar p : primvars) { int cd_type = 0; @@ -446,8 +446,8 @@ void USDMeshReader::read_attributes(Mesh *mesh, if (!p.HasAuthoredValue()) continue; - if (!m_isInitialLoad && - primvar_varying_map.find(p.GetPrimvarName()) == primvar_varying_map.end()) + if (!is_initial_load_ && + primvar_varying_map_.find(p.GetPrimvarName()) == primvar_varying_map_.end()) continue; const char *name = p.GetPrimvarName().GetString().c_str(); @@ -511,14 +511,14 @@ void USDMeshReader::read_attributes(Mesh *mesh, } void USDMeshReader::read_vels(Mesh *mesh, - pxr::UsdGeomMesh mesh_prim, + pxr::UsdGeomMesh mesh_prim_, float vel_scale, double motionSampleTime) { pxr::VtVec3fArray velocities; - pxr::UsdAttribute vel_attr = mesh_prim.GetVelocitiesAttr(); + pxr::UsdAttribute vel_attr = mesh_prim_.GetVelocitiesAttr(); - if (!m_isInitialLoad && !vel_attr.ValueMightBeTimeVarying()) + if (!is_initial_load_ && !vel_attr.ValueMightBeTimeVarying()) return; vel_attr.Get<pxr::VtVec3fArray>(&velocities, motionSampleTime); @@ -539,14 +539,14 @@ void USDMeshReader::read_vels(Mesh *mesh, } void USDMeshReader::read_colors(Mesh *mesh, - const pxr::UsdGeomMesh &mesh_prim, + const pxr::UsdGeomMesh &mesh_prim_, double motionSampleTime) { - if (!(mesh && mesh_prim && mesh->totloop > 0)) { + if (!(mesh && mesh_prim_ && mesh->totloop > 0)) { return; } - pxr::UsdGeomPrimvar color_primvar = mesh_prim.GetDisplayColorPrimvar(); + pxr::UsdGeomPrimvar color_primvar = mesh_prim_.GetDisplayColorPrimvar(); if (!color_primvar.HasValue()) { return; @@ -598,7 +598,7 @@ void USDMeshReader::read_colors(Mesh *mesh, } else if (interp == pxr::UsdGeomTokens->faceVarying) { usd_index = poly->loopstart; - if (m_isLeftHanded) { + if (is_left_handed_) { usd_index += poly->totloop - 1 - j; } else { @@ -624,26 +624,26 @@ void USDMeshReader::read_colors(Mesh *mesh, void USDMeshReader::process_normals_vertex_varying(Mesh *mesh) { - if (m_normals.empty()) { + if (normals_.empty()) { BKE_mesh_calc_normals(mesh); return; } - for (int i = 0; i < m_normals.size(); i++) { + for (int i = 0; i < normals_.size(); i++) { MVert &mvert = mesh->mvert[i]; - normal_float_to_short_v3(mvert.no, m_normals[i].data()); + normal_float_to_short_v3(mvert.no, normals_[i].data()); } } void USDMeshReader::process_normals_face_varying(Mesh *mesh) { - if (m_normals.empty()) { + if (normals_.empty()) { BKE_mesh_calc_normals(mesh); return; } // Check for normals count mismatches to prevent crashes. - if (m_normals.size() != mesh->totloop) { + if (normals_.size() != mesh->totloop) { std::cerr << "WARNING: loop normal count mismatch for mesh " << mesh->id.name << std::endl; BKE_mesh_calc_normals(mesh); return; @@ -651,7 +651,7 @@ void USDMeshReader::process_normals_face_varying(Mesh *mesh) mesh->flag |= ME_AUTOSMOOTH; - long int loop_count = m_normals.size(); + long int loop_count = normals_.size(); float(*lnors)[3] = static_cast<float(*)[3]>( MEM_malloc_arrayN(loop_count, sizeof(float[3]), "USD::FaceNormals")); @@ -663,16 +663,16 @@ void USDMeshReader::process_normals_face_varying(Mesh *mesh) int blender_index = mpoly->loopstart + j; int usd_index = mpoly->loopstart; - if (m_isLeftHanded) { + if (is_left_handed_) { usd_index += mpoly->totloop - 1 - j; } else { usd_index += j; } - lnors[blender_index][0] = m_normals[usd_index][0]; - lnors[blender_index][1] = m_normals[usd_index][1]; - lnors[blender_index][2] = m_normals[usd_index][2]; + lnors[blender_index][0] = normals_[usd_index][0]; + lnors[blender_index][1] = normals_[usd_index][1]; + lnors[blender_index][2] = normals_[usd_index][2]; } } BKE_mesh_set_custom_normals(mesh, lnors); @@ -683,13 +683,13 @@ void USDMeshReader::process_normals_face_varying(Mesh *mesh) // Set USD uniform (per-face) normals as Blender loop normals. void USDMeshReader::process_normals_uniform(Mesh *mesh) { - if (m_normals.empty()) { + if (normals_.empty()) { BKE_mesh_calc_normals(mesh); return; } // Check for normals count mismatches to prevent crashes. - if (m_normals.size() != mesh->totpoly) { + if (normals_.size() != mesh->totpoly) { std::cerr << "WARNING: uniform normal count mismatch for mesh " << mesh->id.name << std::endl; BKE_mesh_calc_normals(mesh); return; @@ -704,9 +704,9 @@ void USDMeshReader::process_normals_uniform(Mesh *mesh) for (int j = 0; j < mpoly->totloop; j++) { int loop_index = mpoly->loopstart + j; - lnors[loop_index][0] = m_normals[i][0]; - lnors[loop_index][1] = m_normals[i][1]; - lnors[loop_index][2] = m_normals[i][2]; + lnors[loop_index][0] = normals_[i][0]; + lnors[loop_index][1] = normals_[i][1]; + lnors[loop_index][2] = normals_[i][2]; } } @@ -719,34 +719,34 @@ void USDMeshReader::process_normals_uniform(Mesh *mesh) void USDMeshReader::read_mesh_sample(const std::string &iobject_full_name, ImportSettings *settings, Mesh *mesh, - const pxr::UsdGeomMesh &mesh_prim, + const pxr::UsdGeomMesh &mesh_prim_, double motionSampleTime, bool new_mesh) { - pxr::UsdAttribute normalsAttr = mesh_prim.GetNormalsAttr(); - std::vector<pxr::UsdGeomPrimvar> primvars = mesh_prim.GetPrimvars(); - pxr::UsdAttribute subdivSchemeAttr = mesh_prim.GetSubdivisionSchemeAttr(); + pxr::UsdAttribute normalsAttr = mesh_prim_.GetNormalsAttr(); + std::vector<pxr::UsdGeomPrimvar> primvars = mesh_prim_.GetPrimvars(); + pxr::UsdAttribute subdivSchemeAttr = mesh_prim_.GetSubdivisionSchemeAttr(); // Note that for new meshes we always want to read verts and polys, // regradless of the value of the read_flag, to avoid a crash downstream // in code that expect this data to be there. if (new_mesh || (settings->read_flag & MOD_MESHSEQ_READ_VERT) != 0) { - for (int i = 0; i < m_positions.size(); i++) { + for (int i = 0; i < positions_.size(); i++) { MVert &mvert = mesh->mvert[i]; - mvert.co[0] = m_positions[i][0]; - mvert.co[1] = m_positions[i][1]; - mvert.co[2] = m_positions[i][2]; + mvert.co[0] = positions_[i][0]; + mvert.co[1] = positions_[i][1]; + mvert.co[2] = positions_[i][2]; } } if (new_mesh || (settings->read_flag & MOD_MESHSEQ_READ_POLY) != 0) { - read_mpolys(mesh, mesh_prim, motionSampleTime); - if (m_normalInterpolation == pxr::UsdGeomTokens->faceVarying) { + read_mpolys(mesh, mesh_prim_, motionSampleTime); + if (normal_interpolation_ == pxr::UsdGeomTokens->faceVarying) { process_normals_face_varying(mesh); } - else if (m_normalInterpolation == pxr::UsdGeomTokens->uniform) { + else if (normal_interpolation_ == pxr::UsdGeomTokens->uniform) { process_normals_uniform(mesh); } else { @@ -760,24 +760,24 @@ void USDMeshReader::read_mesh_sample(const std::string &iobject_full_name, // and we invoke BKE_mesh_calc_normals(mesh), which requires // edges to be defined. if ((settings->read_flag & MOD_MESHSEQ_READ_VERT) != 0 && - m_normalInterpolation == pxr::UsdGeomTokens->vertex) { + normal_interpolation_ == pxr::UsdGeomTokens->vertex) { process_normals_vertex_varying(mesh); } if ((settings->read_flag & MOD_MESHSEQ_READ_UV) != 0) { - read_uvs(mesh, mesh_prim, motionSampleTime, new_mesh); + read_uvs(mesh, mesh_prim_, motionSampleTime, new_mesh); } if ((settings->read_flag & MOD_MESHSEQ_READ_ATTR) != 0) { - read_attributes(mesh, mesh_prim, motionSampleTime); + read_attributes(mesh, mesh_prim_, motionSampleTime); } if ((settings->read_flag & MOD_MESHSEQ_READ_VELS) != 0) { - read_vels(mesh, mesh_prim, settings->vel_scale, motionSampleTime); + read_vels(mesh, mesh_prim_, settings->vel_scale, motionSampleTime); } if ((settings->read_flag & MOD_MESHSEQ_READ_COLOR) != 0) { - read_colors(mesh, mesh_prim, motionSampleTime); + read_colors(mesh, mesh_prim_, motionSampleTime); } } @@ -786,7 +786,7 @@ void USDMeshReader::assign_facesets_to_mpoly(double motionSampleTime, int totpoly, std::map<pxr::SdfPath, int> &r_mat_map) { - pxr::UsdShadeMaterialBindingAPI api = pxr::UsdShadeMaterialBindingAPI(m_prim); + pxr::UsdShadeMaterialBindingAPI api = pxr::UsdShadeMaterialBindingAPI(prim_); std::vector<pxr::UsdGeomSubset> subsets = api.GetMaterialBindSubsets(); int current_mat = 0; @@ -827,13 +827,13 @@ void USDMeshReader::assign_facesets_to_mpoly(double motionSampleTime, void USDMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, const double motionSampleTime) { - if (!m_import_params.import_materials) { + if (!import_params_.import_materials) { return; } std::map<pxr::SdfPath, int> mat_map; assign_facesets_to_mpoly(motionSampleTime, mesh->mpoly, mesh->totpoly, mat_map); - utils::assign_materials(bmain, m_object, mat_map, this->m_import_params, this->m_stage); + utils::assign_materials(bmain, object_, mat_map, this->import_params_, this->stage_); } Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, @@ -842,21 +842,21 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, float vel_scale, const char **err_str) { - mesh_prim = pxr::UsdGeomMesh::Get(m_stage, m_prim.GetPath()); + mesh_prim_ = pxr::UsdGeomMesh::Get(stage_, prim_.GetPath()); - mesh_prim.GetOrientationAttr().Get(&m_orientation); - if (m_orientation == pxr::UsdGeomTokens->leftHanded) - m_isLeftHanded = true; + mesh_prim_.GetOrientationAttr().Get(&orientation_); + if (orientation_ == pxr::UsdGeomTokens->leftHanded) + is_left_handed_ = true; std::vector<pxr::TfToken> uv_tokens; - std::vector<pxr::UsdGeomPrimvar> primvars = mesh_prim.GetPrimvars(); + std::vector<pxr::UsdGeomPrimvar> primvars = mesh_prim_.GetPrimvars(); for (pxr::UsdGeomPrimvar p : primvars) { - if (primvar_varying_map.find(p.GetPrimvarName()) == primvar_varying_map.end()) { - primvar_varying_map.insert(std::make_pair(p.GetPrimvarName(), p.ValueMightBeTimeVarying())); + if (primvar_varying_map_.find(p.GetPrimvarName()) == primvar_varying_map_.end()) { + primvar_varying_map_.insert(std::make_pair(p.GetPrimvarName(), p.ValueMightBeTimeVarying())); if (p.ValueMightBeTimeVarying()) - m_isTimeVarying = true; + is_time_varying_ = true; } // Assume all uvs are stored in one of these primvar types... @@ -864,7 +864,7 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, p.GetTypeName() == pxr::SdfValueTypeNames->TexCoord2fArray || p.GetTypeName() == pxr::SdfValueTypeNames->TexCoord2dArray) { uv_tokens.push_back(p.GetBaseName()); - m_hasUVs = true; + has_uvs_ = true; } } @@ -879,7 +879,7 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, if (topology_changed(existing_mesh, motionSampleTime)) { new_mesh = true; active_mesh = BKE_mesh_new_nomain_from_template( - existing_mesh, m_positions.size(), 0, 0, m_face_indices.size(), m_face_counts.size()); + existing_mesh, positions_.size(), 0, 0, face_indices_.size(), face_counts_.size()); for (pxr::TfToken token : uv_tokens) { void *cd_ptr = add_customdata_cb(active_mesh, token.GetText(), CD_MLOOPUV); @@ -887,19 +887,19 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, } } - read_mesh_sample(m_prim.GetPath().GetString().c_str(), + read_mesh_sample(prim_.GetPath().GetString().c_str(), &settings, active_mesh, - mesh_prim, + mesh_prim_, motionSampleTime, - new_mesh || m_isInitialLoad); + new_mesh || is_initial_load_); if (new_mesh) { /* Here we assume that the number of materials doesn't change, i.e. that * the material slots that were created when the object was loaded from * USD are still valid now. */ size_t num_polys = active_mesh->totpoly; - if (num_polys > 0 && m_import_params.import_materials) { + if (num_polys > 0 && import_params_.import_materials) { std::map<pxr::SdfPath, int> mat_map; assign_facesets_to_mpoly(motionSampleTime, active_mesh->mpoly, num_polys, mat_map); } diff --git a/source/blender/io/usd/intern/usd_reader_mesh.h b/source/blender/io/usd/intern/usd_reader_mesh.h index a275d54e26a..2215bb9fadf 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.h +++ b/source/blender/io/usd/intern/usd_reader_mesh.h @@ -24,6 +24,28 @@ struct MPoly; namespace blender::io::usd { class USDMeshReader : public USDGeomReader { + private: + pxr::UsdGeomMesh mesh_prim_; + + std::unordered_map<std::string, pxr::TfToken> uv_token_map_; + std::map<const pxr::TfToken, bool> primvar_varying_map_; + + pxr::VtIntArray face_indices_; + pxr::VtIntArray face_counts_; + pxr::VtVec3fArray positions_; + pxr::VtVec3fArray normals_; + + pxr::TfToken normal_interpolation_; + pxr::TfToken orientation_; + bool is_left_handed_; + int last_num_positions_; + bool has_uvs_; + bool is_time_varying_; + + // This is to ensure we load all data once because we reuse the read_mesh function + // in the mesh seq modifier, and in initial load. Ideally a better fix would be + // implemented. Note this will break if face or positions vary... + bool is_initial_load_; public: USDMeshReader(pxr::UsdStageRefPtr stage, @@ -55,10 +77,10 @@ class USDMeshReader : public USDGeomReader { void read_mpolys(Mesh *mesh, pxr::UsdGeomMesh mesh_prim, double motionSampleTime); void read_uvs(Mesh *mesh, - pxr::UsdGeomMesh mesh_prim, + pxr::UsdGeomMesh mesh_prim_, double motionSampleTime, bool load_uvs = false); - void read_attributes(Mesh *mesh, pxr::UsdGeomMesh mesh_prim, double motionSampleTime); + void read_attributes(Mesh *mesh, pxr::UsdGeomMesh mesh_prim_, double motionSampleTime); void read_vels(Mesh *mesh, pxr::UsdGeomMesh mesh_prim, float vel_scale, double motionSampleTime); void read_colors(Mesh *mesh, const pxr::UsdGeomMesh &mesh_prim, double motionSampleTime); @@ -68,29 +90,6 @@ class USDMeshReader : public USDGeomReader { const pxr::UsdGeomMesh &mesh_prim, double motionSampleTime, bool new_mesh); - - pxr::UsdGeomMesh mesh_prim; - - std::unordered_map<std::string, pxr::TfToken> uv_token_map; - std::map<const pxr::TfToken, bool> primvar_varying_map; - - pxr::VtIntArray m_face_indices; - pxr::VtIntArray m_face_counts; - pxr::VtVec3fArray m_positions; - pxr::VtVec3fArray m_normals; - pxr::TfToken m_normalInterpolation; - pxr::TfToken m_orientation; - bool m_isLeftHanded; - - int m_lastNumPositions; - - bool m_hasUVs; - bool m_isTimeVarying; - - // This is to ensure we load all data once because we reuse the read_mesh function - // in the mesh seq modifier, and in initial load. Ideally a better fix would be - // implemented. Note this will break if face or positions vary... - bool m_isInitialLoad; }; } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_reader_nurbs.cc b/source/blender/io/usd/intern/usd_reader_nurbs.cc index b2800690512..dd4fd0ad968 100644 --- a/source/blender/io/usd/intern/usd_reader_nurbs.cc +++ b/source/blender/io/usd/intern/usd_reader_nurbs.cc @@ -78,22 +78,22 @@ namespace blender::io::usd { void USDNurbsReader::create_object(Main *bmain, double motionSampleTime) { - m_curve = BKE_curve_add(bmain, m_name.c_str(), OB_CURVE); + curve_ = BKE_curve_add(bmain, name_.c_str(), OB_CURVE); - m_curve->flag |= CU_DEFORM_FILL | CU_3D; - m_curve->actvert = CU_ACT_NONE; - m_curve->resolu = 2; + curve_->flag |= CU_DEFORM_FILL | CU_3D; + curve_->actvert = CU_ACT_NONE; + curve_->resolu = 2; - m_object = BKE_object_add_only_object(bmain, OB_CURVE, m_name.c_str()); - m_object->data = m_curve; + object_ = BKE_object_add_only_object(bmain, OB_CURVE, name_.c_str()); + object_->data = curve_; } void USDNurbsReader::read_object_data(Main *bmain, double motionSampleTime) { - Curve *cu = (Curve *)m_object->data; + Curve *cu = (Curve *)object_->data; read_curve_sample(cu, motionSampleTime); - if (curve_prim.GetPointsAttr().ValueMightBeTimeVarying()) { + if (curve_prim_.GetPointsAttr().ValueMightBeTimeVarying()) { add_cache_modifier(); } @@ -102,11 +102,11 @@ void USDNurbsReader::read_object_data(Main *bmain, double motionSampleTime) void USDNurbsReader::read_curve_sample(Curve *cu, double motionSampleTime) { - curve_prim = pxr::UsdGeomNurbsCurves::Get(m_stage, m_prim.GetPath()); + curve_prim_ = pxr::UsdGeomNurbsCurves::Get(stage_, prim_.GetPath()); - pxr::UsdAttribute widthsAttr = curve_prim.GetWidthsAttr(); - pxr::UsdAttribute vertexAttr = curve_prim.GetCurveVertexCountsAttr(); - pxr::UsdAttribute pointsAttr = curve_prim.GetPointsAttr(); + pxr::UsdAttribute widthsAttr = curve_prim_.GetWidthsAttr(); + pxr::UsdAttribute vertexAttr = curve_prim_.GetCurveVertexCountsAttr(); + pxr::UsdAttribute pointsAttr = curve_prim_.GetPointsAttr(); pxr::VtIntArray usdCounts; @@ -120,23 +120,23 @@ void USDNurbsReader::read_curve_sample(Curve *cu, double motionSampleTime) widthsAttr.Get(&usdWidths, motionSampleTime); pxr::VtIntArray orders; - curve_prim.GetOrderAttr().Get(&orders, motionSampleTime); + curve_prim_.GetOrderAttr().Get(&orders, motionSampleTime); pxr::VtDoubleArray knots; - curve_prim.GetKnotsAttr().Get(&knots, motionSampleTime); + curve_prim_.GetKnotsAttr().Get(&knots, motionSampleTime); pxr::VtVec3fArray usdNormals; - curve_prim.GetNormalsAttr().Get(&usdNormals, motionSampleTime); + curve_prim_.GetNormalsAttr().Get(&usdNormals, motionSampleTime); // If normals, extrude, else bevel // Perhaps to be replaced by Blender/USD Schema if (usdNormals.size() > 0) { // Set extrusion to 1.0f; - m_curve->ext1 = 1.0f; + curve_->ext1 = 1.0f; } else { // Set bevel depth to 1.0f; - m_curve->ext2 = 1.0f; + curve_->ext2 = 1.0f; } size_t idx = 0; @@ -204,11 +204,11 @@ Mesh *USDNurbsReader::read_mesh(struct Mesh *existing_mesh, float vel_scale, const char **err_str) { - pxr::UsdGeomCurves curve_prim = pxr::UsdGeomCurves::Get(m_stage, m_prim.GetPath()); + pxr::UsdGeomCurves curve_prim_ = pxr::UsdGeomCurves::Get(stage_, prim_.GetPath()); - pxr::UsdAttribute widthsAttr = curve_prim.GetWidthsAttr(); - pxr::UsdAttribute vertexAttr = curve_prim.GetCurveVertexCountsAttr(); - pxr::UsdAttribute pointsAttr = curve_prim.GetPointsAttr(); + pxr::UsdAttribute widthsAttr = curve_prim_.GetWidthsAttr(); + pxr::UsdAttribute vertexAttr = curve_prim_.GetCurveVertexCountsAttr(); + pxr::UsdAttribute pointsAttr = curve_prim_.GetPointsAttr(); pxr::VtIntArray usdCounts; @@ -220,7 +220,7 @@ Mesh *USDNurbsReader::read_mesh(struct Mesh *existing_mesh, int vertex_idx = 0; int curve_idx; - Curve *curve = static_cast<Curve *>(m_object->data); + Curve *curve = static_cast<Curve *>(object_->data); const int curve_count = BLI_listbase_count(&curve->nurb); bool same_topology = curve_count == num_subcurves; @@ -268,7 +268,7 @@ Mesh *USDNurbsReader::read_mesh(struct Mesh *existing_mesh, } } - return BKE_mesh_new_nomain_from_curve(m_object); + return BKE_mesh_new_nomain_from_curve(object_); } } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_reader_nurbs.h b/source/blender/io/usd/intern/usd_reader_nurbs.h index 53e52d65293..a53732ddbd9 100644 --- a/source/blender/io/usd/intern/usd_reader_nurbs.h +++ b/source/blender/io/usd/intern/usd_reader_nurbs.h @@ -25,6 +25,9 @@ struct Curve; namespace blender::io::usd { class USDNurbsReader : public USDGeomReader { + protected: + pxr::UsdGeomNurbsCurves curve_prim_; + Curve *curve_; public: USDNurbsReader(pxr::UsdStageRefPtr stage, @@ -45,10 +48,6 @@ class USDNurbsReader : public USDGeomReader { int read_flag, float vel_scale, const char **err_str) override; - - protected: - pxr::UsdGeomNurbsCurves curve_prim; - Curve *m_curve; }; } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_reader_prim.cc b/source/blender/io/usd/intern/usd_reader_prim.cc index 98e32c61e8c..c6b70a06409 100644 --- a/source/blender/io/usd/intern/usd_reader_prim.cc +++ b/source/blender/io/usd/intern/usd_reader_prim.cc @@ -42,19 +42,19 @@ USDPrimReader::USDPrimReader(pxr::UsdStageRefPtr stage, const pxr::UsdPrim &object, const USDImportParams &import_params, ImportSettings &settings) - : m_name(object.GetName().GetString()), - m_prim_path(object.GetPrimPath().GetString()), - m_object(nullptr), - m_prim(object), - m_stage(stage), - m_import_params(import_params), - m_parent_reader(nullptr), - m_settings(&settings), - m_refcount(0) + : name_(object.GetName().GetString()), + prim_path_(object.GetPrimPath().GetString()), + object_(nullptr), + prim_(object), + stage_(stage), + import_params_(import_params), + parent_reader_(nullptr), + settings_(&settings), + refcount_(0) { //@TODO(bjs): This should be handled better - if (m_name == "/") - m_name = "root"; + if (name_ == "/") + name_ = "root"; } USDPrimReader::~USDPrimReader() @@ -63,29 +63,29 @@ USDPrimReader::~USDPrimReader() const pxr::UsdPrim &USDPrimReader::prim() const { - return m_prim; + return prim_; } Object *USDPrimReader::object() const { - return m_object; + return object_; } void USDPrimReader::object(Object *ob) { - m_object = ob; + object_ = ob; } bool USDPrimReader::valid() const { - return m_prim.IsValid(); + return prim_.IsValid(); } void USDPrimReader::create_object(Main *bmain, double motionSampleTime) { - m_object = BKE_object_add_only_object(bmain, OB_EMPTY, m_name.c_str()); - m_object->empty_drawsize = 0.1f; - m_object->data = NULL; + object_ = BKE_object_add_only_object(bmain, OB_EMPTY, name_.c_str()); + object_->empty_drawsize = 0.1f; + object_->data = NULL; } void USDPrimReader::read_object_data(Main *bmain, double motionSampleTime) @@ -98,18 +98,18 @@ void USDPrimReader::add_cache_modifier() int USDPrimReader::refcount() const { - return m_refcount; + return refcount_; } void USDPrimReader::incref() { - m_refcount++; + refcount_++; } void USDPrimReader::decref() { - m_refcount--; - BLI_assert(m_refcount >= 0); + refcount_--; + BLI_assert(refcount_ >= 0); } } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_reader_prim.h b/source/blender/io/usd/intern/usd_reader_prim.h index da96783a9dc..eaeb240ff4d 100644 --- a/source/blender/io/usd/intern/usd_reader_prim.h +++ b/source/blender/io/usd/intern/usd_reader_prim.h @@ -81,17 +81,15 @@ struct ImportSettings { class USDPrimReader { protected: - std::string m_name; - std::string m_prim_path; - Object *m_object; - pxr::UsdPrim m_prim; - pxr::UsdStageRefPtr m_stage; - const USDImportParams &m_import_params; - USDPrimReader *m_parent_reader; - - ImportSettings *m_settings; - - int m_refcount; + std::string name_; + std::string prim_path_; + Object *object_; + pxr::UsdPrim prim_; + pxr::UsdStageRefPtr stage_; + const USDImportParams &import_params_; + USDPrimReader *parent_reader_; + ImportSettings *settings_; + int refcount_; public: USDPrimReader(pxr::UsdStageRefPtr stage, @@ -112,11 +110,11 @@ class USDPrimReader { USDPrimReader *parent() const { - return m_parent_reader; + return parent_reader_; } void parent(USDPrimReader *parent) { - m_parent_reader = parent; + parent_reader_ = parent; } int refcount() const; @@ -127,11 +125,11 @@ class USDPrimReader { const std::string &name() const { - return m_name; + return name_; } const std::string &prim_path() const { - return m_prim_path; + return prim_path_; } }; diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc index 11ea7e1ab93..dc51eabef39 100644 --- a/source/blender/io/usd/intern/usd_reader_stage.cc +++ b/source/blender/io/usd/intern/usd_reader_stage.cc @@ -56,14 +56,14 @@ namespace blender::io::usd { USDStageReader::USDStageReader(struct Main *bmain, const char *filename) { - m_stage = pxr::UsdStage::Open(filename); + stage_ = pxr::UsdStage::Open(filename); } USDStageReader::~USDStageReader() { clear_readers(); - m_stage->Unload(); + stage_->Unload(); } bool USDStageReader::valid() const @@ -169,20 +169,20 @@ std::vector<USDPrimReader *> USDStageReader::collect_readers(Main *bmain, const USDImportParams ¶ms, ImportSettings &settings) { - m_params = params; - m_settings = settings; + params_ = params; + settings_ = settings; clear_readers(); // Iterate through stage - pxr::UsdPrim root = m_stage->GetPseudoRoot(); + pxr::UsdPrim root = stage_->GetPseudoRoot(); std::string prim_path_mask(params.prim_path_mask); if (prim_path_mask.size() > 0) { std::cout << prim_path_mask << '\n'; pxr::SdfPath path = pxr::SdfPath(prim_path_mask); - pxr::UsdPrim prim = m_stage->GetPrimAtPath(path.StripAllVariantSelections()); + pxr::UsdPrim prim = stage_->GetPrimAtPath(path.StripAllVariantSelections()); if (prim.IsValid()) { root = prim; if (path.ContainsPrimVariantSelection()) { @@ -196,38 +196,38 @@ std::vector<USDPrimReader *> USDStageReader::collect_readers(Main *bmain, } } - m_stage->SetInterpolationType(pxr::UsdInterpolationType::UsdInterpolationTypeHeld); - _handlePrim(bmain, m_stage, params, root, NULL, m_readers, settings); + stage_->SetInterpolationType(pxr::UsdInterpolationType::UsdInterpolationTypeHeld); + _handlePrim(bmain, stage_, params, root, NULL, readers_, settings); if (params.use_instancing) { // Collect the scenegraph instance prototypes. - std::vector<pxr::UsdPrim> protos = m_stage->GetMasters(); + std::vector<pxr::UsdPrim> protos = stage_->GetMasters(); for (const pxr::UsdPrim &proto_prim : protos) { std::vector<USDPrimReader *> proto_readers; - _handlePrim(bmain, m_stage, params, proto_prim, NULL, proto_readers, settings); - m_proto_readers.insert(std::make_pair(proto_prim.GetPath(), proto_readers)); + _handlePrim(bmain, stage_, params, proto_prim, NULL, proto_readers, settings); + proto_readers_.insert(std::make_pair(proto_prim.GetPath(), proto_readers)); } } - return m_readers; + return readers_; } void USDStageReader::clear_readers() { std::vector<USDPrimReader *>::iterator iter; - for (iter = m_readers.begin(); iter != m_readers.end(); ++iter) { + for (iter = readers_.begin(); iter != readers_.end(); ++iter) { if (((USDPrimReader *)*iter)->refcount() == 0) { delete *iter; } } - m_readers.clear(); + readers_.clear(); } void USDStageReader::clear_proto_readers(bool decref) { - for (auto &pair : m_proto_readers) { + for (auto &pair : proto_readers_) { for (USDPrimReader *reader : pair.second) { @@ -247,7 +247,7 @@ void USDStageReader::clear_proto_readers(bool decref) pair.second.clear(); } - m_proto_readers.clear(); + proto_readers_.clear(); } } // Namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_reader_stage.h b/source/blender/io/usd/intern/usd_reader_stage.h index 3a3340b51ee..88a6c8c5723 100644 --- a/source/blender/io/usd/intern/usd_reader_stage.h +++ b/source/blender/io/usd/intern/usd_reader_stage.h @@ -39,19 +39,19 @@ namespace blender::io::usd { * the stream objects remain valid as long as the archives are open. */ +typedef std::map<pxr::SdfPath, std::vector<USDPrimReader *>> ProtoReaderMap; + class USDStageReader { - public: - typedef std::map<pxr::SdfPath, std::vector<USDPrimReader *>> ProtoReaderMap; protected: - pxr::UsdStageRefPtr m_stage; - USDImportParams m_params; - ImportSettings m_settings; + pxr::UsdStageRefPtr stage_; + USDImportParams params_; + ImportSettings settings_; - std::vector<USDPrimReader *> m_readers; + std::vector<USDPrimReader *> readers_; // Readers for scenegraph instance prototypes. - ProtoReaderMap m_proto_readers; + ProtoReaderMap proto_readers_; public: USDStageReader(struct Main *bmain, const char *filename); @@ -65,24 +65,24 @@ class USDStageReader { pxr::UsdStageRefPtr stage() { - return m_stage; + return stage_; } USDImportParams ¶ms() { - return m_params; + return params_; } ImportSettings &settings() { - return m_settings; + return settings_; } void params(USDImportParams &a_params) { - m_params = a_params; + params_ = a_params; } void settings(ImportSettings &a_settings) { - m_settings = a_settings; + settings_ = a_settings; } void clear_readers(); @@ -91,7 +91,7 @@ class USDStageReader { const ProtoReaderMap &proto_readers() const { - return m_proto_readers; + return proto_readers_; }; }; diff --git a/source/blender/io/usd/intern/usd_reader_volume.cc b/source/blender/io/usd/intern/usd_reader_volume.cc index b68edf80323..e557e861861 100644 --- a/source/blender/io/usd/intern/usd_reader_volume.cc +++ b/source/blender/io/usd/intern/usd_reader_volume.cc @@ -58,27 +58,27 @@ namespace blender::io::usd { void USDVolumeReader::create_object(Main *bmain, double motionSampleTime) { - Volume *volume = (Volume *)BKE_volume_add(bmain, m_name.c_str()); + Volume *volume = (Volume *)BKE_volume_add(bmain, name_.c_str()); id_us_min(&volume->id); - m_object = BKE_object_add_only_object(bmain, OB_VOLUME, m_name.c_str()); - m_object->data = volume; + object_ = BKE_object_add_only_object(bmain, OB_VOLUME, name_.c_str()); + object_->data = volume; } void USDVolumeReader::read_object_data(Main *bmain, double motionSampleTime) { - m_volume = pxr::UsdVolVolume::Get(m_stage, m_prim.GetPath()); + volume_ = pxr::UsdVolVolume::Get(stage_, prim_.GetPath()); - pxr::UsdVolVolume::FieldMap fields = m_volume.GetFieldPaths(); + pxr::UsdVolVolume::FieldMap fields = volume_.GetFieldPaths(); std::string filepath; - Volume *volume = (Volume *)m_object->data; + Volume *volume = (Volume *)object_->data; VolumeGrid *defaultGrid = BKE_volume_grid_active_get(volume); for (auto it = fields.begin(); it != fields.end(); ++it) { - pxr::UsdPrim fieldPrim = m_stage->GetPrimAtPath(it->second); + pxr::UsdPrim fieldPrim = stage_->GetPrimAtPath(it->second); if (fieldPrim.IsA<pxr::UsdVolOpenVDBAsset>()) { pxr::UsdVolOpenVDBAsset fieldBase(fieldPrim); diff --git a/source/blender/io/usd/intern/usd_reader_volume.h b/source/blender/io/usd/intern/usd_reader_volume.h index 3968956b6b0..8d5c7206b5d 100644 --- a/source/blender/io/usd/intern/usd_reader_volume.h +++ b/source/blender/io/usd/intern/usd_reader_volume.h @@ -23,6 +23,8 @@ namespace blender::io::usd { class USDVolumeReader : public USDXformReader { + private: + pxr::UsdVolVolume volume_; public: USDVolumeReader(pxr::UsdStageRefPtr stage, @@ -35,8 +37,6 @@ class USDVolumeReader : public USDXformReader { void create_object(Main *bmain, double motionSampleTime) override; void read_object_data(Main *bmain, double motionSampleTime) override; - - pxr::UsdVolVolume m_volume; }; } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_reader_xform.cc b/source/blender/io/usd/intern/usd_reader_xform.cc index 52221be4040..78e03cbf7cd 100644 --- a/source/blender/io/usd/intern/usd_reader_xform.cc +++ b/source/blender/io/usd/intern/usd_reader_xform.cc @@ -50,9 +50,9 @@ namespace blender::io::usd { void USDXformReader::create_object(Main *bmain, double motionSampleTime) { - m_object = BKE_object_add_only_object(bmain, OB_EMPTY, m_name.c_str()); - m_object->empty_drawsize = 0.1f; - m_object->data = NULL; + object_ = BKE_object_add_only_object(bmain, OB_EMPTY, name_.c_str()); + object_->empty_drawsize = 0.1f; + object_->data = NULL; } void USDXformReader::read_object_data(Main *bmain, double motionSampleTime) @@ -62,19 +62,19 @@ void USDXformReader::read_object_data(Main *bmain, double motionSampleTime) bool is_constant; float transform_from_usd[4][4]; - read_matrix(transform_from_usd, motionSampleTime, m_import_params.scale, is_constant); + read_matrix(transform_from_usd, motionSampleTime, import_params_.scale, is_constant); if (!is_constant) { bConstraint *con = BKE_constraint_add_for_object( - m_object, NULL, CONSTRAINT_TYPE_TRANSFORM_CACHE); + object_, NULL, CONSTRAINT_TYPE_TRANSFORM_CACHE); bTransformCacheConstraint *data = static_cast<bTransformCacheConstraint *>(con->data); - BLI_strncpy(data->object_path, m_prim.GetPath().GetText(), FILE_MAX); + BLI_strncpy(data->object_path, prim_.GetPath().GetText(), FILE_MAX); - data->cache_file = m_settings->cache_file; + data->cache_file = settings_->cache_file; id_us_plus(&data->cache_file->id); } - BKE_object_apply_mat4(m_object, transform_from_usd, true, false); + BKE_object_apply_mat4(object_, transform_from_usd, true, false); } typedef float m4[4]; @@ -87,7 +87,7 @@ void USDXformReader::read_matrix(float r_mat[4][4] /* local matrix */, is_constant = true; unit_m4(r_mat); - pxr::UsdGeomXformable xformable(m_prim); + pxr::UsdGeomXformable xformable(prim_); if (!xformable) { // This might happen if the prim is a Scope. @@ -106,7 +106,7 @@ void USDXformReader::read_matrix(float r_mat[4][4] /* local matrix */, /* Apply global scaling and rotation only to root objects, parenting * will propagate it. */ - if ((scale != 1.0 || m_settings->do_convert_mat) && is_root_xform_object()) { + if ((scale != 1.0 || settings_->do_convert_mat) && is_root_xform_object()) { if (scale != 1.0f) { float scale_mat[4][4]; @@ -114,8 +114,8 @@ void USDXformReader::read_matrix(float r_mat[4][4] /* local matrix */, mul_m4_m4m4(r_mat, scale_mat, r_mat); } - if (m_settings->do_convert_mat) { - mul_m4_m4m4(r_mat, m_settings->conversion_mat, r_mat); + if (settings_->do_convert_mat) { + mul_m4_m4m4(r_mat, settings_->conversion_mat, r_mat); } } } @@ -127,17 +127,17 @@ bool USDXformReader::is_root_xform_object() const // represent a scope, which is not xformable. E.g., an Xform // parented to a single Scope would be considered the root. - if (m_prim.IsInMaster()) { + if (prim_.IsInMaster()) { // We don't consider prototypes to be root prims, // because we never want to apply global scaling // or rotations to the ptototypes themselves. return false; } - if (m_prim.IsA<pxr::UsdGeomXformable>()) { + if (prim_.IsA<pxr::UsdGeomXformable>()) { // If we don't have an ancestor that also wraps // UsdGeomXformable, then we are the root. - const USDPrimReader *cur_parent = m_parent_reader; + const USDPrimReader *cur_parent = parent_reader_; while (cur_parent) { if (cur_parent->prim().IsA<pxr::UsdGeomXformable>()) { |