Differential D15982 Diff 55757 source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
| Show All 31 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, | ||||
| IndexMask /*mask*/) const final | IndexMask /*mask*/) const final | ||||
| { | { | ||||
| const Span<MVert> verts = mesh.verts(); | const Span<float3> positions = mesh.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(); | ||||
| const Span<float3> poly_normals{(float3 *)BKE_mesh_poly_normals_ensure(&mesh), mesh.totpoly}; | const Span<float3> poly_normals{(float3 *)BKE_mesh_poly_normals_ensure(&mesh), mesh.totpoly}; | ||||
| bke::MeshFieldContext context{mesh, ATTR_DOMAIN_FACE}; | bke::MeshFieldContext context{mesh, ATTR_DOMAIN_FACE}; | ||||
| fn::FieldEvaluator evaluator{context, polys.size()}; | fn::FieldEvaluator evaluator{context, polys.size()}; | ||||
| evaluator.add(threshold_); | evaluator.add(threshold_); | ||||
| evaluator.evaluate(); | evaluator.evaluate(); | ||||
| const VArray<float> thresholds = evaluator.get_evaluated<float>(0); | const VArray<float> thresholds = evaluator.get_evaluated<float>(0); | ||||
| auto planar_fn = [verts, polys, loops, thresholds, poly_normals](const int i) -> bool { | auto planar_fn = [positions, polys, loops, thresholds, poly_normals](const int i) -> bool { | ||||
| const MPoly &poly = polys[i]; | const MPoly &poly = polys[i]; | ||||
| if (poly.totloop <= 3) { | if (poly.totloop <= 3) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| const Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop); | const Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop); | ||||
| const float3 &reference_normal = poly_normals[i]; | const float3 &reference_normal = poly_normals[i]; | ||||
| float min = FLT_MAX; | float min = FLT_MAX; | ||||
| float max = -FLT_MAX; | float max = -FLT_MAX; | ||||
| for (const int i_loop : poly_loops.index_range()) { | for (const int i_loop : poly_loops.index_range()) { | ||||
| const float3 vert = verts[poly_loops[i_loop].v].co; | const float3 &vert = positions[poly_loops[i_loop].v]; | ||||
| float dot = math::dot(reference_normal, vert); | float dot = math::dot(reference_normal, vert); | ||||
| if (dot > max) { | if (dot > max) { | ||||
| max = dot; | max = dot; | ||||
| } | } | ||||
| if (dot < min) { | if (dot < min) { | ||||
| min = dot; | min = dot; | ||||
| } | } | ||||
| } | } | ||||
| Show All 40 Lines | |||||