Blender  V2.93
Classes | Typedefs | Functions
gpencil_geom.c File Reference
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_ghash.h"
#include "BLI_hash.h"
#include "BLI_heap.h"
#include "BLI_math_vector.h"
#include "BLI_polyfill_2d.h"
#include "BLT_translation.h"
#include "DNA_gpencil_modifier_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "BKE_context.h"
#include "BKE_deform.h"
#include "BKE_gpencil.h"
#include "BKE_gpencil_curve.h"
#include "BKE_gpencil_geom.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_object.h"
#include "DEG_depsgraph_query.h"

Go to the source code of this file.

Classes

struct  GpEdge
 
struct  tGPDeleteIsland
 
struct  tSamplePoint
 
struct  tSampleEdge
 
struct  tPerimeterPoint
 

Typedefs

typedef struct GpEdge GpEdge
 
typedef struct tGPDeleteIsland tGPDeleteIsland
 
typedef struct tSamplePoint tSamplePoint
 
typedef struct tSampleEdge tSampleEdge
 
typedef struct tPerimeterPoint tPerimeterPoint
 

Functions

bool BKE_gpencil_stroke_minmax (const bGPDstroke *gps, const bool use_select, float r_min[3], float r_max[3])
 
bool BKE_gpencil_data_minmax (const bGPdata *gpd, float r_min[3], float r_max[3])
 
void BKE_gpencil_centroid_3d (bGPdata *gpd, float r_centroid[3])
 
void BKE_gpencil_stroke_boundingbox_calc (bGPDstroke *gps)
 
static void boundbox_gpencil (Object *ob)
 
BoundBoxBKE_gpencil_boundbox_get (Object *ob)
 
static int stroke_march_next_point (const bGPDstroke *gps, const int index_next_pt, const float *current, const float dist, float *result, float *pressure, float *strength, float *vert_color, float *ratio_result, int *index_from, int *index_to)
 
static int stroke_march_next_point_no_interp (const bGPDstroke *gps, const int index_next_pt, const float *current, const float dist, float *result)
 
static int stroke_march_count (const bGPDstroke *gps, const float dist)
 
static void stroke_defvert_create_nr_list (MDeformVert *dv_list, int count, ListBase *result, int *totweight)
 
static MDeformVertstroke_defvert_new_count (int count, int totweight, ListBase *def_nr_list)
 
static void stroke_interpolate_deform_weights (bGPDstroke *gps, int index_from, int index_to, float ratio, MDeformVert *vert)
 
bool BKE_gpencil_stroke_sample (bGPdata *gpd, bGPDstroke *gps, const float dist, const bool select)
 
bool BKE_gpencil_stroke_stretch (bGPDstroke *gps, const float dist, const float tip_length)
 
bool BKE_gpencil_stroke_trim_points (bGPDstroke *gps, const int index_from, const int index_to)
 
bool BKE_gpencil_stroke_split (bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gps, const int before_index, bGPDstroke **remaining_gps)
 
bool BKE_gpencil_stroke_shrink (bGPDstroke *gps, const float dist)
 
bool BKE_gpencil_stroke_smooth (bGPDstroke *gps, int i, float inf)
 
bool BKE_gpencil_stroke_smooth_strength (bGPDstroke *gps, int point_index, float influence)
 
bool BKE_gpencil_stroke_smooth_thickness (bGPDstroke *gps, int point_index, float influence)
 
bool BKE_gpencil_stroke_smooth_uv (bGPDstroke *gps, int point_index, float influence)
 
void BKE_gpencil_stroke_2d_flat (const bGPDspoint *points, int totpoints, float(*points2d)[2], int *r_direction)
 
void BKE_gpencil_stroke_2d_flat_ref (const bGPDspoint *ref_points, int ref_totpoints, const bGPDspoint *points, int totpoints, float(*points2d)[2], const float scale, int *r_direction)
 
static void gpencil_calc_stroke_fill_uv (const float(*points2d)[2], bGPDstroke *gps, const float minv[2], const float maxv[2], float(*r_uv)[2])
 
void BKE_gpencil_stroke_fill_triangulate (bGPDstroke *gps)
 
void BKE_gpencil_stroke_uv_update (bGPDstroke *gps)
 
void BKE_gpencil_stroke_geometry_update (bGPdata *gpd, bGPDstroke *gps)
 
float BKE_gpencil_stroke_length (const bGPDstroke *gps, bool use_3d)
 
float BKE_gpencil_stroke_segment_length (const struct bGPDstroke *gps, const int start_index, const int end_index, bool use_3d)
 
bool BKE_gpencil_stroke_trim (bGPdata *gpd, bGPDstroke *gps)
 
bool BKE_gpencil_stroke_close (bGPDstroke *gps)
 
void BKE_gpencil_dissolve_points (bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gps, const short tag)
 
void BKE_gpencil_stroke_normal (const bGPDstroke *gps, float r_normal[3])
 
void BKE_gpencil_stroke_simplify_adaptive (bGPdata *gpd, bGPDstroke *gps, float epsilon)
 
void BKE_gpencil_stroke_simplify_fixed (bGPdata *gpd, bGPDstroke *gps)
 
void BKE_gpencil_stroke_subdivide (bGPdata *gpd, bGPDstroke *gps, int level, int type)
 
void BKE_gpencil_stroke_merge_distance (bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gps, const float threshold, const bool use_unselected)
 
static int gpencil_next_edge (GpEdge *gp_edges, int totedges, GpEdge *gped_init, const float threshold, const bool reverse)
 
static int gpencil_walk_edge (GHash *v_table, GpEdge *gp_edges, int totedges, uint *stroke_array, int init_idx, const float angle, const bool reverse)
 
static void gpencil_generate_edgeloops (Object *ob, bGPdata *gpd, bGPDframe *gpf_stroke, int stroke_mat_index, const float angle, const int thickness, const float offset, const float matrix[4][4], const bool use_seams)
 
