Blender V4.3
gpencil_geom_legacy.cc File Reference
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "MEM_guardedalloc.h"
#include "BLI_array_utils.h"
#include "BLI_blenlib.h"
#include "BLI_ghash.h"
#include "BLI_hash.h"
#include "BLI_heap.h"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "BLI_math_vector_types.hh"
#include "BLI_polyfill_2d.h"
#include "BLI_span.hh"
#include "BLI_string_utils.hh"
#include "DNA_gpencil_legacy_types.h"
#include "DNA_gpencil_modifier_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_scene_types.h"
#include "BKE_attribute.hh"
#include "BKE_deform.hh"
#include "BKE_gpencil_curve_legacy.h"
#include "BKE_gpencil_geom_legacy.h"
#include "BKE_gpencil_legacy.h"
#include "BKE_material.h"
#include "BKE_object.hh"
#include "BKE_object_types.hh"
#include "DEG_depsgraph_query.hh"

Go to the source code of this file.

Classes

struct  tGPDeleteIsland
 

Functions

void BKE_gpencil_transform (bGPdata *gpd, const float mat[4][4])
 
int BKE_gpencil_stroke_point_count (const 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)
 
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, const bool smooth, bool auto_flip)
 
void BKE_gpencil_stroke_to_view_space (bGPDstroke *gps, float viewmat[4][4], const float diff_mat[4][4])
 
void BKE_gpencil_stroke_from_view_space (bGPDstroke *gps, float viewinv[4][4], const float diff_mat[4][4])
 
float BKE_gpencil_stroke_average_pressure_get (bGPDstroke *gps)
 
bool BKE_gpencil_stroke_is_pressure_constant (bGPDstroke *gps)
 
Grease Pencil Object: Bound-box Support
bool BKE_gpencil_stroke_minmax (const bGPDstroke *gps, const bool use_select, float r_min[3], float r_max[3])
 
std::optional< blender::Bounds< blender::float3 > > BKE_gpencil_data_minmax (const bGPdata *gpd)
 
void BKE_gpencil_centroid_3d (bGPdata *gpd, float r_centroid[3])
 
void BKE_gpencil_stroke_boundingbox_calc (bGPDstroke *gps)
 
Stroke Smooth Positions
bool BKE_gpencil_stroke_smooth_point (bGPDstroke *gps, int point_index, float influence, int iterations, const bool smooth_caps, const bool keep_shape, bGPDstroke *r_gps)
 
Stroke Smooth Strength
bool BKE_gpencil_stroke_smooth_strength (bGPDstroke *gps, int point_index, float influence, int iterations, bGPDstroke *r_gps)
 
Stroke Smooth Thickness
bool BKE_gpencil_stroke_smooth_thickness (bGPDstroke *gps, int point_index, float influence, int iterations, bGPDstroke *r_gps)
 
Stroke Smooth UV
bool BKE_gpencil_stroke_smooth_uv (bGPDstroke *gps, int point_index, float influence, int iterations, bGPDstroke *r_gps)
 
void BKE_gpencil_stroke_smooth (bGPDstroke *gps, const float influence, const int iterations, const bool smooth_position, const bool smooth_strength, const bool smooth_thickness, const bool smooth_uv, const bool keep_shape, const float *weights)
 
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])
 
Stroke Fill Triangulate
void BKE_gpencil_stroke_fill_triangulate (bGPDstroke *gps)
 
void BKE_gpencil_stroke_uv_update (bGPDstroke *gps)
 
void BKE_gpencil_stroke_geometry_update (bGPdata *, bGPDstroke *gps)
 
float BKE_gpencil_stroke_length (const bGPDstroke *gps, bool use_3d)
 
float BKE_gpencil_stroke_segment_length (const 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)
 
Normal Calculation
void BKE_gpencil_stroke_normal (const bGPDstroke *gps, float r_normal[3])
 

Function Documentation

◆ BKE_gpencil_centroid_3d()

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

Compute center of bounding box.

Parameters
gpdGrease pencil data-block
r_centroidLocation of the center

Definition at line 110 of file gpencil_geom_legacy.cc.

References BKE_gpencil_data_minmax(), bounds(), copy_v3_v3(), and blender::math::midpoint().

Referenced by blender::ed::object::object_origin_set_exec().

◆ BKE_gpencil_data_minmax()

std::optional< blender::Bounds< blender::float3 > > BKE_gpencil_data_minmax ( const bGPdata * gpd)

◆ BKE_gpencil_point_coords_apply()

◆ BKE_gpencil_point_coords_apply_with_mat4()

◆ BKE_gpencil_point_coords_get()

◆ BKE_gpencil_stroke_2d_flat()

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

◆ 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 )

◆ BKE_gpencil_stroke_average_pressure_get()

