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;
53 View view_edit_cage_ = {
"view_edit_cage"};
61 res.depth_planes.clear();
62 res.depth_planes_count = 0;
68 offset_data_ =
state.offset_data_get();
77 show_handles_ = show_points_ = show_lines_ = show_weight_ =
false;
79 switch (
state.object_mode) {
93 show_lines_ = show_lines;
94 show_handles_ = show_points_;
99 show_lines_ = show_lines;
113 edit_handles_ =
nullptr;
114 edit_points_ =
nullptr;
115 edit_lines_ =
nullptr;
118 auto &pass = edit_grease_pencil_ps_;
124 state.clipping_plane_count);
126 const int handle_display = show_handles_ ? int(
state.overlay.handle_display) :
130 auto &sub = pass.sub(
"Handles");
132 sub.shader_set(res.shaders->curve_edit_handles.get());
133 sub.push_constant(
"show_curve_handles", handle_display !=
int(
CURVE_HANDLE_NONE));
134 sub.push_constant(
"curve_handle_display", handle_display);
135 edit_handles_ = ⊂
139 auto &sub = pass.sub(
"Points");
140 sub.shader_set(res.shaders->curve_edit_points.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(
"do_stroke_endpoints", show_direction);
145 sub.push_constant(
"curve_handle_display", handle_display);
150 auto &sub = pass.sub(
"Lines");
151 sub.shader_set(res.shaders->curve_edit_line.get());
152 sub.bind_texture(
"weight_tx", &res.weight_ramp_tx);
153 sub.push_constant(
"use_weight", show_weight_);
154 sub.push_constant(
"use_grease_pencil",
true);
167 auto &pass = grid_ps_;
170 state.clipping_plane_count);
173 state.overlay.gpencil_grid_opacity);
174 pass.shader_set(res.shaders->grid_grease_pencil.get());
177 pass.push_constant(
"color", col_grid);
191 Object *ob = ob_ref.object;
196 edit_handles_->draw_expand(geom,
GPU_PRIM_TRIS, 8, 1, manager.unique_handle(ob_ref));
200 gpu::Batch *geom = show_weight_ ?
204 edit_points_->draw(geom, manager.unique_handle(ob_ref));
211 edit_lines_->draw(geom, manager.unique_handle(ob_ref));
215 if (show_material_name_) {
216 draw_material_names(ob_ref,
state, res);
247 if (ob_ref.object !=
state.object_active) {
253 const int grid_lines =
state.v3d->overlay.gpencil_grid_subdivisions;
254 const int line_count = grid_lines * 4 + 2;
260 const float4x4 grid_mat = grid_matrix_get(*ob_ref.object,
state.scene) * transform_mat;
262 grid_ps_.push_constant(
"axis_x", grid_mat.
x_axis());
263 grid_ps_.push_constant(
"axis_y", grid_mat.
y_axis());
264 grid_ps_.push_constant(
"origin", grid_mat.
location());
265 grid_ps_.push_constant(
"half_line_count", line_count / 2);
279 plane.
plane = GreasePencil::depth_plane_get(object_to_world, plane.
bounds,
view);
290 manager.submit(grid_ps_,
view);
299 view_edit_cage_.sync(
view.viewmat(), offset_data_.winmat_polygon_offset(
view.winmat(), 0.5f));
302 manager.submit(edit_grease_pencil_ps_, view_edit_cage_);
318 if (is_stroke_order_3d) {
327 plane.
handle = res_handle;
353 *ob, info.drawing, memory);
356 const IndexRange points = points_by_curve[stroke_i];
357 const int material_index = stroke_materials[stroke_i];
360 const bool hide_onion = info.onion_id != 0;
363 const int num_stroke_triangles = (points.
size() >= 3) ? (points.
size() - 2) : 0;
364 const int num_stroke_vertices = (points.
size() +
365 int(cyclic[stroke_i] && (points.
size() >= 3)));
367 if (hide_material || hide_onion) {
368 t_offset += num_stroke_triangles;
369 t_offset += num_stroke_vertices * 2;
376 const bool show_fill = (points.
size() >= 3) &&
380 int v_first = t_offset * 3;
381 int v_count = num_stroke_triangles * 3;
382 pass.
draw(geom, 1, v_count, v_first, res_handle, select_id.get());
385 t_offset += num_stroke_triangles;
388 int v_first = t_offset * 3;
389 int v_count = num_stroke_vertices * 2 * 3;
390 pass.
draw(geom, 1, v_count, v_first, res_handle, select_id.get());
392 t_offset += num_stroke_vertices * 2;
417 float4x4 bbox_to_world = object_to_world * bbox_to_object;
420 float3 view_vector = (
view.is_persp()) ? (
view.location() - bbox_center) :
view.forward();
431 return float4(plane_direction, -
dot(plane_direction, bbox_center));
441 float4x4 mat =
object.object_to_world();
450 std::swap(mat[0], mat[2]);
453 std::swap(mat[1], mat[2]);
474 else if (active_layer) {
478 mat.
location() =
object.object_to_world().location();
483 void draw_material_names(
const ObjectRef &ob_ref,
const State &
state, Resources &res)
485 Object &
object = *ob_ref.object;
493 *
state.scene, grease_pencil,
false);
498 for (
const ed::greasepencil::DrawingInfo &info : drawings) {
499 const bke::greasepencil::Drawing &drawing = info.drawing;
501 const bke::CurvesGeometry strokes = drawing.
strokes();
506 ".selection", domain,
true);
509 const Span<float3> positions = strokes.
positions();
511 auto show_stroke_name = [&](
const int stroke_i) {
513 for (
const int point_i : points_by_curve[stroke_i]) {
514 if (selections[point_i]) {
520 return selections[stroke_i];
524 if (!show_stroke_name(stroke_i)) {
527 const int point_i = points_by_curve[stroke_i].first();
533 strlen(ma->id.name + 2),
Low-level operations for curves.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
MaterialGPencilStyle * BKE_gpencil_material_settings(Object *ob, short act)
Material * BKE_object_material_get_eval(Object *ob, short act)
General operations, lookup, etc. for blender objects.
std::optional< blender::Bounds< blender::float3 > > BKE_object_boundbox_get(const Object *ob)
struct GreasePencil GreasePencil
@ GREASE_PENCIL_STROKE_ORDER_3D
@ GP_MATERIAL_STROKE_SHOW
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_PAINT_GREASE_PENCIL
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_WEIGHT_GREASE_PENCIL
@ GP_SCULPT_MASK_SELECTMODE_POINT
@ GP_SCULPT_MASK_SELECTMODE_SEGMENT
@ GP_VERTEX_MASK_SELECTMODE_SEGMENT
@ GP_VERTEX_MASK_SELECTMODE_POINT
@ GP_PROJECT_DEPTH_STROKE
@ V3D_GP_SHOW_MATERIAL_NAME
@ V3D_GP_SHOW_STROKE_DIRECTION
T & DRW_object_get_data_for_drawing(const Object &object)
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
void UI_GetThemeColor4ubv(int colorid, unsigned char col[4])
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
constexpr int64_t size() const
GAttributeReader lookup_or_default(StringRef attribute_id, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
OffsetIndices< int > points_by_curve() const
IndexRange curves_range() const
Span< float3 > positions() const
AttributeAccessor attributes() const
const bke::CurvesGeometry & strokes() const
float4x4 to_world_space(const Object &object) const
SwapChain< ObjectMatricesBuf, 2 > matrix_buf
uint resource_index() const
static View & default_get()
const float4x4 & viewinv(int view_id=0) const
void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state=sampler_auto)
void draw(gpu::Batch *batch, uint instance_len=-1, uint vertex_len=-1, uint vertex_first=-1, ResourceIndexRange res_index={}, uint custom_id=0)
void push_constant(const char *name, const float &data)
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) const
#define DRW_CLIPPING_UBO_SLOT
#define OVERLAY_GLOBALS_SLOT
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)
@ DRW_TEXT_CACHE_GLOBALSPACE
@ DRW_TEXT_CACHE_STRING_PTR
@ DRW_STATE_DEPTH_LESS_EQUAL
VecBase< float, D > normalize(VecOp< float, D >) RET
MatBase< R, C > transpose(MatBase< C, R >) RET
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)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
CartesianBasis invert(const CartesianBasis &basis)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
MatBase< float, 4, 4 > float4x4
blender::VecBase< uint8_t, 4 > uchar4
VecBase< float, 4 > float4
VecBase< float, 2 > float2
MatBase< float, 3, 3 > float3x3
VecBase< float, 3 > float3
struct ToolSettings * toolsettings
ResourceHandleRange handle
detail::SubPassVector< GreasePencilDepthPlane, 16 > depth_planes
int64_t depth_planes_count
static const ID select_invalid_id()