static Materialgpencil_add_material (Main *bmain, Object *ob_gp, const char *name, const float color[4], const bool use_stroke, const bool use_fill, int *r_idx)
 
static int gpencil_material_find_index_by_name (Object *ob, const char *name)
 
static void make_element_name (const char *obname, const char *name, const int maxlen, char *r_name)
 
bool BKE_gpencil_convert_mesh (Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob_gp, Object *ob_mesh, const float angle, const int thickness, const float offset, const float matrix[4][4], const int frame_offset, const bool use_seams, const bool use_faces)
 
void BKE_gpencil_transform (bGPdata *gpd, const float mat[4][4])
 
int BKE_gpencil_stroke_point_count (bGPdata *gpd)
 
void BKE_gpencil_point_coords_get (bGPdata *gpd, GPencilPointCoordinates *elem_data)
 
void BKE_gpencil_point_coords_apply (bGPdata *gpd, const GPencilPointCoordinates *elem_data)
 
void BKE_gpencil_point_coords_apply_with_mat4 (bGPdata *gpd, const GPencilPointCoordinates *elem_data, const float mat[4][4])
 
void BKE_gpencil_stroke_set_random_color (bGPDstroke *gps)
 
void BKE_gpencil_stroke_flip (bGPDstroke *gps)
 
static void gpencil_stroke_join_islands (bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gps_first, bGPDstroke *gps_last)
 
bGPDstrokeBKE_gpencil_stroke_delete_tagged_points (bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gps, bGPDstroke *next_stroke, int tag_flags, const bool select, const bool flat_cap, const int limit)
 
void BKE_gpencil_curve_delete_tagged_points (bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gps, bGPDstroke *next_stroke, bGPDcurve *gpc, int tag_flags)
 
static void gpencil_stroke_copy_point (bGPDstroke *gps, MDeformVert *dvert, bGPDspoint *point, const float delta[3], float pressure, float strength, float deltatime)
 
void BKE_gpencil_stroke_join (bGPDstroke *gps_a, bGPDstroke *gps_b, const bool leave_gaps, const bool fit_thickness)
 
void BKE_gpencil_stroke_copy_to_keyframes (bGPdata *gpd, bGPDlayer *gpl, bGPDframe *gpf, bGPDstroke *gps, const bool tail)
 
static tSamplePointnew_sample_point_from_gp_point (const bGPDspoint *pt, const MDeformVert *dvert)
 
static tSampleEdgenew_sample_edge_from_sample_points (tSamplePoint *from, tSamplePoint *to)
 
void BKE_gpencil_stroke_uniform_subdivide (bGPdata *gpd, bGPDstroke *gps, const uint32_t target_number, const bool select)
 
void BKE_gpencil_stroke_to_view_space (RegionView3D *rv3d, bGPDstroke *gps, const float diff_mat[4][4])
 
void BKE_gpencil_stroke_from_view_space (RegionView3D *rv3d, bGPDstroke *gps, const float diff_mat[4][4])
 
static tPerimeterPointnew_perimeter_point (const float pt[3])
 
static int generate_arc_from_point_to_point (ListBase *list, tPerimeterPoint *from, tPerimeterPoint *to, float center_pt[3], int subdivisions, bool clockwise)
 
static int generate_semi_circle_from_point_to_point (ListBase *list, tPerimeterPoint *from, tPerimeterPoint *to, int subdivisions)
 
static int generate_perimeter_cap (const float point[4], const float other_point[4], float radius, ListBase *list, int subdivisions, short cap_type)
 
static ListBasegpencil_stroke_perimeter_ex (const bGPdata *gpd, const bGPDlayer *gpl, const bGPDstroke *gps, int subdivisions, int *r_num_perimeter_points)
 
bGPDstrokeBKE_gpencil_stroke_perimeter_from_view (struct RegionView3D *rv3d, bGPdata *gpd, const bGPDlayer *gpl, bGPDstroke *gps, const int subdivisions, const float diff_mat[4][4])
 
float BKE_gpencil_stroke_average_pressure_get (bGPDstroke *gps)
 
bool BKE_gpencil_stroke_is_pressure_constant (bGPDstroke *gps)
 

Typedef Documentation

◆ GpEdge

typedef struct GpEdge GpEdge

◆ tGPDeleteIsland

◆ tPerimeterPoint

◆ tSampleEdge

typedef struct tSampleEdge tSampleEdge

◆ tSamplePoint

typedef struct tSamplePoint tSamplePoint

Function Documentation

◆ BKE_gpencil_boundbox_get()

BoundBox* BKE_gpencil_boundbox_get ( Object ob)

Get grease pencil object bounding box.

Parameters
obGrease pencil object
Returns
Bounding box

Definition at line 182 of file gpencil_geom.c.

References Object_Runtime::bb, boundbox_gpencil(), copy_v3_v3(), Object::data, DEG_get_original_id(), ELEM, bGPdata::flag, GP_DATA_CACHE_IS_DIRTY, Object::id, if(), MEM_callocN, NULL, Object::runtime, and BoundBox::vec.

Referenced by BKE_object_boundbox_get(), and BKE_object_minmax().

◆ BKE_gpencil_centroid_3d()

void BKE_gpencil_centroid_3d ( bGPdata gpd,
float  r_centroid[3] 
)

Compute center of bounding box.

Parameters
gpdGrease pencil data-block
r_centroidLocation of the center

Definition at line 130 of file gpencil_geom.c.

References add_v3_v3v3(), BKE_gpencil_data_minmax(), max, min, and mul_v3_v3fl().

Referenced by object_origin_set_exec(), and blender::io::gpencil::GpencilImporterSVG::read().

◆ BKE_gpencil_convert_mesh()

bool BKE_gpencil_convert_mesh ( Main bmain,
Depsgraph depsgraph,
Scene scene,
Object ob_gp,
Object ob_mesh,
const float  angle,
const int  thickness,
const float  offset,
const float  matrix[4][4],
const int  frame_offset,
const bool  use_seams,
const bool  use_faces 
)

