Blender V5.3
grease_pencil_io.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_bounds.hh"
6#include "BLI_color_types.hh"
7#include "BLI_listbase.hh"
8#include "BLI_math_matrix.hh"
9#include "BLI_math_vector.hh"
10#include "BLI_math_vector_c.hh"
11
12#include "BKE_attribute.hh"
13#include "BKE_camera.h"
14#include "BKE_context.hh"
15#include "BKE_crazyspace.hh"
16#include "BKE_curves.hh"
17#include "BKE_grease_pencil.hh"
18#include "BKE_layer.hh"
19#include "BKE_material.hh"
20#include "BKE_scene.hh"
21
23#include "DNA_material_types.h"
24#include "DNA_object_types.h"
25#include "DNA_scene_types.h"
26#include "DNA_view3d_types.h"
27
29
31
32#include "ED_grease_pencil.hh"
33#include "ED_object.hh"
34#include "ED_view3d.hh"
35
36#include "UI_view2d.hh"
37
39
40#include <fmt/format.h>
41#include <numeric>
42#include <optional>
43
49
50static float get_average(const Span<float> values)
51{
52 return values.is_empty() ? 0.0f :
53 std::accumulate(values.begin(), values.end(), 0.0f) / values.size();
54}
55
57{
58 if (values.is_empty()) {
59 return ColorGeometry4f(nullptr);
60 }
61 /* ColorGeometry4f does not support arithmetic directly. */
62 Span<float4> rgba_values = values.cast<float4>();
63 float4 avg_rgba = std::accumulate(rgba_values.begin(), rgba_values.end(), float4(0)) /
64 values.size();
65 return ColorGeometry4f(avg_rgba);
66}
67
69 const ARegion *region,
70 const View3D *v3d,
71 const RegionView3D *rv3d,
72 ReportList *reports)
73 : reports(reports),
74 C(C),
75 region(region),
76 v3d(v3d),
77 rv3d(rv3d),
78 scene(CTX_data_scene(&C)),
79 depsgraph(CTX_data_depsgraph_pointer(&C))
80{
81}
82
84 : context_(context), params_(params)
85{
86}
87
89{
90 const float3 cur_loc = context_.scene->cursor.location;
91 const float3 rot = float3(0.0f);
92 const ushort local_view_bits = (context_.v3d && context_.v3d->localvd) ?
94 ushort(0);
95
96 Object *ob_gpencil = ed::object::add_type(
97 &context_.C, OB_GREASE_PENCIL, name.c_str(), cur_loc, rot, false, local_view_bits);
98
99 return ob_gpencil;
100}
101
103{
104 const ColorGeometry4f default_stroke_color = {0.0f, 0.0f, 0.0f, 1.0f};
105 const ColorGeometry4f default_fill_color = {0.5f, 0.5f, 0.5f, 1.0f};
107 /* Stroke and Fill material. */
108 if (mat_index == -1) {
109 Main *bmain = CTX_data_main(&context_.C);
110 int new_idx;
112 bmain, object_, name.c_str(), &new_idx);
113 MaterialGPencilStyle *gp_style = mat_gp->gp_style;
114
115 copy_v4_v4(gp_style->stroke_rgba, default_stroke_color);
116 copy_v4_v4(gp_style->fill_rgba, default_fill_color);
117 mat_index = object_->totcol - 1;
118 }
119
120 return mat_index;
121}
122
124 : context_(context), params_(params)
125{
126}
127
128std::optional<Bounds<float2>> GreasePencilExporter::compute_screen_space_drawing_bounds(
129 const RegionView3D &rv3d,
130 Object &object,
131 const int layer_index,
132 const bke::greasepencil::Drawing &drawing)
133{
136
137 std::optional<Bounds<float2>> drawing_bounds = std::nullopt;
138
139 BLI_assert(object.type == OB_GREASE_PENCIL);
140 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object.data);
141
142 const Layer &layer = *grease_pencil.layers()[layer_index];
143 const float4x4 layer_to_world = layer.to_world_space(object);
144 const VArray<float> radii = drawing.radii();
145 const bke::CurvesGeometry &strokes = drawing.strokes();
146 const Span<float3> positions = strokes.positions();
147
148 IndexMaskMemory memory;
150 object, drawing, memory);
151
152 visible_strokes.foreach_index(
153 [&](const int curve_i) {
154 const IndexRange points = strokes.points_by_curve()[curve_i];
155
156 for (const int point_i : points) {
157 const float2 screen_co = this->project_to_screen(layer_to_world, positions[point_i]);
158
159 if (screen_co.x != V2D_IS_CLIPPED) {
160 const float3 world_pos = math::transform_point(layer_to_world, positions[point_i]);
161 const float pixels = radii[point_i] / ED_view3d_pixel_size(&rv3d, world_pos);
162
163 std::optional<Bounds<float2>> point_bounds = Bounds<float2>(screen_co);
164 point_bounds->pad(pixels);
165 drawing_bounds = bounds::merge(drawing_bounds, point_bounds);
166 }
167 }
168 },
170
171 return drawing_bounds;
172}
173
174std::optional<Bounds<float2>> GreasePencilExporter::compute_objects_bounds(
175 const RegionView3D &rv3d,
176 const Depsgraph &depsgraph,
177 const Span<GreasePencilExporter::ObjectInfo> objects,
178 const int frame_number)
179{
180 using bke::greasepencil::Drawing;
181 using bke::greasepencil::Layer;
182 using ObjectInfo = GreasePencilExporter::ObjectInfo;
183
184 constexpr float gap = 10.0f;
185
186 std::optional<Bounds<float2>> full_bounds = std::nullopt;
187
188 for (const ObjectInfo &info : objects) {
189 Object *object_eval = DEG_get_evaluated(&depsgraph, info.object);
190 const GreasePencil &grease_pencil_eval = *id_cast<GreasePencil *>(object_eval->data);
191
192 for (const int layer_index : grease_pencil_eval.layers().index_range()) {
193 const Layer &layer = *grease_pencil_eval.layers()[layer_index];
194 const Drawing *drawing = grease_pencil_eval.get_drawing_at(layer, frame_number);
195 if (drawing == nullptr) {
196 continue;
197 }
198
199 std::optional<Bounds<float2>> layer_bounds = this->compute_screen_space_drawing_bounds(
200 rv3d, *object_eval, layer_index, *drawing);
201
202 full_bounds = bounds::merge(full_bounds, layer_bounds);
203 }
204 }
205
206 /* Add small gap. */
207 if (full_bounds) {
208 full_bounds->pad(gap);
209 }
210
211 return full_bounds;
212}
213
215{
216 /* Ensure camera switch is applied. */
218
219 /* Calculate camera matrix. */
220 Object *cam_ob = scene.camera;
221 if (cam_ob == nullptr) {
222 /* XXX not sure when this could ever happen if v3d camera is not null,
223 * conditions are from GPv2 and not explained anywhere. */
224 return float4x4::identity();
225 }
226
227 /* Set up parameters. */
228 CameraParams params;
229 BKE_camera_params_init(&params);
230 BKE_camera_params_from_object(&params, cam_ob);
231
232 /* Compute matrix, view-plane, etc. */
234 &params, scene.r.xsch, scene.r.ysch, scene.r.xasp, scene.r.yasp);
236
237 float4x4 viewmat = math::invert(cam_ob->object_to_world());
238 return float4x4(params.winmat) * viewmat;
239}
240
241void GreasePencilExporter::prepare_render_params(Scene &scene, const int frame_number)
242{
243 const bool use_camera_view = (context_.rv3d->persp == RV3D_CAMOB) &&
244 (context_.v3d->camera != nullptr);
245
246 if (use_camera_view) {
247 /* Camera rectangle (in screen space). */
248 const rctf camera_rect = BKE_camera_view_border(&scene,
254 true,
255 false,
256 true);
257 screen_rect_ = {{camera_rect.xmin, camera_rect.ymin}, {camera_rect.xmax, camera_rect.ymax}};
259
260 /* Output resolution (when in camera view). */
261 int width, height;
262 BKE_render_resolution(&scene.r, false, &width, &height);
263 camera_rect_ = {{0.0f, 0.0f}, {float(width), float(height)}};
264 /* Compute factor that remaps screen_rect to final output resolution. */
265 BLI_assert(screen_rect_.size() != float2(0.0f));
267 }
268 else {
269 Vector<ObjectInfo> objects = this->retrieve_objects();
270 std::optional<Bounds<float2>> full_bounds = this->compute_objects_bounds(
271 *context_.rv3d, *context_.depsgraph, objects, frame_number);
272 screen_rect_ = full_bounds ? *full_bounds : Bounds<float2>(float2(0.0f));
273 camera_persmat_ = std::nullopt;
274 }
275}
276
278 const Material &material, const Span<ColorGeometry4f> vertex_colors)
279{
280 const MaterialGPencilStyle &gp_style = *material.gp_style;
281
282 const ColorGeometry4f material_color = ColorGeometry4f(gp_style.stroke_rgba);
283 const ColorGeometry4f avg_vertex_color = get_average(vertex_colors);
284 return math::interpolate(material_color, avg_vertex_color, avg_vertex_color.a);
285}
286
288{
289 return get_average(opacities);
290}
291
293 const RegionView3D &rv3d, const Span<float3> world_positions, const Span<float> radii)
294{
295 if (world_positions.is_empty()) {
296 return std::nullopt;
297 }
298 BLI_assert(world_positions.size() == radii.size());
299 Array<float> widths(world_positions.size());
300 threading::parallel_for(widths.index_range(), 4096, [&](const IndexRange range) {
301 for (const int index : range) {
302 const float3 &pos = world_positions[index];
303 const float radius = radii[index];
304 /* Compute the width in screen space by dividing by the pixel size at the point position. */
305 widths[index] = 2.0f * radius / ED_view3d_pixel_size(&rv3d, pos);
306 }
307 });
308 return get_average(widths);
309}
310
312{
313 using SelectMode = ExportParams::SelectMode;
314
315 const Main *bmain = CTX_data_main(&context_.C);
316 Scene &scene = *CTX_data_scene(&context_.C);
317 ViewLayer *view_layer = CTX_data_view_layer(&context_.C);
318 const float3 camera_z_axis = float3(context_.rv3d->viewinv[2]);
319
320 BKE_view_layer_synced_ensure(*bmain, &scene, view_layer);
321
322 Vector<ObjectInfo> objects;
323 auto add_object = [&](Object *object) {
324 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
325 return;
326 }
327
328 const float3 position = object->object_to_world().location();
329
330 /* Save z-depth from view to sort from back to front. */
331 const bool use_ortho_depth = camera_persmat_ || !context_.rv3d->is_persp;
332 const float depth = use_ortho_depth ? math::dot(camera_z_axis, position) :
334 objects.append({object, depth});
335 };
336
337 switch (params_.select_mode) {
338 case SelectMode::Active:
339 add_object(params_.object);
340 break;
341 case SelectMode::Selected:
342 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
343 if (base.flag & BASE_SELECTED) {
344 add_object(base.object);
345 }
346 }
347 break;
348 case SelectMode::Visible:
349 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
350 if ((base.flag & BASE_ENABLED_RENDER) != 0) {
351 add_object(base.object);
352 }
353 }
354 break;
355 }
356
357 /* Sort list of objects from point of view. */
358 std::ranges::sort(objects, [](const ObjectInfo &info1, const ObjectInfo &info2) {
359 return info1.depth < info2.depth;
360 });
361
362 return objects;
363}
364
365static float get_miter_limit_angle(const VArray<float> miter_angles,
366 const IndexRange points,
367 const bool is_cyclic)
368{
369 /* Because the SVG file format only supports `linejoin` type per stroke. We use priority
370 * system to decide what type to use.
371 * The order from lowest to highest is `Round`, `Bevel` then `Miter` */
372 float miter_limit_angle = GP_STROKE_MITER_ANGLE_ROUND;
373
374 /* Don't check the ends unless cyclical. */
375 for (const int point_i : points.drop_back(is_cyclic ? 0 : 1).drop_front(is_cyclic ? 0 : 1)) {
376 const float point_miter_angle = miter_angles[point_i];
377
378 /* Miter should take priority over Round. */
379 if (point_miter_angle <= GP_STROKE_MITER_ANGLE_ROUND) {
380 continue;
381 }
382
383 /* This point's limit should replace the round type. */
384 if (miter_limit_angle <= GP_STROKE_MITER_ANGLE_ROUND) {
385 miter_limit_angle = point_miter_angle;
386 }
387
388 /* Sharp corners (Lower angles) should take priority. */
389 miter_limit_angle = math::min(miter_limit_angle, point_miter_angle);
390 }
391
392 return miter_limit_angle;
393}
394
397 const bke::greasepencil::Drawing &drawing,
398 WriteShapeFn shape_fn)
399{
401
402 const float4x4 layer_to_world = layer.to_world_space(object);
403 const float4x4 viewmat = float4x4(context_.rv3d->viewmat);
404 const float4x4 layer_to_view = viewmat * layer_to_world;
405
406 const bke::CurvesGeometry &curves = drawing.strokes();
407 const bke::AttributeAccessor attributes = curves.attributes();
408 /* Curve attributes. */
409 const OffsetIndices points_by_curve = curves.points_by_curve();
410 const VArray<bool> cyclic = curves.cyclic();
411 const VArraySpan<int> material_indices = *attributes.lookup_or_default<int>(
412 "material_index", bke::AttrDomain::Curve, 0);
413 const VArraySpan<ColorGeometry4f> fill_colors = drawing.fill_colors();
414 const VArray<int8_t> start_caps = *attributes.lookup_or_default<int8_t>(
416 const VArray<int8_t> end_caps = *attributes.lookup_or_default<int8_t>(
417 "end_cap", bke::AttrDomain::Curve, 0);
418 const VArray<bool> hide_stroke = *attributes.lookup_or_default<bool>(
419 "hide_stroke", bke::AttrDomain::Curve, false);
420 const VArray<int> fill_ids = *attributes.lookup_or_default<int>(
421 "fill_id", bke::AttrDomain::Curve, 0);
422 const VArray<float> miter_angles = *attributes.lookup_or_default<float>(
424 /* Point attributes. */
425 const Span<float3> positions = curves.positions();
426 const std::optional<Span<float3>> positions_left = curves.handle_positions_left();
427 const std::optional<Span<float3>> positions_right = curves.handle_positions_right();
428 const VArray<int8_t> types = curves.curve_types();
429 const std::optional<GroupedSpan<int>> fills = drawing.fills();
430 const VArraySpan<float> radii = drawing.radii();
431 const VArraySpan<float> opacities = drawing.opacities();
432 const VArraySpan<ColorGeometry4f> vertex_colors = drawing.vertex_colors();
433
434 Array<float3> world_positions(positions.size());
435 math::transform_points(positions, layer_to_world, world_positions);
436
437 /* Fills are made of multiple curves. Keep track of which curve is part of which fill. */
438 Array<int> fill_index_by_curves(curves.curves_num(), -1);
439 /* Keep track of which curve is the first in a fill (e.g. the same index is used for each curve
440 * in the same fill). */
441 Array<int> first_curves(curves.curves_num());
443
444 int fill_index = 0;
445 for (const int i_curve : curves.curves_range()) {
446 const bool is_filled = fill_ids[i_curve] != 0;
447 const bool active_filled = is_filled && (fill_index_by_curves[i_curve] == -1);
448
449 /* Keep track of already rendered fills. */
450 if (active_filled) {
451 const Span<int> fill = (*fills)[fill_index];
452 const int first_curve = fill.first();
453 for (const int pos : fill.index_range()) {
454 const int i_curve = fill[pos];
455 fill_index_by_curves[i_curve] = fill_index;
456 first_curves[i_curve] = first_curve;
457 }
458
459 fill_index++;
460 }
461 }
462
463 /* Iterate over all the curves and render the strokes (if shown). For fills, make sure that they
464 * are rendered when the first curve of the fill is encountered and don't re-render the same fill
465 * multiple times. */
466 for (const int i_curve : curves.curves_range()) {
467 /* Will be `-1` if not a fill. */
468 const int fill_index = fill_index_by_curves[i_curve];
469
470 const bool is_filled = fill_index != -1;
471 const bool active_filled = is_filled && (first_curves[i_curve] == i_curve);
472
473 const int material_index = material_indices[i_curve];
474 const Material *material = [&]() {
475 const Material *material = BKE_object_material_get(const_cast<Object *>(&object),
476 material_index + 1);
477 if (!material) {
478 const Material *material_default = BKE_material_default_gpencil();
479 return material_default;
480 }
481 return material;
482 }();
483
484 BLI_assert(material->gp_style != nullptr);
485 if (material->gp_style->flag & GP_MATERIAL_HIDE) {
486 continue;
487 }
488
489 /* Fill. */
490 if (active_filled && params_.export_fill_materials) {
491 const Span<int> fill = (*fills)[fill_index];
492
493 const ColorGeometry4f material_fill_color = ColorGeometry4f(material->gp_style->fill_rgba);
494 const ColorGeometry4f fill_color = math::interpolate(
495 material_fill_color, fill_colors[i_curve], fill_colors[i_curve].a);
496 shape_fn(positions,
497 positions_left,
498 positions_right,
499 points_by_curve,
500 fill,
501 cyclic,
502 types,
503 fill_color,
504 layer.opacity,
505 std::nullopt,
506 std::nullopt,
507 false,
508 false);
509 }
510
511 /* Stroke. */
512 if (!hide_stroke[i_curve] && params_.export_stroke_materials) {
513 const IndexRange points = points_by_curve[i_curve];
514
516 *material, vertex_colors.slice(points));
517 const float stroke_opacity = compute_average_stroke_opacity(opacities.slice(points)) *
518 layer.opacity;
519 const std::optional<float> uniform_width = params_.use_uniform_width ?
521 *context_.rv3d,
522 world_positions.as_span().slice(points),
523 radii.slice(points)) :
524 std::nullopt;
525 if (uniform_width) {
526 const bool is_cyclic = cyclic[i_curve];
527 const GreasePencilStrokeCapType start_cap = GreasePencilStrokeCapType(start_caps[i_curve]);
528 const GreasePencilStrokeCapType end_cap = GreasePencilStrokeCapType(end_caps[i_curve]);
529 const bool round_cap = start_cap == GP_STROKE_CAP_TYPE_ROUND ||
530 end_cap == GP_STROKE_CAP_TYPE_ROUND;
531
532 const float miter_limit_angle = get_miter_limit_angle(miter_angles, points, is_cyclic);
533
534 shape_fn(positions,
535 positions_left,
536 positions_right,
537 points_by_curve,
538 {i_curve},
539 cyclic,
540 types,
541 stroke_color,
542 stroke_opacity,
543 uniform_width,
544 miter_limit_angle,
545 round_cap,
546 false);
547 }
548 else {
549 const IndexMask single_curve_mask = IndexRange::from_single(i_curve);
550
551 constexpr int corner_subdivisions = 3;
552 constexpr float outline_radius = 0.0f;
553 constexpr float outline_offset = 0.0f;
555 single_curve_mask,
556 layer_to_view,
557 corner_subdivisions,
558 outline_radius,
559 outline_offset,
560 material_index);
561
562 /* Sample the outline stroke. */
563 if (params_.outline_resample_length > 0.0f) {
564 VArray<float> resample_lengths = VArray<float>::from_single(
565 params_.outline_resample_length, outline.curves_num());
567 outline, outline.curves_range(), resample_lengths);
568 }
569
570 const OffsetIndices outline_points_by_curve = outline.points_by_curve();
571 const VArray<bool> outline_cyclic = outline.cyclic();
572 const Span<float3> outline_positions = outline.positions();
573 const std::optional<Span<float3>> outline_positions_left = outline.handle_positions_left();
574 const std::optional<Span<float3>> outline_positions_right =
575 outline.handle_positions_right();
576 const VArray<int8_t> outline_types = outline.curve_types();
577
578 Array<int> outline_shape(outline.curves_num());
580
581 /* Use stroke color to fill the outline. */
582 shape_fn(outline_positions,
583 outline_positions_left,
584 outline_positions_right,
585 outline_points_by_curve,
586 outline_shape.as_span(),
587 outline_cyclic,
588 outline_types,
589 stroke_color,
590 stroke_opacity,
591 std::nullopt,
592 std::nullopt,
593 false,
594 true);
595 }
596 }
597 }
598}
599
601 const float3 &position) const
602{
604
605 if (camera_persmat_) {
606 /* Use camera render space. */
607 const float2 cam_space = (float2(math::project_point(*camera_persmat_, world_pos)) + 1.0f) /
608 2.0f * float2(screen_rect_.size());
609 return cam_space * camera_fac_;
610 }
611
612 /* Use 3D view screen space. */
613 float2 screen_co;
614 if (ED_view3d_project_float_global(context_.region, world_pos, screen_co, V3D_PROJ_TEST_NOP) ==
616 {
617 if (!ELEM(V2D_IS_CLIPPED, screen_co.x, screen_co.y)) {
618 /* Apply offset and scale. */
619 return screen_co - screen_rect_.min;
620 }
621 }
622
623 return float2(V2D_IS_CLIPPED);
624}
625
627 const int frame_number) const
628{
629 for (const bke::greasepencil::Layer *layer : grease_pencil.layers()) {
630 if (layer->is_visible()) {
631 const GreasePencilFrame *frame = layer->frame_at(frame_number);
632 if ((frame != nullptr) && frame->is_selected()) {
633 return true;
634 }
635 }
636 }
637 return false;
638}
639
640std::string GreasePencilExporter::coord_to_svg_string(const float2 &screen_co) const
641{
642 /* SVG has inverted Y axis. */
643 if (camera_persmat_) {
644 return fmt::format("{},{}", screen_co.x, camera_rect_.size().y - screen_co.y);
645 }
646 return fmt::format("{},{}", screen_co.x, screen_rect_.size().y - screen_co.y);
647}
648
649} // namespace blender::io::grease_pencil
Camera data-block and utility functions.
Low-level operations for curves.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
#define GP_STROKE_MITER_ANGLE_ROUND
Object is a sort of wrapper for general info.
#define C
Definition RandGen.cpp:29
#define V2D_IS_CLIPPED
Definition UI_view2d.hh:46
#define ELEM(...)
Span< T > as_span() const
Definition BLI_array.hh:254
MutableSpan< T > as_mutable_span()
Definition BLI_array.hh:259
IndexRange index_range() const
Definition BLI_array.hh:371
ChannelStorageType a
constexpr IndexRange drop_back(int64_t n) const
static constexpr IndexRange from_single(const int64_t index)
constexpr IndexRange drop_front(int64_t n) const
Span< NewT > constexpr cast() const
Definition BLI_span.hh:422
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const T * end() const
Definition BLI_span.hh:228
constexpr const T * begin() const
Definition BLI_span.hh:224
constexpr bool is_empty() const
Definition BLI_span.hh:264
constexpr const char * c_str() const
static VArray from_single(T value, const int64_t size)
void append(const T &value)
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
VArray< int8_t > curve_types() const
std::optional< Span< float3 > > handle_positions_right() const
VArray< bool > cyclic() const
Span< float3 > positions() const
std::optional< Span< float3 > > handle_positions_left() const
IndexRange curves_range() const
OffsetIndices< int > points_by_curve() const
VArray< ColorGeometry4f > vertex_colors() const
std::optional< GroupedSpan< int > > fills() const
const bke::CurvesGeometry & strokes() const
VArray< ColorGeometry4f > fill_colors() const
constexpr Span slice(int64_t start, int64_t size) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
GreasePencilExporter(const IOContext &context, const ExportParams &params)
std::string coord_to_svg_string(const float2 &screen_co) const
static std::optional< float > try_get_uniform_point_width(const RegionView3D &rv3d, const Span< float3 > world_positions, const Span< float > radii)
void foreach_shape_in_layer(const Object &object, const bke::greasepencil::Layer &layer, const bke::greasepencil::Drawing &drawing, WriteShapeFn shape_fn)
static ColorGeometry4f compute_average_stroke_color(const Material &material, const Span< ColorGeometry4f > vertex_colors)
void prepare_render_params(Scene &scene, int frame_number)
bool is_selected_frame(const GreasePencil &grease_pencil, int frame_number) const
static float compute_average_stroke_opacity(const Span< float > opacities)
float2 project_to_screen(const float4x4 &transform, const float3 &position) const
FunctionRef< void(const Span< float3 > positions, const std::optional< Span< float3 > > positions_left, const std::optional< Span< float3 > > positions_right, const OffsetIndices< int > points_by_curve, const Span< int > shape, const VArray< bool > &cyclic, const VArray< int8_t > &types, const ColorGeometry4f &color, float opacity, std::optional< float > width, std::optional< float > miter_limit_angle, bool round_cap, bool is_outline)> WriteShapeFn
GreasePencilImporter(const IOContext &context, const ImportParams &params)
#define rot(x, k)
#define position
#define layer
void fill_index_range(MutableSpan< T > span, const T start=0)
Bounds< T > merge(const Bounds< T > &a, const Bounds< T > &b)
Definition BLI_bounds.hh:27
IndexMask retrieve_visible_strokes(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
bke::CurvesGeometry create_curves_outline(const bke::greasepencil::Drawing &drawing, const IndexMask &strokes, const float4x4 &transform, const int corner_subdivisions, const float outline_radius, const float outline_offset, const int material_index)
Object * add_type(bContext *C, int type, const char *name, const float loc[3], const float rot[3], bool enter_editmode, unsigned short local_view_bits) ATTR_NONNULL(1) ATTR_RETURNS_NONNULL
constexpr ParallelGrainSize grain_size(int grain_size)
CurvesGeometry resample_to_length(const CurvesGeometry &src_curves, const IndexMask &selection, const VArray< float > &sample_lengths, const ResampleCurvesOutputAttributeIDs &output_ids={}, bool keep_last_segment=false)
static float4x4 persmat_from_camera_object(Scene &scene)
static float get_miter_limit_angle(const VArray< float > miter_angles, const IndexRange points, const bool is_cyclic)
static float get_average(const Span< float > values)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T min(const T &a, const T &b)
CartesianBasis invert(const CartesianBasis &basis)
VectorT project_point(const MatT &mat, const VectorT &point)
T interpolate(const T &a, const T &b, const FactorT &t)
void transform_points(const float4x4 &transform, MutableSpan< float3 > points, bool use_threading=true)
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
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ V3D_PROJ_RET_OK
Definition ED_view3d.hh:273
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
float ED_view3d_pixel_size(const RegionView3D *rv3d, const float co[3])
Material * BKE_object_material_get(Object *ob, short act)
unsigned short ushort
Definition BKE_text.h:56
void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float aspx, float aspy)
MatBase< float, 4, 4 > float4x4
Material * BKE_material_default_gpencil()
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_render_resolution(const RenderData *r, const bool use_crop, int *r_width, int *r_height)
Definition scene.cc:3168
VecBase< float, 4 > float4
void BKE_camera_params_compute_matrix(CameraParams *params)
Material * BKE_grease_pencil_object_material_new(Main *bmain, Object *ob, const char *name, int *r_index)
VecBase< float, 2 > float2
int BKE_grease_pencil_object_material_index_get_by_name(Object *ob, const char *name)
BMesh const char void * data
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void BKE_camera_params_from_object(CameraParams *params, const struct Object *cam_ob)
rctf BKE_camera_view_border(const struct Scene *scene, const struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d, int winx, int winy, bool no_shift, bool no_zoom, bool no_roll)
eV3DProjStatus ED_view3d_project_float_global(const ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3])
Main * CTX_data_main(const bContext *C)
bool BKE_scene_camera_switch_update(Scene *scene)
Definition scene.cc:2480
@ V3D_PROJ_TEST_NOP
Definition ED_view3d.hh:295
Scene * CTX_data_scene(const bContext *C)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
MINLINE void copy_v4_v4(float r[4], const float a[4])
VecBase< float, 3 > float3
void BKE_camera_params_init(CameraParams *params)
ListBaseT< Base > * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
signed char int8_t
Definition BKE_text.h:76
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
Bounds()=default
eRegionView3D_Persp persp
struct Object * camera
View3DCursor cursor
struct RenderData r
struct Object * camera
struct View3D * localvd
unsigned short local_view_uid
IOContext(bContext &C, const ARegion *region, const View3D *v3d, const RegionView3D *rv3d, ReportList *reports)