Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/dynamicpaint.c')
-rw-r--r--source/blender/blenkernel/intern/dynamicpaint.c153
1 files changed, 95 insertions, 58 deletions
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index 47043064b90..a6a87b302ab 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -153,12 +153,17 @@ typedef struct Bounds3D {
typedef struct VolumeGrid {
int dim[3];
- Bounds3D grid_bounds; /* whole grid bounds */
-
- Bounds3D *bounds; /* (x*y*z) precalculated grid cell bounds */
- int *s_pos; /* (x*y*z) t_index begin id */
- int *s_num; /* (x*y*z) number of t_index points */
- int *t_index; /* actual surface point index, access: (s_pos + s_num) */
+ /** whole grid bounds */
+ Bounds3D grid_bounds;
+
+ /** (x*y*z) precalculated grid cell bounds */
+ Bounds3D *bounds;
+ /** (x*y*z) t_index begin id */
+ int *s_pos;
+ /** (x*y*z) number of t_index points */
+ int *s_num;
+ /** actual surface point index, access: (s_pos + s_num) */
+ int *t_index;
int *temp_t_index;
} VolumeGrid;
@@ -168,51 +173,67 @@ typedef struct Vec3f {
} Vec3f;
typedef struct BakeAdjPoint {
- float dir[3]; /* vector pointing towards this neighbor */
- float dist; /* distance to */
+ /** vector pointing towards this neighbor */
+ float dir[3];
+ /** distance to */
+ float dist;
} BakeAdjPoint;
-/* Surface data used while processing a frame */
+/** Surface data used while processing a frame */
typedef struct PaintBakeNormal {
- float invNorm[3]; /* current pixel world-space inverted normal */
- float normal_scale; /* normal directional scale for displace mapping */
+ /** current pixel world-space inverted normal */
+ float invNorm[3];
+ /** normal directional scale for displace mapping */
+ float normal_scale;
} PaintBakeNormal;
-/* Temp surface data used to process a frame */
+/** Temp surface data used to process a frame */
typedef struct PaintBakeData {
/* point space data */
PaintBakeNormal *bNormal;
- int *s_pos; /* index to start reading point sample realCoord */
- int *s_num; /* num of realCoord samples */
- Vec3f *
- realCoord; /* current pixel center world-space coordinates for each sample ordered as (s_pos + s_num) */
+ /** index to start reading point sample realCoord */
+ int *s_pos;
+ /** num of realCoord samples */
+ int *s_num;
+ /** current pixel center world-space coordinates for each sample ordered as (s_pos + s_num) */
+ Vec3f *realCoord;
Bounds3D mesh_bounds;
float dim[3];
/* adjacency info */
- BakeAdjPoint *bNeighs; /* current global neighbor distances and directions, if required */
+ /** current global neighbor distances and directions, if required */
+ BakeAdjPoint *bNeighs;
double average_dist;
/* space partitioning */
- VolumeGrid *grid; /* space partitioning grid to optimize brush checks */
+ /** space partitioning grid to optimize brush checks */
+ VolumeGrid *grid;
/* velocity and movement */
- Vec3f *velocity; /* speed vector in global space movement per frame, if required */
+ /** speed vector in global space movement per frame, if required */
+ Vec3f *velocity;
Vec3f *prev_velocity;
- float *brush_velocity; /* special temp data for post-p velocity based brushes like smudge
- * 3 float dir vec + 1 float str */
- MVert *prev_verts; /* copy of previous frame vertices. used to observe surface movement */
- float prev_obmat[4][4]; /* previous frame object matrix */
- int clear; /* flag to check if surface was cleared/reset -> have to redo velocity etc. */
+ /** special temp data for post-p velocity based brushes like smudge
+ * 3 float dir vec + 1 float str */
+ float *brush_velocity;
+ /** copy of previous frame vertices. used to observe surface movement. */
+ MVert *prev_verts;
+ /** Previous frame object matrix. */
+ float prev_obmat[4][4];
+ /** flag to check if surface was cleared/reset -> have to redo velocity etc. */
+ int clear;
} PaintBakeData;
-/* UV Image sequence format point */
+/** UV Image sequence format point */
typedef struct PaintUVPoint {
/* Pixel / mesh data */
- unsigned int tri_index, pixel_index; /* tri index on domain derived mesh */
- unsigned int v1, v2, v3; /* vertex indexes */
-
- unsigned int
- neighbour_pixel; /* If this pixel isn't uv mapped to any face, but it's neighboring pixel is */
+ /** tri index on domain derived mesh */
+ unsigned int tri_index;
+ unsigned int pixel_index;
+ /* vertex indexes */
+ unsigned int v1, v2, v3;
+
+ /** If this pixel isn't uv mapped to any face, but it's neighboring pixel is. */
+ unsigned int neighbour_pixel;
} PaintUVPoint;
typedef struct ImgSeqFormatData {
@@ -225,14 +246,20 @@ typedef struct ImgSeqFormatData {
#define ADJ_BORDER_PIXEL (1 << 1)
typedef struct PaintAdjData {
- int *
- n_target; /* array of neighboring point indexes, for single sample use (n_index + neigh_num) */
- int *n_index; /* index to start reading n_target for each point */
- int *n_num; /* num of neighs for each point */
- int *flags; /* vertex adjacency flags */
- int total_targets; /* size of n_target */
- int *border; /* indices of border pixels (only for texture paint) */
- int total_border; /* size of border */
+ /** Array of neighboring point indexes, for single sample use (n_index + neigh_num). */
+ int *n_target;
+ /** Index to start reading n_target for each point. */
+ int *n_index;
+ /** Num of neighs for each point. */
+ int *n_num;
+ /** Vertex adjacency flags. */
+ int *flags;
+ /** Size of n_target. */
+ int total_targets;
+ /** Indices of border pixels (only for texture paint). */
+ int *border;
+ /** Size of border. */
+ int total_border;
} PaintAdjData;
/************************* Runtime evaluation store ***************************/
@@ -2191,11 +2218,11 @@ Mesh *dynamicPaint_Modifier_do(DynamicPaintModifierData *pmd,
}
}
-/***************************** Image Sequence / UV Image Surface Calls ******************************/
+/* -------------------------------------------------------------------- */
+/** \name Image Sequence / UV Image Surface Calls
+ * \{ */
-/*
- * Create a surface for uv image sequence format
- */
+/* Create a surface for uv image sequence format. */
#define JITTER_SAMPLES \
{ \
0.0f, 0.0f, -0.2f, -0.4f, 0.2f, 0.4f, 0.4f, -0.2f, -0.4f, 0.3f, \
@@ -2473,7 +2500,8 @@ static int dynamic_paint_find_neighbour_pixel(const DynamicPaintCreateUVSurfaceD
const PaintUVPoint *tPoint = &tempPoints[x + w * y]; /* UV neighbor */
const PaintUVPoint *cPoint = &tempPoints[px + w * py]; /* Origin point */
- /* Check if shifted point is on same face -> it's a correct neighbor (and if it isn't marked as an "edge pixel") */
+ /* Check if shifted point is on same face -> it's a correct neighbor
+ * (and if it isn't marked as an "edge pixel") */
if ((tPoint->tri_index == cPoint->tri_index) && (tPoint->neighbour_pixel == -1)) {
return (x + w * y);
}
@@ -2568,7 +2596,8 @@ static void dynamic_paint_find_island_border(const DynamicPaintCreateUVSurfaceDa
const int vert0 = mloop[loop_idx[(edge_idx + 0)]].v;
const int vert1 = mloop[loop_idx[(edge_idx + 1) % 3]].v;
- /* Use a pre-computed vert-to-looptri mapping, speeds up things a lot compared to looping over all loopti. */
+ /* Use a pre-computed vert-to-looptri mapping,
+ * speeds up things a lot compared to looping over all loopti. */
const MeshElemMap *map = &bdata->vert_to_looptri_map[vert0];
bool found_other = false;
@@ -2710,7 +2739,8 @@ static bool dynamicPaint_pointHasNeighbor(PaintAdjData *ed, int index, int neigh
return false;
}
-/* Makes the adjacency data symmetric, except for border pixels. I.e. if A is neighbor of B, B is neighbor of A. */
+/* Makes the adjacency data symmetric, except for border pixels.
+ * I.e. if A is neighbor of B, B is neighbor of A. */
static bool dynamicPaint_symmetrizeAdjData(PaintAdjData *ed, int active_points)
{
int *new_n_index = MEM_callocN(sizeof(int) * active_points, "Surface Adj Index");
@@ -3000,7 +3030,8 @@ int dynamicPaint_createUVSurface(Scene *scene,
}
for (int i = 0; i < 8; i++) {
- /* Try to find a neighboring pixel in defined direction. If not found, -1 is returned */
+ /* Try to find a neighboring pixel in defined direction.
+ * If not found, -1 is returned */
const int n_target = dynamic_paint_find_neighbour_pixel(
&data, vert_to_looptri_map, w, h, tx, ty, i);
@@ -3410,10 +3441,13 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface,
IMB_freeImBuf(ibuf);
}
+/** \} */
+
/***************************** Ray / Nearest Point Utils ******************************/
-/* A modified callback to bvh tree raycast. The tree must have been built using bvhtree_from_mesh_looptri.
- * userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree.
+/* A modified callback to bvh tree raycast.
+ * The tree must have been built using bvhtree_from_mesh_looptri.
+ * userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree.
*
* To optimize brush detection speed this doesn't calculate hit coordinates or normal.
*/
@@ -3443,7 +3477,8 @@ static void mesh_tris_spherecast_dp(void *userdata,
}
}
-/* A modified callback to bvh tree nearest point. The tree must have been built using bvhtree_from_mesh_looptri.
+/* A modified callback to bvh tree nearest point.
+ * The tree must have been built using bvhtree_from_mesh_looptri.
* userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree.
*
* To optimize brush detection speed this doesn't calculate hit normal.
@@ -4848,7 +4883,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, cons
0, sData->total_points, sData, dynamic_paint_prepare_adjacency_cb, &settings);
/* calculate average values (single thread).
- * Note: tried to put this in threaded callback (using _finalize feature), but gave ~30% slower result! */
+ * Note: tried to put this in threaded callback (using _finalize feature),
+ * but gave ~30% slower result! */
bData->average_dist = 0.0;
for (index = 0; index < sData->total_points; index++) {
int numOfNeighs = adj_data->n_num[index];
@@ -4860,7 +4896,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, cons
bData->average_dist /= adj_data->total_targets;
}
-/* find two adjacency points (closest_id) and influence (closest_d) to move paint towards when affected by a force */
+/* Find two adjacency points (closest_id) and influence (closest_d)
+ * to move paint towards when affected by a force. */
static void surface_determineForceTargetPoints(const PaintSurfaceData *sData,
const int index,
const float force[3],
@@ -5350,8 +5387,8 @@ static void dynamic_paint_effect_drip_cb(void *__restrict userdata,
const unsigned int n_trgt = (unsigned int)n_target[n_idx];
/* Sort of spinlock, but only for given ePoint.
- * Since the odds a same ePoint is modified at the same time by several threads is very low, this is
- * much more efficient than a global spin lock. */
+ * Since the odds a same ePoint is modified at the same time by several threads is very low,
+ * this is much more efficient than a global spin lock. */
const unsigned int epointlock_idx = n_trgt / 8;
const uint8_t epointlock_bitmask = 1 << (n_trgt & 7); /* 7 == 0b111 */
while (atomic_fetch_and_or_uint8(&point_locks[epointlock_idx], epointlock_bitmask) &
@@ -5382,8 +5419,8 @@ static void dynamic_paint_effect_drip_cb(void *__restrict userdata,
CLAMP_MAX(ePoint->e_color[3], pPoint_prev->e_color[3]);
}
- /* Decrease paint wetness on current point
- * (just store diff here, that way we can only lock current point once at the end to apply it). */
+ /* Decrease paint wetness on current point (just store diff here,
+ * that way we can only lock current point once at the end to apply it). */
ppoint_wetness_diff += (ePoint->wetness - e_wet);
#ifndef NDEBUG
@@ -5811,10 +5848,10 @@ static void dynamic_paint_surface_pre_step_cb(void *__restrict userdata,
/* reduce wet layer alpha by dry factor */
pPoint->e_color[3] *= dry_ratio;
- /* now calculate new alpha for dry layer that keeps final blended color unchanged */
+ /* Now calculate new alpha for dry layer that keeps final blended color unchanged. */
pPoint->color[3] = (f_color[3] - pPoint->e_color[3]) / (1.0f - pPoint->e_color[3]);
- /* for each rgb component, calculate a new dry layer color that keeps the final blend color
- * with these new alpha values. (wet layer color doesn't change)*/
+ /* For each rgb component, calculate a new dry layer color that keeps the final blend
+ * color with these new alpha values. (wet layer color doesn't change). */
if (pPoint->color[3]) {
for (i = 0; i < 3; i++) {
pPoint->color[i] = (f_color[i] * f_color[3] -