37 PassSimple edit_grease_pencil_ps_ = {
"GPencil Edit"};
43 bool show_points_ =
false;
44 bool show_lines_ =
false;
45 bool show_grid_ =
false;
46 bool show_weight_ =
false;
47 bool show_material_name_ =
false;
51 View view_edit_cage_ = {
"view_edit_cage"};
59 res.depth_planes.clear();
60 res.depth_planes_count = 0;
66 offset_data_ =
state.offset_data_get();
75 show_points_ = show_lines_ = show_weight_ =
false;
77 switch (
state.object_mode) {
91 show_lines_ = show_lines;
96 show_lines_ = show_lines;
110 edit_points_ =
nullptr;
111 edit_lines_ =
nullptr;
114 auto &pass = edit_grease_pencil_ps_;
120 state.clipping_plane_count);
123 auto &sub = pass.sub(
"Points");
124 sub.shader_set(res.shaders->curve_edit_points.get());
125 sub.bind_texture(
"weight_tx", &res.weight_ramp_tx);
126 sub.push_constant(
"use_weight", show_weight_);
127 sub.push_constant(
"use_grease_pencil",
true);
128 sub.push_constant(
"do_stroke_endpoints", show_direction);
133 auto &sub = pass.sub(
"Lines");
134 sub.shader_set(res.shaders->curve_edit_line.get());
135 sub.bind_texture(
"weight_tx", &res.weight_ramp_tx);
136 sub.push_constant(
"use_weight", show_weight_);
137 sub.push_constant(
"use_grease_pencil",
true);
150 auto &pass = grid_ps_;
153 state.clipping_plane_count);
156 state.overlay.gpencil_grid_opacity);
157 pass.shader_set(res.shaders->grid_grease_pencil.get());
160 pass.push_constant(
"color", col_grid);
174 Object *ob = ob_ref.object;
177 gpu::Batch *geom = show_weight_ ?
181 edit_points_->draw(geom, manager.unique_handle(ob_ref));
188 edit_lines_->draw(geom, manager.unique_handle(ob_ref));
192 if (show_material_name_) {
193 draw_material_names(ob_ref,
state, res);
224 if (ob_ref.object !=
state.object_active) {
230 const int grid_lines =
state.v3d->overlay.gpencil_grid_subdivisions;
231 const int line_count = grid_lines * 4 + 2;
237 const float4x4 grid_mat = grid_matrix_get(*ob_ref.object,
state.scene) * transform_mat;
239 grid_ps_.push_constant(
"axis_x", grid_mat.
x_axis());
240 grid_ps_.push_constant(
"axis_y", grid_mat.
y_axis());
241 grid_ps_.push_constant(
"origin", grid_mat.
location());
242 grid_ps_.push_constant(
"half_line_count", line_count / 2);
256 plane.
plane = GreasePencil::depth_plane_get(object_to_world, plane.
bounds,
view);
267 manager.submit(grid_ps_,
view);
276 view_edit_cage_.sync(
view.viewmat(), offset_data_.winmat_polygon_offset(
view.winmat(), 0.5f));
279 manager.submit(edit_grease_pencil_ps_, view_edit_cage_);
295 if (is_stroke_order_3d) {
304 plane.
handle = res_handle;
330 *ob, info.drawing, memory);
333 const IndexRange points = points_by_curve[stroke_i];
334 const int material_index = stroke_materials[stroke_i];
337 const bool hide_onion = info.onion_id != 0;
340 const int num_stroke_triangles = (points.
size() >= 3) ? (points.
size() - 2) : 0;
341 const int num_stroke_vertices = (points.
size() +
342 int(cyclic[stroke_i] && (points.
size() >= 3)));
344 if (hide_material || hide_onion) {
345 t_offset += num_stroke_triangles;
346 t_offset += num_stroke_vertices * 2;
353 const bool show_fill = (points.
size() >= 3) &&
357 int v_first = t_offset * 3;
358 int v_count = num_stroke_triangles * 3;
359 pass.
draw(geom, 1, v_count, v_first, res_handle, select_id.get());
362 t_offset += num_stroke_triangles;
365 int v_first = t_offset * 3;
366 int v_count = num_stroke_vertices * 2 * 3;
367 pass.
draw(geom, 1, v_count, v_first, res_handle, select_id.get());
369 t_offset += num_stroke_vertices * 2;
394 float4x4 bbox_to_world = object_to_world * bbox_to_object;
397 float3 view_vector = (
view.is_persp()) ? (
view.location() - bbox_center) :
view.forward();
408 return float4(plane_direction, -
dot(plane_direction, bbox_center));
418 float4x4 mat =
object.object_to_world();
427 std::swap(mat[0], mat[2]);
430 std::swap(mat[1], mat[2]);
451 else if (active_layer) {
455 mat.
location() =
object.object_to_world().location();
460 void draw_material_names(
const ObjectRef &ob_ref,
const State &
state, Resources &res)
462 Object &
object = *ob_ref.object;
470 *
state.scene, grease_pencil,
false);
475 for (
const ed::greasepencil::DrawingInfo &info : drawings) {
476 const bke::greasepencil::Drawing &drawing = info.drawing;
478 const bke::CurvesGeometry strokes = drawing.
strokes();
483 ".selection", domain,
true);
486 const Span<float3> positions = strokes.
positions();
488 auto show_stroke_name = [&](
const int stroke_i) {
490 for (
const int point_i : points_by_curve[stroke_i]) {
491 if (selections[point_i]) {
497 return selections[stroke_i];
501 if (!show_stroke_name(stroke_i)) {
504 const int point_i = points_by_curve[stroke_i].first();
510 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
void GPU_framebuffer_bind(GPUFrameBuffer *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, eCustomDataType 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
static View & default_get()
const float4x4 & viewinv(int view_id=0) const
void bind_texture(const char *name, GPUTexture *texture, GPUSamplerState state=sampler_auto)
void draw(gpu::Batch *batch, uint instance_len=-1, uint vertex_len=-1, uint vertex_first=-1, ResourceHandleRange handle={0}, 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, ResourceHandle res_handle, select::ID select_id=select::SelectMap::select_invalid_id())
void foreach_index(Fn &&fn) const
Mesh & DRW_object_get_data_for_drawing(const Object &object)
#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::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
uint resource_index() const
detail::SubPassVector< GreasePencilDepthPlane, 16 > depth_planes
int64_t depth_planes_count
static const ID select_invalid_id()