diff options
Diffstat (limited to 'source/blender/io/alembic')
4 files changed, 37 insertions, 20 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, |