Convert a mesh object to grease pencil stroke.

Parameters
bmainMain thread pointer.
depsgraphOriginal depsgraph.
sceneOriginal scene.
ob_gpGrease pencil object to add strokes.
ob_meshMesh to convert.
angleLimit angle to consider a edgeloop ends.
thicknessThickness of the strokes.
offsetOffset along the normals.
matrixTransformation matrix.
frame_offsetDestination frame number offset.
use_seamsOnly export seam edges.
use_facesExport faces as filled strokes.

Definition at line 2391 of file gpencil_geom.c.

References angle(), BKE_gpencil_layer_addnew(), BKE_gpencil_layer_frame_get(), BKE_gpencil_layer_named_get(), BKE_gpencil_material_find_index_by_name_prefix(), BKE_gpencil_stroke_add(), BKE_gpencil_stroke_geometry_update(), BKE_gpencil_stroke_subdivide(), BKE_object_get_evaluated_mesh(), BKE_object_material_get(), CFRA, copy_v3_v3(), copy_v4_v4(), Object::data, DEG_get_evaluated_object(), DEG_id_tag_update(), depsgraph, ELEM, bGPDstroke::flag, GP_GETFRAME_ADD_NEW, GP_STROKE_CYCLIC, GP_SUBDIV_SIMPLE, gpencil_add_material(), gpencil_generate_edgeloops(), gpencil_material_find_index_by_name(), bGPdata::id, Material::id, Object::id, ID_RECALC_COPY_ON_WRITE, ID_RECALC_GEOMETRY, MPoly::loopstart, make_element_name(), MPoly::mat_nr, Mesh::mloop, Mesh::mpoly, mul_m4_v3(), Mesh::mvert, ID::name, NULL, OB_GPENCIL, bGPDstroke::points, bGPDspoint::pressure, Material::r, bGPDspoint::strength, MPoly::totloop, Mesh::totpoly, Mesh::totvert, Object::type, MLoop::v, and bGPDspoint::x.

Referenced by object_convert_exec().

◆ BKE_gpencil_curve_delete_tagged_points()

void BKE_gpencil_curve_delete_tagged_points ( bGPdata gpd,
bGPDframe gpf,
bGPDstroke gps,
bGPDstroke next_stroke,
bGPDcurve gpc,
int  tag_flags 
)

◆ BKE_gpencil_data_minmax()

bool BKE_gpencil_data_minmax ( const bGPdata gpd,
float  r_min[3],
float  r_max[3] 
)

Get min/max bounds of all strokes in grease pencil data-block.

Parameters
gpdGrease pencil datablock
r_minResult minimum coordinates
r_maxResult maximum coordinates
Returns
True if it was possible to calculate

Definition at line 102 of file gpencil_geom.c.

References BKE_gpencil_stroke_minmax(), INIT_MINMAX, bGPdata::layers, LISTBASE_FOREACH, NULL, and bGPDframe::strokes.

Referenced by BKE_gpencil_centroid_3d(), and boundbox_gpencil().

◆ BKE_gpencil_dissolve_points()

void BKE_gpencil_dissolve_points ( bGPdata gpd,
bGPDframe gpf,
bGPDstroke gps,
const short  tag 
)

Dissolve points in stroke.

Parameters
gpdGrease pencil data-block
gpfGrease pencil frame
gpsGrease pencil stroke
tagType of tag for point

Definition at line 1590 of file gpencil_geom.c.

References BKE_gpencil_free_stroke_weights(), BKE_gpencil_stroke_geometry_update(), BLI_freelinkN(), bGPDstroke::dvert, MDeformVert::dw, bGPDspoint::flag, MEM_callocN, MEM_dupallocN, MEM_freeN, NULL, bGPDstroke::points, bGPDframe::strokes, bGPDstroke::totpoints, and bGPDstroke::triangles.

Referenced by BKE_gpencil_stroke_merge_distance().

◆ BKE_gpencil_point_coords_apply()

void BKE_gpencil_point_coords_apply ( bGPdata gpd,
const GPencilPointCoordinates elem_data 
)

◆ BKE_gpencil_point_coords_apply_with_mat4()

void BKE_gpencil_point_coords_apply_with_mat4 ( bGPdata gpd,
const GPencilPointCoordinates elem_data,
const float  mat[4][4] 
)

◆ BKE_gpencil_point_coords_get()

void BKE_gpencil_point_coords_get ( bGPdata gpd,
GPencilPointCoordinates elem_data 
)

◆ BKE_gpencil_stroke_2d_flat()

void BKE_gpencil_stroke_2d_flat ( const bGPDspoint points,
int  totpoints,
float(*)  points2d[2],
int *  r_direction 
)

Get points of stroke always flat to view not affected by camera view or view position.

Parameters
pointsArray of grease pencil points (3D)
totpointsTotal of points
points2dResult array of 2D points
r_directionReturn Concave (-1), Convex (1), or Auto-detect (0)

Definition at line 1013 of file gpencil_geom.c.

References BLI_assert, copy_v3_v3(), cross(), cross_v3_v3v3(), dot_v3v3(), mul_v3_v3fl(), normal, normalize_v3(), sub_v3_v3v3(), and bGPDspoint::x.

Referenced by BKE_gpencil_stroke_fill_triangulate().

◆ BKE_gpencil_stroke_2d_flat_ref()

void BKE_gpencil_stroke_2d_flat_ref ( const bGPDspoint ref_points,
int  ref_totpoints,
const bGPDspoint points,
int  totpoints,
float(*)  points2d[2],
const float  scale,
int *  r_direction 
)

Get points of stroke always flat to view not affected by camera view or view position using another stroke as reference.

Parameters
ref_pointsArray of reference points (3D)
ref_totpointsTotal reference points
pointsArray of points to flat (3D)
totpointsTotal points
points2dResult array of 2D points
scaleScale factor
r_directionReturn Concave (-1), Convex (1), or Auto-detect (0)

