From 53ee7908d6c5a8bbdbec5202196d6dae86972e4c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 12 May 2012 16:11:34 +0000 Subject: style cleanup: whitespace --- source/blender/blenkernel/intern/dynamicpaint.c | 2123 ++++++++++++----------- 1 file changed, 1062 insertions(+), 1061 deletions(-) (limited to 'source/blender/blenkernel/intern/dynamicpaint.c') diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 2bde31cfd63..4d6d6a990f9 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -46,7 +46,7 @@ #include "DNA_texture_types.h" #include "BKE_animsys.h" -#include "BKE_bvhutils.h" /* bvh tree */ +#include "BKE_bvhutils.h" /* bvh tree */ #include "BKE_blender.h" #include "BKE_cdderivedmesh.h" #include "BKE_constraint.h" @@ -86,11 +86,11 @@ #endif /* precalculated gaussian factors for 5x super sampling */ -static float gaussianFactors[5] = { 0.996849f, - 0.596145f, - 0.596145f, - 0.596145f, - 0.524141f}; +static float gaussianFactors[5] = {0.996849f, + 0.596145f, + 0.596145f, + 0.596145f, + 0.524141f}; static float gaussianTotal = 3.309425f; /* UV Image neighboring pixel table x and y list */ @@ -98,11 +98,11 @@ static int neighX[8] = {1, 1, 0, -1, -1, -1, 0, 1}; static int neighY[8] = {0, 1, 1, 1, 0, -1, -1, -1}; /* subframe_updateObject() flags */ -#define UPDATE_PARENTS (1<<0) -#define UPDATE_MESH (1<<1) -#define UPDATE_EVERYTHING (UPDATE_PARENTS|UPDATE_MESH) +#define UPDATE_PARENTS (1 << 0) +#define UPDATE_MESH (1 << 1) +#define UPDATE_EVERYTHING (UPDATE_PARENTS | UPDATE_MESH) /* surface_getBrushFlags() return vals */ -#define BRUSH_USES_VELOCITY (1<<0) +#define BRUSH_USES_VELOCITY (1 << 0) /* brush mesh raycast status */ #define HIT_VOLUME 1 #define HIT_PROXIMITY 2 @@ -113,13 +113,13 @@ static int neighY[8] = {0, 1, 1, 1, 0, -1, -1, -1}; /* paint effect default movement per frame in global units */ #define EFF_MOVEMENT_PER_FRAME 0.05f /* initial wave time factor */ -#define WAVE_TIME_FAC (1.0f/24.f) +#define WAVE_TIME_FAC (1.0f / 24.f) #define CANVAS_REL_SIZE 5.0f /* drying limits */ #define MIN_WETNESS 0.001f #define MAX_WETNESS 5.0f /* dissolve macro */ -#define VALUE_DISSOLVE(VALUE, TIME, SCALE, LOG) (VALUE) = (LOG) ? (VALUE) * (pow(MIN_WETNESS, 1.0f/(1.2f*((float)(TIME))/(SCALE)))) : (VALUE) - 1.0f/(TIME)*(SCALE) +#define VALUE_DISSOLVE(VALUE, TIME, SCALE, LOG) (VALUE) = (LOG) ? (VALUE) *(pow(MIN_WETNESS, 1.0f / (1.2f * ((float)(TIME)) / (SCALE)))) : (VALUE) -1.0f / (TIME)*(SCALE) /***************************** Internal Structs ***************************/ @@ -136,11 +136,11 @@ typedef struct VolumeGrid { int dim[3]; Bounds3D grid_bounds; /* whole grid bounds */ - Bounds3D *bounds; /* (x*y*z) precalculated grid cell 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) */ + access: (s_pos+s_num) */ } VolumeGrid; typedef struct Vec3f { @@ -148,8 +148,8 @@ typedef struct Vec3f { } Vec3f; typedef struct BakeAdjPoint { - float dir[3]; /* vector pointing towards this neighbor */ - float dist; /* distance to */ + float dir[3]; /* vector pointing towards this neighbor */ + float dist; /* distance to */ } BakeAdjPoint; /* Surface data used while processing a frame */ @@ -162,8 +162,8 @@ typedef struct PaintBakeNormal { 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 */ + 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; @@ -172,44 +172,44 @@ typedef struct PaintBakeData { BakeAdjPoint *bNeighs; /* current global neighbor distances and directions, if required */ double average_dist; /* space partitioning */ - VolumeGrid *grid; /* space partitioning grid to optimize brush checks */ + VolumeGrid *grid; /* space partitioning grid to optimize brush checks */ /* velocity and movement */ - Vec3f *velocity; /* speed vector in global space movement per frame, if required */ + 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 */ - MVert *prev_verts; /* copy of previous frame vertices. used to observe surface movement */ + 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. */ + int clear; /* flag to check if surface was cleared/reset -> have to redo velocity etc. */ } PaintBakeData; /* UV Image sequence format point */ typedef struct PaintUVPoint { /* Pixel / mesh data */ - unsigned int face_index, pixel_index; /* face index on domain derived mesh */ - unsigned int v1, v2, v3; /* vertex indexes */ + unsigned int face_index, pixel_index; /* face 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 */ short quad; } PaintUVPoint; typedef struct ImgSeqFormatData { PaintUVPoint *uv_p; - Vec3f *barycentricWeights; /* b-weights for all pixel samples */ + Vec3f *barycentricWeights; /* b-weights for all pixel samples */ } ImgSeqFormatData; /* adjacency data flags */ -#define ADJ_ON_MESH_EDGE (1<<0) +#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_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 *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 */ } PaintAdjData; @@ -230,7 +230,7 @@ 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 */ + if (!surface->canvas->dm) return 0; /* invalid derived mesh */ return surface->canvas->dm->getNumVerts(surface->canvas->dm); } else @@ -259,12 +259,11 @@ int dynamicPaint_surfaceHasColorPreview(DynamicPaintSurface *surface) } /* get currently active surface (in user interface) */ -struct DynamicPaintSurface *get_activeSurface(DynamicPaintCanvasSettings *canvas) -{ +struct DynamicPaintSurface *get_activeSurface(DynamicPaintCanvasSettings *canvas){ DynamicPaintSurface *surface = canvas->surfaces.first; int i; - for (i=0; surface; surface=surface->next) { + for (i = 0; surface; surface = surface->next) { if (i == canvas->active_sur) return surface; i++; @@ -276,12 +275,12 @@ struct DynamicPaintSurface *get_activeSurface(DynamicPaintCanvasSettings *canvas void dynamicPaint_resetPreview(DynamicPaintCanvasSettings *canvas) { DynamicPaintSurface *surface = canvas->surfaces.first; - int done=0; + int done = 0; - for (; surface; surface=surface->next) { + for (; surface; surface = surface->next) { if (!done && dynamicPaint_surfaceHasColorPreview(surface)) { surface->flags |= MOD_DPAINT_PREVIEW; - done=1; + done = 1; } else surface->flags &= ~MOD_DPAINT_PREVIEW; @@ -292,7 +291,7 @@ void dynamicPaint_resetPreview(DynamicPaintCanvasSettings *canvas) static void dynamicPaint_setPreview(DynamicPaintSurface *t_surface) { DynamicPaintSurface *surface = t_surface->canvas->surfaces.first; - for (; surface; surface=surface->next) { + for (; surface; surface = surface->next) { if (surface == t_surface) surface->flags |= MOD_DPAINT_PREVIEW; else @@ -325,14 +324,15 @@ int dynamicPaint_outputLayerExists(struct DynamicPaintSurface *surface, Object * static int surface_duplicateOutputExists(void *arg, const char *name) { - DynamicPaintSurface *t_surface = (DynamicPaintSurface*)arg; + DynamicPaintSurface *t_surface = (DynamicPaintSurface *)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 1; - if (surface->output_name2[0]!='\0' && !BLI_path_cmp(name, surface->output_name2)) return 1; + 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 1; + if (surface->output_name2[0] != '\0' && !BLI_path_cmp(name, surface->output_name2)) return 1; } } return 0; @@ -351,11 +351,11 @@ static void surface_setUniqueOutputName(DynamicPaintSurface *surface, char *base static int surface_duplicateNameExists(void *arg, const char *name) { - DynamicPaintSurface *t_surface = (DynamicPaintSurface*)arg; + DynamicPaintSurface *t_surface = (DynamicPaintSurface *)arg; DynamicPaintSurface *surface = t_surface->canvas->surfaces.first; - for (; surface; surface=surface->next) { - if (surface!=t_surface && !strcmp(name, surface->name)) return 1; + for (; surface; surface = surface->next) { + if (surface != t_surface && !strcmp(name, surface->name)) return 1; } return 0; } @@ -372,8 +372,8 @@ void dynamicPaintSurface_setUniqueName(DynamicPaintSurface *surface, const char void dynamicPaintSurface_updateType(struct DynamicPaintSurface *surface) { if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { - surface->output_name[0]='\0'; - surface->output_name2[0]='\0'; + surface->output_name[0] = '\0'; + surface->output_name2[0] = '\0'; surface->flags |= MOD_DPAINT_ANTIALIAS; surface->depth_clamp = 1.0f; } @@ -418,7 +418,7 @@ static int surface_totalSamples(DynamicPaintSurface *surface) if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX && surface->flags & MOD_DPAINT_ANTIALIAS && surface->data->adj_data) { - return (surface->data->total_points+surface->data->adj_data->total_targets); + return (surface->data->total_points + surface->data->adj_data->total_targets); } return surface->data->total_points; @@ -428,12 +428,12 @@ static void blendColors(float t_color[3], float t_alpha, float s_color[3], float { int i; float i_alpha = 1.0f - s_alpha; - float f_alpha = t_alpha*i_alpha + s_alpha; + float f_alpha = t_alpha * i_alpha + s_alpha; /* blend colors */ if (f_alpha) { - for (i=0; i<3; i++) { - result[i] = (t_color[i]*t_alpha*i_alpha + s_color[i]*s_alpha)/f_alpha; + for (i = 0; i < 3; i++) { + result[i] = (t_color[i] * t_alpha * i_alpha + s_color[i] * s_alpha) / f_alpha; } } else { @@ -451,23 +451,23 @@ static float mixColors(float a_color[3], float a_weight, float b_color[3], float /* if first value has no weight just use b_color */ if (!a_weight) { copy_v3_v3(a_color, b_color); - return b_weight*ratio; + return b_weight * ratio; } - weight_ratio = b_weight/(a_weight+b_weight); + weight_ratio = b_weight / (a_weight + b_weight); } - else return a_weight*(1.0f-ratio); + else return a_weight * (1.0f - ratio); /* calculate final interpolation factor */ - if (ratio<=0.5f) { - factor = weight_ratio*(ratio*2.0f); + if (ratio <= 0.5f) { + factor = weight_ratio * (ratio * 2.0f); } else { - ratio = (ratio*2.0f - 1.0f); - factor = weight_ratio*(1.0f-ratio) + ratio; + ratio = (ratio * 2.0f - 1.0f); + factor = weight_ratio * (1.0f - ratio) + ratio; } /* mix final color */ interp_v3_v3v3(a_color, a_color, b_color, factor); - return (1.0f-factor)*a_weight + factor*b_weight; + return (1.0f - factor) * a_weight + factor * b_weight; } /* set "ignore cache" flag for all caches on this object */ @@ -477,7 +477,7 @@ static void object_cacheIgnoreClear(Object *ob, int state) PTCacheID *pid; BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0); - for (pid=pidlist.first; pid; pid=pid->next) { + for (pid = pidlist.first; pid; pid = pid->next) { if (pid->cache) { if (state) pid->cache->flag |= PTCACHE_IGNORE_CLEAR; @@ -505,19 +505,19 @@ static int subframe_updateObject(Scene *scene, Object *ob, int flags, float fram if (ob->track) is_canvas += subframe_updateObject(scene, ob->track, 0, frame); /* skip subframe if object is parented - * to vertex of a dynamic paint canvas */ + * to vertex of a dynamic paint canvas */ if (is_canvas && (ob->partype == PARVERT1 || ob->partype == PARVERT3)) return 0; /* also update constraint targets */ - for (con = ob->constraints.first; con; con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = ob->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; if (cti && cti->get_constraint_targets) { bConstraintTarget *ct; cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { + for (ct = targets.first; ct; ct = ct->next) { if (ct->tar) subframe_updateObject(scene, ct->tar, 0, frame); } @@ -528,8 +528,8 @@ static int subframe_updateObject(Scene *scene, Object *ob, int flags, float fram } } /* for curve following objects, parented curve has to be updated too */ - if (ob->type==OB_CURVE) { - Curve *cu= ob->data; + if (ob->type == OB_CURVE) { + Curve *cu = ob->data; BKE_animsys_evaluate_animdata(scene, &cu->id, cu->adt, frame, ADT_RECALC_ANIM); } @@ -538,7 +538,7 @@ static int subframe_updateObject(Scene *scene, Object *ob, int flags, float fram BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, frame, ADT_RECALC_ANIM); if (flags & UPDATE_MESH) { /* ignore cache clear during subframe updates - * to not mess up cache validity */ + * to not mess up cache validity */ object_cacheIgnoreClear(ob, 1); BKE_object_handle_update(scene, ob); object_cacheIgnoreClear(ob, 0); @@ -575,21 +575,21 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, Scene *scene) /* select object */ if (surface->brush_group) { - if (go->ob) brushObj = go->ob; + if (go->ob) brushObj = go->ob; } else brushObj = base->object; if (!brushObj) { if (surface->brush_group) go = go->next; - else base= base->next; + else base = base->next; continue; } if (surface->brush_group) go = go->next; else - base= base->next; + base = base->next; md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) { @@ -615,9 +615,9 @@ static int brush_usesMaterial(DynamicPaintBrushSettings *brush, Scene *scene) /* check whether two bounds intersect */ static int boundsIntersect(Bounds3D *b1, Bounds3D *b2) { - int i=2; + int i = 2; if (!b1->valid || !b2->valid) return 0; - for (; i>=0; i-=1) + for (; i >= 0; i -= 1) if (!(b1->min[i] <= b2->max[i] && b1->max[i] >= b2->min[i])) return 0; return 1; } @@ -625,36 +625,36 @@ static int boundsIntersect(Bounds3D *b1, Bounds3D *b2) /* check whether two bounds intersect inside defined proximity */ static int boundsIntersectDist(Bounds3D *b1, Bounds3D *b2, float dist) { - int i=2; + int i = 2; if (!b1->valid || !b2->valid) return 0; - for (; i>=0; i-=1) - if (!(b1->min[i] <= (b2->max[i]+dist) && b1->max[i] >= (b2->min[i]-dist))) return 0; + for (; i >= 0; i -= 1) + if (!(b1->min[i] <= (b2->max[i] + dist) && b1->max[i] >= (b2->min[i] - dist))) return 0; return 1; } /* check whether bounds intersects a point with given radius */ static int boundIntersectPoint(Bounds3D *b, float point[3], float radius) { - int i=2; + int i = 2; if (!b->valid) return 0; - for (; i>=0; i-=1) - if (!(b->min[i] <= (point[i]+radius) && b->max[i] >= (point[i]-radius))) return 0; + for (; i >= 0; i -= 1) + if (!(b->min[i] <= (point[i] + radius) && b->max[i] >= (point[i] - radius))) return 0; return 1; } /* expand bounds by a new point */ static void boundInsert(Bounds3D *b, float point[3]) { - int i=2; + int i = 2; if (!b->valid) { copy_v3_v3(b->min, point); copy_v3_v3(b->max, point); b->valid = 1; } else { - for (; i>=0; i-=1) { - if (point[i] < b->min[i]) b->min[i]=point[i]; - if (point[i] > b->max[i]) b->max[i]=point[i]; + for (; i >= 0; i -= 1) { + if (point[i] < b->min[i]) b->min[i] = point[i]; + if (point[i] > b->max[i]) b->max[i] = point[i]; } } } @@ -662,7 +662,7 @@ static void boundInsert(Bounds3D *b, float point[3]) float getSurfaceDimension(PaintSurfaceData *sData) { Bounds3D *mb = &sData->bData->mesh_bounds; - return MAX3((mb->max[0]-mb->min[0]), (mb->max[1]-mb->min[1]), (mb->max[2]-mb->min[2])); + return MAX3((mb->max[0] - mb->min[0]), (mb->max[1] - mb->min[1]), (mb->max[2] - mb->min[2])); } static void freeGrid(PaintSurfaceData *data) @@ -699,7 +699,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) freeGrid(sData); /* allocate separate bounds for each thread */ - grid_bounds = MEM_callocN(sizeof(Bounds3D)*num_of_threads, "Grid Bounds"); + grid_bounds = MEM_callocN(sizeof(Bounds3D) * num_of_threads, "Grid Bounds"); bData->grid = MEM_callocN(sizeof(VolumeGrid), "Surface Grid"); grid = bData->grid; @@ -711,7 +711,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) /* calculate canvas dimensions */ #pragma omp parallel for schedule(static) - for (i=0; itotal_points; i++) { + for (i = 0; i < sData->total_points; i++) { #ifdef _OPENMP int id = omp_get_thread_num(); boundInsert(&grid_bounds[id], (bData->realCoord[bData->s_pos[i]].v)); @@ -721,7 +721,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) } /* get final dimensions */ - for (i=0; igrid_bounds, grid_bounds[i].min); boundInsert(&grid->grid_bounds, grid_bounds[i].max); } @@ -732,8 +732,8 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) min_dim = MAX3(td[0], td[1], td[2]) / 1000.f; /* deactivate zero axises */ - for (i=0; i<3; i++) { - if (td[i]total_points / 10000.0), 1.0/(double)axis); + dim_factor = (float)pow(volume / ((double)sData->total_points / 10000.0), 1.0 / (double)axis); /* define final grid size using dim_factor, use min 3 for active axises */ - for (i=0; i<3; i++) { + for (i = 0; i < 3; i++) { grid->dim[i] = (int)floor(td[i] / dim_factor); - CLAMP(grid->dim[i], (dim[i]>=min_dim) ? 3 : 1, 100); + CLAMP(grid->dim[i], (dim[i] >= min_dim) ? 3 : 1, 100); } - grid_cells = grid->dim[0]*grid->dim[1]*grid->dim[2]; + grid_cells = grid->dim[0] * grid->dim[1] * grid->dim[2]; /* allocate memory for grids */ grid->bounds = MEM_callocN(sizeof(Bounds3D) * grid_cells, "Surface Grid Bounds"); grid->s_pos = MEM_callocN(sizeof(int) * grid_cells, "Surface Grid Position"); - grid->s_num = MEM_callocN(sizeof(int) * grid_cells*num_of_threads, "Surface Grid Points"); + grid->s_num = MEM_callocN(sizeof(int) * grid_cells * num_of_threads, "Surface Grid Points"); temp_s_num = MEM_callocN(sizeof(int) * grid_cells, "Temp Surface Grid Points"); grid->t_index = MEM_callocN(sizeof(int) * sData->total_points, "Surface Grid Target Ids"); temp_t_index = MEM_callocN(sizeof(int) * sData->total_points, "Temp Surface Grid Target Ids"); @@ -771,37 +771,37 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) if (!error) { /* calculate number of points withing each cell */ #pragma omp parallel for schedule(static) - for (i=0; itotal_points; i++) { + for (i = 0; i < sData->total_points; i++) { int co[3], j; - for (j=0; j<3; j++) { - co[j] = (int)floor((bData->realCoord[bData->s_pos[i]].v[j] - grid->grid_bounds.min[j])/dim[j]*grid->dim[j]); - CLAMP(co[j], 0, grid->dim[j]-1); + for (j = 0; j < 3; j++) { + co[j] = (int)floor((bData->realCoord[bData->s_pos[i]].v[j] - grid->grid_bounds.min[j]) / dim[j] * grid->dim[j]); + CLAMP(co[j], 0, grid->dim[j] - 1); } - temp_t_index[i] = co[0] + co[1] * grid->dim[0] + co[2] * grid->dim[0]*grid->dim[1]; + temp_t_index[i] = co[0] + co[1] * grid->dim[0] + co[2] * grid->dim[0] * grid->dim[1]; #ifdef _OPENMP - grid->s_num[temp_t_index[i]+omp_get_thread_num()*grid_cells]++; + grid->s_num[temp_t_index[i] + omp_get_thread_num() * grid_cells]++; #else grid->s_num[temp_t_index[i]]++; #endif } /* for first cell only calc s_num */ - for (i=1; is_num[0] += grid->s_num[i*grid_cells]; + for (i = 1; i < num_of_threads; i++) { + grid->s_num[0] += grid->s_num[i * grid_cells]; } /* calculate grid indexes */ - for (i=1; is_num[i] += grid->s_num[i+id*grid_cells]; + for (id = 1; id < num_of_threads; id++) { + grid->s_num[i] += grid->s_num[i + id * grid_cells]; } - grid->s_pos[i] = grid->s_pos[i-1] + grid->s_num[i-1]; + grid->s_pos[i] = grid->s_pos[i - 1] + grid->s_num[i - 1]; } /* save point indexes to final array */ - for (i=0; itotal_points; i++) { + for (i = 0; i < sData->total_points; i++) { int pos = grid->s_pos[temp_t_index[i]] + temp_s_num[temp_t_index[i]]; grid->t_index[pos] = i; @@ -812,17 +812,17 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) { int x; #pragma omp parallel for schedule(static) - for (x=0; xdim[0]; x++) { + for (x = 0; x < grid->dim[0]; x++) { int y; - for (y=0; ydim[1]; y++) { + for (y = 0; y < grid->dim[1]; y++) { int z; - for (z=0; zdim[2]; z++) { - int j, b_index = x + y * grid->dim[0] + z * grid->dim[0]*grid->dim[1]; + for (z = 0; z < grid->dim[2]; z++) { + int j, b_index = x + y * grid->dim[0] + z * grid->dim[0] * grid->dim[1]; /* set bounds */ - for (j=0; j<3; j++) { - int s = (j==0) ? x : ((j==1) ? y : z); - grid->bounds[b_index].min[j] = grid->grid_bounds.min[j] + dim[j]/grid->dim[j]*s; - grid->bounds[b_index].max[j] = grid->grid_bounds.min[j] + dim[j]/grid->dim[j]*(s+1); + for (j = 0; j < 3; j++) { + int s = (j == 0) ? x : ((j == 1) ? y : z); + grid->bounds[b_index].min[j] = grid->grid_bounds.min[j] + dim[j] / grid->dim[j] * s; + grid->bounds[b_index].max[j] = grid->grid_bounds.min[j] + dim[j] / grid->dim[j] * (s + 1); } grid->bounds[b_index].valid = 1; } @@ -857,10 +857,10 @@ void dynamicPaint_freeBrush(struct DynamicPaintModifierData *pmd) pmd->brush->dm = NULL; if (pmd->brush->paint_ramp) - MEM_freeN(pmd->brush->paint_ramp); + MEM_freeN(pmd->brush->paint_ramp); pmd->brush->paint_ramp = NULL; if (pmd->brush->vel_ramp) - MEM_freeN(pmd->brush->vel_ramp); + MEM_freeN(pmd->brush->vel_ramp); pmd->brush->vel_ramp = NULL; MEM_freeN(pmd->brush); @@ -919,7 +919,7 @@ void dynamicPaint_freeSurfaceData(DynamicPaintSurface *surface) if (data->format_data) { /* format specific free */ if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { - ImgSeqFormatData *format_data = (ImgSeqFormatData*)data->format_data; + ImgSeqFormatData *format_data = (ImgSeqFormatData *)data->format_data; if (format_data->uv_p) MEM_freeN(format_data->uv_p); if (format_data->barycentricWeights) @@ -989,13 +989,12 @@ void dynamicPaint_Modifier_free(struct DynamicPaintModifierData *pmd) /***************************** Initialize and reset ******************************/ /* -* Creates a new surface and adds it to the list -* If scene is null, frame range of 1-250 is used -* A pointer to this surface is returned -*/ -struct DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSettings *canvas, Scene *scene) -{ - DynamicPaintSurface *surface= MEM_callocN(sizeof(DynamicPaintSurface), "DynamicPaintSurface"); + * Creates a new surface and adds it to the list + * If scene is null, frame range of 1-250 is used + * A pointer to this surface is returned + */ +struct DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSettings *canvas, Scene *scene){ + DynamicPaintSurface *surface = MEM_callocN(sizeof(DynamicPaintSurface), "DynamicPaintSurface"); if (!surface) return NULL; surface->canvas = canvas; @@ -1009,7 +1008,7 @@ struct DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSett /* Set initial values */ surface->flags = MOD_DPAINT_ANTIALIAS | MOD_DPAINT_MULALPHA | MOD_DPAINT_DRY_LOG | MOD_DPAINT_DISSOLVE_LOG | - MOD_DPAINT_ACTIVE | MOD_DPAINT_PREVIEW | MOD_DPAINT_OUT1 | MOD_DPAINT_USE_DRYING; + MOD_DPAINT_ACTIVE | MOD_DPAINT_PREVIEW | MOD_DPAINT_OUT1 | MOD_DPAINT_USE_DRYING; surface->effect = 0; surface->effect_ui = 1; @@ -1064,8 +1063,8 @@ struct DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSett } /* -* Initialize modifier data -*/ + * Initialize modifier data + */ int dynamicPaint_createType(struct DynamicPaintModifierData *pmd, int type, struct Scene *scene) { if (pmd) { @@ -1212,16 +1211,16 @@ static void dynamicPaint_allocateSurfaceType(DynamicPaintSurface *surface) switch (surface->type) { case MOD_DPAINT_SURFACE_T_PAINT: - sData->type_data = MEM_callocN(sizeof(PaintPoint)*sData->total_points, "DynamicPaintSurface Data"); + sData->type_data = MEM_callocN(sizeof(PaintPoint) * sData->total_points, "DynamicPaintSurface Data"); break; case MOD_DPAINT_SURFACE_T_DISPLACE: - sData->type_data = MEM_callocN(sizeof(float)*sData->total_points, "DynamicPaintSurface DepthData"); + sData->type_data = MEM_callocN(sizeof(float) * sData->total_points, "DynamicPaintSurface DepthData"); break; case MOD_DPAINT_SURFACE_T_WEIGHT: - sData->type_data = MEM_callocN(sizeof(float)*sData->total_points, "DynamicPaintSurface WeightData"); + sData->type_data = MEM_callocN(sizeof(float) * sData->total_points, "DynamicPaintSurface WeightData"); break; case MOD_DPAINT_SURFACE_T_WAVE: - sData->type_data = MEM_callocN(sizeof(PaintWavePoint)*sData->total_points, "DynamicPaintSurface WaveData"); + sData->type_data = MEM_callocN(sizeof(PaintWavePoint) * sData->total_points, "DynamicPaintSurface WaveData"); break; } @@ -1261,21 +1260,21 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { /* For vertex format, neighbors are connected by edges */ - neigh_points = 2*dm->getNumEdges(dm); + neigh_points = 2 * dm->getNumEdges(dm); } else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) - neigh_points = sData->total_points*8; + neigh_points = sData->total_points * 8; if (!neigh_points) return; /* allocate memory */ ad = sData->adj_data = MEM_callocN(sizeof(PaintAdjData), "Surface Adj Data"); if (!ad) return; - ad->n_index = MEM_callocN(sizeof(int)*sData->total_points, "Surface Adj Index"); - ad->n_num = MEM_callocN(sizeof(int)*sData->total_points, "Surface Adj Counts"); - temp_data = MEM_callocN(sizeof(int)*sData->total_points, "Temp Adj Data"); - ad->n_target = MEM_callocN(sizeof(int)*neigh_points, "Surface Adj Targets"); - ad->flags = MEM_callocN(sizeof(int)*sData->total_points, "Surface Adj Flags"); + ad->n_index = MEM_callocN(sizeof(int) * sData->total_points, "Surface Adj Index"); + ad->n_num = MEM_callocN(sizeof(int) * sData->total_points, "Surface Adj Counts"); + temp_data = MEM_callocN(sizeof(int) * sData->total_points, "Temp Adj Data"); + ad->n_target = MEM_callocN(sizeof(int) * neigh_points, "Surface Adj Targets"); + ad->flags = MEM_callocN(sizeof(int) * sData->total_points, "Surface Adj Flags"); ad->total_targets = neigh_points; /* in case of allocation error, free memory */ @@ -1298,7 +1297,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for struct MLoop *mloop = dm->getLoopArray(dm); /* count number of edges per vertex */ - for (i=0; in_num[edge[i].v1]++; ad->n_num[edge[i].v2]++; @@ -1307,17 +1306,17 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for } /* also add number of vertices to temp_data - * to locate points on "mesh edge" */ - for (i=0; i vertex is on mesh edge */ - for (i=0; itotal_points; i++) { + * each vertex is even, if not -> vertex is on mesh edge */ + for (i = 0; i < sData->total_points; i++) { if ((temp_data[i] % 2) || (temp_data[i] < 4)) { @@ -1330,29 +1329,29 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for /* order n_index array */ n_pos = 0; - for (i=0; itotal_points; i++) { + for (i = 0; i < sData->total_points; i++) { ad->n_index[i] = n_pos; n_pos += ad->n_num[i]; } /* and now add neighbor data using that info */ - for (i=0; in_index[index]+temp_data[index]; + n_pos = ad->n_index[index] + temp_data[index]; ad->n_target[n_pos] = edge[i].v2; temp_data[index]++; /* second vertex */ index = edge[i].v2; - n_pos = ad->n_index[index]+temp_data[index]; + n_pos = ad->n_index[index] + temp_data[index]; ad->n_target[n_pos] = edge[i].v1; temp_data[index]++; } } else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { /* for image sequences, only allocate memory. - * bake initialization takes care of rest */ + * bake initialization takes care of rest */ } MEM_freeN(temp_data); @@ -1361,7 +1360,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for void dynamicPaint_setInitialColor(DynamicPaintSurface *surface) { PaintSurfaceData *sData = surface->data; - PaintPoint* pPoint = (PaintPoint*)sData->type_data; + PaintPoint *pPoint = (PaintPoint *)sData->type_data; DerivedMesh *dm = surface->canvas->dm; int i; @@ -1374,7 +1373,7 @@ void dynamicPaint_setInitialColor(DynamicPaintSurface *surface) else if (surface->init_color_type == MOD_DPAINT_INITIAL_COLOR) { /* apply color to every surface point */ #pragma omp parallel for schedule(static) - for (i=0; itotal_points; i++) { + for (i = 0; i < sData->total_points; i++) { copy_v3_v3(pPoint[i].color, surface->init_color); pPoint[i].alpha = surface->init_color[3]; } @@ -1395,20 +1394,20 @@ void dynamicPaint_setInitialColor(DynamicPaintSurface *surface) if (!tface) return; /* for vertex surface loop through tfaces and find uv color - * that provides highest alpha */ + * that provides highest alpha */ if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { #pragma omp parallel for schedule(static) - for (i=0; iformat == MOD_DPAINT_SURFACE_F_IMAGESEQ) { - ImgSeqFormatData *f_data = (ImgSeqFormatData*)sData->format_data; + ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; int samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; #pragma omp parallel for schedule(static) - for (i=0; itotal_points; i++) { + for (i = 0; i < sData->total_points; i++) { float uv[9] = {0.0f}; float uv_final[3] = {0.0f}; int j; TexResult texres = {0}; /* collect all uvs */ - for (j=0; j<3; j++) { - int v=(f_data->uv_p[i].quad && j>0) ? j+1 : j; - copy_v2_v2(&uv[j*3], tface[f_data->uv_p[i].face_index].uv[v]); + for (j = 0; j < 3; j++) { + int v = (f_data->uv_p[i].quad && j > 0) ? j + 1 : j; + copy_v2_v2(&uv[j * 3], tface[f_data->uv_p[i].face_index].uv[v]); } /* interpolate final uv pos */ interp_v3_v3v3v3(uv_final, &uv[0], &uv[3], &uv[6], - f_data->barycentricWeights[i*samples].v); + f_data->barycentricWeights[i * samples].v); /* remap to -1.0 to 1.0 */ - uv_final[0] = uv_final[0]*2.0f - 1.0f; - uv_final[1] = uv_final[1]*2.0f - 1.0f; + uv_final[0] = uv_final[0] * 2.0f - 1.0f; + uv_final[1] = uv_final[1] * 2.0f - 1.0f; multitex_ext_safe(tex, uv_final, &texres); @@ -1462,37 +1461,37 @@ void dynamicPaint_setInitialColor(DynamicPaintSurface *surface) if (!col) return; #pragma omp parallel for schedule(static) - for (i=0; iformat == MOD_DPAINT_SURFACE_F_IMAGESEQ) { - ImgSeqFormatData *f_data = (ImgSeqFormatData*)sData->format_data; + ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; int samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; MCol *col = CustomData_get_layer_named(&dm->faceData, CD_MCOL, surface->init_layername); if (!col) return; #pragma omp parallel for schedule(static) - for (i=0; itotal_points; i++) { + for (i = 0; i < sData->total_points; i++) { int face_ind = f_data->uv_p[i].face_index; float colors[3][4] = {{0.0f, 0.0f, 0.0f, 0.0f}}; float final_color[4]; int j; /* collect color values */ - for (j=0; j<3; j++) { - int v=(f_data->uv_p[i].quad && j>0) ? j+1 : j; - colors[j][0] = 1.0f/255.f*(float)col[face_ind*4+v].b; - colors[j][1] = 1.0f/255.f*(float)col[face_ind*4+v].g; - colors[j][2] = 1.0f/255.f*(float)col[face_ind*4+v].r; - colors[j][3] = 1.0f/255.f*(float)col[face_ind*4+v].a; + for (j = 0; j < 3; j++) { + int v = (f_data->uv_p[i].quad && j > 0) ? j + 1 : j; + colors[j][0] = 1.0f / 255.f * (float)col[face_ind * 4 + v].b; + colors[j][1] = 1.0f / 255.f * (float)col[face_ind * 4 + v].g; + colors[j][2] = 1.0f / 255.f * (float)col[face_ind * 4 + v].r; + colors[j][3] = 1.0f / 255.f * (float)col[face_ind * 4 + v].a; } /* interpolate final color */ interp_v4_v4v4v4(final_color, colors[0], colors[1], colors[2], - f_data->barycentricWeights[i*samples].v); + f_data->barycentricWeights[i * samples].v); copy_v3_v3(pPoint[i].color, final_color); pPoint[i].alpha = final_color[3]; @@ -1577,28 +1576,27 @@ static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, Deri if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) { MVert *mvert = result->getVertArray(result); int i; - float* value = (float*)sData->type_data; + float *value = (float *)sData->type_data; #pragma omp parallel for schedule(static) - for (i=0; itotal_points; i++) { - float normal[3], val=value[i]*surface->disp_factor; + for (i = 0; i < sData->total_points; i++) { + float normal[3], val = value[i] * surface->disp_factor; normal_short_to_float_v3(normal, mvert[i].no); normalize_v3(normal); - mvert[i].co[0] -= normal[0]*val; - mvert[i].co[1] -= normal[1]*val; - mvert[i].co[2] -= normal[2]*val; + mvert[i].co[0] -= normal[0] * val; + mvert[i].co[1] -= normal[1] * val; + mvert[i].co[2] -= normal[2] * val; } } } /* -* Apply canvas data to the object derived mesh -*/ + * Apply canvas data to the object derived mesh + */ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object *ob, - DerivedMesh *dm) -{ + DerivedMesh *dm){ DerivedMesh *result = CDDM_copy(dm); if (pmd->canvas && !(pmd->canvas->flags & MOD_DPAINT_BAKING)) { @@ -1607,7 +1605,7 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData int update_normals = 0; /* loop through surfaces */ - for (surface = pmd->canvas->surfaces.first; surface; surface=surface->next) { + for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { PaintSurfaceData *sData = surface->data; if (surface->format != MOD_DPAINT_SURFACE_F_IMAGESEQ && sData) { @@ -1620,18 +1618,18 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { int i; - PaintPoint* pPoint = (PaintPoint*)sData->type_data; + PaintPoint *pPoint = (PaintPoint *)sData->type_data; MLoopCol *col = NULL; MLoop *mloop = CDDM_get_loops(result); int totloop = result->numLoopData; /* paint is stored on dry and wet layers, so mix final color first */ - float *fcolor = MEM_callocN(sizeof(float)*sData->total_points*4, "Temp paint color"); + float *fcolor = MEM_callocN(sizeof(float) * sData->total_points * 4, "Temp paint color"); #pragma omp parallel for schedule(static) - for (i=0; itotal_points; i++) { + for (i = 0; i < sData->total_points; i++) { /* blend dry and wet layer */ - blendColors(pPoint[i].color, pPoint[i].alpha, pPoint[i].e_color, pPoint[i].e_alpha, &fcolor[i*4]); + blendColors(pPoint[i].color, pPoint[i].alpha, pPoint[i].e_color, pPoint[i].e_alpha, &fcolor[i * 4]); } /* viewport preview */ @@ -1649,7 +1647,7 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData #endif /* Save preview results to weight layer to be - * able to share same drawing methods */ + * able to share same drawing methods */ col = CustomData_get_layer(&result->loopData, CD_PREVIEW_MLOOPCOL); if (!col) col = CustomData_add_layer(&result->loopData, CD_PREVIEW_MLOOPCOL, CD_CALLOC, @@ -1657,11 +1655,11 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData if (col) { #pragma omp parallel for schedule(static) - for (i=0; itype == MOD_DPAINT_SURFACE_T_WEIGHT) { int defgrp_index = defgroup_name_index(ob, surface->output_name); MDeformVert *dvert = result->getVertDataArray(result, CD_MDEFORMVERT); - float *weight = (float*)sData->type_data; + float *weight = (float *)sData->type_data; /* viewport preview */ if (surface->flags & MOD_DPAINT_PREVIEW) { @@ -1754,11 +1752,11 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData /* apply weights into a vertex group, if doesnt exists add a new layer */ if (defgrp_index >= 0 && !dvert && (surface->output_name[0] != '\0')) dvert = CustomData_add_layer_named(&result->vertData, CD_MDEFORMVERT, CD_CALLOC, - NULL, sData->total_points, surface->output_name); + NULL, sData->total_points, surface->output_name); if (defgrp_index >= 0 && dvert) { int i; - for (i=0; itotal_points; i++) { - MDeformVert *dv= &dvert[i]; + for (i = 0; i < sData->total_points; i++) { + MDeformVert *dv = &dvert[i]; MDeformWeight *def_weight = defvert_find_index(dv, defgrp_index); /* skip if weight value is 0 and no existing weight is found */ @@ -1766,7 +1764,7 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData /* if not found, add a weight for it */ if (def_weight == NULL) { - def_weight= defvert_verify_index(dv, defgrp_index); + def_weight = defvert_verify_index(dv, defgrp_index); } /* set weight value */ @@ -1779,10 +1777,10 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) { MVert *mvert = result->getVertArray(result); int i; - PaintWavePoint* wPoint = (PaintWavePoint*)sData->type_data; + PaintWavePoint *wPoint = (PaintWavePoint *)sData->type_data; #pragma omp parallel for schedule(static) - for (i=0; itotal_points; i++) { + for (i = 0; i < sData->total_points; i++) { float normal[3]; normal_short_to_float_v3(normal, mvert[i].no); madd_v3_v3fl(mvert[i].co, normal, wPoint[i].height); @@ -1827,8 +1825,8 @@ void canvas_copyDerivedMesh(DynamicPaintCanvasSettings *canvas, DerivedMesh *dm) } /* -* Updates derived mesh copy and processes dynamic paint step / caches. -*/ + * Updates derived mesh copy and processes dynamic paint step / caches. + */ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene, Object *ob, DerivedMesh *dm) { if (pmd->canvas) { @@ -1842,7 +1840,7 @@ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene if (canvas->flags & MOD_DPAINT_BAKING) return; /* loop through surfaces */ - for (; surface; surface=surface->next) { + for (; surface; surface = surface->next) { int current_frame = (int)scene->r.cfra; /* free bake data if not required anymore */ @@ -1903,10 +1901,9 @@ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene } /* Modifier call. Processes dynamic paint modifier step. */ -struct DerivedMesh *dynamicPaint_Modifier_do(DynamicPaintModifierData *pmd, Scene *scene, Object *ob, DerivedMesh *dm) -{ +struct DerivedMesh *dynamicPaint_Modifier_do(DynamicPaintModifierData *pmd, Scene *scene, Object *ob, DerivedMesh *dm){ /* For now generate tessfaces in every case - * XXX - move/remove when most of dpaint functions are converted to use bmesh types */ + * XXX - move/remove when most of dpaint functions are converted to use bmesh types */ DM_ensure_tessface(dm); /* Update canvas data for a new frame */ @@ -1920,19 +1917,19 @@ struct DerivedMesh *dynamicPaint_Modifier_do(DynamicPaintModifierData *pmd, Scen /***************************** Image Sequence / UV Image Surface Calls ******************************/ /* -* Tries to find the neighboring pixel in given (uv space) direction. -* Result is used by effect system to move paint on the surface. -* -* px, py : origin pixel x and y -* n_index : lookup direction index (use neighX, neighY to get final index) -*/ + * Tries to find the neighboring pixel in given (uv space) direction. + * Result is used by effect system to move paint on the surface. + * + * px, py : origin pixel x and y + * n_index : lookup direction index (use neighX, neighY to get final index) + */ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh *dm, const char *uvname, int w, int h, int px, int py, int n_index) { /* Note: Current method only uses polygon edges to detect neighboring pixels. - * -> It doesn't always lead to the optimum pixel but is accurate enough - * and faster/simplier than including possible face tip point links) - */ + * -> It doesn't always lead to the optimum pixel but is accurate enough + * and faster/simplier than including possible face tip point links) + */ int x, y; PaintUVPoint *tPoint = NULL; @@ -1942,44 +1939,44 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh x = px + neighX[n_index]; y = py + neighY[n_index]; - if (x<0 || x>=w) return OUT_OF_TEXTURE; - if (y<0 || y>=h) return OUT_OF_TEXTURE; + if (x < 0 || x >= w) return OUT_OF_TEXTURE; + if (y < 0 || y >= h) return OUT_OF_TEXTURE; - tPoint = &tempPoints[x+w*y]; /* UV neighbor */ - cPoint = &tempPoints[px+w*py]; /* Origin point */ + tPoint = &tempPoints[x + w * y]; /* UV neighbor */ + 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->face_index == cPoint->face_index) && (tPoint->neighbour_pixel == -1)) - return (x+w*y); + return (x + w * y); /* - * Even if shifted point is on another face - * -> use this point. - * - * !! Replace with "is uv faces linked" check !! - * This should work fine as long as uv island - * margin is > 1 pixel. - */ + * Even if shifted point is on another face + * -> use this point. + * + * !! Replace with "is uv faces linked" check !! + * This should work fine as long as uv island + * margin is > 1 pixel. + */ if ((tPoint->face_index != -1) && (tPoint->neighbour_pixel == -1)) { - return (x+w*y); + return (x + w * y); } /* - * If we get here, the actual neighboring pixel - * is located on a non-linked uv face, and we have to find - * it's "real" position. - * - * Simple neighboring face finding algorithm: - * - find closest uv edge to shifted pixel and get - * the another face that shares that edge - * - find corresponding position of that new face edge - * in uv space - * - * TODO: Implement something more accurate / optimized? - */ + * If we get here, the actual neighboring pixel + * is located on a non-linked uv face, and we have to find + * it's "real" position. + * + * Simple neighboring face finding algorithm: + * - find closest uv edge to shifted pixel and get + * the another face that shares that edge + * - find corresponding position of that new face edge + * in uv space + * + * TODO: Implement something more accurate / optimized? + */ { int numOfFaces = dm->getNumTessFaces(dm); MFace *mface = dm->getTessFaceArray(dm); @@ -1989,7 +1986,7 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh { float pixel[2], dist, t_dist; int i, uindex[3], edge1_index, edge2_index, - e1_index, e2_index, target_face; + e1_index, e2_index, target_face; float closest_point[2], lambda, dir_vec[2]; int target_uv1, target_uv2, final_pixel[2], final_index; @@ -2007,41 +2004,41 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh } /* - * Find closest edge to that pixel - */ + * Find closest edge to that pixel + */ /* Dist to first edge */ e1_index = cPoint->v1; e2_index = cPoint->v2; edge1_index = uindex[0]; edge2_index = uindex[1]; dist = dist_to_line_segment_v2(pixel, tface[cPoint->face_index].uv[edge1_index], tface[cPoint->face_index].uv[edge2_index]); /* Dist to second edge */ t_dist = dist_to_line_segment_v2(pixel, tface[cPoint->face_index].uv[uindex[1]], tface[cPoint->face_index].uv[uindex[2]]); - if (t_dist < dist) {e1_index = cPoint->v2; e2_index = cPoint->v3; edge1_index = uindex[1]; edge2_index = uindex[2]; dist = t_dist;} + if (t_dist < dist) {e1_index = cPoint->v2; e2_index = cPoint->v3; edge1_index = uindex[1]; edge2_index = uindex[2]; dist = t_dist; } /* Dist to third edge */ t_dist = dist_to_line_segment_v2(pixel, tface[cPoint->face_index].uv[uindex[2]], tface[cPoint->face_index].uv[uindex[0]]); - if (t_dist < dist) {e1_index = cPoint->v3; e2_index = cPoint->v1; edge1_index = uindex[2]; edge2_index = uindex[0]; dist = t_dist;} + if (t_dist < dist) {e1_index = cPoint->v3; e2_index = cPoint->v1; edge1_index = uindex[2]; edge2_index = uindex[0]; dist = t_dist; } /* - * Now find another face that is linked to that edge - */ + * Now find another face that is linked to that edge + */ target_face = -1; - for (i=0; iface_index) continue; target_face = i; /* - * Get edge UV index - */ + * Get edge UV index + */ if (e1_index == mface[i].v1) target_uv1 = 0; else if (e1_index == mface[i].v2) target_uv1 = 1; else if (e1_index == mface[i].v3) target_uv1 = 2; @@ -2060,8 +2057,8 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh if (target_face == -1) return ON_MESH_EDGE; /* - * If target face is connected in UV space as well, just use original index - */ + * If target face is connected in UV space as well, just use original index + */ s_uv1 = (float *)tface[cPoint->face_index].uv[edge1_index]; s_uv2 = (float *)tface[cPoint->face_index].uv[edge2_index]; t_uv1 = (float *)tface[target_face].uv[target_uv1]; @@ -2074,13 +2071,13 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh ((s_uv2[0] == t_uv1[0] && s_uv2[1] == t_uv1[1]) && (s_uv1[0] == t_uv2[0] && s_uv1[1] == t_uv2[1]) )) { - return ((px+neighX[n_index]) + w*(py+neighY[n_index])); + return ((px + neighX[n_index]) + w * (py + neighY[n_index])); } /* - * Find a point that is relatively at same edge position - * on this other face UV - */ + * Find a point that is relatively at same edge position + * on this other face UV + */ lambda = closest_to_line_v2(closest_point, pixel, tface[cPoint->face_index].uv[edge1_index], tface[cPoint->face_index].uv[edge2_index]); if (lambda < 0.0f) lambda = 0.0f; if (lambda > 1.0f) lambda = 1.0f; @@ -2104,13 +2101,13 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh final_index = final_pixel[0] + w * final_pixel[1]; /* If we ended up to our origin point ( mesh has smaller than pixel sized faces) */ - if (final_index == (px+w*py)) return NOT_FOUND; + if (final_index == (px + w * py)) return NOT_FOUND; /* If found pixel still lies on wrong face ( mesh has smaller than pixel sized faces) */ if (tempPoints[final_index].face_index != target_face) return NOT_FOUND; /* - * If final point is an "edge pixel", use it's "real" neighbor instead - */ + * If final point is an "edge pixel", use it's "real" neighbor instead + */ if (tempPoints[final_index].neighbour_pixel != -1) final_index = cPoint->neighbour_pixel; return final_index; @@ -2119,16 +2116,16 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh } /* -* Create a surface for uv image sequence format -*/ + * Create a surface for uv image sequence format + */ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) { /* Antialias jitter point relative coords */ float jitter5sample[10] = {0.0f, 0.0f, - -0.2f, -0.4f, - 0.2f, 0.4f, - 0.4f, -0.2f, - -0.4f, 0.3f}; + -0.2f, -0.4f, + 0.2f, 0.4f, + 0.4f, -0.2f, + -0.4f, 0.3f}; int ty; int w, h; int numOfFaces; @@ -2165,8 +2162,8 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) w = h = surface->image_resolution; /* - * Start generating the surface - */ + * Start generating the surface + */ printf("DynamicPaint: Preparing UV surface of %ix%i pixels and %i faces.\n", w, h, numOfFaces); /* Init data struct */ @@ -2175,55 +2172,55 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) if (!surface->data) return setError(canvas, "Not enough free memory."); aa_samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; - tempPoints = (struct PaintUVPoint *) MEM_callocN(w*h*sizeof(struct PaintUVPoint), "Temp PaintUVPoint"); - if (!tempPoints) error=1; + tempPoints = (struct PaintUVPoint *) MEM_callocN(w * h * sizeof(struct PaintUVPoint), "Temp PaintUVPoint"); + if (!tempPoints) error = 1; - final_index = (int *) MEM_callocN(w*h*sizeof(int), "Temp UV Final Indexes"); - if (!final_index) error=1; + final_index = (int *) MEM_callocN(w * h * sizeof(int), "Temp UV Final Indexes"); + if (!final_index) error = 1; - tempWeights = (struct Vec3f *) MEM_mallocN(w*h*aa_samples*sizeof(struct Vec3f), "Temp bWeights"); - if (!tempWeights) error=1; + tempWeights = (struct Vec3f *) MEM_mallocN(w * h * aa_samples * sizeof(struct Vec3f), "Temp bWeights"); + if (!tempWeights) error = 1; /* - * Generate a temporary bounding box array for UV faces to optimize - * the pixel-inside-a-face search. - */ + * Generate a temporary bounding box array for UV faces to optimize + * the pixel-inside-a-face search. + */ if (!error) { - faceBB = (struct Bounds2D *) MEM_mallocN(numOfFaces*sizeof(struct Bounds2D), "MPCanvasFaceBB"); - if (!faceBB) error=1; + faceBB = (struct Bounds2D *) MEM_mallocN(numOfFaces * sizeof(struct Bounds2D), "MPCanvasFaceBB"); + if (!faceBB) error = 1; } if (!error) - for (ty=0; ty faceBB[ty].max[0]) faceBB[ty].max[0] = tface[ty].uv[i][0]; - if (tface[ty].uv[i][1] > faceBB[ty].max[1]) faceBB[ty].max[1] = tface[ty].uv[i][1]; + for (i = 1; i < numOfVert; i++) { + if (tface[ty].uv[i][0] < faceBB[ty].min[0]) faceBB[ty].min[0] = tface[ty].uv[i][0]; + if (tface[ty].uv[i][1] < faceBB[ty].min[1]) faceBB[ty].min[1] = tface[ty].uv[i][1]; + if (tface[ty].uv[i][0] > faceBB[ty].max[0]) faceBB[ty].max[0] = tface[ty].uv[i][0]; + if (tface[ty].uv[i][1] > faceBB[ty].max[1]) faceBB[ty].max[1] = tface[ty].uv[i][1]; + } } - } /* - * Loop through every pixel and check - * if pixel is uv-mapped on a canvas face. - */ + * Loop through every pixel and check + * if pixel is uv-mapped on a canvas face. + */ if (!error) { #pragma omp parallel for schedule(static) for (ty = 0; ty < h; ty++) { int tx; for (tx = 0; tx < w; tx++) { int i, sample; - int index = tx+w*ty; + int index = tx + w * ty; PaintUVPoint *tPoint = (&tempPoints[index]); - short isInside = 0; /* if point is inside a uv face */ + short isInside = 0; /* if point is inside a uv face */ float d1[2], d2[2], d3[2], point[5][2]; float dot00, dot01, dot02, dot11, dot12, invDenom, u, v; @@ -2238,27 +2235,27 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) point[0][1] = ((float)ty + 0.5f) / h; /* - * A pixel middle sample isn't enough to find very narrow polygons - * So using 4 samples of each corner too - */ + * A pixel middle sample isn't enough to find very narrow polygons + * So using 4 samples of each corner too + */ point[1][0] = ((float)tx) / w; point[1][1] = ((float)ty) / h; - point[2][0] = ((float)tx+1) / w; + point[2][0] = ((float)tx + 1) / w; point[2][1] = ((float)ty) / h; point[3][0] = ((float)tx) / w; - point[3][1] = ((float)ty+1) / h; + point[3][1] = ((float)ty + 1) / h; - point[4][0] = ((float)tx+1) / w; - point[4][1] = ((float)ty+1) / h; + point[4][0] = ((float)tx + 1) / w; + point[4][1] = ((float)ty + 1) / h; /* Loop through samples, starting from middle point */ - for (sample=0; sample<5; sample++) { + for (sample = 0; sample < 5; sample++) { /* Loop through every face in the mesh */ - for (i=0; i (point[sample][0])) continue; @@ -2267,55 +2264,55 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) if (faceBB[i].max[1] < (point[sample][1])) continue; /* Calculate point inside a triangle check - * for uv0, 1, 2 */ - sub_v2_v2v2(d1, tface[i].uv[2], tface[i].uv[0]); // uv2 - uv0 - sub_v2_v2v2(d2, tface[i].uv[1], tface[i].uv[0]); // uv1 - uv0 - sub_v2_v2v2(d3, point[sample], tface[i].uv[0]); // point - uv0 + * for uv0, 1, 2 */ + sub_v2_v2v2(d1, tface[i].uv[2], tface[i].uv[0]); // uv2 - uv0 + sub_v2_v2v2(d2, tface[i].uv[1], tface[i].uv[0]); // uv1 - uv0 + sub_v2_v2v2(d3, point[sample], tface[i].uv[0]); // point - uv0 - dot00 = d1[0]*d1[0] + d1[1]*d1[1]; - dot01 = d1[0]*d2[0] + d1[1]*d2[1]; - dot02 = d1[0]*d3[0] + d1[1]*d3[1]; - dot11 = d2[0]*d2[0] + d2[1]*d2[1]; - dot12 = d2[0]*d3[0] + d2[1]*d3[1]; + dot00 = d1[0] * d1[0] + d1[1] * d1[1]; + dot01 = d1[0] * d2[0] + d1[1] * d2[1]; + dot02 = d1[0] * d3[0] + d1[1] * d3[1]; + dot11 = d2[0] * d2[0] + d2[1] * d2[1]; + dot12 = d2[0] * d3[0] + d2[1] * d3[1]; invDenom = 1 / (dot00 * dot11 - dot01 * dot01); u = (dot11 * dot02 - dot01 * dot12) * invDenom; v = (dot00 * dot12 - dot01 * dot02) * invDenom; - if ((u > 0) && (v > 0) && (u + v < 1)) {isInside=1;} /* is inside a triangle */ + if ((u > 0) && (v > 0) && (u + v < 1)) {isInside = 1; } /* is inside a triangle */ /* If collision wasn't found but the face is a quad - * do another check for the second half */ + * do another check for the second half */ if ((!isInside) && mface[i].v4) { /* change d2 to test the other half */ - sub_v2_v2v2(d2, tface[i].uv[3], tface[i].uv[0]); // uv3 - uv0 + sub_v2_v2v2(d2, tface[i].uv[3], tface[i].uv[0]); // uv3 - uv0 /* test again */ - dot00 = d1[0]*d1[0] + d1[1]*d1[1]; - dot01 = d1[0]*d2[0] + d1[1]*d2[1]; - dot02 = d1[0]*d3[0] + d1[1]*d3[1]; - dot11 = d2[0]*d2[0] + d2[1]*d2[1]; - dot12 = d2[0]*d3[0] + d2[1]*d3[1]; + dot00 = d1[0] * d1[0] + d1[1] * d1[1]; + dot01 = d1[0] * d2[0] + d1[1] * d2[1]; + dot02 = d1[0] * d3[0] + d1[1] * d3[1]; + dot11 = d2[0] * d2[0] + d2[1] * d2[1]; + dot12 = d2[0] * d3[0] + d2[1] * d3[1]; invDenom = 1 / (dot00 * dot11 - dot01 * dot01); u = (dot11 * dot02 - dot01 * dot12) * invDenom; v = (dot00 * dot12 - dot01 * dot02) * invDenom; - if ((u > 0) && (v > 0) && (u + v < 1)) {isInside=2;} /* is inside the second half of the quad */ + if ((u > 0) && (v > 0) && (u + v < 1)) {isInside = 2; } /* is inside the second half of the quad */ } /* - * If point was inside the face - */ + * If point was inside the face + */ if (isInside != 0) { float uv1co[2], uv2co[2], uv3co[2], uv[2]; int j; /* Get triagnle uvs */ - if (isInside==1) { + if (isInside == 1) { copy_v2_v2(uv1co, tface[i].uv[0]); copy_v2_v2(uv2co, tface[i].uv[1]); copy_v2_v2(uv3co, tface[i].uv[2]); @@ -2327,23 +2324,23 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) } /* Add b-weights per anti-aliasing sample */ - for (j=0; jface_index = i; /* face index */ - tPoint->quad = (isInside == 2) ? 1 : 0; /* quad or tri part*/ + tPoint->face_index = i; /* face index */ + tPoint->quad = (isInside == 2) ? 1 : 0; /* quad or tri part*/ /* save vertex indexes */ tPoint->v1 = mface[i].v1; tPoint->v2 = (isInside == 2) ? mface[i].v3 : mface[i].v2; tPoint->v3 = (isInside == 2) ? mface[i].v4 : mface[i].v3; - sample = 5; /* make sure we exit sample loop as well */ + sample = 5; /* make sure we exit sample loop as well */ break; } } @@ -2352,16 +2349,16 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) } /* - * Now loop through every pixel that was left without index - * and find if they have neighboring pixels that have an index. - * If so use that polygon as pixel surface. - * (To avoid seams on uv island edges) - */ + * Now loop through every pixel that was left without index + * and find if they have neighboring pixels that have an index. + * If so use that polygon as pixel surface. + * (To avoid seams on uv island edges) + */ #pragma omp parallel for schedule(static) for (ty = 0; ty < h; ty++) { int tx; for (tx = 0; tx < w; tx++) { - int index = tx+w*ty; + int index = tx + w * ty; PaintUVPoint *tPoint = (&tempPoints[index]); /* If point isn't't on canvas mesh */ @@ -2372,19 +2369,19 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) /* get loop area */ u_min = (tx > 0) ? -1 : 0; - u_max = (tx < (w-1)) ? 1 : 0; + u_max = (tx < (w - 1)) ? 1 : 0; v_min = (ty > 0) ? -1 : 0; - v_max = (ty < (h-1)) ? 1 : 0; + v_max = (ty < (h - 1)) ? 1 : 0; point[0] = ((float)tx + 0.5f) / w; point[1] = ((float)ty + 0.5f) / h; /* search through defined area for neighbor */ - for (u=u_min; u<=u_max; u++) - for (v=v_min; v<=v_max; v++) { + for (u = u_min; u <= u_max; u++) + for (v = v_min; v <= v_max; v++) { /* if not this pixel itself */ - if (u!=0 || v!=0) { - ind = (tx+u)+w*(ty+v); + if (u != 0 || v != 0) { + ind = (tx + u) + w * (ty + v); /* if neighbor has index */ if (tempPoints[ind].face_index != -1) { @@ -2405,39 +2402,39 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) } /* Add b-weights per anti-aliasing sample */ - for (j=0; jneighbour_pixel = ind; // face index - tPoint->quad = tempPoints[ind].quad; // quad or tri + tPoint->neighbour_pixel = ind; // face index + tPoint->quad = tempPoints[ind].quad; // quad or tri /* save vertex indexes */ tPoint->v1 = mface[i].v1; tPoint->v2 = (tPoint->quad) ? mface[i].v3 : mface[i].v2; tPoint->v3 = (tPoint->quad) ? mface[i].v4 : mface[i].v3; - u = u_max + 1; /* make sure we exit outer loop as well */ + u = u_max + 1; /* make sure we exit outer loop as well */ break; } + } } - } } } } /* - * When base loop is over convert found neighbor indexes to real ones - * Also count the final number of active surface points - */ + * When base loop is over convert found neighbor indexes to real ones + * Also count the final number of active surface points + */ for (ty = 0; ty < h; ty++) { int tx; for (tx = 0; tx < w; tx++) { - int index = tx+w*ty; + int index = tx + w * ty; PaintUVPoint *tPoint = (&tempPoints[index]); if (tPoint->face_index == -1 && tPoint->neighbour_pixel != -1) tPoint->face_index = tempPoints[tPoint->neighbour_pixel].face_index; @@ -2447,18 +2444,18 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) /* Generate surface adjacency data. */ { - int i, cursor=0; + int i, cursor = 0; /* Create a temporary array of final indexes (before unassigned - * pixels have been dropped) */ - for (i=0; itotal_points = w*h; + sData->total_points = w * h; dynamicPaint_initAdjacencyData(surface, 1); if (sData->adj_data) { @@ -2467,16 +2464,16 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) for (ty = 0; ty < h; ty++) { int tx; for (tx = 0; tx < w; tx++) { - int i, index = tx+w*ty; + int i, index = tx + w * ty; if (tempPoints[index].face_index != -1) { ed->n_index[final_index[index]] = n_pos; ed->n_num[final_index[index]] = 0; - for (i=0; i<8; i++) { + for (i = 0; i < 8; i++) { /* Try to find a neighboring pixel in defined direction - * If not found, -1 is returned */ + * If not found, -1 is returned */ int n_target = dynamicPaint_findNeighbourPixel(tempPoints, dm, uvname, w, h, tx, ty, i); if (n_target >= 0) { @@ -2498,12 +2495,12 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) { ImgSeqFormatData *f_data = MEM_callocN(sizeof(struct ImgSeqFormatData), "ImgSeqFormatData"); if (f_data) { - f_data->uv_p = MEM_callocN(active_points*sizeof(struct PaintUVPoint), "PaintUVPoint"); - f_data->barycentricWeights = MEM_callocN(active_points*aa_samples*sizeof(struct Vec3f), "PaintUVPoint"); + f_data->uv_p = MEM_callocN(active_points * sizeof(struct PaintUVPoint), "PaintUVPoint"); + f_data->barycentricWeights = MEM_callocN(active_points * aa_samples * sizeof(struct Vec3f), "PaintUVPoint"); - if (!f_data->uv_p || !f_data->barycentricWeights) error=1; + if (!f_data->uv_p || !f_data->barycentricWeights) error = 1; } - else error=1; + else error = 1; sData->total_points = active_points; @@ -2520,17 +2517,17 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) sData->total_points = active_points; sData->format_data = f_data; - for (index = 0; index < (w*h); index++) { + for (index = 0; index < (w * h); index++) { if (tempPoints[index].face_index != -1) { memcpy(&f_data->uv_p[cursor], &tempPoints[index], sizeof(PaintUVPoint)); - memcpy(&f_data->barycentricWeights[cursor*aa_samples], &tempWeights[index*aa_samples], sizeof(Vec3f)*aa_samples); + memcpy(&f_data->barycentricWeights[cursor * aa_samples], &tempWeights[index * aa_samples], sizeof(Vec3f) * aa_samples); cursor++; } } } } } - if (error==1) setError(canvas, "Not enough free memory."); + if (error == 1) setError(canvas, "Not enough free memory."); if (faceBB) MEM_freeN(faceBB); if (tempPoints) MEM_freeN(tempPoints); @@ -2548,17 +2545,17 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { - ImgSeqFormatData *f_data = (ImgSeqFormatData*)sData->format_data; - PaintUVPoint *uvPoint = &((PaintUVPoint*)f_data->uv_p)[index]; - PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; - pPoint->alpha=1.0f; + ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; + PaintUVPoint *uvPoint = &((PaintUVPoint *)f_data->uv_p)[index]; + PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; + pPoint->alpha = 1.0f; /* Every pixel that is assigned as "edge pixel" gets blue color */ if (uvPoint->neighbour_pixel != -1) pPoint->color[2] = 1.0f; /* and every pixel that finally got an polygon gets red color */ if (uvPoint->face_index != -1) pPoint->color[0] = 1.0f; /* green color shows pixel face index hash */ - if (uvPoint->face_index != -1) pPoint->color[1] = (float)(uvPoint->face_index % 255)/256.0f; + if (uvPoint->face_index != -1) pPoint->color[1] = (float)(uvPoint->face_index % 255) / 256.0f; } #endif @@ -2569,19 +2566,19 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) } /* -* Outputs an image file from uv surface data. -*/ -void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char* filename, short output_layer) + * Outputs an image file from uv surface data. + */ +void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filename, short output_layer) { int index; - ImBuf* ibuf = NULL; + ImBuf *ibuf = NULL; PaintSurfaceData *sData = surface->data; - ImgSeqFormatData *f_data = (ImgSeqFormatData*)sData->format_data; + ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; /* OpenEXR or PNG */ int format = (surface->image_fileformat & MOD_DPAINT_IMGFORMAT_OPENEXR) ? R_IMF_IMTYPE_OPENEXR : R_IMF_IMTYPE_PNG; char output_file[FILE_MAX]; - if (!sData || !sData->type_data) {setError(surface->canvas, "Image save failed: Invalid surface.");return;} + if (!sData || !sData->type_data) {setError(surface->canvas, "Image save failed: Invalid surface."); return; } /* if selected format is openexr, but current build doesnt support one */ #ifndef WITH_OPENEXR if (format == R_IMF_IMTYPE_OPENEXR) format = R_IMF_IMTYPE_PNG; @@ -2595,78 +2592,78 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char* filenam /* Init image buffer */ ibuf = IMB_allocImBuf(surface->image_resolution, surface->image_resolution, 32, IB_rectfloat); - if (ibuf == NULL) {setError(surface->canvas, "Image save failed: Not enough free memory.");return;} + if (ibuf == NULL) {setError(surface->canvas, "Image save failed: Not enough free memory."); return; } #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { - int pos=f_data->uv_p[index].pixel_index*4; /* image buffer position */ + int pos = f_data->uv_p[index].pixel_index * 4; /* image buffer position */ /* Set values of preferred type */ if (output_layer == 1) { /* wetmap */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - PaintPoint *point = &((PaintPoint*)sData->type_data)[index]; + PaintPoint *point = &((PaintPoint *)sData->type_data)[index]; float value = (point->wetness > 1.0f) ? 1.0f : point->wetness; - ibuf->rect_float[pos]=value; - ibuf->rect_float[pos+1]=value; - ibuf->rect_float[pos+2]=value; - ibuf->rect_float[pos+3]=1.0f; + ibuf->rect_float[pos] = value; + ibuf->rect_float[pos + 1] = value; + ibuf->rect_float[pos + 2] = value; + ibuf->rect_float[pos + 3] = 1.0f; } } else if (output_layer == 0) { /* Paintmap */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - PaintPoint *point = &((PaintPoint*)sData->type_data)[index]; + PaintPoint *point = &((PaintPoint *)sData->type_data)[index]; /* blend wet and dry layers */ blendColors(point->color, point->alpha, point->e_color, point->e_alpha, &ibuf->rect_float[pos]); /* Multiply color by alpha if enabled */ if (surface->flags & MOD_DPAINT_MULALPHA) { - ibuf->rect_float[pos] *= ibuf->rect_float[pos+3]; - ibuf->rect_float[pos+1] *= ibuf->rect_float[pos+3]; - ibuf->rect_float[pos+2] *= ibuf->rect_float[pos+3]; + ibuf->rect_float[pos] *= ibuf->rect_float[pos + 3]; + ibuf->rect_float[pos + 1] *= ibuf->rect_float[pos + 3]; + ibuf->rect_float[pos + 2] *= ibuf->rect_float[pos + 3]; } } /* displace */ else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) { - float depth = ((float*)sData->type_data)[index]; + float depth = ((float *)sData->type_data)[index]; if (surface->depth_clamp) depth /= surface->depth_clamp; if (surface->disp_type == MOD_DPAINT_DISP_DISPLACE) { - depth = (0.5f - depth/2.0f); + depth = (0.5f - depth / 2.0f); } CLAMP(depth, 0.0f, 1.0f); - ibuf->rect_float[pos]=depth; - ibuf->rect_float[pos+1]=depth; - ibuf->rect_float[pos+2]=depth; - ibuf->rect_float[pos+3]=1.0f; + ibuf->rect_float[pos] = depth; + ibuf->rect_float[pos + 1] = depth; + ibuf->rect_float[pos + 2] = depth; + ibuf->rect_float[pos + 3] = 1.0f; } /* waves */ else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) { - PaintWavePoint *wPoint = &((PaintWavePoint*)sData->type_data)[index]; + PaintWavePoint *wPoint = &((PaintWavePoint *)sData->type_data)[index]; float depth = wPoint->height; if (surface->depth_clamp) - depth /= surface->depth_clamp; - depth = (0.5f + depth/2.0f); + depth /= surface->depth_clamp; + depth = (0.5f + depth / 2.0f); CLAMP(depth, 0.0f, 1.0f); - ibuf->rect_float[pos]=depth; - ibuf->rect_float[pos+1]=depth; - ibuf->rect_float[pos+2]=depth; - ibuf->rect_float[pos+3]=1.0f; + ibuf->rect_float[pos] = depth; + ibuf->rect_float[pos + 1] = depth; + ibuf->rect_float[pos + 2] = depth; + ibuf->rect_float[pos + 3] = 1.0f; } } } /* Set output format, png in case exr isn't supported */ - ibuf->ftype= PNG|95; + ibuf->ftype = PNG | 95; #ifdef WITH_OPENEXR - if (format == R_IMF_IMTYPE_OPENEXR) { /* OpenEXR 32-bit float */ + if (format == R_IMF_IMTYPE_OPENEXR) { /* OpenEXR 32-bit float */ ibuf->ftype = OPENEXR | OPENEXR_COMPRESS; } #endif @@ -2680,7 +2677,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char* filenam /***************************** Material / Texture Sampling ******************************/ /* stores a copy of required materials to allow doing adjustments -* without interfering the render/preview */ + * without interfering the render/preview */ typedef struct BrushMaterials { Material *mat; Material **ob_mats; @@ -2688,24 +2685,24 @@ typedef struct BrushMaterials { } BrushMaterials; /* Initialize materials for brush object: -* Calculates inverse matrices for linked objects, updates -* volume caches etc. */ + * Calculates inverse matrices for linked objects, updates + * volume caches etc. */ static void dynamicPaint_updateBrushMaterials(Object *brushOb, Material *ui_mat, Scene *scene, BrushMaterials *bMats) { /* Calculate inverse transformation matrix - * for this object */ + * for this object */ invert_m4_m4(brushOb->imat, brushOb->obmat); copy_m4_m4(brushOb->imat_ren, brushOb->imat); /* Now process every material linked to this brush object */ if ((ui_mat == NULL) && brushOb->mat && brushOb->totcol) { - int i, tot=(*give_totcolp(brushOb)); + int i, tot = (*give_totcolp(brushOb)); /* allocate material pointer array */ if (tot) { - bMats->ob_mats = MEM_callocN(sizeof(Material*)*(tot), "BrushMaterials"); - for (i=0; iob_mats[i] = RE_init_sample_material(give_current_material(brushOb, (i+1)), scene); + bMats->ob_mats = MEM_callocN(sizeof(Material *) * (tot), "BrushMaterials"); + for (i = 0; i < tot; i++) { + bMats->ob_mats[i] = RE_init_sample_material(give_current_material(brushOb, (i + 1)), scene); } } bMats->tot = tot; @@ -2721,7 +2718,7 @@ static void dynamicPaint_freeBrushMaterials(BrushMaterials *bMats) /* Now process every material linked to this brush object */ if (bMats->ob_mats) { int i; - for (i=0; itot; i++) { + for (i = 0; i < bMats->tot; i++) { RE_free_sample_material(bMats->ob_mats[i]); } MEM_freeN(bMats->ob_mats); @@ -2732,8 +2729,8 @@ static void dynamicPaint_freeBrushMaterials(BrushMaterials *bMats) } /* -* Get material diffuse color and alpha (including linked textures) in given coordinates -*/ + * Get material diffuse color and alpha (including linked textures) in given coordinates + */ void dynamicPaint_doMaterialTex(BrushMaterials *bMats, float color[3], float *alpha, Object *brushOb, const float volume_co[3], const float surface_co[3], int faceIndex, short isQuad, DerivedMesh *orcoDm) { Material *mat = bMats->mat; @@ -2745,7 +2742,7 @@ void dynamicPaint_doMaterialTex(BrushMaterials *bMats, float color[3], float *al int mat_nr = mface[faceIndex].mat_nr; if (mat_nr >= (*give_totcolp(brushOb))) return; mat = bMats->ob_mats[mat_nr]; - if (mat == NULL) return; /* No material assigned */ + if (mat == NULL) return; /* No material assigned */ } else return; } @@ -2758,26 +2755,25 @@ void dynamicPaint_doMaterialTex(BrushMaterials *bMats, float color[3], float *al /* A modified callback to bvh tree raycast. The tree must bust have been built using bvhtree_from_mesh_faces. -* 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. -* If ray hit the second half of a quad, no[0] is set to 1.0f. -*/ + * 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. + * If ray hit the second half of a quad, no[0] is set to 1.0f. + */ static void mesh_faces_spherecast_dp(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit) { - const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata; - MVert *vert = data->vert; + const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata; + MVert *vert = data->vert; MFace *face = data->face + index; short quad = 0; float *t0, *t1, *t2, *t3; - t0 = vert[ face->v1 ].co; - t1 = vert[ face->v2 ].co; - t2 = vert[ face->v3 ].co; - t3 = face->v4 ? vert[ face->v4].co : NULL; + t0 = vert[face->v1].co; + t1 = vert[face->v2].co; + t2 = vert[face->v3].co; + t3 = face->v4 ? vert[face->v4].co : NULL; - do - { + do { float dist = bvhtree_ray_tri_intersection(ray, hit->dist, t0, t1, t2); if (dist >= 0 && dist < hit->dist) { @@ -2795,26 +2791,25 @@ static void mesh_faces_spherecast_dp(void *userdata, int index, const BVHTreeRay } /* A modified callback to bvh tree nearest point. The tree must bust have been built using bvhtree_from_mesh_faces. -* userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. -* -* To optimize brush detection speed this doesn't calculate hit normal. -* If ray hit the second half of a quad, no[0] is set to 1.0f, else 0.0f -*/ + * userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. + * + * To optimize brush detection speed this doesn't calculate hit normal. + * If ray hit the second half of a quad, no[0] is set to 1.0f, else 0.0f + */ static void mesh_faces_nearest_point_dp(void *userdata, int index, const float co[3], BVHTreeNearest *nearest) { - const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata; - MVert *vert = data->vert; + const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata; + MVert *vert = data->vert; MFace *face = data->face + index; short quad = 0; float *t0, *t1, *t2, *t3; - t0 = vert[ face->v1 ].co; - t1 = vert[ face->v2 ].co; - t2 = vert[ face->v3 ].co; - t3 = face->v4 ? vert[ face->v4].co : NULL; + t0 = vert[face->v1].co; + t1 = vert[face->v2].co; + t2 = vert[face->v3].co; + t3 = face->v4 ? vert[face->v4].co : NULL; - do - { + do { float nearest_tmp[3], dist; int vertex, edge; @@ -2838,18 +2833,18 @@ static void mesh_faces_nearest_point_dp(void *userdata, int index, const float c /***************************** Brush Painting Calls ******************************/ /* -* Mix color values to canvas point. -* -* surface : canvas surface -* index : surface point index -* paintFlags : paint object flags -* paintColor,Alpha,Wetness : to be mixed paint values -* timescale : value used to adjust time dependand -* operations when using substeps -*/ + * Mix color values to canvas point. + * + * surface : canvas surface + * index : surface point index + * paintFlags : paint object flags + * paintColor,Alpha,Wetness : to be mixed paint values + * timescale : value used to adjust time dependand + * operations when using substeps + */ static void dynamicPaint_mixPaintColors(DynamicPaintSurface *surface, int index, int paintFlags, float *paintColor, float *paintAlpha, float *paintWetness, float *timescale) { - PaintPoint *pPoint = &((PaintPoint*)surface->data->type_data)[index]; + PaintPoint *pPoint = &((PaintPoint *)surface->data->type_data)[index]; /* Add paint */ if (!(paintFlags & MOD_DPAINT_ERASE)) { @@ -2870,10 +2865,10 @@ static void dynamicPaint_mixPaintColors(DynamicPaintSurface *surface, int index, float wetness = (*paintWetness); CLAMP(wetness, 0.0f, 1.0f); pPoint->e_alpha = mix[3]; - pPoint->wetness = pPoint->wetness*(1.0f-wetness) + wetness; + pPoint->wetness = pPoint->wetness * (1.0f - wetness) + wetness; } - if (pPoint->wetnesswetness = MIN_WETNESS; + if (pPoint->wetness < MIN_WETNESS) pPoint->wetness = MIN_WETNESS; pPoint->state = DPAINT_PAINT_NEW; } @@ -2884,9 +2879,9 @@ static void dynamicPaint_mixPaintColors(DynamicPaintSurface *surface, int index, float invFact = 1.0f - (*paintAlpha); /* - * Make highest alpha to match erased value - * but maintain alpha ratio - */ + * Make highest alpha to match erased value + * but maintain alpha ratio + */ if (paintFlags & MOD_DPAINT_ABS_ALPHA) { a_highest = (pPoint->e_alpha > pPoint->alpha) ? pPoint->e_alpha : pPoint->alpha; if (a_highest > invFact) { @@ -2937,100 +2932,100 @@ static void dynamicPaint_mixWaveHeight(PaintWavePoint *wPoint, DynamicPaintBrush wPoint->state = DPAINT_WAVE_REFLECT_ONLY; else if (brush->wave_type == MOD_DPAINT_WAVEB_CHANGE) { if (isect_change < 0.0f) - wPoint->height += isect_change*brush->wave_factor; + wPoint->height += isect_change * brush->wave_factor; } } } /* -* add brush results to the surface data depending on surface type -*/ + * add brush results to the surface data depending on surface type + */ static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned int index, DynamicPaintBrushSettings *brush, - float paint[3], float influence, float depth, float vel_factor, float timescale) + float paint[3], float influence, float depth, float vel_factor, float timescale) { - PaintSurfaceData *sData = surface->data; - float strength; - - /* apply influence scale */ - influence *= surface->influence_scale; - depth *= surface->influence_scale; - - strength = influence * brush->alpha; - CLAMP(strength, 0.0f, 1.0f); - - /* Sample velocity colorband if required */ - if (brush->flags & (MOD_DPAINT_VELOCITY_ALPHA|MOD_DPAINT_VELOCITY_COLOR|MOD_DPAINT_VELOCITY_DEPTH)) { - float coba_res[4]; - vel_factor /= brush->max_velocity; - CLAMP(vel_factor, 0.0f, 1.0f); - - if (do_colorband(brush->vel_ramp, vel_factor, coba_res)) { - if (brush->flags & MOD_DPAINT_VELOCITY_COLOR) { - paint[0] = coba_res[0]; - paint[1] = coba_res[1]; - paint[2] = coba_res[2]; - } - if (brush->flags & MOD_DPAINT_VELOCITY_ALPHA) - strength *= coba_res[3]; - if (brush->flags & MOD_DPAINT_VELOCITY_DEPTH) - depth *= coba_res[3]; + PaintSurfaceData *sData = surface->data; + float strength; + + /* apply influence scale */ + influence *= surface->influence_scale; + depth *= surface->influence_scale; + + strength = influence * brush->alpha; + CLAMP(strength, 0.0f, 1.0f); + + /* Sample velocity colorband if required */ + if (brush->flags & (MOD_DPAINT_VELOCITY_ALPHA | MOD_DPAINT_VELOCITY_COLOR | MOD_DPAINT_VELOCITY_DEPTH)) { + float coba_res[4]; + vel_factor /= brush->max_velocity; + CLAMP(vel_factor, 0.0f, 1.0f); + + if (do_colorband(brush->vel_ramp, vel_factor, coba_res)) { + if (brush->flags & MOD_DPAINT_VELOCITY_COLOR) { + paint[0] = coba_res[0]; + paint[1] = coba_res[1]; + paint[2] = coba_res[2]; } + if (brush->flags & MOD_DPAINT_VELOCITY_ALPHA) + strength *= coba_res[3]; + if (brush->flags & MOD_DPAINT_VELOCITY_DEPTH) + depth *= coba_res[3]; } + } - /* mix paint surface */ - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - - float paintWetness = brush->wetness * strength; - float paintAlpha = strength; + /* mix paint surface */ + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - dynamicPaint_mixPaintColors(surface, index, brush->flags, paint, &paintAlpha, &paintWetness, ×cale); + float paintWetness = brush->wetness * strength; + float paintAlpha = strength; - } - /* displace surface */ - else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) { - float *value = (float*)sData->type_data; + dynamicPaint_mixPaintColors(surface, index, brush->flags, paint, &paintAlpha, &paintWetness, ×cale); - if (surface->flags & MOD_DPAINT_DISP_INCREMENTAL) - depth = value[index] + depth; + } + /* displace surface */ + else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) { + float *value = (float *)sData->type_data; - if (surface->depth_clamp) { - CLAMP(depth, 0.0f-surface->depth_clamp, surface->depth_clamp); - } + if (surface->flags & MOD_DPAINT_DISP_INCREMENTAL) + depth = value[index] + depth; - if (brush->flags & MOD_DPAINT_ERASE) { - value[index] *= (1.0f - strength); - if (value[index] < 0.0f) value[index] = 0.0f; - } - else { - if (value[index] < depth) value[index] = depth; - } + if (surface->depth_clamp) { + CLAMP(depth, 0.0f - surface->depth_clamp, surface->depth_clamp); } - /* vertex weight group surface */ - else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) { - float *value = (float*)sData->type_data; - if (brush->flags & MOD_DPAINT_ERASE) { - value[index] *= (1.0f - strength); - if (value[index] < 0.0f) value[index] = 0.0f; - } - else { - if (value[index] < strength) value[index] = strength; - } + if (brush->flags & MOD_DPAINT_ERASE) { + value[index] *= (1.0f - strength); + if (value[index] < 0.0f) value[index] = 0.0f; } - /* wave surface */ - else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) { - if (brush->wave_clamp) { - CLAMP(depth, 0.0f-brush->wave_clamp, brush->wave_clamp); - } - - dynamicPaint_mixWaveHeight(&((PaintWavePoint*)sData->type_data)[index], - brush, 0.0f-depth); + else { + if (value[index] < depth) value[index] = depth; } + } + /* vertex weight group surface */ + else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) { + float *value = (float *)sData->type_data; - /* doing velocity based painting */ - if (sData->bData->brush_velocity) { - sData->bData->brush_velocity[index*4+3] *= influence; + if (brush->flags & MOD_DPAINT_ERASE) { + value[index] *= (1.0f - strength); + if (value[index] < 0.0f) value[index] = 0.0f; + } + else { + if (value[index] < strength) value[index] = strength; + } + } + /* wave surface */ + else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) { + if (brush->wave_clamp) { + CLAMP(depth, 0.0f - brush->wave_clamp, brush->wave_clamp); } + + dynamicPaint_mixWaveHeight(&((PaintWavePoint *)sData->type_data)[index], + brush, 0.0f - depth); + } + + /* doing velocity based painting */ + if (sData->bData->brush_velocity) { + sData->bData->brush_velocity[index * 4 + 3] *= influence; + } } /* checks whether surface and brush bounds intersect depending on brush type */ @@ -3081,17 +3076,17 @@ static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, Dy numOfVerts_c = dm_c->getNumVerts(dm_c); mvert_c = dm_p->getVertArray(dm_c); - (*brushVel) = (struct Vec3f *) MEM_mallocN(numOfVerts_c*sizeof(Vec3f), "Dynamic Paint brush velocity"); + (*brushVel) = (struct Vec3f *) MEM_mallocN(numOfVerts_c * sizeof(Vec3f), "Dynamic Paint brush velocity"); if (!(*brushVel)) return; /* if mesh is constructive -> num of verts has changed, - * only use current frame derived mesh */ + * only use current frame derived mesh */ if (numOfVerts_p != numOfVerts_c) mvert_p = mvert_c; /* calculate speed */ #pragma omp parallel for schedule(static) - for (i=0; iobmat, p2); sub_v3_v3v3((*brushVel)[i].v, p2, p1); - mul_v3_fl((*brushVel)[i].v, 1.0f/timescale); + mul_v3_fl((*brushVel)[i].v, 1.0f / timescale); } dm_p->release(dm_p); @@ -3139,12 +3134,12 @@ static void dynamicPaint_brushObjectCalculateVelocity(Scene *scene, Object *ob, mul_m4_v3(ob->obmat, cur_loc); sub_v3_v3v3(brushVel->v, cur_loc, prev_loc); - mul_v3_fl(brushVel->v, 1.0f/timescale); + mul_v3_fl(brushVel->v, 1.0f / timescale); } /* -* Paint a brush object mesh to the surface -*/ + * Paint a brush object mesh to the surface + */ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, DynamicPaintBrushSettings *brush, Object *brushOb, @@ -3178,9 +3173,9 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, numOfVerts = dm->getNumVerts(dm); /* Transform collider vertices to global space - * (Faster than transforming per surface point - * coordinates and normals to object space) */ - for (ii=0; iiobmat, mvert[ii].co); boundInsert(&mesh_bb, mvert[ii].co); @@ -3196,7 +3191,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, } if (brush->flags & MOD_DPAINT_PROX_PROJECT && brush->collision != MOD_DPAINT_COL_VOLUME) { - mul_v3_fl(avg_brushNor, 1.0f/(float)numOfVerts); + mul_v3_fl(avg_brushNor, 1.0f / (float)numOfVerts); /* instead of null vector use positive z */ if (!(MIN3(avg_brushNor[0], avg_brushNor[1], avg_brushNor[2]))) avg_brushNor[2] = 1.0f; @@ -3205,316 +3200,318 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, } /* check bounding box collision */ - if (grid && meshBrush_boundsIntersect(&grid->grid_bounds, &mesh_bb, brush, brush_radius)) - /* Build a bvh tree from transformed vertices */ - if (bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 8)) { - int c_index; - int total_cells = grid->dim[0]*grid->dim[1]*grid->dim[2]; - - /* loop through space partitioning grid */ - for (c_index=0; c_indexgrid_bounds, &mesh_bb, brush, brush_radius)) { + /* Build a bvh tree from transformed vertices */ + if (bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 8)) { + int c_index; + int total_cells = grid->dim[0] * grid->dim[1] * grid->dim[2]; + + /* loop through space partitioning grid */ + for (c_index = 0; c_index < total_cells; c_index++) { + int id; - /* check grid cell bounding box */ - if (!grid->s_num[c_index] || !meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush, brush_radius)) - continue; + /* check grid cell bounding box */ + if (!grid->s_num[c_index] || !meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush, brush_radius)) + continue; - /* loop through cell points and process brush */ + /* loop through cell points and process brush */ #pragma omp parallel for schedule(static) - for (id = 0; id < grid->s_num[c_index]; id++) { - int index = grid->t_index[grid->s_pos[c_index] + id]; - int ss, samples = bData->s_num[index]; - float total_sample = (float)samples; - float brushStrength = 0.0f; /* brush influence factor */ - float depth = 0.0f; /* brush intersection depth */ - float velocity_val = 0.0f; - - float paintColor[3] = {0.0f}; - int numOfHits = 0; - - /* for image sequence anti-aliasing, use gaussian factors */ - if (samples > 1 && surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) - total_sample = gaussianTotal; - - /* Supersampling */ - for (ss=0; ssflags & MOD_DPAINT_INVERSE_PROX && - brush->collision == MOD_DPAINT_COL_VOLDIST); - - /* hit data */ - float hitCoord[3]; - int hitFace = -1; - short hitQuad = 0; - - /* Supersampling factor */ + for (id = 0; id < grid->s_num[c_index]; id++) { + int index = grid->t_index[grid->s_pos[c_index] + id]; + int ss, samples = bData->s_num[index]; + float total_sample = (float)samples; + float brushStrength = 0.0f; /* brush influence factor */ + float depth = 0.0f; /* brush intersection depth */ + float velocity_val = 0.0f; + + float paintColor[3] = {0.0f}; + int numOfHits = 0; + + /* for image sequence anti-aliasing, use gaussian factors */ if (samples > 1 && surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) - sample_factor = gaussianFactors[ss]; - else - sample_factor = 1.0f; - - /* Get current sample position in world coordinates */ - copy_v3_v3(ray_start, bData->realCoord[bData->s_pos[index]+ss].v); - copy_v3_v3(ray_dir, bData->bNormal[index].invNorm); - - /* a simple hack to minimize chance of ray leaks at identical ray <-> edge locations */ - add_v3_fl(ray_start, 0.001f); - - hit.index = -1; - hit.dist = 9999; - nearest.index = -1; - nearest.dist = brush_radius * brush_radius; /* find_nearest uses squared distance */ - - /* Check volume collision */ - if (brush->collision == MOD_DPAINT_COL_VOLUME || brush->collision == MOD_DPAINT_COL_VOLDIST) - if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1) { - /* We hit a triangle, now check if collision point normal is facing the point */ - - /* For optimization sake, hit point normal isn't calculated in ray cast loop */ - int v1=mface[hit.index].v1, v2=mface[hit.index].v2, v3=mface[hit.index].v3, quad=(hit.no[0] == 1.0f); - float dot; - - if (quad) {v2=mface[hit.index].v3; v3=mface[hit.index].v4;} - normal_tri_v3(hit.no, mvert[v1].co, mvert[v2].co, mvert[v3].co); - dot = ray_dir[0]*hit.no[0] + ray_dir[1]*hit.no[1] + ray_dir[2]*hit.no[2]; - - /* If ray and hit face normal are facing same direction - * hit point is inside a closed mesh. */ - if (dot>=0) { - float dist = hit.dist; - int f_index = hit.index; - - /* Also cast a ray in opposite direction to make sure - * point is at least surrounded by two brush faces */ - negate_v3(ray_dir); - hit.index = -1; - hit.dist = 9999; - - BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData); - - if (hit.index != -1) { - /* Add factor on supersample filter */ - volume_factor = 1.0f; - hit_found = HIT_VOLUME; - - /* Mark hit info */ - madd_v3_v3v3fl(hitCoord, ray_start, ray_dir, hit.dist); /* Calculate final hit coordinates */ - depth += dist*sample_factor; - hitFace = f_index; - hitQuad = quad; - } - } - } + total_sample = gaussianTotal; - /* Check proximity collision */ - if ((brush->collision == MOD_DPAINT_COL_DIST || brush->collision == MOD_DPAINT_COL_VOLDIST) && - (!hit_found || (brush->flags & MOD_DPAINT_INVERSE_PROX))) - { - float proxDist = -1.0f; - float hitCo[3]; - short hQuad; - int face; - - /* if inverse prox and no hit found, skip this sample */ - if (inner_proximity && !hit_found) continue; - - /* If pure distance proximity, find the nearest point on the mesh */ - if (!(brush->flags & MOD_DPAINT_PROX_PROJECT)) { - if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, mesh_faces_nearest_point_dp, &treeData) != -1) { - proxDist = sqrtf(nearest.dist); - copy_v3_v3(hitCo, nearest.co); - hQuad = (nearest.no[0] == 1.0f); - face = nearest.index; + /* Supersampling */ + for (ss = 0; ss < samples; ss++) { + + float ray_start[3], ray_dir[3]; + float sample_factor = 0.0f; + float sampleStrength = 0.0f; + BVHTreeRayHit hit; + BVHTreeNearest nearest; + short hit_found = 0; + + /* volume sample */ + float volume_factor = 0.0f; + /* proximity sample */ + float proximity_factor = 0.0f; + float prox_colorband[4] = {0.0f}; + int inner_proximity = (brush->flags & MOD_DPAINT_INVERSE_PROX && + brush->collision == MOD_DPAINT_COL_VOLDIST); + + /* hit data */ + float hitCoord[3]; + int hitFace = -1; + short hitQuad = 0; + + /* Supersampling factor */ + if (samples > 1 && surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) + sample_factor = gaussianFactors[ss]; + else + sample_factor = 1.0f; + + /* Get current sample position in world coordinates */ + copy_v3_v3(ray_start, bData->realCoord[bData->s_pos[index] + ss].v); + copy_v3_v3(ray_dir, bData->bNormal[index].invNorm); + + /* a simple hack to minimize chance of ray leaks at identical ray <-> edge locations */ + add_v3_fl(ray_start, 0.001f); + + hit.index = -1; + hit.dist = 9999; + nearest.index = -1; + nearest.dist = brush_radius * brush_radius; /* find_nearest uses squared distance */ + + /* Check volume collision */ + if (brush->collision == MOD_DPAINT_COL_VOLUME || brush->collision == MOD_DPAINT_COL_VOLDIST) + if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1) { + /* We hit a triangle, now check if collision point normal is facing the point */ + + /* For optimization sake, hit point normal isn't calculated in ray cast loop */ + int v1 = mface[hit.index].v1, v2 = mface[hit.index].v2, v3 = mface[hit.index].v3, quad = (hit.no[0] == 1.0f); + float dot; + + if (quad) {v2 = mface[hit.index].v3; v3 = mface[hit.index].v4; } + normal_tri_v3(hit.no, mvert[v1].co, mvert[v2].co, mvert[v3].co); + dot = ray_dir[0] * hit.no[0] + ray_dir[1] * hit.no[1] + ray_dir[2] * hit.no[2]; + + /* If ray and hit face normal are facing same direction + * hit point is inside a closed mesh. */ + if (dot >= 0) { + float dist = hit.dist; + int f_index = hit.index; + + /* Also cast a ray in opposite direction to make sure + * point is at least surrounded by two brush faces */ + negate_v3(ray_dir); + hit.index = -1; + hit.dist = 9999; + + BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData); + + if (hit.index != -1) { + /* Add factor on supersample filter */ + volume_factor = 1.0f; + hit_found = HIT_VOLUME; + + /* Mark hit info */ + madd_v3_v3v3fl(hitCoord, ray_start, ray_dir, hit.dist); /* Calculate final hit coordinates */ + depth += dist * sample_factor; + hitFace = f_index; + hitQuad = quad; + } + } } - } - else { /* else cast a ray in defined projection direction */ - float proj_ray[3] = {0.0f}; - if (brush->ray_dir == MOD_DPAINT_RAY_CANVAS) { - copy_v3_v3(proj_ray, bData->bNormal[index].invNorm); - negate_v3(proj_ray); - } - else if (brush->ray_dir == MOD_DPAINT_RAY_BRUSH_AVG) { - copy_v3_v3(proj_ray, avg_brushNor); - } - else { /* MOD_DPAINT_RAY_ZPLUS */ - proj_ray[2] = 1.0f; + /* Check proximity collision */ + if ((brush->collision == MOD_DPAINT_COL_DIST || brush->collision == MOD_DPAINT_COL_VOLDIST) && + (!hit_found || (brush->flags & MOD_DPAINT_INVERSE_PROX))) + { + float proxDist = -1.0f; + float hitCo[3]; + short hQuad; + int face; + + /* if inverse prox and no hit found, skip this sample */ + if (inner_proximity && !hit_found) continue; + + /* If pure distance proximity, find the nearest point on the mesh */ + if (!(brush->flags & MOD_DPAINT_PROX_PROJECT)) { + if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, mesh_faces_nearest_point_dp, &treeData) != -1) { + proxDist = sqrtf(nearest.dist); + copy_v3_v3(hitCo, nearest.co); + hQuad = (nearest.no[0] == 1.0f); + face = nearest.index; + } } - hit.index = -1; - hit.dist = brush_radius; - - /* Do a face normal directional raycast, and use that distance */ - if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, proj_ray, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1) { - proxDist = hit.dist; - madd_v3_v3v3fl(hitCo, ray_start, proj_ray, hit.dist); /* Calculate final hit coordinates */ - hQuad = (hit.no[0] == 1.0f); - face = hit.index; + else { /* else cast a ray in defined projection direction */ + float proj_ray[3] = {0.0f}; + + if (brush->ray_dir == MOD_DPAINT_RAY_CANVAS) { + copy_v3_v3(proj_ray, bData->bNormal[index].invNorm); + negate_v3(proj_ray); + } + else if (brush->ray_dir == MOD_DPAINT_RAY_BRUSH_AVG) { + copy_v3_v3(proj_ray, avg_brushNor); + } + else { /* MOD_DPAINT_RAY_ZPLUS */ + proj_ray[2] = 1.0f; + } + hit.index = -1; + hit.dist = brush_radius; + + /* Do a face normal directional raycast, and use that distance */ + if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, proj_ray, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1) { + proxDist = hit.dist; + madd_v3_v3v3fl(hitCo, ray_start, proj_ray, hit.dist); /* Calculate final hit coordinates */ + hQuad = (hit.no[0] == 1.0f); + face = hit.index; + } } - } - /* If a hit was found, calculate required values */ - if (proxDist >= 0.0f && proxDist <= brush_radius) { - proximity_factor = proxDist / brush_radius; - CLAMP(proximity_factor, 0.0f, 1.0f); - if (!inner_proximity) - proximity_factor = 1.0f - proximity_factor; + /* If a hit was found, calculate required values */ + if (proxDist >= 0.0f && proxDist <= brush_radius) { + proximity_factor = proxDist / brush_radius; + CLAMP(proximity_factor, 0.0f, 1.0f); + if (!inner_proximity) + proximity_factor = 1.0f - proximity_factor; - hit_found = HIT_PROXIMITY; + hit_found = HIT_PROXIMITY; - /* if no volume hit, use prox point face info */ - if (hitFace == -1) { - copy_v3_v3(hitCoord, hitCo); - hitQuad = hQuad; - hitFace = face; + /* if no volume hit, use prox point face info */ + if (hitFace == -1) { + copy_v3_v3(hitCoord, hitCo); + hitQuad = hQuad; + hitFace = face; + } } } - } - /* mix final sample strength depending on brush settings */ - if (hit_found) { - /* if "negate volume" enabled, negate all factors within volume*/ - if (brush->collision == MOD_DPAINT_COL_VOLDIST && brush->flags & MOD_DPAINT_NEGATE_VOLUME) { - volume_factor = 1.0f - volume_factor; - if (inner_proximity) - proximity_factor = 1.0f - proximity_factor; - } + /* mix final sample strength depending on brush settings */ + if (hit_found) { + /* if "negate volume" enabled, negate all factors within volume*/ + if (brush->collision == MOD_DPAINT_COL_VOLDIST && brush->flags & MOD_DPAINT_NEGATE_VOLUME) { + volume_factor = 1.0f - volume_factor; + if (inner_proximity) + proximity_factor = 1.0f - proximity_factor; + } - /* apply final sample depending on final hit type */ - if (hit_found == HIT_VOLUME) { - sampleStrength = volume_factor; - } - else if (hit_found == HIT_PROXIMITY) { - /* apply falloff curve to the proximity_factor */ - if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && do_colorband(brush->paint_ramp, (1.0f-proximity_factor), prox_colorband)) - proximity_factor = prox_colorband[3]; - else if (brush->proximity_falloff == MOD_DPAINT_PRFALL_CONSTANT) - proximity_factor = (!inner_proximity || brush->flags & MOD_DPAINT_NEGATE_VOLUME) ? 1.0f : 0.0f; - /* apply sample */ - sampleStrength = proximity_factor; - } + /* apply final sample depending on final hit type */ + if (hit_found == HIT_VOLUME) { + sampleStrength = volume_factor; + } + else if (hit_found == HIT_PROXIMITY) { + /* apply falloff curve to the proximity_factor */ + if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && do_colorband(brush->paint_ramp, (1.0f - proximity_factor), prox_colorband)) + proximity_factor = prox_colorband[3]; + else if (brush->proximity_falloff == MOD_DPAINT_PRFALL_CONSTANT) + proximity_factor = (!inner_proximity || brush->flags & MOD_DPAINT_NEGATE_VOLUME) ? 1.0f : 0.0f; + /* apply sample */ + sampleStrength = proximity_factor; + } - sampleStrength *= sample_factor; - } - else continue; - - /* velocity brush, only do on main sample */ - if (brush->flags & MOD_DPAINT_USES_VELOCITY && ss==0 && brushVelocity) { - int v1, v2, v3; - float weights[4]; - float brushPointVelocity[3]; - float velocity[3]; - - if (!hitQuad) { - v1 = mface[hitFace].v1; - v2 = mface[hitFace].v2; - v3 = mface[hitFace].v3; - } - else { - v1 = mface[hitFace].v2; - v2 = mface[hitFace].v3; - v3 = mface[hitFace].v4; + sampleStrength *= sample_factor; } - /* calculate barycentric weights for hit point */ - interp_weights_face_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, NULL, hitCoord); + else continue; + + /* velocity brush, only do on main sample */ + if (brush->flags & MOD_DPAINT_USES_VELOCITY && ss == 0 && brushVelocity) { + int v1, v2, v3; + float weights[4]; + float brushPointVelocity[3]; + float velocity[3]; + + if (!hitQuad) { + v1 = mface[hitFace].v1; + v2 = mface[hitFace].v2; + v3 = mface[hitFace].v3; + } + else { + v1 = mface[hitFace].v2; + v2 = mface[hitFace].v3; + v3 = mface[hitFace].v4; + } + /* calculate barycentric weights for hit point */ + interp_weights_face_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, NULL, hitCoord); - /* simple check based on brush surface velocity, - * todo: perhaps implement something that handles volume movement as well */ + /* simple check based on brush surface velocity, + * todo: perhaps implement something that handles volume movement as well */ - /* interpolate vertex speed vectors to get hit point velocity */ - interp_v3_v3v3v3(brushPointVelocity, - brushVelocity[v1].v, - brushVelocity[v2].v, - brushVelocity[v3].v, weights); - - /* substract canvas point velocity */ - if (bData->velocity) { - sub_v3_v3v3(velocity, brushPointVelocity, bData->velocity[index].v); - } - else { - copy_v3_v3(velocity, brushPointVelocity); - } - velocity_val = len_v3(velocity); - - /* if brush has smudge enabled store brush velocity */ - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && - brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) { - copy_v3_v3(&bData->brush_velocity[index*4], velocity); - mul_v3_fl(&bData->brush_velocity[index*4], 1.0f/velocity_val); - bData->brush_velocity[index*4+3] = velocity_val; + /* interpolate vertex speed vectors to get hit point velocity */ + interp_v3_v3v3v3(brushPointVelocity, + brushVelocity[v1].v, + brushVelocity[v2].v, + brushVelocity[v3].v, weights); + + /* substract canvas point velocity */ + if (bData->velocity) { + sub_v3_v3v3(velocity, brushPointVelocity, bData->velocity[index].v); + } + else { + copy_v3_v3(velocity, brushPointVelocity); + } + velocity_val = len_v3(velocity); + + /* if brush has smudge enabled store brush velocity */ + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && + brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) + { + copy_v3_v3(&bData->brush_velocity[index * 4], velocity); + mul_v3_fl(&bData->brush_velocity[index * 4], 1.0f / velocity_val); + bData->brush_velocity[index * 4 + 3] = velocity_val; + } } - } - /* - * Process hit color and alpha - */ - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - float sampleColor[3]; - float alpha_factor = 1.0f; - - sampleColor[0] = brush->r; - sampleColor[1] = brush->g; - sampleColor[2] = brush->b; - - /* Get material+textures color on hit point if required */ - if (brush_usesMaterial(brush, scene)) - dynamicPaint_doMaterialTex(bMats, sampleColor, &alpha_factor, brushOb, bData->realCoord[bData->s_pos[index]+ss].v, hitCoord, hitFace, hitQuad, brush->dm); - - /* Sample proximity colorband if required */ - if ((hit_found == HIT_PROXIMITY) && (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP)) { - if (!(brush->flags & MOD_DPAINT_RAMP_ALPHA)) { - sampleColor[0] = prox_colorband[0]; - sampleColor[1] = prox_colorband[1]; - sampleColor[2] = prox_colorband[2]; + /* + * Process hit color and alpha + */ + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { + float sampleColor[3]; + float alpha_factor = 1.0f; + + sampleColor[0] = brush->r; + sampleColor[1] = brush->g; + sampleColor[2] = brush->b; + + /* Get material+textures color on hit point if required */ + if (brush_usesMaterial(brush, scene)) + dynamicPaint_doMaterialTex(bMats, sampleColor, &alpha_factor, brushOb, bData->realCoord[bData->s_pos[index] + ss].v, hitCoord, hitFace, hitQuad, brush->dm); + + /* Sample proximity colorband if required */ + if ((hit_found == HIT_PROXIMITY) && (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP)) { + if (!(brush->flags & MOD_DPAINT_RAMP_ALPHA)) { + sampleColor[0] = prox_colorband[0]; + sampleColor[1] = prox_colorband[1]; + sampleColor[2] = prox_colorband[2]; + } } + + /* Add AA sample */ + paintColor[0] += sampleColor[0]; + paintColor[1] += sampleColor[1]; + paintColor[2] += sampleColor[2]; + sampleStrength *= alpha_factor; + numOfHits++; } - /* Add AA sample */ - paintColor[0] += sampleColor[0]; - paintColor[1] += sampleColor[1]; - paintColor[2] += sampleColor[2]; - sampleStrength *= alpha_factor; - numOfHits++; - } + /* apply sample strength */ + brushStrength += sampleStrength; + } // end supersampling - /* apply sample strength */ - brushStrength += sampleStrength; - } // end supersampling + /* if any sample was inside paint range */ + if (brushStrength > 0.0f || depth > 0.0f) { - /* if any sample was inside paint range */ - if (brushStrength > 0.0f || depth > 0.0f) { + /* apply supersampling results */ + if (samples > 1) { + brushStrength /= total_sample; + } + CLAMP(brushStrength, 0.0f, 1.0f); - /* apply supersampling results */ - if (samples > 1) { - brushStrength /= total_sample; - } - CLAMP(brushStrength, 0.0f, 1.0f); + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { + /* Get final pixel color and alpha */ + paintColor[0] /= numOfHits; + paintColor[1] /= numOfHits; + paintColor[2] /= numOfHits; + } + /* get final object space depth */ + else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || + surface->type == MOD_DPAINT_SURFACE_T_WAVE) { + depth /= bData->bNormal[index].normal_scale * total_sample; + } - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - /* Get final pixel color and alpha */ - paintColor[0] /= numOfHits; - paintColor[1] /= numOfHits; - paintColor[2] /= numOfHits; + dynamicPaint_updatePointData(surface, index, brush, paintColor, brushStrength, depth, velocity_val, timescale); } - /* get final object space depth */ - else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WAVE) { - depth /= bData->bNormal[index].normal_scale * total_sample; - } - - dynamicPaint_updatePointData(surface, index, brush, paintColor, brushStrength, depth, velocity_val, timescale); } } } @@ -3533,14 +3530,14 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, } /* -* Paint a particle system to the surface -*/ + * Paint a particle system to the surface + */ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, ParticleSystem *psys, DynamicPaintBrushSettings *brush, float timescale) { - ParticleSettings *part=psys->part; + ParticleSettings *part = psys->part; ParticleData *pa = NULL; PaintSurfaceData *sData = surface->data; PaintBakeData *bData = sData->bData; @@ -3551,8 +3548,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, int invalidParticles = 0; int p = 0; - float solidradius = surface->radius_scale*((brush->flags & MOD_DPAINT_PART_RAD) ? psys->part->size : brush->particle_radius); - float smooth = brush->particle_smooth*surface->radius_scale; + float solidradius = surface->radius_scale * ((brush->flags & MOD_DPAINT_PART_RAD) ? psys->part->size : brush->particle_radius); + float smooth = brush->particle_smooth * surface->radius_scale; float range = solidradius + smooth; float particle_timestep = 0.04f * part->timetweak; @@ -3562,21 +3559,21 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, if (psys->totpart < 1) return 1; /* - * Build a kd-tree to optimize distance search - */ - tree= BLI_kdtree_new(psys->totpart); + * Build a kd-tree to optimize distance search + */ + tree = BLI_kdtree_new(psys->totpart); /* loop through particles and insert valid ones to the tree */ - for (p=0, pa=psys->particles; ptotpart; p++, pa++) { + for (p = 0, pa = psys->particles; p < psys->totpart; p++, pa++) { /* Proceed only if particle is active */ - if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN)==0) continue; - else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0) continue; + if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN) == 0) continue; + else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED) == 0) continue; else if (pa->flag & PARS_UNEXIST) continue; /* for debug purposes check if any NAN particle proceeds - * For some reason they get past activity check, this should rule most of them out */ - if (isnan(pa->state.co[0]) || isnan(pa->state.co[1]) || isnan(pa->state.co[2])) {invalidParticles++;continue;} + * For some reason they get past activity check, this should rule most of them out */ + if (isnan(pa->state.co[0]) || isnan(pa->state.co[1]) || isnan(pa->state.co[2])) {invalidParticles++; continue; } /* make sure particle is close enough to canvas */ if (!boundIntersectPoint(&grid->grid_bounds, pa->state.co, range)) continue; @@ -3603,13 +3600,13 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* only continue if particle bb is close enough to canvas bb */ if (boundsIntersectDist(&grid->grid_bounds, &part_bb, range)) { int c_index; - int total_cells = grid->dim[0]*grid->dim[1]*grid->dim[2]; + int total_cells = grid->dim[0] * grid->dim[1] * grid->dim[2]; /* balance tree */ BLI_kdtree_balance(tree); /* loop through space partitioning grid */ - for (c_index=0; c_index dist = 0 */ smooth_range = (nearest.dist - part_solidradius); - if (smooth_range<0.0f) smooth_range=0.0f; + if (smooth_range < 0.0f) smooth_range = 0.0f; /* do smoothness if enabled */ - if (smooth) smooth_range/=smooth; + if (smooth) smooth_range /= smooth; strength = 1.0f - smooth_range; disp_intersect = radius - nearest.dist; @@ -3666,20 +3663,20 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* If using random per particle radius and closest particle didn't give max influence */ if (brush->flags & MOD_DPAINT_PART_RAD && strength < 1.0f && psys->part->randsize > 0.0f) { /* - * If we use per particle radius, we have to sample all particles - * within max radius range - */ + * If we use per particle radius, we have to sample all particles + * within max radius range + */ KDTreeNearest *nearest; int n, particles = 0; - float smooth_range = smooth * (1.0f-strength), dist; + float smooth_range = smooth * (1.0f - strength), dist; /* calculate max range that can have particles with higher influence than the nearest one */ - float max_range = smooth - strength*smooth + solidradius; + float max_range = smooth - strength * smooth + solidradius; particles = BLI_kdtree_range_search(tree, max_range, bData->realCoord[bData->s_pos[index]].v, NULL, &nearest); /* Find particle that produces highest influence */ - for (n=0; nparticles + nearest[n].index; float s_range; @@ -3712,14 +3709,14 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* now calculate influence for this particle */ { float rad = radius + smooth, str; - if ((rad-dist) > disp_intersect) { + if ((rad - dist) > disp_intersect) { disp_intersect = radius - dist; radius = rad; } /* do smoothness if enabled */ - if (smooth_range<0.0f) smooth_range=0.0f; - if (smooth) smooth_range/=smooth; + if (smooth_range < 0.0f) smooth_range = 0.0f; + if (smooth) smooth_range /= smooth; str = 1.0f - smooth_range; /* if influence is greater, use this one */ if (str > strength) strength = str; @@ -3746,9 +3743,9 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, if ( (surface->type == MOD_DPAINT_SURFACE_T_PAINT) && (brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity)) { - copy_v3_v3(&bData->brush_velocity[index*4], velocity); - mul_v3_fl(&bData->brush_velocity[index*4], 1.0f/velocity_val); - bData->brush_velocity[index*4+3] = velocity_val; + copy_v3_v3(&bData->brush_velocity[index * 4], velocity); + mul_v3_fl(&bData->brush_velocity[index * 4], 1.0f / velocity_val); + bData->brush_velocity[index * 4 + 3] = velocity_val; } } @@ -3758,10 +3755,10 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, else if ( (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) || (surface->type == MOD_DPAINT_SURFACE_T_WAVE)) { - /* get displace depth */ + /* get displace depth */ disp_intersect = (1.0f - sqrtf(disp_intersect / radius)) * radius; depth = (radius - disp_intersect) / bData->bNormal[index].normal_scale; - if (depth<0.0f) depth = 0.0f; + if (depth < 0.0f) depth = 0.0f; } dynamicPaint_updatePointData(surface, index, brush, paintColor, strength, depth, velocity_val, timescale); @@ -3789,8 +3786,8 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po dynamicPaint_brushObjectCalculateVelocity(scene, brushOb, &brushVel, timescale); /* - * Loop through every surface point - */ + * Loop through every surface point + */ #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { float distance = len_v3v3(pointCoord, bData->realCoord[bData->s_pos[index]].v); @@ -3801,7 +3798,7 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po /* Smooth range or color ramp */ if (brush->proximity_falloff == MOD_DPAINT_PRFALL_SMOOTH || - brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP) { + brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP) { strength = 1.0f - distance / brush_radius; CLAMP(strength, 0.0f, 1.0f); @@ -3826,7 +3823,7 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po } /* color ramp */ - if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && do_colorband(brush->paint_ramp, (1.0f-strength), colorband)) + if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && do_colorband(brush->paint_ramp, (1.0f - strength), colorband)) strength = colorband[3]; if (brush->flags & MOD_DPAINT_USES_VELOCITY) { @@ -3843,16 +3840,17 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po /* store brush velocity for smudge */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && - brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) { - copy_v3_v3(&bData->brush_velocity[index*4], velocity); - mul_v3_fl(&bData->brush_velocity[index*4], 1.0f/velocity_val); - bData->brush_velocity[index*4+3] = velocity_val; + brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) + { + copy_v3_v3(&bData->brush_velocity[index * 4], velocity); + mul_v3_fl(&bData->brush_velocity[index * 4], 1.0f / velocity_val); + bData->brush_velocity[index * 4 + 3] = velocity_val; } } if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && - !(brush->flags & MOD_DPAINT_RAMP_ALPHA)) { + !(brush->flags & MOD_DPAINT_RAMP_ALPHA)) { paintColor[0] = colorband[0]; paintColor[1] = colorband[1]; paintColor[2] = colorband[2]; @@ -3866,11 +3864,12 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po } } else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WAVE) { - /* get displace depth */ - float disp_intersect = (1.0f - sqrtf((brush_radius-distance) / brush_radius)) * brush_radius; + surface->type == MOD_DPAINT_SURFACE_T_WAVE) + { + /* get displace depth */ + float disp_intersect = (1.0f - sqrtf((brush_radius - distance) / brush_radius)) * brush_radius; depth = (brush_radius - disp_intersect) / bData->bNormal[index].normal_scale; - if (depth<0.0f) depth = 0.0f; + if (depth < 0.0f) depth = 0.0f; } dynamicPaint_updatePointData(surface, index, brush, paintColor, strength, depth, velocity_val, timescale); } @@ -3883,8 +3882,8 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po /***************************** Dynamic Paint Step / Baking ******************************/ /* -* Calculate current frame distances and directions for adjacency data -*/ + * Calculate current frame distances and directions for adjacency data + */ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int force_init) { PaintSurfaceData *sData = surface->data; @@ -3897,7 +3896,7 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int if ((!surface_usesAdjDistance(surface) && !force_init) || !sData->adj_data) return; if (bData->bNeighs) MEM_freeN(bData->bNeighs); - bNeighs = bData->bNeighs = MEM_mallocN(sData->adj_data->total_targets*sizeof(struct BakeAdjPoint), "PaintEffectBake"); + bNeighs = bData->bNeighs = MEM_mallocN(sData->adj_data->total_targets * sizeof(struct BakeAdjPoint), "PaintEffectBake"); if (!bNeighs) return; #pragma omp parallel for schedule(static) @@ -3905,8 +3904,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int int i; int numOfNeighs = adj_data->n_num[index]; - for (i=0; in_index[index]+i; + for (i = 0; i < numOfNeighs; i++) { + int n_index = adj_data->n_index[index] + i; int t_index = adj_data->n_target[n_index]; /* dir vec */ @@ -3914,7 +3913,7 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int /* dist */ bNeighs[n_index].dist = len_v3(bNeighs[n_index].dir); /* normalize dir */ - if (bNeighs[n_index].dist) mul_v3_fl(bNeighs[n_index].dir, 1.0f/bNeighs[n_index].dist); + if (bNeighs[n_index].dist) mul_v3_fl(bNeighs[n_index].dir, 1.0f / bNeighs[n_index].dist); } } @@ -3924,8 +3923,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int int i; int numOfNeighs = adj_data->n_num[index]; - for (i=0; iaverage_dist += (double)bNeighs[adj_data->n_index[index]+i].dist; + for (i = 0; i < numOfNeighs; i++) { + bData->average_dist += (double)bNeighs[adj_data->n_index[index] + i].dist; } } bData->average_dist /= adj_data->total_targets; @@ -3938,34 +3937,36 @@ void surface_determineForceTargetPoints(PaintSurfaceData *sData, int index, floa int numOfNeighs = sData->adj_data->n_num[index]; int i; - closest_id[0]=closest_id[1]= -1; - closest_d[0]=closest_d[1]= -1.0f; + closest_id[0] = closest_id[1] = -1; + closest_d[0] = closest_d[1] = -1.0f; /* find closest neigh */ - for (i=0; iadj_data->n_index[index]+i; + for (i = 0; i < numOfNeighs; i++) { + int n_index = sData->adj_data->n_index[index] + i; float dir_dot = dot_v3v3(bNeighs[n_index].dir, force); - if (dir_dot>closest_d[0] && dir_dot>0.0f) {closest_d[0]=dir_dot; closest_id[0]=n_index;} + if (dir_dot > closest_d[0] && dir_dot > 0.0f) {closest_d[0] = dir_dot; closest_id[0] = n_index; } } if (closest_d[0] < 0.0f) return; /* find second closest neigh */ - for (i=0; iadj_data->n_index[index]+i; + for (i = 0; i < numOfNeighs; i++) { + int n_index = sData->adj_data->n_index[index] + i; float dir_dot = dot_v3v3(bNeighs[n_index].dir, force); float closest_dot = dot_v3v3(bNeighs[n_index].dir, bNeighs[closest_id[0]].dir); if (n_index == closest_id[0]) continue; /* only accept neighbor at "other side" of the first one in relation to force dir - * so make sure angle between this and closest neigh is greater than first angle */ - if (dir_dot>closest_d[1] && closest_dot0.0f) {closest_d[1]=dir_dot; closest_id[1]=n_index;} + * so make sure angle between this and closest neigh is greater than first angle */ + if (dir_dot > closest_d[1] && closest_dot < closest_d[0] && dir_dot > 0.0f) { + closest_d[1] = dir_dot; closest_id[1] = n_index; + } } /* if two valid neighs found, calculate how force effect is divided - * evenly between them (so that d[0]+d[1] = 1.0)*/ + * evenly between them (so that d[0]+d[1] = 1.0)*/ if (closest_id[1] != -1) { float force_proj[3]; float tangent[3]; @@ -3974,28 +3975,28 @@ void surface_determineForceTargetPoints(PaintSurfaceData *sData, int index, floa float temp; /* project force vector on the plane determined by these two neightbour points - * and calculate relative force angle from it*/ + * and calculate relative force angle from it*/ cross_v3_v3v3(tangent, bNeighs[closest_id[0]].dir, bNeighs[closest_id[1]].dir); normalize_v3(tangent); force_intersect = dot_v3v3(force, tangent); - madd_v3_v3v3fl(force_proj, force, tangent, (-1.0f)*force_intersect); + madd_v3_v3v3fl(force_proj, force, tangent, (-1.0f) * force_intersect); normalize_v3(force_proj); /* get drip factor based on force dir in relation to angle between those neighbors */ temp = dot_v3v3(bNeighs[closest_id[0]].dir, force_proj); CLAMP(temp, -1.0f, 1.0f); /* float precision might cause values > 1.0f that return infinite */ - closest_d[1] = acosf(temp)/neigh_diff; + closest_d[1] = acosf(temp) / neigh_diff; closest_d[0] = 1.0f - closest_d[1]; /* and multiply depending on how deeply force intersects surface */ temp = fabs(force_intersect); CLAMP(temp, 0.0f, 1.0f); - closest_d[0] *= acosf(temp)/1.57079633f; - closest_d[1] *= acosf(temp)/1.57079633f; + closest_d[0] *= acosf(temp) / 1.57079633f; + closest_d[1] *= acosf(temp) / 1.57079633f; } else { /* if only single neighbor, still linearize force intersection effect */ - closest_d[0] = 1.0f - acosf(closest_d[0])/1.57079633f; + closest_d[0] = 1.0f - acosf(closest_d[0]) / 1.57079633f; } } @@ -4011,20 +4012,20 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus /* find max velocity */ for (index = 0; index < sData->total_points; index++) { - float vel = bData->brush_velocity[index*4+3]; + float vel = bData->brush_velocity[index * 4 + 3]; if (vel > max_velocity) max_velocity = vel; } steps = (int)ceil(max_velocity / bData->average_dist * timescale); CLAMP(steps, 0, 12); - eff_scale = brush->smudge_strength/(float)steps*timescale; + eff_scale = brush->smudge_strength / (float)steps * timescale; - for (step=0; steptotal_points; index++) { int i; - PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; - float smudge_str = bData->brush_velocity[index*4+3]; + PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; + float smudge_str = bData->brush_velocity[index * 4 + 3]; /* force targets */ int closest_id[2]; @@ -4033,15 +4034,15 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus if (!smudge_str) continue; /* get force affect points */ - surface_determineForceTargetPoints(sData, index, &bData->brush_velocity[index*4], closest_d, closest_id); + surface_determineForceTargetPoints(sData, index, &bData->brush_velocity[index * 4], closest_d, closest_id); /* Apply movement towards those two points */ - for (i=0; i<2; i++) { + for (i = 0; i < 2; i++) { int n_index = closest_id[i]; - if (n_index != -1 && closest_d[i]>0.0f) { + if (n_index != -1 && closest_d[i] > 0.0f) { float dir_dot = closest_d[i], dir_factor; - float speed_scale = eff_scale*smudge_str/bNeighs[n_index].dist; - PaintPoint *ePoint = &((PaintPoint*)sData->type_data)[sData->adj_data->n_target[n_index]]; + float speed_scale = eff_scale * smudge_str / bNeighs[n_index].dist; + PaintPoint *ePoint = &((PaintPoint *)sData->type_data)[sData->adj_data->n_target[n_index]]; /* just skip if angle is too extreme */ if (dir_dot <= 0.0f) continue; @@ -4051,12 +4052,12 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus /* mix new color and alpha */ mixColors(ePoint->color, ePoint->alpha, pPoint->color, pPoint->alpha, dir_factor); - ePoint->alpha = ePoint->alpha*(1.0f-dir_factor) + pPoint->alpha*dir_factor; + ePoint->alpha = ePoint->alpha * (1.0f - dir_factor) + pPoint->alpha * dir_factor; /* smudge "wet layer" */ mixColors(ePoint->e_color, ePoint->e_alpha, pPoint->e_color, pPoint->e_alpha, dir_factor); - ePoint->e_alpha = ePoint->e_alpha*(1.0f-dir_factor) + pPoint->e_alpha*dir_factor; - pPoint->wetness *= (1.0f-dir_factor); + ePoint->e_alpha = ePoint->e_alpha * (1.0f - dir_factor) + pPoint->e_alpha * dir_factor; + pPoint->wetness *= (1.0f - dir_factor); } } } @@ -4064,13 +4065,13 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus } /* -* Prepare data required by effects for current frame. -* Returns number of steps required -*/ + * Prepare data required by effects for current frame. + * Returns number of steps required + */ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *scene, Object *ob, float **force, float timescale) { double average_force = 0.0f; - float shrink_speed=0.0f, spread_speed=0.0f; + float shrink_speed = 0.0f, spread_speed = 0.0f; float fastest_effect, avg_dist; int steps; PaintSurfaceData *sData = surface->data; @@ -4084,7 +4085,7 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s ListBase *effectors = pdInitEffectors(scene, ob, NULL, surface->effector_weights); /* allocate memory for force data (dir vector + strength) */ - *force = MEM_mallocN(sData->total_points*4*sizeof(float), "PaintEffectForces"); + *force = MEM_mallocN(sData->total_points * 4 * sizeof(float), "PaintEffectForces"); if (*force) { #pragma omp parallel for schedule(static) @@ -4102,34 +4103,34 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s /* if global gravity is enabled, add it too */ if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) /* also divide by 10 to about match default grav - * with default force strength (1.0) */ + * with default force strength (1.0) */ madd_v3_v3fl(forc, scene->physics_settings.gravity, - surface->effector_weights->global_gravity*surface->effector_weights->weight[0] / 10.f); + surface->effector_weights->global_gravity * surface->effector_weights->weight[0] / 10.f); /* add surface point velocity and acceleration if enabled */ if (bData->velocity) { if (surface->drip_vel) - madd_v3_v3fl(forc, bData->velocity[index].v, surface->drip_vel*(-1.0f)); + madd_v3_v3fl(forc, bData->velocity[index].v, surface->drip_vel * (-1.0f)); /* acceleration */ if (bData->prev_velocity && surface->drip_acc) { float acc[3]; copy_v3_v3(acc, bData->velocity[index].v); sub_v3_v3(acc, bData->prev_velocity[index].v); - madd_v3_v3fl(forc, acc, surface->drip_acc*(-1.0f)); + madd_v3_v3fl(forc, acc, surface->drip_acc * (-1.0f)); } } /* force strength */ - (*force)[index*4+3] = len_v3(forc); + (*force)[index * 4 + 3] = len_v3(forc); /* normalize and copy */ - if ((*force)[index*4+3]) mul_v3_fl(forc, 1.0f/(*force)[index*4+3]); - copy_v3_v3(&((*force)[index*4]), forc); + if ((*force)[index * 4 + 3]) mul_v3_fl(forc, 1.0f / (*force)[index * 4 + 3]); + copy_v3_v3(&((*force)[index * 4]), forc); } /* calculate average values (single thread) */ for (index = 0; index < sData->total_points; index++) { - average_force += (*force)[index*4+3]; + average_force += (*force)[index * 4 + 3]; } average_force /= sData->total_points; } @@ -4137,7 +4138,7 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s } /* Get number of required steps using averate point distance - * so that just a few ultra close pixels wont up substeps to max */ + * so that just a few ultra close pixels wont up substeps to max */ /* adjust number of required substep by fastest active effect */ if (surface->effect & MOD_DPAINT_EFFECT_DO_SPREAD) @@ -4146,9 +4147,9 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s shrink_speed = surface->shrink_speed; fastest_effect = MAX3(spread_speed, shrink_speed, average_force); - avg_dist = bData->average_dist*CANVAS_REL_SIZE/getSurfaceDimension(sData); + avg_dist = bData->average_dist * CANVAS_REL_SIZE / getSurfaceDimension(sData); - steps = (int)ceil(1.5f*EFF_MOVEMENT_PER_FRAME*fastest_effect/avg_dist*timescale); + steps = (int)ceil(1.5f * EFF_MOVEMENT_PER_FRAME * fastest_effect / avg_dist * timescale); CLAMP(steps, 1, 20); return steps; @@ -4161,7 +4162,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force { PaintSurfaceData *sData = surface->data; BakeAdjPoint *bNeighs = sData->bData->bNeighs; - float distance_scale = getSurfaceDimension(sData)/CANVAS_REL_SIZE; + float distance_scale = getSurfaceDimension(sData) / CANVAS_REL_SIZE; int index; timescale /= steps; @@ -4171,39 +4172,39 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force * Spread Effect */ if (surface->effect & MOD_DPAINT_EFFECT_DO_SPREAD) { - float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*surface->spread_speed*timescale; + float eff_scale = distance_scale * EFF_MOVEMENT_PER_FRAME * surface->spread_speed * timescale; /* Copy current surface to the previous points array to read unmodified values */ - memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint)); + memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(struct PaintPoint)); #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { int i; int numOfNeighs = sData->adj_data->n_num[index]; - PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; + PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; /* Only reads values from the surface copy (prevPoint[]), * so this one is thread safe */ /* Loop through neighboring points */ - for (i=0; iadj_data->n_index[index]+i; + for (i = 0; i < numOfNeighs; i++) { + int n_index = sData->adj_data->n_index[index] + i; float w_factor; PaintPoint *ePoint = &prevPoint[sData->adj_data->n_target[n_index]]; - float speed_scale = (bNeighs[n_index].distwetness, pPoint->wetness, 1.0f))*0.25f*surface->color_spread_speed; + float speed_scale = (bNeighs[n_index].dist < eff_scale) ? 1.0f : eff_scale / bNeighs[n_index].dist; + float color_mix = (MIN3(ePoint->wetness, pPoint->wetness, 1.0f)) * 0.25f * surface->color_spread_speed; /* do color mixing */ if (color_mix) mixColors(pPoint->e_color, pPoint->e_alpha, ePoint->e_color, ePoint->e_alpha, color_mix); /* Only continue if surrounding point has higher wetness */ - if (ePoint->wetnesswetness || ePoint->wetnesswetness < pPoint->wetness || ePoint->wetness < MIN_WETNESS) continue; - w_factor = 1.0f/numOfNeighs * MIN2(ePoint->wetness, 1.0f) * speed_scale; + w_factor = 1.0f / numOfNeighs *MIN2(ePoint->wetness, 1.0f) * speed_scale; CLAMP(w_factor, 0.0f, 1.0f); /* mix new wetness and color */ - pPoint->wetness = (1.0f-w_factor)*pPoint->wetness + w_factor*ePoint->wetness; + pPoint->wetness = (1.0f - w_factor) * pPoint->wetness + w_factor * ePoint->wetness; pPoint->e_alpha = mixColors(pPoint->e_color, pPoint->e_alpha, ePoint->e_color, ePoint->e_alpha, w_factor); } } @@ -4213,21 +4214,21 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force * Shrink Effect */ if (surface->effect & MOD_DPAINT_EFFECT_DO_SHRINK) { - float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*surface->shrink_speed*timescale; + float eff_scale = distance_scale * EFF_MOVEMENT_PER_FRAME * surface->shrink_speed * timescale; /* Copy current surface to the previous points array to read unmodified values */ - memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint)); + memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(struct PaintPoint)); #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { int i; int numOfNeighs = sData->adj_data->n_num[index]; float totalAlpha = 0.0f; - PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; + PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; - for (i=0; iadj_data->n_index[index]+i; - float speed_scale = (bNeighs[n_index].distadj_data->n_index[index] + i; + float speed_scale = (bNeighs[n_index].dist < eff_scale) ? 1.0f : eff_scale / bNeighs[n_index].dist; PaintPoint *ePoint = &prevPoint[sData->adj_data->n_target[n_index]]; float a_factor, ea_factor, w_factor; @@ -4238,13 +4239,13 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force if (pPoint->alpha <= 0.0f && pPoint->e_alpha <= 0.0f && pPoint->wetness <= 0.0f) continue; /* decrease factor for dry paint alpha */ - a_factor = (1.0f - ePoint->alpha)/numOfNeighs * (pPoint->alpha - ePoint->alpha) * speed_scale; + a_factor = (1.0f - ePoint->alpha) / numOfNeighs * (pPoint->alpha - ePoint->alpha) * speed_scale; if (a_factor < 0.0f) a_factor = 0.0f; /* decrease factor for wet paint alpha */ - ea_factor = (1.0f - ePoint->e_alpha)/8 * (pPoint->e_alpha - ePoint->e_alpha) * speed_scale; + ea_factor = (1.0f - ePoint->e_alpha) / 8 * (pPoint->e_alpha - ePoint->e_alpha) * speed_scale; if (ea_factor < 0.0f) ea_factor = 0.0f; /* decrease factor for paint wetness */ - w_factor = (1.0f - ePoint->wetness)/8 * (pPoint->wetness - ePoint->wetness) * speed_scale; + w_factor = (1.0f - ePoint->wetness) / 8 * (pPoint->wetness - ePoint->wetness) * speed_scale; if (w_factor < 0.0f) w_factor = 0.0f; pPoint->alpha -= a_factor; @@ -4261,13 +4262,13 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force * Drip Effect */ if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP && force) { - float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*timescale/2.0f; + float eff_scale = distance_scale * EFF_MOVEMENT_PER_FRAME * timescale / 2.0f; /* Copy current surface to the previous points array to read unmodified values */ - memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint)); + memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(struct PaintPoint)); for (index = 0; index < sData->total_points; index++) { int i; - PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; + PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; PaintPoint *pPoint_prev = &prevPoint[index]; int closest_id[2]; @@ -4279,15 +4280,15 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force CLAMP(w_factor, 0.0f, 1.0f); /* get force affect points */ - surface_determineForceTargetPoints(sData, index, &force[index*4], closest_d, closest_id); + surface_determineForceTargetPoints(sData, index, &force[index * 4], closest_d, closest_id); /* Apply movement towards those two points */ - for (i=0; i<2; i++) { + for (i = 0; i < 2; i++) { int n_index = closest_id[i]; - if (n_index != -1 && closest_d[i]>0.0f) { + if (n_index != -1 && closest_d[i] > 0.0f) { float dir_dot = closest_d[i], dir_factor, a_factor; - float speed_scale = eff_scale*force[index*4+3]/bNeighs[n_index].dist; - PaintPoint *ePoint = &((PaintPoint*)sData->type_data)[sData->adj_data->n_target[n_index]]; + float speed_scale = eff_scale * force[index * 4 + 3] / bNeighs[n_index].dist; + PaintPoint *ePoint = &((PaintPoint *)sData->type_data)[sData->adj_data->n_target[n_index]]; float e_wet = ePoint->wetness; /* just skip if angle is too extreme */ @@ -4330,11 +4331,11 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) float wave_speed = surface->wave_speed; double average_dist = 0.0f; Bounds3D *mb = &sData->bData->mesh_bounds; - float canvas_size = MAX3((mb->max[0]-mb->min[0]), (mb->max[1]-mb->min[1]), (mb->max[2]-mb->min[2])); - float wave_scale = CANVAS_REL_SIZE/canvas_size; + float canvas_size = MAX3((mb->max[0] - mb->min[0]), (mb->max[1] - mb->min[1]), (mb->max[2] - mb->min[2])); + float wave_scale = CANVAS_REL_SIZE / canvas_size; /* allocate memory */ - PaintWavePoint *prevPoint = MEM_mallocN(sData->total_points*sizeof(PaintWavePoint), "Temp previous points for wave simulation"); + PaintWavePoint *prevPoint = MEM_mallocN(sData->total_points * sizeof(PaintWavePoint), "Temp previous points for wave simulation"); if (!prevPoint) return; /* calculate average neigh distance (single thread) */ @@ -4342,30 +4343,30 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) int i; int numOfNeighs = sData->adj_data->n_num[index]; - for (i=0; iadj_data->n_index[index]+i].dist; + for (i = 0; i < numOfNeighs; i++) { + average_dist += bNeighs[sData->adj_data->n_index[index] + i].dist; } } - average_dist *= wave_scale/sData->adj_data->total_targets; + average_dist *= wave_scale / sData->adj_data->total_targets; /* determine number of required steps */ - steps = (int)ceil((WAVE_TIME_FAC*timescale*surface->wave_timescale) / (average_dist/wave_speed/3)); + steps = (int)ceil((WAVE_TIME_FAC * timescale * surface->wave_timescale) / (average_dist / wave_speed / 3)); CLAMP(steps, 1, 20); timescale /= steps; /* apply simulation values for final timescale */ - dt = WAVE_TIME_FAC*timescale*surface->wave_timescale; - min_dist = wave_speed*dt*1.5f; - damp_factor = pow((1.0f-surface->wave_damping), timescale*surface->wave_timescale); + dt = WAVE_TIME_FAC * timescale * surface->wave_timescale; + min_dist = wave_speed * dt * 1.5f; + damp_factor = pow((1.0f - surface->wave_damping), timescale * surface->wave_timescale); - for (ss=0; sstype_data, sData->total_points*sizeof(PaintWavePoint)); + memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(PaintWavePoint)); #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { - PaintWavePoint *wPoint = &((PaintWavePoint*)sData->type_data)[index]; + PaintWavePoint *wPoint = &((PaintWavePoint *)sData->type_data)[index]; int numOfNeighs = sData->adj_data->n_num[index]; float force = 0.0f, avg_dist = 0.0f, avg_height = 0.0f; int numOfN = 0, numOfRN = 0; @@ -4374,13 +4375,13 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) if (wPoint->state > 0) continue; /* calculate force from surrounding points */ - for (i=0; iadj_data->n_index[index]+i; - float dist = bNeighs[n_index].dist*wave_scale; + for (i = 0; i < numOfNeighs; i++) { + int n_index = sData->adj_data->n_index[index] + i; + float dist = bNeighs[n_index].dist * wave_scale; PaintWavePoint *tPoint = &prevPoint[sData->adj_data->n_target[n_index]]; - if (!dist || tPoint->state>0) continue; - if (diststate > 0) continue; + if (dist < min_dist) dist = min_dist; avg_dist += dist; numOfN++; @@ -4390,28 +4391,28 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) numOfRN++; } - force += (tPoint->height - wPoint->height) / (dist*dist); + force += (tPoint->height - wPoint->height) / (dist * dist); } - avg_dist = (numOfN) ? avg_dist/numOfN : 0.0f; + avg_dist = (numOfN) ? avg_dist / numOfN : 0.0f; if (surface->flags & MOD_DPAINT_WAVE_OPEN_BORDERS && - sData->adj_data->flags[index] & ADJ_ON_MESH_EDGE) { + sData->adj_data->flags[index] & ADJ_ON_MESH_EDGE) { /* if open borders, apply a fake height to keep waves going on */ - avg_height = (numOfRN) ? avg_height/numOfRN : 0.0f; - wPoint->height = (dt*wave_speed*avg_height + wPoint->height*avg_dist) / (avg_dist + dt*wave_speed); + avg_height = (numOfRN) ? avg_height / numOfRN : 0.0f; + wPoint->height = (dt * wave_speed * avg_height + wPoint->height * avg_dist) / (avg_dist + dt * wave_speed); } /* else do wave eq */ else { /* add force towards zero height based on average dist */ if (avg_dist) - force += (0.0f - wPoint->height) * surface->wave_spring / (avg_dist*avg_dist) / 2.0f; + force += (0.0f - wPoint->height) * surface->wave_spring / (avg_dist * avg_dist) / 2.0f; /* change point velocity */ - wPoint->velocity += force*dt * wave_speed*wave_speed; + wPoint->velocity += force * dt * wave_speed * wave_speed; /* damping */ wPoint->velocity *= damp_factor; /* and new height */ - wPoint->height += wPoint->velocity*dt; + wPoint->height += wPoint->velocity * dt; } } } @@ -4419,7 +4420,7 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) /* reset state */ #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { - PaintWavePoint *wPoint = &((PaintWavePoint*)sData->type_data)[index]; + PaintWavePoint *wPoint = &((PaintWavePoint *)sData->type_data)[index]; /* if there wasnt any brush intersection, clear isect height */ if (wPoint->state == DPAINT_WAVE_NONE) { wPoint->brush_isect = 0.0f; @@ -4437,10 +4438,10 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time int index; #pragma omp parallel for schedule(static) - for (index=0; indextotal_points; index++) { + for (index = 0; index < sData->total_points; index++) { /* Do drying dissolve effects */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; + PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; /* drying */ if (surface->flags & MOD_DPAINT_USE_DRYING) { if (pPoint->wetness >= MIN_WETNESS) { @@ -4448,10 +4449,10 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time float dry_ratio, f_color[4]; float p_wetness = pPoint->wetness; VALUE_DISSOLVE(pPoint->wetness, surface->dry_speed, timescale, (surface->flags & MOD_DPAINT_DRY_LOG)); - if (pPoint->wetness<0.0f) pPoint->wetness=0.0f; + if (pPoint->wetness < 0.0f) pPoint->wetness = 0.0f; if (pPoint->wetness < surface->color_dry_threshold) { - dry_ratio = pPoint->wetness/p_wetness; + dry_ratio = pPoint->wetness / p_wetness; /* * Slowly "shift" paint from wet layer to dry layer as it drys: @@ -4466,12 +4467,12 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time pPoint->e_alpha *= dry_ratio; /* now calculate new alpha for dry layer that keeps final blended color unchanged */ - pPoint->alpha = (f_color[3] - pPoint->e_alpha)/(1.0f-pPoint->e_alpha); + pPoint->alpha = (f_color[3] - pPoint->e_alpha) / (1.0f - pPoint->e_alpha); /* for each rgb component, calculate a new dry layer color that keeps the final blend color * with these new alpha values. (wet layer color doesnt change)*/ if (pPoint->alpha) { - for (i=0; i<3; i++) { - pPoint->color[i] = (f_color[i]*f_color[3] - pPoint->e_color[i]*pPoint->e_alpha)/(pPoint->alpha*(1.0f-pPoint->e_alpha)); + for (i = 0; i < 3; i++) { + pPoint->color[i] = (f_color[i] * f_color[3] - pPoint->e_color[i] * pPoint->e_alpha) / (pPoint->alpha * (1.0f - pPoint->e_alpha)); } } } @@ -4501,10 +4502,10 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time } /* dissolve for float types */ else if (surface->flags & MOD_DPAINT_DISSOLVE && - (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WEIGHT)) { + (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || + surface->type == MOD_DPAINT_SURFACE_T_WEIGHT)) { - float *point = &((float*)sData->type_data)[index]; + float *point = &((float *)sData->type_data)[index]; /* log or linear */ VALUE_DISSOLVE(*point, surface->diss_speed, timescale, (surface->flags & MOD_DPAINT_DISSOLVE_LOG)); if (*point < 0.0f) *point = 0.0f; @@ -4526,17 +4527,17 @@ static int dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *ob if (!bData->prev_verts) return 1; /* matrix comparison */ - for (i=0; i<4; i++) { + for (i = 0; i < 4; i++) { int j; - for (j=0; j<4; j++) - if (bData->prev_obmat[i][j] != ob->obmat[i][j]) return 1; + for (j = 0; j < 4; j++) + if (bData->prev_obmat[i][j] != ob->obmat[i][j]) return 1; } /* vertices */ #pragma omp parallel for schedule(static) - for (i=0; iprev_verts[i].co[j] != mvert[i].co[j]) { ret = 1; break; @@ -4585,18 +4586,18 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc /* get previous speed for accelertaion */ if (do_accel_data && bData->prev_velocity && bData->velocity) - memcpy(bData->prev_velocity, bData->velocity, sData->total_points*sizeof(Vec3f)); + memcpy(bData->prev_velocity, bData->velocity, sData->total_points * sizeof(Vec3f)); /* reset speed vectors */ if (do_velocity_data && bData->velocity && (bData->clear || !surface_moved)) - memset(bData->velocity, 0, sData->total_points*sizeof(Vec3f)); + memset(bData->velocity, 0, sData->total_points * sizeof(Vec3f)); /* if previous data exists and mesh hasn't moved, no need to recalc */ if (!surface_moved) return 1; } - canvas_verts = (struct Vec3f *) MEM_mallocN(canvasNumOfVerts*sizeof(struct Vec3f), "Dynamic Paint transformed canvas verts"); + canvas_verts = (struct Vec3f *) MEM_mallocN(canvasNumOfVerts * sizeof(struct Vec3f), "Dynamic Paint transformed canvas verts"); if (!canvas_verts) return 0; /* allocate memory if required */ @@ -4608,11 +4609,11 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc } /* Init bdata */ - bData->bNormal = (struct PaintBakeNormal *) MEM_mallocN(sData->total_points*sizeof(struct PaintBakeNormal), "Dynamic Paint step data"); - bData->s_pos = MEM_mallocN(sData->total_points*sizeof(unsigned int), "Dynamic Paint bData s_pos"); - bData->s_num = MEM_mallocN(sData->total_points*sizeof(unsigned int), "Dynamic Paint bData s_num"); - bData->realCoord = (struct Vec3f *) MEM_mallocN(surface_totalSamples(surface)*sizeof(Vec3f), "Dynamic Paint point coords"); - bData->prev_verts = MEM_mallocN(canvasNumOfVerts*sizeof(MVert), "Dynamic Paint bData prev_verts"); + bData->bNormal = (struct PaintBakeNormal *) MEM_mallocN(sData->total_points * sizeof(struct PaintBakeNormal), "Dynamic Paint step data"); + bData->s_pos = MEM_mallocN(sData->total_points * sizeof(unsigned int), "Dynamic Paint bData s_pos"); + bData->s_num = MEM_mallocN(sData->total_points * sizeof(unsigned int), "Dynamic Paint bData s_num"); + bData->realCoord = (struct Vec3f *) MEM_mallocN(surface_totalSamples(surface) * sizeof(Vec3f), "Dynamic Paint point coords"); + bData->prev_verts = MEM_mallocN(canvasNumOfVerts * sizeof(MVert), "Dynamic Paint bData prev_verts"); /* if any allocation failed, free everything */ if (!bData->bNormal || !bData->s_pos || !bData->s_num || !bData->realCoord || !canvas_verts) { @@ -4629,20 +4630,20 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc } if (do_velocity_data && !bData->velocity) { - bData->velocity = (struct Vec3f *) MEM_callocN(sData->total_points*sizeof(Vec3f), "Dynamic Paint velocity"); + bData->velocity = (struct Vec3f *) MEM_callocN(sData->total_points * sizeof(Vec3f), "Dynamic Paint velocity"); } if (do_accel_data && !bData->prev_velocity) { - bData->prev_velocity = (struct Vec3f *) MEM_mallocN(sData->total_points*sizeof(Vec3f), "Dynamic Paint prev velocity"); + bData->prev_velocity = (struct Vec3f *) MEM_mallocN(sData->total_points * sizeof(Vec3f), "Dynamic Paint prev velocity"); /* copy previous vel */ if (bData->prev_velocity && bData->velocity) - memcpy(bData->prev_velocity, bData->velocity, sData->total_points*sizeof(Vec3f)); + memcpy(bData->prev_velocity, bData->velocity, sData->total_points * sizeof(Vec3f)); } /* * Make a transformed copy of canvas derived mesh vertices to avoid recalculation. */ bData->mesh_bounds.valid = 0; - for (index=0; indexobmat, canvas_verts[index].v); boundInsert(&bData->mesh_bounds, canvas_verts[index].v); @@ -4652,7 +4653,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc * Prepare each surface point for a new step */ #pragma omp parallel for schedule(static) - for (index=0; indextotal_points; index++) { + for (index = 0; index < sData->total_points; index++) { float prev_point[3] = {0.0f, 0.0f, 0.0f}; if (do_velocity_data && !new_bdata) { copy_v3_v3(prev_point, bData->realCoord[bData->s_pos[index]].v); @@ -4662,16 +4663,16 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc */ if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { float n1[3], n2[3], n3[3]; - ImgSeqFormatData *f_data = (ImgSeqFormatData*)sData->format_data; - PaintUVPoint *tPoint = &((PaintUVPoint*)f_data->uv_p)[index]; + ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; + PaintUVPoint *tPoint = &((PaintUVPoint *)f_data->uv_p)[index]; int ss; bData->s_num[index] = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; bData->s_pos[index] = index * bData->s_num[index]; /* per sample coordinates */ - for (ss=0; sss_num[index]; ss++) { - interp_v3_v3v3v3(bData->realCoord[bData->s_pos[index]+ss].v, + for (ss = 0; ss < bData->s_num[index]; ss++) { + interp_v3_v3v3v3(bData->realCoord[bData->s_pos[index] + ss].v, canvas_verts[tPoint->v1].v, canvas_verts[tPoint->v2].v, canvas_verts[tPoint->v3].v, @@ -4684,7 +4685,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc normal_short_to_float_v3(n3, mvert[tPoint->v3].no); interp_v3_v3v3v3(bData->bNormal[index].invNorm, - n1, n2, n3, f_data->barycentricWeights[index*bData->s_num[index]].v); + n1, n2, n3, f_data->barycentricWeights[index * bData->s_num[index]].v); mul_mat3_m4_v3(ob->obmat, bData->bNormal[index].invNorm); normalize_v3(bData->bNormal[index].invNorm); negate_v3(bData->bNormal[index].invNorm); @@ -4692,8 +4693,8 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { int ss; if (surface->flags & MOD_DPAINT_ANTIALIAS && adj_data) { - bData->s_num[index] = adj_data->n_num[index]+1; - bData->s_pos[index] = adj_data->n_index[index]+index; + bData->s_num[index] = adj_data->n_num[index] + 1; + bData->s_pos[index] = adj_data->n_index[index] + index; } else { bData->s_num[index] = 1; @@ -4701,14 +4702,14 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc } /* calculate position for each sample */ - for (ss=0; sss_num[index]; ss++) { + for (ss = 0; ss < bData->s_num[index]; ss++) { /* first sample is always point center */ - copy_v3_v3(bData->realCoord[bData->s_pos[index]+ss].v, canvas_verts[index].v); + copy_v3_v3(bData->realCoord[bData->s_pos[index] + ss].v, canvas_verts[index].v); if (ss > 0) { - int t_index = adj_data->n_index[index]+(ss-1); + int t_index = adj_data->n_index[index] + (ss - 1); /* get vertex position at 1/3 of each neigh edge */ - mul_v3_fl(bData->realCoord[bData->s_pos[index]+ss].v, 2.0f/3.0f); - madd_v3_v3fl(bData->realCoord[bData->s_pos[index]+ss].v, canvas_verts[adj_data->n_target[t_index]].v, 1.0f/3.0f); + mul_v3_fl(bData->realCoord[bData->s_pos[index] + ss].v, 2.0f / 3.0f); + madd_v3_v3fl(bData->realCoord[bData->s_pos[index] + ss].v, canvas_verts[adj_data->n_target[t_index]].v, 1.0f / 3.0f); } } @@ -4722,7 +4723,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc /* Prepare surface normal directional scale to easily convert * brush intersection amount between global and local space */ if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WAVE) { + surface->type == MOD_DPAINT_SURFACE_T_WAVE) { float temp_nor[3]; if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { normal_short_to_float_v3(temp_nor, mvert[index].no); @@ -4730,14 +4731,14 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc } else { float n1[3], n2[3], n3[3]; - ImgSeqFormatData *f_data = (ImgSeqFormatData*)sData->format_data; - PaintUVPoint *tPoint = &((PaintUVPoint*)f_data->uv_p)[index]; + ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; + PaintUVPoint *tPoint = &((PaintUVPoint *)f_data->uv_p)[index]; normal_short_to_float_v3(n1, mvert[tPoint->v1].no); normal_short_to_float_v3(n2, mvert[tPoint->v2].no); normal_short_to_float_v3(n3, mvert[tPoint->v3].no); interp_v3_v3v3v3(temp_nor, - n1, n2, n3, f_data->barycentricWeights[index*bData->s_num[index]].v); + n1, n2, n3, f_data->barycentricWeights[index * bData->s_num[index]].v); } mul_v3_v3(temp_nor, ob->size); @@ -4759,7 +4760,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc /* Copy current frame vertices to check against in next frame */ copy_m4_m4(bData->prev_obmat, ob->obmat); - memcpy(bData->prev_verts, mvert, canvasNumOfVerts*sizeof(MVert)); + memcpy(bData->prev_verts, mvert, canvasNumOfVerts * sizeof(MVert)); bData->clear = 0; @@ -4801,7 +4802,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su brushObj = NULL; /* select object */ if (surface->brush_group) { - if (go->ob) brushObj = go->ob; + if (go->ob) brushObj = go->ob; } else brushObj = base->object; @@ -4809,7 +4810,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su if (!brushObj) { /* skip item */ if (surface->brush_group) go = go->next; - else base= base->next; + else base = base->next; continue; } @@ -4817,7 +4818,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su if (surface->brush_group) go = go->next; else - base= base->next; + base = base->next; /* check if target has an active dp modifier */ md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); @@ -4830,7 +4831,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su /* calculate brush speed vectors if required */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && brush->flags & MOD_DPAINT_DO_SMUDGE) { - bData->brush_velocity = MEM_callocN(sData->total_points*sizeof(float)*4, "Dynamic Paint brush velocity"); + bData->brush_velocity = MEM_callocN(sData->total_points * sizeof(float) * 4, "Dynamic Paint brush velocity"); /* init adjacency data if not already */ if (!sData->adj_data) dynamicPaint_initAdjacencyData(surface, 1); @@ -4850,8 +4851,8 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su /* Apply brush on the surface depending on it's collision type */ /* Particle brush: */ if (brush->collision == MOD_DPAINT_COL_PSYS) { - if (brush && brush->psys && brush->psys->part && brush->psys->part->type==PART_EMITTER && - psys_check_enabled(brushObj, brush->psys)) { + if (brush && brush->psys && brush->psys->part && brush->psys->part->type == PART_EMITTER && + psys_check_enabled(brushObj, brush->psys)) { /* Paint a particle system */ BKE_animsys_evaluate_animdata(scene, &brush->psys->part->id, brush->psys->part->adt, BKE_scene_frame_get(scene), ADT_RECALC_ANIM); @@ -4903,7 +4904,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su float *force = NULL; /* Allocate memory for surface previous points to read unchanged values from */ - prevPoint = MEM_mallocN(sData->total_points*sizeof(struct PaintPoint), "PaintSurfaceDataCopy"); + prevPoint = MEM_mallocN(sData->total_points * sizeof(struct PaintPoint), "PaintSurfaceDataCopy"); if (!prevPoint) return setError(canvas, "Not enough free memory."); @@ -4939,10 +4940,10 @@ int dynamicPaint_calculateFrame(DynamicPaintSurface *surface, Scene *scene, Obje /* don't do substeps for first frame */ if (surface->substeps && (frame != surface->start_frame)) { int st; - timescale = 1.0f / (surface->substeps+1); + timescale = 1.0f / (surface->substeps + 1); for (st = 1; st <= surface->substeps; st++) { - float subframe = ((float) st) / (surface->substeps+1); + float subframe = ((float) st) / (surface->substeps + 1); if (!dynamicPaint_doStep(scene, cObject, surface, timescale, subframe)) return 0; } } -- cgit v1.2.3