Blender V5.3
node_geo_duplicate_elements.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"
6#include "BLI_noise.hh"
8#include "BLI_span.hh"
9#include "BLI_task.hh"
10
12
13#include "BKE_attribute_math.hh"
14#include "BKE_curves.hh"
15#include "BKE_customdata.hh"
16#include "BKE_grease_pencil.hh"
17#include "BKE_instances.hh"
18#include "BKE_mesh.h"
19#include "BKE_mesh.hh"
20#include "BKE_pointcloud.hh"
21
22#include "node_geometry_util.hh"
23
24#include "NOD_rna_define.hh"
25
27
29
31#include "UI_resources.hh"
32
34
36
38{
39 b.add_input<decl::Geometry>("Geometry"_ustr).description("Geometry to duplicate elements of");
40 b.add_input<decl::Bool>("Selection"_ustr)
41 .default_value(true)
42 .hide_value()
43 .evaluated_geometry_field();
44 b.add_input<decl::Int>("Amount"_ustr)
45 .min(0)
46 .default_value(1)
47 .evaluated_geometry_field()
48 .description("The number of duplicates to create for each element")
49 .translation_context(BLT_I18NCONTEXT_COUNTABLE);
50
51 b.add_output<decl::Geometry>("Geometry"_ustr)
52 .propagate_all_geometry()
53 .description("The duplicated geometry, not including the original geometry");
54 b.add_output<decl::Int>("Duplicate Index"_ustr)
55 .anonymous_attribute_output()
56 .description("The indices of the duplicates for each element");
57}
58
59static void node_init(bNodeTree * /*tree*/, bNode *node)
60{
61 NodeGeometryDuplicateElements *data = MEM_new<NodeGeometryDuplicateElements>(__func__);
62 data->domain = int8_t(AttrDomain::Point);
63 node->storage = data;
64}
65
66static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
67{
68 layout.prop(ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
69}
70
72 std::optional<std::string> duplicate_index;
73};
74
75/* -------------------------------------------------------------------- */
78
80 const VArray<int> &counts,
81 Array<int> &r_offset_data)
82{
83 r_offset_data.reinitialize(selection.size() + 1);
84 if (const std::optional<int> count = counts.get_if_single()) {
85 offset_indices::fill_constant_group_size(*count, 0, r_offset_data);
86 }
87 else {
89 selection,
90 r_offset_data.as_mutable_span().drop_back(1),
93 }
94 return OffsetIndices<int>(r_offset_data);
95}
96
97static void copy_hashed_ids(const Span<int> src, const int hash, MutableSpan<int> dst)
98{
99 for (const int i : src.index_range()) {
100 dst[i] = noise::hash(src[i], hash);
101 }
102}
103
105 const Span<int> src,
106 MutableSpan<int> all_dst)
107{
108 BLI_assert(offsets.total_size() == all_dst.size());
109 threading::parallel_for(offsets.index_range(), 512, [&](IndexRange range) {
110 for (const int i : range) {
111 MutableSpan<int> dst = all_dst.slice(offsets[i]);
112 if (dst.is_empty()) {
113 continue;
114 }
115 dst.first() = src[i];
116 for (const int i_duplicate : dst.index_range().drop_front(1)) {
117 dst[i_duplicate] = noise::hash(src[i], i_duplicate);
118 }
119 }
120 });
121}
122
125 const AttrDomain output_domain,
126 const IndexMask &selection,
127 const IndexAttributes &attribute_outputs,
128 const OffsetIndices<int> offsets)
129{
130 SpanAttributeWriter<int> duplicate_indices = attributes.lookup_or_add_for_write_only_span<int>(
131 *attribute_outputs.duplicate_index, output_domain);
132 for (const int i : selection.index_range()) {
133 array_utils::fill_index_range(duplicate_indices.span.slice(offsets[i]));
134 }
135 duplicate_indices.finish();
136}
137
142static void copy_stable_id_point(const OffsetIndices<int> offsets,
143 const bke::AttributeAccessor src_attributes,
144 bke::MutableAttributeAccessor dst_attributes)
145{
146 GAttributeReader src_attribute = src_attributes.lookup("id");
147 if (!src_attribute) {
148 return;
149 }
150 if (!ELEM(src_attribute.domain, AttrDomain::Point, AttrDomain::Instance)) {
151 return;
152 }
153 if (!src_attribute.varray.type().is<int>()) {
154 return;
155 }
156 SpanAttributeWriter dst_attribute = dst_attributes.lookup_or_add_for_write_only_span<int>(
157 "id", AttrDomain::Point);
158 if (!dst_attribute) {
159 return;
160 }
161
162 VArraySpan<int> src{src_attribute.varray.typed<int>()};
163 MutableSpan<int> dst = dst_attribute.span;
164 threaded_id_offset_copy(offsets, src, dst);
165 dst_attribute.finish();
166}
167
169
170/* -------------------------------------------------------------------- */
173
179 const IndexMask &selection,
180 const OffsetIndices<int> curve_offsets,
181 const AttributeFilter &attribute_filter,
182 bke::CurvesGeometry &dst_curves)
183{
184 const OffsetIndices src_points_by_curve = src_curves.points_by_curve();
185 const OffsetIndices dst_points_by_curve = dst_curves.points_by_curve();
186
188 src_curves.attributes(),
189 dst_curves.attributes_for_write(),
190 {bke::AttrDomain::Point, bke::AttrDomain::Curve},
191 bke::attribute_filter_with_skip_ref(attribute_filter, {"id"})))
192 {
193 switch (attribute.meta_data.domain) {
194 case AttrDomain::Curve:
196 curve_offsets, selection, attribute.src, attribute.dst.span);
197 break;
198 case AttrDomain::Point:
199 bke::attribute_math::to_static_type(attribute.src.type(), [&]<typename T>() {
200 const Span<T> src = attribute.src.typed<T>();
201 MutableSpan<T> dst = attribute.dst.span.typed<T>();
202 selection.foreach_index(
203 [&](const int64_t index, const int64_t i_selection) {
204 const Span<T> curve_src = src.slice(src_points_by_curve[index]);
205 for (const int dst_curve_index : curve_offsets[i_selection]) {
206 dst.slice(dst_points_by_curve[dst_curve_index]).copy_from(curve_src);
207 }
208 },
210 });
211 break;
212 default:
214 break;
215 }
216 attribute.dst.finish();
217 }
218}
219
226static void copy_stable_id_curves(const bke::CurvesGeometry &src_curves,
227 const IndexMask &selection,
228 const OffsetIndices<int> offsets,
229 bke::CurvesGeometry &dst_curves)
230{
231 GAttributeReader src_attribute = src_curves.attributes().lookup("id");
232 if (!src_attribute) {
233 return;
234 }
235 if (src_attribute.domain != AttrDomain::Point) {
236 return;
237 }
238 if (!src_attribute.varray.type().is<int>()) {
239 return;
240 }
241
242 SpanAttributeWriter dst_attribute =
244 AttrDomain::Point);
245 if (!dst_attribute) {
246 return;
247 }
248
249 VArraySpan<int> src{src_attribute.varray.typed<int>()};
250 MutableSpan<int> dst = dst_attribute.span;
251
252 const OffsetIndices src_points_by_curve = src_curves.points_by_curve();
253 const OffsetIndices dst_points_by_curve = dst_curves.points_by_curve();
254
255 selection.foreach_index(
256 [&](const int64_t i_src_curve, const int64_t i_selection) {
257 const Span<int> curve_src = src.slice(src_points_by_curve[i_src_curve]);
258 const IndexRange duplicates_range = offsets[i_selection];
259 dst.slice(dst_points_by_curve[duplicates_range.first()]).copy_from(curve_src);
260 for (const int i_duplicate : duplicates_range.index_range().drop_front(1)) {
261 const int i_dst_curve = duplicates_range[i_duplicate];
262 copy_hashed_ids(curve_src, i_duplicate, dst.slice(dst_points_by_curve[i_dst_curve]));
263 }
264 },
266
267 dst_attribute.finish();
268}
269
271 const FieldContext &field_context,
272 const Field<int> &count_field,
273 const Field<bool> &selection_field,
274 const IndexAttributes &attribute_outputs,
275 const AttributeFilter &attribute_filter)
276{
277 FieldEvaluator evaluator{field_context, curves.curves_num()};
278 evaluator.add(count_field);
279 evaluator.set_selection(selection_field);
280 evaluator.evaluate();
281 const VArray<int> counts = evaluator.get_evaluated<int>(0);
282 const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
283
284 const OffsetIndices points_by_curve = curves.points_by_curve();
285
286 /* The offset in the result curve domain at every selected input curve. */
287 Array<int> curve_offset_data(selection.size() + 1);
288 Array<int> point_offset_data(selection.size() + 1);
289
290 int dst_curves_num = 0;
291 int dst_points_num = 0;
292
293 selection.foreach_index_optimized<int>([&](const int index, const int i_curve) {
294 const int count = counts[index];
295 curve_offset_data[i_curve] = dst_curves_num;
296 point_offset_data[i_curve] = dst_points_num;
297 dst_curves_num += count;
298 dst_points_num += count * points_by_curve[index].size();
299 });
300
301 if (dst_points_num == 0) {
302 return {};
303 }
304
305 curve_offset_data.last() = dst_curves_num;
306 point_offset_data.last() = dst_points_num;
307
308 const OffsetIndices<int> curve_offsets(curve_offset_data);
309 const OffsetIndices<int> point_offsets(point_offset_data);
310
311 bke::CurvesGeometry new_curves{dst_points_num, dst_curves_num};
312 MutableSpan<int> all_dst_offsets = new_curves.offsets_for_write();
313 selection.foreach_index(
314 [&](const int64_t i_src_curve, const int64_t i_selection) {
315 const IndexRange src_curve_range = points_by_curve[i_src_curve];
316 const IndexRange dst_curves_range = curve_offsets[i_selection];
317 MutableSpan<int> dst_offsets = all_dst_offsets.slice(dst_curves_range);
318 for (const int i_duplicate : IndexRange(dst_curves_range.size())) {
319 dst_offsets[i_duplicate] = point_offsets[i_selection].start() +
320 src_curve_range.size() * i_duplicate;
321 }
322 },
324 all_dst_offsets.last() = dst_points_num;
325
326 copy_curve_attributes_without_id(curves, selection, curve_offsets, attribute_filter, new_curves);
327 copy_stable_id_curves(curves, selection, curve_offsets, new_curves);
328
329 if (attribute_outputs.duplicate_index) {
331 AttrDomain::Curve,
332 selection,
333 attribute_outputs,
334 curve_offsets);
335 }
336
337 new_curves.update_curve_types();
338 return new_curves;
339}
340
341static void duplicate_curves(GeometrySet &geometry_set,
342 const Field<int> &count_field,
343 const Field<bool> &selection_field,
344 const IndexAttributes &attribute_outputs,
345 const AttributeFilter &attribute_filter)
346{
351 if (const Curves *curves_id = geometry_set.get_curves()) {
352 const bke::CurvesFieldContext field_context{*curves_id, AttrDomain::Curve};
353 bke::CurvesGeometry new_curves = duplicate_curves_CurveGeometry(curves_id->geometry.wrap(),
354 field_context,
355 count_field,
356 selection_field,
357 attribute_outputs,
358 attribute_filter);
359 Curves *new_curves_id = bke::curves_new_nomain(std::move(new_curves));
360 bke::curves_copy_parameters(*curves_id, *new_curves_id);
361 geometry_set.replace_curves(new_curves_id);
362 }
364 using namespace bke::greasepencil;
366 grease_pencil->layers().index_range(), 16, [&](const IndexRange layers_range) {
367 for (const int layer_i : layers_range) {
368 Layer &layer = grease_pencil->layer(layer_i);
369 Drawing *drawing = grease_pencil->get_eval_drawing(layer);
370 if (!drawing) {
371 continue;
372 }
373 bke::CurvesGeometry &curves = drawing->strokes_for_write();
374 const bke::GreasePencilLayerFieldContext field_context{
375 *grease_pencil, AttrDomain::Curve, layer_i};
376 curves = duplicate_curves_CurveGeometry(curves,
377 field_context,
378 count_field,
379 selection_field,
380 attribute_outputs,
381 attribute_filter);
382 drawing->tag_topology_changed();
383 }
384 });
385 }
386}
387
389
390/* -------------------------------------------------------------------- */
393
398static void copy_face_attributes_without_id(const Span<int> edge_mapping,
399 const Span<int> vert_mapping,
400 const Span<int> loop_mapping,
401 const OffsetIndices<int> offsets,
402 const IndexMask &selection,
403 const AttributeFilter &attribute_filter,
404 const bke::AttributeAccessor src_attributes,
405 bke::MutableAttributeAccessor dst_attributes)
406{
408 src_attributes,
409 dst_attributes,
415 attribute_filter, {"id", ".corner_vert", ".corner_edge", ".edge_verts"})))
416 {
417 switch (attribute.meta_data.domain) {
418 case AttrDomain::Point:
419 bke::attribute_math::gather(attribute.src, vert_mapping, attribute.dst.span);
420 break;
421 case AttrDomain::Edge:
422 bke::attribute_math::gather(attribute.src, edge_mapping, attribute.dst.span);
423 break;
424 case AttrDomain::Face:
426 offsets, selection, attribute.src, attribute.dst.span);
427 break;
428 case AttrDomain::Corner:
429 bke::attribute_math::gather(attribute.src, loop_mapping, attribute.dst.span);
430 break;
431 default:
433 break;
434 }
435 attribute.dst.finish();
436 }
437}
438
446static void copy_stable_id_faces(const Mesh &mesh,
447 const IndexMask &selection,
448 const OffsetIndices<int> face_offsets,
449 const Span<int> vert_mapping,
450 const bke::AttributeAccessor src_attributes,
451 bke::MutableAttributeAccessor dst_attributes)
452{
453 GAttributeReader src_attribute = src_attributes.lookup("id");
454 if (!src_attribute) {
455 return;
456 }
457 if (src_attribute.domain != AttrDomain::Point) {
458 return;
459 }
460 if (!src_attribute.varray.type().is<int>()) {
461 return;
462 }
463 SpanAttributeWriter dst_attribute = dst_attributes.lookup_or_add_for_write_only_span<int>(
464 "id", AttrDomain::Point);
465 if (!dst_attribute) {
466 return;
467 }
468
469 VArraySpan<int> src{src_attribute.varray.typed<int>()};
470 MutableSpan<int> dst = dst_attribute.span;
471
472 const OffsetIndices faces = mesh.faces();
473 int loop_index = 0;
474 for (const int i_face : selection.index_range()) {
475 const IndexRange range = face_offsets[i_face];
476 if (range.is_empty()) {
477 continue;
478 }
479 const IndexRange source = faces[i_face];
480 for ([[maybe_unused]] const int i_duplicate : IndexRange(range.size())) {
481 for ([[maybe_unused]] const int i_loops : IndexRange(source.size())) {
482 if (i_duplicate == 0) {
483 dst[loop_index] = src[vert_mapping[loop_index]];
484 }
485 else {
486 dst[loop_index] = noise::hash(src[vert_mapping[loop_index]], i_duplicate);
487 }
488 loop_index++;
489 }
490 }
491 }
492
493 dst_attribute.finish();
494}
495
496static void duplicate_faces(GeometrySet &geometry_set,
497 const Field<int> &count_field,
498 const Field<bool> &selection_field,
499 const IndexAttributes &attribute_outputs,
500 const AttributeFilter &attribute_filter)
501{
502 if (!geometry_set.has_mesh()) {
503 geometry_set.clear();
504 return;
505 }
507
508 const Mesh &mesh = *geometry_set.get_mesh();
509 const OffsetIndices faces = mesh.faces();
510 const Span<int> corner_verts = mesh.corner_verts();
511 const Span<int> corner_edges = mesh.corner_edges();
512
513 const bke::MeshFieldContext field_context{mesh, AttrDomain::Face};
514 FieldEvaluator evaluator(field_context, faces.size());
515 evaluator.add(count_field);
516 evaluator.set_selection(selection_field);
517 evaluator.evaluate();
518 const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
519 const VArray<int> counts = evaluator.get_evaluated<int>(0);
520
521 int total_faces = 0;
522 int total_loops = 0;
523 Array<int> offset_data(selection.size() + 1);
524 selection.foreach_index_optimized<int>([&](const int index, const int i_selection) {
525 const int count = counts[index];
526 offset_data[i_selection] = total_faces;
527 total_faces += count;
528 total_loops += count * faces[index].size();
529 });
530 offset_data[selection.size()] = total_faces;
531
532 const OffsetIndices<int> duplicates(offset_data);
533
534 Mesh *new_mesh = BKE_mesh_new_nomain(total_loops, total_loops, total_faces, total_loops);
536 MutableSpan<int2> new_edges = new_mesh->edges_for_write();
537 MutableSpan<int> new_face_offsets = new_mesh->face_offsets_for_write();
538 MutableSpan<int> new_corner_verts = new_mesh->corner_verts_for_write();
539 MutableSpan<int> new_corner_edges = new_mesh->corner_edges_for_write();
540
541 Array<int> vert_mapping(new_mesh->verts_num);
542 Array<int> edge_mapping(new_edges.size());
543 Array<int> loop_mapping(total_loops);
544
545 int face_index = 0;
546 int loop_index = 0;
547 selection.foreach_index_optimized<int>([&](const int index, const int i_selection) {
548 const IndexRange face_range = duplicates[i_selection];
549 const IndexRange source = faces[index];
550 for ([[maybe_unused]] const int i_duplicate : face_range.index_range()) {
551 new_face_offsets[face_index] = loop_index;
552 for (const int src_corner : source) {
553 loop_mapping[loop_index] = src_corner;
554 vert_mapping[loop_index] = corner_verts[src_corner];
555 edge_mapping[loop_index] = corner_edges[src_corner];
556 new_edges[loop_index][0] = loop_index;
557 if (src_corner != source.last()) {
558 new_edges[loop_index][1] = loop_index + 1;
559 }
560 else {
561 new_edges[loop_index][1] = new_face_offsets[face_index];
562 }
563 loop_index++;
564 }
565 face_index++;
566 }
567 });
568 array_utils::fill_index_range<int>(new_corner_verts);
569 array_utils::fill_index_range<int>(new_corner_edges);
570
571 new_mesh->tag_loose_verts_none();
572 new_mesh->tag_loose_edges_none();
573 new_mesh->tag_overlapping_none();
574
576 vert_mapping,
577 loop_mapping,
578 duplicates,
579 selection,
580 attribute_filter,
581 mesh.attributes(),
582 new_mesh->attributes_for_write());
583
584 if (CustomData_has_layer(&mesh.vert_data, CD_ORIGINDEX)) {
585 const Span src(static_cast<const int *>(CustomData_get_layer(&mesh.vert_data, CD_ORIGINDEX)),
586 mesh.verts_num);
587 MutableSpan dst(static_cast<int *>(CustomData_add_layer(
588 &new_mesh->vert_data, CD_ORIGINDEX, CD_CONSTRUCT, new_mesh->verts_num)),
589 new_mesh->verts_num);
590 array_utils::gather(src, vert_mapping.as_span(), dst);
591 }
592
593 if (CustomData_has_layer(&mesh.edge_data, CD_ORIGINDEX)) {
594 const Span src(static_cast<const int *>(CustomData_get_layer(&mesh.edge_data, CD_ORIGINDEX)),
595 mesh.edges_num);
596 MutableSpan dst(static_cast<int *>(CustomData_add_layer(
597 &new_mesh->edge_data, CD_ORIGINDEX, CD_CONSTRUCT, new_mesh->edges_num)),
598 new_mesh->edges_num);
599 array_utils::gather(src, edge_mapping.as_span(), dst);
600 }
601
602 if (CustomData_has_layer(&mesh.face_data, CD_ORIGINDEX)) {
603 const Span src(static_cast<const int *>(CustomData_get_layer(&mesh.face_data, CD_ORIGINDEX)),
604 mesh.faces_num);
605 MutableSpan dst(static_cast<int *>(CustomData_add_layer(
606 &new_mesh->face_data, CD_ORIGINDEX, CD_CONSTRUCT, new_mesh->faces_num)),
607 new_mesh->faces_num);
608 bke::attribute_math::gather_to_groups(duplicates, selection, src, dst);
609 }
610
612 selection,
613 duplicates,
614 vert_mapping,
615 mesh.attributes(),
616 new_mesh->attributes_for_write());
617
618 if (attribute_outputs.duplicate_index) {
619 create_duplicate_index_attribute(new_mesh->attributes_for_write(),
620 AttrDomain::Face,
621 selection,
622 attribute_outputs,
623 duplicates);
624 }
625
626 geometry_set.replace_mesh(new_mesh);
627}
628
630
631/* -------------------------------------------------------------------- */
634
639static void copy_edge_attributes_without_id(const Span<int> point_mapping,
640 const OffsetIndices<int> offsets,
641 const IndexMask &selection,
642 const AttributeFilter &attribute_filter,
643 const bke::AttributeAccessor src_attributes,
644 bke::MutableAttributeAccessor dst_attributes)
645{
647 src_attributes,
648 dst_attributes,
650 bke::attribute_filter_with_skip_ref(attribute_filter, {"id", ".edge_verts"})))
651 {
652 switch (attribute.meta_data.domain) {
653 case AttrDomain::Edge:
655 offsets, selection, attribute.src, attribute.dst.span);
656 break;
657 case AttrDomain::Point:
658 bke::attribute_math::gather(attribute.src, point_mapping, attribute.dst.span);
659 break;
660 default:
662 break;
663 }
664 attribute.dst.finish();
665 }
666}
667
674 const AttrDomain domain,
675 const Span<AttrDomain> copied_domains,
676 const OffsetIndices<int> offsets,
677 const IndexMask &selection,
678 const AttributeFilter &attribute_filter,
679 bke::MutableAttributeAccessor dst_attributes)
680{
681 src_attributes.foreach_attribute([&](const bke::AttributeIter &iter) {
682 if (copied_domains.contains(iter.domain)) {
683 return;
684 }
685 if (dst_attributes.contains(iter.name)) {
686 return;
687 }
688 if (iter.is_builtin || bke::mesh::is_uv_map({iter.domain, iter.data_type}) ||
689 iter.name == "id" || iter.data_type == bke::AttrType::String ||
690 attribute_filter.allow_skip(iter.name))
691 {
692 return;
693 }
694 if (ELEM(iter.name,
695 ".corner_vert",
696 ".corner_edge",
697 ".edge_verts",
698 ".select_edge",
699 ".select_poly",
700 ".hide_edge",
701 ".hide_poly",
702 ".sculpt_face_set",
703 "custom_normal"))
704 {
705 return;
706 }
707
708 const bke::GAttributeReader src = iter.get(domain);
709 if (!src) {
710 return;
711 }
712 const CommonVArrayInfo info = src.varray.common_info();
714 const CPPType &type = src.varray.type();
715 const bke::AttributeInitValue init(GPointer(type, info.data));
716 dst_attributes.add(iter.name, domain, iter.data_type, init);
717 return;
718 }
719
721 iter.name, domain, iter.data_type);
722 if (!dst) {
723 return;
724 }
725 const GVArraySpan src_span = src.varray;
726 bke::attribute_math::gather_to_groups(offsets, selection, src_span, dst.span);
727 dst.finish();
728 });
729}
730
735static void copy_stable_id_edges(const Mesh &mesh,
736 const IndexMask &selection,
737 const OffsetIndices<int> offsets,
738 const bke::AttributeAccessor src_attributes,
739 bke::MutableAttributeAccessor dst_attributes)
740{
741 GAttributeReader src_attribute = src_attributes.lookup("id");
742 if (!src_attribute) {
743 return;
744 }
745 if (src_attribute.domain != AttrDomain::Point) {
746 return;
747 }
748 if (!src_attribute.varray.type().is<int>()) {
749 return;
750 }
751 SpanAttributeWriter dst_attribute = dst_attributes.lookup_or_add_for_write_only_span<int>(
752 "id", AttrDomain::Point);
753 if (!dst_attribute) {
754 return;
755 }
756
757 const Span<int2> edges = mesh.edges();
758
759 VArraySpan<int> src{src_attribute.varray.typed<int>()};
760 MutableSpan<int> dst = dst_attribute.span;
761 selection.foreach_index(
762 [&](const int64_t index, const int64_t i_selection) {
763 const IndexRange edge_range = offsets[i_selection];
764 if (edge_range.is_empty()) {
765 return;
766 }
767 const int2 &edge = edges[index];
768 const IndexRange vert_range = {edge_range.start() * 2, edge_range.size() * 2};
769
770 dst[vert_range[0]] = src[edge[0]];
771 dst[vert_range[1]] = src[edge[1]];
772 for (const int i_duplicate : IndexRange(1, edge_range.size() - 1)) {
773 dst[vert_range[i_duplicate * 2]] = noise::hash(src[edge[0]], i_duplicate);
774 dst[vert_range[i_duplicate * 2 + 1]] = noise::hash(src[edge[1]], i_duplicate);
775 }
776 },
778 dst_attribute.finish();
779}
780
781static void duplicate_edges(GeometrySet &geometry_set,
782 const Field<int> &count_field,
783 const Field<bool> &selection_field,
784 const IndexAttributes &attribute_outputs,
785 const AttributeFilter &attribute_filter)
786{
787 if (!geometry_set.has_mesh()) {
788 geometry_set.clear();
789 return;
790 };
791 const Mesh &mesh = *geometry_set.get_mesh();
792 const Span<int2> edges = mesh.edges();
793
794 const bke::MeshFieldContext field_context{mesh, AttrDomain::Edge};
795 FieldEvaluator evaluator{field_context, edges.size()};
796 evaluator.add(count_field);
797 evaluator.set_selection(selection_field);
798 evaluator.evaluate();
799 const VArray<int> counts = evaluator.get_evaluated<int>(0);
800 const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
801
802 Array<int> offset_data;
804 selection, counts, offset_data);
805 const int output_edges_num = duplicates.total_size();
806
807 Mesh *new_mesh = BKE_mesh_new_nomain(output_edges_num * 2, output_edges_num, 0, 0);
809 MutableSpan<int2> new_edges = new_mesh->edges_for_write();
810
811 Array<int> vert_orig_indices(output_edges_num * 2);
812 selection.foreach_index(
813 [&](const int64_t index, const int64_t i_selection) {
814 const int2 &edge = edges[index];
815 const IndexRange edge_range = duplicates[i_selection];
816 const IndexRange vert_range(edge_range.start() * 2, edge_range.size() * 2);
817
818 for (const int i_duplicate : IndexRange(edge_range.size())) {
819 vert_orig_indices[vert_range[i_duplicate * 2]] = edge[0];
820 vert_orig_indices[vert_range[i_duplicate * 2 + 1]] = edge[1];
821 }
822 },
824
825 threading::parallel_for(selection.index_range(), 1024, [&](IndexRange range) {
826 for (const int i_selection : range) {
827 const IndexRange edge_range = duplicates[i_selection];
828 const IndexRange vert_range(edge_range.start() * 2, edge_range.size() * 2);
829 for (const int i_duplicate : IndexRange(edge_range.size())) {
830 int2 &new_edge = new_edges[edge_range[i_duplicate]];
831 new_edge[0] = vert_range[i_duplicate * 2];
832 new_edge[1] = vert_range[i_duplicate * 2] + 1;
833 }
834 }
835 });
836
837 copy_edge_attributes_without_id(vert_orig_indices,
838 duplicates,
839 selection,
840 attribute_filter,
841 mesh.attributes(),
842 new_mesh->attributes_for_write());
843
844 copy_attributes_from_other_domains(mesh.attributes(),
845 AttrDomain::Edge,
846 {AttrDomain::Point, AttrDomain::Edge},
847 duplicates,
848 selection,
849 attribute_filter,
850 new_mesh->attributes_for_write());
851
852 if (CustomData_has_layer(&mesh.vert_data, CD_ORIGINDEX)) {
853 const Span src(static_cast<const int *>(CustomData_get_layer(&mesh.vert_data, CD_ORIGINDEX)),
854 mesh.verts_num);
855 MutableSpan dst(static_cast<int *>(CustomData_add_layer(
856 &new_mesh->vert_data, CD_ORIGINDEX, CD_CONSTRUCT, new_mesh->verts_num)),
857 new_mesh->verts_num);
858 array_utils::gather(src, vert_orig_indices.as_span(), dst);
859 }
860
861 if (CustomData_has_layer(&mesh.edge_data, CD_ORIGINDEX)) {
862 const Span src(static_cast<const int *>(CustomData_get_layer(&mesh.edge_data, CD_ORIGINDEX)),
863 mesh.edges_num);
864 MutableSpan dst(static_cast<int *>(CustomData_add_layer(
865 &new_mesh->edge_data, CD_ORIGINDEX, CD_CONSTRUCT, new_mesh->edges_num)),
866 new_mesh->edges_num);
867 bke::attribute_math::gather_to_groups(duplicates, selection, src, dst);
868 }
869
870 copy_stable_id_edges(
871 mesh, selection, duplicates, mesh.attributes(), new_mesh->attributes_for_write());
872
873 if (attribute_outputs.duplicate_index) {
874 create_duplicate_index_attribute(new_mesh->attributes_for_write(),
875 AttrDomain::Edge,
876 selection,
877 attribute_outputs,
878 duplicates);
879 }
880
881 new_mesh->tag_overlapping_none();
882
883 geometry_set.replace_mesh(new_mesh);
884}
885
887
888/* -------------------------------------------------------------------- */
891
893 const bke::CurvesGeometry &src_curves,
894 const FieldContext &field_context,
895 const Field<int> &count_field,
896 const Field<bool> &selection_field,
897 const IndexAttributes &attribute_outputs,
898 const AttributeFilter &attribute_filter)
899{
900 if (src_curves.is_empty()) {
901 return {};
902 }
903
904 FieldEvaluator evaluator{field_context, src_curves.points_num()};
905 evaluator.add(count_field);
906 evaluator.set_selection(selection_field);
907 evaluator.evaluate();
908 const VArray<int> counts = evaluator.get_evaluated<int>(0);
909 const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
910
911 Array<int> offset_data;
913 selection, counts, offset_data);
914 const int dst_num = duplicates.total_size();
915
916 const Array<int> point_to_curve_map = src_curves.point_to_curve_map();
917
918 bke::CurvesGeometry new_curves{dst_num, dst_num};
920
922 AttrDomain::Point,
923 AttrDomain::Point,
924 attribute_filter,
925 duplicates,
926 selection,
927 new_curves.attributes_for_write());
928
930 src_curves.attributes(),
931 new_curves.attributes_for_write(),
932 {bke::AttrDomain::Curve},
933 bke::attribute_filter_with_skip_ref(attribute_filter, {"id"})))
934 {
935 bke::attribute_math::to_static_type(attribute.src.type(), [&]<typename T>() {
936 const Span<T> src = attribute.src.typed<T>();
937 MutableSpan<T> dst = attribute.dst.span.typed<T>();
938 selection.foreach_index(
939 [&](const int64_t index, const int64_t i_selection) {
940 const T &src_value = src[point_to_curve_map[index]];
941 dst.slice(duplicates[i_selection]).fill(src_value);
942 },
944 });
945 attribute.dst.finish();
946 }
947
948 copy_stable_id_point(duplicates, src_curves.attributes(), new_curves.attributes_for_write());
949
950 if (attribute_outputs.duplicate_index) {
951 create_duplicate_index_attribute(new_curves.attributes_for_write(),
952 AttrDomain::Point,
953 selection,
954 attribute_outputs,
955 duplicates);
956 }
957
958 return new_curves;
959}
960
961static void duplicate_points_curve(GeometrySet &geometry_set,
962 const Field<int> &count_field,
963 const Field<bool> &selection_field,
964 const IndexAttributes &attribute_outputs,
965 const AttributeFilter &attribute_filter)
966{
967 const Curves &src_curves_id = *geometry_set.get_curves();
968 const bke::CurvesGeometry &src_curves = src_curves_id.geometry.wrap();
969
970 const bke::CurvesFieldContext field_context{src_curves_id, AttrDomain::Point};
972 field_context,
973 count_field,
974 selection_field,
975 attribute_outputs,
976 attribute_filter);
977
978 Curves *new_curves_id = bke::curves_new_nomain(std::move(new_curves));
979 bke::curves_copy_parameters(src_curves_id, *new_curves_id);
980 geometry_set.replace_curves(new_curves_id);
981}
982
984
985/* -------------------------------------------------------------------- */
988
990 const Field<int> &count_field,
991 const Field<bool> &selection_field,
992 const IndexAttributes &attribute_outputs,
993 const AttributeFilter &attribute_filter)
994{
995 using namespace bke::greasepencil;
998 grease_pencil.layers().index_range(), 16, [&](const IndexRange layers_range) {
999 for (const int layer_i : layers_range) {
1000 Layer &layer = grease_pencil.layer(layer_i);
1001 Drawing *drawing = grease_pencil.get_eval_drawing(layer);
1002 if (!drawing) {
1003 continue;
1004 }
1005 bke::CurvesGeometry &curves = drawing->strokes_for_write();
1006 const bke::GreasePencilLayerFieldContext field_context{
1007 grease_pencil, AttrDomain::Point, layer_i};
1008 curves = duplicate_points_CurvesGeometry(curves,
1009 field_context,
1010 count_field,
1011 selection_field,
1012 attribute_outputs,
1013 attribute_filter);
1014 drawing->tag_topology_changed();
1015 }
1016 });
1017}
1018
1020
1021/* -------------------------------------------------------------------- */
1024
1025static void duplicate_points_mesh(GeometrySet &geometry_set,
1026 const Field<int> &count_field,
1027 const Field<bool> &selection_field,
1028 const IndexAttributes &attribute_outputs,
1029 const AttributeFilter &attribute_filter)
1030{
1031 const Mesh &mesh = *geometry_set.get_mesh();
1032
1033 const bke::MeshFieldContext field_context{mesh, AttrDomain::Point};
1034 FieldEvaluator evaluator{field_context, mesh.verts_num};
1035 evaluator.add(count_field);
1036 evaluator.set_selection(selection_field);
1037 evaluator.evaluate();
1038 const VArray<int> counts = evaluator.get_evaluated<int>(0);
1039 const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
1040
1041 Array<int> offset_data;
1043 selection, counts, offset_data);
1044
1045 Mesh *new_mesh = BKE_mesh_new_nomain(duplicates.total_size(), 0, 0, 0);
1047
1049 AttrDomain::Point,
1050 AttrDomain::Point,
1051 bke::attribute_filter_with_skip_ref(attribute_filter, {"id"}),
1052 duplicates,
1053 selection,
1054 new_mesh->attributes_for_write());
1055
1057 AttrDomain::Point,
1058 {AttrDomain::Point},
1059 duplicates,
1060 selection,
1061 attribute_filter,
1062 new_mesh->attributes_for_write());
1063
1064 copy_stable_id_point(duplicates, mesh.attributes(), new_mesh->attributes_for_write());
1065
1066 if (attribute_outputs.duplicate_index) {
1067 create_duplicate_index_attribute(new_mesh->attributes_for_write(),
1068 AttrDomain::Point,
1069 selection,
1070 attribute_outputs,
1071 duplicates);
1072 }
1073
1074 if (CustomData_has_layer(&mesh.vert_data, CD_ORIGINDEX)) {
1075 const Span src(static_cast<const int *>(CustomData_get_layer(&mesh.vert_data, CD_ORIGINDEX)),
1076 mesh.verts_num);
1077 MutableSpan dst(static_cast<int *>(CustomData_add_layer(
1078 &new_mesh->vert_data, CD_ORIGINDEX, CD_CONSTRUCT, new_mesh->verts_num)),
1079 new_mesh->verts_num);
1080 array_utils::gather_to_groups(duplicates, selection, src, dst);
1081 }
1082
1083 new_mesh->tag_overlapping_none();
1084
1085 geometry_set.replace_mesh(new_mesh);
1086}
1087
1089
1090/* -------------------------------------------------------------------- */
1093
1095 const Field<int> &count_field,
1096 const Field<bool> &selection_field,
1097 const IndexAttributes &attribute_outputs,
1098 const AttributeFilter &attribute_filter)
1099{
1100 const PointCloud &src_points = *geometry_set.get_pointcloud();
1101
1102 const bke::PointCloudFieldContext field_context{src_points};
1103 FieldEvaluator evaluator{field_context, src_points.totpoint};
1104 evaluator.add(count_field);
1105 evaluator.set_selection(selection_field);
1106 evaluator.evaluate();
1107 const VArray<int> counts = evaluator.get_evaluated<int>(0);
1108 const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
1109
1110 Array<int> offset_data;
1112 selection, counts, offset_data);
1113
1114 PointCloud *pointcloud = BKE_pointcloud_new_nomain(src_points.type, duplicates.total_size());
1115
1116 bke::gather_attributes_to_groups(src_points.attributes(),
1117 AttrDomain::Point,
1118 AttrDomain::Point,
1119 bke::attribute_filter_with_skip_ref(attribute_filter, {"id"}),
1120 duplicates,
1121 selection,
1122 pointcloud->attributes_for_write());
1123
1124 copy_stable_id_point(duplicates, src_points.attributes(), pointcloud->attributes_for_write());
1125
1126 if (attribute_outputs.duplicate_index) {
1127 create_duplicate_index_attribute(pointcloud->attributes_for_write(),
1128 AttrDomain::Point,
1129 selection,
1130 attribute_outputs,
1131 duplicates);
1132 }
1133 geometry_set.replace_pointcloud(pointcloud);
1134}
1135
1137
1138/* -------------------------------------------------------------------- */
1141
1142static void duplicate_points(GeometrySet &geometry_set,
1143 const Field<int> &count_field,
1144 const Field<bool> &selection_field,
1145 const IndexAttributes &attribute_outputs,
1146 const AttributeFilter &attribute_filter)
1147{
1148 Vector<GeometryComponent::Type> component_types = geometry_set.gather_component_types(true,
1149 true);
1150 for (const GeometryComponent::Type component_type : component_types) {
1151 switch (component_type) {
1153 if (geometry_set.has_pointcloud()) {
1155 geometry_set, count_field, selection_field, attribute_outputs, attribute_filter);
1156 }
1157 break;
1159 if (geometry_set.has_mesh()) {
1161 geometry_set, count_field, selection_field, attribute_outputs, attribute_filter);
1162 }
1163 break;
1165 if (geometry_set.has_curves()) {
1167 geometry_set, count_field, selection_field, attribute_outputs, attribute_filter);
1168 }
1169 break;
1171 if (geometry_set.has_grease_pencil()) {
1173 geometry_set, count_field, selection_field, attribute_outputs, attribute_filter);
1174 }
1175 break;
1176 }
1177 default:
1178 break;
1179 }
1180 }
1181 component_types.append(GeometryComponent::Type::Edit);
1182 geometry_set.keep_only(component_types);
1183}
1184
1186
1187/* -------------------------------------------------------------------- */
1190
1191static void duplicate_layers(GeometrySet &geometry_set,
1192 const Field<int> &count_field,
1193 const Field<bool> &selection_field,
1194 const IndexAttributes &attribute_outputs,
1195 const AttributeFilter &attribute_filter)
1196{
1197 using namespace bke::greasepencil;
1198 if (!geometry_set.has_grease_pencil()) {
1199 geometry_set.clear();
1200 return;
1201 }
1204 const GreasePencil &src_grease_pencil = *geometry_set.get_grease_pencil();
1205
1206 bke::GreasePencilFieldContext field_context{src_grease_pencil};
1207 FieldEvaluator evaluator{field_context, src_grease_pencil.layers().size()};
1208 evaluator.add(count_field);
1209 evaluator.set_selection(selection_field);
1210 evaluator.evaluate();
1211 const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
1212 const VArray<int> counts = evaluator.get_evaluated<int>(0);
1213
1214 Array<int> offset_data;
1216 selection, counts, offset_data);
1217 const int new_layers_num = duplicates.total_size();
1218 if (new_layers_num == 0) {
1219 geometry_set.clear();
1220 return;
1221 }
1222
1223 GreasePencil *new_grease_pencil = BKE_grease_pencil_new_nomain();
1224 BKE_grease_pencil_copy_parameters(src_grease_pencil, *new_grease_pencil);
1225
1226 new_grease_pencil->add_layers_with_empty_drawings_for_eval(new_layers_num);
1227 static bke::CurvesGeometry static_empty_curves;
1228 selection.foreach_index([&](const int src_layer_i, const int pos) {
1229 const IndexRange range = duplicates[pos];
1230 if (range.is_empty()) {
1231 return;
1232 }
1233 const Layer &src_layer = src_grease_pencil.layer(src_layer_i);
1234 const Drawing *src_drawing = src_grease_pencil.get_eval_drawing(src_layer);
1235 const bke::CurvesGeometry &src_curves = src_drawing ? src_drawing->strokes() :
1236 static_empty_curves;
1237 const StringRefNull src_layer_name = src_layer.name();
1238 for (Layer *new_layer : new_grease_pencil->layers_for_write().slice(range)) {
1239 BKE_grease_pencil_copy_layer_parameters(src_layer, *new_layer);
1240 new_layer->set_name(src_layer_name);
1241 Drawing *new_drawing = new_grease_pencil->get_eval_drawing(*new_layer);
1242 new_drawing->strokes_for_write() = src_curves;
1243 }
1244 });
1245
1246 bke::gather_attributes_to_groups(src_grease_pencil.attributes(),
1247 AttrDomain::Layer,
1248 AttrDomain::Layer,
1249 attribute_filter,
1250 duplicates,
1251 selection,
1252 new_grease_pencil->attributes_for_write());
1253
1254 if (attribute_outputs.duplicate_index) {
1255 create_duplicate_index_attribute(new_grease_pencil->attributes_for_write(),
1256 AttrDomain::Layer,
1257 selection,
1258 attribute_outputs,
1259 duplicates);
1260 }
1261
1262 geometry_set.replace_grease_pencil(new_grease_pencil);
1263}
1264
1266
1267/* -------------------------------------------------------------------- */
1270
1271static void duplicate_instances(GeometrySet &geometry_set,
1272 const Field<int> &count_field,
1273 const Field<bool> &selection_field,
1274 const IndexAttributes &attribute_outputs,
1275 const AttributeFilter &attribute_filter)
1276{
1277 if (!geometry_set.has_instances()) {
1278 geometry_set.clear();
1279 return;
1280 }
1281
1282 const bke::Instances &src_instances = *geometry_set.get_instances();
1283
1284 bke::InstancesFieldContext field_context{src_instances};
1285 FieldEvaluator evaluator{field_context, src_instances.instances_num()};
1286 evaluator.add(count_field);
1287 evaluator.set_selection(selection_field);
1288 evaluator.evaluate();
1289 IndexMask selection = evaluator.get_evaluated_selection_as_mask();
1290 const VArray<int> counts = evaluator.get_evaluated<int>(0);
1291
1292 Array<int> offset_data;
1294 selection, counts, offset_data);
1295 if (duplicates.total_size() == 0) {
1296 geometry_set.clear();
1297 return;
1298 }
1299
1300 const Span<bke::InstanceReference> src_references = src_instances.references();
1301 const Span<int> src_handles = src_instances.reference_handles();
1302
1303 auto dst_instances = std::make_unique<bke::Instances>(duplicates.total_size());
1304
1305 MutableSpan<int> handles = dst_instances->reference_handles_for_write();
1306 selection.foreach_index([&](const int i_src, const int i_dst) {
1307 const IndexRange range = duplicates[i_dst];
1308 if (range.is_empty()) {
1309 return;
1310 }
1311 const int old_handle = src_handles[i_src];
1312 const bke::InstanceReference reference = src_references[old_handle];
1313 const int new_handle = dst_instances->add_reference(reference);
1314 handles.slice(range).fill(new_handle);
1315 });
1316
1318 src_instances.attributes(),
1319 AttrDomain::Instance,
1320 AttrDomain::Instance,
1321 bke::attribute_filter_with_skip_ref(attribute_filter, {"id", ".reference_index"}),
1322 duplicates,
1323 selection,
1324 dst_instances->attributes_for_write());
1325
1326 if (attribute_outputs.duplicate_index) {
1327 create_duplicate_index_attribute(dst_instances->attributes_for_write(),
1328 AttrDomain::Instance,
1329 selection,
1330 attribute_outputs,
1331 duplicates);
1332 }
1333
1334 geometry_set = GeometrySet::from_instances(std::move(dst_instances));
1335}
1336
1338
1339/* -------------------------------------------------------------------- */
1342
1344{
1345 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"_ustr);
1346
1347 const NodeGeometryDuplicateElements &storage = node_storage(params.node());
1348 const AttrDomain duplicate_domain = AttrDomain(storage.domain);
1349
1350 const Field<int> count_field(
1352 {fn::Field<int>(0), params.extract_input<Field<int>>("Amount"_ustr)}));
1353
1354 Field<bool> selection_field = params.extract_input<Field<bool>>("Selection"_ustr);
1355 IndexAttributes attribute_outputs;
1356 attribute_outputs.duplicate_index = params.get_output_anonymous_attribute_id_if_needed(
1357 "Duplicate Index"_ustr);
1358
1359 const NodeAttributeFilter &attribute_filter = params.get_attribute_filter("Geometry"_ustr);
1360
1361 if (duplicate_domain == AttrDomain::Instance) {
1363 geometry_set, count_field, selection_field, attribute_outputs, attribute_filter);
1364 }
1365 else {
1366 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
1367 switch (duplicate_domain) {
1368 case AttrDomain::Curve:
1370 geometry_set, count_field, selection_field, attribute_outputs, attribute_filter);
1371 break;
1372 case AttrDomain::Face:
1374 geometry_set, count_field, selection_field, attribute_outputs, attribute_filter);
1375 break;
1376 case AttrDomain::Edge:
1378 geometry_set, count_field, selection_field, attribute_outputs, attribute_filter);
1379 break;
1380 case AttrDomain::Point:
1382 geometry_set, count_field, selection_field, attribute_outputs, attribute_filter);
1383 break;
1384 case AttrDomain::Layer:
1386 geometry_set, count_field, selection_field, attribute_outputs, attribute_filter);
1387 break;
1388 default:
1390 break;
1391 }
1392 });
1393 }
1394
1395 if (geometry_set.is_empty()) {
1397 return;
1398 }
1399
1400 params.set_output("Geometry"_ustr, std::move(geometry_set));
1401}
1402
1404
1405static void node_rna(StructRNA *srna)
1406{
1407 static const EnumPropertyItem domain_items[] = {
1408 {int(AttrDomain::Point), "POINT", 0, "Point", ""},
1409 {int(AttrDomain::Edge), "EDGE", 0, "Edge", ""},
1410 {int(AttrDomain::Face), "FACE", 0, "Face", ""},
1411 {int(AttrDomain::Curve), "SPLINE", 0, "Spline", ""},
1412 {int(AttrDomain::Layer), "LAYER", 0, "Layer", ""},
1413 {int(AttrDomain::Instance), "INSTANCE", 0, "Instance", ""},
1414 {0, nullptr, 0, nullptr, nullptr},
1415 };
1416
1417 RNA_def_node_enum(srna,
1418 "domain",
1419 "Domain",
1420 "Which domain to duplicate",
1421 domain_items,
1423 int(AttrDomain::Point),
1424 nullptr,
1425 true);
1426}
1427
1428static void node_register()
1429{
1430 static bke::bNodeType ntype;
1431 geo_node_type_base(&ntype, "GeometryNodeDuplicateElements"_ustr, GEO_NODE_DUPLICATE_ELEMENTS);
1432 ntype.ui_name = "Duplicate Elements";
1433 ntype.ui_description = "Generate an arbitrary number copies of each selected input element";
1434 ntype.enum_name_legacy = "DUPLICATE_ELEMENTS";
1437 "NodeGeometryDuplicateElements",
1440
1441 ntype.initfunc = node_init;
1442 ntype.draw_buttons = node_layout;
1444 ntype.declare = node_declare;
1446
1447 node_rna(ntype.rna_ext.srna);
1448}
1449NOD_REGISTER_NODE(node_register)
1450
1451} // namespace blender::nodes::node_geo_duplicate_elements_cc
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
Low-level operations for grease pencil.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_DUPLICATE_ELEMENTS
General operations for point clouds.
#define BLT_I18NCONTEXT_COUNTABLE
#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
const T & last(const int64_t n=0) const
Definition BLI_array.hh:307
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
bool is() const
CommonVArrayInfo common_info() const
constexpr int64_t first() const
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr int64_t start() const
constexpr IndexRange index_range() const
constexpr IndexRange drop_front(int64_t n) const
constexpr int64_t size() const
Definition BLI_span.hh:499
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:579
constexpr void fill(const T &value) const
Definition BLI_span.hh:523
constexpr void copy_from(Span< T > values) const
Definition BLI_span.hh:745
constexpr T & last(const int64_t n=0) const
Definition BLI_span.hh:695
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr bool contains(const T &value) const
Definition BLI_span.hh:281
std::optional< T > get_if_single() const
void append(const T &value)
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
bool contains(StringRef name) const
GAttributeReader lookup(const StringRef name) const
GAttributeReader get() const
AttributeAccessor attributes() const
MutableSpan< int > offsets_for_write()
OffsetIndices< int > points_by_curve() const
Array< int > point_to_curve_map() const
MutableAttributeAccessor attributes_for_write()
Span< int > reference_handles() const
Definition instances.cc:222
Span< InstanceReference > references() const
Definition instances.cc:290
bke::AttributeAccessor attributes() const
Definition instances.cc:68
int instances_num() const
Definition instances.cc:408
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
bke::CurvesGeometry & strokes_for_write()
const bke::CurvesGeometry & strokes() const
constexpr Span slice(int64_t start, int64_t size) const
void set_selection(Field< bool > selection)
int add(GField field, GVArray *varray_ptr)
IndexMask get_evaluated_selection_as_mask() const
const GVArray & get_evaluated(const int field_index) const
void foreach_index_optimized(Fn &&fn, Mode mode=exec_mode::serial) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) 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)
static void remember_deformed_positions_if_necessary(GeometrySet &geometry)
#define storage(slot, qualifiers)
#define attribute(slot)
#define T
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 fill_index_range(MutableSpan< T > span, const T start=0)
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 to_static_type(const CPPType &cpp_type, Fn &&fn)
IndexRange face_range(const OffsetIndices< int > faces, const int grid_area, const int face)
bool is_uv_map(const AttributeMetaData &meta_data)
auto attribute_filter_with_skip_ref(const AttributeFilter &filter, const Span< StringRef > skip)
void curves_copy_parameters(const Curves &src, Curves &dst)
void gather_attributes_to_groups(AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, OffsetIndices< int > dst_offsets, const IndexMask &src_selection, MutableAttributeAccessor dst_attributes)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
Vector< AttributeTransferData > retrieve_attributes_for_transfer(const AttributeAccessor src_attributes, MutableAttributeAccessor dst_attributes, Span< AttrDomain > domains, const AttributeFilter &attribute_filter={})
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
Curves * curves_new_nomain(int points_num, int curves_num)
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)
NODE_STORAGE_FUNCS(NodeGeometryDuplicateElements)
static void copy_stable_id_curves(const bke::CurvesGeometry &src_curves, const IndexMask &selection, const OffsetIndices< int > offsets, bke::CurvesGeometry &dst_curves)
static void duplicate_points_grease_pencil(GeometrySet &geometry_set, const Field< int > &count_field, const Field< bool > &selection_field, const IndexAttributes &attribute_outputs, const AttributeFilter &attribute_filter)
static void duplicate_points_pointcloud(GeometrySet &geometry_set, const Field< int > &count_field, const Field< bool > &selection_field, const IndexAttributes &attribute_outputs, const AttributeFilter &attribute_filter)
static void duplicate_faces(GeometrySet &geometry_set, const Field< int > &count_field, const Field< bool > &selection_field, const IndexAttributes &attribute_outputs, const AttributeFilter &attribute_filter)
static OffsetIndices< int > accumulate_counts_to_offsets(const IndexMask &selection, const VArray< int > &counts, Array< int > &r_offset_data)
static void copy_edge_attributes_without_id(const Span< int > point_mapping, const OffsetIndices< int > offsets, const IndexMask &selection, const AttributeFilter &attribute_filter, const bke::AttributeAccessor src_attributes, bke::MutableAttributeAccessor dst_attributes)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void duplicate_instances(GeometrySet &geometry_set, const Field< int > &count_field, const Field< bool > &selection_field, const IndexAttributes &attribute_outputs, const AttributeFilter &attribute_filter)
static bke::CurvesGeometry duplicate_curves_CurveGeometry(const bke::CurvesGeometry &curves, const FieldContext &field_context, const Field< int > &count_field, const Field< bool > &selection_field, const IndexAttributes &attribute_outputs, const AttributeFilter &attribute_filter)
static void copy_stable_id_faces(const Mesh &mesh, const IndexMask &selection, const OffsetIndices< int > face_offsets, const Span< int > vert_mapping, const bke::AttributeAccessor src_attributes, bke::MutableAttributeAccessor dst_attributes)
static void copy_hashed_ids(const Span< int > src, const int hash, MutableSpan< int > dst)
static void duplicate_layers(GeometrySet &geometry_set, const Field< int > &count_field, const Field< bool > &selection_field, const IndexAttributes &attribute_outputs, const AttributeFilter &attribute_filter)
static void duplicate_curves(GeometrySet &geometry_set, const Field< int > &count_field, const Field< bool > &selection_field, const IndexAttributes &attribute_outputs, const AttributeFilter &attribute_filter)
static void copy_stable_id_edges(const Mesh &mesh, const IndexMask &selection, const OffsetIndices< int > offsets, const bke::AttributeAccessor src_attributes, bke::MutableAttributeAccessor dst_attributes)
static void copy_face_attributes_without_id(const Span< int > edge_mapping, const Span< int > vert_mapping, const Span< int > loop_mapping, const OffsetIndices< int > offsets, const IndexMask &selection, const AttributeFilter &attribute_filter, const bke::AttributeAccessor src_attributes, bke::MutableAttributeAccessor dst_attributes)
static void node_declare(NodeDeclarationBuilder &b)
static void duplicate_points_curve(GeometrySet &geometry_set, const Field< int > &count_field, const Field< bool > &selection_field, const IndexAttributes &attribute_outputs, const AttributeFilter &attribute_filter)
static bke::CurvesGeometry duplicate_points_CurvesGeometry(const bke::CurvesGeometry &src_curves, const FieldContext &field_context, const Field< int > &count_field, const Field< bool > &selection_field, const IndexAttributes &attribute_outputs, const AttributeFilter &attribute_filter)
static void copy_attributes_from_other_domains(const bke::AttributeAccessor src_attributes, const AttrDomain domain, const Span< AttrDomain > copied_domains, const OffsetIndices< int > offsets, const IndexMask &selection, const AttributeFilter &attribute_filter, bke::MutableAttributeAccessor dst_attributes)
static void duplicate_points_mesh(GeometrySet &geometry_set, const Field< int > &count_field, const Field< bool > &selection_field, const IndexAttributes &attribute_outputs, const AttributeFilter &attribute_filter)
static void copy_curve_attributes_without_id(const bke::CurvesGeometry &src_curves, const IndexMask &selection, const OffsetIndices< int > curve_offsets, const AttributeFilter &attribute_filter, bke::CurvesGeometry &dst_curves)
static void create_duplicate_index_attribute(bke::MutableAttributeAccessor attributes, const AttrDomain output_domain, const IndexMask &selection, const IndexAttributes &attribute_outputs, const OffsetIndices< int > offsets)
static void duplicate_edges(GeometrySet &geometry_set, const Field< int > &count_field, const Field< bool > &selection_field, const IndexAttributes &attribute_outputs, const AttributeFilter &attribute_filter)
static void threaded_id_offset_copy(const OffsetIndices< int > offsets, const Span< int > src, MutableSpan< int > all_dst)
static void copy_stable_id_point(const OffsetIndices< int > offsets, const bke::AttributeAccessor src_attributes, bke::MutableAttributeAccessor dst_attributes)
static void duplicate_points(GeometrySet &geometry_set, const Field< int > &count_field, const Field< bool > &selection_field, const IndexAttributes &attribute_outputs, const AttributeFilter &attribute_filter)
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)
uint32_t hash(uint32_t kx)
Definition noise.cc:89
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)
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_has_layer(const CustomData *data, eCustomDataType type)
void BKE_grease_pencil_copy_layer_parameters(const bke::greasepencil::Layer &src, bke::greasepencil::Layer &dst)
void BKE_mesh_copy_parameters_for_eval(Mesh *me_dst, const Mesh *me_src)
VecBase< int32_t, 2 > int2
BMesh const char void * data
void BKE_grease_pencil_copy_parameters(const GreasePencil &src, GreasePencil &dst)
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
PointCloud * BKE_pointcloud_new_nomain(PointCloudType type, int totpoint)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
GreasePencil * BKE_grease_pencil_new_nomain()
signed char int8_t
Definition BKE_text.h:76
void * CustomData_add_layer(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem)
#define hash
Definition noise_c.cc:156
#define min(a, b)
Definition sort.cc:38
CustomData face_data
CustomData edge_data
CustomData vert_data
bool allow_skip(const StringRef name) const
void keep_only(Span< GeometryComponent::Type > component_types)
const GreasePencil * get_grease_pencil() const
void replace_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const Curves * get_curves() const
const Instances * get_instances() const
void replace_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const PointCloud * get_pointcloud() const
const Mesh * get_mesh() const
void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
GreasePencil * get_grease_pencil_for_write()
Vector< GeometryComponent::Type > gather_component_types(bool include_instances, bool ignore_empty) const
void replace_grease_pencil(GreasePencil *grease_pencil, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
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
static GeometrySet from_instances(std::unique_ptr< Instances > instances)
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)