Definition at line 1098 of file gpencil_geom.c.

References add_v3_v3v3(), BLI_assert, copy_v3_v3(), cross_v3_v3v3(), dot_v3v3(), mul_v3_fl(), mul_v3_v3fl(), normal, normalize_v3(), sub_v3_v3v3(), v1, vn, and bGPDspoint::x.

◆ BKE_gpencil_stroke_average_pressure_get()

float BKE_gpencil_stroke_average_pressure_get ( bGPDstroke gps)

Get average pressure.

Definition at line 4005 of file gpencil_geom.c.

References float(), bGPDstroke::points, bGPDspoint::pressure, and bGPDstroke::totpoints.

◆ BKE_gpencil_stroke_boundingbox_calc()

void BKE_gpencil_stroke_boundingbox_calc ( bGPDstroke gps)

Compute stroke bounding box.

Parameters
gpsGrease pencil Stroke

Definition at line 144 of file gpencil_geom.c.

References BKE_gpencil_stroke_minmax(), bGPDstroke::boundbox_max, bGPDstroke::boundbox_min, and INIT_MINMAX.

Referenced by BKE_gpencil_stroke_geometry_update(), and ED_gpencil_stroke_check_collision().

◆ BKE_gpencil_stroke_close()

bool BKE_gpencil_stroke_close ( bGPDstroke gps)

◆ BKE_gpencil_stroke_copy_to_keyframes()

void BKE_gpencil_stroke_copy_to_keyframes ( bGPdata gpd,
bGPDlayer gpl,
bGPDframe gpf,
bGPDstroke gps,
const bool  tail 
)

◆ BKE_gpencil_stroke_delete_tagged_points()

bGPDstroke* BKE_gpencil_stroke_delete_tagged_points ( bGPdata gpd,
bGPDframe gpf,
bGPDstroke gps,
bGPDstroke next_stroke,
int  tag_flags,
const bool  select,
const bool  flat_cap,
const int  limit 
)

◆ BKE_gpencil_stroke_fill_triangulate()

void BKE_gpencil_stroke_fill_triangulate ( bGPDstroke gps)

◆ BKE_gpencil_stroke_flip()

void BKE_gpencil_stroke_flip ( bGPDstroke gps)

◆ BKE_gpencil_stroke_from_view_space()

void BKE_gpencil_stroke_from_view_space ( RegionView3D rv3d,
bGPDstroke gps,
const float  diff_mat[4][4] 
)

Stroke from view space Transforms a stroke from view space back to world space. Inverse of BKE_gpencil_stroke_to_view_space Note: also takes care of parent space transform

Definition at line 3512 of file gpencil_geom.c.

References invert_m4_m4(), mul_m4_v3(), mul_v3_m4v3(), bGPDstroke::points, bGPDstroke::totpoints, RegionView3D::viewinv, and bGPDspoint::x.

Referenced by BKE_gpencil_stroke_perimeter_from_view().

◆ BKE_gpencil_stroke_geometry_update()

void BKE_gpencil_stroke_geometry_update ( bGPdata gpd,
bGPDstroke gps 
)

Recalc all internal geometry data for the stroke

Parameters
gpdGrease pencil data-block
gpsGrease pencil stroke

Definition at line 1307 of file gpencil_geom.c.

References BKE_gpencil_stroke_boundingbox_calc(), BKE_gpencil_stroke_fill_triangulate(), BKE_gpencil_stroke_update_geometry_from_editcurve(), BKE_gpencil_stroke_uv_update(), bGPdata::curve_edit_resolution, bGPDstroke::editcurve, bGPDcurve::flag, bGPDstroke::flag, bGPdata::flag, GP_CURVE_NEEDS_STROKE_UPDATE, GP_DATA_CURVE_ADAPTIVE_RESOLUTION, GP_STROKE_NEEDS_CURVE_UPDATE, GPENCIL_CURVE_EDIT_SESSIONS_ON, MEM_SAFE_FREE, NULL, bGPDstroke::tot_triangles, bGPDstroke::totpoints, and bGPDstroke::triangles.

Referenced by BKE_gpencil_convert_mesh(), BKE_gpencil_curve_delete_tagged_points(), BKE_gpencil_dissolve_points(), BKE_gpencil_from_image(), BKE_gpencil_point_coords_apply(), BKE_gpencil_point_coords_apply_with_mat4(), BKE_gpencil_stroke_delete_tagged_points(), BKE_gpencil_stroke_merge_distance(), BKE_gpencil_stroke_perimeter_from_view(), BKE_gpencil_stroke_sample(), BKE_gpencil_stroke_simplify_adaptive(), BKE_gpencil_stroke_simplify_fixed(), BKE_gpencil_stroke_split(), BKE_gpencil_stroke_subdivide(), BKE_gpencil_stroke_trim(), BKE_gpencil_stroke_uniform_subdivide(), BKE_gpencil_strokes_selected_update_editcurve(), BKE_gpencil_transform(), blo_do_versions_280(), deformStroke(), duplicateStroke(), ED_gpencil_create_monkey(), ED_gpencil_create_stroke(), ED_gpencil_select_curve_toggle_all(), ED_gpencil_trace_data_to_strokes(), gpencil_add_move_points(), gpencil_convert_spline(), gpencil_curve_extrude_points(), gpencil_dissolve_selected_curve_points(), gpencil_dissolve_selected_stroke_points(), gpencil_duplicate_exec(), gpencil_duplicate_points(), gpencil_editcurve_set_handle_type_exec(), gpencil_editmode_toggle_exec(), gpencil_generate_edgeloops(), gpencil_generic_stroke_select(), gpencil_insert_point(), gpencil_interpolate_modal(), gpencil_interpolate_seq_exec(), gpencil_interpolate_set_points(), gpencil_interpolate_update_strokes(), gpencil_primitive_interaction_end(), gpencil_primitive_update_strokes(), gpencil_recalc_geometry_exec(), gpencil_reset_transform_fill_exec(), gpencil_sculpt_brush_do_frame(), gpencil_select_exec(), gpencil_snap_to_grid(), gpencil_stroke_cyclical_set_exec(), gpencil_stroke_do_circle_sel(), gpencil_stroke_enter_editcurve_mode_exec(), gpencil_stroke_from_buffer(), gpencil_stroke_join_exec(), gpencil_stroke_join_islands(), gpencil_stroke_merge_exec(), gpencil_stroke_newfrombuffer(), gpencil_stroke_subdivide_exec(), gpencil_strokes_copy_exec(), gpencil_strokes_paste_exec(), gpencil_strokes_reproject_exec(), gpencil_subdivide_stroke(), gpencil_update_geometry(), gpencil_uv_transform_calc(), lineart_gpencil_generate(), object_origin_set_exec(), recalcData_gpencil_strokes(), and reduce_stroke_points().

