[Bf-blender-cvs] [f82c8a4] compositor-2016: Dynapaint: cleanup of BKE code.
Bastien Montagne
noreply at git.blender.org
Wed Jun 8 21:46:39 CEST 2016
Commit: f82c8a4c907db61b3665695b0daa89f28db55912
Author: Bastien Montagne
Date: Thu May 12 12:08:03 2016 +0200
Branches: compositor-2016
https://developer.blender.org/rBf82c8a4c907db61b3665695b0daa89f28db55912
Dynapaint: cleanup of BKE code.
Line lengths, monolined 'if' statements, int -> bool, etc.
Also, replaced some internal cooked stuff by BLI helpers (most notably, the
'is inside UV triangle' code in `dynamicPaint_createUVSurface()`), and some
other minor optimizations.
===================================================================
M source/blender/blenkernel/intern/dynamicpaint.c
===================================================================
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index ab5d1b4..92de1eb 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -85,7 +85,7 @@
/* could enable at some point but for now there are far too many conversions */
#ifdef __GNUC__
-# pragma GCC diagnostic ignored "-Wdouble-promotion"
+//# pragma GCC diagnostic ignored "-Wdouble-promotion"
#endif
/* precalculated gaussian factors for 5x super sampling */
@@ -123,7 +123,7 @@ static int neighY[8] = {0, 1, 1, 1, 0, -1, -1, -1};
/* dissolve inline function */
-BLI_INLINE void value_dissolve(float *r_value, const float time, const float scale, const int is_log)
+BLI_INLINE void value_dissolve(float *r_value, const float time, const float scale, const bool is_log)
{
*r_value = (is_log) ?
(*r_value) * (powf(MIN_WETNESS, 1.0f / (1.2f * time / scale))) :
@@ -144,13 +144,12 @@ typedef struct Bounds3D {
typedef struct VolumeGrid {
int dim[3];
- Bounds3D grid_bounds; /* whole grid bounds */
+ 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) */
+ 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) */
} VolumeGrid;
typedef struct Vec3f {
@@ -165,21 +164,20 @@ typedef struct BakeAdjPoint {
/* 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 */
+ float normal_scale; /* normal directional scale for displace mapping */
} PaintBakeNormal;
/* 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)*/
+ 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) */
Bounds3D mesh_bounds;
/* adjacency info */
- BakeAdjPoint *bNeighs; /* current global neighbor distances and directions, if required */
+ BakeAdjPoint *bNeighs; /* current global neighbor distances and directions, if required */
double average_dist;
/* space partitioning */
VolumeGrid *grid; /* space partitioning grid to optimize brush checks */
@@ -188,7 +186,7 @@ typedef struct PaintBakeData {
Vec3f *velocity; /* speed vector in global space movement per frame, if required */
Vec3f *prev_velocity;
float *brush_velocity; /* special temp data for post-p velocity based brushes like smudge
- * 3 float dir vec + 1 float str */
+ * 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. */
@@ -201,8 +199,7 @@ typedef struct PaintUVPoint {
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 */
+ unsigned int neighbour_pixel; /* If this pixel isn't uv mapped to any face, but it's neighboring pixel is */
} PaintUVPoint;
typedef struct ImgSeqFormatData {
@@ -214,8 +211,7 @@ typedef struct ImgSeqFormatData {
#define ADJ_ON_MESH_EDGE (1 << 0)
typedef struct PaintAdjData {
- int *n_target; /* array of neighboring point indexes,
- * for single sample use (n_index + neigh_num) */
+ 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 */
@@ -239,11 +235,10 @@ static int dynamicPaint_surfaceNumOfPoints(DynamicPaintSurface *surface)
return 0; /* not supported atm */
}
else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
- if (!surface->canvas->dm) return 0; /* invalid derived mesh */
- return surface->canvas->dm->getNumVerts(surface->canvas->dm);
+ return (surface->canvas->dm) ? surface->canvas->dm->getNumVerts(surface->canvas->dm) : 0;
}
- else
- return 0;
+
+ return 0;
}
/* checks whether surface's format/type has realtime preview */
@@ -253,32 +248,16 @@ bool dynamicPaint_surfaceHasColorPreview(DynamicPaintSurface *surface)
return false;
}
else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
- if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE ||
- surface->type == MOD_DPAINT_SURFACE_T_WAVE)
- {
- return false;
- }
- else {
- return true;
- }
- }
- else {
- return true;
+ return !ELEM(surface->type, MOD_DPAINT_SURFACE_T_DISPLACE, MOD_DPAINT_SURFACE_T_WAVE);
}
+
+ return true;
}
/* get currently active surface (in user interface) */
DynamicPaintSurface *get_activeSurface(DynamicPaintCanvasSettings *canvas)
{
- DynamicPaintSurface *surface = canvas->surfaces.first;
- int i;
-
- for (i = 0; surface; surface = surface->next) {
- if (i == canvas->active_sur)
- return surface;
- i++;
- }
- return NULL;
+ return BLI_findlink(&canvas->surfaces, canvas->active_sur);
}
/* set preview to first previewable surface */
@@ -292,8 +271,9 @@ void dynamicPaint_resetPreview(DynamicPaintCanvasSettings *canvas)
surface->flags |= MOD_DPAINT_PREVIEW;
done = true;
}
- else
+ else {
surface->flags &= ~MOD_DPAINT_PREVIEW;
+ }
}
}
@@ -325,8 +305,9 @@ bool dynamicPaint_outputLayerExists(struct DynamicPaintSurface *surface, Object
Mesh *me = ob->data;
return (CustomData_get_named_layer_index(&me->ldata, CD_MLOOPCOL, name) != -1);
}
- else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT)
+ else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
return (defgroup_name_index(ob, surface->output_name) != -1);
+ }
}
return false;
@@ -334,15 +315,16 @@ bool dynamicPaint_outputLayerExists(struct DynamicPaintSurface *surface, Object
static bool surface_duplicateOutputExists(void *arg, const char *name)
{
- DynamicPaintSurface *t_surface = (DynamicPaintSurface *)arg;
+ DynamicPaintSurface *t_surface = arg;
DynamicPaintSurface *surface = t_surface->canvas->surfaces.first;
for (; surface; surface = surface->next) {
- if (surface != t_surface && surface->type == t_surface->type &&
- surface->format == t_surface->format)
- {
- if (surface->output_name[0] != '\0' && !BLI_path_cmp(name, surface->output_name)) return true;
- if (surface->output_name2[0] != '\0' && !BLI_path_cmp(name, surface->output_name2)) return true;
+ if (surface != t_surface && surface->type == t_surface->type && surface->format == t_surface->format) {
+ if ((surface->output_name[0] != '\0' && !BLI_path_cmp(name, surface->output_name)) ||
+ (surface->output_name2[0] != '\0' && !BLI_path_cmp(name, surface->output_name2)))
+ {
+ return true;
+ }
}
}
return false;
@@ -352,20 +334,25 @@ static void surface_setUniqueOutputName(DynamicPaintSurface *surface, char *base
{
char name[64];
BLI_strncpy(name, basename, sizeof(name)); /* in case basename is surface->name use a copy */
- if (!output)
- BLI_uniquename_cb(surface_duplicateOutputExists, surface, name, '.', surface->output_name, sizeof(surface->output_name));
- if (output)
- BLI_uniquename_cb(surface_duplicateOutputExists, surface, name, '.', surface->output_name2, sizeof(surface->output_name2));
+ if (output == 0) {
+ BLI_uniquename_cb(surface_duplicateOutputExists, surface, name, '.',
+ surface->output_name, sizeof(surface->output_name));
+ }
+ else if (output == 1) {
+ BLI_uniquename_cb(surface_duplicateOutputExists, surface, name, '.',
+ surface->output_name2, sizeof(surface->output_name2));
+ }
}
static bool surface_duplicateNameExists(void *arg, const char *name)
{
- DynamicPaintSurface *t_surface = (DynamicPaintSurface *)arg;
+ DynamicPaintSurface *t_surface = arg;
DynamicPaintSurface *surface = t_surface->canvas->surfaces.first;
for (; surface; surface = surface->next) {
- if (surface != t_surface && STREQ(name, surface->name)) return true;
+ if (surface != t_surface && STREQ(name, surface->name))
+ return true;
}
return false;
}
@@ -420,9 +407,7 @@ void dynamicPaintSurface_updateType(struct DynamicPaintSurface *surface)
static int surface_totalSamples(DynamicPaintSurface *surface)
{
- if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ &&
- surface->flags & MOD_DPAINT_ANTIALIAS)
- {
+ if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ && surface->flags & MOD_DPAINT_ANTIALIAS) {
return (surface->data->total_points * 5);
}
if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX &&
@@ -436,6 +421,7 @@ static int surface_totalSamples(DynamicPaintSurface *surface)
static void blendColors(const float t_color[3], float t_alpha, const float s_color[3], float s_alpha, float result[4])
{
+ /* Same thing as BLI's blend_color_mix_float(), but for non-premultiplied alpha. */
int i;
float i_alpha = 1.0f - s_alpha;
float f_alpha = t_alpha * i_alpha + s_alpha;
@@ -508,15 +494,11 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, const Scene *scen
/* select object */
if (surface->brush_group
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list