float BKE_gpencil_stroke_average_pressure_get ( struct bGPDstroke * gps)

Get average pressure.

Definition at line 1714 of file gpencil_geom_legacy.cc.

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

◆ BKE_gpencil_stroke_boundingbox_calc()

void BKE_gpencil_stroke_boundingbox_calc ( struct bGPDstroke * gps)

Compute stroke bounding box.

Parameters
gpsGrease pencil Stroke

Definition at line 117 of file gpencil_geom_legacy.cc.

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

Referenced by BKE_gpencil_stroke_geometry_update().

◆ BKE_gpencil_stroke_close()

◆ BKE_gpencil_stroke_delete_tagged_points()

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

◆ BKE_gpencil_stroke_fill_triangulate()

void BKE_gpencil_stroke_fill_triangulate ( struct bGPDstroke * gps)

◆ BKE_gpencil_stroke_flip()

void BKE_gpencil_stroke_flip ( struct bGPDstroke * gps)

Flip stroke.

Definition at line 1225 of file gpencil_geom_legacy.cc.

References BLI_array_reverse, bGPDstroke::dvert, bGPDstroke::points, and bGPDstroke::totpoints.

Referenced by BKE_gpencil_stroke_join().

◆ BKE_gpencil_stroke_from_view_space()

void BKE_gpencil_stroke_from_view_space ( struct bGPDstroke * gps,
float viewinv[4][4],
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 1698 of file gpencil_geom_legacy.cc.

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

◆ BKE_gpencil_stroke_geometry_update()

◆ BKE_gpencil_stroke_is_pressure_constant()

bool BKE_gpencil_stroke_is_pressure_constant ( struct bGPDstroke * gps)

Check if the thickness of the stroke is constant.

Definition at line 1730 of file gpencil_geom_legacy.cc.

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

◆ BKE_gpencil_stroke_join()

void BKE_gpencil_stroke_join ( struct bGPDstroke * gps_a,
struct bGPDstroke * gps_b,
bool leave_gaps,
bool fit_thickness,
bool smooth,
bool auto_flip )

Join two strokes using the shortest distance (reorder stroke if necessary).

Parameters
auto_flipFlip the stroke if the join between two strokes is not end->start points.

Definition at line 1552 of file gpencil_geom_legacy.cc.

References BKE_gpencil_stroke_flip(), BKE_gpencil_stroke_smooth_point(), copy_v3_v3(), bGPDstroke::dvert, ELEM, float, gpencil_stroke_copy_point(), len, len_squared_v3v3(), point, bGPDstroke::points, bGPDspoint::pressure, bGPDspoint::strength, bGPDstroke::thickness, bGPDstroke::totpoints, and bGPDspoint::x.

◆ BKE_gpencil_stroke_length()

float BKE_gpencil_stroke_length ( const bGPDstroke * gps,
bool use_3d )

◆ BKE_gpencil_stroke_minmax()

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

◆ BKE_gpencil_stroke_normal()

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

◆ BKE_gpencil_stroke_point_count()

int BKE_gpencil_stroke_point_count ( const bGPdata * gpd)

Definition at line 1085 of file gpencil_geom_legacy.cc.

References bGPdata::layers, LISTBASE_FOREACH, and bGPDstroke::totpoints.

◆ BKE_gpencil_stroke_segment_length()

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

◆ BKE_gpencil_stroke_set_random_color()

void BKE_gpencil_stroke_set_random_color ( struct bGPDstroke * gps)

Set a random color to stroke using vertex color.

Parameters
gpsStroke

Definition at line 1210 of file gpencil_geom_legacy.cc.

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.

◆ BKE_gpencil_stroke_smooth()

void BKE_gpencil_stroke_smooth ( struct bGPDstroke * gps,
const float influence,
const int iterations,
const bool smooth_position,
const bool smooth_strength,
const bool smooth_thickness,
const bool smooth_uv,
const bool keep_shape,
const float * weights )

Apply smooth operation to the stroke.

Parameters
gpsStroke to smooth
influenceThe interpolation factor for the smooth and the original stroke
iterationsRadius of points to consider, equivalent to iterations
smooth_positionSmooth point locations
smooth_strengthSmooth point strength
smooth_thicknessSmooth point thickness
smooth_uvSmooth uv rotation/factor
keep_shapeUse different distribution for smooth locations to keep the shape
weightsper point weights to multiply influence with (optional, can be null)

Definition at line 438 of file gpencil_geom_legacy.cc.

References BKE_gpencil_stroke_smooth_point(), BKE_gpencil_stroke_smooth_strength(), BKE_gpencil_stroke_smooth_thickness(), BKE_gpencil_stroke_smooth_uv(), MEM_dupallocN, MEM_freeN(), bGPDstroke::points, and bGPDstroke::totpoints.

◆ BKE_gpencil_stroke_smooth_point()

bool BKE_gpencil_stroke_smooth_point ( struct bGPDstroke * gps,
int point_index,
float influence,
int iterations,
bool smooth_caps,
bool keep_shape,
struct bGPDstroke * r_gps )

Apply smooth position to stroke point.

Parameters
gpsStroke to smooth
iPoint index
infAmount of smoothing to apply
iterationsRadius of points to consider, equivalent to iterations
smooth_capsApply smooth to stroke extremes
keep_shapeSmooth out fine details first
r_gpsStroke to put the result into

Definition at line 129 of file gpencil_geom_legacy.cc.

References add_v3_v3(), copy_v3_v3(), double(), ELEM, exp(), bGPDstroke::flag, float, GP_STROKE_CYCLIC, interp_v3_v3v3(), is_cyclic(), M_SQRT3, madd_v3_v3fl(), mul_v3_fl(), bGPDstroke::points, sub_v3_v3v3(), bGPDstroke::totpoints, w(), and bGPDspoint::x.

Referenced by BKE_gpencil_stroke_join(), and BKE_gpencil_stroke_smooth().

◆ BKE_gpencil_stroke_smooth_strength()

bool BKE_gpencil_stroke_smooth_strength ( struct bGPDstroke * gps,
int point_index,
float influence,
int iterations,
struct bGPDstroke * r_gps )

Apply smooth strength to stroke point.

Parameters
gpsStroke to smooth
point_indexPoint index
influenceAmount of smoothing to apply
iterationsRadius of points to consider, equivalent to iterations
r_gpsStroke to put the result into

Definition at line 251 of file gpencil_geom_legacy.cc.

References CLAMP_MAX, CLAMP_MIN, bGPDstroke::flag, float, GP_STROKE_CYCLIC, is_cyclic(), bGPDstroke::points, bGPDspoint::strength, bGPDstroke::totpoints, and w().

Referenced by BKE_gpencil_stroke_smooth().

◆ BKE_gpencil_stroke_smooth_thickness()

bool BKE_gpencil_stroke_smooth_thickness ( struct bGPDstroke * gps,
int point_index,
float influence,
int iterations,
struct bGPDstroke * r_gps )

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

Parameters
gpsStroke to smooth
point_indexPoint index
influenceAmount of smoothing to apply
iterationsRadius of points to consider, equivalent to iterations
r_gpsStroke to put the result into

Definition at line 309 of file gpencil_geom_legacy.cc.

References CLAMP_MAX, CLAMP_MIN, bGPDstroke::flag, float, GP_STROKE_CYCLIC, is_cyclic(), bGPDstroke::points, bGPDspoint::pressure, bGPDstroke::totpoints, and w().

Referenced by BKE_gpencil_stroke_smooth().

◆ BKE_gpencil_stroke_smooth_uv()

bool BKE_gpencil_stroke_smooth_uv ( struct bGPDstroke * gps,
int point_index,
float influence,
int iterations,
struct bGPDstroke * r_gps )

Apply smooth for UV rotation/factor to stroke point.

Parameters
gpsStroke to smooth
point_indexPoint index
influenceAmount of smoothing to apply
iterationsRadius of points to consider, equivalent to iterations
r_gpsStroke to put the result into

Definition at line 367 of file gpencil_geom_legacy.cc.

References ELEM, bGPDstroke::flag, float, GP_STROKE_CYCLIC, is_cyclic(), bGPDstroke::points, bGPDstroke::totpoints, bGPDspoint::uv_fac, bGPDspoint::uv_rot, and w().

Referenced by BKE_gpencil_stroke_smooth().

◆ BKE_gpencil_stroke_to_view_space()

void BKE_gpencil_stroke_to_view_space ( struct bGPDstroke * gps,
float viewmat[4][4],
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 1685 of file gpencil_geom_legacy.cc.

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

◆ BKE_gpencil_stroke_trim()

bool BKE_gpencil_stroke_trim ( struct bGPdata * gpd,
struct bGPDstroke * gps )

◆ BKE_gpencil_stroke_uv_update()

void BKE_gpencil_stroke_uv_update ( struct bGPDstroke * gps)

Update Stroke UV data.

Parameters
gpsGrease pencil stroke

Definition at line 750 of file gpencil_geom_legacy.cc.

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

Referenced by BKE_gpencil_stroke_geometry_update().

◆ BKE_gpencil_transform()

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

Apply grease pencil Transforms.

Parameters
gpdGrease pencil data-block
matTransformation matrix

Definition at line 1052 of file gpencil_geom_legacy.cc.

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

Referenced by blender::ed::object::apply_objects_internal().

◆ 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_stroke_copy_point()

◆ gpencil_stroke_join_islands()