diff options
Diffstat (limited to 'source/blender/blenkernel/intern/dynamicpaint.c')
-rw-r--r-- | source/blender/blenkernel/intern/dynamicpaint.c | 188 |
1 files changed, 100 insertions, 88 deletions
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index e6f38a3a334..9ce4d68eeed 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -231,22 +231,13 @@ static int dynamicPaint_surfaceNumOfPoints(DynamicPaintSurface *surface) /* checks whether surface's format/type has realtime preview */ int dynamicPaint_surfaceHasColorPreview(DynamicPaintSurface *surface) { - if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { - return 0; - } + if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) return 0; else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WAVE) - { - return 0; - } - else { - return 1; - } - } - else { - return 1; + surface->type == MOD_DPAINT_SURFACE_T_WAVE) return 0; + else return 1; } + else return 1; } /* get currently active surface (in user interface) */ @@ -402,15 +393,11 @@ void dynamicPaintSurface_updateType(struct DynamicPaintSurface *surface) static int surface_totalSamples(DynamicPaintSurface *surface) { if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ && - surface->flags & MOD_DPAINT_ANTIALIAS) - { - return (surface->data->total_points * 5); - } + surface->flags & MOD_DPAINT_ANTIALIAS) + return (surface->data->total_points*5); if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX && - surface->flags & MOD_DPAINT_ANTIALIAS && surface->data->adj_data) - { + 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; } @@ -561,7 +548,8 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, Scene *scene) else base = scene->base.first; - while (base || go) { + while (base || go) + { brushObj = NULL; /* select object */ @@ -571,7 +559,8 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, Scene *scene) else brushObj = base->object; - if (!brushObj) { + if (!brushObj) + { if (surface->brush_group) go = go->next; else base= base->next; continue; @@ -583,10 +572,12 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, Scene *scene) base= base->next; md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); - if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) { + if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) + { DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)md; - if (pmd2->brush) { + if (pmd2->brush) + { DynamicPaintBrushSettings *brush = pmd2->brush; if (brush->flags & MOD_DPAINT_USES_VELOCITY) @@ -897,10 +888,8 @@ void surface_freeUnusedData(DynamicPaintSurface *surface) /* free bakedata if not active or surface is baked */ if (!(surface->flags & MOD_DPAINT_ACTIVE) || - (surface->pointcache && surface->pointcache->flag & PTCACHE_BAKED)) - { + (surface->pointcache && surface->pointcache->flag & PTCACHE_BAKED)) free_bakeData(surface->data); - } } void dynamicPaint_freeSurfaceData(DynamicPaintSurface *surface) @@ -1230,13 +1219,9 @@ static int surface_usesAdjData(DynamicPaintSurface *surface) { if (surface_usesAdjDistance(surface)) return 1; if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX && - surface->flags & MOD_DPAINT_ANTIALIAS) - { - return 1; - } - else { - return 0; - } + surface->flags & MOD_DPAINT_ANTIALIAS) return 1; + + return 0; } /* initialize surface adjacency data */ @@ -1309,12 +1294,10 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for /* now check if total number of edges+faces for * 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)) - { + if ((temp_data[i]%2) || + temp_data[i] < 4) ad->flags[i] |= ADJ_ON_MESH_EDGE; - } - + /* reset temp data */ temp_data[i] = 0; } @@ -1880,10 +1863,8 @@ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene /* restore canvas derivedmesh if required */ if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE && - surface->flags & MOD_DPAINT_DISP_INCREMENTAL && surface->next) - { + surface->flags & MOD_DPAINT_DISP_INCREMENTAL && surface->next) canvas_copyDerivedMesh(canvas, dm); - } BKE_ptcache_validate(cache, surface->current_frame); BKE_ptcache_write(&pid, surface->current_frame); @@ -2061,12 +2042,9 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh //printf("connected UV : %f,%f & %f,%f - %f,%f & %f,%f\n", s_uv1[0], s_uv1[1], s_uv2[0], s_uv2[1], t_uv1[0], t_uv1[1], t_uv2[0], t_uv2[1]); if (((s_uv1[0] == t_uv1[0] && s_uv1[1] == t_uv1[1]) && - (s_uv2[0] == t_uv2[0] && s_uv2[1] == t_uv2[1]) ) || - ((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])); - } + (s_uv2[0] == t_uv2[0] && s_uv2[1] == t_uv2[1]) ) || + ((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])); /* * Find a point that is relatively at same edge position @@ -2207,9 +2185,11 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) */ if (!error) { #pragma omp parallel for schedule(static) - for (ty = 0; ty < h; ty++) { + for (ty = 0; ty < h; ty++) + { int tx; - for (tx = 0; tx < w; tx++) { + for (tx = 0; tx < w; tx++) + { int i, sample; int index = tx+w*ty; PaintUVPoint *tPoint = (&tempPoints[index]); @@ -2277,7 +2257,8 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) /* If collision wasn't found but the face is a quad * do another check for the second half */ - if ((!isInside) && mface[i].v4) { + 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 @@ -2349,9 +2330,11 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) * (To avoid seams on uv island edges) */ #pragma omp parallel for schedule(static) - for (ty = 0; ty < h; ty++) { + for (ty = 0; ty < h; ty++) + { int tx; - for (tx = 0; tx < w; tx++) { + for (tx = 0; tx < w; tx++) + { int index = tx+w*ty; PaintUVPoint *tPoint = (&tempPoints[index]); @@ -2425,9 +2408,11 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) * 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++) { + for (ty = 0; ty < h; ty++) + { int tx; - for (tx = 0; tx < w; tx++) { + for (tx = 0; tx < w; tx++) + { int index = tx+w*ty; PaintUVPoint *tPoint = (&tempPoints[index]); @@ -2455,9 +2440,11 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) if (sData->adj_data) { PaintAdjData *ed = sData->adj_data; unsigned int n_pos = 0; - for (ty = 0; ty < h; ty++) { + for (ty = 0; ty < h; ty++) + { int tx; - for (tx = 0; tx < w; tx++) { + for (tx = 0; tx < w; tx++) + { int i, index = tx+w*ty; if (tempPoints[index].face_index != -1) { @@ -2589,7 +2576,8 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char* filenam 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++) { + for (index = 0; index < sData->total_points; index++) + { int pos=f_data->uv_p[index].pixel_index*4; /* image buffer position */ /* Set values of preferred type */ @@ -2771,7 +2759,8 @@ static void mesh_faces_spherecast_dp(void *userdata, int index, const BVHTreeRay { float dist = bvhtree_ray_tri_intersection(ray, hit->dist, t0, t1, t2); - if (dist >= 0 && dist < hit->dist) { + if (dist >= 0 && dist < hit->dist) + { hit->index = index; hit->dist = dist; hit->no[0] = (quad) ? 1.0f : 0.0f; @@ -2791,7 +2780,7 @@ static void mesh_faces_spherecast_dp(void *userdata, int index, const BVHTreeRay * 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) +static void mesh_faces_nearest_point_dp(void *userdata, int index, const float *co, BVHTreeNearest *nearest) { const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata; MVert *vert = data->vert; @@ -2810,7 +2799,8 @@ static void mesh_faces_nearest_point_dp(void *userdata, int index, const float c int vertex, edge; dist = nearest_point_in_tri_surface(t0, t1, t2, co, &vertex, &edge, nearest_tmp); - if (dist < nearest->dist) { + if (dist < nearest->dist) + { nearest->index = index; nearest->dist = dist; copy_v3_v3(nearest->co, nearest_tmp); @@ -3198,7 +3188,8 @@ 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)) { + 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]; @@ -3212,7 +3203,8 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* loop through cell points and process brush */ #pragma omp parallel for schedule(static) - for (id = 0; id < grid->s_num[c_index]; id++) { + 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; @@ -3228,7 +3220,8 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, total_sample = gaussianTotal; /* Supersampling */ - for (ss=0; ss<samples; ss++) { + for (ss=0; ss<samples; ss++) + { float ray_start[3], ray_dir[3]; float sample_factor = 0.0f; @@ -3270,7 +3263,8 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* 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) { + 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 */ @@ -3283,7 +3277,8 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* If ray and hit face normal are facing same direction * hit point is inside a closed mesh. */ - if (dot>=0) { + if (dot>=0) + { float dist = hit.dist; int f_index = hit.index; @@ -3347,7 +3342,8 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, 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) { + 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); @@ -3450,7 +3446,8 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* * Process hit color and alpha */ - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) + { float sampleColor[3]; float alpha_factor = 1.0f; @@ -3592,7 +3589,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, BLI_begin_threaded_malloc(); /* only continue if particle bb is close enough to canvas bb */ - if (boundsIntersectDist(&grid->grid_bounds, &part_bb, range)) { + if (boundsIntersectDist(&grid->grid_bounds, &part_bb, range)) + { int c_index; int total_cells = grid->dim[0]*grid->dim[1]*grid->dim[2]; @@ -3605,14 +3603,13 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* check cell bounding box */ if (!grid->s_num[c_index] || - !boundsIntersectDist(&grid->bounds[c_index], &part_bb, range)) - { + !boundsIntersectDist(&grid->bounds[c_index], &part_bb, range)) continue; - } /* loop through cell points */ #pragma omp parallel for schedule(static) - for (id = 0; id < grid->s_num[c_index]; id++) { + for (id = 0; id < grid->s_num[c_index]; id++) + { int index = grid->t_index[grid->s_pos[c_index] + id]; float disp_intersect = 0.0f; float radius = 0.0f; @@ -3717,7 +3714,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, } } - if (strength > 0.001f) { + if (strength > 0.001f) + { float paintColor[4] = {0.0f}; float depth = 0.0f; @@ -3783,7 +3781,8 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po * Loop through every surface point */ #pragma omp parallel for schedule(static) - for (index = 0; index < sData->total_points; index++) { + for (index = 0; index < sData->total_points; index++) + { float distance = len_v3v3(pointCoord, bData->realCoord[bData->s_pos[index]].v); float colorband[4] = {0.0f}; float strength; @@ -3892,7 +3891,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int if (!bNeighs) return; #pragma omp parallel for schedule(static) - for (index = 0; index < sData->total_points; index++) { + for (index = 0; index < sData->total_points; index++) + { int i; int numOfNeighs = adj_data->n_num[index]; @@ -3911,7 +3911,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int /* calculate average values (single thread) */ bData->average_dist = 0.0f; - for (index = 0; index < sData->total_points; index++) { + for (index = 0; index < sData->total_points; index++) + { int i; int numOfNeighs = adj_data->n_num[index]; @@ -4079,7 +4080,8 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s if (*force) { #pragma omp parallel for schedule(static) - for (index = 0; index < sData->total_points; index++) { + for (index = 0; index < sData->total_points; index++) + { float forc[3] = {0}; /* apply force fields */ @@ -4119,7 +4121,8 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s } /* calculate average values (single thread) */ - for (index = 0; index < sData->total_points; index++) { + for (index = 0; index < sData->total_points; index++) + { average_force += (*force)[index*4+3]; } average_force /= sData->total_points; @@ -4168,7 +4171,8 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force 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++) { + 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]; @@ -4210,7 +4214,8 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force 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++) { + for (index = 0; index < sData->total_points; index++) + { int i; int numOfNeighs = sData->adj_data->n_num[index]; float totalAlpha = 0.0f; @@ -4251,7 +4256,8 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force /* * Drip Effect */ - if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP && force) { + if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP && force) + { 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)); @@ -4329,7 +4335,8 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) if (!prevPoint) return; /* calculate average neigh distance (single thread) */ - for (index = 0; index < sData->total_points; index++) { + for (index = 0; index < sData->total_points; index++) + { int i; int numOfNeighs = sData->adj_data->n_num[index]; @@ -4428,7 +4435,8 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time int index; #pragma omp parallel for schedule(static) - for (index=0; index<sData->total_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]; @@ -4643,7 +4651,8 @@ 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; index<sData->total_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); @@ -4787,7 +4796,8 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su else base = scene->base.first; - while (base || go) { + while (base || go) + { brushObj = NULL; /* select object */ if (surface->brush_group) { @@ -4811,10 +4821,12 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su /* check if target has an active dp modifier */ md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); - if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) { + if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) + { DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)md; /* make sure we're dealing with a brush */ - if (pmd2->brush) { + if (pmd2->brush) + { DynamicPaintBrushSettings *brush = pmd2->brush; BrushMaterials bMats = {0}; |