52#include "RNA_prototypes.hh"
62# include "curve_fit_nd.h"
67#define STROKE_SAMPLE_DIST_MIN_PX 1
68#define STROKE_SAMPLE_DIST_MAX_PX 3
71#define STROKE_CYCLIC_DIST_PX 8
157 if ((cdd->
project.surface_offset != 0.0f) && !cdd->
project.use_surface_offset_absolute &&
185 const float mval_fl[2],
186 float surface_offset,
188 float r_location_world[3],
189 float r_normal_world[3])
193 bool is_location_world_set =
false;
200 if (r_normal_world) {
203 is_location_world_set =
true;
208 if (depths && (
uint(mval_i[0]) < depths->
w) && (
uint(mval_i[1]) < depths->
h)) {
209 float depth_fl = 1.0f;
211 const double depth = double(depth_fl);
212 if ((depth > depths->
depth_range[0]) && (depth < depths->depth_range[1])) {
214 is_location_world_set =
true;
215 if (r_normal_world) {
219 if (surface_offset != 0.0f) {
220 const float offset = cdd->
project.use_surface_offset_absolute ? 1.0f : radius;
223 madd_v3_v3fl(r_location_world, normal, offset * surface_offset);
224 if (r_normal_world) {
234 if (is_location_world_set) {
240 return is_location_world_set;
245 const float mval_fl[2],
246 const float surface_offset,
248 const float location_fallback_depth[3],
249 float r_location_world[3],
250 float r_location_local[3],
251 float r_normal_world[3],
252 float r_normal_local[3])
255 cdd, mval_i, mval_fl, surface_offset, radius, r_location_world, r_normal_world);
256 if (is_depth_found ==
false) {
258 cdd->
vc.
v3d, cdd->
vc.
region, location_fallback_depth, mval_fl, r_location_world);
272 return is_depth_found;
279 const float location_fallback_depth[3],
282 const int mval_i[2] = {int(selem->
mval[0]), int(selem->
mval[1])};
289 location_fallback_depth,
361 if (stroke_len == 0) {
366 Curve *cu = id_cast<Curve *>(obedit->
data);
372 const float location_zero[3] = {0};
373 const float *location_prev = location_zero;
407 if (stroke_len > 1) {
434 for (
int i = 0; i < stroke_len; i++) {
443 for (
int i = 0; i < stroke_len; i++) {
456 MEM_delete(coord_array);
472 selem->
pressure =
event->tablet.pressure;
475 cdd, cdd->
prev.location_world_valid, selem);
477 if (is_depth_found) {
486 if (cdd->
sample.use_substeps && cdd->
prev.selem) {
492 for (
int i = 1; i < n; i++) {
497 cdd, cdd->
prev.location_world_valid, selem_new);
498 if (is_depth_found ==
false) {
499 if (is_depth_found_substep) {
507 selem = selem_new_last;
508 *selem_new_last = selem_target;
511 cdd->
prev.selem = selem;
529 cdd->
project.use_depth =
false;
532 float normal[3] = {0.0f};
539 float cross_a[3], cross_b[3];
557 if (cdd->
project.surface_offset != 0.0f) {
560 float location_no_offset[3];
566 cdd->
project.use_offset =
true;
618 cdd->
project.use_surface_offset_absolute = (cps->
flag &
675 float len_3d = 0.0f, len_2d = 0.0f;
687 scale_px = ((len_3d > 0.0f) && (len_2d > 0.0f)) ? (len_3d / len_2d) : 0.0f;
694 bool use_cyclic =
false;
698 const StrokeElem *selem, *selem_first, *selem_last;
734 selem_array[0] = selem_prev;
739 len_3d += len_3d_segment;
741 selem_array[i] = selem;
747 for (i = 0; i < stroke_len && lengths[i] < len_taper_max; i++) {
748 const float pressure_new = selem_array[i]->
pressure * (lengths[i] / len_taper_max);
755 const float len_taper_min = len_3d - len_taper_max;
756 for (i = stroke_len - 1; i > 0 && lengths[i] > len_taper_min; i--) {
757 const float pressure_new = selem_array[i]->
pressure *
758 ((len_3d - lengths[i]) / len_taper_max);
764 MEM_delete(selem_array);
780 Curve *cu = id_cast<Curve *>(obedit->
data);
785 const bool is_3d = (cu->
flag &
CU_3D) != 0;
800 Nurb *nu = MEM_new<Nurb>(__func__);
820 coords_indices.radius = use_pressure_radius ? dims++ : -1;
824 float *cubic_spline =
nullptr;
825 uint cubic_spline_len = 0;
843 if (coords_indices.radius != -1) {
844 co[coords_indices.radius] = selem->
pressure;
848 if ((co != coords) &&
UNLIKELY(memcmp(co, co - dims,
sizeof(
float) * dims) == 0)) {
855 uint *corners =
nullptr;
856 uint corners_len = 0;
860 const float corner_radius_min = error_threshold / 8;
861 const float corner_radius_max = error_threshold * 2;
862 const uint samples_max = 16;
864 curve_fit_corners_detect_fl(coords,
875 uint *corners_index =
nullptr;
876 uint corners_index_len = 0;
877 uint calc_flag = CURVE_FIT_CALC_HIGH_QUALITY;
879 if ((stroke_len > 2) && use_cyclic) {
880 calc_flag |= CURVE_FIT_CALC_CYCLIC;
885 result = curve_fit_cubic_to_points_refit_fl(coords,
900 result = curve_fit_cubic_to_points_fl(coords,
920 nu->
pntsu = cubic_spline_len;
923 float *co = cubic_spline;
925 for (
int j = 0; j < cubic_spline_len; j++, bezt++, co += (dims * 3)) {
926 const float *handle_l = co + (dims * 0);
927 const float *pt = co + (dims * 1);
928 const float *handle_r = co + (dims * 2);
934 if (coords_indices.radius != -1) {
938 bezt->
radius = radius_max;
947 uint i_start = 0, i_end = corners_index_len;
949 if ((corners_index_len >= 2) && (calc_flag & CURVE_FIT_CALC_CYCLIC) == 0) {
954 for (
uint i = i_start; i < i_end; i++) {
955 bezt = &nu->
bezt[corners_index[i]];
960 if (calc_flag & CURVE_FIT_CALC_CYCLIC) {
974 nu->
pntsu = stroke_len;
987 bezt->
vec[1][2] = 0.0f;
990 if (use_pressure_radius) {
994 bezt->
radius = radius_max;
1014 nu->
pntsu = stroke_len;
1036 if (use_pressure_radius) {
1097 Curve *cu = id_cast<Curve *>(obedit->
data);
1099 const float *plane_no =
nullptr;
1100 const float *plane_co =
nullptr;
1104 plane_co = obedit->object_to_world().location();
1105 plane_no = obedit->object_to_world().ptr()[2];
1106 cdd->
project.use_plane =
true;
1126 if (cdd->
depths !=
nullptr) {
1127 cdd->
project.use_depth =
true;
1131 cdd->
project.use_depth =
false;
1136 if (cdd->
project.use_depth ==
false) {
1139 cdd->
project.use_plane =
true;
1143 cdd->
sample.use_substeps =
true;
1153 if (is_modal ==
false) {
1214 ot->
name =
"Draw Curve";
1215 ot->
idname =
"CURVE_OT_draw";
1237 "Error distance threshold (in object units)",
#define BLT_I18NCONTEXT_AMOUNT
Object is a sort of wrapper for general info.
#define REGION_DRAW_POST_VIEW
#define GPU_batch_uniform_3fv(batch, name, val)
Read Blender memory allocation and freeing.
#define RNA_BEGIN(sptr, itemptr, propname)
#define ARRAY_SET_ITEMS(...)
#define STROKE_CYCLIC_DIST_PX
#define STROKE_SAMPLE_DIST_MIN_PX
#define STROKE_SAMPLE_DIST_MAX_PX
void free(Subdiv *subdiv)
void get_color_3fv(int colorid, float col[3])
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE void negate_v3_v3(float r[3], const float a[3])
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void GPU_matrix_scale_1f(float factor)
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void ED_view3d_depths_free(ViewDepths *depths)
static void stroke_elem_interp(StrokeElem *selem_out, const StrokeElem *selem_a, const StrokeElem *selem_b, float t)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
MINLINE void copy_v2_v2(float r[2], const float a[2])
GPUVertFormat * immVertexFormat()
static void curve_draw_stroke_from_operator(wmOperator *op)
void WM_cursor_modal_set(wmWindow *win, int val)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
bool ED_operator_editcurve(bContext *C)
void immBegin(GPUPrimType, uint vertex_len)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static bool stroke_elem_project_fallback_elem(const CurveDrawData *cdd, const float location_fallback_depth[3], StrokeElem *selem)
void GPU_line_smooth(bool enable)
static wmOperatorStatus curve_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
void view3d_operator_needs_gpu(const bContext *C)
PropertyRNA * RNA_def_collection_runtime(StructOrFunctionRNA *cont, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
static bool stroke_elem_project(const CurveDrawData *cdd, const int mval_i[2], const float mval_fl[2], float surface_offset, const float radius, float r_location_world[3], float r_normal_world[3])
static void curve_draw_stroke_to_operator_elem(wmOperator *op, const StrokeElem *selem)
bool ED_curve_deselect_all_multi(bContext *C)
const EnumPropertyItem rna_enum_curve_fit_method_items[]
static float stroke_elem_radius_from_pressure(const CurveDrawData *cdd, const float pressure)
void ED_region_tag_redraw(ARegion *region)
static void curve_draw_stroke_to_operator(wmOperator *op)
static void stroke_elem_pressure_set(const CurveDrawData *cdd, StrokeElem *selem, float pressure)
ViewLayer * CTX_data_view_layer(const bContext *C)
void GPU_matrix_mul(const float m[4][4])
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
void GPU_line_width(float width)
void BKE_curve_nurb_active_set(Curve *cu, const Nurb *nu)
static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
void CURVE_OT_draw(wmOperatorType *ot)
void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1)
static void curve_draw_exit(wmOperator *op)
@ CURVE_PAINT_PROJECT_SURFACE
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
@ CURVE_PAINT_SURFACE_PLANE_NORMAL_SURFACE
@ CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void BKE_nurb_handles_calc(Nurb *nu)
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
static void curve_draw_event_add(wmOperator *op, const wmEvent *event)
bool ED_view3d_win_to_3d_on_plane(const ARegion *region, const float plane[4], const float mval[2], bool do_clip, float r_out[3])
@ GPU_SHADER_3D_UNIFORM_COLOR
BLI_mempool * BLI_mempool_create(unsigned int esize, unsigned int elem_num, unsigned int pchunk, unsigned int flag) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
static void curve_draw_exec_precalc(wmOperator *op)
Object * CTX_data_edit_object(const bContext *C)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
static void curve_draw_stroke_3d(const bContext *, ARegion *, void *arg)
void WM_cursor_modal_restore(wmWindow *win)
@ CURVE_PAINT_FIT_METHOD_REFIT
@ CURVE_PAINT_FIT_METHOD_SPLIT
void GPU_batch_draw(gpu::Batch *batch)
void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) ATTR_NONNULL()
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
void * BLI_mempool_iterstep(BLI_mempool_iter *iter) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static wmOperatorStatus curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
ListBaseT< Nurb > * object_editcurve_get(Object *ob)
MINLINE void zero_v3(float r[3])
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void GPU_batch_program_set_builtin(gpu::Batch *batch, GPUBuiltinShader shader_id)
MINLINE float normalize_v3_v3(float r[3], const float a[3])
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void immVertex3fv(uint attr_id, const float data[3])
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
static void curve_draw_cancel(bContext *, wmOperator *op)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Main * CTX_data_main(const bContext *C)
static wmOperatorStatus curve_draw_exec(bContext *C, wmOperator *op)
void interp_v2_v2v2(float r[2], const float a[2], const float b[2], float t)
void ED_view3d_depth_override(Depsgraph *depsgraph, ARegion *region, View3D *v3d, Object *obact, eV3DDepthOverrideMode mode, bool use_overlay, ViewDepths **r_depths)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
bool ED_view3d_depth_read_cached(const ViewDepths *vd, const int mval[2], int margin, float *r_depth)
void * BLI_mempool_calloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
PropertyRNA * RNA_def_float_distance(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
MINLINE float square_f(float a)
@ V3D_DEPTH_SELECTED_ONLY
bool ED_view3d_depth_read_cached_normal(const ARegion *region, const ViewDepths *depths, const int mval[2], float r_normal[3])
MINLINE float interpf(float target, float origin, float t)
static float stroke_elem_radius(const CurveDrawData *cdd, const StrokeElem *selem)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Scene * CTX_data_scene(const bContext *C)
gpu::Batch * GPU_batch_preset_sphere(int lod) ATTR_WARN_UNUSED_RESULT
bool RNA_collection_is_empty(PointerRNA *ptr, const char *name)
void GPU_blend(GPUBlend blend)
bool ED_view3d_depth_unproject_v3(const ARegion *region, const int mval[2], double depth, float r_location_world[3])
void GPU_matrix_translate_3f(float x, float y, float z)
@ CURVE_PAINT_FLAG_DEPTH_ONLY_SELECTED
@ CURVE_PAINT_FLAG_CORNERS_DETECT
@ CURVE_PAINT_FLAG_PRESSURE_RADIUS
@ CURVE_PAINT_FLAG_DEPTH_STROKE_ENDPOINTS
@ CURVE_PAINT_FLAG_DEPTH_STROKE_OFFSET_ABS
int BLI_mempool_len(const BLI_mempool *pool) ATTR_NONNULL(1)
void BKE_nurb_knot_calc_u(Nurb *nu)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
static void curve_draw_stroke_from_operator_elem(wmOperator *op, PointerRNA *itemptr)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
void ED_view3d_win_to_3d(const View3D *v3d, const ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
static bool stroke_elem_project_fallback(const CurveDrawData *cdd, const int mval_i[2], const float mval_fl[2], const float surface_offset, const float radius, const float location_fallback_depth[3], float r_location_world[3], float r_location_local[3], float r_normal_world[3], float r_normal_local[3])
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
void GPU_depth_test(GPUDepthTest test)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
float RNA_float_get(PointerRNA *ptr, const char *name)
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void mul_transposed_mat3_m4_v3(const float M[4][4], float r[3])
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::ARegionRuntime * runtime
float location_world_valid[3]
bool use_surface_offset_absolute
struct blender::CurveDrawData::@156325255003027135357105342153325365161173160072 project
struct blender::CurveDrawData::@062375322331123247056003106277120211133242374153 sample
BLI_mempool * stroke_elem_pool
struct blender::CurveDrawData::@137145357117003102113331326375343242026266350061 radius
struct blender::CurveDrawData::@111115321263170113037071137311213323330021203231 prev
const c_style_mat & ptr() const
bke::ObjectRuntime * runtime
struct ToolSettings * toolsettings
struct ARegionType * type
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
void(*) cancel(bContext *C, wmOperator *op)
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
#define ISMOUSE_MOTION(event_type)