Differential D15982 Diff 58991 source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc
| Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | public: | ||||
| { | { | ||||
| category_ = Category::Generated; | category_ = Category::Generated; | ||||
| } | } | ||||
| GVArray get_varray_for_context(const Mesh &mesh, | GVArray get_varray_for_context(const Mesh &mesh, | ||||
| const eAttrDomain domain, | const eAttrDomain domain, | ||||
| const IndexMask /*mask*/) const final | const IndexMask /*mask*/) const final | ||||
| { | { | ||||
| const Span<MVert> verts = mesh.verts(); | const Span<float3> positions = mesh.vert_positions(); | ||||
| const Span<MPoly> polys = mesh.polys(); | const Span<MPoly> polys = mesh.polys(); | ||||
| const Span<MLoop> loops = mesh.loops(); | const Span<MLoop> loops = mesh.loops(); | ||||
| Array<EdgeMapEntry> edge_map = create_edge_map(polys, loops, mesh.totedge); | Array<EdgeMapEntry> edge_map = create_edge_map(polys, loops, mesh.totedge); | ||||
| auto angle_fn = [edge_map = std::move(edge_map), verts, polys, loops](const int i) -> float { | auto angle_fn = | ||||
| [edge_map = std::move(edge_map), positions, polys, loops](const int i) -> float { | |||||
| if (edge_map[i].face_count != 2) { | if (edge_map[i].face_count != 2) { | ||||
| return 0.0f; | return 0.0f; | ||||
| } | } | ||||
| const MPoly &mpoly_1 = polys[edge_map[i].face_index_1]; | const MPoly &mpoly_1 = polys[edge_map[i].face_index_1]; | ||||
| const MPoly &mpoly_2 = polys[edge_map[i].face_index_2]; | const MPoly &mpoly_2 = polys[edge_map[i].face_index_2]; | ||||
| float3 normal_1, normal_2; | float3 normal_1, normal_2; | ||||
| BKE_mesh_calc_poly_normal(&mpoly_1, &loops[mpoly_1.loopstart], verts.data(), normal_1); | BKE_mesh_calc_poly_normal(&mpoly_1, | ||||
| BKE_mesh_calc_poly_normal(&mpoly_2, &loops[mpoly_2.loopstart], verts.data(), normal_2); | &loops[mpoly_1.loopstart], | ||||
| reinterpret_cast<const float(*)[3]>(positions.data()), | |||||
| normal_1); | |||||
| BKE_mesh_calc_poly_normal(&mpoly_2, | |||||
| &loops[mpoly_2.loopstart], | |||||
| reinterpret_cast<const float(*)[3]>(positions.data()), | |||||
| normal_2); | |||||
| return angle_normalized_v3v3(normal_1, normal_2); | return angle_normalized_v3v3(normal_1, normal_2); | ||||
| }; | }; | ||||
| VArray<float> angles = VArray<float>::ForFunc(mesh.totedge, angle_fn); | VArray<float> angles = VArray<float>::ForFunc(mesh.totedge, angle_fn); | ||||
| return mesh.attributes().adapt_domain<float>(std::move(angles), ATTR_DOMAIN_EDGE, domain); | return mesh.attributes().adapt_domain<float>(std::move(angles), ATTR_DOMAIN_EDGE, domain); | ||||
| } | } | ||||
| uint64_t hash() const override | uint64_t hash() const override | ||||
| Show All 19 Lines | public: | ||||
| { | { | ||||
| category_ = Category::Generated; | category_ = Category::Generated; | ||||
| } | } | ||||
| GVArray get_varray_for_context(const Mesh &mesh, | GVArray get_varray_for_context(const Mesh &mesh, | ||||
| const eAttrDomain domain, | const eAttrDomain domain, | ||||
| const IndexMask /*mask*/) const final | const IndexMask /*mask*/) const final | ||||
| { | { | ||||
| const Span<MVert> verts = mesh.verts(); | const Span<float3> positions = mesh.vert_positions(); | ||||
| const Span<MEdge> edges = mesh.edges(); | const Span<MEdge> edges = mesh.edges(); | ||||
| const Span<MPoly> polys = mesh.polys(); | const Span<MPoly> polys = mesh.polys(); | ||||
| const Span<MLoop> loops = mesh.loops(); | const Span<MLoop> loops = mesh.loops(); | ||||
| Array<EdgeMapEntry> edge_map = create_edge_map(polys, loops, mesh.totedge); | Array<EdgeMapEntry> edge_map = create_edge_map(polys, loops, mesh.totedge); | ||||
| auto angle_fn = | auto angle_fn = | ||||
| [edge_map = std::move(edge_map), verts, edges, polys, loops](const int i) -> float { | [edge_map = std::move(edge_map), positions, edges, polys, loops](const int i) -> float { | ||||
| if (edge_map[i].face_count != 2) { | if (edge_map[i].face_count != 2) { | ||||
| return 0.0f; | return 0.0f; | ||||
| } | } | ||||
| const MPoly &mpoly_1 = polys[edge_map[i].face_index_1]; | const MPoly &mpoly_1 = polys[edge_map[i].face_index_1]; | ||||
| const MPoly &mpoly_2 = polys[edge_map[i].face_index_2]; | const MPoly &mpoly_2 = polys[edge_map[i].face_index_2]; | ||||
| /* Find the normals of the 2 polys. */ | /* Find the normals of the 2 polys. */ | ||||
| float3 poly_1_normal, poly_2_normal; | float3 poly_1_normal, poly_2_normal; | ||||
| BKE_mesh_calc_poly_normal(&mpoly_1, &loops[mpoly_1.loopstart], verts.data(), poly_1_normal); | BKE_mesh_calc_poly_normal(&mpoly_1, | ||||
| BKE_mesh_calc_poly_normal(&mpoly_2, &loops[mpoly_2.loopstart], verts.data(), poly_2_normal); | &loops[mpoly_1.loopstart], | ||||
| reinterpret_cast<const float(*)[3]>(positions.data()), | |||||
| poly_1_normal); | |||||
| BKE_mesh_calc_poly_normal(&mpoly_2, | |||||
| &loops[mpoly_2.loopstart], | |||||
| reinterpret_cast<const float(*)[3]>(positions.data()), | |||||
| poly_2_normal); | |||||
| /* Find the centerpoint of the axis edge */ | /* Find the centerpoint of the axis edge */ | ||||
| const float3 edge_centerpoint = (float3(verts[edges[i].v1].co) + | const float3 edge_centerpoint = (positions[edges[i].v1] + positions[edges[i].v2]) * 0.5f; | ||||
| float3(verts[edges[i].v2].co)) * | |||||
| 0.5f; | |||||
| /* Get the centerpoint of poly 2 and subtract the edge centerpoint to get a tangent | /* Get the centerpoint of poly 2 and subtract the edge centerpoint to get a tangent | ||||
| * normal for poly 2. */ | * normal for poly 2. */ | ||||
| float3 poly_center_2; | float3 poly_center_2; | ||||
| BKE_mesh_calc_poly_center(&mpoly_2, &loops[mpoly_2.loopstart], verts.data(), poly_center_2); | BKE_mesh_calc_poly_center(&mpoly_2, | ||||
| &loops[mpoly_2.loopstart], | |||||
| reinterpret_cast<const float(*)[3]>(positions.data()), | |||||
| poly_center_2); | |||||
| const float3 poly_2_tangent = math::normalize(poly_center_2 - edge_centerpoint); | const float3 poly_2_tangent = math::normalize(poly_center_2 - edge_centerpoint); | ||||
| const float concavity = math::dot(poly_1_normal, poly_2_tangent); | const float concavity = math::dot(poly_1_normal, poly_2_tangent); | ||||
| /* Get the unsigned angle between the two polys */ | /* Get the unsigned angle between the two polys */ | ||||
| const float angle = angle_normalized_v3v3(poly_1_normal, poly_2_normal); | const float angle = angle_normalized_v3v3(poly_1_normal, poly_2_normal); | ||||
| if (angle == 0.0f || angle == 2.0f * M_PI || concavity < 0) { | if (angle == 0.0f || angle == 2.0f * M_PI || concavity < 0) { | ||||
| return angle; | return angle; | ||||
| ▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines | |||||