diff options
Diffstat (limited to 'source/blender/io/usd')
-rw-r--r-- | source/blender/io/usd/intern/usd_reader_mesh.cc | 27 | ||||
-rw-r--r-- | source/blender/io/usd/intern/usd_writer_mesh.cc | 10 |
2 files changed, 16 insertions, 21 deletions
diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 3ad1d4adf18..53dbaac99fd 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -30,6 +30,8 @@ #include "BLI_math.h" #include "BLI_math_geom.h" +#include "BLI_math_vec_types.hh" +#include "BLI_span.hh" #include "BLI_string.h" #include "DNA_customdata_types.h" @@ -527,34 +529,32 @@ void USDMeshReader::process_normals_vertex_varying(Mesh *mesh) } if (normals_.empty()) { - BKE_mesh_calc_normals(mesh); return; } if (normals_.size() != mesh->totvert) { std::cerr << "WARNING: vertex varying normals count mismatch for mesh " << prim_path_ << std::endl; - BKE_mesh_calc_normals(mesh); return; } - for (int i = 0; i < normals_.size(); i++) { - MVert &mvert = mesh->mvert[i]; - normal_float_to_short_v3(mvert.no, normals_[i].data()); - } + 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())}); + BKE_mesh_vertex_normals_clear_dirty(mesh); } void USDMeshReader::process_normals_face_varying(Mesh *mesh) { if (normals_.empty()) { - BKE_mesh_calc_normals(mesh); + BKE_mesh_normals_tag_dirty(mesh); return; } /* Check for normals count mismatches to prevent crashes. */ if (normals_.size() != mesh->totloop) { std::cerr << "WARNING: loop normal count mismatch for mesh " << mesh->id.name << std::endl; - BKE_mesh_calc_normals(mesh); + BKE_mesh_normals_tag_dirty(mesh); return; } @@ -592,14 +592,14 @@ void USDMeshReader::process_normals_face_varying(Mesh *mesh) void USDMeshReader::process_normals_uniform(Mesh *mesh) { if (normals_.empty()) { - BKE_mesh_calc_normals(mesh); + BKE_mesh_normals_tag_dirty(mesh); return; } /* Check for normals count mismatches to prevent crashes. */ if (normals_.size() != mesh->totpoly) { std::cerr << "WARNING: uniform normal count mismatch for mesh " << mesh->id.name << std::endl; - BKE_mesh_calc_normals(mesh); + BKE_mesh_normals_tag_dirty(mesh); return; } @@ -652,14 +652,11 @@ void USDMeshReader::read_mesh_sample(ImportSettings *settings, } else { /* Default */ - BKE_mesh_calc_normals(mesh); + BKE_mesh_normals_tag_dirty(mesh); } } - /* Process point normals after reading polys. This - * is important in the case where the normals are empty - * and we invoke BKE_mesh_calc_normals(mesh), which requires - * edges to be defined. */ + /* Process point normals after reading polys. */ if ((settings->read_flag & MOD_MESHSEQ_READ_VERT) != 0 && normal_interpolation_ == pxr::UsdGeomTokens->vertex) { process_normals_vertex_varying(mesh); diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index 61b14155dd0..b21dd8ac1fd 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -378,16 +378,15 @@ void USDGenericMeshWriter::write_normals(const Mesh *mesh, pxr::UsdGeomMesh usd_ } else { /* Compute the loop normals based on the 'smooth' flag. */ - float normal[3]; + const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh); + const float(*face_normals)[3] = BKE_mesh_poly_normals_ensure(mesh); MPoly *mpoly = mesh->mpoly; - const MVert *mvert = mesh->mvert; for (int poly_idx = 0, totpoly = mesh->totpoly; poly_idx < totpoly; ++poly_idx, ++mpoly) { MLoop *mloop = mesh->mloop + mpoly->loopstart; if ((mpoly->flag & ME_SMOOTH) == 0) { /* Flat shaded, use common normal for all verts. */ - BKE_mesh_calc_poly_normal(mpoly, mloop, mvert, normal); - pxr::GfVec3f pxr_normal(normal); + pxr::GfVec3f pxr_normal(face_normals[poly_idx]); for (int loop_idx = 0; loop_idx < mpoly->totloop; ++loop_idx) { loop_normals.push_back(pxr_normal); } @@ -395,8 +394,7 @@ void USDGenericMeshWriter::write_normals(const Mesh *mesh, pxr::UsdGeomMesh usd_ else { /* Smooth shaded, use individual vert normals. */ for (int loop_idx = 0; loop_idx < mpoly->totloop; ++loop_idx, ++mloop) { - normal_short_to_float_v3(normal, mvert[mloop->v].no); - loop_normals.push_back(pxr::GfVec3f(normal)); + loop_normals.push_back(pxr::GfVec3f(vert_normals[mloop->v])); } } } |