◆ BKE_gpencil_stroke_is_pressure_constant()

bool BKE_gpencil_stroke_is_pressure_constant ( bGPDstroke gps)

Check if the thickness of the stroke is constant.

Definition at line 4022 of file gpencil_geom.c.

References bGPDstroke::points, bGPDspoint::pressure, and bGPDstroke::totpoints.

◆ BKE_gpencil_stroke_join()

void BKE_gpencil_stroke_join ( bGPDstroke gps_a,
bGPDstroke gps_b,
const bool  leave_gaps,
const bool  fit_thickness 
)

◆ BKE_gpencil_stroke_length()

float BKE_gpencil_stroke_length ( const bGPDstroke gps,
bool  use_3d 
)

Calculate grease pencil stroke length.

Parameters
gpsGrease pencil stroke
use_3dSet to true to use 3D points
Returns
Length of the stroke

Definition at line 1350 of file gpencil_geom.c.

References len_v2v2(), len_v3v3(), bGPDstroke::points, bGPDstroke::totpoints, and bGPDspoint::x.

◆ BKE_gpencil_stroke_merge_distance()

void BKE_gpencil_stroke_merge_distance ( bGPdata gpd,
bGPDframe gpf,
bGPDstroke gps,
const float  threshold,
const bool  use_unselected 
)

Reduce a series of points when the distance is below a threshold. Special case for first and last points (both are keeped) for other points, the merge point always is at first point.

Parameters
gpdGrease pencil data-block
gpfGrease Pencil frame
gpsGrease Pencil stroke
thresholdDistance between points
use_unselectedSet to true to analyze all stroke and not only selected points

Definition at line 2017 of file gpencil_geom.c.

References BKE_gpencil_dissolve_points(), BKE_gpencil_stroke_geometry_update(), bGPDspoint::flag, GP_SPOINT_SELECT, GP_SPOINT_TAG, len_squared_v3v3(), NULL, bGPDstroke::points, bGPDstroke::totpoints, and bGPDspoint::x.

Referenced by deformStroke(), ED_gpencil_stroke_join_and_trim(), and gpencil_merge_by_distance_exec().

◆ BKE_gpencil_stroke_minmax()

bool BKE_gpencil_stroke_minmax ( const bGPDstroke gps,
const bool  use_select,
float  r_min[3],
float  r_max[3] 
)

Get min/max coordinate bounds for single stroke.

Parameters
gpsGrease pencil stroke
use_selectInclude only selected points
r_minResult minimum coordinates
r_maxResult maximum coordinates
Returns
True if it was possible to calculate

Definition at line 73 of file gpencil_geom.c.

References ELEM, bGPDspoint::flag, GP_SPOINT_SELECT, minmax_v3v3_v3(), NULL, bGPDstroke::points, and bGPDspoint::x.

Referenced by BKE_gpencil_data_minmax(), and BKE_gpencil_stroke_boundingbox_calc().

◆ BKE_gpencil_stroke_normal()

void BKE_gpencil_stroke_normal ( const bGPDstroke gps,
float  r_normal[3] 
)

Calculate stroke normals.

Parameters
gpsGrease pencil stroke
r_normalReturn Normal vector normalized

Definition at line 1675 of file gpencil_geom.c.

References cross_v3_v3v3(), normalize_v3(), bGPDstroke::points, sub_v3_v3v3(), bGPDstroke::totpoints, bGPDspoint::x, and zero_v3().

◆ BKE_gpencil_stroke_perimeter_from_view()

bGPDstroke* BKE_gpencil_stroke_perimeter_from_view ( struct RegionView3D rv3d,
bGPdata gpd,
const bGPDlayer gpl,
bGPDstroke gps,
const int  subdivisions,
const float  diff_mat[4][4] 
)

◆ BKE_gpencil_stroke_point_count()

int BKE_gpencil_stroke_point_count ( bGPdata gpd)

◆ BKE_gpencil_stroke_sample()

bool BKE_gpencil_stroke_sample ( bGPdata gpd,
bGPDstroke gps,
const float  dist,
const bool  select 
)

◆ BKE_gpencil_stroke_segment_length()

float BKE_gpencil_stroke_segment_length ( const struct bGPDstroke gps,
const int  start_index,
const int  end_index,
bool  use_3d 
)

Calculate grease pencil stroke length between points.

Definition at line 1371 of file gpencil_geom.c.

References len_v2v2(), len_v3v3(), MAX2, MIN2, bGPDstroke::points, bGPDstroke::totpoints, and bGPDspoint::x.

Referenced by ED_gpencil_stroke_join_and_trim().

◆ BKE_gpencil_stroke_set_random_color()

void BKE_gpencil_stroke_set_random_color ( bGPDstroke gps)

Set a random color to stroke using vertex color.

Parameters
gpsStroke

Definition at line 2680 of file gpencil_geom.c.

