86#include "RNA_prototypes.hh"
117 grease_pencil->root_group_ptr = MEM_new<greasepencil::LayerGroup>(__func__);
123 grease_pencil->runtime = MEM_new<GreasePencilRuntime>(__func__);
138 "RNA struct GreasePencilLayer is expected to have a 'hide' property.");
141 "RNA struct GreasePencilLayerGroup is expected to have a 'hide' property.");
145 &id_dst, RNA_GreasePencilLayerGroup, layer_group);
150 "It should be possible to construct the RNA path of a grease pencil layer group.");
158 if (parent.runtime->is_visibility_animated_) {
163 return parent_group_visibility_animated(*parent_group);
169 if (parent_group_visibility_animated(
layer->parent_group())) {
170 layer->runtime->is_visibility_animated_ =
true;
177 "It should be possible to construct the RNA path of a grease pencil layer.");
193 int empty_drawing_users = 0;
194 const int empty_drawing_index =
grease_pencil.drawings().size();
197 if (frame.is_end()) {
198 empty_drawing_users++;
199 frame.drawing_index = empty_drawing_index;
201 layer->tag_frames_map_keys_changed();
205 if (empty_drawing_users > 0) {
210 "Converted %d end frames to regular frames using an empty drawing in \"%s\"",
227 if (!
grease_pencil.drawings().index_range().contains(value.drawing_index)) {
234 for (
const int drawing_i :
grease_pencil.drawings().index_range()) {
245 std::optional<Library *> ,
254 grease_pencil_dst->material_array =
static_cast<Material **
>(
255 MEM_dupalloc(grease_pencil_src->material_array));
260 grease_pencil_dst->root_group_ptr = MEM_new<bke::greasepencil::LayerGroup>(
261 __func__, grease_pencil_src->root_group());
264 if (grease_pencil_src->get_active_node()) {
266 grease_pencil_src->get_active_node()->name());
268 grease_pencil_dst->set_active_node(active_node);
271 new (&grease_pencil_dst->attribute_storage.wrap())
275 &grease_pencil_src->vertex_group_names);
278 grease_pencil_dst->runtime = MEM_new<bke::GreasePencilRuntime>(__func__);
280 if (grease_pencil_src->runtime->bake_materials) {
281 grease_pencil_dst->runtime->bake_materials = std::make_unique<bke::bake::BakeMaterialsList>(
282 *grease_pencil_src->runtime->bake_materials);
314 for (
int i = 0; i <
grease_pencil->material_array_num; i++) {
343 grease_pencil->attribute_storage.wrap().foreach_working_space_color(
fn);
358 [&](
const AttrDomain ) { return grease_pencil->layers().size(); },
373 grease_pencil->attribute_storage.wrap().blend_write(*writer, attribute_data);
406 grease_pencil->runtime = MEM_new<bke::GreasePencilRuntime>(__func__);
424 .id_code = GreasePencil::id_type,
429 .name =
"GreasePencil",
430 .name_plural =
N_(
"grease_pencils"),
433 .asset_type_info =
nullptr,
438 .make_local =
nullptr,
440 .foreach_cache =
nullptr,
441 .foreach_path =
nullptr,
443 .foreach_asset_weak_reference =
nullptr,
444 .owner_pointer_get =
nullptr,
448 .blend_read_after_liblink =
nullptr,
450 .blend_read_undo_preserve =
nullptr,
452 .lib_override_apply_post =
nullptr,
468 this->
runtime = MEM_new<bke::greasepencil::DrawingRuntime>(__func__);
478 this->
runtime = MEM_new<bke::greasepencil::DrawingRuntime>(__func__);
496 other.runtime =
nullptr;
501 if (
this == &other) {
504 std::destroy_at(
this);
511 if (
this == &other) {
514 std::destroy_at(
this);
515 new (
this)
Drawing(std::move(other));
557 struct LocalMemArena {
563 if (pf_arena !=
nullptr) {
578 const int fill_index = mask_segment[
index];
579 const int pos = segment_pos +
index;
586 base_fill, memory, [&](
const int64_t curve_i) {
587 const IndexRange points = points_by_curve[curve_i];
588 return points.
size() >= 3;
591 if (fill.is_empty()) {
599 float (*projverts)[2] =
static_cast<float (*)[2]
>(
603 pf_arena,
sizeof(*fill_points_by_curve_data) *
size_t(fill.size() + 1)));
608 MutableSpan(fill_points_by_curve_data, fill.size() + 1));
612 const IndexRange fill_points = fill_points_by_curve[pos];
613 const IndexRange points = points_by_curve[curve_i];
615 const int curve_p = points[i];
616 const int fill_p = fill_points[i];
617 mul_v2_m3v3(projverts[fill_p], axis_mat.
ptr(), positions[curve_p]);
623 if (fill.size() == 1) {
624 triangle_results[pos].resize(num_points - 2);
639 for (
const int i : range) {
640 verts[i] =
double2(projverts[i]);
649 for (const int i : range) {
650 const IndexRange fill_points = fill_points_by_curve[i];
651 MutableSpan<int> face = face_vert_indices.as_mutable_span().slice(fill_points);
653 array_utils::fill_index_range<int>(face, fill_points.first());
654 const Span<float2> projpoints = projverts_span.slice(fill_points);
657 if (cross_poly_v2(reinterpret_cast<const float (*)[2]>(projpoints.data()),
658 projpoints.size()) < 0.0)
676 const float3 depth_point = positions[points_by_curve[fill.first()].first()];
679 const float3 depth_direction = depth_point - invert_axis_mat *
float3(pos2d, 0.0f);
681 for (
const int vert :
result.vert.index_range()) {
683 if (!
result.vert_orig[vert].is_empty()) {
687 vert_id_to_intersection_point.
add_new(vert, intersection_point_results[pos].size());
690 intersection_point_results[pos].append(invert_axis_mat *
float3(co.x, co.y, 0.0f) +
694 auto vert_to_point = [&](
const int vert) {
696 if (
result.vert_orig[vert].is_empty()) {
697 const int inter = vert_id_to_intersection_point.
lookup(vert);
701 return int(
result.vert_orig[vert].first());
704 for (
const int i :
result.face.index_range()) {
707 vert_to_point(
result.face[i][1]),
708 vert_to_point(
result.face[i][2]));
710 triangle_results[pos].append(tri);
720 for (const int i : range) {
721 r_triangle_offsets[i] = triangle_results[i].size();
725 intersection_point_results.index_range(), 512, [&](
const IndexRange range) {
726 for (const int i : range) {
727 r_intersection_point_offsets[i] = intersection_point_results[i].size();
736 r_triangles.resize(triangle_offsets.
total_size());
737 r_intersection_points.resize(intersection_point_offsets.
total_size());
741 for (const int pos : range) {
742 const IndexRange fill_range = triangle_offsets[pos];
743 array_utils::copy(triangle_results[pos].as_span(), r_triangles_span.slice(fill_range));
749 for (const int pos : range) {
750 const IndexRange fill_range = intersection_point_offsets[pos];
751 array_utils::copy(intersection_point_results[pos].as_span(),
752 r_intersection_points_span.slice(fill_range));
767 curves.evaluated_positions(),
769 curves.evaluated_points_by_curve(),
770 fills->index_range(),
777 r_triangle_cache = std::move(triangle_cache);
780 r_triangle_cache = std::nullopt;
813 [&](
const int curve_i) {
814 const IndexRange points = points_by_curve[curve_i];
815 if (points.
size() < 2) {
816 normals[curve_i] =
float3(1.0f, 0.0f, 0.0f);
822 const float3 first_point = positions[points.
first()];
824 float max_extent_sq = 0.0f;
825 for (
const int point_i : points) {
826 const float3 curr_point = positions[point_i];
829 prev_point = curr_point;
838 std::numeric_limits<float>::epsilon() *
math::max(points.
size() * max_extent_sq, 1.0f))
840 for (
const int point_i : points.
drop_back(1)) {
841 float3 segment_vec = positions[point_i] - positions[point_i + 1];
849 normals[curve_i] = normal;
875 if (positions.
size() <= 2) {
879 const float3 point_0 = positions[0];
880 const float3 point_1 = positions[1];
903 const float2 uv_translation,
909 const float s =
sin(uv_rotation);
910 const float c =
cos(uv_rotation);
930 texture_matrix =
rot * texture_matrix;
933 texture_matrix[2] += uv_translation;
935 return texture_matrix;
952 strokemat4x3[2][2] = 0.0f;
953 strokemat4x3[3][2] = 1.0f;
977 for (const int curve_i : range) {
978 const IndexRange points = points_by_curve[curve_i];
979 const float3 normal = normals[curve_i];
980 const float4x2 strokemat = get_local_to_stroke_matrix(positions.slice(points), normal);
981 const float3x2 texture_matrix = get_stroke_to_texture_matrix(
982 uv_rotations[curve_i], uv_translations[curve_i], uv_scales[curve_i]);
984 const float4x2 texspace = texture_matrix * expand_4x2_mat(strokemat);
986 r_data[curve_i] = texspace;
990 return this->runtime->curve_texture_matrices.data().as_span();
1004 if (!uv_rotations || !uv_translations || !uv_scales) {
1015 const IndexRange points = points_by_curve[curve_i];
1016 const float3 normal = normals[curve_i];
1018 const float4x2 texspace = matrices[pos];
1042 const double3x4 right_inverse = transpose_strokemat *
1048 const float2 uv_translation = texture_matrix[2];
1051 const float uv_rotation =
math::atan2(texture_matrix[0][1], texture_matrix[0][0]);
1061 uv_rotations.
span[curve_i] = uv_rotation;
1062 uv_translations.span[curve_i] = uv_translation;
1063 uv_scales.span[curve_i] = uv_scale;
1067 uv_translations.finish();
1094 this->strokes().points_num(),
1109 this->strokes().points_num(),
1125 this->strokes().points_num(),
1141 this->strokes().curves_num(),
1171 const int num_curves,
1179 curve_mask.
to_bools(selected_curves);
1182 const Span<int> fill = (*fills)[fill_index];
1184 fill.begin(), fill.end(), [&](const int curve_i) { return selected_curves[curve_i]; });
1200 const int num_fills = fills.has_value() ? fills->size() : 0;
1204 changed_curves, fills, dst_points_by_curve.
size(), memory);
1207 Array<int> changed_triangle_offsets_data(changed_fills.
size() + 1);
1209 Array<int> changed_intersection_point_offsets_data(changed_fills.
size() + 1);
1215 dst_points_by_curve,
1220 changed_intersection_points,
1227 changed_triangle_offsets_data);
1229 changed_intersection_point_offsets_data);
1231 Array<int> all_src_triangle_sizes(num_fills);
1233 Array<int> all_src_intersection_point_sizes(num_fills);
1234 Array<int> changed_intersection_point_sizes(changed_fills.
size());
1235 copy_group_sizes(src_triangles.
offsets, src_triangles.
index_range(), all_src_triangle_sizes);
1237 changed_triangle_offsets, changed_triangle_offsets.
index_range(), changed_triangle_sizes);
1238 copy_group_sizes(src_intersection_points.
offsets,
1240 all_src_intersection_point_sizes);
1241 copy_group_sizes(changed_intersection_point_offsets,
1243 changed_intersection_point_sizes);
1256 src_intersection_point_sizes.
as_span(), unchanged_fills, r_intersection_point_offsets);
1258 changed_intersection_point_sizes.
as_span(), changed_fills, r_intersection_point_offsets);
1261 r_triangle_offsets);
1265 r_triangles.
resize(r_triangle_offsets.
last());
1266 r_intersection_points.
resize(r_intersection_point_offsets.
last());
1273 intersection_point_offsets,
1275 src_intersection_points.
data,
1279 [&](
const int i,
const int pos) {
1281 .slice(triangle_offsets[i])
1282 .copy_from(changed_triangles.
as_span().slice(changed_triangle_offsets[pos]));
1286 [&](
const int i,
const int pos) {
1288 .slice(intersection_point_offsets[i])
1289 .copy_from(changed_intersection_points.
as_span().slice(
1290 changed_intersection_point_offsets[pos]));
1305 if (changed_curves.
size() > this->strokes().curves_num() / 2) {
1310 !this->runtime->curve_plane_normals_cache.is_cached())
1321 curves.positions(),
curves.points_by_curve(), changed_curves, normals);
1332 const Array<int> src_triangle_offsets(src_triangle_cache->triangle_offsets.as_span());
1333 const Array<int3> src_triangles_data(src_triangle_cache->triangles.as_span());
1335 src_triangles_data.
as_span());
1336 const Array<int> src_intersection_point_offsets(
1337 src_triangle_cache->intersection_point_offsets.as_span());
1339 src_triangle_cache->intersection_points.as_span());
1341 src_intersection_points_data.
as_span());
1344 const std::optional<GroupedSpan<int>>
fills = this->fills();
1353 this->
strokes().evaluated_points_by_curve(),
1357 src_intersection_points,
1362 r_triangle_cache = std::move(triangle_cache);
1387 if (changed_curves.
size() > this->strokes().curves_num() / 2) {
1392 !this->runtime->curve_plane_normals_cache.is_cached())
1403 curves.positions(),
curves.points_by_curve(), changed_curves, normals);
1412 const Array<int> src_triangle_offsets(src_triangle_cache->triangle_offsets.as_span());
1413 const Array<int3> src_triangles_data(src_triangle_cache->triangles.as_span());
1415 src_triangles_data.
as_span());
1416 const Array<int> src_intersection_point_offsets(
1417 src_triangle_cache->intersection_point_offsets.as_span());
1419 src_triangle_cache->intersection_points.as_span());
1421 src_intersection_points_data.
as_span());
1424 const std::optional<GroupedSpan<int>>
fills = this->fills();
1433 this->
strokes().evaluated_points_by_curve(),
1437 src_intersection_points,
1442 r_triangle_cache = std::move(triangle_cache);
1476 switch (src_drawing_base->
type) {
1481 MEM_new<bke::greasepencil::Drawing>(__func__, src_drawing->wrap()));
1488 MEM_new<bke::greasepencil::DrawingReference>(__func__, src_drawing_reference->wrap()));
1528void TreeNode::set_name(
const StringRef name)
1536 return *
reinterpret_cast<const LayerGroup *
>(
this);
1541 return *
reinterpret_cast<const Layer *
>(
this);
1546 return *
reinterpret_cast<LayerGroup *
>(
this);
1551 return *
reinterpret_cast<Layer *
>(
this);
1556 return (this->
parent) ? &this->
parent->wrap() :
nullptr;
1560 return (this->
parent) ? &this->
parent->wrap() :
nullptr;
1609 masks_.clear_and_shrink();
1635 this->
masks.clear_no_delete();
1638 this->
runtime = MEM_new<LayerRuntime>(__func__);
1651 LayerMask *new_mask = MEM_new<LayerMask>(__func__,
1652 *
reinterpret_cast<LayerMask *
>(&other_mask));
1684 this->
base.wrap().~TreeNode();
1692 this->
masks.clear_no_delete();
1715 while (next_it != end && this->
frames().lookup(*next_it).is_end()) {
1718 next_it = std::next(next_it);
1725 if (!this->
frames().contains(frame_number)) {
1733 GreasePencilFrame frame{};
1746 if (frame ==
nullptr) {
1754 if (next_key_it !=
sorted_keys.
end() && *next_key_it == end_key) {
1757 next_key_it = this->remove_leading_end_frames_in_range(next_key_it,
sorted_keys.
end());
1759 if (duration == 0) {
1765 if (next_key_it ==
sorted_keys.
end() || *next_key_it > end_key) {
1775 if (!this->
frames().contains(key)) {
1778 if (this->
frames().size() == 1) {
1789 this->remove_leading_end_frames_in_range(next_key_it,
sorted_keys.
end());
1798 if (
false && !prev_frame.is_implicit_hold() && !prev_frame.is_end()) {
1820 std::ranges::sort(r_data);
1845 return std::prev(it);
1848std::optional<FramesMapKeyT> Layer::frame_key_at(
const int frame_number)
const
1851 if (it ==
nullptr) {
1859 const std::optional<FramesMapKeyT> frame_key = this->frame_key_at(frame_number);
1861 if (frame_key && !this->
frames().lookup_ptr(*frame_key)->is_end()) {
1870 if (it ==
nullptr) {
1883 const std::optional<FramesMapKeyT> frame_key = this->frame_key_at(frame_number);
1887 return this->
frames().lookup_ptr(*frame_key);
1889 if (frame_ptr ==
nullptr || frame_ptr->is_end()) {
1903 const std::optional<FramesMapKeyT> frame_key = this->frame_key_at(frame_number);
1909 if (frame_ptr ==
nullptr || frame_ptr->is_end()) {
1924 return frame_at(frame_number) !=
nullptr;
1930 if (it ==
nullptr) {
1936 if (frame->is_implicit_hold()) {
1940 if (frame->is_end()) {
1948 const int next_frame_number = *(std::next(it));
1973 const size_t frames_num = size_t(
frames().size());
1996 runtime = MEM_new<bke::greasepencil::LayerRuntime>(__func__);
2006 if (this->
parent ==
nullptr) {
2015 if (this->
parent ==
nullptr) {
2041 const float4x4 &parent_object_to_world =
parent.object_to_world();
2044 this->parent_bone_name().c_str()))
2046 return parent_object_to_world *
float4x4_view(channel->pose_mat);
2049 return parent_object_to_world;
2094 this->
runtime = MEM_new<LayerGroupRuntime>(__func__);
2107 switch (child.
type) {
2110 Layer *dup_layer = MEM_new<Layer>(__func__,
layer->wrap());
2116 LayerGroup *dup_group = MEM_new<LayerGroup>(__func__, group->wrap());
2128 this->
base.wrap().~TreeNode();
2131 switch (child.type) {
2134 MEM_delete(&
layer->wrap());
2139 MEM_delete(&group->wrap());
2151 if (
this == &other) {
2170 this->tag_nodes_cache_dirty();
2178 this->tag_nodes_cache_dirty();
2185 this->tag_nodes_cache_dirty();
2191 this->tag_nodes_cache_dirty();
2196 this->tag_nodes_cache_dirty();
2202 this->tag_nodes_cache_dirty();
2208 this->tag_nodes_cache_dirty();
2218 this->ensure_nodes_cache();
2231 ListBaseT<GreasePencilLayerTreeNode> link_children = link.
as_group().
children;
2237 child.parent =
this;
2241 if (link.
next !=
nullptr) {
2245 if (link.
prev !=
nullptr) {
2251 if (this->
children.last() == &link) {
2254 if (this->
children.first() == &link) {
2262 this->tag_nodes_cache_dirty();
2267 this->tag_nodes_cache_dirty();
2275 this->ensure_nodes_cache();
2281 this->ensure_nodes_cache();
2287 this->ensure_nodes_cache();
2293 this->ensure_nodes_cache();
2299 this->ensure_nodes_cache();
2305 this->ensure_nodes_cache();
2312 if (
node->name() == name) {
2322 if (
node->name() == name) {
2341 std::cout << header << std::endl;
2345 next_node.
push(std::make_pair(1, child));
2348 auto [indent,
node] = next_node.
pop();
2349 for (
int i = 0; i < indent; i++) {
2352 if (
node->is_layer()) {
2353 std::cout <<
node->name();
2355 else if (
node->is_group()) {
2356 std::cout <<
node->name() <<
": ";
2359 next_node.
push(std::make_pair(indent + 1, child));
2362 std::cout << std::endl;
2364 std::cout << std::endl;
2367void LayerGroup::ensure_nodes_cache()
const
2377 switch (
node->type) {
2384 for (
TreeNode *child :
node->as_group().nodes_for_write()) {
2386 if (child->is_layer()) {
2389 else if (child->is_group()) {
2400void LayerGroup::tag_nodes_cache_dirty()
const
2404 this->
base.
parent->wrap().tag_nodes_cache_dirty();
2412 switch (child.
type) {
2429 switch (child.
type) {
2445 if (
layer->name().is_empty()) {
2461 return std::nullopt;
2463 const int points_num = this->
drawing_orig->geometry.wrap().points_num();
2470 return std::nullopt;
2473 const int points_num = this->
drawing_orig->geometry.wrap().points_num();
2475 if (
data.sharing_info->is_mutable()) {
2477 data.sharing_info->tag_ensured_mutable();
2482 data.data = new_sharing_info->data.data();
2517 grease_pencil->runtime->eval_frame = grease_pencil_src->runtime->eval_frame;
2523 dst.material_array_num = src.material_array_num;
2524 dst.material_array = MEM_dupalloc(src.material_array);
2525 dst.attributes_active_index = src.attributes_active_index;
2526 dst.flag = src.flag;
2528 dst.vertex_group_active_index = src.vertex_group_active_index;
2529 dst.onion_skinning_settings = src.onion_skinning_settings;
2543 LayerMask *new_mask = MEM_new<LayerMask>(__func__, *
reinterpret_cast<LayerMask *
>(&src_mask));
2576 grease_pencil_dst->resize_drawings(grease_pencil_src->drawing_array_num);
2577 for (
const int i :
IndexRange(grease_pencil_dst->drawing_array_num)) {
2578 switch (grease_pencil_src->drawing_array[i]->type) {
2582 grease_pencil_dst->drawing_array[i] = &MEM_new<Drawing>(__func__, src_drawing)->base;
2587 grease_pencil_src->drawing_array[i])
2589 grease_pencil_dst->drawing_array[i] =
2590 &MEM_new<DrawingReference>(__func__, src_drawing_ref)->base;
2596 if (grease_pencil_dst->root_group_ptr) {
2597 MEM_delete(&grease_pencil_dst->root_group());
2600 grease_pencil_dst->root_group_ptr = MEM_new<bke::greasepencil::LayerGroup>(
2601 __func__, grease_pencil_src->root_group_ptr->wrap());
2602 BLI_assert(grease_pencil_src->layers().size() == grease_pencil_dst->layers().size());
2605 grease_pencil_dst->active_node =
nullptr;
2607 grease_pencil_dst->attribute_storage.wrap() = std::move(
2608 grease_pencil_src->attribute_storage.wrap());
2659 for (; tmd; tmd = tmd->
next) {
2676 for (; md; md = md->
next) {
2699 struct LayerDrawingInfo {
2701 const int layer_index;
2706 for (
const int layer_i :
grease_pencil.layers().index_range()) {
2710 if (all_drawings.
add(drawing)) {
2711 drawing_infos.
append({drawing, layer_i});
2716 if (layer_attributes.
contains(
"radius_offset")) {
2720 if (radius_offsets[info.layer_index] == 0.0f) {
2725 for (const int i : range) {
2726 radii[i] += radius_offsets[info.layer_index];
2732 if (layer_attributes.contains(
"tint_color")) {
2734 return base * (1.0 - tint.w) + tint * tint.
w;
2736 const VArray<ColorGeometry4f> tint_colors =
2740 if (tint_colors[info.layer_index].a == 0.0f) {
2743 MutableSpan<ColorGeometry4f> vertex_colors = info.drawing->vertex_colors_for_write();
2745 for (const int i : range) {
2746 vertex_colors[i] = ColorGeometry4f(
2747 mix_tint(float4(vertex_colors[i]), float4(tint_colors[info.layer_index])));
2750 MutableSpan<ColorGeometry4f> fill_colors = info.drawing->fill_colors_for_write();
2752 for (const int i : range) {
2753 fill_colors[i] = ColorGeometry4f(
2754 mix_tint(float4(fill_colors[i]), float4(tint_colors[info.layer_index])));
2772 layer->runtime->orig_layer_index_ = layer_i;
2776 if (
layer->is_visible() ||
layer->runtime->is_visibility_animated_) {
2806 if (layer_attributes.
contains(
"tint_color") || layer_attributes.
contains(
"radius_offset")) {
2831 empty_grease_pencil->runtime->eval_frame = int(
DEG_get_ctime(depsgraph));
2841 object->runtime->geometry_set_eval =
new GeometrySet(std::move(geometry_set));
2847 grease_pencil_dst->drawing_array_num = grease_pencil_src->drawing_array_num;
2848 if (grease_pencil_dst->drawing_array_num > 0) {
2849 grease_pencil_dst->drawing_array = MEM_new_array<GreasePencilDrawingBase *>(
2850 grease_pencil_src->drawing_array_num, __func__);
2852 grease_pencil_dst->drawings());
2872 if (
curves.has_curve_with_type(type)) {
2882 int total_points = 0;
2884 for (
const int layer_i :
grease_pencil.layers().index_range()) {
2896 total_points +=
curves.points_num();
2900 return total_points;
2908 for (
const int layer_i :
grease_pencil.layers().index_range()) {
2925 for (
const int i :
curves.points_range()) {
2927 all_radii[
index] = radii[i];
2932 const std::optional<Span<float3>> handle_positions_left =
curves.handle_positions_left();
2933 const std::optional<Span<float3>> handle_positions_right =
curves.handle_positions_right();
2934 for (
const int i :
curves.points_range()) {
2935 const int index_pos =
index * 3;
2937 (*handle_positions_left)[i]);
2940 (*handle_positions_right)[i]);
2941 all_radii[
index] = radii[i];
2954 for (
const int layer_i :
grease_pencil.layers().index_range()) {
2971 for (
const int i :
curves.points_range()) {
2973 radii[i] = all_radii[
index];
2980 for (
const int i :
curves.points_range()) {
2981 const int index_pos =
index * 3;
2983 all_positions[index_pos]);
2986 all_positions[index_pos + 2]);
2987 radii[i] = all_radii[
index];
2992 curves.tag_radii_changed();
3005 for (
const int layer_i :
grease_pencil.layers().index_range()) {
3022 for (
const int i :
curves.points_range()) {
3024 radii[i] = all_radii[
index] * scalef;
3031 for (
const int i :
curves.points_range()) {
3032 const int index_pos =
index * 3;
3034 all_positions[index_pos]);
3036 all_positions[index_pos + 1]);
3038 all_positions[index_pos + 2]);
3039 radii[i] = all_radii[
index] * scalef;
3044 curves.tag_radii_changed();
3060 for (
short i = 0; i < *totcol; i++) {
3062 if (
STREQ(name, read_ma->id.name + 2)) {
3082 *r_index = ob->
actcol - 1;
3092 return brush->gpencil_settings->material;
3115 Material *ma = (
brush->gpencil_settings) ?
brush->gpencil_settings->material :
nullptr;
3126 const bool change_active_material =
false;
3166 Material *material_alt = (
brush->gpencil_settings) ?
brush->gpencil_settings->material_alt :
3169 material_alt =
reinterpret_cast<Material *
>(
3172 return material_alt;
3191 if (!material_indices) {
3195 for (
const int i : material_indices.
span.index_range()) {
3198 material_indices.
span[i] = remap[material_indices.
span[i]];
3200 material_indices.
finish();
3216 if (!material_indices) {
3220 for (
const int i : material_indices.
span.index_range()) {
3221 if (material_indices.
span[i] > 0 && material_indices.
span[i] >=
index) {
3222 material_indices.
span[i]--;
3225 material_indices.
finish();
3253 if (
brush->gpencil_settings->material != ma) {
3254 if (
brush->gpencil_settings->material) {
3260 brush->gpencil_settings->material = ma;
3273 const char *hexcol[] = {
3274 "FFFFFF",
"F2F2F2",
"E6E6E6",
"D9D9D9",
"CCCCCC",
"BFBFBF",
"B2B2B2",
"A6A6A6",
"999999",
3275 "8C8C8C",
"808080",
"737373",
"666666",
"595959",
"4C4C4C",
"404040",
"333333",
"262626",
3276 "1A1A1A",
"000000",
"F2FC24",
"FFEA00",
"FEA711",
"FE8B68",
"FB3B02",
"FE3521",
"D00000",
3277 "A81F3D",
"780422",
"2B0000",
"F1E2C5",
"FEE4B3",
"FEDABB",
"FEC28E",
"D88F57",
"BD6340",
3278 "A2402B",
"63352D",
"6B2833",
"34120C",
"E7CB8F",
"D1B38B",
"C1B17F",
"D7980B",
"FFB100",
3279 "FE8B00",
"FF6A00",
"B74100",
"5F3E1D",
"3B2300",
"FECADA",
"FE65CB",
"FE1392",
"DD3062",
3280 "C04A6D",
"891688",
"4D2689",
"441521",
"2C1139",
"241422",
"FFFF7D",
"FFFF00",
"FF7F00",
3281 "FF7D7D",
"FF7DFF",
"FF00FE",
"FF007F",
"FF0000",
"7F0000",
"0A0A00",
"F6FDFF",
"E9F7FF",
3282 "CFE6FE",
"AAC7FE",
"77B3FE",
"1E74FD",
"0046AA",
"2F4476",
"003052",
"0E0E25",
"EEF5F0",
3283 "D6E5DE",
"ACD8B9",
"6CADC6",
"42A9AF",
"007F7F",
"49675C",
"2E4E4E",
"1D3239",
"0F1C21",
3284 "D8FFF4",
"B8F4F5",
"AECCB5",
"76C578",
"358757",
"409B68",
"468768",
"1F512B",
"2A3C37",
3285 "122E1D",
"EFFFC9",
"E6F385",
"BCF51C",
"D4DC18",
"82D322",
"5C7F00",
"59932B",
"297F00",
3286 "004320",
"1C3322",
"00FF7F",
"00FF00",
"7DFF7D",
"7DFFFF",
"00FFFF",
"7D7DFF",
"7F00FF",
3287 "0000FF",
"3F007F",
"00007F"};
3295 const char *palette_id =
"Palette";
3299 if (palette ==
nullptr) {
3304 if (palette ==
nullptr) {
3310 for (
int i = 0; i <
ARRAY_SIZE(hexcol); i++) {
3334 if (id_reference == reference->id_reference) {
3359 int mode) =
nullptr;
3385 const int new_array_num = *
num + add_num;
3389 if (*
array !=
nullptr) {
3394 *
num = new_array_num;
3399 const int new_array_num = *
num - shrink_num;
3400 if (new_array_num == 0) {
3413 *
num = new_array_num;
3421MutableSpan<GreasePencilDrawingBase *> GreasePencil::drawings()
3423 return MutableSpan<GreasePencilDrawingBase *>{this->drawing_array, this->drawing_array_num};
3430 MEM_delete(drawing_base);
3437 MEM_delete(&drawing->wrap());
3443 MEM_delete(&drawing_reference->wrap());
3449void GreasePencil::resize_drawings(
const int new_num)
3453 const int prev_num = int(this->drawings().
size());
3454 if (new_num == prev_num) {
3457 if (new_num > prev_num) {
3458 const int add_num = new_num - prev_num;
3462 const int shrink_num = prev_num - new_num;
3463 MutableSpan<GreasePencilDrawingBase *> old_drawings = this->drawings().drop_front(new_num);
3465 if (GreasePencilDrawingBase *drawing_base = old_drawings[i]) {
3470 &this->drawing_array, &this->drawing_array_num, shrink_num);
3474void GreasePencil::add_empty_drawings(
const int add_num)
3477 const int prev_num = this->drawings().size();
3479 MutableSpan<GreasePencilDrawingBase *> new_drawings = this->drawings().drop_front(prev_num);
3481 new_drawings[i] =
reinterpret_cast<GreasePencilDrawingBase *
>(
3482 MEM_new<bke::greasepencil::Drawing>(__func__));
3486void GreasePencil::add_duplicate_drawings(
const int duplicate_num,
3487 const bke::greasepencil::Drawing &drawing)
3490 const int prev_num = this->drawings().size();
3492 &this->drawing_array, &this->drawing_array_num, duplicate_num);
3493 MutableSpan<GreasePencilDrawingBase *> new_drawings = this->drawings().
drop_front(prev_num);
3495 new_drawings[i] =
reinterpret_cast<GreasePencilDrawingBase *
>(
3496 MEM_new<bke::greasepencil::Drawing>(__func__, drawing));
3500bke::greasepencil::Drawing *GreasePencil::insert_frame(bke::greasepencil::Layer &
layer,
3501 const int frame_number,
3505 GreasePencilFrame *frame =
layer.add_frame(frame_number, duration);
3506 if (frame ==
nullptr) {
3509 this->add_empty_drawings(1);
3510 frame->
drawing_index = this->drawings().index_range().last();
3513 GreasePencilDrawingBase *drawing_base = this->drawings().last();
3516 return &drawing->wrap();
3519void GreasePencil::insert_frames(Span<bke::greasepencil::Layer *> layers,
3520 const int frame_number,
3527 Vector<GreasePencilFrame *> frames;
3529 for (bke::greasepencil::Layer *
layer : layers) {
3531 GreasePencilFrame *frame =
layer->add_frame(frame_number, duration);
3532 if (frame !=
nullptr) {
3541 this->add_empty_drawings(frames.
size());
3544 GreasePencilFrame *frame = frames[frame_i];
3550bool GreasePencil::insert_duplicate_frame(bke::greasepencil::Layer &
layer,
3551 const int src_frame_number,
3552 const int dst_frame_number,
3553 const bool do_instance)
3555 using namespace blender::bke::greasepencil;
3557 if (!
layer.frames().contains(src_frame_number)) {
3561 if (
layer.is_locked()) {
3564 const GreasePencilFrame src_frame =
layer.frames().lookup(src_frame_number);
3570 const int duration = 0 ;
3571 GreasePencilFrame *dst_frame =
layer.add_frame(dst_frame_number, duration);
3572 if (dst_frame ==
nullptr) {
3578 const GreasePencilDrawingBase *src_drawing_base = this->drawing(src_frame.
drawing_index);
3579 switch (src_drawing_base->
type) {
3592 this->add_duplicate_drawings(1, src_drawing);
3599 layer.remove_frame(dst_frame_number);
3603 this->validate_drawing_user_counts();
3608bool GreasePencil::remove_frames(bke::greasepencil::Layer &
layer, Span<int> frame_numbers)
3610 using namespace blender::bke::greasepencil;
3611 bool removed_any_drawing_user =
false;
3612 for (
const int frame_number : frame_numbers) {
3613 if (!
layer.frames().contains(frame_number)) {
3616 const GreasePencilFrame frame_to_remove =
layer.frames().lookup(frame_number);
3618 if (!
layer.remove_frame(frame_number)) {
3622 if (frame_to_remove.is_end()) {
3626 GreasePencilDrawingBase *drawing_base = this->drawing(drawing_index_to_remove);
3634 removed_any_drawing_user =
true;
3636 if (removed_any_drawing_user) {
3637 this->remove_drawings_with_no_users();
3641 this->validate_drawing_user_counts();
3646void GreasePencil::copy_frames_from_layer(bke::greasepencil::Layer &dst_layer,
3647 const GreasePencil &src_grease_pencil,
3648 const bke::greasepencil::Layer &src_layer,
3649 const std::optional<int> frame_select)
3651 const Span<const GreasePencilDrawingBase *> src_drawings = src_grease_pencil.drawings();
3652 Array<int> drawing_index_map(src_grease_pencil.drawing_array_num, -1);
3654 for (
auto [frame_number, src_frame] : src_layer.
frames().items()) {
3655 if (frame_select && *frame_select != frame_number) {
3660 int dst_drawing_index = drawing_index_map[src_drawing_index];
3661 if (dst_drawing_index < 0) {
3662 switch (src_drawings[src_drawing_index]->type) {
3664 const bke::greasepencil::Drawing &src_drawing =
3667 this->add_duplicate_drawings(1, src_drawing);
3672 this->add_empty_drawings(1);
3675 dst_drawing_index = this->drawings().size() - 1;
3676 drawing_index_map[src_drawing_index] = dst_drawing_index;
3680 GreasePencilFrame *dst_frame = dst_layer.
add_frame(frame_number);
3686void GreasePencil::add_layers_with_empty_drawings_for_eval(
const int num)
3688 using namespace blender::bke::greasepencil;
3689 const int old_drawings_num = this->drawing_array_num;
3690 const int old_layers_num = this->layers().size();
3691 this->add_empty_drawings(
num);
3692 this->add_layers_for_eval(
num);
3694 for (
const int i : range) {
3695 const int new_drawing_i = old_drawings_num + i;
3696 const int new_layer_i = old_layers_num + i;
3698 GreasePencilFrame *frame =
layer.add_frame(this->runtime->eval_frame);
3705void GreasePencil::remove_drawings_with_no_users()
3707 using namespace blender::bke::greasepencil;
3717 const MutableSpan<GreasePencilDrawingBase *> drawings = this->drawings();
3722 auto is_drawing_used = [&](
const int drawing_index) {
3723 GreasePencilDrawingBase *drawing_base = drawings[drawing_index];
3735 constexpr const int unchanged_index = -1;
3736 Array<int> drawing_index_map(drawings.
size(), unchanged_index);
3738 int first_unused_drawing = -1;
3739 int last_used_drawing = drawings.
size() - 1;
3742 auto find_next_swap_index = [&]() ->
bool {
3744 ++first_unused_drawing;
3745 }
while (first_unused_drawing <= last_used_drawing && is_drawing_used(first_unused_drawing));
3746 while (last_used_drawing >= 0 && !is_drawing_used(last_used_drawing)) {
3747 --last_used_drawing;
3750 return first_unused_drawing < last_used_drawing;
3753 while (find_next_swap_index()) {
3755 std::swap(drawings[first_unused_drawing], drawings[last_used_drawing]);
3756 drawing_index_map[last_used_drawing] = first_unused_drawing;
3762 BLI_assert(last_used_drawing == first_unused_drawing - 1);
3765 if (i < first_unused_drawing) {
3775 const IndexRange drawings_to_remove = (first_unused_drawing > 0) ?
3777 first_unused_drawing) :
3779 if (drawings_to_remove.
is_empty()) {
3784 for (
const int i : drawings_to_remove) {
3785 GreasePencilDrawingBase *unused_drawing_base = drawings[i];
3786 switch (unused_drawing_base->
type) {
3789 MEM_delete(&unused_drawing->wrap());
3793 auto *unused_drawing_ref =
reinterpret_cast<GreasePencilDrawingReference *
>(
3794 unused_drawing_base);
3795 MEM_delete(&unused_drawing_ref->wrap());
3801 &this->drawing_array, &this->drawing_array_num, drawings_to_remove.size());
3804 for (
Layer *
layer : this->layers_for_write()) {
3805 for (
auto [key, value] :
layer->frames_for_write().items()) {
3806 const int new_drawing_index = drawing_index_map[value.drawing_index];
3807 if (new_drawing_index != unchanged_index) {
3808 value.drawing_index = new_drawing_index;
3809 layer->tag_frames_map_changed();
3815 this->validate_drawing_user_counts();
3819void GreasePencil::update_drawing_users_for_layer(
const bke::greasepencil::Layer &
layer)
3821 for (
const auto &[key, value] :
layer.frames().items()) {
3823 GreasePencilDrawingBase *drawing_base = this->drawing(value.drawing_index);
3827 bke::greasepencil::Drawing &drawing =
3835 this->validate_drawing_user_counts();
3839void GreasePencil::move_frames(bke::greasepencil::Layer &
layer,
3840 const Map<int, int> &frame_number_destinations)
3842 this->move_duplicate_frames(
layer, frame_number_destinations, Map<int, GreasePencilFrame>());
3845void GreasePencil::move_duplicate_frames(bke::greasepencil::Layer &
layer,
3846 const Map<int, int> &frame_number_destinations,
3847 const Map<int, GreasePencilFrame> &duplicate_frames)
3849 Map<int, GreasePencilFrame> layer_frames_copy =
layer.frames();
3852 Map<int, int> src_layer_frames_durations;
3853 for (
const auto [frame_number, frame] :
layer.frames().items()) {
3854 src_layer_frames_durations.
add(frame_number,
layer.get_frame_duration_at(frame_number));
3860 for (
const auto src_frame_number : frame_number_destinations.
keys()) {
3861 if (!duplicate_frames.
contains(src_frame_number)) {
3863 layer.remove_frame(src_frame_number);
3867 auto get_source_frame = [&](
const int frame_number) ->
const GreasePencilFrame * {
3868 if (
const GreasePencilFrame *ptr = duplicate_frames.
lookup_ptr(frame_number)) {
3871 return layer_frames_copy.
lookup_ptr(frame_number);
3874 for (
const auto [src_frame_number, dst_frame_number] : frame_number_destinations.
items()) {
3875 const GreasePencilFrame *src_frame = get_source_frame(src_frame_number);
3879 const int duration = 0 ;
3882 if (
layer.frames().contains(dst_frame_number)) {
3883 GreasePencilFrame frame_to_overwrite =
layer.frames().lookup(dst_frame_number);
3884 GreasePencilDrawingBase *drawing_base = this->drawing(frame_to_overwrite.
drawing_index);
3888 layer.remove_frame(dst_frame_number);
3890 GreasePencilFrame *frame =
layer.add_frame(dst_frame_number, duration);
3891 *frame = *src_frame;
3895 this->remove_drawings_with_no_users();
3898const bke::greasepencil::Drawing *GreasePencil::get_drawing_at(
3899 const bke::greasepencil::Layer &
layer,
const int frame_number)
const
3901 if (this->drawings().is_empty()) {
3904 const int drawing_index =
layer.drawing_index_at(frame_number);
3905 if (drawing_index == -1) {
3909 const GreasePencilDrawingBase *drawing_base = this->drawing(drawing_index);
3915 return &drawing->wrap();
3918bke::greasepencil::Drawing *GreasePencil::get_drawing_at(
const bke::greasepencil::Layer &
layer,
3919 const int frame_number)
3921 if (this->drawings().is_empty()) {
3924 const int drawing_index =
layer.drawing_index_at(frame_number);
3925 if (drawing_index == -1) {
3929 GreasePencilDrawingBase *drawing_base = this->drawing(drawing_index);
3935 return &drawing->wrap();
3938bke::greasepencil::Drawing *GreasePencil::get_editable_drawing_at(
3939 const bke::greasepencil::Layer &
layer,
const int frame_number)
3941 if (!
layer.is_editable()) {
3944 if (this->drawings().is_empty()) {
3947 const int drawing_index =
layer.drawing_index_at(frame_number);
3948 if (drawing_index == -1) {
3952 GreasePencilDrawingBase *drawing_base = this->drawing(drawing_index);
3958 return &drawing->wrap();
3961const bke::greasepencil::Drawing *GreasePencil::get_eval_drawing(
3962 const bke::greasepencil::Layer &
layer)
const
3964 return this->get_drawing_at(
layer, this->runtime->eval_frame);
3967bke::greasepencil::Drawing *GreasePencil::get_eval_drawing(
const bke::greasepencil::Layer &
layer)
3969 return this->get_drawing_at(
layer, this->runtime->eval_frame);
3972std::optional<Bounds<float3>> GreasePencil::bounds_min_max(
const int frame,
3973 const bool use_radius)
const
3975 std::optional<Bounds<float3>> bounds;
3976 const Span<const bke::greasepencil::Layer *> layers = this->layers();
3978 const bke::greasepencil::Layer &
layer = *layers[layer_i];
3980 if (!
layer.is_visible()) {
3983 const bke::greasepencil::Drawing *drawing = this->get_drawing_at(
layer, frame);
3987 const bke::CurvesGeometry &curves = drawing->
strokes();
3999 const Bounds<float3> drawing_bounds = *
bounds::min_max(positions_world.as_span());
4003 if (
const std::optional radius_single =
radius.get_if_single()) {
4005 drawing_bounds.
pad(*radius_single);
4009 const Span radius_span =
radius.get_internal_span();
4020 radii_eval.as_span());
4026std::optional<Bounds<float3>> GreasePencil::bounds_min_max_eval(
const bool use_radius)
const
4028 return this->bounds_min_max(this->runtime->eval_frame, use_radius);
4031void GreasePencil::count_memory(MemoryCounter &memory)
const
4033 using namespace blender::bke;
4034 for (
const GreasePencilDrawingBase *base : this->drawings()) {
4038 const greasepencil::Drawing &drawing =
4044std::optional<int> GreasePencil::material_index_max()
const
4046 using namespace blender::bke;
4047 std::optional<int> max_index;
4048 for (
const GreasePencilDrawingBase *drawing_base : this->drawings()) {
4054 const std::optional<int> max_index_in_drawing = drawing->wrap().strokes().material_index_max();
4056 if (max_index_in_drawing) {
4057 max_index = std::max(*max_index, *max_index_in_drawing);
4061 max_index = max_index_in_drawing;
4067Span<const bke::greasepencil::Layer *> GreasePencil::layers()
const
4070 return this->root_group().layers();
4073Span<bke::greasepencil::Layer *> GreasePencil::layers_for_write()
4076 return this->root_group().layers_for_write();
4079Span<const bke::greasepencil::LayerGroup *> GreasePencil::layer_groups()
const
4082 return this->root_group().groups();
4085Span<bke::greasepencil::LayerGroup *> GreasePencil::layer_groups_for_write()
4088 return this->root_group().groups_for_write();
4091Span<const bke::greasepencil::TreeNode *> GreasePencil::nodes()
const
4094 return this->root_group().nodes();
4097Span<bke::greasepencil::TreeNode *> GreasePencil::nodes_for_write()
4100 return this->root_group().nodes_for_write();
4103std::optional<int> GreasePencil::get_layer_index(
const bke::greasepencil::Layer &
layer)
const
4105 const int index = int(this->layers().first_index_try(&
layer));
4112const bke::greasepencil::Layer *GreasePencil::get_active_layer()
const
4114 if (this->active_node ==
nullptr) {
4117 const bke::greasepencil::TreeNode &active_node = *this->get_active_node();
4124bke::greasepencil::Layer *GreasePencil::get_active_layer()
4126 if (this->active_node ==
nullptr) {
4129 bke::greasepencil::TreeNode &active_node = *this->get_active_node();
4136void GreasePencil::set_active_layer(bke::greasepencil::Layer *
layer)
4138 this->active_node =
reinterpret_cast<GreasePencilLayerTreeNode *
>(&
layer->as_node());
4141 this->autolock_inactive_layers();
4145bool GreasePencil::is_layer_active(
const bke::greasepencil::Layer *
layer)
const
4147 if (
layer ==
nullptr) {
4150 return this->get_active_layer() ==
layer;
4153void GreasePencil::autolock_inactive_layers()
4155 using namespace blender::bke::greasepencil;
4157 for (
Layer *
layer : this->layers_for_write()) {
4158 if (this->is_layer_active(
layer)) {
4159 layer->set_locked(
false);
4162 layer->set_locked(
true);
4166const bke::greasepencil::LayerGroup *GreasePencil::get_active_group()
const
4168 if (this->active_node ==
nullptr) {
4171 const bke::greasepencil::TreeNode &active_node = *this->get_active_node();
4178bke::greasepencil::LayerGroup *GreasePencil::get_active_group()
4180 if (this->active_node ==
nullptr) {
4183 bke::greasepencil::TreeNode &active_node = *this->get_active_node();
4190const bke::greasepencil::TreeNode *GreasePencil::get_active_node()
const
4192 if (this->active_node ==
nullptr) {
4195 return &this->active_node->wrap();
4198bke::greasepencil::TreeNode *GreasePencil::get_active_node()
4200 if (this->active_node ==
nullptr) {
4203 return &this->active_node->wrap();
4206void GreasePencil::set_active_node(bke::greasepencil::TreeNode *
node)
4208 this->active_node =
reinterpret_cast<GreasePencilLayerTreeNode *
>(
node);
4225 [&](
const StringRef check_name) {
return names.
contains(check_name); },
'.', name);
4228std::string GreasePencil::unique_layer_name(
StringRef name)
4232 name =
DATA_(
"Layer");
4241 name =
DATA_(
"Group");
4247 const bool check_name_is_unique)
4249 std::string unique_name = check_name_is_unique ? unique_layer_name(name) : std::string(name);
4250 const int numLayers = layers().
size();
4269bke::greasepencil::Layer &GreasePencil::add_layer(bke::greasepencil::LayerGroup &parent_group,
4270 const StringRef name,
4271 const bool check_name_is_unique)
4273 bke::greasepencil::Layer &new_layer = this->add_layer(name, check_name_is_unique);
4274 move_node_into(new_layer.
as_node(), parent_group);
4278void GreasePencil::add_layers_for_eval(
const int num_new_layers)
4280 const int num_layers = this->layers().
size();
4282 for ([[maybe_unused]]
const int i :
IndexRange(num_new_layers)) {
4283 bke::greasepencil::Layer *new_layer = MEM_new<bke::greasepencil::Layer>(__func__);
4286 this->root_group().add_node(new_layer->
as_node());
4290bke::greasepencil::Layer &GreasePencil::duplicate_layer(
4291 const bke::greasepencil::Layer &duplicate_layer,
4292 const bool duplicate_frames,
4293 const bool duplicate_drawings)
4295 std::string unique_name = unique_layer_name(duplicate_layer.name());
4296 std::optional<int> duplicate_layer_idx = get_layer_index(duplicate_layer);
4298 const int numLayers = layers().
size();
4299 bke::greasepencil::Layer *new_layer = MEM_new<bke::greasepencil::Layer>(__func__,
4301 root_group().add_node(new_layer->
as_node());
4304 bke::MutableAttributeAccessor attributes = this->attributes_for_write();
4310 GMutableSpan span = attr.
span;
4318 if (duplicate_frames) {
4319 for (
auto [frame_number, frame] : duplicate_layer.
frames().items()) {
4320 const int duration = 0 ;
4321 bke::greasepencil::Drawing *dst_drawing = this->insert_frame(
4323 if (duplicate_drawings) {
4326 const bke::greasepencil::Drawing &src_drawing = *this->get_drawing_at(duplicate_layer,
4329 *dst_drawing = src_drawing;
4334 this->update_drawing_users_for_layer(*new_layer);
4335 new_layer->set_name(unique_name);
4339bke::greasepencil::Layer &GreasePencil::duplicate_layer(
4340 bke::greasepencil::LayerGroup &parent_group,
4341 const bke::greasepencil::Layer &duplicate_layer,
4342 const bool duplicate_frames,
4343 const bool duplicate_drawings)
4345 bke::greasepencil::Layer &new_layer = this->duplicate_layer(
4346 duplicate_layer, duplicate_frames, duplicate_drawings);
4347 move_node_into(new_layer.
as_node(), parent_group);
4351bke::greasepencil::LayerGroup &GreasePencil::add_layer_group(
const StringRef name,
4352 const bool check_name_is_unique)
4356 bke::greasepencil::LayerGroup *new_group = MEM_new<bke::greasepencil::LayerGroup>(__func__,
4358 return root_group().add_node(new_group->
as_node()).as_group();
4361bke::greasepencil::LayerGroup &GreasePencil::add_layer_group(
4362 bke::greasepencil::LayerGroup &parent_group,
4363 const StringRef name,
4364 const bool check_name_is_unique)
4366 bke::greasepencil::LayerGroup &new_group = this->add_layer_group(name, check_name_is_unique);
4367 move_node_into(new_group.
as_node(), parent_group);
4376 if (attr.
domain() != domain) {
4380 switch (attr.storage_type()) {
4382 const auto &
data = std::get<bke::Attribute::ArrayData>(attr.data());
4387 attr.assign_data(std::move(new_data));
4406 old_layer_index_by_layer.
add_new(layers[i], i);
4410 do_layer_order_changes();
4416 for (
const int layer_i_new : layers.
index_range()) {
4419 const int layer_i_old = old_layer_index_by_layer.
pop(
layer);
4420 new_by_old_map[layer_i_new] = layer_i_old;
4431 if (!
node.parent_group()) {
4436void GreasePencil::move_node_down(bke::greasepencil::TreeNode &
node,
const int step)
4438 if (!
node.parent_group()) {
4443void GreasePencil::move_node_top(bke::greasepencil::TreeNode &
node)
4445 if (!
node.parent_group()) {
4450void GreasePencil::move_node_bottom(bke::greasepencil::TreeNode &
node)
4452 if (!
node.parent_group()) {
4458void GreasePencil::move_node_after(bke::greasepencil::TreeNode &
node,
4459 bke::greasepencil::TreeNode &target_node)
4465 node.parent_group()->unlink_node(
node);
4470void GreasePencil::move_node_before(bke::greasepencil::TreeNode &
node,
4471 bke::greasepencil::TreeNode &target_node)
4477 node.parent_group()->unlink_node(
node);
4482void GreasePencil::move_node_into(bke::greasepencil::TreeNode &
node,
4483 bke::greasepencil::LayerGroup &parent_group)
4485 if (!
node.parent_group()) {
4489 node.parent_group()->unlink_node(
node);
4494const bke::greasepencil::TreeNode *GreasePencil::find_node_by_name(
const StringRef name)
const
4496 return this->root_group().find_node_by_name(name);
4499bke::greasepencil::TreeNode *GreasePencil::find_node_by_name(
const StringRef name)
4501 return this->root_group().find_node_by_name(name);
4504IndexMask GreasePencil::layer_selection_by_name(
const StringRef name,
4505 IndexMaskMemory &memory)
const
4507 using namespace blender::bke::greasepencil;
4513 if (
node->is_layer()) {
4514 const int index = *this->get_layer_index(
node->as_layer());
4517 if (
node->is_group()) {
4518 Vector<int64_t> layer_indices;
4519 for (
const int64_t layer_index : this->layers().index_range()) {
4520 const Layer &
layer = *this->layers()[layer_index];
4521 if (
layer.is_child_of(
node->as_group())) {
4522 layer_indices.
append(layer_index);
4641void GreasePencil::rename_node(
Main &bmain,
4645 if (
node.name() == new_name) {
4650 std::string old_name =
node.name();
4651 if (
node.is_layer()) {
4652 node.set_name(unique_layer_name(new_name));
4654 else if (
node.is_group()) {
4659 if (
node.is_layer()) {
4667 for (bke::greasepencil::Layer *
layer : this->layers_for_write()) {
4668 for (GreasePencilLayerMask &mask :
layer->masks) {
4669 if (
STREQ(
mask.layer_name, old_name.c_str())) {
4677 for (Object &
object : bmain.
objects) {
4678 if (
object.
data != id_cast<ID *>(
this)) {
4683 for (ModifierData &md :
object.modifiers) {
4684 char *dst_layer_name =
nullptr;
4685 size_t dst_layer_name_maxncpy = 0;
4688 auto *lmd =
reinterpret_cast<GreasePencilLineartModifierData *
>(&md);
4689 dst_layer_name = lmd->target_layer;
4690 dst_layer_name_maxncpy =
sizeof(lmd->target_layer);
4695 dst_layer_name = influence_data->layer_name;
4696 dst_layer_name_maxncpy =
sizeof(influence_data->layer_name);
4698 if (dst_layer_name &&
STREQ(dst_layer_name, old_name.c_str())) {
4699 BLI_strncpy(dst_layer_name,
node.name().c_str(), dst_layer_name_maxncpy);
4706 const int index_to_remove,
4709 const IndexRange range_before(index_to_remove);
4710 const IndexRange range_after(index_to_remove + 1, size - index_to_remove - 1);
4714 switch (attr.storage_type()) {
4716 const auto &
data = std::get<bke::Attribute::ArrayData>(attr.data());
4722 range_after.
size());
4724 attr.assign_data(std::move(new_data));
4739 if (
node.prev !=
nullptr) {
4744 else if (
node.next !=
nullptr) {
4762 if (&
layer.as_node() == this->get_active_node()) {
4767 const int layer_index = *this->get_layer_index(
layer);
4771 layer.parent_group().unlink_node(
layer.as_node());
4774 for (
const GreasePencilFrame frame :
layer.frames().values()) {
4775 GreasePencilDrawingBase *drawing_base = this->drawing(frame.drawing_index);
4781 drawing->wrap().remove_user();
4783 this->remove_drawings_with_no_users();
4789void GreasePencil::remove_group(bke::greasepencil::LayerGroup &group,
const bool keep_children)
4791 using namespace blender::bke::greasepencil;
4793 if (&group.
as_node() == this->get_active_node()) {
4795 if (keep_children && !group.
is_empty()) {
4796 this->set_active_node(
reinterpret_cast<TreeNode *
>(group.
children.last()));
4803 if (!keep_children) {
4805 for (GreasePencilLayerTreeNode &child : group.
children.items_mutable()) {
4806 switch (child.type) {
4808 this->remove_layer(
reinterpret_cast<GreasePencilLayer *
>(&child)->
wrap());
4812 this->remove_group(
reinterpret_cast<GreasePencilLayerTreeGroup *
>(&child)->
wrap(),
4828void GreasePencil::print_layer_tree()
4830 using namespace blender::bke::greasepencil;
4831 this->root_group().print_nodes(
"Layer Tree:");
4834Array<int> GreasePencil::count_frame_users_for_drawings()
const
4836 using namespace blender::bke::greasepencil;
4837 Array<int> user_counts(this->drawings().
size(), 0);
4839 for (
const auto &[frame, value] :
layer->frames().items()) {
4841 user_counts[value.drawing_index]++;
4847void GreasePencil::validate_drawing_user_counts()
4850 using namespace blender::bke::greasepencil;
4851 Array<int> actual_user_counts = this->count_frame_users_for_drawings();
4852 for (
const int drawing_i : this->drawings().index_range()) {
4853 const GreasePencilDrawingBase *drawing_base = this->drawing(drawing_i);
4863bke::AttributeAccessor GreasePencil::attributes()
const
4868bke::MutableAttributeAccessor GreasePencil::attributes_for_write()
4870 return bke::MutableAttributeAccessor(
this,
4898 return drawing_struct_size(GreasePencilDrawingType(drawing.type));
4904 if (drawing_base ==
nullptr) {
4906 MEM_new<bke::greasepencil::Drawing>(__func__));
4913 drawing->wrap().strokes_for_write().blend_read(*reader);
4915 drawing->
runtime = MEM_new<bke::greasepencil::DrawingRuntime>(__func__);
4940 drawing_copy.
runtime =
nullptr;
4946 struct_writer.generated_ptr(
4978 node->base.parent = parent;
4988 node->frames_storage.num = 0;
5001 node->runtime =
nullptr;
5002 node->wrap().update_from_dna_read();
5021 node->base.parent = parent;
5025 return layer_tree_node_struct_size(child.type);
5028 switch (child.
type) {
5042 node->wrap().runtime = MEM_new<bke::greasepencil::LayerGroupRuntime>(__func__);
5053 grease_pencil.root_group_ptr = MEM_new<bke::greasepencil::LayerGroup>(__func__);
5061 grease_pencil.root_group_ptr->wrap().update_from_dna_read();
5085 switch (child.
type) {
5102 grease_pencil.root_group_ptr->wrap().prepare_for_dna_write();
Blender kernel action and pose functionality.
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
Low-level operations for grease pencil that cannot be defined in the C++ header yet.
Low-level operations for grease pencil.
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
#define BLI_MEMARENA_STD_BUFSIZE
#define STRNCPY_UTF8(dst, src)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define BLT_I18NCONTEXT_ID_GPENCIL
#define CLOG_WARN(clg_ref,...)
ID and Library types, which are fundamental for SDNA.
Enumerations for DNA_ID.h.
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member)
#define POINTER_OFFSET(v, ofs)
#define BLI_assert_msg(a, msg)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
IndexRange index_range() const
void generated_ptr(int64_t offset)
void copy_construct_n(const void *src, void *dst, int64_t n) const
void copy_assign(const void *src, void *dst) const
void ensure(const FunctionRef< void()> compute_cache)
std::optional< GroupedSpan< int3 > > triangles() const
const CPPType & type() const
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_indices(Span< T > indices, LinearAllocator<> &memory)
constexpr int64_t first() const
constexpr IndexRange drop_back(int64_t n) const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr IndexRange()=default
constexpr int64_t start() const
constexpr IndexRange take_back(int64_t n) const
static constexpr IndexRange from_single(const int64_t index)
constexpr IndexRange index_range() const
constexpr IndexRange drop_front(int64_t n) const
const Value * lookup_ptr(const Key &key) const
Value pop(const Key &key)
bool add(const Key &key, const Value &value)
const Value & lookup(const Key &key) const
void foreach_item(const FuncT &func) const
void add_new(const Key &key, const Value &value)
KeyIterator keys() const &
bool contains(const Key &key) const
ItemIterator items() const &
constexpr MutableSpan()=default
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr T * data() const
constexpr MutableSpan drop_front(const int64_t n) const
constexpr IndexRange index_range() const
constexpr T & last(const int64_t n=0) const
IndexRange index_range() const
T & construct(Args &&...args)
constexpr Span slice(int64_t start, int64_t size) const
constexpr const T & first() const
constexpr int64_t size() const
constexpr const T & last(const int64_t n=0) const
constexpr const T * end() const
constexpr IndexRange index_range() const
constexpr const T * begin() const
constexpr bool is_empty() const
void push(const T &value)
constexpr StringRefNull()
bool contains(const Key &key) const
void append(const T &value)
IndexRange index_range() const
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
void reserve(const int64_t min_capacity)
void reinitialize(const int64_t new_size)
Span< T > as_span() const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
bool contains(StringRef name) const
GAttributeReader lookup(const StringRef name) const
std::optional< AttrStorageType > storage_type
void ensure_can_interpolate_to_evaluated() const
int evaluated_points_num() const
std::optional< Bounds< float3 > > bounds_min_max(bool use_radius=true) const
AttributeAccessor attributes() const
bool is_single_type(CurveType type) const
void interpolate_to_evaluated(int curve_index, GSpan src, GMutableSpan dst) const
void tag_topology_changed()
Span< float3 > evaluated_positions() const
void tag_positions_changed()
VArray< float > radius() const
void count_memory(MemoryCounter &memory) const
MutableAttributeAccessor attributes_for_write()
std::unique_ptr< GreasePencilEditHints > grease_pencil_edit_hints_
std::optional< MutableSpan< float3 > > positions_for_write()
const greasepencil::Drawing * drawing_orig
std::optional< Span< float3 > > positions() const
ImplicitSharingPtrAndData positions_data
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_for_write_span(StringRef name)
SharedCache< std::optional< FillCache > > fill_cache
SharedCache< Vector< float3 > > curve_plane_normals_cache
SharedCache< Vector< float4x2 > > curve_texture_matrices
SharedCache< std::optional< TriangleCache > > triangle_cache
std::atomic< int > user_count
VArray< ColorGeometry4f > vertex_colors() const
Drawing & operator=(const Drawing &other)
Span< float3 > curve_plane_normals() const
std::optional< GroupedSpan< int > > fills() const
MutableSpan< float > opacities_for_write()
Span< float4x2 > texture_matrices() const
MutableSpan< float > radii_for_write()
bke::CurvesGeometry & strokes_for_write()
void tag_triangles_changed()
const bke::CurvesGeometry & strokes() const
VArray< float > radii() const
void tag_positions_changed()
void tag_texture_matrices_changed()
void tag_topology_changed()
VArray< ColorGeometry4f > fill_colors() const
VArray< float > opacities() const
MutableSpan< ColorGeometry4f > fill_colors_for_write()
MutableSpan< ColorGeometry4f > vertex_colors_for_write()
void set_texture_matrices(Span< float4x2 > matrices, const IndexMask &selection)
GroupedSpan< float3 > intersection_points() const
Vector< LayerGroup * > layer_group_cache_
Vector< Layer * > layer_cache_
Vector< TreeNode * > nodes_cache_
CacheMutex nodes_cache_mutex_
void move_node_top(TreeNode &node)
void prepare_for_dna_write()
void set_expanded(bool expanded)
TreeNode & add_node(TreeNode &node)
void move_node_down(TreeNode &node, int step=1)
void move_node_bottom(TreeNode &node)
bool unlink_node(TreeNode &link, bool keep_children=false)
const TreeNode & as_node() const
int64_t num_direct_nodes() const
int64_t num_nodes_total() const
Span< TreeNode * > nodes_for_write()
const TreeNode * find_node_by_name(StringRef name) const
Span< const Layer * > layers() const
void update_from_dna_read()
Span< Layer * > layers_for_write()
void add_node_before(TreeNode &node, TreeNode &link)
void add_node_after(TreeNode &node, TreeNode &link)
void move_node_up(TreeNode &node, int step=1)
void print_nodes(StringRef header) const
LayerGroup & operator=(const LayerGroup &other)
Span< const LayerGroup * > groups() const
Span< LayerGroup * > groups_for_write()
Span< const TreeNode * > nodes() const
SharedCache< Vector< FramesMapKeyT > > sorted_keys_cache_
Map< FramesMapKeyT, GreasePencilFrame > frames_
LayerTransformData trans_data_
Vector< LayerMask > masks_
SortedKeysIterator sorted_keys_iterator_at(int frame_number) const
StringRefNull parent_bone_name() const
int sorted_keys_index_at(int frame_number) const
float4x4 to_world_space(const Object &object) const
StringRefNull view_layer_name() const
void set_local_transform(const float4x4 &transform)
void set_view_layer_name(StringRef new_name)
void tag_frames_map_keys_changed()
bool remove_frame(FramesMapKeyT key)
const Map< FramesMapKeyT, GreasePencilFrame > & frames() const
float4x4 local_transform() const
GreasePencilFrame * add_frame(FramesMapKeyT key, int duration=0)
const TreeNode & as_node() const
const GreasePencilFrame * frame_at(const int frame_number) const
void tag_frames_map_changed()
bool has_drawing_at(const int frame_number) const
const int * SortedKeysIterator
int drawing_index_at(const int frame_number) const
int get_frame_duration_at(const int frame_number) const
std::optional< int > start_frame_at(int frame_number) const
float4x4 to_object_space(const Object &object) const
void update_from_dna_read()
Span< FramesMapKeyT > sorted_keys() const
float4x4 parent_inverse() const
void prepare_for_dna_write()
Map< FramesMapKeyT, GreasePencilFrame > & frames_for_write()
void set_parent_bone_name(StringRef new_name)
const TreeNode * parent_node() const
const LayerGroup & as_group() const
const Layer & as_layer() const
const LayerGroup * parent_group() const
constexpr bool contains(const T &value) const
constexpr bool is_empty() const
constexpr int64_t size() const
constexpr const char * data() const
void foreach_segment(Fn &&fn, Mode mode=exec_mode::serial) 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
IndexRange index_range() const
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
#define storage(slot, qualifiers)
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
MatBase< R, C > transpose(MatBase< C, R >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
float length(VecOp< float, D >) RET
float2x2 from_scale(float2 scale)
float length_squared(VecT a)
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void copy_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
void scatter(const Span< T > src, const Span< IndexT > indices, MutableSpan< T > dst, const Mode mode={})
bool contains(const VArray< bool > &varray, const IndexMask &indices_to_check, bool value)
bool prop_is_animated(const AnimData *adt, StringRefNull rna_path, int array_index)
void gather(GSpan src, Span< int > map, GMutableSpan dst)
void ensure_non_empty_layer_names(Main &bmain, GreasePencil &grease_pencil)
static void update_curve_plane_normal_cache(const Span< float3 > positions, const OffsetIndices< int > points_by_curve, const IndexMask &curve_mask, MutableSpan< float3 > normals)
static void update_triangle_and_offsets_changed(const Span< float3 > positions, const Span< float3 > normals, const OffsetIndices< int > dst_points_by_curve, const IndexMask &changed_curves, const std::optional< GroupedSpan< int > > fills, const GroupedSpan< int3 > src_triangles, const GroupedSpan< float3 > src_intersection_points, Vector< int3 > &r_triangles, MutableSpan< int > r_triangle_offsets, Vector< float3 > &r_intersection_points, MutableSpan< int > r_intersection_point_offsets)
constexpr StringRef ATTR_RADIUS
std::optional< FillCache > fill_cache_from_fill_ids(const VArray< int > &fill_ids)
static void ensure_fill_cache(const Drawing &drawing)
static float4x2 get_local_to_stroke_matrix(const Span< float3 > positions, const float3 normal)
constexpr StringRef ATTR_VERTEX_COLOR
static float3x2 get_stroke_to_texture_matrix(const float uv_rotation, const float2 uv_translation, const float2 uv_scale)
const AttributeAccessorFunctions & get_attribute_accessor_functions()
static void ensure_triangle_cache(const Drawing &drawing)
constexpr StringRef ATTR_OPACITY
constexpr StringRef ATTR_FILL_COLOR
static IndexMask curves_to_fills_mask(const IndexMask &curve_mask, const std::optional< GroupedSpan< int > > fills, const int num_curves, IndexMaskMemory &memory)
static float4x3 expand_4x2_mat(const float4x2 &strokemat)
static void update_triangle_and_offsets_cache(const Span< float3 > positions, const Span< float3 > normals, const OffsetIndices< int > points_by_curve, const IndexMask &fill_mask, const GroupedSpan< int > fills, Vector< int3 > &r_triangles, MutableSpan< int > r_triangle_offsets, Vector< float3 > &r_intersection_points, MutableSpan< int > r_intersection_point_offsets)
void copy_drawing_array(Span< const GreasePencilDrawingBase * > src_drawings, MutableSpan< GreasePencilDrawingBase * > dst_drawings)
GMutableSpan get_mutable_attribute(AttributeStorage &storage, const AttrDomain domain, const CPPType &cpp_type, const StringRef name, const int64_t domain_size, const void *custom_default_value)
auto attribute_filter_from_skip_ref(const Span< StringRef > skip)
void fill_attribute_range_default(MutableAttributeAccessor dst_attributes, AttrDomain domain, const AttributeFilter &attribute_filter, IndexRange range)
ID * asset_edit_id_find_local(Main &global_main, ID &id)
void attribute_storage_blend_write_prepare(AttributeStorage &data, bool use_5_0_compatibility, FunctionRef< int(AttrDomain)> get_domain_size, AttributeStorage::BlendWriteData &write_data)
ID * asset_edit_id_ensure_local(Main &global_main, ID &id)
const CPPType & attribute_type_to_cpp_type(AttrType type)
Bounds< T > merge(const Bounds< T > &a, const Bounds< T > &b)
std::optional< Bounds< T > > min_max_with_radii(const Span< T > values, const Span< RadiusT > radii)
std::optional< Bounds< T > > min_max(const std::optional< Bounds< T > > &a, const T &b)
int size(const AssetLibraryReference *library_reference)
constexpr ParallelGrainSize grain_size(int grain_size)
const MultiFunction & lookup(UString id)
BLI_INLINE Texture * wrap(MTLTexture *texture)
T length_squared(const VecBase< T, Size > &a)
MatBase< T, NumCol, NumRow > transpose(const MatBase< T, NumRow, NumCol > &mat)
T distance(const T &a, const T &b)
T length(const VecBase< T, Size > &a)
QuaternionBase< T > normalize_and_get_length(const QuaternionBase< T > &q, T &out_length)
EulerXYZBase< float > EulerXYZ
CartesianBasis invert(const CartesianBasis &basis)
T atan2(const T &y, const T &x)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
T max(const T &a, const T &b)
void to_loc_rot_scale_safe(const MatBase< T, 4, 4 > &mat, VecBase< T, 3 > &r_location, RotationT &r_rotation, VecBase< T, 3 > &r_scale)
T determinant(const MatBase< T, Size, Size > &mat)
void transform_points(const float4x4 &transform, MutableSpan< float3 > points, bool use_threading=true)
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)
constexpr StringRefNull radius
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
int sum_group_sizes(OffsetIndices< int > offsets, const IndexMask &mask)
OffsetIndices< int > gather_selected_offsets(OffsetIndices< int > src_offsets, const IndexMask &selection, int start_offset, MutableSpan< int > dst_offsets)
void parallel_for_each(Range &&range, const Function &function)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
auto isolate_task(const Function &function)
void BLO_read_struct_with_type_size(BlendDataReader *reader, T **ptr_p, FunctionRef< size_t(const T &data)> type_size_fn)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
GreasePencilLayerTreeNodeFlag
@ GP_LAYER_TREE_NODE_EXPANDED
@ GP_LAYER_TREE_NODE_USE_LIGHTS
@ GP_LAYER_TREE_NODE_HIDE_MASKS
static void delete_drawing(GreasePencilDrawingBase *drawing_base)
void BKE_defbase_blend_write(BlendWriter *writer, const ListBaseT< bDeformGroup > *defbase)
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
static void reorder_layer_data(GreasePencil &grease_pencil, const FunctionRef< void()> do_layer_order_changes)
bool BKE_grease_pencil_has_curve_with_type(const GreasePencil &grease_pencil, CurveType type)
void BKE_object_eval_grease_pencil(Depsgraph *depsgraph, Scene *scene, Object *object)
MINLINE void copy_v3_v3(float r[3], const float a[3])
static void write_layer(BlendWriter *writer, GreasePencilLayer *node)
GreasePencilLayerFramesMapStorageFlag
@ GP_LAYER_FRAMES_STORAGE_DIRTY
static Material * grease_pencil_object_material_ensure_from_brush_pinned(Main *bmain, Object *ob, Brush *brush)
short * BKE_object_material_len_p(Object *ob)
static void grease_pencil_replace_end_frames_after_read(GreasePencil &grease_pencil)
GreasePencil * BKE_grease_pencil_copy_for_eval(const GreasePencil *grease_pencil_src)
void BLO_read_pointer_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size)
static void grease_pencil_set_runtime_visibilities(ID &id_dst, GreasePencil &grease_pencil)
Material * BKE_gpencil_material_add(Main *bmain, const char *name)
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
void(*) BKE_grease_pencil_batch_cache_dirty_tag_cb(GreasePencil *grease_pencil, int mode)
BLI_INLINE void BLI_listbase_clear(ListBase *lb)
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
float mat4_to_scale(const float mat[4][4])
bool BKE_object_material_slot_add(Main *bmain, Object *ob, bool set_active=true)
Material * BKE_object_material_get(Object *ob, short act)
MatBase< double, 4, 2 > double4x2
void BKE_grease_pencil_copy_layer_group_parameters(const bke::greasepencil::LayerGroup &src, bke::greasepencil::LayerGroup &dst)
static void write_drawing_array(GreasePencil &grease_pencil, ResourceScope &scope, BlendWriter *writer)
void BKE_object_eval_assign_data(Object *object, ID *data, bool is_owned)
bool BKE_grease_pencil_drawing_attribute_required(const GreasePencilDrawing *, StringRef name)
MatBase< float, 2, 2 > float2x2
std::string RNA_path_name_to_infix(const StringRefNull string)
@ eModifierType_GreasePencilOffset
@ eModifierType_GreasePencilMultiply
@ eModifierType_GreasePencilArray
@ eModifierType_GreasePencilThickness
@ eModifierType_GreasePencilSubdiv
@ eModifierType_GreasePencilShrinkwrap
@ eModifierType_GreasePencilDash
@ eModifierType_GreasePencilBuild
@ eModifierType_GreasePencilWeightAngle
@ eModifierType_GreasePencilColor
@ eModifierType_GreasePencilLineart
@ eModifierType_GreasePencilHook
@ eModifierType_GreasePencilMirror
@ eModifierType_GreasePencilLattice
@ eModifierType_GreasePencilSmooth
@ eModifierType_GreasePencilTexture
@ eModifierType_GreasePencilArmature
@ eModifierType_GreasePencilTime
@ eModifierType_GreasePencilOpacity
@ eModifierType_GreasePencilOutline
@ eModifierType_GreasePencilTint
@ eModifierType_GreasePencilNoise
@ eModifierType_GreasePencilSimplify
@ eModifierType_GreasePencilLength
@ eModifierType_GreasePencilEnvelope
@ eModifierType_GreasePencilWeightProximity
VecBase< double, 2 > double2
void mul_v2_m3v3(float r[2], const float M[3][3], const float a[3])
static std::string unique_node_name(const GreasePencil &grease_pencil, const StringRef name)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static void read_layer_tree_group(BlendDataReader *reader, GreasePencilLayerTreeGroup *node, GreasePencilLayerTreeGroup *parent)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BKE_grease_pencil_point_coords_get(const GreasePencil &grease_pencil, MutableSpan< float3 > all_positions, MutableSpan< float > all_radii)
void BLI_polyfill_calc_arena(const float(*coords)[2], unsigned int coords_num, int coords_sign, unsigned int(*r_tris)[3], struct MemArena *arena)
void BKE_object_material_assign(Main *bmain, Object *ob, Material *ma, short act, int assign_type)
void BLO_read_data_invalidate(BlendDataReader *reader, const char *message)
static size_t drawing_struct_size(const GreasePencilDrawingType type)
static void write_layer_tree(GreasePencil &grease_pencil, BlendWriter *writer)
MatBase< float, 4, 4 > float4x4
const char * BKE_id_name(const ID &id)
Material * BKE_material_default_gpencil()
static void shrink_array(T **array, int *num, const int shrink_num)
MatBase< float, 2, 4 > float2x4
void BKE_id_blend_write(BlendWriter *writer, ID *id)
void BKE_grease_pencil_copy_layer_parameters(const bke::greasepencil::Layer &src, bke::greasepencil::Layer &dst)
GreasePencil * BKE_grease_pencil_add(Main *bmain, const char *name)
static size_t layer_tree_node_struct_size(const GreasePencilLayerTreeNodeType type)
static bool grease_pencil_initialize_drawing_user_counts(GreasePencil &grease_pencil)
bool BKE_grease_pencil_material_index_used(GreasePencil *grease_pencil, int index)
void BKE_animdata_fix_paths(ID &id, StringRef prefix, StringRef old_infix, StringRef new_infix, bool verify_paths, const DriverMap &driver_map)
void BKE_brush_tag_unsaved_changes(Brush *brush)
VecBase< float, 4 > float4
static void shrink_attribute_storage(bke::AttributeStorage &storage, const int index_to_remove, const int size)
MatBase< double, 3, 4 > double3x4
void BKE_grease_pencil_point_coords_apply_with_mat4(GreasePencil &grease_pencil, Span< float3 > all_positions, Span< float > all_radii, const float4x4 &mat)
static void read_drawing_array(GreasePencil &grease_pencil, BlendDataReader *reader)
size_t void BLI_uniquename_cb(FunctionRef< bool(StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
Material * BKE_grease_pencil_object_material_new(Main *bmain, Object *ob, const char *name, int *r_index)
static void grow_array(T **array, int *num, const int add_num)
void BKE_grease_pencil_eval_geometry(Depsgraph *depsgraph, GreasePencil *grease_pencil)
void BKE_grease_pencil_nomain_to_grease_pencil(GreasePencil *grease_pencil_src, GreasePencil *grease_pencil_dst)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BKE_grease_pencil_batch_cache_dirty_tag(GreasePencil *grease_pencil, int mode)
@ GREASE_PENCIL_AUTOLOCK_LAYERS
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
MatView< float, 4, 4, 4, 4, 0, 0, alignof(float)> float4x4_view
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
static void read_layer_tree(GreasePencil &grease_pencil, BlendDataReader *reader)
void BKE_grease_pencil_duplicate_drawing_array(const GreasePencil *grease_pencil_src, GreasePencil *grease_pencil_dst)
int BKE_grease_pencil_object_material_index_get_by_name(Object *ob, const char *name)
static void grease_pencil_foreach_id(ID *id, LibraryForeachIDData *data)
void BKE_object_free_derived_caches(Object *ob)
void CustomData_reset(CustomData *data)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void DEG_id_tag_update(ID *id, unsigned int flags)
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_WEIGHT_GREASE_PENCIL
BMesh const char void * data
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
void BKE_grease_pencil_brush_material_set(struct Brush *brush, struct Material *material)
static std::string unique_layer_group_name(const GreasePencil &grease_pencil, StringRef name)
void BKE_animdata_free(ID *id, bool do_id_user)
void BLI_memarena_clear(MemArena *ma) ATTR_NONNULL(1)
MatBase< float, 4, 2 > float4x2
static GreasePencilModifierInfluenceData * influence_data_from_modifier(ModifierData *md)
BLI_INLINE void IMB_colormanagement_srgb_to_scene_linear_v3(float scene_linear[3], const float srgb[3])
@ BKE_MAT_ASSIGN_USERPREF
void BKE_grease_pencil_material_index_remove(GreasePencil *grease_pencil, int index)
void(*) BKE_grease_pencil_batch_cache_free_cb(GreasePencil *grease_pencil)
void BKE_grease_pencil_copy_parameters(const GreasePencil &src, GreasePencil &dst)
static void grease_pencil_evaluate_layers(GreasePencil &grease_pencil)
ModifierData * BKE_modifiers_get_virtual_modifierlist(const Object *ob, VirtualModifierData *data)
Material * BKE_grease_pencil_object_material_ensure_by_name(Main *bmain, Object *ob, const char *name, int *r_index)
void BLO_read_struct_list_with_type_size(BlendDataReader *reader, size_t base_size, ListBase *list, FunctionRef< size_t(const void *data)> type_size_fn)
MatBase< float, 3, 2 > float3x2
static void grease_pencil_do_layer_adjustments(GreasePencil &grease_pencil)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void BKE_grease_pencil_vgroup_name_update(Object *ob, const char *old_name, const char *new_name)
void unit_m4(float m[4][4])
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
static void reorder_attribute_domain(bke::AttributeStorage &data, const bke::AttrDomain domain, const Span< int > new_by_old_map)
bool BKE_grease_pencil_references_cyclic_check(const GreasePencil *id_reference, const GreasePencil *grease_pencil)
int BKE_object_material_index_get(Object *ob, const Material *ma)
void BKE_modifiers_clear_errors(Object *ob)
MatBase< float, 4, 3 > float4x3
ATTR_WARN_UNUSED_RESULT const size_t num
MINLINE void zero_v3(float r[3])
MatBase< float, 3, 3 > float3x3
void BKE_id_free(Main *bmain, void *idv)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
bool BLO_read_array(BlendDataReader *reader, T **ptr_p, const SizeT array_size, const int elems=1)
PaletteColor * BKE_palette_color_add(Palette *palette)
bool BKE_object_is_in_editmode(const Object *ob)
void * BKE_id_new_nomain(short type, const char *name)
void * BLI_memarena_alloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
static void grease_pencil_foreach_working_space_color(ID *id, const IDTypeForeachColorFunctionCallback &fn)
static void read_layer(BlendDataReader *reader, GreasePencilLayer *node, GreasePencilLayerTreeGroup *parent)
static void write_layer_tree_group(BlendWriter *writer, GreasePencilLayerTreeGroup *node)
T * DEG_get_original(T *id)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BKE_grease_pencil_point_coords_apply(GreasePencil &grease_pencil, Span< float3 > all_positions, Span< float > all_radii)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
MINLINE void copy_v3_fl(float r[3], float f)
static VectorSet< StringRef > get_node_names(const GreasePencil &grease_pencil)
static void free_drawing_array(GreasePencil &grease_pencil)
MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3])
static void grease_pencil_init_data(ID *id)
short BKE_object_material_slot_find_index(Object *ob, Material *ma)
void hex_to_rgb(const char *hexcol, float *r_r, float *r_g, float *r_b)
static void update_active_node_from_node_to_remove(GreasePencil &grease_pencil, const bke::greasepencil::TreeNode &node)
Material * BKE_grease_pencil_object_material_from_brush_get(Object *ob, const Brush *brush)
void BKE_defgroup_copy_list(ListBaseT< bDeformGroup > *outbase, const ListBaseT< bDeformGroup > *inbase)
Material * BKE_grease_pencil_object_material_ensure_from_brush(Main *bmain, Object *ob, Brush *brush)
static void grease_pencil_evaluate_modifiers(Depsgraph *depsgraph, Scene *scene, Object *object, bke::GeometrySet &geometry_set)
bool BLI_remlink_safe(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void uninitialized_relocate_n(T *src, int64_t n, T *dst)
static void grease_pencil_blend_read_data(BlendDataReader *reader, ID *id)
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
static const char * ATTR_POSITION
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
VecBase< float, 3 > float3
GreasePencilLayerMaskFlag
static bool grease_pencil_references_cyclic_check_internal(const GreasePencil *id_reference, const GreasePencil *grease_pencil)
MatBase< double, 4, 3 > double4x3
bool DEG_is_evaluated(const T *id)
@ GP_BRUSH_MATERIAL_PINNED
void BKE_grease_pencil_material_remap(GreasePencil *grease_pencil, const uint *remap, int totcol)
static void grease_pencil_blend_write(BlendWriter *writer, ID *id, const void *id_address)
bool BKE_modifier_is_enabled(const Scene *scene, ModifierData *md, int required_mode)
static void grease_pencil_free_data(ID *id)
float DEG_get_ctime(const Depsgraph *graph)
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
GreasePencilLayerTreeNodeType
void * BKE_id_new(Main *bmain, short type, const char *name)
void BKE_paint_palette_set(Paint *paint, Palette *palette)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
GreasePencil * BKE_grease_pencil_new_nomain()
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
static void grease_pencil_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int)
int BKE_grease_pencil_stroke_point_count(const GreasePencil &grease_pencil)
void axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3])
Normal to x,y matrix.
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
GreasePencilDrawingBaseFlag
void uninitialized_move_n(T *src, int64_t n, T *dst)
Material * BKE_grease_pencil_object_material_alt_ensure_from_brush(Main *bmain, Object *ob, Brush *brush)
void void void bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) ATTR_NONNULL()
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
Palette * BKE_palette_add(Main *bmain, const char *name)
void CustomData_blend_read(BlendDataReader *reader, CustomData *data, int count)
void BKE_grease_pencil_batch_cache_free(GreasePencil *grease_pencil)
void BKE_grease_pencil_palette_ensure(Main *bmain, Scene *scene)
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
void mask(PageMask &srt, TileMaps &tilemaps, const uint3 global_id, const uint local_tile_index)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
void write_pointer_array(int64_t num, const void *data)
void generated_pointer_tag(const void *data)
void write_string(const char *data)
void write_struct_at_address_cast(const void *address, const void *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_id_struct(const void *id_address, const T *id, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct_list(const ListBaseT< T > *list, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct_array(const int64_t array_size, const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_int32_array(int64_t num, const int32_t *data)
void pad(const PaddingT &padding)
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilDrawingBaseFlag flag
GreasePencilDrawingType type
struct GreasePencil * id_reference
GreasePencilDrawingBase base
bke::greasepencil::DrawingRuntime * runtime
GreasePencilDrawingBase base
GreasePencilModifierInfluenceData influence
GreasePencilFrameFlag flag
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilLayerFramesMapStorageFlag flag
GreasePencilFrame * values
GreasePencilLayerMaskFlag flag
GreasePencilLayerTreeNode base
bke::greasepencil::LayerGroupRuntime * runtime
ListBaseT< GreasePencilLayerTreeNode > children
GreasePencilLayerTreeNodeType type
GreasePencilLayerTreeNodeFlag flag
struct GreasePencilLayerTreeNode * next
struct GreasePencilLayerTreeNode * prev
struct GreasePencilLayerTreeGroup * parent
GreasePencilLayerTreeNode base
ListBaseT< GreasePencilLayerMask > masks
GreasePencilLayerFramesMapStorage frames_storage
bke::greasepencil::LayerRuntime * runtime
GreasePencilLayerBlendMode blend_mode
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
GreasePencilModifierInfluenceData influence
ListBaseT< Palette > palettes
ListBaseT< Object > objects
const c_style_mat & ptr() const
static MatBase identity()
struct ModifierData * next
void(*) modify_geometry_set(ModifierData *md, const ModifierEvalContext *ctx, bke::GeometrySet *geometry_set)
struct ToolSettings * toolsettings
AttributeInitValue(const T &value)
Vector< blender::Attribute, 16 > & attributes
static ArrayData from_uninitialized(const CPPType &type, int64_t domain_size)
static ArrayData from_constructed(const CPPType &type, int64_t domain_size)
GeometryComponent & get_component_for_write(GeometryComponent::Type component_type)
static GeometrySet from_grease_pencil(GreasePencil *grease_pencil, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const GreasePencil * get_grease_pencil() const
bool has_grease_pencil() const
GreasePencil * get_grease_pencil_for_write()
void replace_grease_pencil(GreasePencil *grease_pencil, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
MutableVArraySpan< T > span
Vector< int > fill_offsets
Vector< float3 > intersection_points
Vector< int > intersection_point_offsets
Vector< int > triangle_offsets
OffsetIndices< int > offsets
IndexRange index_range() const