diff options
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc | 73 |
1 files changed, 34 insertions, 39 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc index acf85e74353..237e8ffaa7c 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc @@ -61,15 +61,15 @@ struct AttributeOutputs { StrongAnonymousAttributeID side_id; }; -static void save_selection_as_attribute(MeshComponent &component, +static void save_selection_as_attribute(Mesh &mesh, const AnonymousAttributeID *id, const eAttrDomain domain, const IndexMask selection) { - BLI_assert(!component.attributes()->contains(id)); + MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh); + BLI_assert(!attributes.contains(id)); - SpanAttributeWriter<bool> attribute = - component.attributes_for_write()->lookup_or_add_for_write_span<bool>(id, domain); + SpanAttributeWriter<bool> attribute = attributes.lookup_or_add_for_write_span<bool>(id, domain); /* Rely on the new attribute being zeroed by default. */ BLI_assert(!attribute.span.as_span().contains(true)); @@ -225,7 +225,7 @@ template<typename T, typename GetMixIndicesFn> void copy_with_mixing(MutableSpan<T> dst, Span<T> src, GetMixIndicesFn get_mix_indices_fn) { threading::parallel_for(dst.index_range(), 512, [&](const IndexRange range) { - attribute_math::DefaultPropatationMixer<T> mixer{dst.slice(range)}; + attribute_math::DefaultPropagationMixer<T> mixer{dst.slice(range)}; for (const int i_dst : IndexRange(range.size())) { for (const int i_src : get_mix_indices_fn(range[i_dst])) { mixer.mix_in(i_dst, src[i_src]); @@ -247,16 +247,15 @@ static Array<Vector<int>> create_vert_to_edge_map(const int vert_size, return vert_to_edge_map; } -static void extrude_mesh_vertices(MeshComponent &component, +static void extrude_mesh_vertices(Mesh &mesh, const Field<bool> &selection_field, const Field<float3> &offset_field, const AttributeOutputs &attribute_outputs) { - Mesh &mesh = *component.get_for_write(); const int orig_vert_size = mesh.totvert; const int orig_edge_size = mesh.totedge; - GeometryComponentFieldContext context{component, ATTR_DOMAIN_POINT}; + bke::MeshFieldContext context{mesh, ATTR_DOMAIN_POINT}; FieldEvaluator evaluator{context, mesh.totvert}; evaluator.add(offset_field); evaluator.set_selection(selection_field); @@ -279,7 +278,7 @@ static void extrude_mesh_vertices(MeshComponent &component, new_edges[i_selection] = new_loose_edge(selection[i_selection], new_vert_range[i_selection]); } - MutableAttributeAccessor attributes = *component.attributes_for_write(); + MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh); attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) { if (!ELEM(meta_data.domain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_EDGE)) { @@ -326,11 +325,11 @@ static void extrude_mesh_vertices(MeshComponent &component, if (attribute_outputs.top_id) { save_selection_as_attribute( - component, attribute_outputs.top_id.get(), ATTR_DOMAIN_POINT, new_vert_range); + mesh, attribute_outputs.top_id.get(), ATTR_DOMAIN_POINT, new_vert_range); } if (attribute_outputs.side_id) { save_selection_as_attribute( - component, attribute_outputs.side_id.get(), ATTR_DOMAIN_EDGE, new_edge_range); + mesh, attribute_outputs.side_id.get(), ATTR_DOMAIN_EDGE, new_edge_range); } BKE_mesh_runtime_clear_cache(&mesh); @@ -408,18 +407,17 @@ static VectorSet<int> vert_indices_from_edges(const Mesh &mesh, const Span<T> ed return vert_indices; } -static void extrude_mesh_edges(MeshComponent &component, +static void extrude_mesh_edges(Mesh &mesh, const Field<bool> &selection_field, const Field<float3> &offset_field, const AttributeOutputs &attribute_outputs) { - Mesh &mesh = *component.get_for_write(); const int orig_vert_size = mesh.totvert; Span<MEdge> orig_edges = mesh_edges(mesh); Span<MPoly> orig_polys = mesh_polys(mesh); const int orig_loop_size = mesh.totloop; - GeometryComponentFieldContext edge_context{component, ATTR_DOMAIN_EDGE}; + bke::MeshFieldContext edge_context{mesh, ATTR_DOMAIN_EDGE}; FieldEvaluator edge_evaluator{edge_context, mesh.totedge}; edge_evaluator.set_selection(selection_field); edge_evaluator.add(offset_field); @@ -437,7 +435,7 @@ static void extrude_mesh_edges(MeshComponent &component, Array<float3> vert_offsets; if (!edge_offsets.is_single()) { vert_offsets.reinitialize(orig_vert_size); - attribute_math::DefaultPropatationMixer<float3> mixer(vert_offsets); + attribute_math::DefaultPropagationMixer<float3> mixer(vert_offsets); for (const int i_edge : edge_selection) { const MEdge &edge = orig_edges[i_edge]; const float3 offset = edge_offsets[i_edge]; @@ -525,7 +523,7 @@ static void extrude_mesh_edges(MeshComponent &component, const Array<Vector<int>> new_vert_to_duplicate_edge_map = create_vert_to_edge_map( new_vert_range.size(), duplicate_edges, orig_vert_size); - MutableAttributeAccessor attributes = *component.attributes_for_write(); + MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh); attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) { GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_span( @@ -583,7 +581,7 @@ static void extrude_mesh_edges(MeshComponent &component, /* Both corners on each vertical edge of the side polygon get the same value, * so there are only two unique values to mix. */ Array<T> side_poly_corner_data(2); - attribute_math::DefaultPropatationMixer<T> mixer{side_poly_corner_data}; + attribute_math::DefaultPropagationMixer<T> mixer{side_poly_corner_data}; const MEdge &duplicate_edge = duplicate_edges[i_edge_selection]; const int new_vert_1 = duplicate_edge.v1; @@ -658,11 +656,11 @@ static void extrude_mesh_edges(MeshComponent &component, if (attribute_outputs.top_id) { save_selection_as_attribute( - component, attribute_outputs.top_id.get(), ATTR_DOMAIN_EDGE, duplicate_edge_range); + mesh, attribute_outputs.top_id.get(), ATTR_DOMAIN_EDGE, duplicate_edge_range); } if (attribute_outputs.side_id) { save_selection_as_attribute( - component, attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE, new_poly_range); + mesh, attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE, new_poly_range); } BKE_mesh_runtime_clear_cache(&mesh); @@ -672,18 +670,17 @@ static void extrude_mesh_edges(MeshComponent &component, * Edges connected to one selected face are on the boundary of a region and will be duplicated into * a "side face". Edges inside a region will be duplicated to leave any original faces unchanged. */ -static void extrude_mesh_face_regions(MeshComponent &component, +static void extrude_mesh_face_regions(Mesh &mesh, const Field<bool> &selection_field, const Field<float3> &offset_field, const AttributeOutputs &attribute_outputs) { - Mesh &mesh = *component.get_for_write(); const int orig_vert_size = mesh.totvert; Span<MEdge> orig_edges = mesh_edges(mesh); Span<MPoly> orig_polys = mesh_polys(mesh); Span<MLoop> orig_loops = mesh_loops(mesh); - GeometryComponentFieldContext poly_context{component, ATTR_DOMAIN_FACE}; + bke::MeshFieldContext poly_context{mesh, ATTR_DOMAIN_FACE}; FieldEvaluator poly_evaluator{poly_context, mesh.totpoly}; poly_evaluator.set_selection(selection_field); poly_evaluator.add(offset_field); @@ -705,7 +702,7 @@ static void extrude_mesh_face_regions(MeshComponent &component, Array<float3> vert_offsets; if (!poly_offsets.is_single()) { vert_offsets.reinitialize(orig_vert_size); - attribute_math::DefaultPropatationMixer<float3> mixer(vert_offsets); + attribute_math::DefaultPropagationMixer<float3> mixer(vert_offsets); for (const int i_poly : poly_selection) { const MPoly &poly = orig_polys[i_poly]; const float3 offset = poly_offsets[i_poly]; @@ -905,7 +902,7 @@ static void extrude_mesh_face_regions(MeshComponent &component, const Array<Vector<int>> new_vert_to_duplicate_edge_map = create_vert_to_edge_map( new_vert_range.size(), boundary_edges, orig_vert_size); - MutableAttributeAccessor attributes = *component.attributes_for_write(); + MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh); attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) { GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_span( @@ -1039,11 +1036,11 @@ static void extrude_mesh_face_regions(MeshComponent &component, if (attribute_outputs.top_id) { save_selection_as_attribute( - component, attribute_outputs.top_id.get(), ATTR_DOMAIN_FACE, poly_selection); + mesh, attribute_outputs.top_id.get(), ATTR_DOMAIN_FACE, poly_selection); } if (attribute_outputs.side_id) { save_selection_as_attribute( - component, attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE, side_poly_range); + mesh, attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE, side_poly_range); } BKE_mesh_runtime_clear_cache(&mesh); @@ -1057,12 +1054,11 @@ static IndexRange selected_corner_range(Span<int> offsets, const int index) return IndexRange(offset, next_offset - offset); } -static void extrude_individual_mesh_faces(MeshComponent &component, +static void extrude_individual_mesh_faces(Mesh &mesh, const Field<bool> &selection_field, const Field<float3> &offset_field, const AttributeOutputs &attribute_outputs) { - Mesh &mesh = *component.get_for_write(); const int orig_vert_size = mesh.totvert; const int orig_edge_size = mesh.totedge; Span<MPoly> orig_polys = mesh_polys(mesh); @@ -1071,7 +1067,7 @@ static void extrude_individual_mesh_faces(MeshComponent &component, /* Use a mesh for the result of the evaluation because the mesh is reallocated before * the vertices are moved, and the evaluated result might reference an attribute. */ Array<float3> poly_offset(orig_polys.size()); - GeometryComponentFieldContext poly_context{component, ATTR_DOMAIN_FACE}; + bke::MeshFieldContext poly_context{mesh, ATTR_DOMAIN_FACE}; FieldEvaluator poly_evaluator{poly_context, mesh.totpoly}; poly_evaluator.set_selection(selection_field); poly_evaluator.add_with_destination(offset_field, poly_offset.as_mutable_span()); @@ -1159,7 +1155,7 @@ static void extrude_individual_mesh_faces(MeshComponent &component, } }); - MutableAttributeAccessor attributes = *component.attributes_for_write(); + MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh); attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) { GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_span( @@ -1318,11 +1314,11 @@ static void extrude_individual_mesh_faces(MeshComponent &component, if (attribute_outputs.top_id) { save_selection_as_attribute( - component, attribute_outputs.top_id.get(), ATTR_DOMAIN_FACE, poly_selection); + mesh, attribute_outputs.top_id.get(), ATTR_DOMAIN_FACE, poly_selection); } if (attribute_outputs.side_id) { save_selection_as_attribute( - component, attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE, side_poly_range); + mesh, attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE, side_poly_range); } BKE_mesh_runtime_clear_cache(&mesh); @@ -1359,27 +1355,26 @@ static void node_geo_exec(GeoNodeExecParams params) params.extract_input<bool>("Individual"); geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { - if (geometry_set.has_mesh()) { - MeshComponent &component = geometry_set.get_component_for_write<MeshComponent>(); + if (Mesh *mesh = geometry_set.get_mesh_for_write()) { switch (mode) { case GEO_NODE_EXTRUDE_MESH_VERTICES: - extrude_mesh_vertices(component, selection, final_offset, attribute_outputs); + extrude_mesh_vertices(*mesh, selection, final_offset, attribute_outputs); break; case GEO_NODE_EXTRUDE_MESH_EDGES: - extrude_mesh_edges(component, selection, final_offset, attribute_outputs); + extrude_mesh_edges(*mesh, selection, final_offset, attribute_outputs); break; case GEO_NODE_EXTRUDE_MESH_FACES: { if (extrude_individual) { - extrude_individual_mesh_faces(component, selection, final_offset, attribute_outputs); + extrude_individual_mesh_faces(*mesh, selection, final_offset, attribute_outputs); } else { - extrude_mesh_face_regions(component, selection, final_offset, attribute_outputs); + extrude_mesh_face_regions(*mesh, selection, final_offset, attribute_outputs); } break; } } - BLI_assert(BKE_mesh_is_valid(component.get_for_write())); + BLI_assert(BKE_mesh_is_valid(mesh)); } }); |