References BLI_assert, BLI_hash_int_01(), BLI_hash_int_2d(), copy_v4_v4(), bGPDstroke::points, bGPDstroke::totpoints, bGPDspoint::vert_color, bGPDspoint::x, bGPDspoint::y, and bGPDspoint::z.

Referenced by lineart_gpencil_generate().

◆ BKE_gpencil_stroke_shrink()

bool BKE_gpencil_stroke_shrink ( bGPDstroke gps,
const float  dist 
)

Shrink the stroke by length.

Parameters
gpsStroke to shrink
distdelta length

Definition at line 706 of file gpencil_geom.c.

References BKE_gpencil_stroke_trim_points(), copy_v3_v3(), interp_v3_v3v3(), len_v3v3(), bGPDstroke::points, bGPDstroke::totpoints, x, and bGPDspoint::x.

◆ BKE_gpencil_stroke_simplify_adaptive()

void BKE_gpencil_stroke_simplify_adaptive ( bGPdata gpd,
bGPDstroke gps,
float  epsilon 
)

Reduce a series of points to a simplified version, but maintains the general shape of the series

Ramer - Douglas - Peucker algorithm by http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm

Parameters
gpdGrease pencil data-block
gpsGrease pencil stroke
epsilonEpsilon value to define precision of the algorithm

Definition at line 1717 of file gpencil_geom.c.

References BKE_gpencil_free_point_weights(), BKE_gpencil_stroke_geometry_update(), closest_to_line_segment_v3(), bGPDstroke::dvert, MDeformVert::dw, blender::robust_pred::epsilon, len_v3v3(), max_i(), MEM_callocN, MEM_dupallocN, MEM_SAFE_FREE, NULL, bGPDstroke::points, bGPDstroke::totpoints, and x.

Referenced by deformStroke(), gpencil_stroke_newfrombuffer(), and gpencil_stroke_simplify_exec().

◆ BKE_gpencil_stroke_simplify_fixed()

void BKE_gpencil_stroke_simplify_fixed ( bGPdata gpd,
bGPDstroke gps 
)

Simplify alternate vertex of stroke except extremes.

Parameters
gpdGrease pencil data-block
gpsGrease pencil stroke

Definition at line 1826 of file gpencil_geom.c.

References BKE_gpencil_free_point_weights(), BKE_gpencil_stroke_geometry_update(), bGPDstroke::dvert, MDeformVert::dw, MEM_dupallocN, MEM_recallocN, MEM_SAFE_FREE, NULL, bGPDstroke::points, and bGPDstroke::totpoints.

Referenced by deformStroke(), gpencil_stroke_from_buffer(), and gpencil_stroke_simplify_fixed_exec().

◆ BKE_gpencil_stroke_smooth()

bool BKE_gpencil_stroke_smooth ( bGPDstroke gps,
int  i,
float  inf 
)

Apply smooth position to stroke point.

Parameters
gpsStroke to smooth
iPoint index
infAmount of smoothing to apply

Definition at line 778 of file gpencil_geom.c.

References CLAMP_MAX, CLAMP_MIN, ELEM, float(), interp_v3_v3v3(), madd_v3_v3fl(), bGPDstroke::points, steps, bGPDstroke::totpoints, and bGPDspoint::x.

Referenced by deformStroke(), gpencil_brush_smooth_apply(), gpencil_interpolate_smooth_stroke(), gpencil_smooth_stroke(), gpencil_stroke_from_buffer(), and gpencil_stroke_newfrombuffer().

◆ BKE_gpencil_stroke_smooth_strength()

bool BKE_gpencil_stroke_smooth_strength ( bGPDstroke gps,
int  point_index,
float  influence 
)

Apply smooth strength to stroke point.

Parameters
gpsStroke to smooth
point_indexPoint index
influenceAmount of smoothing to apply

Definition at line 841 of file gpencil_geom.c.

References CLAMP_MAX, CLAMP_MIN, ELEM, float(), interpf(), bGPDstroke::points, steps, bGPDspoint::strength, and bGPDstroke::totpoints.

Referenced by deformStroke(), gpencil_brush_smooth_apply(), gpencil_interpolate_smooth_stroke(), gpencil_smooth_stroke(), and gpencil_stroke_newfrombuffer().

◆ BKE_gpencil_stroke_smooth_thickness()

bool BKE_gpencil_stroke_smooth_thickness ( bGPDstroke gps,
int  point_index,
float  influence 
)

Apply smooth for thickness to stroke point (use pressure).

Parameters
gpsStroke to smooth
point_indexPoint index
influenceAmount of smoothing to apply

Definition at line 905 of file gpencil_geom.c.

References CLAMP_MAX, CLAMP_MIN, ELEM, float(), interpf(), bGPDstroke::points, bGPDspoint::pressure, steps, and bGPDstroke::totpoints.

Referenced by deformStroke(), gpencil_brush_smooth_apply(), and gpencil_smooth_stroke().

◆ BKE_gpencil_stroke_smooth_uv()

bool BKE_gpencil_stroke_smooth_uv ( bGPDstroke gps,
int  point_index,
float  influence 
)

Apply smooth for UV rotation to stroke point (use pressure).

Parameters
gpsStroke to smooth
point_indexPoint index
influenceAmount of smoothing to apply

Definition at line 968 of file gpencil_geom.c.

References CLAMP, CLAMP_MAX, CLAMP_MIN, interpf(), line_point_factor_v3(), M_PI_2, bGPDstroke::points, bGPDstroke::totpoints, bGPDspoint::uv_rot, and bGPDspoint::x.

Referenced by deformStroke(), gpencil_brush_smooth_apply(), and gpencil_smooth_stroke().

◆ BKE_gpencil_stroke_split()

bool BKE_gpencil_stroke_split ( bGPdata gpd,
bGPDframe gpf,
bGPDstroke gps,
const int  before_index,
bGPDstroke **  remaining_gps 
)

Split stroke.

Parameters
gpdGrease pencil data-block
gpfGrease pencil frame
gpsGrease pencil original stroke
before_indexPosition of the point to split
remaining_gpsSecondary stroke after split.
Returns
True if the split was done

