Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/io/usd/intern/usd_writer_mesh.cc')
-rw-r--r--source/blender/io/usd/intern/usd_writer_mesh.cc51
1 files changed, 27 insertions, 24 deletions
diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc
index ade75fdb365..f6250eebd5d 100644
--- a/source/blender/io/usd/intern/usd_writer_mesh.cc
+++ b/source/blender/io/usd/intern/usd_writer_mesh.cc
@@ -246,8 +246,8 @@ static void get_vertices(const Mesh *mesh, USDMeshData &usd_mesh_data)
{
usd_mesh_data.points.reserve(mesh->totvert);
- const MVert *verts = mesh->mvert;
- for (int i = 0; i < mesh->totvert; ++i) {
+ const Span<MVert> verts = mesh->vertices();
+ for (const int i : verts.index_range()) {
usd_mesh_data.points.push_back(pxr::GfVec3f(verts[i].co));
}
}
@@ -269,13 +269,14 @@ static void get_loops_polys(const Mesh *mesh, USDMeshData &usd_mesh_data)
usd_mesh_data.face_vertex_counts.reserve(mesh->totpoly);
usd_mesh_data.face_indices.reserve(mesh->totloop);
- MLoop *mloop = mesh->mloop;
- MPoly *mpoly = mesh->mpoly;
- for (int i = 0; i < mesh->totpoly; ++i, ++mpoly) {
- MLoop *loop = mloop + mpoly->loopstart;
- usd_mesh_data.face_vertex_counts.push_back(mpoly->totloop);
- for (int j = 0; j < mpoly->totloop; ++j, ++loop) {
- usd_mesh_data.face_indices.push_back(loop->v);
+ const Span<MPoly> polys = mesh->polygons();
+ const Span<MLoop> loops = mesh->loops();
+
+ for (const int i : polys.index_range()) {
+ const MPoly &poly = polys[i];
+ usd_mesh_data.face_vertex_counts.push_back(poly.totloop);
+ for (const MLoop &loop : loops.slice(poly.loopstart, poly.totloop)) {
+ usd_mesh_data.face_indices.push_back(loop.v);
}
}
}
@@ -284,22 +285,23 @@ static void get_edge_creases(const Mesh *mesh, USDMeshData &usd_mesh_data)
{
const float factor = 1.0f / 255.0f;
- MEdge *edge = mesh->medge;
+ const Span<MEdge> edges = mesh->edges();
float sharpness;
- for (int edge_idx = 0, totedge = mesh->totedge; edge_idx < totedge; ++edge_idx, ++edge) {
- if (edge->crease == 0) {
+ for (const int i : edges.index_range()) {
+ const MEdge &edge = edges[i];
+ if (edge.crease == 0) {
continue;
}
- if (edge->crease == 255) {
+ if (edge.crease == 255) {
sharpness = pxr::UsdGeomMesh::SHARPNESS_INFINITE;
}
else {
- sharpness = static_cast<float>(edge->crease) * factor;
+ sharpness = static_cast<float>(edge.crease) * factor;
}
- usd_mesh_data.crease_vertex_indices.push_back(edge->v1);
- usd_mesh_data.crease_vertex_indices.push_back(edge->v2);
+ usd_mesh_data.crease_vertex_indices.push_back(edge.v1);
+ usd_mesh_data.crease_vertex_indices.push_back(edge.v2);
usd_mesh_data.crease_lengths.push_back(2);
usd_mesh_data.crease_sharpnesses.push_back(sharpness);
}
@@ -397,6 +399,8 @@ void USDGenericMeshWriter::write_normals(const Mesh *mesh, pxr::UsdGeomMesh usd_
{
pxr::UsdTimeCode timecode = get_export_time_code();
const float(*lnors)[3] = static_cast<float(*)[3]>(CustomData_get_layer(&mesh->ldata, CD_NORMAL));
+ const Span<MPoly> polys = mesh->polygons();
+ const Span<MLoop> loops = mesh->loops();
pxr::VtVec3fArray loop_normals;
loop_normals.reserve(mesh->totloop);
@@ -411,21 +415,20 @@ void USDGenericMeshWriter::write_normals(const Mesh *mesh, pxr::UsdGeomMesh usd_
/* Compute the loop normals based on the 'smooth' flag. */
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;
- for (int poly_idx = 0, totpoly = mesh->totpoly; poly_idx < totpoly; ++poly_idx, ++mpoly) {
- MLoop *mloop = mesh->mloop + mpoly->loopstart;
+ for (const int i : polys.index_range()) {
+ const MPoly &poly = polys[i];
- if ((mpoly->flag & ME_SMOOTH) == 0) {
+ if ((poly.flag & ME_SMOOTH) == 0) {
/* Flat shaded, use common normal for all verts. */
- pxr::GfVec3f pxr_normal(face_normals[poly_idx]);
- for (int loop_idx = 0; loop_idx < mpoly->totloop; ++loop_idx) {
+ pxr::GfVec3f pxr_normal(face_normals[i]);
+ for (int loop_idx = 0; loop_idx < poly.totloop; ++loop_idx) {
loop_normals.push_back(pxr_normal);
}
}
else {
/* Smooth shaded, use individual vert normals. */
- for (int loop_idx = 0; loop_idx < mpoly->totloop; ++loop_idx, ++mloop) {
- loop_normals.push_back(pxr::GfVec3f(vert_normals[mloop->v]));
+ for (const MLoop &loop : loops.slice(poly.loopstart, poly.totloop)) {
+ loop_normals.push_back(pxr::GfVec3f(vert_normals[loop.v]));
}
}
}