Blender V5.3
node_geo_extrude_mesh.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_array_utils.hh"
7#include "BLI_listbase.hh"
8#include "BLI_task.hh"
9#include "BLI_vector_set.hh"
10
11#include "DNA_mesh_types.h"
12#include "DNA_meshdata_types.h"
13
14#include "BKE_attribute_math.hh"
16#include "BKE_customdata.hh"
17#include "BKE_deform.hh"
18#include "BKE_mesh.hh"
19#include "BKE_mesh_mapping.hh"
20#include "BKE_mesh_runtime.hh"
21
23#include "GEO_mesh_selection.hh"
24#include "GEO_randomize.hh"
25
26#include "NOD_rna_define.hh"
27
29#include "UI_resources.hh"
30
32
33#include "node_geometry_util.hh"
34
36
38
40{
41 b.add_input<decl::Geometry>("Mesh"_ustr)
42 .supported_type(GeometryComponent::Type::Mesh)
43 .description("Mesh to extrude elements of");
44 b.add_input<decl::Bool>("Selection"_ustr)
45 .default_value(true)
46 .evaluated_geometry_field()
47 .hide_value();
48 b.add_input<decl::Vector>("Offset"_ustr)
50 .default_input_type(NODE_DEFAULT_INPUT_NORMAL_FIELD)
51 .evaluated_geometry_field();
52 b.add_input<decl::Float>("Offset Scale"_ustr).default_value(1.0f).evaluated_geometry_field();
53 auto &individual = b.add_input<decl::Bool>("Individual"_ustr)
54 .default_value(true)
55 .make_available([](bNode &node) {
56 node_storage(node).mode = GEO_NODE_EXTRUDE_MESH_FACES;
57 });
58 b.add_output<decl::Geometry>("Mesh"_ustr).propagate_all_geometry();
59 b.add_output<decl::Bool>("Top"_ustr)
60 .anonymous_attribute_output()
61 .translation_context(BLT_I18NCONTEXT_ID_NODETREE);
62 b.add_output<decl::Bool>("Side"_ustr).anonymous_attribute_output();
63
64 const bNode *node = b.node_or_null();
65 if (node != nullptr) {
66 const NodeGeometryExtrudeMesh &storage = node_storage(*node);
68 individual.available(mode == GEO_NODE_EXTRUDE_MESH_FACES);
69 }
70}
71
72static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
73{
74 layout.use_property_split_set(true);
75 layout.use_property_decorate_set(false);
76 layout.prop(ptr, "mode", UI_ITEM_NONE, "", ICON_NONE);
77}
78
79static void node_init(bNodeTree * /*tree*/, bNode *node)
80{
81 NodeGeometryExtrudeMesh *data = MEM_new<NodeGeometryExtrudeMesh>(__func__);
83 node->storage = data;
84}
85
87 std::optional<std::string> top_id;
88 std::optional<std::string> side_id;
89};
90
92 const StringRef name,
93 const AttrDomain domain,
94 const IndexMask &selection)
95{
96 BLI_assert(!attributes.contains(name));
97
99 domain);
100 selection.to_bools(attribute.span);
101 attribute.finish();
102}
103
105 const AttributeFilter &attribute_filter)
106{
107 Vector<std::string> names_to_remove;
108 for (const StringRefNull name : attributes.all_names()) {
109 if (attribute_filter.allow_skip(name)) {
110 names_to_remove.append(name);
111 }
112 }
113 for (const StringRef name : names_to_remove) {
114 attributes.remove(name);
115 }
116}
117
124
131
132static void expand_mesh(Mesh &mesh,
133 const int vert_expand,
134 const int edge_expand,
135 const int face_expand,
136 const int loop_expand)
137{
138 /* Remove types that aren't supported for interpolation in this node. */
139 if (vert_expand != 0) {
140 const int old_verts_num = mesh.verts_num;
141 mesh.verts_num += vert_expand;
142 CustomData_realloc(&mesh.vert_data, old_verts_num, mesh.verts_num);
143 mesh.attribute_storage.wrap().resize(AttrDomain::Point, mesh.verts_num);
144 }
145 if (edge_expand != 0) {
146 if (mesh.edges_num == 0) {
147 mesh.attributes_for_write().add(
148 ".edge_verts", AttrDomain::Edge, bke::AttrType::Int32_2D, bke::AttributeInitConstruct());
149 }
150 const int old_edges_num = mesh.edges_num;
151 mesh.edges_num += edge_expand;
152 CustomData_realloc(&mesh.edge_data, old_edges_num, mesh.edges_num);
153 mesh.attribute_storage.wrap().resize(AttrDomain::Edge, mesh.edges_num);
154 }
155 if (face_expand != 0) {
156 const int old_faces_num = mesh.faces_num;
157 mesh.faces_num += face_expand;
158 CustomData_realloc(&mesh.face_data, old_faces_num, mesh.faces_num);
159 mesh.attribute_storage.wrap().resize(AttrDomain::Face, mesh.faces_num);
160 implicit_sharing::resize_trivial_array(&mesh.face_offset_indices,
161 &mesh.runtime->face_offsets_sharing_info,
162 old_faces_num == 0 ? 0 : (old_faces_num + 1),
163 mesh.faces_num + 1);
164 /* Set common values for convenience. */
165 mesh.face_offset_indices[0] = 0;
166 mesh.face_offset_indices[mesh.faces_num] = mesh.corners_num + loop_expand;
167 }
168 if (loop_expand != 0) {
169 if (mesh.corners_num == 0) {
170 mesh.attributes_for_write().add(
171 ".corner_vert", AttrDomain::Corner, bke::AttrType::Int32, bke::AttributeInitConstruct());
172 mesh.attributes_for_write().add(
173 ".corner_edge", AttrDomain::Corner, bke::AttrType::Int32, bke::AttributeInitConstruct());
174 }
175 const int old_loops_num = mesh.corners_num;
176 mesh.corners_num += loop_expand;
177 CustomData_realloc(&mesh.corner_data, old_loops_num, mesh.corners_num);
178 mesh.attribute_storage.wrap().resize(AttrDomain::Corner, mesh.corners_num);
179 }
180}
181
183{
184 switch (domain) {
185 case AttrDomain::Point:
186 return mesh.vert_data;
187 case AttrDomain::Edge:
188 return mesh.edge_data;
189 case AttrDomain::Face:
190 return mesh.face_data;
191 case AttrDomain::Corner:
192 return mesh.corner_data;
193 default:
195 return mesh.vert_data;
196 }
197}
198
199static std::optional<MutableSpan<int>> get_orig_index_layer(Mesh &mesh, const AttrDomain domain)
200{
201 const bke::AttributeAccessor attributes = mesh.attributes();
202 CustomData &custom_data = mesh_custom_data_for_domain(mesh, domain);
203 if (int *orig_indices = static_cast<int *>(CustomData_get_layer_for_write(
204 &custom_data, CD_ORIGINDEX, attributes.domain_size(domain))))
205 {
206 return MutableSpan<int>(orig_indices, attributes.domain_size(domain));
207 }
208 return std::nullopt;
209}
210
211template<typename SelectionT>
213 const SelectionT &selection,
214 Array<int> &r_offsets,
215 Array<int> &r_indices)
216{
217 r_offsets.reinitialize(selection.size() + 1);
219 src_groups.offsets, selection, r_offsets);
220 r_indices.reinitialize(offsets.total_size());
222 src_groups.offsets, offsets, selection, src_groups.data, r_indices.as_mutable_span());
223 return {offsets, r_indices};
224}
225
228{
229 if (type.is<ColorGeometry4f>()) {
230 static const ColorGeometry4f color(0.0f, 0.0f, 0.0f, 1.0f);
231 return GPointer(type, &color);
232 }
233 if (type.is<ColorGeometry4b>()) {
234 static const ColorGeometry4b color(0, 0, 0, 255);
235 return GPointer(type, &color);
236 }
237 if (type.is<float4x4>()) {
238 static const float4x4 matrix = float4x4::identity();
239 return GPointer(type, &matrix);
240 }
241 return GPointer(type, type.default_value());
242}
243
245static void mix_groups_or_default(const GSpan src,
246 const GroupedSpan<int> groups,
247 const GPointer default_value,
248 GMutableSpan dst)
249{
250 bke::attribute_math::mix_groups(src, groups, dst);
251 IndexMaskMemory memory;
252 const IndexMask empty_groups = IndexMask::from_predicate(
253 groups.offsets.index_range(),
254 memory,
255 [&](const int64_t i) { return groups.offsets[i].is_empty(); },
257 dst.type().fill_assign_indices(default_value.get(), dst.data(), empty_groups);
258}
259
260static void mix_groups_or_default(const GSpan src, const GroupedSpan<int> groups, GMutableSpan dst)
261{
262 mix_groups_or_default(src, groups, mixing_default_value(src.type()), dst);
263}
264
265using IDsByDomain = std::array<Vector<StringRef>, ATTR_DOMAIN_NUM>;
266
268 const Set<StringRef> &skip)
269{
270 IDsByDomain names_by_domain;
271 attributes.foreach_attribute([&](const bke::AttributeIter &iter) {
273 return;
274 }
275 if (iter.data_type == bke::AttrType::String) {
276 return;
277 }
278 if (skip.contains(iter.name)) {
279 return;
280 }
281 names_by_domain[int(iter.domain)].append(iter.name);
282 });
283 return names_by_domain;
284}
285
286static bool is_empty_domain(const AttributeAccessor attributes,
287 const Set<StringRef> &skip,
288 const AttrDomain domain)
289{
290 bool is_empty = true;
291 attributes.foreach_attribute([&](const bke::AttributeIter &iter) {
292 if (iter.data_type == bke::AttrType::String) {
293 return;
294 }
295 if (iter.domain != domain) {
296 return;
297 }
298 if (skip.contains(iter.name)) {
299 return;
300 }
301 is_empty = false;
302 iter.stop();
303 });
304 return is_empty;
305}
306
308 const Span<StringRef> names,
309 const Span<int> indices,
310 const IndexRange new_range)
311{
312 for (const StringRef name : names) {
314 bke::attribute_math::gather(attribute.span, indices, attribute.span.slice(new_range));
315 attribute.finish();
316 }
317}
318
320 const Span<StringRef> names,
321 const IndexMask &indices,
322 const IndexRange new_range)
323{
324 for (const StringRef name : names) {
326 array_utils::gather(attribute.span, indices, attribute.span.slice(new_range));
327 attribute.finish();
328 }
329}
330
332 const Span<StringRef> names,
333 const Span<int> indices,
334 const IndexRange new_range)
335{
336 Set<StringRef> vertex_group_names;
337 for (bDeformGroup &group : mesh.vertex_group_names) {
338 vertex_group_names.add(group.name);
339 }
340
341 if (!vertex_group_names.is_empty() && !mesh.deform_verts().is_empty()) {
342 MutableSpan<MDeformVert> dverts = mesh.deform_verts_for_write();
343 bke::gather_deform_verts(dverts, indices, dverts.slice(new_range));
344 }
345
346 MutableAttributeAccessor attributes = mesh.attributes_for_write();
347 for (const StringRef name : names) {
348 if (!vertex_group_names.contains(name)) {
350 bke::attribute_math::gather(attribute.span, indices, attribute.span.slice(new_range));
351 attribute.finish();
352 }
353 }
354}
355
357 const Span<StringRef> names,
358 const IndexMask &indices,
359 const IndexRange new_range)
360{
361 Set<StringRef> vertex_group_names;
362 for (bDeformGroup &group : mesh.vertex_group_names) {
363 vertex_group_names.add(group.name);
364 }
365
366 if (!vertex_group_names.is_empty() && !mesh.deform_verts().is_empty()) {
367 MutableSpan<MDeformVert> dverts = mesh.deform_verts_for_write();
368 bke::gather_deform_verts(dverts, indices, dverts.slice(new_range));
369 }
370
371 MutableAttributeAccessor attributes = mesh.attributes_for_write();
372 for (const StringRef name : names) {
373 if (!vertex_group_names.contains(name)) {
375 array_utils::gather(attribute.span, indices, attribute.span.slice(new_range));
376 attribute.finish();
377 }
378 }
379}
380
382 const Field<bool> &selection_field,
383 const Field<float3> &offset_field,
384 const AttributeOutputs &attribute_outputs,
385 const AttributeFilter &attribute_filter)
386{
387 const int orig_vert_size = mesh.verts_num;
388 const int orig_edge_size = mesh.edges_num;
389
390 /* Use an array for the result of the evaluation because the mesh is reallocated before
391 * the vertices are moved, and the evaluated result might reference an attribute. */
392 Array<float3> offsets(orig_vert_size);
393 const bke::MeshFieldContext context{mesh, AttrDomain::Point};
394 FieldEvaluator evaluator{context, mesh.verts_num};
395 evaluator.add_with_destination(offset_field, offsets.as_mutable_span());
396 evaluator.set_selection(selection_field);
397 evaluator.evaluate();
398 const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
399 if (selection.is_empty()) {
400 return;
401 }
402
403 MutableAttributeAccessor attributes = mesh.attributes_for_write();
404 remove_non_propagated_attributes(attributes, attribute_filter);
405
406 const IDsByDomain names_by_domain = get_transfer_attribute_names(attributes,
407 {"position", ".edge_verts"});
408
409 Array<int> vert_to_edge_offsets;
410 Array<int> vert_to_edge_indices;
411 GroupedSpan<int> vert_to_edge_map;
412 if (!names_by_domain[int(AttrDomain::Edge)].is_empty()) {
413 vert_to_edge_map = bke::mesh::build_vert_to_edge_map(
414 mesh.edges(), orig_vert_size, vert_to_edge_offsets, vert_to_edge_indices);
415 }
416
418 expand_mesh(mesh, selection.size(), selection.size(), 0, 0);
419
420 const IndexRange new_vert_range{orig_vert_size, selection.size()};
421 const IndexRange new_edge_range{orig_edge_size, selection.size()};
422
423 MutableSpan<int2> new_edges = mesh.edges_for_write().slice(new_edge_range);
424 selection.foreach_index_optimized<int>(
425 [&](const int index, const int i_selection) {
426 new_edges[i_selection] = int2(index, new_vert_range[i_selection]);
427 },
429
430 /* New vertices copy the attribute values from their source vertex. */
431 gather_vert_attributes(mesh, names_by_domain[int(AttrDomain::Point)], selection, new_vert_range);
432
433 /* New edge values are mixed from of all the edges connected to the source vertex. */
434 if (!names_by_domain[int(AttrDomain::Edge)].is_empty()) {
435 Array<int> new_edge_offsets;
436 Array<int> new_edge_indices;
437 const GroupedSpan<int> new_edge_groups = gather_groups(
438 vert_to_edge_map, selection, new_edge_offsets, new_edge_indices);
439 for (const StringRef name : names_by_domain[int(AttrDomain::Edge)]) {
441 mix_groups_or_default(attribute.span, new_edge_groups, attribute.span.slice(new_edge_range));
442 attribute.finish();
443 }
444 }
445
446 MutableSpan<float3> positions = mesh.vert_positions_for_write();
447 MutableSpan<float3> new_positions = positions.slice(new_vert_range);
448 selection.foreach_index_optimized<int>(
449 [&](const int index, const int i) { new_positions[i] = positions[index] + offsets[index]; },
451
452 if (std::optional<MutableSpan<int>> indices = get_orig_index_layer(mesh, AttrDomain::Point)) {
453 array_utils::gather(indices->as_span(), selection, indices->slice(new_vert_range));
454 }
455 if (std::optional<MutableSpan<int>> indices = get_orig_index_layer(mesh, AttrDomain::Edge)) {
456 indices->slice(new_edge_range).fill(ORIGINDEX_NONE);
457 }
458
459 if (attribute_outputs.top_id) {
461 attributes, *attribute_outputs.top_id, AttrDomain::Point, new_vert_range);
462 }
463 if (attribute_outputs.side_id) {
465 attributes, *attribute_outputs.side_id, AttrDomain::Edge, new_edge_range);
466 }
467
468 const bool no_loose_vert_hint = mesh.runtime->loose_verts_cache.is_cached() &&
469 mesh.runtime->loose_verts_cache.data().mask.is_empty();
470 const bool no_overlapping_hint = mesh.no_overlapping_topology();
472 if (no_loose_vert_hint) {
473 mesh.tag_loose_verts_none();
474 }
475 if (no_overlapping_hint) {
476 mesh.tag_overlapping_none();
477 }
478}
479
480static void fill_quad_consistent_direction(const Span<int> other_face_verts,
481 const Span<int> other_face_edges,
482 MutableSpan<int> new_corner_verts,
483 MutableSpan<int> new_corner_edges,
484 const int vert_connected_to_face_1,
485 const int vert_connected_to_face_2,
486 const int vert_across_from_face_1,
487 const int vert_across_from_face_2,
488 const int edge_connected_to_face,
489 const int connecting_edge_1,
490 const int edge_across_from_face,
491 const int connecting_edge_2)
492{
493 /* Find the loop on the face connected to the new quad that uses the duplicate edge. */
494 bool start_with_connecting_edge = true;
495 for (const int i : other_face_edges.index_range()) {
496 if (other_face_edges[i] == edge_connected_to_face) {
497 start_with_connecting_edge = other_face_verts[i] == vert_connected_to_face_1;
498 break;
499 }
500 }
501 if (start_with_connecting_edge) {
502 new_corner_verts[0] = vert_connected_to_face_1;
503 new_corner_edges[0] = connecting_edge_1;
504 new_corner_verts[1] = vert_across_from_face_1;
505 new_corner_edges[1] = edge_across_from_face;
506 new_corner_verts[2] = vert_across_from_face_2;
507 new_corner_edges[2] = connecting_edge_2;
508 new_corner_verts[3] = vert_connected_to_face_2;
509 new_corner_edges[3] = edge_connected_to_face;
510 }
511 else {
512 new_corner_verts[0] = vert_connected_to_face_1;
513 new_corner_edges[0] = edge_connected_to_face;
514 new_corner_verts[1] = vert_connected_to_face_2;
515 new_corner_edges[1] = connecting_edge_2;
516 new_corner_verts[2] = vert_across_from_face_2;
517 new_corner_edges[2] = edge_across_from_face;
518 new_corner_verts[3] = vert_across_from_face_1;
519 new_corner_edges[3] = connecting_edge_1;
520 }
521}
522
524 const IndexMask &edge_mask,
525 const int verts_num,
526 Array<int> &r_offsets,
527 Array<int> &r_indices)
528{
529 if (edge_mask.size() == edges.size()) {
530 return bke::mesh::build_vert_to_edge_map(edges, verts_num, r_offsets, r_indices);
531 }
532 Array<int2> masked_edges(edge_mask.size());
533 array_utils::gather(edges, edge_mask, masked_edges.as_mutable_span());
534
535 bke::mesh::build_vert_to_edge_map(masked_edges, verts_num, r_offsets, r_indices);
536
537 Array<int> masked_edge_to_edge(edge_mask.size());
538 edge_mask.to_indices<int>(masked_edge_to_edge);
540 masked_edge_to_edge.as_span(), r_indices.as_span(), r_indices.as_mutable_span());
541
542 return {r_offsets.as_span(), r_indices.as_span()};
543}
545{
546 const bool no_loose_vert_hint = mesh.runtime->loose_verts_cache.is_cached() &&
547 mesh.runtime->loose_verts_cache.data().mask.is_empty();
548 const bool no_loose_edge_hint = mesh.runtime->loose_edges_cache.is_cached() &&
549 mesh.runtime->loose_edges_cache.data().mask.is_empty();
550 const bool no_overlapping_hint = mesh.no_overlapping_topology();
552 if (no_loose_vert_hint) {
553 mesh.tag_loose_verts_none();
554 }
555 if (no_loose_edge_hint) {
556 mesh.tag_loose_edges_none();
557 }
558 if (no_overlapping_hint) {
559 mesh.tag_overlapping_none();
560 }
561}
562
564 const Field<bool> &selection_field,
565 const Field<float3> &offset_field,
566 const AttributeOutputs &attribute_outputs,
567 const AttributeFilter &attribute_filter)
568{
569 const int orig_vert_size = mesh.verts_num;
570 const Span<int2> orig_edges = mesh.edges();
571 const OffsetIndices orig_faces = mesh.faces();
572 const int orig_loop_size = mesh.corners_num;
573
574 const bke::MeshFieldContext edge_context{mesh, AttrDomain::Edge};
575 FieldEvaluator edge_evaluator{edge_context, mesh.edges_num};
576 edge_evaluator.set_selection(selection_field);
577 edge_evaluator.add(offset_field);
578 edge_evaluator.evaluate();
579 const IndexMask edge_selection = edge_evaluator.get_evaluated_selection_as_mask();
580 const VArray<float3> edge_offsets = edge_evaluator.get_evaluated<float3>(0);
581 if (edge_selection.is_empty()) {
582 return;
583 }
584
585 /* Find the offsets on the vertex domain for translation. This must be done before the mesh's
586 * custom data layers are reallocated, in case the virtual array references one of them. */
587 Array<float3> vert_offsets;
588 if (!edge_offsets.is_single()) {
589 vert_offsets.reinitialize(orig_vert_size);
591 edge_selection.foreach_index([&](const int i_edge) {
592 const int2 edge = orig_edges[i_edge];
593 const float3 offset = edge_offsets[i_edge];
594 mixer.mix_in(edge[0], offset);
595 mixer.mix_in(edge[1], offset);
596 });
597 mixer.finalize();
598 }
599
600 IndexMaskMemory memory;
602 orig_edges, edge_selection, orig_vert_size, memory);
603
604 const IndexRange new_vert_range{orig_vert_size, new_verts.size()};
605 /* The extruded edges connect the original and duplicate edges. */
606 const IndexRange connect_edge_range{orig_edges.size(), new_vert_range.size()};
607 /* The duplicate edges are extruded copies of the selected edges. */
608 const IndexRange duplicate_edge_range = connect_edge_range.after(edge_selection.size());
609 /* There is a new face for every selected edge. */
610 const IndexRange new_face_range{orig_faces.size(), edge_selection.size()};
611 /* Every new face is a quad with four corners. */
612 const IndexRange new_loop_range{orig_loop_size, new_face_range.size() * 4};
613
614 MutableAttributeAccessor attributes = mesh.attributes_for_write();
615 remove_non_propagated_attributes(attributes, attribute_filter);
616
617 Array<int> edge_to_face_offsets;
618 Array<int> edge_to_face_indices;
620 orig_faces, mesh.corner_edges(), mesh.edges_num, edge_to_face_offsets, edge_to_face_indices);
621
622 Array<int> vert_to_edge_offsets;
623 Array<int> vert_to_edge_indices;
624 GroupedSpan<int> vert_to_selected_edge_map;
625 if (!is_empty_domain(attributes, {".edge_verts"}, AttrDomain::Edge)) {
626 vert_to_selected_edge_map = build_vert_to_edge_map(
627 orig_edges, edge_selection, orig_vert_size, vert_to_edge_offsets, vert_to_edge_indices);
628 }
629
633 new_vert_range.size(),
634 connect_edge_range.size() + duplicate_edge_range.size(),
635 new_face_range.size(),
636 new_loop_range.size());
637
638 const IDsByDomain names_by_domain = get_transfer_attribute_names(
639 attributes, {"position", ".edge_verts", ".corner_vert", ".corner_edge"});
640
641 MutableSpan<int2> edges = mesh.edges_for_write();
642 MutableSpan<int2> connect_edges = edges.slice(connect_edge_range);
643 MutableSpan<int2> duplicate_edges = edges.slice(duplicate_edge_range);
644 MutableSpan<int> face_offsets = mesh.face_offsets_for_write();
645 MutableSpan<int> new_face_offsets = face_offsets.slice(new_face_range);
646 MutableSpan<int> corner_verts = mesh.corner_verts_for_write();
647 MutableSpan<int> new_corner_verts = corner_verts.slice(new_loop_range);
648 MutableSpan<int> corner_edges = mesh.corner_edges_for_write();
649 MutableSpan<int> new_corner_edges = corner_edges.slice(new_loop_range);
650
651 offset_indices::fill_constant_group_size(4, orig_loop_size, new_face_offsets);
652 const OffsetIndices faces = mesh.faces();
653
654 new_verts.foreach_index_optimized<int>(
655 [&](const int src, const int dst) { connect_edges[dst] = int2(src, new_vert_range[dst]); },
657
658 {
659 Array<int> vert_to_new_vert(orig_vert_size);
660 index_mask::build_reverse_map<int>(new_verts, vert_to_new_vert);
661 for (const int i : duplicate_edges.index_range()) {
662 const int2 orig_edge = edges[edge_selection[i]];
663 const int i_new_vert_1 = vert_to_new_vert[orig_edge[0]];
664 const int i_new_vert_2 = vert_to_new_vert[orig_edge[1]];
665 duplicate_edges[i] = int2(new_vert_range[i_new_vert_1], new_vert_range[i_new_vert_2]);
666 }
667 }
668
669 edge_selection.foreach_index([&](const int64_t orig_edge_index, const int64_t i) {
670 const int2 duplicate_edge = duplicate_edges[i];
671 const int new_vert_1 = duplicate_edge[0];
672 const int new_vert_2 = duplicate_edge[1];
673 const int extrude_index_1 = new_vert_1 - orig_vert_size;
674 const int extrude_index_2 = new_vert_2 - orig_vert_size;
675
676 const int2 orig_edge = edges[orig_edge_index];
677 const Span<int> connected_faces = edge_to_face_map[orig_edge_index];
678
679 /* When there was a single face connected to the new face, we can use the old one to keep
680 * the face direction consistent. When there is more than one connected face, the new face
681 * direction is totally arbitrary and the only goal for the behavior is to be deterministic. */
682 Span<int> connected_face_verts;
683 Span<int> connected_face_edges;
684 if (connected_faces.size() == 1) {
685 const IndexRange connected_face = faces[connected_faces.first()];
686 connected_face_verts = corner_verts.slice(connected_face);
687 connected_face_edges = corner_edges.slice(connected_face);
688 }
689 fill_quad_consistent_direction(connected_face_verts,
690 connected_face_edges,
691 new_corner_verts.slice(4 * i, 4),
692 new_corner_edges.slice(4 * i, 4),
693 orig_edge[0],
694 orig_edge[1],
695 new_vert_1,
696 new_vert_2,
697 orig_edge_index,
698 connect_edge_range[extrude_index_1],
699 duplicate_edge_range[i],
700 connect_edge_range[extrude_index_2]);
701 });
702
703 /* New vertices copy the attribute values from their source vertex. */
704 gather_vert_attributes(mesh, names_by_domain[int(AttrDomain::Point)], new_verts, new_vert_range);
705
706 /* Edges parallel to original edges copy the edge attributes from the original edges. */
708 attributes, names_by_domain[int(AttrDomain::Edge)], edge_selection, duplicate_edge_range);
709
710 /* Edges connected to original vertices mix values of selected connected edges. */
711 if (!names_by_domain[int(AttrDomain::Edge)].is_empty()) {
712 Array<int> connect_edge_offsets;
713 Array<int> connect_edge_indices;
714 const GroupedSpan<int> connect_edge_groups = gather_groups(
715 vert_to_selected_edge_map, new_verts, connect_edge_offsets, connect_edge_indices);
716 for (const StringRef name : names_by_domain[int(AttrDomain::Edge)]) {
719 attribute.span, connect_edge_groups, attribute.span.slice(connect_edge_range));
720 attribute.finish();
721 }
722 }
723
724 /* Attribute values for new faces are a mix of values connected to its original edge. */
725 if (!names_by_domain[int(AttrDomain::Face)].is_empty()) {
726 Array<int> new_face_offsets;
727 Array<int> new_face_indices;
728 const GroupedSpan<int> new_face_groups = gather_groups(
729 edge_to_face_map, edge_selection, new_face_offsets, new_face_indices);
730 for (const StringRef name : names_by_domain[int(AttrDomain::Face)]) {
732 mix_groups_or_default(attribute.span, new_face_groups, attribute.span.slice(new_face_range));
733 attribute.finish();
734 }
735 }
736
737 /* New corners get the average value of all adjacent corners on original faces connected
738 * to the original edge of their face. */
739 if (!names_by_domain[int(AttrDomain::Corner)].is_empty()) {
740 /* Both corners on each vertical edge of the side face get the same value, so there are only
741 * two values to mix for each extruded edge, one for each of its vertices. Each value mixes one
742 * corner from every connected face. */
743 Array<int> vert_group_offsets(edge_selection.size() * 2 + 1);
744 edge_selection.foreach_index(
745 [&](const int orig_edge_index, const int i_edge_selection) {
746 const int faces_num = edge_to_face_map[orig_edge_index].size();
747 vert_group_offsets[2 * i_edge_selection] = faces_num;
748 vert_group_offsets[2 * i_edge_selection + 1] = faces_num;
749 },
752 vert_group_offsets);
753 Array<int> vert_group_corners(vert_groups.total_size());
754 /* The index of the mixed value used by every new corner. */
755 Array<int> new_corner_values(new_loop_range.size());
756 edge_selection.foreach_index(
757 [&](const int orig_edge_index, const int i_edge_selection) {
758 const int2 orig_edge = edges[orig_edge_index];
759 const int2 duplicate_edge = duplicate_edges[i_edge_selection];
760 const Span<int> connected_faces = edge_to_face_map[orig_edge_index];
761 const int group_1 = 2 * i_edge_selection;
762 const int group_2 = 2 * i_edge_selection + 1;
763 MutableSpan<int> corners_1 = vert_group_corners.as_mutable_span().slice(
764 vert_groups[group_1]);
765 MutableSpan<int> corners_2 = vert_group_corners.as_mutable_span().slice(
766 vert_groups[group_2]);
767 for (const int i_face : connected_faces.index_range()) {
768 for (const int corner : faces[connected_faces[i_face]]) {
769 if (corner_verts[corner] == orig_edge[0]) {
770 corners_1[i_face] = corner;
771 }
772 else if (corner_verts[corner] == orig_edge[1]) {
773 corners_2[i_face] = corner;
774 }
775 }
776 }
777 /* Instead of replicating the order in #fill_quad_consistent_direction here, it's
778 * simpler to match the corners based on the vertex indices. */
779 for (const int new_corner : IndexRange(4 * i_edge_selection, 4)) {
780 const int vert = new_corner_verts[new_corner];
781 new_corner_values[new_corner] = ELEM(vert, orig_edge[0], duplicate_edge[0]) ? group_1 :
782 group_2;
783 }
784 },
786
787 const GroupedSpan<int> vert_group_corners_map(vert_groups, vert_group_corners);
788 for (const StringRef name : names_by_domain[int(AttrDomain::Corner)]) {
790 GArray<> values(attribute.span.type(), vert_groups.size());
791 const CPPType &type = attribute.span.type();
793 attribute.span, vert_group_corners_map, GPointer(type, type.default_value()), values);
795 values.as_span(), new_corner_values, attribute.span.slice(new_loop_range));
796 attribute.finish();
797 }
798 }
799
800 MutableSpan<float3> positions = mesh.vert_positions_for_write();
801 MutableSpan<float3> new_positions = positions.slice(new_vert_range);
802 if (edge_offsets.is_single()) {
803 const float3 offset = edge_offsets.get_internal_single();
804 new_verts.foreach_index_optimized<int>(
805 [&](const int src, const int dst) { new_positions[dst] = positions[src] + offset; },
807 }
808 else {
809 new_verts.foreach_index_optimized<int>(
810 [&](const int src, const int dst) {
811 new_positions[dst] = positions[src] + vert_offsets[src];
812 },
814 }
815
816 if (std::optional<MutableSpan<int>> indices = get_orig_index_layer(mesh, AttrDomain::Point)) {
817 array_utils::gather(indices->as_span(), new_verts, indices->slice(new_vert_range));
818 }
819 if (std::optional<MutableSpan<int>> indices = get_orig_index_layer(mesh, AttrDomain::Edge)) {
820 indices->slice(connect_edge_range).fill(ORIGINDEX_NONE);
821 array_utils::gather(indices->as_span(), edge_selection, indices->slice(duplicate_edge_range));
822 }
823 if (std::optional<MutableSpan<int>> indices = get_orig_index_layer(mesh, AttrDomain::Face)) {
824 indices->slice(new_face_range).fill(ORIGINDEX_NONE);
825 }
826
827 if (attribute_outputs.top_id) {
829 attributes, *attribute_outputs.top_id, AttrDomain::Edge, duplicate_edge_range);
830 }
831 if (attribute_outputs.side_id) {
833 attributes, *attribute_outputs.side_id, AttrDomain::Face, new_face_range);
834 }
835
837}
838
839static VectorSet<int> vert_indices_from_edges(const Mesh &mesh, const Span<int> edge_indices)
840{
841 const Span<int2> edges = mesh.edges();
842
843 VectorSet<int> vert_indices;
844 vert_indices.reserve(edge_indices.size());
845 for (const int i_edge : edge_indices) {
846 const int2 &edge = edges[i_edge];
847 vert_indices.add(edge[0]);
848 vert_indices.add(edge[1]);
849 }
850 return vert_indices;
851}
852
858 const Field<bool> &selection_field,
859 const Field<float3> &offset_field,
860 const AttributeOutputs &attribute_outputs,
861 const AttributeFilter &attribute_filter)
862{
863 const int orig_vert_size = mesh.verts_num;
864 const Span<int2> orig_edges = mesh.edges();
865 const OffsetIndices orig_faces = mesh.faces();
866 const Span<int> orig_corner_verts = mesh.corner_verts();
867 const int orig_loop_size = orig_corner_verts.size();
868
869 const bke::MeshFieldContext face_context{mesh, AttrDomain::Face};
870 FieldEvaluator face_evaluator{face_context, mesh.faces_num};
871 face_evaluator.set_selection(selection_field);
872 face_evaluator.add(offset_field);
873 face_evaluator.evaluate();
874 const IndexMask face_selection = face_evaluator.get_evaluated_selection_as_mask();
875 const VArray<float3> face_position_offsets = face_evaluator.get_evaluated<float3>(0);
876 if (face_selection.is_empty()) {
877 return;
878 }
879
880 Array<bool> face_selection_array(orig_faces.size());
881 face_selection.to_bools(face_selection_array);
882
883 /* Mix the offsets from the face domain to the vertex domain. Evaluate on the face domain above
884 * in order to be consistent with the selection, and to use the face normals rather than vertex
885 * normals as an offset, for example. */
886 Array<float3> vert_offsets;
887 if (!face_position_offsets.is_single()) {
888 vert_offsets.reinitialize(orig_vert_size);
890 face_selection.foreach_index([&](const int i_face) {
891 const float3 offset = face_position_offsets[i_face];
892 for (const int vert : orig_corner_verts.slice(orig_faces[i_face])) {
893 mixer.mix_in(vert, offset);
894 }
895 });
896 mixer.finalize();
897 }
898
899 /* All of the faces (selected and deselected) connected to each edge. */
900 Array<int> edge_to_face_offsets;
901 Array<int> edge_to_face_indices;
903 orig_faces, mesh.corner_edges(), mesh.edges_num, edge_to_face_offsets, edge_to_face_indices);
904
905 /* All vertices that are connected to the selected faces. */
906 IndexMaskMemory memory;
907 const IndexMask all_selected_verts = geometry::vert_selection_from_face(
908 orig_faces, face_selection, orig_corner_verts, orig_vert_size, memory);
909
910 /* Edges inside of an extruded region that are also attached to deselected edges. They must be
911 * duplicated in order to leave the old edge attached to the unchanged deselected faces. */
912 VectorSet<int> new_inner_edge_indices;
913 /* Edges inside of an extruded region. Their vertices should be translated
914 * with the offset, but the edges themselves should not be duplicated. */
915 Vector<int> inner_edge_indices;
916 /* The extruded face corresponding to each boundary edge (and each boundary face). */
917 Vector<int> edge_extruded_face_indices;
918 /* Edges on the outside of selected regions, either because there are no
919 * other connected faces, or because all of the other faces aren't selected. */
920 VectorSet<int> boundary_edge_indices;
921 for (const int i_edge : orig_edges.index_range()) {
922 const Span<int> faces = edge_to_face_map[i_edge];
923
924 int i_selected_face = -1;
925 int deselected_face_count = 0;
926 int selected_face_count = 0;
927 for (const int i_other_face : faces) {
928 if (face_selection_array[i_other_face]) {
929 selected_face_count++;
930 i_selected_face = i_other_face;
931 }
932 else {
933 deselected_face_count++;
934 }
935 }
936
937 if (selected_face_count == 1) {
938 /* If there is only one selected face connected to the edge,
939 * the edge should be extruded to form a "side face". */
940 boundary_edge_indices.add_new(i_edge);
941 edge_extruded_face_indices.append(i_selected_face);
942 }
943 else if (selected_face_count > 1) {
944 /* The edge is inside an extruded region of faces. */
945 if (deselected_face_count > 0) {
946 /* Add edges that are also connected to deselected edges to a separate list. */
947 new_inner_edge_indices.add_new(i_edge);
948 }
949 else {
950 /* Otherwise, just keep track of edges inside the region so that
951 * we can reattach them to duplicated vertices if necessary. */
952 inner_edge_indices.append(i_edge);
953 }
954 }
955 }
956
957 VectorSet<int> new_vert_indices = vert_indices_from_edges(mesh, boundary_edge_indices);
958 /* Before adding the rest of the new vertices from the new inner edges, store the number
959 * of new vertices from the boundary edges, since this is the number of connecting edges. */
960 const int extruded_vert_size = new_vert_indices.size();
961
962 /* The vertices attached to duplicate inner edges also have to be duplicated. */
963 for (const int i_edge : new_inner_edge_indices) {
964 const int2 &edge = orig_edges[i_edge];
965 new_vert_indices.add(edge[0]);
966 new_vert_indices.add(edge[1]);
967 }
968
969 /* New vertices forming the duplicated boundary edges and the ends of the new inner edges. */
970 const IndexRange new_vert_range{orig_vert_size, new_vert_indices.size()};
971 /* One edge connects each selected vertex to a new vertex on the extruded faces. */
972 const IndexRange connect_edge_range{orig_edges.size(), extruded_vert_size};
973 /* Each selected edge is duplicated to form a single edge on the extrusion. */
974 const IndexRange boundary_edge_range = connect_edge_range.after(boundary_edge_indices.size());
975 /* Duplicated edges inside regions that were connected to deselected faces. */
976 const IndexRange new_inner_edge_range = boundary_edge_range.after(new_inner_edge_indices.size());
977 /* Each edge selected for extrusion is extruded into a single face. */
978 const IndexRange side_face_range{orig_faces.size(), boundary_edge_indices.size()};
979 /* The loops that form the new side faces. */
980 const IndexRange side_loop_range{orig_corner_verts.size(), side_face_range.size() * 4};
981
982 MutableAttributeAccessor attributes = mesh.attributes_for_write();
983 remove_non_propagated_attributes(attributes, attribute_filter);
984
988 new_vert_range.size(),
989 connect_edge_range.size() + boundary_edge_range.size() + new_inner_edge_range.size(),
990 side_face_range.size(),
991 side_loop_range.size());
992
993 const IDsByDomain names_by_domain = get_transfer_attribute_names(
994 attributes, {".corner_vert", ".corner_edge", ".edge_verts"});
995
996 MutableSpan<int2> edges = mesh.edges_for_write();
997 MutableSpan<int2> connect_edges = edges.slice(connect_edge_range);
998 MutableSpan<int2> boundary_edges = edges.slice(boundary_edge_range);
999 MutableSpan<int2> new_inner_edges = edges.slice(new_inner_edge_range);
1000 MutableSpan<int> face_offsets = mesh.face_offsets_for_write();
1001 MutableSpan<int> new_face_offsets = face_offsets.slice(side_face_range);
1002 MutableSpan<int> corner_verts = mesh.corner_verts_for_write();
1003 MutableSpan<int> new_corner_verts = corner_verts.slice(side_loop_range);
1004 MutableSpan<int> corner_edges = mesh.corner_edges_for_write();
1005 MutableSpan<int> new_corner_edges = corner_edges.slice(side_loop_range);
1006
1007 /* Initialize the new side faces. */
1008 if (!new_face_offsets.is_empty()) {
1009 offset_indices::fill_constant_group_size(4, orig_loop_size, new_face_offsets);
1010 }
1011 const OffsetIndices faces = mesh.faces();
1012
1013 /* Initialize the edges that form the sides of the extrusion. */
1014 for (const int i : connect_edges.index_range()) {
1015 connect_edges[i] = int2(new_vert_indices[i], new_vert_range[i]);
1016 }
1017
1018 /* Initialize the edges that form the top of the extrusion. */
1019 for (const int i : boundary_edges.index_range()) {
1020 const int2 &orig_edge = edges[boundary_edge_indices[i]];
1021 const int i_new_vert_1 = new_vert_indices.index_of(orig_edge[0]);
1022 const int i_new_vert_2 = new_vert_indices.index_of(orig_edge[1]);
1023 boundary_edges[i] = int2(new_vert_range[i_new_vert_1], new_vert_range[i_new_vert_2]);
1024 }
1025
1026 /* Initialize the new edges inside of extrude regions. */
1027 for (const int i : new_inner_edge_indices.index_range()) {
1028 const int2 &orig_edge = edges[new_inner_edge_indices[i]];
1029 const int i_new_vert_1 = new_vert_indices.index_of(orig_edge[0]);
1030 const int i_new_vert_2 = new_vert_indices.index_of(orig_edge[1]);
1031 new_inner_edges[i] = int2(new_vert_range[i_new_vert_1], new_vert_range[i_new_vert_2]);
1032 }
1033
1034 /* Connect original edges inside face regions to any new vertices, if necessary. */
1035 for (const int i : inner_edge_indices) {
1036 int2 &edge = edges[i];
1037 const int i_new_vert_1 = new_vert_indices.index_of_try(edge[0]);
1038 const int i_new_vert_2 = new_vert_indices.index_of_try(edge[1]);
1039 if (i_new_vert_1 != -1) {
1040 edge[0] = new_vert_range[i_new_vert_1];
1041 }
1042 if (i_new_vert_2 != -1) {
1043 edge[1] = new_vert_range[i_new_vert_2];
1044 }
1045 }
1046
1047 /* Connect the selected faces to the extruded or duplicated edges and the new vertices. */
1048 face_selection.foreach_index([&](const int i_face) {
1049 for (const int corner : faces[i_face]) {
1050 const int i_new_vert = new_vert_indices.index_of_try(corner_verts[corner]);
1051 if (i_new_vert != -1) {
1052 corner_verts[corner] = new_vert_range[i_new_vert];
1053 }
1054 const int i_boundary_edge = boundary_edge_indices.index_of_try(corner_edges[corner]);
1055 if (i_boundary_edge != -1) {
1056 corner_edges[corner] = boundary_edge_range[i_boundary_edge];
1057 /* Skip the next check, an edge cannot be both a boundary edge and an inner edge. */
1058 continue;
1059 }
1060 const int i_new_inner_edge = new_inner_edge_indices.index_of_try(corner_edges[corner]);
1061 if (i_new_inner_edge != -1) {
1062 corner_edges[corner] = new_inner_edge_range[i_new_inner_edge];
1063 }
1064 }
1065 });
1066
1067 /* Create the faces on the sides of extruded regions. */
1068 for (const int i : boundary_edge_indices.index_range()) {
1069 const int2 &boundary_edge = boundary_edges[i];
1070 const int new_vert_1 = boundary_edge[0];
1071 const int new_vert_2 = boundary_edge[1];
1072 const int extrude_index_1 = new_vert_1 - orig_vert_size;
1073 const int extrude_index_2 = new_vert_2 - orig_vert_size;
1074
1075 const IndexRange extrude_face = faces[edge_extruded_face_indices[i]];
1076
1077 fill_quad_consistent_direction(corner_verts.slice(extrude_face),
1078 corner_edges.slice(extrude_face),
1079 new_corner_verts.slice(4 * i, 4),
1080 new_corner_edges.slice(4 * i, 4),
1081 new_vert_1,
1082 new_vert_2,
1083 new_vert_indices[extrude_index_1],
1084 new_vert_indices[extrude_index_2],
1085 boundary_edge_range[i],
1086 connect_edge_range[extrude_index_1],
1087 boundary_edge_indices[i],
1088 connect_edge_range[extrude_index_2]);
1089 }
1090
1091 /* New vertices copy the attributes from their original vertices. */
1093 mesh, names_by_domain[int(AttrDomain::Point)], new_vert_indices, new_vert_range);
1094
1095 /* New faces on the side of extrusions get the values from the corresponding selected face. */
1096 gather_attributes(attributes,
1097 names_by_domain[int(AttrDomain::Face)],
1098 edge_extruded_face_indices,
1099 side_face_range);
1100
1101 if (!names_by_domain[int(AttrDomain::Edge)].is_empty()) {
1102 IndexMaskMemory memory;
1103 const IndexMask boundary_edge_mask = IndexMask::from_indices<int>(boundary_edge_indices,
1104 memory);
1105
1106 Array<int> vert_to_edge_offsets;
1107 Array<int> vert_to_edge_indices;
1108 const GroupedSpan<int> vert_to_boundary_edge_map = build_vert_to_edge_map(
1109 edges, boundary_edge_mask, mesh.verts_num, vert_to_edge_offsets, vert_to_edge_indices);
1110 Array<int> connect_edge_offsets;
1111 Array<int> connect_edge_indices;
1112 const GroupedSpan<int> connect_edge_groups = gather_groups(
1113 vert_to_boundary_edge_map,
1114 new_vert_indices.as_span().take_front(connect_edge_range.size()),
1115 connect_edge_offsets,
1116 connect_edge_indices);
1117
1118 for (const StringRef name : names_by_domain[int(AttrDomain::Edge)]) {
1120
1121 /* Edges parallel to original edges copy the edge attributes from the original edges. */
1122 GMutableSpan boundary_data = attribute.span.slice(boundary_edge_range);
1123 array_utils::gather(attribute.span, boundary_edge_mask, boundary_data);
1124
1125 /* Edges inside of face regions also just duplicate their source data. */
1126 GMutableSpan new_inner_data = attribute.span.slice(new_inner_edge_range);
1127 bke::attribute_math::gather(attribute.span, new_inner_edge_indices, new_inner_data);
1128
1129 /* Edges connected to original vertices mix values of selected connected edges. */
1131 attribute.span, connect_edge_groups, attribute.span.slice(connect_edge_range));
1132 attribute.finish();
1133 }
1134 }
1135
1136 /* New corners get the values from the corresponding corner on the extruded face. */
1137 if (!names_by_domain[int(AttrDomain::Corner)].is_empty()) {
1138 Array<int> orig_corners(side_loop_range.size());
1139 threading::parallel_for(boundary_edge_indices.index_range(), 256, [&](const IndexRange range) {
1140 for (const int i_boundary_edge : range) {
1141 const int2 &boundary_edge = boundary_edges[i_boundary_edge];
1142 const int new_vert_1 = boundary_edge[0];
1143 const int new_vert_2 = boundary_edge[1];
1144 const int orig_vert_1 = new_vert_indices[new_vert_1 - orig_vert_size];
1145 const int orig_vert_2 = new_vert_indices[new_vert_2 - orig_vert_size];
1146
1147 /* Retrieve the data for the first two sides of the quad from the extruded
1148 * face, which we generally expect to have just a small amount of sides. This
1149 * loop could be eliminated by adding a cache of connected loops (which would
1150 * also simplify some of the other code to find the correct loops on the extruded
1151 * face). */
1152 int corner_1;
1153 int corner_2;
1154 for (const int corner : faces[edge_extruded_face_indices[i_boundary_edge]]) {
1155 if (corner_verts[corner] == new_vert_1) {
1156 corner_1 = corner;
1157 }
1158 if (corner_verts[corner] == new_vert_2) {
1159 corner_2 = corner;
1160 }
1161 }
1162
1163 /* Instead of replicating the order in #fill_quad_consistent_direction here, it's
1164 * simpler (though probably slower) to just match the corner data based on the
1165 * vertex indices. */
1166 for (const int i : IndexRange(4 * i_boundary_edge, 4)) {
1167 if (ELEM(new_corner_verts[i], new_vert_1, orig_vert_1)) {
1168 orig_corners[i] = corner_1;
1169 }
1170 else if (ELEM(new_corner_verts[i], new_vert_2, orig_vert_2)) {
1171 orig_corners[i] = corner_2;
1172 }
1173 }
1174 }
1175 });
1177 attributes, names_by_domain[int(AttrDomain::Corner)], orig_corners, side_loop_range);
1178 }
1179
1180 /* Translate vertices based on the offset. If the vertex is used by a selected edge, it will
1181 * have been duplicated and only the new vertex should use the offset. Otherwise the vertex might
1182 * still need an offset, but it was reused on the inside of a region of extruded faces. */
1183 MutableSpan<float3> positions = mesh.vert_positions_for_write();
1184 if (face_position_offsets.is_single()) {
1185 const float3 offset = face_position_offsets.get_internal_single();
1186 all_selected_verts.foreach_index(
1187 [&](const int orig_vert) {
1188 const int i_new = new_vert_indices.index_of_try(orig_vert);
1189 if (i_new == -1) {
1190 positions[orig_vert] += offset;
1191 }
1192 else {
1193 positions[new_vert_range[i_new]] += offset;
1194 }
1195 },
1196 exec_mode::grain_size(1024));
1197 }
1198 else {
1199 all_selected_verts.foreach_index(
1200 [&](const int orig_vert) {
1201 const int i_new = new_vert_indices.index_of_try(orig_vert);
1202 const float3 offset = vert_offsets[orig_vert];
1203 if (i_new == -1) {
1204 positions[orig_vert] += offset;
1205 }
1206 else {
1207 positions[new_vert_range[i_new]] += offset;
1208 }
1209 },
1210 exec_mode::grain_size(1024));
1211 }
1212
1213 if (std::optional<MutableSpan<int>> indices = get_orig_index_layer(mesh, AttrDomain::Point)) {
1215 indices->as_span(), new_vert_indices.as_span(), indices->slice(new_vert_range));
1216 }
1217 if (std::optional<MutableSpan<int>> indices = get_orig_index_layer(mesh, AttrDomain::Edge)) {
1218 indices->slice(connect_edge_range).fill(ORIGINDEX_NONE);
1219 array_utils::gather(indices->as_span(),
1220 new_inner_edge_indices.as_span(),
1221 indices->slice(new_inner_edge_range));
1223 indices->as_span(), boundary_edge_indices.as_span(), indices->slice(boundary_edge_range));
1224 }
1225 if (std::optional<MutableSpan<int>> indices = get_orig_index_layer(mesh, AttrDomain::Face)) {
1227 indices->as_span(), edge_extruded_face_indices.as_span(), indices->slice(side_face_range));
1228 }
1229
1230 if (attribute_outputs.top_id) {
1232 attributes, *attribute_outputs.top_id, AttrDomain::Face, face_selection);
1233 }
1234 if (attribute_outputs.side_id) {
1236 attributes, *attribute_outputs.side_id, AttrDomain::Face, side_face_range);
1237 }
1238
1240}
1241
1243 const Field<bool> &selection_field,
1244 const Field<float3> &offset_field,
1245 const AttributeOutputs &attribute_outputs,
1246 const AttributeFilter &attribute_filter)
1247{
1248 const int orig_vert_size = mesh.verts_num;
1249 const int orig_edge_size = mesh.edges_num;
1250 const OffsetIndices orig_faces = mesh.faces();
1251 const Span<int> orig_corner_verts = mesh.corner_verts();
1252 const int orig_loop_size = orig_corner_verts.size();
1253
1254 /* Use an array for the result of the evaluation because the mesh is reallocated before
1255 * the vertices are moved, and the evaluated result might reference an attribute. */
1256 Array<float3> face_offset(orig_faces.size());
1257 const bke::MeshFieldContext face_context{mesh, AttrDomain::Face};
1258 FieldEvaluator face_evaluator{face_context, mesh.faces_num};
1259 face_evaluator.set_selection(selection_field);
1260 face_evaluator.add_with_destination(offset_field, face_offset.as_mutable_span());
1261 face_evaluator.evaluate();
1262 const IndexMask face_selection = face_evaluator.get_evaluated_selection_as_mask();
1263 if (face_selection.is_empty()) {
1264 return;
1265 }
1266
1267 /* Build an array of offsets into the new data for each face. This is used to facilitate
1268 * parallelism later on by avoiding the need to keep track of an offset when iterating through
1269 * all faces. */
1270 Array<int> group_per_face_data(face_selection.size() + 1);
1272 orig_faces, face_selection, group_per_face_data);
1273 const int extrude_corner_size = group_per_face.total_size();
1274
1275 const IndexRange new_vert_range{orig_vert_size, extrude_corner_size};
1276 /* One edge connects each selected vertex to a new vertex on the extruded faces. */
1277 const IndexRange connect_edge_range{orig_edge_size, extrude_corner_size};
1278 /* Each selected edge is duplicated to form a single edge on the extrusion. */
1279 const IndexRange duplicate_edge_range = connect_edge_range.after(extrude_corner_size);
1280 /* Each edge selected for extrusion is extruded into a single face. */
1281 const IndexRange side_face_range{orig_faces.size(), duplicate_edge_range.size()};
1282 const IndexRange side_loop_range{orig_loop_size, side_face_range.size() * 4};
1283
1284 MutableAttributeAccessor attributes = mesh.attributes_for_write();
1285 remove_non_propagated_attributes(attributes, attribute_filter);
1286
1290 new_vert_range.size(),
1291 connect_edge_range.size() + duplicate_edge_range.size(),
1292 side_face_range.size(),
1293 side_loop_range.size());
1294
1295 const IDsByDomain names_by_domain = get_transfer_attribute_names(
1296 attributes, {"position", ".edge_verts", ".corner_vert", ".corner_edge"});
1297
1298 MutableSpan<float3> positions = mesh.vert_positions_for_write();
1299 MutableSpan<float3> new_positions = positions.slice(new_vert_range);
1300 MutableSpan<int2> edges = mesh.edges_for_write();
1301 MutableSpan<int2> connect_edges = edges.slice(connect_edge_range);
1302 MutableSpan<int2> duplicate_edges = edges.slice(duplicate_edge_range);
1303 MutableSpan<int> face_offsets = mesh.face_offsets_for_write();
1304 MutableSpan<int> new_face_offsets = face_offsets.slice(side_face_range);
1305 MutableSpan<int> corner_verts = mesh.corner_verts_for_write();
1306 MutableSpan<int> corner_edges = mesh.corner_edges_for_write();
1307
1308 offset_indices::fill_constant_group_size(4, orig_loop_size, new_face_offsets);
1309 const OffsetIndices faces = mesh.faces();
1310
1311 /* For every selected face, change it to use the new extruded vertices and the duplicate
1312 * edges, and build the faces that form the sides of the extrusion. Build "original index"
1313 * arrays for the new vertices and edges so they can be accessed later.
1314 *
1315 * Filling some of this data like the new edges or faces could be easily split into
1316 * separate loops, which may or may not be faster, but would involve more duplication. */
1317 Array<int> new_vert_indices(extrude_corner_size);
1318 Array<int> duplicate_edge_indices(extrude_corner_size);
1319 face_selection.foreach_index(
1320 [&](const int64_t index, const int64_t i_selection) {
1321 const IndexRange extrude_range = group_per_face[i_selection];
1322
1323 const IndexRange face = faces[index];
1324 MutableSpan<int> face_verts = corner_verts.slice(face);
1325 MutableSpan<int> face_edges = corner_edges.slice(face);
1326
1327 for (const int i : face.index_range()) {
1328 const int i_extrude = extrude_range[i];
1329 new_vert_indices[i_extrude] = face_verts[i];
1330 duplicate_edge_indices[i_extrude] = face_edges[i];
1331
1332 face_verts[i] = new_vert_range[i_extrude];
1333 face_edges[i] = duplicate_edge_range[i_extrude];
1334 }
1335
1336 for (const int i : face.index_range()) {
1337 const int i_next = (i == face.size() - 1) ? 0 : i + 1;
1338 const int i_extrude = extrude_range[i];
1339 const int i_extrude_next = extrude_range[i_next];
1340
1341 const int i_duplicate_edge = duplicate_edge_range[i_extrude];
1342 const int new_vert = new_vert_range[i_extrude];
1343 const int new_vert_next = new_vert_range[i_extrude_next];
1344
1345 const int orig_edge = duplicate_edge_indices[i_extrude];
1346
1347 const int orig_vert = new_vert_indices[i_extrude];
1348 const int orig_vert_next = new_vert_indices[i_extrude_next];
1349
1350 duplicate_edges[i_extrude] = int2(new_vert, new_vert_next);
1351
1352 MutableSpan<int> side_face_verts = corner_verts.slice(side_loop_range[i_extrude * 4], 4);
1353 MutableSpan<int> side_face_edges = corner_edges.slice(side_loop_range[i_extrude * 4], 4);
1354 side_face_verts[0] = new_vert_next;
1355 side_face_edges[0] = i_duplicate_edge;
1356 side_face_verts[1] = new_vert;
1357 side_face_edges[1] = connect_edge_range[i_extrude];
1358 side_face_verts[2] = orig_vert;
1359 side_face_edges[2] = orig_edge;
1360 side_face_verts[3] = orig_vert_next;
1361 side_face_edges[3] = connect_edge_range[i_extrude_next];
1362
1363 connect_edges[i_extrude] = int2(orig_vert, new_vert);
1364 }
1365 },
1367
1368 /* New vertices copy the attributes from their original vertices. */
1370 mesh, names_by_domain[int(AttrDomain::Point)], new_vert_indices, new_vert_range);
1371
1372 /* The data for the duplicate edge is simply a copy of the original edge's data. */
1373 gather_attributes(attributes,
1374 names_by_domain[int(AttrDomain::Edge)],
1375 duplicate_edge_indices,
1376 duplicate_edge_range);
1377
1378 /* For extruded edges, mix the data from the two neighboring original edges of the face. */
1379 if (!names_by_domain[int(AttrDomain::Edge)].is_empty()) {
1380 Array<int2> neighbor_edges(connect_edge_range.size());
1381 face_selection.foreach_index(
1382 [&](const int64_t index, const int64_t i_selection) {
1383 const IndexRange face = faces[index];
1384 const IndexRange extrude_range = group_per_face[i_selection];
1385
1386 for (const int i : face.index_range()) {
1387 const int i_prev = (i == 0) ? face.size() - 1 : i - 1;
1388 const int i_extrude = extrude_range[i];
1389 const int i_extrude_prev = extrude_range[i_prev];
1390 neighbor_edges[i_extrude] = int2(duplicate_edge_indices[i_extrude],
1391 duplicate_edge_indices[i_extrude_prev]);
1392 }
1393 },
1394 exec_mode::grain_size(1024));
1395
1396 Array<int> neighbor_edge_offsets(connect_edge_range.size() + 1);
1397 offset_indices::fill_constant_group_size(2, 0, neighbor_edge_offsets);
1398 const GroupedSpan<int> neighbor_edge_groups(neighbor_edge_offsets.as_span(),
1399 neighbor_edges.as_span().cast<int>());
1400 for (const StringRef name : names_by_domain[int(AttrDomain::Edge)]) {
1403 attribute.span, neighbor_edge_groups, attribute.span.slice(connect_edge_range));
1404 attribute.finish();
1405 }
1406 }
1407
1408 /* Each side face gets the values from the corresponding new face. */
1409 for (const StringRef name : names_by_domain[int(AttrDomain::Face)]) {
1412 group_per_face, face_selection, attribute.span, attribute.span.slice(side_face_range));
1413 attribute.finish();
1414 }
1415
1416 /* Each corner on a side face gets its value from the matching corner on an extruded face. */
1417 if (!names_by_domain[int(AttrDomain::Corner)].is_empty()) {
1418 Array<int> orig_corners(side_loop_range.size());
1419 face_selection.foreach_index(
1420 [&](const int64_t index, const int64_t i_selection) {
1421 const IndexRange face = faces[index];
1422 const IndexRange extrude_range = group_per_face[i_selection];
1423
1424 for (const int i : face.index_range()) {
1425 const IndexRange side_face(extrude_range[i] * 4, 4);
1426 /* The two corners on each side of the side face get the data from the
1427 * matching corners of the extruded face. This order depends on the loop
1428 * filling the loop indices. */
1429 const int corner = face[i];
1430 const int next_corner = bke::mesh::face_corner_next(face, corner);
1431 orig_corners[side_face[0]] = next_corner;
1432 orig_corners[side_face[1]] = corner;
1433 orig_corners[side_face[2]] = corner;
1434 orig_corners[side_face[3]] = next_corner;
1435 }
1436 },
1439 attributes, names_by_domain[int(AttrDomain::Corner)], orig_corners, side_loop_range);
1440 }
1441
1442 /* Offset the new vertices. */
1443 face_selection.foreach_index(
1444 [&](const int64_t index, const int64_t i_selection) {
1445 const IndexRange extrude_range = group_per_face[i_selection];
1446 for (const int i : extrude_range) {
1447 const int src_vert = new_vert_indices[i];
1448 new_positions[i] = positions[src_vert] + face_offset[index];
1449 }
1450 },
1451 exec_mode::grain_size(1025));
1452
1453 if (std::optional<MutableSpan<int>> indices = get_orig_index_layer(mesh, AttrDomain::Point)) {
1455 indices->as_span(), new_vert_indices.as_span(), indices->slice(new_vert_range));
1456 }
1457 if (std::optional<MutableSpan<int>> indices = get_orig_index_layer(mesh, AttrDomain::Edge)) {
1458 indices->slice(connect_edge_range).fill(ORIGINDEX_NONE);
1459 array_utils::gather(indices->as_span(),
1460 duplicate_edge_indices.as_span(),
1461 indices->slice(duplicate_edge_range));
1462 }
1463 if (std::optional<MutableSpan<int>> indices = get_orig_index_layer(mesh, AttrDomain::Face)) {
1465 group_per_face, face_selection, indices->as_span(), indices->slice(side_face_range));
1466 }
1467
1468 if (attribute_outputs.top_id) {
1470 attributes, *attribute_outputs.top_id, AttrDomain::Face, face_selection);
1471 }
1472 if (attribute_outputs.side_id) {
1474 attributes, *attribute_outputs.side_id, AttrDomain::Face, side_face_range);
1475 }
1476
1478}
1479
1481{
1482 GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh"_ustr);
1483 Field<bool> selection = params.extract_input<Field<bool>>("Selection"_ustr);
1484 Field<float3> offset_field = params.extract_input<Field<float3>>("Offset"_ustr);
1485 Field<float> scale_field = params.extract_input<Field<float>>("Offset Scale"_ustr);
1486 const NodeGeometryExtrudeMesh &storage = node_storage(params.node());
1488
1489 /* Create a combined field from the offset and the scale so the field evaluator
1490 * can take care of the multiplication and to simplify each extrude function. */
1491 const Field<float3> final_offset{
1493 {std::move(offset_field), std::move(scale_field)})};
1494
1495 AttributeOutputs attribute_outputs;
1496 attribute_outputs.top_id = params.get_output_anonymous_attribute_id_if_needed("Top"_ustr);
1497 attribute_outputs.side_id = params.get_output_anonymous_attribute_id_if_needed("Side"_ustr);
1498
1499 const bool extrude_individual = mode == GEO_NODE_EXTRUDE_MESH_FACES &&
1500 params.extract_input<bool>("Individual"_ustr);
1501
1502 const NodeAttributeFilter &attribute_filter = params.get_attribute_filter("Mesh"_ustr);
1503
1504 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
1505 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
1506
1507 switch (mode) {
1510 *mesh, selection, final_offset, attribute_outputs, attribute_filter);
1511 break;
1513 extrude_mesh_edges(*mesh, selection, final_offset, attribute_outputs, attribute_filter);
1514 break;
1516 if (extrude_individual) {
1518 *mesh, selection, final_offset, attribute_outputs, attribute_filter);
1519 }
1520 else {
1522 *mesh, selection, final_offset, attribute_outputs, attribute_filter);
1523 }
1524 break;
1525 }
1526 }
1527
1529 }
1530 });
1531
1532 params.set_output("Mesh"_ustr, std::move(geometry_set));
1533}
1534
1535static void node_rna(StructRNA *srna)
1536{
1537 static const EnumPropertyItem mode_items[] = {
1538 {GEO_NODE_EXTRUDE_MESH_VERTICES, "VERTICES", 0, "Vertices", ""},
1539 {GEO_NODE_EXTRUDE_MESH_EDGES, "EDGES", 0, "Edges", ""},
1540 {GEO_NODE_EXTRUDE_MESH_FACES, "FACES", 0, "Faces", ""},
1541 {0, nullptr, 0, nullptr, nullptr},
1542 };
1543
1544 RNA_def_node_enum(srna,
1545 "mode",
1546 "Mode",
1547 "",
1548 mode_items,
1551}
1552
1553static void node_register()
1554{
1555 static bke::bNodeType ntype;
1556 geo_node_type_base(&ntype, "GeometryNodeExtrudeMesh"_ustr, GEO_NODE_EXTRUDE_MESH);
1557 ntype.ui_name = "Extrude Mesh";
1558 ntype.ui_description =
1559 "Generate new vertices, edges, or faces from selected elements and move them based on an "
1560 "offset while keeping them connected by their boundary";
1561 ntype.enum_name_legacy = "EXTRUDE_MESH";
1563 ntype.declare = node_declare;
1564 ntype.initfunc = node_init;
1567 ntype, "NodeGeometryExtrudeMesh", node_free_standard_storage, node_copy_standard_storage);
1568 ntype.draw_buttons = node_layout;
1570
1571 node_rna(ntype.rna_ext.srna);
1572}
1573NOD_REGISTER_NODE(node_register)
1574
1575} // namespace blender::nodes::node_geo_extrude_mesh_cc
#define ATTR_DOMAIN_NUM
CustomData interface, see also DNA_customdata_types.h.
#define ORIGINDEX_NONE
support for deformation groups and hooks.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1353
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_EXTRUDE_MESH
#define BLT_I18NCONTEXT_ID_NODETREE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
#define UI_ITEM_NONE
#define BLI_assert_unreachable()
#define ELEM(...)
Span< T > as_span() const
Definition BLI_array.hh:254
MutableSpan< T > as_mutable_span()
Definition BLI_array.hh:259
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
void fill_assign_indices(const void *value, void *dst, const IndexMask &mask) const
bool is() const
const void * default_value() const
GSpan as_span() const
const CPPType & type() const
GPointer()=default
const void * get() const
const CPPType & type() const
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_indices(Span< T > indices, LinearAllocator<> &memory)
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr IndexRange after(int64_t n) const
constexpr IndexRange index_range() const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:579
constexpr bool is_empty() const
Definition BLI_span.hh:515
constexpr IndexRange index_range() const
Definition BLI_span.hh:676
IndexRange index_range() const
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
bool is_empty() const
Definition BLI_set.hh:614
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr const T & first() const
Definition BLI_span.hh:319
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
int64_t index_of_try(const Key &key) const
bool add(const Key &key)
void reserve(const int64_t n)
int64_t size() const
int64_t index_of(const Key &key) const
IndexRange index_range() const
Span< Key > as_span() const
void add_new(const Key &key)
void append(const T &value)
Set< StringRefNull > all_names() const
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
bool contains(StringRef name) const
int domain_size(const AttrDomain domain) const
std::optional< AttrStorageType > storage_type
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_for_write_span(StringRef name)
void set_selection(Field< bool > selection)
int add(GField field, GVArray *varray_ptr)
IndexMask get_evaluated_selection_as_mask() const
int add_with_destination(GField field, GVMutableArray dst)
const GVArray & get_evaluated(const int field_index) const
void foreach_index_optimized(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask slice(IndexRange range) const
void to_indices(MutableSpan< T > r_indices) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
void to_bools(MutableSpan< bool > r_bools) const
static FieldOperationPtr from(std::shared_ptr< const mf::MultiFunction > fn, Vector< GField > inputs)
Definition field.cc:252
NodeAttributeFilter get_attribute_filter(const UString output_identifier) const
std::optional< std::string > get_output_anonymous_attribute_id_if_needed(const UString output_identifier, const bool force_create=false)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
#define storage(slot, qualifiers)
#define attribute(slot)
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void gather_to_groups(const OffsetIndices< int > dst_offsets, const IndexMask &src_selection, const Span< T > src, MutableSpan< T > dst)
void gather_group_to_group(const OffsetIndices< int > src_offsets, const OffsetIndices< int > dst_offsets, const IndexMask &selection, const Span< T > src, MutableSpan< T > dst)
void gather(GSpan src, Span< int > map, GMutableSpan dst)
void gather_to_groups(OffsetIndices< int > dst_offsets, const IndexMask &src_selection, GSpan src, GMutableSpan dst)
void mix_groups(GSpan src, OffsetIndices< int > groups, Span< int > all_indices, std::optional< Span< float > > all_weights, GMutableSpan dst)
typename DefaultPropagationMixerStruct< T >::type DefaultPropagationMixer
GroupedSpan< int > build_edge_to_face_map(OffsetIndices< int > faces, Span< int > corner_edges, int edges_num, Array< int > &r_offsets, Array< int > &r_indices)
int face_corner_next(const IndexRange face, const int corner)
Definition BKE_mesh.hh:315
GroupedSpan< int > build_vert_to_edge_map(Span< int2 > edges, int verts_num, Array< int > &r_offsets, Array< int > &r_indices)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void gather_deform_verts(Span< MDeformVert > src, Span< int > indices, MutableSpan< MDeformVert > dst)
Definition deform.cc:1774
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
constexpr ParallelGrainSize grain_size(int grain_size)
const MultiFunction & lookup(UString id)
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
void debug_randomize_mesh_order(Mesh *mesh)
Definition randomize.cc:305
IndexMask vert_selection_from_face(OffsetIndices< int > faces, const IndexMask &face_mask, Span< int > corner_verts, int verts_num, IndexMaskMemory &memory)
IndexMask vert_selection_from_edge(Span< int2 > edges, const IndexMask &edge_mask, int verts_num, IndexMaskMemory &memory)
void resize_trivial_array(T **data, const ImplicitSharingInfo **sharing_info, int64_t old_size, int64_t new_size)
template void build_reverse_map< int >(const IndexMask &mask, MutableSpan< int > r_map)
static void node_declare(NodeDeclarationBuilder &b)
static void extrude_individual_mesh_faces(Mesh &mesh, const Field< bool > &selection_field, const Field< float3 > &offset_field, const AttributeOutputs &attribute_outputs, const AttributeFilter &attribute_filter)
static void extrude_mesh_face_regions(Mesh &mesh, const Field< bool > &selection_field, const Field< float3 > &offset_field, const AttributeOutputs &attribute_outputs, const AttributeFilter &attribute_filter)
static void extrude_mesh_edges(Mesh &mesh, const Field< bool > &selection_field, const Field< float3 > &offset_field, const AttributeOutputs &attribute_outputs, const AttributeFilter &attribute_filter)
std::array< Vector< StringRef >, ATTR_DOMAIN_NUM > IDsByDomain
static IDsByDomain get_transfer_attribute_names(const AttributeAccessor attributes, const Set< StringRef > &skip)
static GPointer mixing_default_value(const CPPType &type)
static void gather_attributes(MutableAttributeAccessor attributes, const Span< StringRef > names, const Span< int > indices, const IndexRange new_range)
static VectorSet< int > vert_indices_from_edges(const Mesh &mesh, const Span< int > edge_indices)
static void gather_vert_attributes(Mesh &mesh, const Span< StringRef > names, const Span< int > indices, const IndexRange new_range)
static bool is_empty_domain(const AttributeAccessor attributes, const Set< StringRef > &skip, const AttrDomain domain)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static CustomData & mesh_custom_data_for_domain(Mesh &mesh, const AttrDomain domain)
static void extrude_mesh_vertices(Mesh &mesh, const Field< bool > &selection_field, const Field< float3 > &offset_field, const AttributeOutputs &attribute_outputs, const AttributeFilter &attribute_filter)
static void remove_non_propagated_attributes(MutableAttributeAccessor attributes, const AttributeFilter &attribute_filter)
static std::optional< MutableSpan< int > > get_orig_index_layer(Mesh &mesh, const AttrDomain domain)
static void fill_quad_consistent_direction(const Span< int > other_face_verts, const Span< int > other_face_edges, MutableSpan< int > new_corner_verts, MutableSpan< int > new_corner_edges, const int vert_connected_to_face_1, const int vert_connected_to_face_2, const int vert_across_from_face_1, const int vert_across_from_face_2, const int edge_connected_to_face, const int connecting_edge_1, const int edge_across_from_face, const int connecting_edge_2)
static void node_geo_exec(GeoNodeExecParams params)
static void save_selection_as_attribute(MutableAttributeAccessor attributes, const StringRef name, const AttrDomain domain, const IndexMask &selection)
static void mix_groups_or_default(const GSpan src, const GroupedSpan< int > groups, const GPointer default_value, GMutableSpan dst)
static void expand_mesh(Mesh &mesh, const int vert_expand, const int edge_expand, const int face_expand, const int loop_expand)
static GroupedSpan< int > build_vert_to_edge_map(const Span< int2 > edges, const IndexMask &edge_mask, const int verts_num, Array< int > &r_offsets, Array< int > &r_indices)
static GroupedSpan< int > gather_groups(const GroupedSpan< int > src_groups, const SelectionT &selection, Array< int > &r_offsets, Array< int > &r_indices)
static void node_init(bNodeTree *, bNode *node)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
void fill_constant_group_size(int size, int start_offset, MutableSpan< int > offsets)
OffsetIndices< int > gather_selected_offsets(OffsetIndices< int > src_offsets, const IndexMask &selection, int start_offset, MutableSpan< int > dst_offsets)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
bool CustomData_free_layers(CustomData *data, eCustomDataType type)
void CustomData_realloc(CustomData *data, int old_size, int new_size, eCDAllocType alloctype=CD_CONSTRUCT)
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
BMesh const char void * data
void BKE_mesh_runtime_clear_cache(Mesh *mesh)
GeometryNodeExtrudeMeshMode
@ GEO_NODE_EXTRUDE_MESH_VERTICES
@ GEO_NODE_EXTRUDE_MESH_EDGES
@ GEO_NODE_EXTRUDE_MESH_FACES
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
void * CustomData_get_layer_for_write(CustomData *data, eCustomDataType type, int totelem)
VecBase< float, 3 > float3
@ PROP_TRANSLATION
Definition RNA_types.hh:318
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
bool allow_skip(const StringRef name) const
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)