diff options
author | Hans Goudey <h.goudey@me.com> | 2022-09-23 17:02:05 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-09-23 17:02:28 +0300 |
commit | a8a454287a27d408668f8adc6fe1b3aa988de1ac (patch) | |
tree | a0c55182e620598bb92542562d2fc134091a2c08 /source/blender/io | |
parent | b197cd5821f1dfaa5168d31984dd8014f5252456 (diff) |
Mesh: Move edge crease out of MEdge
This is very similar to D14077. There are two differences though.
First is that vertex creases are already stored in a separate layer,
and second is that we can now completely remove use of `Mesh.cd_flag`,
since that information is now inherent to whether the layers exist.
There are two functional differences here:
* Operators are used to add and remove layers instead of a property.
* The "crease" attribute can be created and removed by geometry nodes.
The second change should make various geometry nodes slightly faster,
since the "crease" attribute was always processed before. Creases are
now interpolated generically in the CustomData API too, which should
help maintain the values across edits better.
Meshes get an `edge_creases` RNA property like the existing vertex
property, to provide more efficient access to the data in Cycles.
One test failure is expected, where different rounding between float
the old char storage means that 5 additional points are scattered in
a geometry nodes test.
Differential Revision: https://developer.blender.org/D15927
Diffstat (limited to 'source/blender/io')
4 files changed, 18 insertions, 22 deletions
diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.cc b/source/blender/io/alembic/exporter/abc_writer_mesh.cc index 7d38cd1ec88..084d26198bc 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mesh.cc +++ b/source/blender/io/alembic/exporter/abc_writer_mesh.cc @@ -476,16 +476,17 @@ static void get_edge_creases(struct Mesh *mesh, std::vector<int32_t> &lengths, std::vector<float> &sharpnesses) { - const float factor = 1.0f / 255.0f; - indices.clear(); lengths.clear(); sharpnesses.clear(); + const float *creases = static_cast<const float *>(CustomData_get_layer(&mesh->edata, CD_CREASE)); + if (!creases) { + return; + } const Span<MEdge> edges = mesh->edges(); - for (const int i : edges.index_range()) { - const float sharpness = static_cast<float>(edges[i].crease) * factor; + const float sharpness = creases[i]; if (sharpness != 0.0f) { indices.push_back(edges[i].v1); diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index c07aaa37988..c9fa307541a 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -903,8 +903,6 @@ static void read_vertex_creases(Mesh *mesh, vertex_crease_data[idx] = (*sharpnesses)[i]; } - - mesh->cd_flag |= ME_CDFLAG_VERT_CREASE; } static void read_edge_creases(Mesh *mesh, @@ -918,6 +916,9 @@ static void read_edge_creases(Mesh *mesh, MutableSpan<MEdge> edges = mesh->edges_for_write(); EdgeHash *edge_hash = BLI_edgehash_new_ex(__func__, edges.size()); + float *creases = static_cast<float *>( + CustomData_add_layer(&mesh->edata, CD_CREASE, CD_SET_DEFAULT, nullptr, edges.size())); + for (const int i : edges.index_range()) { MEdge *edge = &edges[i]; BLI_edgehash_insert(edge_hash, edge->v1, edge->v2, edge); @@ -939,13 +940,11 @@ static void read_edge_creases(Mesh *mesh, } if (edge) { - edge->crease = unit_float_to_uchar_clamp((*sharpnesses)[s]); + creases[edge - edges.data()] = unit_float_to_uchar_clamp((*sharpnesses)[s]); } } BLI_edgehash_free(edge_hash, nullptr); - - mesh->cd_flag |= ME_CDFLAG_EDGE_CREASE; } /* ************************************************************************** */ diff --git a/source/blender/io/collada/MeshImporter.cpp b/source/blender/io/collada/MeshImporter.cpp index 719ac752413..fdb389b61c5 100644 --- a/source/blender/io/collada/MeshImporter.cpp +++ b/source/blender/io/collada/MeshImporter.cpp @@ -592,7 +592,6 @@ void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *me) unsigned int *indices = mp->getPositionIndices().getData(); for (int j = 0; j < edge_count; j++, med++) { - med->crease = 0; med->flag |= ME_LOOSEEDGE; med->v1 = indices[2 * j]; med->v2 = indices[2 * j + 1]; diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index a39f74c6420..e949bafe517 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -283,25 +283,22 @@ static void get_loops_polys(const Mesh *mesh, USDMeshData &usd_mesh_data) static void get_edge_creases(const Mesh *mesh, USDMeshData &usd_mesh_data) { - const float factor = 1.0f / 255.0f; + const float *creases = static_cast<const float *>(CustomData_get_layer(&mesh->edata, CD_CREASE)); + if (!creases) { + return; + } const Span<MEdge> edges = mesh->edges(); - float sharpness; for (const int i : edges.index_range()) { - const MEdge &edge = edges[i]; - if (edge.crease == 0) { + const float crease = creases[i]; + if (crease == 0.0f) { continue; } - if (edge.crease == 255) { - sharpness = pxr::UsdGeomMesh::SHARPNESS_INFINITE; - } - else { - sharpness = static_cast<float>(edge.crease) * factor; - } + const float sharpness = crease >= 1.0f ? pxr::UsdGeomMesh::SHARPNESS_INFINITE : crease; - 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(edges[i].v1); + usd_mesh_data.crease_vertex_indices.push_back(edges[i].v2); usd_mesh_data.crease_lengths.push_back(2); usd_mesh_data.crease_sharpnesses.push_back(sharpness); } |