Definition at line 646 of file gpencil_geom.c.

References BKE_gpencil_stroke_add_existing_style(), BKE_gpencil_stroke_geometry_update(), BKE_gpencil_stroke_trim_points(), MDeformWeight::def_nr, bGPDstroke::dvert, MDeformVert::dw, MDeformVert::flag, bGPDstroke::mat_nr, MEM_callocN, bGPDstroke::points, bGPDstroke::thickness, bGPDstroke::totpoints, MDeformVert::totweight, and MDeformWeight::weight.

◆ BKE_gpencil_stroke_stretch()

bool BKE_gpencil_stroke_stretch ( bGPDstroke gps,
const float  dist,
const float  tip_length 
)

Backbone stretch similar to Freestyle.

Parameters
gpsStroke to sample
distDistance of one segment
tip_lengthIgnore tip jittering, set zero to use default value.

Definition at line 537 of file gpencil_geom.c.

References copy_v3_v3(), interp_v3_v3v3(), len_v3v3(), bGPDstroke::points, bGPDstroke::totpoints, and bGPDspoint::x.

◆ BKE_gpencil_stroke_subdivide()

void BKE_gpencil_stroke_subdivide ( bGPdata gpd,
bGPDstroke gps,
int  level,
int  type 
)

◆ BKE_gpencil_stroke_to_view_space()

void BKE_gpencil_stroke_to_view_space ( RegionView3D rv3d,
bGPDstroke gps,
const float  diff_mat[4][4] 
)

Stroke to view space Transforms a stroke to view space. This allows for manipulations in 2D but also easy conversion back to 3D. Note: also takes care of parent space transform

Definition at line 3493 of file gpencil_geom.c.

References mul_m4_v3(), mul_v3_m4v3(), bGPDstroke::points, bGPDstroke::totpoints, RegionView3D::viewmat, and bGPDspoint::x.

Referenced by BKE_gpencil_stroke_perimeter_from_view().

◆ BKE_gpencil_stroke_trim()

bool BKE_gpencil_stroke_trim ( bGPdata gpd,
bGPDstroke gps 
)

◆ BKE_gpencil_stroke_trim_points()

bool BKE_gpencil_stroke_trim_points ( bGPDstroke gps,
const int  index_from,
const int  index_to 
)

Trim stroke to needed segments

Parameters
gpsTarget stroke
index_fromthe index of the first point to be used in the trimmed result
index_tothe index of the last point to be used in the trimmed result

Definition at line 587 of file gpencil_geom.c.

References BKE_gpencil_free_stroke_weights(), MDeformWeight::def_nr, bGPDstroke::dvert, MDeformVert::dw, MDeformVert::flag, MEM_callocN, MEM_freeN, NULL, bGPDstroke::points, bGPDstroke::totpoints, MDeformVert::totweight, and MDeformWeight::weight.

Referenced by BKE_gpencil_stroke_shrink(), and BKE_gpencil_stroke_split().

◆ BKE_gpencil_stroke_uniform_subdivide()

void BKE_gpencil_stroke_uniform_subdivide ( bGPdata gpd,
bGPDstroke gps,
const uint32_t  target_number,
const bool  select 
)

Subdivide the grease pencil stroke so the number of points is target_number. Does not change the shape of the stroke. The new points will be distributed as uniformly as possible by repeatedly subdividing the current longest edge.

Parameters
gpsThe stroke to be up-sampled.
target_numberThe number of points the up-sampled stroke should have.
selectSelect/Deselect the stroke.

Definition at line 3353 of file gpencil_geom.c.

References BKE_gpencil_stroke_geometry_update(), BKE_gpencil_stroke_select_index_set(), BLI_addtail(), BLI_assert, BLI_heap_free(), BLI_heap_insert(), BLI_heap_new(), BLI_heap_pop_min(), BLI_insertlinkafter(), copy_v3_v3(), copy_v4_v4(), MDeformWeight::def_nr, bGPDstroke::dvert, tSamplePoint::dw, MDeformVert::dw, ListBase::first, bGPDspoint::flag, bGPDstroke::flag, tSampleEdge::from, GP_SPOINT_SELECT, GP_STROKE_CYCLIC, GP_STROKE_SELECT, interp_v3_v3v3(), interp_v4_v4v4(), interpf(), ListBase::last, tSampleEdge::length_sq, LISTBASE_FOREACH_MUTABLE, MEM_callocN, MEM_freeN, MEM_recallocN, MEM_SAFE_FREE, MIN2, new_sample_edge_from_sample_points(), new_sample_point_from_gp_point(), tSamplePoint::next, NULL, bGPDstroke::points, tSamplePoint::pressure, bGPDspoint::pressure, select(), tSamplePoint::strength, bGPDspoint::strength, tSamplePoint::time, bGPDspoint::time, tSampleEdge::to, bGPDstroke::totpoints, tSamplePoint::totweight, MDeformVert::totweight, bGPDspoint::vert_color, tSamplePoint::vertex_color, MDeformWeight::weight, tSamplePoint::x, and bGPDspoint::x.

Referenced by gpencil_interpolate_seq_exec(), and gpencil_interpolate_set_points().

◆ BKE_gpencil_stroke_uv_update()

void BKE_gpencil_stroke_uv_update ( bGPDstroke gps)

Update Stroke UV data.

Parameters
gpsGrease pencil stroke

Definition at line 1287 of file gpencil_geom.c.

References len_v3v3(), NULL, bGPDstroke::points, bGPDstroke::totpoints, bGPDspoint::uv_fac, and x.

Referenced by BKE_gpencil_stroke_geometry_update(), ED_gpencil_update_color_uv(), and gpencil_sbuffer_stroke_ensure().

◆ BKE_gpencil_transform()

void BKE_gpencil_transform ( bGPdata gpd,
const float  mat[4][4] 
)

Apply grease pencil Transforms.

Parameters
gpdGrease pencil data-block
matTransformation matrix

Definition at line 2514 of file gpencil_geom.c.

References BKE_gpencil_stroke_geometry_update(), bGPdata::layers, LISTBASE_FOREACH, mat4_to_scale(), mul_m4_v3(), NULL, bGPDstroke::points, bGPDspoint::pressure, and bGPDspoint::x.

Referenced by apply_objects_internal().

◆ boundbox_gpencil()

static void boundbox_gpencil ( Object ob)
static

Create bounding box values.

Parameters
obGrease pencil object

Definition at line 154 of file gpencil_geom.c.

References Object_Runtime::bb, BKE_boundbox_init_from_minmax(), BKE_gpencil_data_minmax(), BOUNDBOX_DIRTY, Object::data, BoundBox::flag, max, MEM_callocN, min, NULL, and Object::runtime.

Referenced by BKE_gpencil_boundbox_get().

◆ generate_arc_from_point_to_point()

static int generate_arc_from_point_to_point ( ListBase list,
tPerimeterPoint from,
tPerimeterPoint to,
float  center_pt[3],
int  subdivisions,
bool  clockwise 
)
static

◆ generate_perimeter_cap()

static int generate_perimeter_cap ( const float  point[4],
const float  other_point[4],
float  radius,
ListBase list,
int  subdivisions,
short  cap_type 
)
static

◆ generate_semi_circle_from_point_to_point()

static int generate_semi_circle_from_point_to_point ( ListBase list,
tPerimeterPoint from,
tPerimeterPoint to,
int  subdivisions 
)
static

◆ gpencil_add_material()

static Material* gpencil_add_material ( Main bmain,
Object ob_gp,
const char *  name,
const float  color[4],
const bool  use_stroke,
const bool  use_fill,
int *  r_idx 
)
static

◆ gpencil_calc_stroke_fill_uv()

static void gpencil_calc_stroke_fill_uv ( const float(*)  points2d[2],
bGPDstroke gps,
const float  minv[2],
const float  maxv[2],
float(*)  r_uv[2] 
)
static

◆ gpencil_generate_edgeloops()

static void gpencil_generate_edgeloops ( Object ob,
bGPdata gpd,
bGPDframe gpf_stroke,
int  stroke_mat_index,
const float  angle,
const int  thickness,
const float  offset,
const float  matrix[4][4],
const bool  use_seams 
)
static

◆ gpencil_material_find_index_by_name()

static int gpencil_material_find_index_by_name ( Object ob,
const char *  name 
)
static

◆ gpencil_next_edge()

static int gpencil_next_edge ( GpEdge gp_edges,
int  totedges,
GpEdge gped_init,
const float  threshold,
const bool  reverse 
)
static

Definition at line 2101 of file gpencil_geom.c.

References angle(), angle_v3v3(), GpEdge::flag, GpEdge::v1, GpEdge::v2, and GpEdge::vec.

Referenced by gpencil_walk_edge().

◆ gpencil_stroke_copy_point()

static void gpencil_stroke_copy_point ( bGPDstroke gps,
MDeformVert dvert,
bGPDspoint point,
const float  delta[3],
float  pressure,
float  strength,
float  deltatime 
)
static

◆ gpencil_stroke_join_islands()

static void gpencil_stroke_join_islands ( bGPdata gpd,
bGPDframe gpf,
bGPDstroke gps_first,
bGPDstroke gps_last 
)
static

◆ gpencil_stroke_perimeter_ex()

static ListBase* gpencil_stroke_perimeter_ex ( const bGPdata gpd,
const bGPDlayer gpl,
const bGPDstroke gps,
int  subdivisions,
int *  r_num_perimeter_points 
)
static

◆ gpencil_walk_edge()

static int gpencil_walk_edge ( GHash v_table,
GpEdge gp_edges,
int  totedges,
uint stroke_array,
int  init_idx,
const float  angle,
const bool  reverse 
)
static

◆ make_element_name()

static void make_element_name ( const char *  obname,
const char *  name,
const int  maxlen,
char *  r_name 
)
static

Create the name with the object name and a suffix.

Definition at line 2364 of file gpencil_geom.c.

References BLI_str_replace_char(), BLI_strncpy_utf8(), SNPRINTF, and str.

Referenced by BKE_gpencil_convert_mesh().

◆ new_perimeter_point()

static tPerimeterPoint* new_perimeter_point ( const float  pt[3])
static

◆ new_sample_edge_from_sample_points()

static tSampleEdge* new_sample_edge_from_sample_points ( tSamplePoint from,
tSamplePoint to 
)
static

◆ new_sample_point_from_gp_point()

static tSamplePoint* new_sample_point_from_gp_point ( const bGPDspoint pt,
const MDeformVert dvert 
)
static

◆ stroke_defvert_create_nr_list()

static void stroke_defvert_create_nr_list ( MDeformVert dv_list,
int  count,
ListBase result,
int *  totweight 
)
static

◆ stroke_defvert_new_count()

static MDeformVert* stroke_defvert_new_count ( int  count,
int  totweight,
ListBase def_nr_list 
)
static

◆ stroke_interpolate_deform_weights()

static void stroke_interpolate_deform_weights ( bGPDstroke gps,
int  index_from,
int  index_to,
float  ratio,
MDeformVert vert 
)
static

◆ stroke_march_count()

static int stroke_march_count ( const bGPDstroke gps,
const float  dist 
)
static

◆ stroke_march_next_point()

static int stroke_march_next_point ( const bGPDstroke gps,
const int  index_next_pt,
const float current,
const float  dist,
float result,
float pressure,
float strength,
float vert_color,
float ratio_result,
int *  index_from,
int *  index_to 
)
static

◆ stroke_march_next_point_no_interp()

static int stroke_march_next_point_no_interp ( const bGPDstroke gps,
const int  index_next_pt,
const float current,
const float  dist,
float result 
)
static