Blender V5.3
curves_ops.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
8
9#include "BLI_array_utils.hh"
10#include "BLI_generic_array.hh"
12#include "BLI_listbase.hh"
13#include "BLI_math_geom_c.hh"
14#include "BLI_math_matrix.hh"
15#include "BLI_string.hh"
16#include "BLI_utildefines.hh"
17#include "BLI_vector_set.hh"
18
19#include "BLT_translation.hh"
20
21#include "ED_curves.hh"
22#include "ED_object.hh"
23#include "ED_screen.hh"
24#include "ED_select_utils.hh"
25#include "ED_view3d.hh"
26
27#include "WM_api.hh"
28
29#include "BKE_attribute.h"
30#include "BKE_attribute_math.hh"
31#include "BKE_bvh.hh"
32#include "BKE_bvhutils.hh"
33#include "BKE_context.hh"
34#include "BKE_curves.hh"
35#include "BKE_customdata.hh"
36#include "BKE_geometry_set.hh"
37#include "BKE_layer.hh"
38#include "BKE_lib_id.hh"
39#include "BKE_mesh.hh"
41#include "BKE_mesh_runtime.hh"
42#include "BKE_mesh_sample.hh"
43#include "BKE_object.hh"
44#include "BKE_paint.hh"
45#include "BKE_particle.h"
46#include "BKE_report.hh"
47
48#include "DNA_mesh_types.h"
49#include "DNA_meshdata_types.h"
50#include "DNA_modifier_types.h"
51#include "DNA_object_types.h"
52#include "DNA_particle_types.h"
53#include "DNA_scene_types.h"
54
55#include "DEG_depsgraph.hh"
57
58#include "RNA_access.hh"
59#include "RNA_define.hh"
60#include "RNA_enum_types.hh"
61#include "RNA_prototypes.hh"
62
64#include "UI_resources.hh"
65
68#include "GEO_set_curve_type.hh"
70#include "GEO_transform.hh"
71
79
80namespace blender::ed::curves {
81
86
87bool object_has_editable_curves(const Main &bmain, const Object &object)
88{
89 if (object.type != OB_CURVES) {
90 return false;
91 }
92 if (!ELEM(object.mode, OB_MODE_SCULPT_CURVES, OB_MODE_EDIT)) {
93 return false;
94 }
95 if (!BKE_id_is_editable(&bmain, static_cast<const ID *>(object.data))) {
96 return false;
97 }
98 return true;
99}
100
102{
103 VectorSet<Curves *> unique_curves;
104
105 const Main &bmain = *CTX_data_main(&C);
106
107 Object *object = CTX_data_active_object(&C);
108 if (object && object_has_editable_curves(bmain, *object)) {
109 unique_curves.add_new(id_cast<Curves *>(object->data));
110 }
111
112 CTX_DATA_BEGIN (&C, Object *, object, selected_objects) {
113 if (object_has_editable_curves(bmain, *object)) {
114 unique_curves.add(id_cast<Curves *>(object->data));
115 }
116 }
118
119 return unique_curves;
120}
121
123 const bool check_editable,
124 const bool check_surface,
125 const bool check_edit_mode)
126{
128 if (object == nullptr || object->type != OB_CURVES) {
129 return false;
130 }
131 if (check_editable) {
133 return false;
134 }
135 }
136 if (check_surface) {
137 Curves &curves = *id_cast<Curves *>(object->data);
138 if (curves.surface == nullptr || curves.surface->type != OB_MESH) {
139 CTX_wm_operator_poll_msg_set(C, "Curves must have a mesh surface object set");
140 return false;
141 }
142 }
143 if (check_edit_mode) {
144 if ((object->mode & OB_MODE_EDIT) == 0) {
145 return false;
146 }
147 }
148 return true;
149}
150
152{
153 return curves_poll_impl(C, true, false, true);
154}
155
157{
158 return curves_poll_impl(C, true, true, false);
159}
160
162{
163 return curves_poll_impl(C, false, true, false);
164}
165
167{
168 return curves_poll_impl(C, false, false, false);
169}
170
172{
173 return curves_poll_impl(C, false, false, false);
174}
175
177{
179 return false;
180 }
181 const Curves *curves_id = id_cast<const Curves *>(CTX_data_active_object(C)->data);
182 if (bke::AttrDomain(curves_id->selection_domain) != bke::AttrDomain::Point) {
183 CTX_wm_operator_poll_msg_set(C, "Only available in point selection mode");
184 return false;
185 }
186 return true;
187}
188
190
192
194 const MFace *mface,
195 const Span<int> possible_mface_indices,
196 const float3 &root_pos)
197{
198 BLI_assert(possible_mface_indices.size() >= 1);
199 if (possible_mface_indices.size() == 1) {
200 return possible_mface_indices.first();
201 }
202 /* Find the closest #MFace to #root_pos. */
203 int mface_i;
204 float best_distance_sq = FLT_MAX;
205 for (const int possible_mface_i : possible_mface_indices) {
206 const MFace &possible_mface = mface[possible_mface_i];
207 {
208 float3 point_in_triangle;
209 closest_on_tri_to_point_v3(point_in_triangle,
210 root_pos,
211 positions[possible_mface.v1],
212 positions[possible_mface.v2],
213 positions[possible_mface.v3]);
214 const float distance_sq = len_squared_v3v3(root_pos, point_in_triangle);
215 if (distance_sq < best_distance_sq) {
216 best_distance_sq = distance_sq;
217 mface_i = possible_mface_i;
218 }
219 }
220 /* Optionally check the second triangle if the #MFace is a quad. */
221 if (possible_mface.v4) {
222 float3 point_in_triangle;
223 closest_on_tri_to_point_v3(point_in_triangle,
224 root_pos,
225 positions[possible_mface.v1],
226 positions[possible_mface.v3],
227 positions[possible_mface.v4]);
228 const float distance_sq = len_squared_v3v3(root_pos, point_in_triangle);
229 if (distance_sq < best_distance_sq) {
230 best_distance_sq = distance_sq;
231 mface_i = possible_mface_i;
232 }
233 }
234 }
235 return mface_i;
236}
237
242 const MFace &mface,
243 const float3 &position)
244{
245 float4 mface_weights;
246 if (mface.v4) {
247 float mface_positions_su[4][3];
248 copy_v3_v3(mface_positions_su[0], positions[mface.v1]);
249 copy_v3_v3(mface_positions_su[1], positions[mface.v2]);
250 copy_v3_v3(mface_positions_su[2], positions[mface.v3]);
251 copy_v3_v3(mface_positions_su[3], positions[mface.v4]);
252 interp_weights_poly_v3(mface_weights, mface_positions_su, 4, position);
253 }
254 else {
256 mface_weights, positions[mface.v1], positions[mface.v2], positions[mface.v3], position);
257 mface_weights[3] = 0.0f;
258 }
259 return mface_weights;
260}
261
262static void try_convert_single_object(Object &curves_ob,
263 Main &bmain,
264 Scene &scene,
265 bool *r_could_not_convert_some_curves)
266{
267 if (curves_ob.type != OB_CURVES) {
268 return;
269 }
270 Curves &curves_id = *id_cast<Curves *>(curves_ob.data);
271 CurvesGeometry &curves = curves_id.geometry.wrap();
272 if (curves_id.surface == nullptr) {
273 return;
274 }
275 Object &surface_ob = *curves_id.surface;
276 if (surface_ob.type != OB_MESH) {
277 return;
278 }
279 Mesh &surface_me = *id_cast<Mesh *>(surface_ob.data);
280
281 const bke::bvh::Tree &surface_bvh = surface_me.bvh_tris();
282
283 const Span<float3> positions_cu = curves.positions();
284 const Span<int> tri_faces = surface_me.corner_tri_faces();
285
286 if (tri_faces.is_empty()) {
287 *r_could_not_convert_some_curves = true;
288 }
289
290 const OffsetIndices<int> points_by_curve = curves.points_by_curve();
291 IndexMaskMemory memory;
292 const IndexMask multi_point_curves = IndexMask::from_predicate(
293 curves.curves_range(), memory, [&](const int curve_i) {
294 return points_by_curve[curve_i].size() > 1;
295 });
296
297 const int hair_num = multi_point_curves.size();
298
299 if (hair_num == 0) {
300 return;
301 }
302
303 ParticleSystem *particle_system = nullptr;
304 for (ParticleSystem &psys : surface_ob.particlesystem) {
305 if (STREQ(psys.name, curves_ob.id.name + 2)) {
306 particle_system = &psys;
307 break;
308 }
309 }
310 if (particle_system == nullptr) {
311 ParticleSystemModifierData &psmd = *reinterpret_cast<ParticleSystemModifierData *>(
312 object_add_particle_system(&bmain, &scene, &surface_ob, curves_ob.id.name + 2));
313 particle_system = psmd.psys;
314 particle_system->part->draw_step = 3;
315 }
316
317 ParticleSettings &settings = *particle_system->part;
318
319 psys_free_particles(particle_system);
320 settings.type = PART_HAIR;
321 settings.totpart = 0;
322 psys_changed_type(&surface_ob, particle_system);
323
324 MutableSpan<ParticleData> particles{MEM_new_array<ParticleData>(hair_num, __func__), hair_num};
325
326 /* The old hair system still uses #MFace, so make sure those are available on the mesh. */
327 BKE_mesh_tessface_calc(&surface_me);
328
329 /* Prepare utility data structure to map hair roots to #MFace's. */
330 const Span<int> mface_to_poly_map{
331 static_cast<const int *>(CustomData_get_layer(&surface_me.fdata_legacy, CD_ORIGINDEX)),
332 surface_me.totface_legacy};
333 Array<Vector<int>> poly_to_mface_map(surface_me.faces_num);
334 for (const int mface_i : mface_to_poly_map.index_range()) {
335 const int face_i = mface_to_poly_map[mface_i];
336 poly_to_mface_map[face_i].append(mface_i);
337 }
338
339 /* Prepare transformation matrices. */
340 const bke::CurvesSurfaceTransforms transforms{curves_ob, &surface_ob};
341
342 const MFace *mfaces = static_cast<const MFace *>(
344 const Span<float3> positions = surface_me.vert_positions();
345
346 multi_point_curves.foreach_index([&](const int curve_i, const int new_hair_i) {
347 const IndexRange points = points_by_curve[curve_i];
348
349 const float3 &root_pos_cu = positions_cu[points.first()];
350 const float3 root_pos_su = math::transform_point(transforms.curves_to_surface, root_pos_cu);
351
352 const std::optional<bke::bvh::ClosestPointResult> nearest = surface_bvh.closest_point(
353 root_pos_su);
354 BLI_assert(nearest.has_value());
355
356 const int tri_i = nearest->index;
357 const int face_i = tri_faces[tri_i];
358
359 const int mface_i = find_mface_for_root_position(
360 positions, mfaces, poly_to_mface_map[face_i], root_pos_su);
361 const MFace &mface = mfaces[mface_i];
362
363 const float4 mface_weights = compute_mface_weights_for_position(positions, mface, root_pos_su);
364
365 ParticleData &particle = particles[new_hair_i];
366 const int num_keys = points.size();
367 MutableSpan<HairKey> hair_keys{
368 MEM_new_array_zeroed<HairKey>(num_keys, "try_convert_single_object hair_keys"), num_keys};
369
370 particle.hair = hair_keys.data();
371 particle.totkey = hair_keys.size();
372 copy_v4_v4(particle.fuv, mface_weights);
373 particle.num = mface_i;
374 /* Not sure if there is a better way to initialize this. */
375 particle.num_dmcache = DMCACHE_NOTFOUND;
376
377 float4x4 hair_to_surface_mat;
379 &surface_ob, &surface_me, PART_FROM_FACE, &particle, hair_to_surface_mat.ptr());
380 /* In theory, #psys_mat_hair_to_object should handle this, but it doesn't right now. */
381 hair_to_surface_mat.location() = root_pos_su;
382 const float4x4 surface_to_hair_mat = math::invert(hair_to_surface_mat);
383
384 for (const int key_i : hair_keys.index_range()) {
385 const float3 &key_pos_cu = positions_cu[points[key_i]];
386 const float3 key_pos_su = math::transform_point(transforms.curves_to_surface, key_pos_cu);
387 const float3 key_pos_ha = math::transform_point(surface_to_hair_mat, key_pos_su);
388
389 HairKey &key = hair_keys[key_i];
390 copy_v3_v3(key.co, key_pos_ha);
391 const float key_fac = key_i / float(hair_keys.size() - 1);
392 key.time = 100.0f * key_fac;
393 key.weight = 1.0f - key_fac;
394 }
395 });
396
397 particle_system->particles = particles.data();
398 particle_system->totpart = particles.size();
399 particle_system->flag |= PSYS_EDITED;
400 particle_system->recalc |= ID_RECALC_PSYS_RESET;
401
404}
405
407{
408 Main &bmain = *CTX_data_main(C);
409 Scene &scene = *CTX_data_scene(C);
410
411 bool could_not_convert_some_curves = false;
412
413 Object &active_object = *CTX_data_active_object(C);
414 try_convert_single_object(active_object, bmain, scene, &could_not_convert_some_curves);
415
416 CTX_DATA_BEGIN (C, Object *, curves_ob, selected_objects) {
417 if (curves_ob != &active_object) {
418 try_convert_single_object(*curves_ob, bmain, scene, &could_not_convert_some_curves);
419 }
420 }
422
423 if (could_not_convert_some_curves) {
425 RPT_INFO,
426 "Some curves could not be converted because they were not attached to the surface");
427 }
428
430
431 return OPERATOR_FINISHED;
432}
433
434} // namespace convert_to_particle_system
435
437{
438 ot->name = "Convert Curves to Particle System";
439 ot->idname = "CURVES_OT_convert_to_particle_system";
440 ot->description = "Add a new or update an existing hair particle system on the surface object";
441
444
446}
447
449
451{
452 ParticleSettings &settings = *psys.part;
453 if (psys.part->type != PART_HAIR) {
454 return {};
455 }
456
457 const bool transfer_parents = (settings.draw & PART_DRAW_PARENT) || settings.childtype == 0;
458
459 const Span<ParticleCacheKey *> parents_cache{psys.pathcache, psys.totcached};
460 const Span<ParticleCacheKey *> children_cache{psys.childcache, psys.totchildcache};
461
462 int points_num = 0;
463 Vector<int> curve_offsets;
464 Vector<int> parents_to_transfer;
465 Vector<int> children_to_transfer;
466 if (transfer_parents) {
467 for (const int parent_i : parents_cache.index_range()) {
468 const int segments = parents_cache[parent_i]->segments;
469 if (segments <= 0) {
470 continue;
471 }
472 parents_to_transfer.append(parent_i);
473 curve_offsets.append(points_num);
474 points_num += segments + 1;
475 }
476 }
477 for (const int child_i : children_cache.index_range()) {
478 const int segments = children_cache[child_i]->segments;
479 if (segments <= 0) {
480 continue;
481 }
482 children_to_transfer.append(child_i);
483 curve_offsets.append(points_num);
484 points_num += segments + 1;
485 }
486 const int curves_num = parents_to_transfer.size() + children_to_transfer.size();
487 curve_offsets.append(points_num);
488 BLI_assert(curve_offsets.size() == curves_num + 1);
489 bke::CurvesGeometry curves(points_num, curves_num);
490 curves.offsets_for_write().copy_from(curve_offsets);
491
492 const float4x4 &object_to_world_mat = object.object_to_world();
493 const float4x4 world_to_object_mat = math::invert(object_to_world_mat);
494
495 MutableSpan<float3> positions = curves.positions_for_write();
496 const OffsetIndices points_by_curve = curves.points_by_curve();
497
498 const auto copy_hair_to_curves = [&](const Span<ParticleCacheKey *> hair_cache,
499 const Span<int> indices_to_transfer,
500 const int curve_index_offset) {
501 threading::parallel_for(indices_to_transfer.index_range(), 256, [&](const IndexRange range) {
502 for (const int i : range) {
503 const int hair_i = indices_to_transfer[i];
504 const int curve_i = i + curve_index_offset;
505 const IndexRange points = points_by_curve[curve_i];
506 const Span<ParticleCacheKey> keys{hair_cache[hair_i], points.size()};
507 for (const int key_i : keys.index_range()) {
508 const float3 key_pos_wo = keys[key_i].co;
509 positions[points[key_i]] = math::transform_point(world_to_object_mat, key_pos_wo);
510 }
511 }
512 });
513 };
514
515 if (transfer_parents) {
516 copy_hair_to_curves(parents_cache, parents_to_transfer, 0);
517 }
518 copy_hair_to_curves(children_cache, children_to_transfer, parents_to_transfer.size());
519
520 curves.update_curve_types();
521 curves.tag_topology_changed();
522 return curves;
523}
524
526{
527 Main &bmain = *CTX_data_main(C);
528 Scene &scene = *CTX_data_scene(C);
529 ViewLayer &view_layer = *CTX_data_view_layer(C);
530 Depsgraph &depsgraph = *CTX_data_depsgraph_pointer(C);
531 Object *ob_from_orig = object::context_active_object(C);
532 ParticleSystem *psys_orig = static_cast<ParticleSystem *>(
533 CTX_data_pointer_get_type(C, "particle_system", RNA_ParticleSystem).data);
534 if (psys_orig == nullptr) {
535 psys_orig = psys_get_current(ob_from_orig);
536 }
537 if (psys_orig == nullptr) {
538 return OPERATOR_CANCELLED;
539 }
540 Object *ob_from_eval = DEG_get_evaluated(&depsgraph, ob_from_orig);
541 ParticleSystem *psys_eval = nullptr;
542 for (ModifierData &md : ob_from_eval->modifiers) {
544 continue;
545 }
546 ParticleSystemModifierData *psmd = reinterpret_cast<ParticleSystemModifierData *>(&md);
547 if (!STREQ(psmd->psys->name, psys_orig->name)) {
548 continue;
549 }
550 psys_eval = psmd->psys;
551 }
552
553 Object *ob_new = BKE_object_add(&bmain, &scene, &view_layer, OB_CURVES, psys_eval->name);
554 Curves *curves_id = id_cast<Curves *>(ob_new->data);
555 BKE_object_apply_mat4(ob_new, ob_from_orig->object_to_world().ptr(), true, false);
556 curves_id->geometry.wrap() = particles_to_curves(*ob_from_eval, *psys_eval);
557
560
561 return OPERATOR_FINISHED;
562}
563
568
569} // namespace convert_from_particle_system
570
572{
573 ot->name = "Convert Particle System to Curves";
574 ot->idname = "CURVES_OT_convert_from_particle_system";
575 ot->description = "Add a new curves object based on the current state of the particle system";
576
579
581}
582
584
585enum class AttachMode {
588};
589
591 const Object &surface_ob,
592 const AttachMode attach_mode,
593 bool *r_invalid_uvs,
594 bool *r_missing_uvs)
595{
596 Curves &curves_id = *id_cast<Curves *>(curves_ob.data);
597 CurvesGeometry &curves = curves_id.geometry.wrap();
598
599 const Mesh &surface_mesh = *id_cast<const Mesh *>(surface_ob.data);
600 const Span<float3> surface_positions = surface_mesh.vert_positions();
601 const Span<int> corner_verts = surface_mesh.corner_verts();
602 const Span<int3> surface_corner_tris = surface_mesh.corner_tris();
603 VArraySpan<float2> surface_uv_map;
604 if (curves_id.surface_uv_map != nullptr) {
605 const bke::AttributeAccessor surface_attributes = surface_mesh.attributes();
606 surface_uv_map = *surface_attributes.lookup<float2>(curves_id.surface_uv_map,
608 }
609
610 const OffsetIndices points_by_curve = curves.points_by_curve();
611 MutableSpan<float3> positions_cu = curves.positions_for_write();
612 MutableSpan<float2> surface_uv_coords = curves.surface_uv_coords_for_write();
613
614 const bke::CurvesSurfaceTransforms transforms{curves_ob, &surface_ob};
615
616 switch (attach_mode) {
617 case AttachMode::Nearest: {
618 const bke::bvh::Tree &surface_bvh = surface_mesh.bvh_tris();
619
620 threading::parallel_for(curves.curves_range(), 256, [&](const IndexRange curves_range) {
621 for (const int curve_i : curves_range) {
622 const IndexRange points = points_by_curve[curve_i];
623 const int first_point_i = points.first();
624 const float3 old_first_point_pos_cu = positions_cu[first_point_i];
625 const float3 old_first_point_pos_su = math::transform_point(transforms.curves_to_surface,
626 old_first_point_pos_cu);
627
628 const std::optional<bke::bvh::ClosestPointResult> nearest = surface_bvh.closest_point(
629 old_first_point_pos_su);
630 if (!nearest) {
631 continue;
632 }
633 const int tri_index = nearest->index;
634
635 const float3 new_first_point_pos_su = nearest->position;
636 const float3 new_first_point_pos_cu = math::transform_point(transforms.surface_to_curves,
637 new_first_point_pos_su);
638 const float3 pos_diff_cu = new_first_point_pos_cu - old_first_point_pos_cu;
639
640 for (float3 &pos_cu : positions_cu.slice(points)) {
641 pos_cu += pos_diff_cu;
642 }
643
644 if (!surface_uv_map.is_empty()) {
645 const int3 &tri = surface_corner_tris[tri_index];
646 const float3 bary_coords = bke::mesh_surface_sample::compute_bary_coord_in_triangle(
647 surface_positions, corner_verts, tri, new_first_point_pos_su);
648 const float2 uv = bke::mesh_surface_sample::sample_corner_attribute_with_bary_coords(
649 bary_coords, tri, surface_uv_map);
650 surface_uv_coords[curve_i] = uv;
651 }
652 }
653 });
654 break;
655 }
656 case AttachMode::Deform: {
657 if (surface_uv_map.is_empty()) {
658 *r_missing_uvs = true;
659 break;
660 }
662 ReverseUVSampler reverse_uv_sampler{surface_uv_map, surface_corner_tris};
663
664 threading::parallel_for(curves.curves_range(), 256, [&](const IndexRange curves_range) {
665 for (const int curve_i : curves_range) {
666 const IndexRange points = points_by_curve[curve_i];
667 const int first_point_i = points.first();
668 const float3 old_first_point_pos_cu = positions_cu[first_point_i];
669
670 const float2 uv = surface_uv_coords[curve_i];
671 ReverseUVSampler::Result lookup_result = reverse_uv_sampler.sample(uv);
672 if (lookup_result.type != ReverseUVSampler::ResultType::Ok) {
673 *r_invalid_uvs = true;
674 continue;
675 }
676
677 const int3 &tri = surface_corner_tris[lookup_result.tri_index];
678 const float3 &bary_coords = lookup_result.bary_weights;
679
680 const float3 &p0_su = surface_positions[corner_verts[tri[0]]];
681 const float3 &p1_su = surface_positions[corner_verts[tri[1]]];
682 const float3 &p2_su = surface_positions[corner_verts[tri[2]]];
683
684 float3 new_first_point_pos_su;
685 interp_v3_v3v3v3(new_first_point_pos_su, p0_su, p1_su, p2_su, bary_coords);
686 const float3 new_first_point_pos_cu = math::transform_point(transforms.surface_to_curves,
687 new_first_point_pos_su);
688
689 const float3 pos_diff_cu = new_first_point_pos_cu - old_first_point_pos_cu;
690 for (float3 &pos_cu : positions_cu.slice(points)) {
691 pos_cu += pos_diff_cu;
692 }
693 }
694 });
695 break;
696 }
697 }
698
699 curves.tag_positions_changed();
701}
702
704{
705 const AttachMode attach_mode = static_cast<AttachMode>(RNA_enum_get(op->ptr, "attach_mode"));
706
707 bool found_invalid_uvs = false;
708 bool found_missing_uvs = false;
709
710 CTX_DATA_BEGIN (C, Object *, curves_ob, selected_objects) {
711 if (curves_ob->type != OB_CURVES) {
712 continue;
713 }
714 Curves &curves_id = *id_cast<Curves *>(curves_ob->data);
715 if (curves_id.surface == nullptr) {
716 continue;
717 }
718 if (curves_id.surface->type != OB_MESH) {
719 continue;
720 }
722 *curves_ob, *curves_id.surface, attach_mode, &found_invalid_uvs, &found_missing_uvs);
723 }
725
726 if (found_missing_uvs) {
728 RPT_ERROR,
729 "Curves do not have attachment information that can be used for deformation");
730 }
731 if (found_invalid_uvs) {
732 BKE_report(op->reports, RPT_INFO, "Could not snap some curves to the surface");
733 }
734
735 /* Refresh the entire window to also clear eventual modifier and nodes editor warnings. */
737
738 return OPERATOR_FINISHED;
739}
740
741} // namespace snap_curves_to_surface
742
744{
745 using namespace snap_curves_to_surface;
746
747 ot->name = "Snap Curves to Surface";
748 ot->idname = "CURVES_OT_snap_curves_to_surface";
749 ot->description = "Move curves so that the first point is exactly on the surface mesh";
750
752 ot->exec = snap_curves_to_surface_exec;
753
755
756 static const EnumPropertyItem attach_mode_items[] = {
757 {int(AttachMode::Nearest),
758 "NEAREST",
759 0,
760 "Nearest",
761 "Find the closest point on the surface for the root point of every curve and move the root "
762 "there"},
763 {int(AttachMode::Deform),
764 "DEFORM",
765 0,
766 "Deform",
767 "Re-attach curves to a deformed surface using the existing attachment information. This "
768 "only works when the topology of the surface mesh has not changed"},
769 {0, nullptr, 0, nullptr, nullptr},
770 };
771
772 RNA_def_enum(ot->srna,
773 "attach_mode",
774 attach_mode_items,
775 int(AttachMode::Nearest),
776 "Attach Mode",
777 "How to find the point on the surface to attach to");
778}
779
781
783{
784 const bke::AttrDomain domain = bke::AttrDomain(RNA_enum_get(op->ptr, "domain"));
785
786 for (Curves *curves_id : get_unique_editable_curves(*C)) {
787 if (bke::AttrDomain(curves_id->selection_domain) == domain) {
788 continue;
789 }
790
791 curves_id->selection_domain = char(domain);
792
793 CurvesGeometry &curves = curves_id->geometry.wrap();
794 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
795 if (curves.is_empty()) {
796 continue;
797 }
798
799 /* Adding and removing attributes with the C++ API doesn't affect the active attribute index.
800 * In order to make the active attribute consistent before and after the change, save the name
801 * and reset the active item afterwards.
802 *
803 * This would be unnecessary if the active attribute were stored as a string on the ID. */
804 AttributeOwner owner = AttributeOwner::from_id(&curves_id->id);
805 const std::string active_attribute = BKE_attributes_active_name_get(owner).value_or("");
806 for (const StringRef selection_name : get_curves_selection_attribute_names(curves)) {
807 if (const GVArray src = *attributes.lookup(selection_name, domain)) {
808 auto *dst = new ImplicitSharedValue<GArray<>>(src.type(), src.size(), NoInitialization());
809 src.materialize_to_uninitialized(dst->data.data());
810
811 attributes.remove(selection_name);
812 attributes.add(selection_name,
813 domain,
814 bke::cpp_type_to_attribute_type(dst->data.type()),
815 bke::AttributeInitShared(dst->data.data(), *dst));
816 dst->remove_user_and_delete_if_last();
817 }
818 }
819 if (!active_attribute.empty()) {
820 BKE_attributes_active_set(owner, active_attribute);
821 }
822
823 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
824 * attribute for now. */
825 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
826 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
827 }
828
830
831 return OPERATOR_FINISHED;
832}
833
834} // namespace set_selection_domain
835
837{
838 PropertyRNA *prop;
839
840 ot->name = "Set Select Mode";
841 ot->idname = __func__;
842 ot->description = "Change the mode used for selection masking in curves sculpt mode";
843
846
848
849 ot->prop = prop = RNA_def_enum(
850 ot->srna, "domain", rna_enum_attribute_curves_domain_items, 0, "Domain", "");
852}
853
854static bool has_anything_selected(const Span<Curves *> curves_ids)
855{
856 return std::any_of(curves_ids.begin(), curves_ids.end(), [](const Curves *curves_id) {
857 return has_anything_selected(curves_id->geometry.wrap());
858 });
859}
860
862{
863 int action = RNA_enum_get(op->ptr, "action");
864
866
867 if (action == SEL_TOGGLE) {
868 action = has_anything_selected(unique_curves) ? SEL_DESELECT : SEL_SELECT;
869 }
870
871 for (Curves *curves_id : unique_curves) {
872 /* (De)select all the curves. */
873 select_all(curves_id->geometry.wrap(), bke::AttrDomain(curves_id->selection_domain), action);
874
875 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
876 * attribute for now. */
877 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
878 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
879 }
880
881 return OPERATOR_FINISHED;
882}
883
885{
886 ot->name = "(De)select All";
887 ot->idname = "CURVES_OT_select_all";
888 ot->description = "(De)select all control points";
889
890 ot->exec = select_all_exec;
892
894
896}
897
899{
901
902 const int seed = RNA_int_get(op->ptr, "seed");
903 const float probability = RNA_float_get(op->ptr, "probability");
904
905 for (Curves *curves_id : unique_curves) {
906 CurvesGeometry &curves = curves_id->geometry.wrap();
907 const bke::AttrDomain selection_domain = bke::AttrDomain(curves_id->selection_domain);
908 const int domain_size = curves.attributes().domain_size(selection_domain);
909
910 IndexMaskMemory memory;
911 const IndexMask inv_random_elements = random_mask(domain_size, seed, probability, memory)
912 .complement(IndexRange(domain_size), memory);
913
914 const bool was_anything_selected = has_anything_selected(curves);
916 curves, selection_domain, bke::AttrType::Bool);
917 if (!was_anything_selected) {
919 }
920
921 curves::fill_selection_false(selection.span, inv_random_elements);
922 selection.finish();
923
924 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
925 * attribute for now. */
926 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
927 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
928 }
929 return OPERATOR_FINISHED;
930}
931
932static void select_random_ui(bContext * /*C*/, wmOperator *op)
933{
934 ui::Layout &layout = *op->layout;
935
936 layout.prop(op->ptr, "seed", UI_ITEM_NONE, std::nullopt, ICON_NONE);
937 layout.prop(op->ptr, "probability", ui::ITEM_R_SLIDER, IFACE_("Probability"), ICON_NONE);
938}
939
941{
942 ot->name = "Select Random";
943 ot->idname = __func__;
944 ot->description = "Randomize existing selection or create new random selection";
945
948 ot->ui = select_random_ui;
949
951
952 RNA_def_int(ot->srna,
953 "seed",
954 0,
955 INT32_MIN,
956 INT32_MAX,
957 "Seed",
958 "Source of randomness",
959 INT32_MIN,
960 INT32_MAX);
962 "probability",
963 0.5f,
964 0.0f,
965 1.0f,
966 "Probability",
967 "Chance of every point or curve being included in the selection",
968 0.0f,
969 1.0f);
970}
971
973{
975 const int amount_start = RNA_int_get(op->ptr, "amount_start");
976 const int amount_end = RNA_int_get(op->ptr, "amount_end");
977
978 for (Curves *curves_id : unique_curves) {
979 CurvesGeometry &curves = curves_id->geometry.wrap();
980
981 IndexMaskMemory memory;
982 const IndexMask inverted_end_points_mask = end_points(
983 curves, amount_start, amount_end, true, memory);
984
985 const bool was_anything_selected = has_anything_selected(curves);
988 if (!was_anything_selected) {
989 fill_selection_true(selection.span);
990 }
991
992 if (selection.span.type().is<bool>()) {
993 index_mask::masked_fill(selection.span.typed<bool>(), false, inverted_end_points_mask);
994 }
995 if (selection.span.type().is<float>()) {
996 index_mask::masked_fill(selection.span.typed<float>(), 0.0f, inverted_end_points_mask);
997 }
998 selection.finish();
999
1000 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
1001 * attribute for now. */
1002 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1003 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1004 }
1005
1006 return OPERATOR_FINISHED;
1007}
1008
1009static void select_ends_ui(bContext * /*C*/, wmOperator *op)
1010{
1011 ui::Layout &layout = *op->layout;
1012
1013 layout.use_property_split_set(true);
1014
1015 ui::Layout &col = layout.column(true);
1016 col.use_property_decorate_set(false);
1017 col.prop(op->ptr, "amount_start", UI_ITEM_NONE, IFACE_("Amount Start"), ICON_NONE);
1018 col.prop(op->ptr, "amount_end", UI_ITEM_NONE, IFACE_("End"), ICON_NONE);
1019}
1020
1022{
1023 ot->name = "Select Ends";
1024 ot->idname = __func__;
1025 ot->description = "Select end points of curves";
1026
1027 ot->exec = select_ends_exec;
1028 ot->ui = select_ends_ui;
1030
1032
1033 RNA_def_int(ot->srna,
1034 "amount_start",
1035 0,
1036 0,
1037 INT32_MAX,
1038 "Amount Front",
1039 "Number of points to select from the front",
1040 0,
1041 INT32_MAX);
1042 RNA_def_int(ot->srna,
1043 "amount_end",
1044 1,
1045 0,
1046 INT32_MAX,
1047 "Amount Back",
1048 "Number of points to select from the back",
1049 0,
1050 INT32_MAX);
1051}
1052
1054{
1056 for (Curves *curves_id : unique_curves) {
1057 CurvesGeometry &curves = curves_id->geometry.wrap();
1059 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
1060 * attribute for now. */
1061 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1062 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1063 }
1064
1065 return OPERATOR_FINISHED;
1066}
1067
1069{
1070 ot->name = "Select Linked";
1071 ot->idname = __func__;
1072 ot->description = "Select all points in curves with any point selection";
1073
1076
1078}
1079
1081{
1083 for (Curves *curves_id : unique_curves) {
1084 CurvesGeometry &curves = curves_id->geometry.wrap();
1085 select_adjacent(curves, false);
1086 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
1087 * attribute for now. */
1088 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1089 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1090 }
1091
1092 return OPERATOR_FINISHED;
1093}
1094
1096{
1097 ot->name = "Select More";
1098 ot->idname = __func__;
1099 ot->description = "Grow the selection by one point";
1100
1101 ot->exec = select_more_exec;
1103
1105}
1106
1108{
1110 for (Curves *curves_id : unique_curves) {
1111 CurvesGeometry &curves = curves_id->geometry.wrap();
1112 select_adjacent(curves, true);
1113 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
1114 * attribute for now. */
1115 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1116 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1117 }
1118
1119 return OPERATOR_FINISHED;
1120}
1121
1123{
1124 ot->name = "Select Less";
1125 ot->idname = __func__;
1126 ot->description = "Shrink the selection by one point";
1127
1128 ot->exec = select_less_exec;
1130
1132}
1133
1134namespace split {
1135
1137{
1138 View3D *v3d = CTX_wm_view3d(C);
1139 const eHandleDisplay handle_display = view3d_handle_type_or_default(v3d);
1141 for (Curves *curves_id : unique_curves) {
1142 CurvesGeometry &curves = curves_id->geometry.wrap();
1143 IndexMaskMemory memory;
1144 const IndexMask points_to_split = retrieve_all_selected_points(curves, handle_display, memory);
1145 if (points_to_split.is_empty()) {
1146 continue;
1147 }
1148 curves = split_points(curves, points_to_split);
1149
1150 curves.calculate_bezier_auto_handles();
1151
1152 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1153 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1154 }
1155
1156 return OPERATOR_FINISHED;
1157}
1158
1159} // namespace split
1160
1162{
1163 ot->name = "Split";
1164 ot->idname = __func__;
1165 ot->description = "Split selected points";
1166
1167 ot->exec = split::split_exec;
1169
1171}
1172
1173namespace surface_set {
1174
1176{
1177 const Object *object = CTX_data_active_object(C);
1178 if (object == nullptr) {
1179 return false;
1180 }
1181 if (object->type != OB_MESH) {
1182 return false;
1183 }
1184 return true;
1185}
1186
1188{
1189 Main *bmain = CTX_data_main(C);
1190 Scene *scene = CTX_data_scene(C);
1191
1192 Object &new_surface_ob = *CTX_data_active_object(C);
1193
1194 Mesh &new_surface_mesh = *id_cast<Mesh *>(new_surface_ob.data);
1195 const StringRef new_uv_map_name = new_surface_mesh.active_uv_map_name();
1196
1197 CTX_DATA_BEGIN (C, Object *, selected_ob, selected_objects) {
1198 if (selected_ob->type != OB_CURVES) {
1199 continue;
1200 }
1201 Object &curves_ob = *selected_ob;
1202 Curves &curves_id = *id_cast<Curves *>(curves_ob.data);
1203
1204 MEM_SAFE_DELETE(curves_id.surface_uv_map);
1205 if (!new_uv_map_name.is_empty()) {
1206 curves_id.surface_uv_map = BLI_strdupn(new_uv_map_name.data(), new_uv_map_name.size());
1207 }
1208
1209 bool missing_uvs;
1210 bool invalid_uvs;
1212 curves_ob,
1213 new_surface_ob,
1215 &invalid_uvs,
1216 &missing_uvs);
1217
1218 /* Add deformation modifier if necessary. */
1220
1221 curves_id.surface = &new_surface_ob;
1223 C,
1224 scene,
1225 &curves_ob,
1226 &new_surface_ob,
1228 false,
1229 true,
1230 nullptr);
1231
1233 WM_event_add_notifier(C, NC_GEOM | ND_DATA, &curves_id);
1235
1236 /* Required for deformation. */
1238 DEG_id_tag_update(&new_surface_ob.id, ID_RECALC_GEOMETRY);
1239 }
1241
1243
1244 return OPERATOR_FINISHED;
1245}
1246
1247} // namespace surface_set
1248
1250{
1251 ot->name = "Set Curves Surface Object";
1252 ot->idname = __func__;
1253 ot->description =
1254 "Use the active object as surface for selected curves objects and set it as the parent";
1255
1258
1260}
1261
1262namespace curves_delete {
1263
1265{
1266 for (Curves *curves_id : get_unique_editable_curves(*C)) {
1267 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
1268 if (remove_selection(curves, bke::AttrDomain(curves_id->selection_domain))) {
1269 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1270 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1271 }
1272 }
1273
1274 return OPERATOR_FINISHED;
1275}
1276
1277} // namespace curves_delete
1278
1280{
1281 ot->name = "Delete";
1282 ot->idname = __func__;
1283 ot->description = "Remove selected control points or curves";
1284
1287
1289}
1290
1292
1294{
1295 for (Curves *curves_id : get_unique_editable_curves(*C)) {
1296 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
1297 IndexMaskMemory memory;
1298 switch (bke::AttrDomain(curves_id->selection_domain)) {
1300 duplicate_points(curves, retrieve_selected_points(*curves_id, memory));
1301 break;
1303 duplicate_curves(curves, retrieve_selected_curves(*curves_id, memory));
1304 break;
1305 default:
1307 break;
1308 }
1309 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1310 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1311 }
1312 return OPERATOR_FINISHED;
1313}
1314
1315} // namespace curves_duplicate
1316
1318{
1319 ot->name = "Duplicate";
1320 ot->idname = __func__;
1321 ot->description = "Copy selected points or curves";
1322
1325
1327}
1328
1329namespace clear_tilt {
1330
1332{
1333 for (Curves *curves_id : get_unique_editable_curves(*C)) {
1334 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
1335 IndexMaskMemory memory;
1336 const IndexMask selection = retrieve_selected_points(*curves_id, memory);
1337 if (selection.is_empty()) {
1338 continue;
1339 }
1340
1341 if (selection.size() == curves.points_num()) {
1342 curves.attributes_for_write().remove("tilt");
1343 }
1344 else {
1345 index_mask::masked_fill(curves.tilt_for_write(), 0.0f, selection);
1346 }
1347
1348 curves.tag_normals_changed();
1349 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1350 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1351 }
1352 return OPERATOR_FINISHED;
1353}
1354
1355} // namespace clear_tilt
1356
1358{
1359 ot->name = "Clear Tilt";
1360 ot->idname = __func__;
1361 ot->description = "Clear the tilt of selected control points";
1362
1363 ot->exec = clear_tilt::exec;
1365
1367}
1368
1369namespace cyclic_toggle {
1370
1372{
1373 for (Curves *curves_id : get_unique_editable_curves(*C)) {
1374 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
1375 IndexMaskMemory memory;
1376 const IndexMask selection = retrieve_selected_curves(*curves_id, memory);
1377 if (selection.is_empty()) {
1378 continue;
1379 }
1380
1381 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
1382
1384 "cyclic", bke::AttrDomain::Curve);
1385 array_utils::invert_booleans(cyclic.span, selection);
1386 cyclic.finish();
1387
1388 if (!cyclic.span.contains(true)) {
1389 attributes.remove("cyclic");
1390 }
1391
1392 curves.calculate_bezier_auto_handles();
1393
1394 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1395 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1396 }
1397 return OPERATOR_FINISHED;
1398}
1399
1400} // namespace cyclic_toggle
1401
1403{
1404 ot->name = "Toggle Cyclic";
1405 ot->idname = __func__;
1406 ot->description = "Make active curve closed/open loop";
1407
1410
1412}
1413
1415
1417{
1418 const CurveType dst_type = CurveType(RNA_enum_get(op->ptr, "type"));
1419 const bool use_handles = RNA_boolean_get(op->ptr, "use_handles");
1420
1421 for (Curves *curves_id : get_unique_editable_curves(*C)) {
1422 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
1423 IndexMaskMemory memory;
1424 const IndexMask selection = retrieve_selected_curves(*curves_id, memory);
1425 if (selection.is_empty()) {
1426 continue;
1427 }
1428
1430 options.convert_bezier_handles_to_poly_points = use_handles;
1431 options.convert_bezier_handles_to_catmull_rom_points = use_handles;
1432 options.keep_bezier_shape_as_nurbs = use_handles;
1433 options.keep_catmull_rom_shape_as_nurbs = use_handles;
1434
1435 curves = blender::geometry::convert_curves(curves, selection, dst_type, {}, options);
1436
1437 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1438 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1439 }
1440 return OPERATOR_FINISHED;
1441}
1442
1443} // namespace curve_type_set
1444
1446{
1447 ot->name = "Set Curve Type";
1448 ot->idname = __func__;
1449 ot->description = "Set type of selected curves";
1450
1453
1455
1456 ot->prop = RNA_def_enum(
1457 ot->srna, "type", rna_enum_curves_type_items, CURVE_TYPE_POLY, "Type", "Curve type");
1458
1460 "use_handles",
1461 false,
1462 "Handles",
1463 "Take handle information into account in the conversion");
1464}
1465
1467
1469{
1470 for (Curves *curves_id : get_unique_editable_curves(*C)) {
1471 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
1472 IndexMaskMemory memory;
1473 const IndexMask selection = retrieve_selected_curves(*curves_id, memory);
1474 if (selection.is_empty()) {
1475 continue;
1476 }
1477
1478 curves.reverse_curves(selection);
1479
1480 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1481 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1482 }
1483 return OPERATOR_FINISHED;
1484}
1485
1486} // namespace switch_direction
1487
1489{
1490 ot->name = "Switch Direction";
1491 ot->idname = __func__;
1492 ot->description = "Reverse the direction of the selected curves";
1493
1496
1498}
1499
1500namespace subdivide {
1501
1503{
1504 const int number_cuts = RNA_int_get(op->ptr, "number_cuts");
1505
1506 for (Curves *curves_id : get_unique_editable_curves(*C)) {
1507 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
1508 const int points_num = curves.points_num();
1509 IndexMaskMemory memory;
1510 const IndexMask points_selection = retrieve_selected_points(*curves_id, memory);
1511 if (points_selection.is_empty()) {
1512 continue;
1513 }
1514
1515 Array<bool> points_selection_span(points_num);
1516 points_selection.to_bools(points_selection_span);
1517
1518 Array<int> segment_cuts(points_num, number_cuts);
1519
1520 const OffsetIndices points_by_curve = curves.points_by_curve();
1521 threading::parallel_for(points_by_curve.index_range(), 512, [&](const IndexRange range) {
1522 for (const int curve_i : range) {
1523 const IndexRange points = points_by_curve[curve_i];
1524 if (points.size() <= 1) {
1525 continue;
1526 }
1527 for (const int point_i : points.drop_back(1)) {
1528 if (!points_selection_span[point_i] || !points_selection_span[point_i + 1]) {
1529 segment_cuts[point_i] = 0;
1530 }
1531 }
1532 /* Cyclic segment. Doesn't matter if it is computed even if the curve is not cyclic. */
1533 if (!points_selection_span[points.last()] || !points_selection_span[points.first()]) {
1534 segment_cuts[points.last()] = 0;
1535 }
1536 }
1537 });
1538
1540 curves, curves.curves_range(), VArray<int>::from_span(segment_cuts), {});
1541
1542 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1543 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1544 }
1545 return OPERATOR_FINISHED;
1546}
1547
1548} // namespace subdivide
1549
1551{
1552 ot->name = "Subdivide";
1553 ot->idname = __func__;
1554 ot->description = "Subdivide selected curve segments";
1555
1556 ot->exec = subdivide::exec;
1558
1560
1561 PropertyRNA *prop;
1562 prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, 1000, "Number of Cuts", "", 1, 10);
1563 /* Avoid re-using last value because it can cause an unexpectedly high number of subdivisions. */
1565}
1566
1569 Curves &curves_id,
1570 CurvesGeometry new_curves,
1571 wmOperator &op)
1572{
1573 const int new_points_num = new_curves.points_num();
1574 const int new_curves_num = new_curves.curves_num();
1575
1576 /* Create geometry sets so that generic join code can be used. */
1580 bke::curves_new_nomain(std::move(new_curves)));
1581
1582 /* Transform primitive according to settings. */
1583 float3 location;
1584 float3 rotation;
1585 float3 scale;
1586 object::add_generic_get_opts(C, &op, 'Z', location, rotation, scale, nullptr, nullptr, nullptr);
1588 location, math::EulerXYZ(rotation), scale);
1590
1592 {old_geometry, new_geometry}, {});
1593 Curves *joined_curves_id = joined_geometry.get_curves_for_write();
1594 CurvesGeometry &dst_curves = curves_id.geometry.wrap();
1595 dst_curves = std::move(joined_curves_id->geometry.wrap());
1596
1597 /* Only select the new curves. */
1598 const bke::AttrDomain selection_domain = bke::AttrDomain(curves_id.selection_domain);
1599 const int new_element_num = selection_domain == bke::AttrDomain::Point ? new_points_num :
1600 new_curves_num;
1602 dst_curves, selection_domain, [&](bke::GSpanAttributeWriter &selection) {
1603 fill_selection_false(selection.span.drop_back(new_element_num));
1604 fill_selection_true(selection.span.take_back(new_element_num));
1605 });
1606
1607 dst_curves.tag_topology_changed();
1608}
1609
1610namespace add_circle {
1611
1613{
1614 CurvesGeometry curves{4, 1};
1615
1616 MutableSpan<int> offsets = curves.offsets_for_write();
1617 offsets[0] = 0;
1618 offsets[1] = 4;
1619
1620 curves.fill_curve_types(CURVE_TYPE_BEZIER);
1621 curves.cyclic_for_write().fill(true);
1622 curves.handle_types_left_for_write().fill(BEZIER_HANDLE_AUTO);
1623 curves.handle_types_right_for_write().fill(BEZIER_HANDLE_AUTO);
1624 curves.resolution_for_write().fill(12);
1625
1626 MutableSpan<float3> positions = curves.positions_for_write();
1627 positions[0] = float3(-radius, 0, 0);
1628 positions[1] = float3(0, radius, 0);
1629 positions[2] = float3(radius, 0, 0);
1630 positions[3] = float3(0, -radius, 0);
1631
1632 /* Ensure these attributes exist. */
1633 curves.handle_positions_left_for_write();
1634 curves.handle_positions_right_for_write();
1635
1636 curves.calculate_bezier_auto_handles();
1637
1638 return curves;
1639}
1640
1642{
1643 Object *object = CTX_data_edit_object(C);
1644 Curves *active_curves_id = id_cast<Curves *>(object->data);
1645
1646 const float radius = RNA_float_get(op->ptr, "radius");
1647 append_primitive_curve(C, *active_curves_id, generate_circle_primitive(radius), *op);
1648
1649 DEG_id_tag_update(&active_curves_id->id, ID_RECALC_GEOMETRY);
1650 WM_event_add_notifier(C, NC_GEOM | ND_DATA, active_curves_id);
1651 return OPERATOR_FINISHED;
1652}
1653
1654} // namespace add_circle
1655
1657{
1658 ot->name = "Add Circle";
1659 ot->idname = __func__;
1660 ot->description = "Add new circle curve";
1661
1662 ot->exec = add_circle::exec;
1664
1666
1668 object::add_generic_props(ot, true);
1669}
1670
1671namespace add_bezier {
1672
1674{
1675 CurvesGeometry curves{2, 1};
1676
1677 MutableSpan<int> offsets = curves.offsets_for_write();
1678 offsets[0] = 0;
1679 offsets[1] = 2;
1680
1681 curves.fill_curve_types(CURVE_TYPE_BEZIER);
1682 curves.handle_types_left_for_write().fill(BEZIER_HANDLE_ALIGN);
1683 curves.handle_types_right_for_write().fill(BEZIER_HANDLE_ALIGN);
1684 curves.resolution_for_write().fill(12);
1685
1686 MutableSpan<float3> positions = curves.positions_for_write();
1687 MutableSpan<float3> left_handles = curves.handle_positions_left_for_write();
1688 MutableSpan<float3> right_handles = curves.handle_positions_right_for_write();
1689
1690 left_handles[0] = float3(-1.5f, -0.5, 0) * radius;
1691 positions[0] = float3(-1.0f, 0, 0) * radius;
1692 right_handles[0] = float3(-0.5f, 0.5f, 0) * radius;
1693
1694 left_handles[1] = float3(0, 0, 0) * radius;
1695 positions[1] = float3(1.0f, 0, 0) * radius;
1696 right_handles[1] = float3(2.0f, 0, 0) * radius;
1697
1698 return curves;
1699}
1700
1702{
1703 Object *object = CTX_data_edit_object(C);
1704 Curves *active_curves_id = id_cast<Curves *>(object->data);
1705
1706 const float radius = RNA_float_get(op->ptr, "radius");
1707 append_primitive_curve(C, *active_curves_id, generate_bezier_primitive(radius), *op);
1708
1709 DEG_id_tag_update(&active_curves_id->id, ID_RECALC_GEOMETRY);
1710 WM_event_add_notifier(C, NC_GEOM | ND_DATA, active_curves_id);
1711 return OPERATOR_FINISHED;
1712}
1713
1714} // namespace add_bezier
1715
1717{
1718 ot->name = "Add Bézier";
1719 ot->idname = __func__;
1720 ot->description = "Add new Bézier curve";
1721
1722 ot->exec = add_bezier::exec;
1724
1726
1728 object::add_generic_props(ot, true);
1729}
1730
1732
1734{
1735 const SetHandleType dst_type = SetHandleType(RNA_enum_get(op->ptr, "type"));
1736
1737 auto new_handle_type = [&](const int8_t handle_type) {
1738 switch (dst_type) {
1740 return int8_t(BEZIER_HANDLE_FREE);
1742 return int8_t(BEZIER_HANDLE_AUTO);
1748 return int8_t(handle_type == BEZIER_HANDLE_FREE ? BEZIER_HANDLE_ALIGN :
1750 }
1752 return int8_t(0);
1753 };
1754
1755 for (Curves *curves_id : get_unique_editable_curves(*C)) {
1756 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
1757 const bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
1758
1759 const VArraySpan<bool> selection = *attributes.lookup_or_default<bool>(
1760 ".selection", bke::AttrDomain::Point, true);
1761 const VArraySpan<bool> selection_left = *attributes.lookup_or_default<bool>(
1762 ".selection_handle_left", bke::AttrDomain::Point, true);
1763 const VArraySpan<bool> selection_right = *attributes.lookup_or_default<bool>(
1764 ".selection_handle_right", bke::AttrDomain::Point, true);
1765
1766 MutableSpan<int8_t> handle_types_left = curves.handle_types_left_for_write();
1767 MutableSpan<int8_t> handle_types_right = curves.handle_types_right_for_write();
1768
1769 threading::parallel_for(curves.points_range(), 4096, [&](const IndexRange range) {
1770 for (const int point_i : range) {
1771 if (selection_left[point_i] || selection[point_i]) {
1772 handle_types_left[point_i] = new_handle_type(handle_types_left[point_i]);
1773 }
1774 if (selection_right[point_i] || selection[point_i]) {
1775 handle_types_right[point_i] = new_handle_type(handle_types_right[point_i]);
1776 }
1777 }
1778 });
1779
1780 curves.calculate_bezier_auto_handles();
1781 curves.calculate_bezier_aligned_handles();
1782 curves.tag_topology_changed();
1783
1784 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
1785 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
1786 }
1787 return OPERATOR_FINISHED;
1788}
1789
1790} // namespace set_handle_type
1791
1793 {int(SetHandleType::Auto),
1794 "AUTO",
1795 ICON_HANDLE_AUTO,
1796 "Auto",
1797 "The location is automatically calculated to be smooth"},
1799 "VECTOR",
1800 ICON_HANDLE_VECTOR,
1801 "Vector",
1802 "The location is calculated to point to the next/previous control point"},
1804 "ALIGN",
1805 ICON_HANDLE_ALIGNED,
1806 "Align",
1807 "The location is constrained to point in the opposite direction as the other handle"},
1808 {int(SetHandleType::Free),
1809 "FREE_ALIGN",
1810 ICON_HANDLE_FREE,
1811 "Free",
1812 "The handle can be moved anywhere, and does not influence the point's other handle"},
1814 "TOGGLE_FREE_ALIGN",
1815 0,
1816 "Toggle Free/Align",
1817 "Replace Free handles with Align, and all Align with Free handles"},
1818 {0, nullptr, 0, nullptr, nullptr},
1819};
1820
1822{
1823 ot->name = "Set Handle Type";
1824 ot->idname = __func__;
1825 ot->description = "Set the handle type for Bézier curves";
1826
1827 ot->invoke = WM_menu_invoke;
1830
1832
1833 ot->prop = RNA_def_enum(ot->srna,
1834 "type",
1837 "Type",
1838 nullptr);
1839}
1840
1842{
1870
1872}
1873
1875{
1876 wmOperatorType *ot;
1877 wmOperatorTypeMacro *otmacro;
1878
1879 ot = WM_operatortype_append_macro("CURVES_OT_duplicate_move",
1880 "Duplicate",
1881 "Make copies of selected elements and move them",
1883 WM_operatortype_macro_define(ot, "CURVES_OT_duplicate");
1884 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
1885 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
1886 RNA_boolean_set(otmacro->ptr, "mirror", false);
1887
1888 ot = WM_operatortype_append_macro("CURVES_OT_extrude_move",
1889 "Extrude Curve and Move",
1890 "Extrude curve and move result",
1892 WM_operatortype_macro_define(ot, "CURVES_OT_extrude");
1893 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
1894 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
1895 RNA_boolean_set(otmacro->ptr, "mirror", false);
1896}
1897
1899{
1900 /* Only set in editmode curves, by space_view3d listener. */
1901 wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Curves", SPACE_EMPTY, RGN_TYPE_WINDOW);
1903
1905}
1906
1907} // namespace blender::ed::curves
Generic geometry attributes built on CustomData.
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
General operations, lookup, etc. for blender objects.
#define DMCACHE_NOTFOUND
#define INT32_MAX
#define INT32_MIN
#define IFACE_(msgid)
Object is a sort of wrapper for general info.
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define NC_WINDOW
Definition WM_types.hh:388
#define NC_NODE
Definition WM_types.hh:407
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DRAW
Definition WM_types.hh:502
#define ND_DATA
Definition WM_types.hh:552
#define NA_ADDED
Definition WM_types.hh:636
#define NA_EDITED
Definition WM_types.hh:634
#define ND_PARTICLE
Definition WM_types.hh:506
#define ND_SPACE_VIEW3D
Definition WM_types.hh:571
#define NC_OBJECT
Definition WM_types.hh:392
#define NC_SPACE
Definition WM_types.hh:405
#define BLI_assert_unreachable()
#define ELEM(...)
#define STREQ(a, b)
static AttributeOwner from_id(ID *id)
bool is() const
GMutableSpan take_back(const int64_t n) const
GMutableSpan drop_back(const int64_t n) const
const CPPType & type() const
MutableSpan< T > typed() const
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
constexpr int64_t first() const
constexpr int64_t size() const
constexpr int64_t size() const
Definition BLI_span.hh:499
constexpr T * data() const
Definition BLI_span.hh:545
constexpr IndexRange index_range() const
Definition BLI_span.hh:676
constexpr const T & first() const
Definition BLI_span.hh:319
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const T * end() const
Definition BLI_span.hh:228
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr const T * begin() const
Definition BLI_span.hh:224
constexpr bool is_empty() const
Definition BLI_span.hh:264
static VArray from_span(Span< T > values)
bool add(const Key &key)
void add_new(const Key &key)
int64_t size() const
void append(const T &value)
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
GAttributeReader lookup(const StringRef name) const
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
std::optional< ClosestPointResult > closest_point(const float3 &point, float radius=std::numeric_limits< float >::max()) const
Definition bvh.cc:709
constexpr bool is_empty() const
constexpr bool is_empty() const
constexpr int64_t size() const
constexpr const char * data() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask complement(const IndexMask &universe, LinearAllocator<> &memory) const
void to_bools(MutableSpan< bool > r_bools) const
CCL_NAMESPACE_BEGIN struct Options options
#define FLT_MAX
#define position
float3x3 scale(float3x3 mat, float2 scale)
void invert_booleans(MutableSpan< bool > span)
AttrType cpp_type_to_attribute_type(const CPPType &type)
Curves * curves_new_nomain(int points_num, int curves_num)
static wmOperatorStatus exec(bContext *C, wmOperator *op)
static CurvesGeometry generate_bezier_primitive(const float radius)
static CurvesGeometry generate_circle_primitive(const float radius)
static wmOperatorStatus exec(bContext *C, wmOperator *op)
static wmOperatorStatus exec(bContext *C, wmOperator *)
static wmOperatorStatus curves_convert_from_particle_system_exec(bContext *C, wmOperator *)
static bke::CurvesGeometry particles_to_curves(Object &object, ParticleSystem &psys)
static bool curves_convert_from_particle_system_poll(bContext *C)
static float4 compute_mface_weights_for_position(const Span< float3 > positions, const MFace &mface, const float3 &position)
static int find_mface_for_root_position(const Span< float3 > positions, const MFace *mface, const Span< int > possible_mface_indices, const float3 &root_pos)
static wmOperatorStatus curves_convert_to_particle_system_exec(bContext *C, wmOperator *op)
static void try_convert_single_object(Object &curves_ob, Main &bmain, Scene &scene, bool *r_could_not_convert_some_curves)
static wmOperatorStatus exec(bContext *C, wmOperator *op)
static wmOperatorStatus delete_exec(bContext *C, wmOperator *)
static wmOperatorStatus duplicate_exec(bContext *C, wmOperator *)
static wmOperatorStatus exec(bContext *C, wmOperator *)
static wmOperatorStatus exec(bContext *C, wmOperator *op)
static wmOperatorStatus curves_set_selection_domain_exec(bContext *C, wmOperator *op)
static wmOperatorStatus snap_curves_to_surface_exec(bContext *C, wmOperator *op)
static void snap_curves_to_surface_exec_object(Object &curves_ob, const Object &surface_ob, const AttachMode attach_mode, bool *r_invalid_uvs, bool *r_missing_uvs)
static wmOperatorStatus split_exec(bContext *C, wmOperator *)
static wmOperatorStatus exec(bContext *C, wmOperator *op)
static wmOperatorStatus surface_set_exec(bContext *C, wmOperator *op)
static bool surface_set_poll(bContext *C)
static wmOperatorStatus exec(bContext *C, wmOperator *)
static void CURVES_OT_surface_set(wmOperatorType *ot)
const EnumPropertyItem rna_enum_set_handle_type_items[]
static wmOperatorStatus select_linked_exec(bContext *C, wmOperator *)
bool remove_selection(bke::CurvesGeometry &curves, const bke::AttrDomain selection_domain)
static void CURVES_OT_convert_from_particle_system(wmOperatorType *ot)
void keymap_curves(wmKeyConfig *keyconf)
void CURVES_OT_draw(wmOperatorType *ot)
static bool has_anything_selected(const Span< Curves * > curves_ids)
static void CURVES_OT_select_less(wmOperatorType *ot)
static void CURVES_OT_convert_to_particle_system(wmOperatorType *ot)
static void CURVES_OT_select_random(wmOperatorType *ot)
static eHandleDisplay view3d_handle_type_or_default(const View3D *v3d)
Definition curves_ops.cc:82
static void CURVES_OT_select_ends(wmOperatorType *ot)
void select_linked(bke::CurvesGeometry &curves, const IndexMask &curves_mask, const bool unselect)
void select_all(bke::CurvesGeometry &curves, const IndexMask &mask, const bke::AttrDomain selection_domain, int action)
static bool editable_curves_point_domain_poll(bContext *C)
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
void duplicate_curves(bke::CurvesGeometry &curves, const IndexMask &mask)
static void CURVES_OT_add_bezier(wmOperatorType *ot)
void duplicate_points(bke::CurvesGeometry &curves, const IndexMask &mask)
static void CURVES_OT_select_linked(wmOperatorType *ot)
VectorSet< Curves * > get_unique_editable_curves(const bContext &C)
void foreach_selection_attribute_writer(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, FunctionRef< void(bke::GSpanAttributeWriter &selection)> fn)
bool editable_curves_poll(bContext *C)
void select_adjacent(bke::CurvesGeometry &curves, const IndexMask &curves_mask, const bool deselect)
static void CURVES_OT_handle_type_set(wmOperatorType *ot)
static void CURVES_OT_subdivide(wmOperatorType *ot)
static void CURVES_OT_select_more(wmOperatorType *ot)
static void CURVES_OT_select_all(wmOperatorType *ot)
static void CURVES_OT_switch_direction(wmOperatorType *ot)
bke::CurvesGeometry split_points(const bke::CurvesGeometry &curves, const IndexMask &points_to_split)
void fill_selection_false(GMutableSpan selection)
bool object_has_editable_curves(const Main &bmain, const Object &object)
Definition curves_ops.cc:87
static void select_random_ui(bContext *, wmOperator *op)
void ED_curves_pentool_modal_keymap(wmKeyConfig *keyconf)
bool editable_curves_in_edit_mode_poll(bContext *C)
static void CURVES_OT_split(wmOperatorType *ot)
IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
static void CURVES_OT_tilt_clear(wmOperatorType *ot)
static void CURVES_OT_duplicate(wmOperatorType *ot)
static wmOperatorStatus select_all_exec(bContext *C, wmOperator *op)
static wmOperatorStatus select_more_exec(bContext *C, wmOperator *)
void fill_selection_true(GMutableSpan selection)
static bool curves_poll_impl(bContext *C, const bool check_editable, const bool check_surface, const bool check_edit_mode)
Span< StringRef > get_curves_selection_attribute_names(const bke::CurvesGeometry &curves)
static void CURVES_OT_curve_type_set(wmOperatorType *ot)
static wmOperatorStatus select_random_exec(bContext *C, wmOperator *op)
static void CURVES_OT_cyclic_toggle(wmOperatorType *ot)
void ED_operatortypes_curves_pen()
static wmOperatorStatus select_ends_exec(bContext *C, wmOperator *op)
static void CURVES_OT_delete(wmOperatorType *ot)
static void CURVES_OT_snap_curves_to_surface(wmOperatorType *ot)
static wmOperatorStatus select_less_exec(bContext *C, wmOperator *)
void ensure_surface_deformation_node_exists(bContext &C, Object &curves_ob)
Definition curves_add.cc:64
static void append_primitive_curve(bContext *C, Curves &curves_id, CurvesGeometry new_curves, wmOperator &op)
IndexMask end_points(const bke::CurvesGeometry &curves, const IndexMask &curves_mask, const int amount_start, const int amount_end, const bool inverted, IndexMaskMemory &memory)
bool curves_with_surface_poll(bContext *C)
static void select_ends_ui(bContext *, wmOperator *op)
void CURVES_OT_separate(wmOperatorType *ot)
void CURVES_OT_attribute_set(wmOperatorType *ot)
IndexMask retrieve_all_selected_points(const bke::CurvesGeometry &curves, const int handle_display, LinearAllocator<> &memory)
bool curves_poll(bContext *C)
bke::GSpanAttributeWriter ensure_selection_attribute(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, bke::AttrType create_type, StringRef attribute_name)
void CURVES_OT_extrude(wmOperatorType *ot)
void CURVES_OT_select_linked_pick(wmOperatorType *ot)
static void CURVES_OT_set_selection_domain(wmOperatorType *ot)
static void CURVES_OT_add_circle(wmOperatorType *ot)
bool editable_curves_with_surface_poll(bContext *C)
void add_unit_props_radius(wmOperatorType *ot)
bool parent_set(ReportList *reports, const bContext *C, Scene *scene, Object *const ob, Object *const par, int partype, bool xmirror, bool keep_transform, const int vert_par[3])
Object * context_active_object(const bContext *C)
void add_generic_props(wmOperatorType *ot, bool do_editmode)
void add_generic_get_opts(bContext *C, wmOperator *op, char view_align_axis, float r_loc[3], float r_rot[3], float r_scale[3], bool *r_enter_editmode, unsigned short *r_local_view_bits, bool *r_is_view_aligned)
bke::GeometrySet join_geometries(Span< bke::GeometrySet > geometries, const bke::AttributeFilter &attribute_filter, const std::optional< Span< bke::GeometryComponent::Type > > &component_types_to_join=std::nullopt, bool allow_merging_instance_references=true)
std::optional< TransformGeometryErrors > transform_geometry(bke::GeometrySet &geometry, const float4x4 &transform)
bke::CurvesGeometry subdivide_curves(const bke::CurvesGeometry &src_curves, const IndexMask &selection, const VArray< int > &cuts, const bke::AttributeFilter &attribute_filter={})
bke::CurvesGeometry convert_curves(const bke::CurvesGeometry &src_curves, const IndexMask &selection, CurveType dst_type, const bke::AttributeFilter &attribute_filter, const ConvertCurvesOptions &options={})
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
EulerXYZBase< float > EulerXYZ
CartesianBasis invert(const CartesianBasis &basis)
MatT from_loc_rot_scale(const typename MatT::loc_type &location, const RotationT &rotation, const VecBase< typename MatT::base_type, ScaleDim > &scale)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
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
void WM_main_add_notifier(uint type, void *reference)
std::optional< StringRefNull > BKE_attributes_active_name_get(AttributeOwner &owner)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
const EnumPropertyItem rna_enum_attribute_curves_domain_items[]
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
Object * BKE_object_add(Main *bmain, Scene *scene, ViewLayer *view_layer, ObjectType type, const char *name) ATTR_NONNULL(1
Definition object.cc:2296
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
@ CURVE_HANDLE_SELECTED
struct ModifierData * object_add_particle_system(struct Main *bmain, const struct Scene *scene, struct Object *ob, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
MINLINE void copy_v3_v3(float r[3], const float a[3])
struct ParticleSystem * psys_get_current(struct Object *ob)
Definition particle.cc:571
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
const EnumPropertyItem rna_enum_curves_type_items[]
Definition rna_curves.cc:26
@ eModifierType_ParticleSystem
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
wmOperatorTypeMacro * WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
int RNA_int_get(PointerRNA *ptr, const char *name)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BKE_attributes_active_set(AttributeOwner &owner, StringRef name)
MatBase< float, 4, 4 > float4x4
void psys_free_particles(struct ParticleSystem *psys)
Definition particle.cc:963
@ OB_MODIFIER_FLAG_ADD_REST_POSITION
ViewLayer * CTX_data_view_layer(const bContext *C)
void WM_operator_properties_select_all(wmOperatorType *ot)
void BKE_object_apply_mat4(Object *ob, const float mat[4][4], bool use_compat, bool use_parent)
Definition object.cc:3663
VecBase< float, 4 > float4
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
VecBase< float, 2 > float2
void BKE_mesh_tessface_calc(Mesh *mesh)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
@ OB_MODE_SCULPT_CURVES
BMesh const char void * data
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
Object * CTX_data_edit_object(const bContext *C)
void interp_weights_tri_v3(float w[3], const float v1[3], const float v2[3], const float v3[3], const float co[3])
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
void psys_mat_hair_to_object(struct Object *ob, struct Mesh *mesh, short from, struct ParticleData *pa, float hairmat[4][4])
Definition particle.cc:3888
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
void interp_weights_poly_v3(float w[], float v[][3], int n, const float co[3])
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
wmOperatorType * WM_operatortype_append_macro(const char *idname, const char *name, const char *description, int flag)
Main * CTX_data_main(const bContext *C)
void closest_on_tri_to_point_v3(float r[3], const float p[3], const float v1[3], const float v2[3], const float v3[3])
@ ID_RECALC_PSYS_RESET
Definition DNA_ID.h:1083
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
void DEG_relations_tag_update(Main *bmain)
Scene * CTX_data_scene(const bContext *C)
MINLINE void copy_v4_v4(float r[4], const float a[4])
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
VecBase< float, 3 > float3
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void psys_changed_type(struct Object *ob, struct ParticleSystem *psys)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
Object * CTX_data_active_object(const bContext *C)
bool ED_operator_object_active_editable_ex(bContext *C, const Object *ob)
float RNA_float_get(PointerRNA *ptr, const char *name)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
View3D * CTX_wm_view3d(const bContext *C)
signed char int8_t
Definition BKE_text.h:76
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
char name[258]
Definition DNA_ID.h:433
const c_style_mat & ptr() const
CustomData fdata_legacy
ListBaseT< ModifierData > modifiers
ObjectModifierFlag modifier_flag
ListBaseT< struct ParticleSystem > particlesystem
struct ParticleCacheKey ** childcache
struct ParticleCacheKey ** pathcache
eParticleSystem_Flag flag
eHandleDisplay handle_display
View3DOverlay overlay
static GeometrySet from_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
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)
Layout & column(bool align)
bool(*) poll(struct bContext *)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) ui(bContext *C, wmOperator *op)
Definition WM_types.hh:1176
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports