diff options
Diffstat (limited to 'source/blender/io/alembic/intern/abc_reader_mesh.cc')
-rw-r--r-- | source/blender/io/alembic/intern/abc_reader_mesh.cc | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index 16e5ee968a3..dadfa93a6fb 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -117,14 +117,14 @@ struct AbcMeshData { UInt32ArraySamplePtr uvs_indices; }; -static void read_mverts_interp(MVert *mverts, +static void read_mverts_interp(MutableSpan<MVert> verts, const P3fArraySamplePtr &positions, const P3fArraySamplePtr &ceil_positions, const double weight) { float tmp[3]; for (int i = 0; i < positions->size(); i++) { - MVert &mvert = mverts[i]; + MVert &mvert = verts[i]; const Imath::V3f &floor_pos = (*positions)[i]; const Imath::V3f &ceil_pos = (*ceil_positions)[i]; @@ -137,13 +137,13 @@ static void read_mverts_interp(MVert *mverts, static void read_mverts(CDStreamConfig &config, const AbcMeshData &mesh_data) { - MVert *mverts = config.mvert; + MutableSpan<MVert> verts = config.verts; const P3fArraySamplePtr &positions = mesh_data.positions; if (config.use_vertex_interpolation && config.weight != 0.0f && mesh_data.ceil_positions != nullptr && mesh_data.ceil_positions->size() == positions->size()) { - read_mverts_interp(mverts, positions, mesh_data.ceil_positions, config.weight); + read_mverts_interp(verts, positions, mesh_data.ceil_positions, config.weight); return; } @@ -152,8 +152,9 @@ static void read_mverts(CDStreamConfig &config, const AbcMeshData &mesh_data) void read_mverts(Mesh &mesh, const P3fArraySamplePtr positions, const N3fArraySamplePtr normals) { + MutableSpan<MVert> verts = mesh.vertices_for_write(); for (int i = 0; i < positions->size(); i++) { - MVert &mvert = mesh.mvert[i]; + MVert &mvert = verts[i]; Imath::V3f pos_in = (*positions)[i]; copy_zup_from_yup(mvert.co, pos_in.getValue()); @@ -172,8 +173,8 @@ void read_mverts(Mesh &mesh, const P3fArraySamplePtr positions, const N3fArraySa static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data) { - MPoly *mpolys = config.mpoly; - MLoop *mloops = config.mloop; + MutableSpan<MPoly> polys = config.polys; + MutableSpan<MLoop> loops = config.loops; MLoopUV *mloopuvs = config.mloopuv; const Int32ArraySamplePtr &face_indices = mesh_data.face_indices; @@ -194,7 +195,7 @@ static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data) for (int i = 0; i < face_counts->size(); i++) { const int face_size = (*face_counts)[i]; - MPoly &poly = mpolys[i]; + MPoly &poly = polys[i]; poly.loopstart = loop_index; poly.totloop = face_size; @@ -207,7 +208,7 @@ static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data) uint last_vertex_index = 0; for (int f = 0; f < face_size; f++, loop_index++, rev_loop_index--) { - MLoop &loop = mloops[rev_loop_index]; + MLoop &loop = loops[rev_loop_index]; loop.v = (*face_indices)[loop_index]; if (f > 0 && loop.v == last_vertex_index) { @@ -269,7 +270,8 @@ static void process_loop_normals(CDStreamConfig &config, const N3fArraySamplePtr float(*lnors)[3] = static_cast<float(*)[3]>( MEM_malloc_arrayN(loop_count, sizeof(float[3]), "ABC::FaceNormals")); - MPoly *mpoly = mesh->mpoly; + MutableSpan<MPoly> polys = mesh->polygons_for_write(); + MPoly *mpoly = polys.data(); const N3fArraySample &loop_normals = *loop_normals_ptr; int abc_index = 0; for (int i = 0, e = mesh->totpoly; i < e; i++, mpoly++) { @@ -514,16 +516,10 @@ static void read_mesh_sample(const std::string &iobject_full_name, CDStreamConfig get_config(Mesh *mesh, const bool use_vertex_interpolation) { CDStreamConfig config; - - BLI_assert(mesh->mvert || mesh->totvert == 0); - config.mesh = mesh; - config.mvert = mesh->mvert; - config.mloop = mesh->mloop; - config.mpoly = mesh->mpoly; - config.totvert = mesh->totvert; - config.totloop = mesh->totloop; - config.totpoly = mesh->totpoly; + config.verts = mesh->vertices_for_write(); + config.loops = mesh->loops_for_write(); + config.polys = mesh->polygons_for_write(); config.loopdata = &mesh->ldata; config.add_customdata_cb = add_customdata_cb; config.use_vertex_interpolation = use_vertex_interpolation; @@ -763,8 +759,8 @@ Mesh *AbcMeshReader::read_mesh(Mesh *existing_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 * Alembic are still valid now. */ - size_t num_polys = new_mesh->totpoly; - if (num_polys > 0) { + MutableSpan<MPoly> polys = new_mesh->polygons_for_write(); + if (!polys.is_empty()) { std::map<std::string, int> mat_map; bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*new_mesh); bke::SpanAttributeWriter<int> material_indices = @@ -920,12 +916,10 @@ static void read_edge_creases(Mesh *mesh, return; } - MEdge *edges = mesh->medge; - const int totedge = mesh->totedge; - - EdgeHash *edge_hash = BLI_edgehash_new_ex(__func__, mesh->totedge); + MutableSpan<MEdge> edges = mesh->edges_for_write(); + EdgeHash *edge_hash = BLI_edgehash_new_ex(__func__, edges.size()); - for (int i = 0; i < totedge; i++) { + for (const int i : edges.index_range()) { MEdge *edge = &edges[i]; BLI_edgehash_insert(edge_hash, edge->v1, edge->v2, edge); } |