37 PassSimple edit_grease_pencil_ps_ = {
"GPencil Edit"};
44 bool show_handles_ =
false;
45 bool show_points_ =
false;
46 bool show_lines_ =
false;
47 bool show_grid_ =
false;
48 bool show_weight_ =
false;
49 bool show_material_name_ =
false;
50 bool skip_unselected_ =
false;
54 View view_edit_cage_ = {
"view_edit_cage"};
62 res.depth_planes.clear();
63 res.depth_planes_count = 0;
69 offset_data_ =
state.offset_data_get();
78 show_handles_ = show_points_ = show_lines_ = show_weight_ =
false;
80 switch (
state.object_mode) {
83 if (
state.active_tool && (
STREQ(
state.active_tool->idname,
"builtin.select_lasso") ||
84 STREQ(
state.active_tool->idname,
"builtin.select_circle") ||
85 STREQ(
state.active_tool->idname,
"builtin.select") ||
86 STREQ(
state.active_tool->idname,
"builtin.select_box")))
89 skip_unselected_ =
true;
102 show_lines_ = show_lines;
103 show_handles_ = show_points_;
108 show_lines_ = show_lines;
122 edit_handles_ =
nullptr;
123 edit_points_ =
nullptr;
124 edit_lines_ =
nullptr;
127 auto &pass = edit_grease_pencil_ps_;
133 state.clipping_plane_count);
135 const int handle_display = show_handles_ ? int(
state.overlay.handle_display) :
139 auto &sub = pass.sub(
"Lines");
140 sub.shader_set(res.shaders->curve_edit_line.get());
141 sub.bind_texture(
"weight_tx", &res.weight_ramp_tx);
142 sub.push_constant(
"use_weight", show_weight_);
143 sub.push_constant(
"use_grease_pencil",
true);
144 sub.push_constant(
"skip_unselected", skip_unselected_);
149 auto &sub = pass.sub(
"Handles");
151 sub.shader_set(res.shaders->curve_edit_handles.get());
152 sub.push_constant(
"show_curve_handles", handle_display !=
int(
CURVE_HANDLE_NONE));
153 sub.push_constant(
"curve_handle_display", handle_display);
154 edit_handles_ = ⊂
158 auto &sub = pass.sub(
"Points");
159 sub.shader_set(res.shaders->curve_edit_points.get());
160 sub.bind_texture(
"weight_tx", &res.weight_ramp_tx);
161 sub.push_constant(
"use_weight", show_weight_);
162 sub.push_constant(
"use_grease_pencil",
true);
163 sub.push_constant(
"do_stroke_endpoints", show_direction);
164 sub.push_constant(
"curve_handle_display", handle_display);
177 auto &pass = grid_ps_;
180 state.clipping_plane_count);
183 state.overlay.gpencil_grid_opacity);
184 pass.shader_set(res.shaders->grid_grease_pencil.get());
187 pass.push_constant(
"color", col_grid);
201 Object *ob = ob_ref.object;
207 edit_lines_->draw(geom, manager.unique_handle(ob_ref));
213 edit_handles_->draw_expand(geom,
GPU_PRIM_TRIS, 8, 1, manager.unique_handle(ob_ref));
217 gpu::Batch *geom = show_weight_ ?
221 edit_points_->draw(geom, manager.unique_handle(ob_ref));
225 if (show_material_name_) {
226 draw_material_names(ob_ref,
state, res);
257 if (ob_ref.object !=
state.object_active) {
263 const int grid_lines =
state.v3d->overlay.gpencil_grid_subdivisions;
264 const int line_count = grid_lines * 4 + 2;
270 const float4x4 grid_mat = grid_matrix_get(*ob_ref.object,
state.scene) * transform_mat;
272 grid_ps_.push_constant(
"axis_x", grid_mat.
x_axis());
273 grid_ps_.push_constant(
"axis_y", grid_mat.
y_axis());
274 grid_ps_.push_constant(
"origin", grid_mat.
location());
275 grid_ps_.push_constant(
"half_line_count", line_count / 2);
289 plane.
plane = GreasePencil::depth_plane_get(object_to_world, plane.
bounds, view);
300 manager.submit(grid_ps_, view);
309 view_edit_cage_.sync(view.viewmat(), offset_data_.winmat_polygon_offset(view.winmat(), 0.5f));
312 manager.submit(edit_grease_pencil_ps_, view_edit_cage_);
328 if (is_stroke_order_3d) {
337 plane.
handle = res_handle;
356 const std::optional<GroupedSpan<int3>> triangles = info.drawing.triangles();
369 *ob, info.drawing, memory);
370 const std::optional<GroupedSpan<int>> fills = info.drawing.fills();
372 const bool hide_onion = info.onion_id != 0;
380 for (
const int curve_i :
curves.curves_range()) {
381 const bool is_filled = fill_ids[curve_i] != 0;
382 const bool active_filled = is_filled && (fill_index_by_curves[curve_i] == -1);
386 const Span<int> fill = (*fills)[fill_index];
387 const int first_curve = fill.first();
388 for (
const int pos : fill.index_range()) {
389 const int curve_i = fill[pos];
390 fill_index_by_curves[curve_i] = fill_index;
391 first_curves[curve_i] = first_curve;
400 const int fill_index = fill_index_by_curves[curve_i];
402 const bool is_filled = fill_index != -1;
403 const bool active_filled = is_filled && (first_curves[curve_i] == curve_i);
405 const int material_index = stroke_materials[curve_i];
410 const int num_stroke_triangles = (active_filled && triangles.has_value()) ?
411 (*triangles)[fill_index].size() :
414 const IndexRange points = points_by_curve[curve_i];
415 const int num_stroke_vertices = (points.
size() +
416 int(cyclic[curve_i] && (points.
size() >= 3)));
418 if (hide_material || hide_onion) {
419 t_offset += num_stroke_triangles;
420 t_offset += num_stroke_vertices * 2;
426 const bool show_stroke = !hide_stroke[curve_i];
427 const bool show_fill = (num_stroke_triangles != 0) && active_filled;
430 const int v_first = t_offset * 3;
431 const int v_count = num_stroke_triangles * 3;
432 pass.
draw(geom, 1, v_count, v_first, res_handle, select_id.get());
436 t_offset += num_stroke_triangles;
440 const int v_first = t_offset * 3;
441 const int v_count = num_stroke_vertices * 2 * 3;
442 pass.
draw(geom, 1, v_count, v_first, res_handle, select_id.get());
444 t_offset += num_stroke_vertices * 2;
469 float4x4 bbox_to_world = object_to_world * bbox_to_object;
483 return float4(plane_direction, -
dot(plane_direction, bbox_center));
494 float4x4 mat =
object.object_to_world();
503 std::swap(mat[0], mat[2]);
506 std::swap(mat[1], mat[2]);
527 else if (active_layer) {
531 mat.
location() =
object.object_to_world().location();
536 void draw_material_names(
const ObjectRef &ob_ref,
const State &
state, Resources &res)
547 *
state.scene, grease_pencil,
false);
552 for (
const ed::greasepencil::DrawingInfo &info : drawings) {
553 const bke::greasepencil::Drawing &drawing = info.drawing;
555 const bke::CurvesGeometry strokes = drawing.
strokes();
560 ".selection", domain,
true);
563 const Span<float3> positions = strokes.
positions();
565 auto show_stroke_name = [&](
const int stroke_i) {
567 for (
const int point_i : points_by_curve[stroke_i]) {
568 if (selections[point_i]) {
574 return selections[stroke_i];
578 if (!show_stroke_name(stroke_i)) {
581 const int point_i = points_by_curve[stroke_i].first();
587 strlen(ma->id.name + 2),
Low-level operations for curves.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
constexpr IndexRange()=default
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
AttributeAccessor attributes() const
Span< float3 > positions() const
IndexRange curves_range() const
OffsetIndices< int > points_by_curve() const
const bke::CurvesGeometry & strokes() const
float4x4 to_world_space(const Object &object) const
SwapChain< ObjectMatricesBuf, 2 > matrix_buf
const float3 & location(int view_id=0) const
bool is_persp(int view_id=0) const
static View & default_get()
const float4x4 & viewinv(int view_id=0) const
const float3 & forward(int view_id=0) const
void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state=sampler_auto)
void push_constant(const char *name, const float &data)
void draw(gpu::Batch *batch, uint instance_len=-1, uint vertex_len=-1, uint vertex_first=-1, ResourceIDRange res_id={}, uint custom_id=0)
detail::PassBase< command::DrawCommandBuf > Sub
void sculpt_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state)
void draw_line(Framebuffer &framebuffer, Manager &manager, View &view) final
void draw_color_only(Framebuffer &framebuffer, Manager &manager, View &view) final
void begin_sync(Resources &res, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &, const State &state) final
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state) final
void paint_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state)
static void compute_depth_planes(Manager &manager, View &view, Resources &res, const State &)
static void draw_grease_pencil(Resources &res, PassMain::Sub &pass, const Scene *scene, Object *ob, ResourceHandleRange res_handle, select::ID select_id=select::SelectMap::select_invalid_id())
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
#define DRW_CLIPPING_UBO_SLOT
#define OVERLAY_GLOBALS_SLOT
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
MatBase< R, C > transpose(MatBase< C, R >) RET
float2x2 invert(float2x2 mat)
void fill_index_range(MutableSpan< T > span, const T start=0)
gpu::Batch * DRW_cache_grease_pencil_get(const Scene *scene, Object *ob)
detail::Pass< command::DrawCommandBuf > PassSimple
gpu::Batch * DRW_cache_grease_pencil_edit_handles_get(const Scene *scene, Object *ob)
gpu::VertBuf * DRW_cache_grease_pencil_position_buffer_get(const Scene *scene, Object *ob)
gpu::Batch * DRW_cache_grease_pencil_edit_lines_get(const Scene *scene, Object *ob)
gpu::Batch * DRW_cache_grease_pencil_weight_lines_get(const Scene *scene, Object *ob)
gpu::Batch * DRW_cache_grease_pencil_edit_points_get(const Scene *scene, Object *ob)
gpu::Batch * DRW_cache_grease_pencil_weight_points_get(const Scene *scene, Object *ob)
gpu::VertBuf * DRW_cache_grease_pencil_color_buffer_get(const Scene *scene, Object *ob)
Vector< DrawingInfo > retrieve_visible_drawings(const Scene &scene, const GreasePencil &grease_pencil, const bool do_onion_skinning)
IndexMask retrieve_visible_strokes(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
MatT from_loc_scale(const typename MatT::loc_type &location, const VecBase< typename MatT::base_type, ScaleDim > &scale)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void get_color_4ubv(int colorid, unsigned char col[4])
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
VecBase< uint8_t, 4 > uchar4
@ GP_SCULPT_MASK_SELECTMODE_POINT
@ GP_SCULPT_MASK_SELECTMODE_SEGMENT
@ DRW_TEXT_CACHE_GLOBALSPACE
@ DRW_TEXT_CACHE_STRING_PTR
MatBase< float, 4, 4 > float4x4
MaterialGPencilStyle * BKE_gpencil_material_settings(Object *ob, short act)
@ GREASE_PENCIL_STROKE_ORDER_3D
@ GP_VERTEX_MASK_SELECTMODE_POINT
@ GP_VERTEX_MASK_SELECTMODE_SEGMENT
T & DRW_object_get_data_for_drawing(const Object &object)
void DRW_text_cache_add(DRWTextStore *dt, const float co[3], const char *str, const int str_len, short xoffs, short yoffs, short flag, const uchar col[4], const bool shadow, const bool align_center)
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_WEIGHT_GREASE_PENCIL
@ OB_MODE_PAINT_GREASE_PENCIL
@ V3D_GP_SHOW_MATERIAL_NAME
@ V3D_GP_SHOW_STROKE_DIRECTION
@ DRW_STATE_DEPTH_LESS_EQUAL
MatBase< float, 3, 3 > float3x3
Material * BKE_object_material_get_eval(Object *ob, short act)
std::optional< Bounds< float3 > > BKE_object_boundbox_get(const Object *ob)
@ GP_PROJECT_DEPTH_STROKE
Point object_to_world(Point pt, float4x4 object_to_world)
eGP_Lockaxis_Types lock_axis
eMaterialGPencilStyle_Flag flag
struct ToolSettings * toolsettings
detail::SubPassVector< GreasePencilDepthPlane, 16 > depth_planes
int64_t depth_planes_count
ThemeColorID object_wire_theme_id(const ObjectRef &ob_ref, const State &state) const
static const ID select_invalid_id()