diff options
Diffstat (limited to 'source/blender/io')
8 files changed, 55 insertions, 43 deletions
diff --git a/source/blender/io/alembic/exporter/abc_writer_hair.cc b/source/blender/io/alembic/exporter/abc_writer_hair.cc index 80f2cadd08c..e8c156a2b8d 100644 --- a/source/blender/io/alembic/exporter/abc_writer_hair.cc +++ b/source/blender/io/alembic/exporter/abc_writer_hair.cc @@ -136,6 +136,7 @@ void ABCHairWriter::write_hair_sample(const HierarchyContext &context, MTFace *mtface = mesh->mtface; MFace *mface = mesh->mface; MVert *mverts = mesh->mvert; + const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh); if ((!mtface || !mface) && !uv_warning_shown_) { std::fprintf(stderr, @@ -173,8 +174,17 @@ void ABCHairWriter::write_hair_sample(const HierarchyContext &context, psys_interpolate_uvs(tface, face->v4, pa->fuv, r_uv); uv_values.emplace_back(r_uv[0], r_uv[1]); - psys_interpolate_face( - mverts, face, tface, nullptr, mapfw, vec, normal, nullptr, nullptr, nullptr); + psys_interpolate_face(mverts, + vert_normals, + face, + tface, + nullptr, + mapfw, + vec, + normal, + nullptr, + nullptr, + nullptr); copy_yup_from_zup(tmp_nor.getValue(), normal); norm_values.push_back(tmp_nor); @@ -206,10 +216,7 @@ void ABCHairWriter::write_hair_sample(const HierarchyContext &context, if (vtx[o] == num) { uv_values.emplace_back(tface->uv[o][0], tface->uv[o][1]); - - MVert *mv = mverts + vtx[o]; - - normal_short_to_float_v3(normal, mv->no); + copy_v3_v3(normal, vert_normals[vtx[o]]); copy_yup_from_zup(tmp_nor.getValue(), normal); norm_values.push_back(tmp_nor); found = true; @@ -250,6 +257,7 @@ void ABCHairWriter::write_hair_child_sample(const HierarchyContext &context, MTFace *mtface = mesh->mtface; MVert *mverts = mesh->mvert; + const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh); ParticleSystem *psys = context.particle_system; ParticleSettings *part = psys->part; @@ -281,8 +289,17 @@ void ABCHairWriter::write_hair_child_sample(const HierarchyContext &context, psys_interpolate_uvs(tface, face->v4, pc->fuv, r_uv); uv_values.emplace_back(r_uv[0], r_uv[1]); - psys_interpolate_face( - mverts, face, tface, nullptr, mapfw, vec, tmpnor, nullptr, nullptr, nullptr); + psys_interpolate_face(mverts, + vert_normals, + face, + tface, + nullptr, + mapfw, + vec, + tmpnor, + nullptr, + nullptr, + nullptr); /* Convert Z-up to Y-up. */ norm_values.emplace_back(tmpnor[0], tmpnor[2], -tmpnor[1]); diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index 83ca3399db5..3c1ac8ceeaf 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -34,6 +34,7 @@ #include "DNA_object_types.h" #include "BLI_compiler_compat.h" +#include "BLI_index_range.hh" #include "BLI_listbase.h" #include "BLI_math_geom.h" @@ -160,27 +161,26 @@ static void read_mverts(CDStreamConfig &config, const AbcMeshData &mesh_data) return; } - read_mverts(mverts, positions, nullptr); + read_mverts(*config.mesh, positions, nullptr); } -void read_mverts(MVert *mverts, const P3fArraySamplePtr positions, const N3fArraySamplePtr normals) +void read_mverts(Mesh &mesh, const P3fArraySamplePtr positions, const N3fArraySamplePtr normals) { for (int i = 0; i < positions->size(); i++) { - MVert &mvert = mverts[i]; + MVert &mvert = mesh.mvert[i]; Imath::V3f pos_in = (*positions)[i]; copy_zup_from_yup(mvert.co, pos_in.getValue()); mvert.bweight = 0; - - if (normals) { + } + if (normals) { + float(*vert_normals)[3] = BKE_mesh_vertex_normals_for_write(&mesh); + for (const int i : IndexRange(normals->size())) { Imath::V3f nor_in = (*normals)[i]; - - short no[3]; - normal_float_to_short_v3(no, nor_in.getValue()); - - copy_zup_from_yup(mvert.no, no); + copy_zup_from_yup(vert_normals[i], nor_in.getValue()); } + BKE_mesh_vertex_normals_clear_dirty(&mesh); } } diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.h b/source/blender/io/alembic/intern/abc_reader_mesh.h index e78f2186eda..1123616943e 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.h +++ b/source/blender/io/alembic/intern/abc_reader_mesh.h @@ -81,7 +81,7 @@ class AbcSubDReader final : public AbcObjectReader { const char **err_str) override; }; -void read_mverts(MVert *mverts, +void read_mverts(Mesh &mesh, const Alembic::AbcGeom::P3fArraySamplePtr positions, const Alembic::AbcGeom::N3fArraySamplePtr normals); diff --git a/source/blender/io/alembic/intern/abc_reader_points.cc b/source/blender/io/alembic/intern/abc_reader_points.cc index 75ed18f57f2..0135e150097 100644 --- a/source/blender/io/alembic/intern/abc_reader_points.cc +++ b/source/blender/io/alembic/intern/abc_reader_points.cc @@ -121,7 +121,7 @@ void read_points_sample(const IPointsSchema &schema, } } - read_mverts(config.mvert, positions, vnormals); + read_mverts(*config.mesh, positions, vnormals); } struct Mesh *AbcPointsReader::read_mesh(struct Mesh *existing_mesh, diff --git a/source/blender/io/collada/GeometryExporter.cpp b/source/blender/io/collada/GeometryExporter.cpp index eeee220fd2c..73e3eeda462 100644 --- a/source/blender/io/collada/GeometryExporter.cpp +++ b/source/blender/io/collada/GeometryExporter.cpp @@ -631,6 +631,7 @@ void GeometryExporter::create_normals(std::vector<Normal> &normals, int last_normal_index = -1; MVert *verts = me->mvert; + const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(me); MLoop *mloops = me->mloop; float(*lnors)[3] = nullptr; bool use_custom_normals = false; @@ -666,7 +667,7 @@ void GeometryExporter::create_normals(std::vector<Normal> &normals, normalize_v3_v3(normalized, lnors[loop_idx]); } else { - normal_short_to_float_v3(normalized, verts[mloops[loop_index].v].no); + copy_v3_v3(normalized, vert_normals[mloops[loop_index].v]); normalize_v3(normalized); } Normal n = {normalized[0], normalized[1], normalized[2]}; 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])); } } } diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc index efe17c7d1a2..ab1448aa10c 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc @@ -156,7 +156,6 @@ int OBJMesh::ith_smooth_group(const int poly_index) const void OBJMesh::ensure_mesh_normals() const { - BKE_mesh_ensure_normals(export_mesh_eval_); BKE_mesh_calc_normals_split(export_mesh_eval_); } |