diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/anim.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/customdata.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/ipo.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/smoke.c | 1036 | ||||
-rw-r--r-- | source/blender/editors/armature/meshlaplacian.c | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 12 | ||||
-rw-r--r-- | source/blender/editors/object/object_iterators.c | 6 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 8 | ||||
-rw-r--r-- | source/blender/editors/physics/dynamicpaint_ops.c | 38 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawvolume.c | 113 |
11 files changed, 615 insertions, 621 deletions
diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 58d20fff2bc..f44cb6d6b19 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -1678,8 +1678,8 @@ ListBase *object_duplilist_ex(Scene *sce, Object *ob, int update, int for_render ListBase *duplilist = MEM_mallocN(sizeof(ListBase), "duplilist"); int flag = 0; - if(update) flag |= DUPLILIST_DO_UPDATE; - if(for_render) flag |= DUPLILIST_FOR_RENDER; + if (update) flag |= DUPLILIST_DO_UPDATE; + if (for_render) flag |= DUPLILIST_FOR_RENDER; duplilist->first = duplilist->last = NULL; object_duplilist_recursive((ID *)sce, sce, ob, duplilist, NULL, 0, 0, flag); diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index efcc00c401d..423bd93c70f 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -2358,7 +2358,9 @@ void CustomData_bmesh_free_block(CustomData *data, void **block) const LayerTypeInfo *typeInfo; int i; - if (!*block) return; + if (*block == NULL) + return; + for (i = 0; i < data->totlayer; ++i) { if (!(data->layers[i].flag & CD_FLAG_NOFREE)) { typeInfo = layerType_getInfo(data->layers[i].type); @@ -2394,7 +2396,7 @@ void CustomData_bmesh_copy_data(const CustomData *source, CustomData *dest, const LayerTypeInfo *typeInfo; int dest_i, src_i; - if (!*dest_block) { + if (*dest_block == NULL) { CustomData_bmesh_alloc_block(dest, dest_block); if (*dest_block) memset(*dest_block, 0, dest->totsize); @@ -2614,7 +2616,7 @@ void CustomData_bmesh_set_default(CustomData *data, void **block) const LayerTypeInfo *typeInfo; int i; - if (!*block) + if (*block == NULL) CustomData_bmesh_alloc_block(data, block); for (i = 0; i < data->totlayer; ++i) { @@ -2634,7 +2636,7 @@ void CustomData_to_bmesh_block(const CustomData *source, CustomData *dest, const LayerTypeInfo *typeInfo; int dest_i, src_i, src_offset; - if (!*dest_block) + if (*dest_block == NULL) CustomData_bmesh_alloc_block(dest, dest_block); /* copies a layer at a time */ diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 5216aefab58..b7e33f1cf71 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -2093,7 +2093,7 @@ void do_versions_ipos_to_animato(Main *main) bAction *new_act; /* add a new action for this, and convert all data into that action */ - new_act = add_empty_action(id->name+2); + new_act = add_empty_action(id->name + 2); ipo_to_animato(NULL, ipo, NULL, NULL, NULL, NULL, &new_act->curves, &drivers); new_act->idroot = ipo->blocktype; } diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index a20d88c03c7..519c4008e0d 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -95,38 +95,38 @@ static LARGE_INTEGER liFrequency; static LARGE_INTEGER liStartTime; static LARGE_INTEGER liCurrentTime; -static void tstart ( void ) +static void tstart(void) { - QueryPerformanceFrequency ( &liFrequency ); - QueryPerformanceCounter ( &liStartTime ); + QueryPerformanceFrequency(&liFrequency); + QueryPerformanceCounter(&liStartTime); } -static void tend ( void ) +static void tend(void) { - QueryPerformanceCounter ( &liCurrentTime ); + QueryPerformanceCounter(&liCurrentTime); } -static double tval( void ) +static double tval(void) { - return ((double)( (liCurrentTime.QuadPart - liStartTime.QuadPart)* (double)1000.0/(double)liFrequency.QuadPart )); + return ((double)( (liCurrentTime.QuadPart - liStartTime.QuadPart) * (double)1000.0 / (double)liFrequency.QuadPart)); } #else #include <sys/time.h> static struct timeval _tstart, _tend; static struct timezone tz; -static void tstart ( void ) +static void tstart(void) { - gettimeofday ( &_tstart, &tz ); + gettimeofday(&_tstart, &tz); } -static void tend ( void ) +static void tend(void) { - gettimeofday ( &_tend,&tz ); + gettimeofday(&_tend, &tz); } -static double UNUSED_FUNCTION(tval)( void ) +static double UNUSED_FUNCTION(tval) (void) { double t1, t2; - t1 = ( double ) _tstart.tv_sec*1000 + ( double ) _tstart.tv_usec/ ( 1000 ); - t2 = ( double ) _tend.tv_sec*1000 + ( double ) _tend.tv_usec/ ( 1000 ); - return t2-t1; + t1 = ( double ) _tstart.tv_sec * 1000 + ( double ) _tstart.tv_usec / (1000); + t2 = ( double ) _tend.tv_sec * 1000 + ( double ) _tend.tv_usec / (1000); + return t2 - t1; } #endif @@ -138,9 +138,9 @@ struct SmokeModifierData; // timestep default value for nice appearance 0.1f #define DT_DEFAULT 0.1f -#define ADD_IF_LOWER_POS(a,b) (MIN2((a)+(b), MAX2((a),(b)))) -#define ADD_IF_LOWER_NEG(a,b) (MAX2((a)+(b), MIN2((a),(b)))) -#define ADD_IF_LOWER(a,b) (((b)>0)?ADD_IF_LOWER_POS((a),(b)):ADD_IF_LOWER_NEG((a),(b))) +#define ADD_IF_LOWER_POS(a, b) (MIN2((a) + (b), MAX2((a), (b)))) +#define ADD_IF_LOWER_NEG(a, b) (MAX2((a) + (b), MIN2((a), (b)))) +#define ADD_IF_LOWER(a, b) (((b) > 0) ? ADD_IF_LOWER_POS((a), (b)) : ADD_IF_LOWER_NEG((a), (b))) #else /* WITH_SMOKE */ @@ -152,8 +152,8 @@ float *smoke_get_density(struct FLUID_3D *UNUSED(fluid)) { return NULL; } void smoke_turbulence_free(struct WTURBULENCE *UNUSED(wt)) {} void smoke_initWaveletBlenderRNA(struct WTURBULENCE *UNUSED(wt), float *UNUSED(strength)) {} void smoke_initBlenderRNA(struct FLUID_3D *UNUSED(fluid), float *UNUSED(alpha), float *UNUSED(beta), float *UNUSED(dt_factor), float *UNUSED(vorticity), - int *UNUSED(border_colli), float *UNUSED(burning_rate), float *UNUSED(flame_smoke), float *UNUSED(flame_smoke_color), - float *UNUSED(flame_vorticity), float *UNUSED(flame_ignition_temp), float *UNUSED(flame_max_temp)) {} + int *UNUSED(border_colli), float *UNUSED(burning_rate), float *UNUSED(flame_smoke), float *UNUSED(flame_smoke_color), + float *UNUSED(flame_vorticity), float *UNUSED(flame_ignition_temp), float *UNUSED(flame_max_temp)) {} struct DerivedMesh *smokeModifier_do(SmokeModifierData *UNUSED(smd), Scene *UNUSED(scene), Object *UNUSED(ob), DerivedMesh *UNUSED(dm)) { return NULL; } float smoke_get_velocity_at(struct Object *UNUSED(ob), float UNUSED(position[3]), float UNUSED(velocity[3])) { return 0.0f; } void flame_get_spectrum(unsigned char *UNUSED(spec), int UNUSED(width), float UNUSED(t1), float UNUSED(t2)) {} @@ -165,18 +165,18 @@ void flame_get_spectrum(unsigned char *UNUSED(spec), int UNUSED(width), float UN void smoke_reallocate_fluid(SmokeDomainSettings *sds, float dx, int res[3], int free_old) { int use_heat = (sds->active_fields & SM_ACTIVE_HEAT); - int use_fire = (sds->active_fields & (SM_ACTIVE_HEAT|SM_ACTIVE_FIRE)); + int use_fire = (sds->active_fields & (SM_ACTIVE_HEAT | SM_ACTIVE_FIRE)); int use_colors = (sds->active_fields & SM_ACTIVE_COLORS); if (free_old && sds->fluid) smoke_free(sds->fluid); - if (!MIN3(res[0],res[1],res[2])) { + if (!MIN3(res[0], res[1], res[2])) { sds->fluid = NULL; return; } sds->fluid = smoke_init(res, dx, DT_DEFAULT, use_heat, use_fire, use_colors); smoke_initBlenderRNA(sds->fluid, &(sds->alpha), &(sds->beta), &(sds->time_scale), &(sds->vorticity), &(sds->border_collisions), - &(sds->burning_rate), &(sds->flame_smoke), sds->flame_smoke_color, &(sds->flame_vorticity), &(sds->flame_ignition), &(sds->flame_max_temp)); + &(sds->burning_rate), &(sds->flame_smoke), sds->flame_smoke_color, &(sds->flame_vorticity), &(sds->flame_ignition), &(sds->flame_max_temp)); /* reallocate shadow buffer */ if (sds->shadow) @@ -186,19 +186,19 @@ void smoke_reallocate_fluid(SmokeDomainSettings *sds, float dx, int res[3], int void smoke_reallocate_highres_fluid(SmokeDomainSettings *sds, float dx, int res[3], int free_old) { - int use_fire = (sds->active_fields & (SM_ACTIVE_HEAT|SM_ACTIVE_FIRE)); + int use_fire = (sds->active_fields & (SM_ACTIVE_HEAT | SM_ACTIVE_FIRE)); int use_colors = (sds->active_fields & SM_ACTIVE_COLORS); if (free_old && sds->wt) smoke_turbulence_free(sds->wt); - if (!MIN3(res[0],res[1],res[2])) { + if (!MIN3(res[0], res[1], res[2])) { sds->wt = NULL; return; } sds->wt = smoke_turbulence_init(res, sds->amplify + 1, sds->noise, use_fire, use_colors); sds->res_wt[0] = res[0] * (sds->amplify + 1); - sds->res_wt[1] = res[1] * (sds->amplify + 1); - sds->res_wt[2] = res[2] * (sds->amplify + 1); + sds->res_wt[1] = res[1] * (sds->amplify + 1); + sds->res_wt[2] = res[2] * (sds->amplify + 1); sds->dx_wt = dx / (sds->amplify + 1); smoke_initWaveletBlenderRNA(sds->wt, &(sds->strength)); } @@ -208,9 +208,9 @@ static void smoke_pos_to_cell(SmokeDomainSettings *sds, float pos[3]) { mul_m4_v3(sds->imat, pos); sub_v3_v3(pos, sds->p0); - pos[0] *= 1.0f/sds->cell_size[0]; - pos[1] *= 1.0f/sds->cell_size[1]; - pos[2] *= 1.0f/sds->cell_size[2]; + pos[0] *= 1.0f / sds->cell_size[0]; + pos[1] *= 1.0f / sds->cell_size[1]; + pos[2] *= 1.0f / sds->cell_size[2]; } /* set domain resolution and dimensions from object derivedmesh */ @@ -226,7 +226,7 @@ static void smoke_set_domain_from_derivedmesh(SmokeDomainSettings *sds, Object * res = sds->maxres; // get BB of domain - for(i = 0; i < dm->getNumVerts(dm); i++) + for (i = 0; i < dm->getNumVerts(dm); i++) { // min BB min[0] = MIN2(min[0], verts[i].co[0]); @@ -254,7 +254,7 @@ static void smoke_set_domain_from_derivedmesh(SmokeDomainSettings *sds, Object * invert_m4_m4(sds->imat, ob->obmat); // prevent crash when initializing a plane as domain - if((size[0] < FLT_EPSILON) || (size[1] < FLT_EPSILON) || (size[2] < FLT_EPSILON)) + if ((size[0] < FLT_EPSILON) || (size[1] < FLT_EPSILON) || (size[2] < FLT_EPSILON)) return; /* define grid resolutions from longest domain side */ @@ -288,7 +288,7 @@ static void smoke_set_domain_from_derivedmesh(SmokeDomainSettings *sds, Object * static int smokeModifier_init(SmokeModifierData *smd, Object *ob, Scene *scene, DerivedMesh *dm) { - if((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain && !smd->domain->fluid) + if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain && !smd->domain->fluid) { SmokeDomainSettings *sds = smd->domain; int res[3]; @@ -309,7 +309,7 @@ static int smokeModifier_init(SmokeModifierData *smd, Object *ob, Scene *scene, VECCOPY(res, sds->base_res); } VECCOPY(sds->res, res); - sds->total_cells = sds->res[0]*sds->res[1]*sds->res[2]; + sds->total_cells = sds->res[0] * sds->res[1] * sds->res[2]; sds->res_min[0] = sds->res_min[1] = sds->res_min[2] = 0; VECCOPY(sds->res_max, res); @@ -319,24 +319,24 @@ static int smokeModifier_init(SmokeModifierData *smd, Object *ob, Scene *scene, smd->time = scene->r.cfra; /* allocate highres fluid */ - if(sds->flags & MOD_SMOKE_HIGHRES) { + if (sds->flags & MOD_SMOKE_HIGHRES) { smoke_reallocate_highres_fluid(sds, sds->dx, sds->res, 0); } /* allocate shadow buffer */ - if(!sds->shadow) + if (!sds->shadow) sds->shadow = MEM_callocN(sizeof(float) * sds->res[0] * sds->res[1] * sds->res[2], "SmokeDomainShadow"); return 1; } - else if((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) + else if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) { smd->time = scene->r.cfra; return 1; } - else if((smd->type & MOD_SMOKE_TYPE_COLL)) + else if ((smd->type & MOD_SMOKE_TYPE_COLL)) { - if(!smd->coll) + if (!smd->coll) { smokeModifier_createType(smd); } @@ -353,20 +353,20 @@ static int smokeModifier_init(SmokeModifierData *smd, Object *ob, Scene *scene, static void smokeModifier_freeDomain(SmokeModifierData *smd) { - if(smd->domain) + if (smd->domain) { - if(smd->domain->shadow) - MEM_freeN(smd->domain->shadow); - smd->domain->shadow = NULL; + if (smd->domain->shadow) + MEM_freeN(smd->domain->shadow); + smd->domain->shadow = NULL; - if(smd->domain->fluid) + if (smd->domain->fluid) smoke_free(smd->domain->fluid); - if(smd->domain->wt) + if (smd->domain->wt) smoke_turbulence_free(smd->domain->wt); - if(smd->domain->effector_weights) - MEM_freeN(smd->domain->effector_weights); + if (smd->domain->effector_weights) + MEM_freeN(smd->domain->effector_weights); smd->domain->effector_weights = NULL; BKE_ptcache_free_list(&(smd->domain->ptcaches[0])); @@ -379,7 +379,7 @@ static void smokeModifier_freeDomain(SmokeModifierData *smd) static void smokeModifier_freeFlow(SmokeModifierData *smd) { - if(smd->flow) + if (smd->flow) { if (smd->flow->dm) smd->flow->dm->release(smd->flow->dm); if (smd->flow->verts_old) MEM_freeN(smd->flow->verts_old); @@ -390,20 +390,20 @@ static void smokeModifier_freeFlow(SmokeModifierData *smd) static void smokeModifier_freeCollision(SmokeModifierData *smd) { - if(smd->coll) + if (smd->coll) { SmokeCollSettings *scs = smd->coll; - if(scs->numverts) + if (scs->numverts) { - if(scs->verts_old) + if (scs->verts_old) { MEM_freeN(scs->verts_old); scs->verts_old = NULL; } } - if(smd->coll->dm) + if (smd->coll->dm) smd->coll->dm->release(smd->coll->dm); smd->coll->dm = NULL; @@ -414,7 +414,7 @@ static void smokeModifier_freeCollision(SmokeModifierData *smd) void smokeModifier_reset_turbulence(struct SmokeModifierData *smd) { - if(smd && smd->domain && smd->domain->wt) + if (smd && smd->domain && smd->domain->wt) { smoke_turbulence_free(smd->domain->wt); smd->domain->wt = NULL; @@ -423,15 +423,15 @@ void smokeModifier_reset_turbulence(struct SmokeModifierData *smd) void smokeModifier_reset(struct SmokeModifierData *smd) { - if(smd) + if (smd) { - if(smd->domain) + if (smd->domain) { - if(smd->domain->shadow) + if (smd->domain->shadow) MEM_freeN(smd->domain->shadow); smd->domain->shadow = NULL; - if(smd->domain->fluid) + if (smd->domain->fluid) { smoke_free(smd->domain->fluid); smd->domain->fluid = NULL; @@ -443,17 +443,17 @@ void smokeModifier_reset(struct SmokeModifierData *smd) smd->domain->total_cells = 0; smd->domain->active_fields = 0; } - else if(smd->flow) + else if (smd->flow) { if (smd->flow->verts_old) MEM_freeN(smd->flow->verts_old); smd->flow->verts_old = NULL; smd->flow->numverts = 0; } - else if(smd->coll) + else if (smd->coll) { SmokeCollSettings *scs = smd->coll; - if(scs->numverts && scs->verts_old) + if (scs->numverts && scs->verts_old) { MEM_freeN(scs->verts_old); scs->verts_old = NULL; @@ -464,7 +464,7 @@ void smokeModifier_reset(struct SmokeModifierData *smd) void smokeModifier_free(SmokeModifierData *smd) { - if(smd) + if (smd) { smokeModifier_freeDomain(smd); smokeModifier_freeFlow(smd); @@ -474,11 +474,11 @@ void smokeModifier_free(SmokeModifierData *smd) void smokeModifier_createType(struct SmokeModifierData *smd) { - if(smd) + if (smd) { - if(smd->type & MOD_SMOKE_TYPE_DOMAIN) + if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { - if(smd->domain) + if (smd->domain) smokeModifier_freeDomain(smd); smd->domain = MEM_callocN(sizeof(SmokeDomainSettings), "SmokeDomain"); @@ -494,12 +494,12 @@ void smokeModifier_createType(struct SmokeModifierData *smd) smd->domain->ptcaches[1].first = smd->domain->ptcaches[1].last = NULL; /* set some standard values */ smd->domain->fluid = NULL; - smd->domain->wt = NULL; + smd->domain->wt = NULL; smd->domain->eff_group = NULL; smd->domain->fluid_group = NULL; smd->domain->coll_group = NULL; smd->domain->maxres = 32; - smd->domain->amplify = 1; + smd->domain->amplify = 1; smd->domain->alpha = -0.001; smd->domain->beta = 0.1; smd->domain->time_scale = 1.0; @@ -528,9 +528,9 @@ void smokeModifier_createType(struct SmokeModifierData *smd) smd->domain->viewsettings = MOD_SMOKE_VIEW_SHOWBIG; smd->domain->effector_weights = BKE_add_effector_weights(NULL); } - else if(smd->type & MOD_SMOKE_TYPE_FLOW) + else if (smd->type & MOD_SMOKE_TYPE_FLOW) { - if(smd->flow) + if (smd->flow) smokeModifier_freeFlow(smd); smd->flow = MEM_callocN(sizeof(SmokeFlowSettings), "SmokeFlow"); @@ -555,9 +555,9 @@ void smokeModifier_createType(struct SmokeModifierData *smd) smd->flow->psys = NULL; } - else if(smd->type & MOD_SMOKE_TYPE_COLL) + else if (smd->type & MOD_SMOKE_TYPE_COLL) { - if(smd->coll) + if (smd->coll) smokeModifier_freeCollision(smd); smd->coll = MEM_callocN(sizeof(SmokeCollSettings), "SmokeColl"); @@ -579,7 +579,7 @@ void smokeModifier_copy(struct SmokeModifierData *smd, struct SmokeModifierData { tsmd->type = smd->type; tsmd->time = smd->time; - + smokeModifier_createType(tsmd); if (tsmd->domain) { @@ -610,10 +610,10 @@ void smokeModifier_copy(struct SmokeModifierData *smd, struct SmokeModifierData tsmd->domain->flame_ignition = smd->domain->flame_ignition; tsmd->domain->flame_max_temp = smd->domain->flame_max_temp; copy_v3_v3(tsmd->domain->flame_smoke_color, smd->domain->flame_smoke_color); - + MEM_freeN(tsmd->domain->effector_weights); tsmd->domain->effector_weights = MEM_dupallocN(smd->domain->effector_weights); - } + } else if (tsmd->flow) { tsmd->flow->psys = smd->flow->psys; tsmd->flow->noise_texture = smd->flow->noise_texture; @@ -652,20 +652,20 @@ static void smoke_calc_transparency(SmokeDomainSettings *sds, Scene *scene); static float calc_voxel_transp(float *result, float *input, int res[3], int *pixel, float *tRay, float correct); static int get_lamp(Scene *scene, float *light) -{ - Base *base_tmp = NULL; +{ + Base *base_tmp = NULL; int found_lamp = 0; // try to find a lamp, preferably local - for(base_tmp = scene->base.first; base_tmp; base_tmp= base_tmp->next) { - if(base_tmp->object->type == OB_LAMP) { + for (base_tmp = scene->base.first; base_tmp; base_tmp = base_tmp->next) { + if (base_tmp->object->type == OB_LAMP) { Lamp *la = base_tmp->object->data; - if(la->type == LA_LOCAL) { + if (la->type == LA_LOCAL) { copy_v3_v3(light, base_tmp->object->obmat[3]); return 1; } - else if(!found_lamp) { + else if (!found_lamp) { copy_v3_v3(light, base_tmp->object->obmat[3]); found_lamp = 1; } @@ -717,7 +717,7 @@ static void obstacles_from_derivedmesh(Object *coll_ob, SmokeDomainSettings *sds } /* Transform collider vertices to - * domain grid space for fast lookups */ + * domain grid space for fast lookups */ for (i = 0; i < numverts; i++) { float n[3]; float co[3]; @@ -735,58 +735,58 @@ static void obstacles_from_derivedmesh(Object *coll_ob, SmokeDomainSettings *sds /* vert velocity */ VECADD(co, mvert[i].co, sds->shift); - if (has_velocity) + if (has_velocity) { - sub_v3_v3v3(&vert_vel[i*3], co, &scs->verts_old[i*3]); - mul_v3_fl(&vert_vel[i*3], sds->dx/dt); + sub_v3_v3v3(&vert_vel[i * 3], co, &scs->verts_old[i * 3]); + mul_v3_fl(&vert_vel[i * 3], sds->dx / dt); } - copy_v3_v3(&scs->verts_old[i*3], co); + copy_v3_v3(&scs->verts_old[i * 3], co); } if (bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 6)) { #pragma omp parallel for schedule(static) for (z = sds->res_min[2]; z < sds->res_max[2]; z++) { - int x,y; + int x, y; for (x = sds->res_min[0]; x < sds->res_max[0]; x++) - for (y = sds->res_min[1]; y < sds->res_max[1]; y++) { - int index = smoke_get_index(x-sds->res_min[0], sds->res[0], y-sds->res_min[1], sds->res[1], z-sds->res_min[2]); - - float ray_start[3] = {(float)x + 0.5f, (float)y + 0.5f, (float)z + 0.5f}; - BVHTreeNearest nearest = {0}; - nearest.index = -1; - nearest.dist = surface_distance * surface_distance; /* find_nearest uses squared distance */ - - /* find the nearest point on the mesh */ - if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, treeData.nearest_callback, &treeData) != -1) { - float weights[4]; - int v1, v2, v3, f_index = nearest.index; - - /* calculate barycentric weights for nearest point */ - v1 = mface[f_index].v1; - v2 = (nearest.flags & BVH_ONQUAD) ? mface[f_index].v3 : mface[f_index].v2; - v3 = (nearest.flags & BVH_ONQUAD) ? mface[f_index].v4 : mface[f_index].v3; - interp_weights_face_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, NULL, nearest.co); - - // DG TODO - if(has_velocity) - { - /* apply object velocity */ + for (y = sds->res_min[1]; y < sds->res_max[1]; y++) { + int index = smoke_get_index(x - sds->res_min[0], sds->res[0], y - sds->res_min[1], sds->res[1], z - sds->res_min[2]); + + float ray_start[3] = {(float)x + 0.5f, (float)y + 0.5f, (float)z + 0.5f}; + BVHTreeNearest nearest = {0}; + nearest.index = -1; + nearest.dist = surface_distance * surface_distance; /* find_nearest uses squared distance */ + + /* find the nearest point on the mesh */ + if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, treeData.nearest_callback, &treeData) != -1) { + float weights[4]; + int v1, v2, v3, f_index = nearest.index; + + /* calculate barycentric weights for nearest point */ + v1 = mface[f_index].v1; + v2 = (nearest.flags & BVH_ONQUAD) ? mface[f_index].v3 : mface[f_index].v2; + v3 = (nearest.flags & BVH_ONQUAD) ? mface[f_index].v4 : mface[f_index].v3; + interp_weights_face_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, NULL, nearest.co); + + // DG TODO + if (has_velocity) { - float hit_vel[3]; - interp_v3_v3v3v3(hit_vel, &vert_vel[v1*3], &vert_vel[v2*3], &vert_vel[v3*3], weights); - velocityX[index] += hit_vel[0]; - velocityY[index] += hit_vel[1]; - velocityZ[index] += hit_vel[2]; + /* apply object velocity */ + { + float hit_vel[3]; + interp_v3_v3v3v3(hit_vel, &vert_vel[v1 * 3], &vert_vel[v2 * 3], &vert_vel[v3 * 3], weights); + velocityX[index] += hit_vel[0]; + velocityY[index] += hit_vel[1]; + velocityZ[index] += hit_vel[2]; + } } - } - /* tag obstacle cells */ - obstacle_map[index] = 1; + /* tag obstacle cells */ + obstacle_map[index] = 1; - if(has_velocity) - obstacle_map[index] |= 8; + if (has_velocity) + obstacle_map[index] |= 8; + } } - } } } /* free bvh tree */ @@ -823,9 +823,9 @@ static void update_obstacles(Scene *scene, Object *ob, SmokeDomainSettings *sds, smoke_get_ob_velocity(sds->fluid, &velx, &vely, &velz); // TODO: delete old obstacle flags - for(z = 0; z < sds->res[0] * sds->res[1] * sds->res[2]; z++) + for (z = 0; z < sds->res[0] * sds->res[1] * sds->res[2]; z++) { - if(obstacles[z] & 8) // Do not delete static obstacles + if (obstacles[z] & 8) // Do not delete static obstacles { obstacles[z] = 0; } @@ -839,27 +839,27 @@ static void update_obstacles(Scene *scene, Object *ob, SmokeDomainSettings *sds, collobjs = get_collisionobjects(scene, ob, sds->coll_group, &numcollobj, eModifierType_Smoke); // update obstacle tags in cells - for(collIndex = 0; collIndex < numcollobj; collIndex++) + for (collIndex = 0; collIndex < numcollobj; collIndex++) { - Object *collob= collobjs[collIndex]; - SmokeModifierData *smd2 = (SmokeModifierData*)modifiers_findByType(collob, eModifierType_Smoke); + Object *collob = collobjs[collIndex]; + SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(collob, eModifierType_Smoke); // DG TODO: check if modifier is active? - - if((smd2->type & MOD_SMOKE_TYPE_COLL) && smd2->coll) + + if ((smd2->type & MOD_SMOKE_TYPE_COLL) && smd2->coll) { SmokeCollSettings *scs = smd2->coll; obstacles_from_derivedmesh(collob, sds, scs, obstacles, velx, vely, velz, dt); } } - if(collobjs) + if (collobjs) MEM_freeN(collobjs); /* obstacle cells should not contain any velocity from the smoke simulation */ - for(z = 0; z < sds->res[0] * sds->res[1] * sds->res[2]; z++) + for (z = 0; z < sds->res[0] * sds->res[1] * sds->res[2]; z++) { - if(obstacles[z]) + if (obstacles[z]) { velxOrig[z] = 0; velyOrig[z] = 0; @@ -905,35 +905,35 @@ static void em_boundInsert(EmissionMap *em, float point[3]) static void clampBoundsInDomain(SmokeDomainSettings *sds, int min[3], int max[3], float *min_vel, float *max_vel, int margin, float dt) { int i; - for (i=0; i<3; i++) { + for (i = 0; i < 3; i++) { int adapt = (sds->flags & MOD_SMOKE_ADAPTIVE_DOMAIN) ? sds->adapt_res : 0; /* add margin */ min[i] -= margin; max[i] += margin; /* adapt to velocity */ - if (min_vel && min_vel[i]<0.0f) { + if (min_vel && min_vel[i] < 0.0f) { min[i] += (int)ceil(min_vel[i] * dt); } - if (max_vel && max_vel[i]>0.0f) { + if (max_vel && max_vel[i] > 0.0f) { max[i] += (int)ceil(max_vel[i] * dt); } /* clamp within domain max size */ - CLAMP(min[i], -adapt, sds->base_res[i]+adapt); - CLAMP(max[i], -adapt, sds->base_res[i]+adapt); + CLAMP(min[i], -adapt, sds->base_res[i] + adapt); + CLAMP(max[i], -adapt, sds->base_res[i] + adapt); } } static void em_allocateData(EmissionMap *em, int use_velocity) { int i, res[3]; - for (i=0; i<3; i++) { + for (i = 0; i < 3; i++) { res[i] = em->max[i] - em->min[i]; if (res[i] <= 0) return; } - em->total_cells = res[0]*res[1]*res[2]; + em->total_cells = res[0] * res[1] * res[2]; copy_v3_v3_int(em->res, res); @@ -952,13 +952,13 @@ static void em_freeData(EmissionMap *em) { static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, SmokeFlowSettings *sfs, EmissionMap *em, Scene *scene, float time, float dt) { - if(sfs && sfs->psys && sfs->psys->part && sfs->psys->part->type==PART_EMITTER) // is particle system selected + if (sfs && sfs->psys && sfs->psys->part && sfs->psys->part->type == PART_EMITTER) // is particle system selected { ParticleSimulationData sim; ParticleSystem *psys = sfs->psys; float *particle_pos; float *particle_vel; - int totpart=psys->totpart, totchild; + int totpart = psys->totpart, totchild; int p = 0; int valid_particles = 0; @@ -966,45 +966,45 @@ static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, Smoke sim.ob = flow_ob; sim.psys = psys; - if(psys->part->type==PART_HAIR) + if (psys->part->type == PART_HAIR) { // TODO: PART_HAIR not supported whatsoever - totchild=0; + totchild = 0; } else - totchild=psys->totchild*psys->part->disp/100; + totchild = psys->totchild * psys->part->disp / 100; - particle_pos = MEM_callocN(sizeof(float) * (totpart+totchild) * 3, "smoke_flow_particles"); - particle_vel = MEM_callocN(sizeof(float) * (totpart+totchild) * 3, "smoke_flow_particles"); + particle_pos = MEM_callocN(sizeof(float) * (totpart + totchild) * 3, "smoke_flow_particles"); + particle_vel = MEM_callocN(sizeof(float) * (totpart + totchild) * 3, "smoke_flow_particles"); /* calculate local position for each particle */ - for(p=0; p<totpart+totchild; p++) + for (p = 0; p < totpart + totchild; p++) { ParticleKey state; float *pos; - if(p < totpart) { - if(psys->particles[p].flag & (PARS_NO_DISP|PARS_UNEXIST)) + if (p < totpart) { + if (psys->particles[p].flag & (PARS_NO_DISP | PARS_UNEXIST)) continue; } else { /* handle child particle */ ChildParticle *cpa = &psys->child[p - totpart]; - if(psys->particles[cpa->parent].flag & (PARS_NO_DISP|PARS_UNEXIST)) + if (psys->particles[cpa->parent].flag & (PARS_NO_DISP | PARS_UNEXIST)) continue; } state.time = time; - if(psys_get_particle_state(&sim, p, &state, 0) == 0) + if (psys_get_particle_state(&sim, p, &state, 0) == 0) continue; /* location */ - pos = &particle_pos[valid_particles*3]; + pos = &particle_pos[valid_particles * 3]; copy_v3_v3(pos, state.co); smoke_pos_to_cell(sds, pos); /* velocity */ - copy_v3_v3(&particle_vel[valid_particles*3], state.vel); - mul_mat3_m4_v3(sds->imat, &particle_vel[valid_particles*3]); + copy_v3_v3(&particle_vel[valid_particles * 3], state.vel); + mul_mat3_m4_v3(sds->imat, &particle_vel[valid_particles * 3]); /* calculate emission map bounds */ em_boundInsert(em, pos); @@ -1015,7 +1015,7 @@ static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, Smoke clampBoundsInDomain(sds, em->min, em->max, NULL, NULL, 1, dt); em_allocateData(em, sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY); - for(p=0; p<valid_particles; p++) + for (p = 0; p < valid_particles; p++) { int cell[3]; size_t i = 0; @@ -1023,28 +1023,28 @@ static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, Smoke int badcell = 0; /* 1. get corresponding cell */ - cell[0] = floor(particle_pos[p*3]) - em->min[0]; - cell[1] = floor(particle_pos[p*3+1]) - em->min[1]; - cell[2] = floor(particle_pos[p*3+2]) - em->min[2]; + cell[0] = floor(particle_pos[p * 3]) - em->min[0]; + cell[1] = floor(particle_pos[p * 3 + 1]) - em->min[1]; + cell[2] = floor(particle_pos[p * 3 + 2]) - em->min[2]; /* check if cell is valid (in the domain boundary) */ - for(i = 0; i < 3; i++) { - if((cell[i] > em->res[i] - 1) || (cell[i] < 0)) { + for (i = 0; i < 3; i++) { + if ((cell[i] > em->res[i] - 1) || (cell[i] < 0)) { badcell = 1; break; } } - if(badcell) + if (badcell) continue; /* get cell index */ index = smoke_get_index(cell[0], em->res[0], cell[1], em->res[1], cell[2]); /* Add influence to emission map */ em->influence[index] = 1.0f; /* Uses particle velocity as initial velocity for smoke */ - if(sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY && (psys->part->phystype != PART_PHYS_NO)) + if (sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY && (psys->part->phystype != PART_PHYS_NO)) { - VECADDFAC(&em->velocity[index*3], &em->velocity[index*3], &particle_vel[p*3], sfs->vel_multi); + VECADDFAC(&em->velocity[index * 3], &em->velocity[index * 3], &particle_vel[p * 3], sfs->vel_multi); } - } // particles loop + } // particles loop /* free data */ if (particle_pos) @@ -1078,7 +1078,7 @@ static void emit_from_derivedmesh(Object *flow_ob, SmokeDomainSettings *sds, Smo if (!sfs->dm) return; { DerivedMesh *dm = sfs->dm; - int defgrp_index = sfs->vgroup_density-1; + int defgrp_index = sfs->vgroup_density - 1; MDeformVert *dvert = NULL; MVert *mvert = NULL; MVert *mvert_orig = NULL; @@ -1093,7 +1093,7 @@ static void emit_from_derivedmesh(Object *flow_ob, SmokeDomainSettings *sds, Smo CDDM_calc_normals(dm); mvert = dm->getVertArray(dm); - mvert_orig = dm->dupVertArray(dm); /* copy original mvert and restore when done */ + mvert_orig = dm->dupVertArray(dm); /* copy original mvert and restore when done */ mface = dm->getTessFaceArray(dm); numOfVerts = dm->getNumVerts(dm); dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); @@ -1113,7 +1113,7 @@ static void emit_from_derivedmesh(Object *flow_ob, SmokeDomainSettings *sds, Smo } /* Transform dm vertices to - * domain grid space for fast lookups */ + * domain grid space for fast lookups */ for (i = 0; i < numOfVerts; i++) { float n[3]; /* vert pos */ @@ -1130,10 +1130,10 @@ static void emit_from_derivedmesh(Object *flow_ob, SmokeDomainSettings *sds, Smo float co[3]; VECADD(co, mvert[i].co, sds->shift); if (has_velocity) { - sub_v3_v3v3(&vert_vel[i*3], co, &sfs->verts_old[i*3]); - mul_v3_fl(&vert_vel[i*3], sds->dx/dt); + sub_v3_v3v3(&vert_vel[i * 3], co, &sfs->verts_old[i * 3]); + mul_v3_fl(&vert_vel[i * 3], sds->dx / dt); } - copy_v3_v3(&sfs->verts_old[i*3], co); + copy_v3_v3(&sfs->verts_old[i * 3], co); } /* calculate emission map bounds */ @@ -1149,135 +1149,135 @@ static void emit_from_derivedmesh(Object *flow_ob, SmokeDomainSettings *sds, Smo if (bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 6)) { #pragma omp parallel for schedule(static) for (z = em->min[2]; z < em->max[2]; z++) { - int x,y; + int x, y; for (x = em->min[0]; x < em->max[0]; x++) - for (y = em->min[1]; y < em->max[1]; y++) { - int index = smoke_get_index(x-em->min[0], em->res[0], y-em->min[1], em->res[1], z-em->min[2]); - - float ray_start[3] = {(float)x + 0.5f, (float)y + 0.5f, (float)z + 0.5f}; - float ray_dir[3] = {1.0f, 0.0f, 0.0f}; - - BVHTreeRayHit hit = {0}; - BVHTreeNearest nearest = {0}; - - float volume_factor = 0.0f; - float sample_str = 0.0f; - - hit.index = -1; - hit.dist = 9999; - nearest.index = -1; - nearest.dist = sfs->surface_distance * sfs->surface_distance; /* find_nearest uses squared distance */ - - /* Check volume collision */ - if (sfs->volume_density) { - if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, treeData.raycast_callback, &treeData) != -1) { - float 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) { - /* Also cast a ray in opposite direction to make sure - * point is at least surrounded by two faces */ - negate_v3(ray_dir); - hit.index = -1; - hit.dist = 9999; - - BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, treeData.raycast_callback, &treeData); - if (hit.index != -1) { - volume_factor = sfs->volume_density; - nearest.dist = hit.dist*hit.dist; + for (y = em->min[1]; y < em->max[1]; y++) { + int index = smoke_get_index(x - em->min[0], em->res[0], y - em->min[1], em->res[1], z - em->min[2]); + + float ray_start[3] = {(float)x + 0.5f, (float)y + 0.5f, (float)z + 0.5f}; + float ray_dir[3] = {1.0f, 0.0f, 0.0f}; + + BVHTreeRayHit hit = {0}; + BVHTreeNearest nearest = {0}; + + float volume_factor = 0.0f; + float sample_str = 0.0f; + + hit.index = -1; + hit.dist = 9999; + nearest.index = -1; + nearest.dist = sfs->surface_distance * sfs->surface_distance; /* find_nearest uses squared distance */ + + /* Check volume collision */ + if (sfs->volume_density) { + if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, treeData.raycast_callback, &treeData) != -1) { + float 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) { + /* Also cast a ray in opposite direction to make sure + * point is at least surrounded by two faces */ + negate_v3(ray_dir); + hit.index = -1; + hit.dist = 9999; + + BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, treeData.raycast_callback, &treeData); + if (hit.index != -1) { + volume_factor = sfs->volume_density; + nearest.dist = hit.dist * hit.dist; + } } } } - } - /* find the nearest point on the mesh */ - if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, treeData.nearest_callback, &treeData) != -1) { - float weights[4]; - int v1, v2, v3, f_index = nearest.index; - float n1[3], n2[3], n3[3], hit_normal[3]; - - /* emit from surface based on distance */ - if (sfs->surface_distance) { - sample_str = sqrtf(nearest.dist) / sfs->surface_distance; - CLAMP(sample_str, 0.0f, 1.0f); - sample_str = pow(1.0f - sample_str, 0.5f); - } - else - sample_str = 0.0f; - - /* calculate barycentric weights for nearest point */ - v1 = mface[f_index].v1; - v2 = (nearest.flags & BVH_ONQUAD) ? mface[f_index].v3 : mface[f_index].v2; - v3 = (nearest.flags & BVH_ONQUAD) ? mface[f_index].v4 : mface[f_index].v3; - interp_weights_face_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, NULL, nearest.co); - - if(sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY) { - /* apply normal directional velocity */ - if (sfs->vel_normal) { - /* interpolate vertex normal vectors to get nearest point normal */ - normal_short_to_float_v3(n1, mvert[v1].no); - normal_short_to_float_v3(n2, mvert[v2].no); - normal_short_to_float_v3(n3, mvert[v3].no); - interp_v3_v3v3v3(hit_normal, n1, n2, n3, weights); - normalize_v3(hit_normal); - /* apply normal directional and random velocity - * - TODO: random disabled for now since it doesnt really work well as pressure calc smoothens it out... */ - em->velocity[index*3] += hit_normal[0]*sfs->vel_normal * 0.25f; - em->velocity[index*3+1] += hit_normal[1]*sfs->vel_normal * 0.25f; - em->velocity[index*3+2] += hit_normal[2]*sfs->vel_normal * 0.25f; - /* TODO: for fire emitted from mesh surface we can use - * Vf = Vs + (Ps/Pf - 1)*S to model gaseous expansion from solid to fuel */ + /* find the nearest point on the mesh */ + if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, treeData.nearest_callback, &treeData) != -1) { + float weights[4]; + int v1, v2, v3, f_index = nearest.index; + float n1[3], n2[3], n3[3], hit_normal[3]; + + /* emit from surface based on distance */ + if (sfs->surface_distance) { + sample_str = sqrtf(nearest.dist) / sfs->surface_distance; + CLAMP(sample_str, 0.0f, 1.0f); + sample_str = pow(1.0f - sample_str, 0.5f); } - /* apply object velocity */ - if (has_velocity && sfs->vel_multi) { - float hit_vel[3]; - interp_v3_v3v3v3(hit_vel, &vert_vel[v1*3], &vert_vel[v2*3], &vert_vel[v3*3], weights); - em->velocity[index*3] += hit_vel[0] * sfs->vel_multi; - em->velocity[index*3+1] += hit_vel[1] * sfs->vel_multi; - em->velocity[index*3+2] += hit_vel[2] * sfs->vel_multi; + else + sample_str = 0.0f; + + /* calculate barycentric weights for nearest point */ + v1 = mface[f_index].v1; + v2 = (nearest.flags & BVH_ONQUAD) ? mface[f_index].v3 : mface[f_index].v2; + v3 = (nearest.flags & BVH_ONQUAD) ? mface[f_index].v4 : mface[f_index].v3; + interp_weights_face_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, NULL, nearest.co); + + if (sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY) { + /* apply normal directional velocity */ + if (sfs->vel_normal) { + /* interpolate vertex normal vectors to get nearest point normal */ + normal_short_to_float_v3(n1, mvert[v1].no); + normal_short_to_float_v3(n2, mvert[v2].no); + normal_short_to_float_v3(n3, mvert[v3].no); + interp_v3_v3v3v3(hit_normal, n1, n2, n3, weights); + normalize_v3(hit_normal); + /* apply normal directional and random velocity + * - TODO: random disabled for now since it doesnt really work well as pressure calc smoothens it out... */ + em->velocity[index * 3] += hit_normal[0] * sfs->vel_normal * 0.25f; + em->velocity[index * 3 + 1] += hit_normal[1] * sfs->vel_normal * 0.25f; + em->velocity[index * 3 + 2] += hit_normal[2] * sfs->vel_normal * 0.25f; + /* TODO: for fire emitted from mesh surface we can use + * Vf = Vs + (Ps/Pf - 1)*S to model gaseous expansion from solid to fuel */ + } + /* apply object velocity */ + if (has_velocity && sfs->vel_multi) { + float hit_vel[3]; + interp_v3_v3v3v3(hit_vel, &vert_vel[v1 * 3], &vert_vel[v2 * 3], &vert_vel[v3 * 3], weights); + em->velocity[index * 3] += hit_vel[0] * sfs->vel_multi; + em->velocity[index * 3 + 1] += hit_vel[1] * sfs->vel_multi; + em->velocity[index * 3 + 2] += hit_vel[2] * sfs->vel_multi; + } } - } - /* apply vertex group influence if used */ - if (defgrp_index >= 0 && dvert) { - float weight_mask = defvert_find_weight(&dvert[v1], defgrp_index) * weights[0] + - defvert_find_weight(&dvert[v2], defgrp_index) * weights[1] + - defvert_find_weight(&dvert[v3], defgrp_index) * weights[2]; - sample_str *= weight_mask; - } + /* apply vertex group influence if used */ + if (defgrp_index >= 0 && dvert) { + float weight_mask = defvert_find_weight(&dvert[v1], defgrp_index) * weights[0] + + defvert_find_weight(&dvert[v2], defgrp_index) * weights[1] + + defvert_find_weight(&dvert[v3], defgrp_index) * weights[2]; + sample_str *= weight_mask; + } - /* apply emission texture */ - if ((sfs->flags & MOD_SMOKE_FLOW_TEXTUREEMIT) && sfs->noise_texture) { - float tex_co[3] = {0}; - TexResult texres; + /* apply emission texture */ + if ((sfs->flags & MOD_SMOKE_FLOW_TEXTUREEMIT) && sfs->noise_texture) { + float tex_co[3] = {0}; + TexResult texres; - if (sfs->texture_type == MOD_SMOKE_FLOW_TEXTURE_MAP_AUTO) { - tex_co[0] = ((float)(x - flow_center[0]) / sds->base_res[0]) / sfs->texture_size; - tex_co[1] = ((float)(y - flow_center[1]) / sds->base_res[1]) / sfs->texture_size; - tex_co[2] = ((float)(z - flow_center[2]) / sds->base_res[2] - sfs->texture_offset) / sfs->texture_size; - } - else if (tface) { - interp_v2_v2v2v2(tex_co, tface[f_index].uv[0], tface[f_index].uv[(nearest.flags & BVH_ONQUAD) ? 2 : 1], - tface[f_index].uv[(nearest.flags & BVH_ONQUAD) ? 3 : 2], weights); - /* map between -1.0f and 1.0f */ - tex_co[0] = tex_co[0] * 2.0f - 1.0f; - tex_co[1] = tex_co[1] * 2.0f - 1.0f; - tex_co[2] = sfs->texture_offset; + if (sfs->texture_type == MOD_SMOKE_FLOW_TEXTURE_MAP_AUTO) { + tex_co[0] = ((float)(x - flow_center[0]) / sds->base_res[0]) / sfs->texture_size; + tex_co[1] = ((float)(y - flow_center[1]) / sds->base_res[1]) / sfs->texture_size; + tex_co[2] = ((float)(z - flow_center[2]) / sds->base_res[2] - sfs->texture_offset) / sfs->texture_size; + } + else if (tface) { + interp_v2_v2v2v2(tex_co, tface[f_index].uv[0], tface[f_index].uv[(nearest.flags & BVH_ONQUAD) ? 2 : 1], + tface[f_index].uv[(nearest.flags & BVH_ONQUAD) ? 3 : 2], weights); + /* map between -1.0f and 1.0f */ + tex_co[0] = tex_co[0] * 2.0f - 1.0f; + tex_co[1] = tex_co[1] * 2.0f - 1.0f; + tex_co[2] = sfs->texture_offset; + } + texres.nor = NULL; + get_texture_value(sfs->noise_texture, tex_co, &texres); + sample_str *= texres.tin; } - texres.nor = NULL; - get_texture_value(sfs->noise_texture, tex_co, &texres); - sample_str *= texres.tin; } - } - /* multiply initial velocity by emitter influence */ - if(sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY) { - mul_v3_fl(&em->velocity[index*3], sample_str); - } + /* multiply initial velocity by emitter influence */ + if (sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY) { + mul_v3_fl(&em->velocity[index * 3], sample_str); + } - /* apply final influence based on volume factor */ - em->influence[index] = MAX2(volume_factor, sample_str); - } + /* apply final influence based on volume factor */ + em->influence[index] = MAX2(volume_factor, sample_str); + } } } /* free bvh tree */ @@ -1293,10 +1293,10 @@ static void emit_from_derivedmesh(Object *flow_ob, SmokeDomainSettings *sds, Smo static void adjustDomainResolution(SmokeDomainSettings *sds, int new_shift[3], EmissionMap *emaps, unsigned int numflowobj, float dt) { - int min[3]={32767,32767,32767}, max[3]={-32767,-32767,-32767}, res[3]; + int min[3] = {32767, 32767, 32767}, max[3] = {-32767, -32767, -32767}, res[3]; int total_cells = 1, res_changed = 0, shift_changed = 0; float min_vel[3], max_vel[3]; - int x,y,z, i; + int x, y, z, i; float *density = smoke_get_density(sds->fluid); float *fuel = smoke_get_fuel(sds->fluid); float *vx = smoke_get_velocity_x(sds->fluid); @@ -1306,14 +1306,14 @@ static void adjustDomainResolution(SmokeDomainSettings *sds, int new_shift[3], E INIT_MINMAX(min_vel, max_vel); /* Calculate bounds for current domain content */ - for(x = sds->res_min[0]; x < sds->res_max[0]; x++) - for(y = sds->res_min[1]; y < sds->res_max[1]; y++) - for(z = sds->res_min[2]; z < sds->res_max[2]; z++) + for (x = sds->res_min[0]; x < sds->res_max[0]; x++) + for (y = sds->res_min[1]; y < sds->res_max[1]; y++) + for (z = sds->res_min[2]; z < sds->res_max[2]; z++) { - int xn = x-new_shift[0]; - int yn = y-new_shift[1]; - int zn = z-new_shift[2]; - int index = smoke_get_index(x-sds->res_min[0], sds->res[0], y-sds->res_min[1], sds->res[1], z-sds->res_min[2]); + int xn = x - new_shift[0]; + int yn = y - new_shift[1]; + int zn = z - new_shift[2]; + int index = smoke_get_index(x - sds->res_min[0], sds->res[0], y - sds->res_min[1], sds->res[1], z - sds->res_min[2]); float max_den = (fuel) ? MAX2(density[index], fuel[index]) : density[index]; /* content bounds (use shifted coordinates) */ @@ -1335,15 +1335,15 @@ static void adjustDomainResolution(SmokeDomainSettings *sds, int new_shift[3], E } /* also apply emission maps */ - for(i = 0; i < numflowobj; i++) + for (i = 0; i < numflowobj; i++) { EmissionMap *em = &emaps[i]; - for(x = em->min[0]; x < em->max[0]; x++) - for(y = em->min[1]; y < em->max[1]; y++) - for(z = em->min[2]; z < em->max[2]; z++) + for (x = em->min[0]; x < em->max[0]; x++) + for (y = em->min[1]; y < em->max[1]; y++) + for (z = em->min[2]; z < em->max[2]; z++) { - int index = smoke_get_index(x-em->min[0], em->res[0], y-em->min[1], em->res[1], z-em->min[2]); + int index = smoke_get_index(x - em->min[0], em->res[0], y - em->min[1], em->res[1], z - em->min[2]); float max_den = em->influence[index]; /* density bounds */ @@ -1357,20 +1357,20 @@ static void adjustDomainResolution(SmokeDomainSettings *sds, int new_shift[3], E } /* velocity bounds */ if (em->velocity) { - if (min_vel[0] > em->velocity[index*3]) min_vel[0] = em->velocity[index*3]; - if (min_vel[1] > em->velocity[index*3+1]) min_vel[1] = em->velocity[index*3+1]; - if (min_vel[2] > em->velocity[index*3+2]) min_vel[2] = em->velocity[index*3+2]; - if (max_vel[0] < em->velocity[index*3]) max_vel[0] = em->velocity[index*3]; - if (max_vel[1] < em->velocity[index*3+1]) max_vel[1] = em->velocity[index*3+1]; - if (max_vel[2] < em->velocity[index*3+2]) max_vel[2] = em->velocity[index*3+2]; + if (min_vel[0] > em->velocity[index * 3]) min_vel[0] = em->velocity[index * 3]; + if (min_vel[1] > em->velocity[index * 3 + 1]) min_vel[1] = em->velocity[index * 3 + 1]; + if (min_vel[2] > em->velocity[index * 3 + 2]) min_vel[2] = em->velocity[index * 3 + 2]; + if (max_vel[0] < em->velocity[index * 3]) max_vel[0] = em->velocity[index * 3]; + if (max_vel[1] < em->velocity[index * 3 + 1]) max_vel[1] = em->velocity[index * 3 + 1]; + if (max_vel[2] < em->velocity[index * 3 + 2]) max_vel[2] = em->velocity[index * 3 + 2]; } } } /* calculate new bounds based on these values */ - clampBoundsInDomain(sds, min, max, min_vel, max_vel, sds->adapt_margin+1, dt); + clampBoundsInDomain(sds, min, max, min_vel, max_vel, sds->adapt_margin + 1, dt); - for (i=0; i<3; i++) { + for (i = 0; i < 3; i++) { /* calculate new resolution */ res[i] = max[i] - min[i]; total_cells *= res[i]; @@ -1381,7 +1381,7 @@ static void adjustDomainResolution(SmokeDomainSettings *sds, int new_shift[3], E /* if no content set minimum dimensions */ if (res[i] <= 0) { int j; - for (j=0; j<3; j++) { + for (j = 0; j < 3; j++) { min[j] = 0; max[j] = 1; res[j] = 1; @@ -1399,12 +1399,12 @@ static void adjustDomainResolution(SmokeDomainSettings *sds, int new_shift[3], E struct WTURBULENCE *turb_old = sds->wt; /* allocate new fluid data */ smoke_reallocate_fluid(sds, sds->dx, res, 0); - if(sds->flags & MOD_SMOKE_HIGHRES) { + if (sds->flags & MOD_SMOKE_HIGHRES) { smoke_reallocate_highres_fluid(sds, sds->dx, res, 0); } /* copy values from old fluid to new */ - if (sds->total_cells>1 && total_cells>1) { + if (sds->total_cells > 1 && total_cells > 1) { /* low res smoke */ float *o_dens, *o_react, *o_flame, *o_fuel, *o_heat, *o_heatold, *o_vx, *o_vy, *o_vz, *o_r, *o_g, *o_b; float *n_dens, *n_react, *n_flame, *n_fuel, *n_heat, *n_heatold, *n_vx, *n_vy, *n_vz, *n_r, *n_g, *n_b; @@ -1418,32 +1418,32 @@ static void adjustDomainResolution(SmokeDomainSettings *sds, int new_shift[3], E smoke_export(fluid_old, &dummy, &dummy, &o_dens, &o_react, &o_flame, &o_fuel, &o_heat, &o_heatold, &o_vx, &o_vy, &o_vz, &o_r, &o_g, &o_b, &dummy_p); smoke_export(sds->fluid, &dummy, &dummy, &n_dens, &n_react, &n_flame, &n_fuel, &n_heat, &n_heatold, &n_vx, &n_vy, &n_vz, &n_r, &n_g, &n_b, &dummy_p); - if(sds->flags & MOD_SMOKE_HIGHRES) { + if (sds->flags & MOD_SMOKE_HIGHRES) { smoke_turbulence_export(turb_old, &o_wt_dens, &o_wt_react, &o_wt_flame, &o_wt_fuel, &o_wt_r, &o_wt_g, &o_wt_b, &o_wt_tcu, &o_wt_tcv, &o_wt_tcw); smoke_turbulence_get_res(turb_old, wt_res_old); smoke_turbulence_export(sds->wt, &n_wt_dens, &n_wt_react, &n_wt_flame, &n_wt_fuel, &n_wt_r, &n_wt_g, &n_wt_b, &n_wt_tcu, &n_wt_tcv, &n_wt_tcw); } - for(x = sds->res_min[0]; x < sds->res_max[0]; x++) - for(y = sds->res_min[1]; y < sds->res_max[1]; y++) - for(z = sds->res_min[2]; z < sds->res_max[2]; z++) + for (x = sds->res_min[0]; x < sds->res_max[0]; x++) + for (y = sds->res_min[1]; y < sds->res_max[1]; y++) + for (z = sds->res_min[2]; z < sds->res_max[2]; z++) { /* old grid index */ - int xo = x-sds->res_min[0]; - int yo = y-sds->res_min[1]; - int zo = z-sds->res_min[2]; + int xo = x - sds->res_min[0]; + int yo = y - sds->res_min[1]; + int zo = z - sds->res_min[2]; int index_old = smoke_get_index(xo, sds->res[0], yo, sds->res[1], zo); /* new grid index */ - int xn = x-min[0]-new_shift[0]; - int yn = y-min[1]-new_shift[1]; - int zn = z-min[2]-new_shift[2]; + int xn = x - min[0] - new_shift[0]; + int yn = y - min[1] - new_shift[1]; + int zn = z - min[2] - new_shift[2]; int index_new = smoke_get_index(xn, res[0], yn, res[1], zn); /* skip if outside new domain */ - if (xn<0 || xn>=res[0] || - yn<0 || yn>=res[1] || - zn<0 || zn>=res[2]) + if (xn < 0 || xn >= res[0] || + yn < 0 || yn >= res[1] || + zn < 0 || zn >= res[2]) continue; /* copy data */ @@ -1469,28 +1469,28 @@ static void adjustDomainResolution(SmokeDomainSettings *sds, int new_shift[3], E n_vy[index_new] = o_vy[index_old]; n_vz[index_new] = o_vz[index_old]; - if(sds->flags & MOD_SMOKE_HIGHRES && turb_old) { + if (sds->flags & MOD_SMOKE_HIGHRES && turb_old) { int block_size = sds->amplify + 1; - int i,j,k; + int i, j, k; /* old grid index */ - int xx_o = xo*block_size; - int yy_o = yo*block_size; - int zz_o = zo*block_size; + int xx_o = xo * block_size; + int yy_o = yo * block_size; + int zz_o = zo * block_size; /* new grid index */ - int xx_n = xn*block_size; - int yy_n = yn*block_size; - int zz_n = zn*block_size; + int xx_n = xn * block_size; + int yy_n = yn * block_size; + int zz_n = zn * block_size; n_wt_tcu[index_new] = o_wt_tcu[index_old]; n_wt_tcv[index_new] = o_wt_tcv[index_old]; n_wt_tcw[index_new] = o_wt_tcw[index_old]; - for(i = 0; i < block_size; i++) - for(j = 0; j < block_size; j++) - for(k = 0; k < block_size; k++) + for (i = 0; i < block_size; i++) + for (j = 0; j < block_size; j++) + for (k = 0; k < block_size; k++) { - int big_index_old = smoke_get_index(xx_o+i, wt_res_old[0], yy_o+j, wt_res_old[1], zz_o+k); - int big_index_new = smoke_get_index(xx_n+i, sds->res_wt[0], yy_n+j, sds->res_wt[1], zz_n+k); + int big_index_old = smoke_get_index(xx_o + i, wt_res_old[0], yy_o + j, wt_res_old[1], zz_o + k); + int big_index_new = smoke_get_index(xx_n + i, sds->res_wt[0], yy_n + j, sds->res_wt[1], zz_n + k); /* copy data */ n_wt_dens[big_index_new] = o_wt_dens[big_index_old]; if (n_wt_flame && o_wt_flame) { @@ -1545,7 +1545,7 @@ BLI_INLINE void apply_inflow_fields(SmokeFlowSettings *sfs, float emission_value float fuel_flow = emission_value * sfs->fuel_amount; /* add heat */ if (heat) { - heat[index] = MAX2(emission_value*sfs->temp, heat[index]); + heat[index] = MAX2(emission_value * sfs->temp, heat[index]); } /* absolute */ if (absolute_flow) { @@ -1572,7 +1572,7 @@ BLI_INLINE void apply_inflow_fields(SmokeFlowSettings *sfs, float emission_value /* set color */ if (color_r && dens_flow) { - float total_dens = density[index]/(dens_old+dens_flow); + float total_dens = density[index] / (dens_old + dens_flow); color_r[index] = (color_r[index] + sfs->color[0] * dens_flow) * total_dens; color_g[index] = (color_g[index] + sfs->color[1] * dens_flow) * total_dens; color_b[index] = (color_b[index] + sfs->color[2] * dens_flow) * total_dens; @@ -1586,7 +1586,7 @@ BLI_INLINE void apply_inflow_fields(SmokeFlowSettings *sfs, float emission_value if (value > react[index]) { float f = fuel_flow / fuel[index]; - react[index] = value*f + (1.0f - f)*react[index]; + react[index] = value * f + (1.0f - f) * react[index]; } } } @@ -1612,9 +1612,9 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd copy_v3_v3(sds->prev_loc, ob_loc); /* convert global space shift to local "cell" space */ mul_mat3_m4_v3(sds->imat, frame_shift_f); - frame_shift_f[0] = frame_shift_f[0]/sds->cell_size[0]; - frame_shift_f[1] = frame_shift_f[1]/sds->cell_size[1]; - frame_shift_f[2] = frame_shift_f[2]/sds->cell_size[2]; + frame_shift_f[0] = frame_shift_f[0] / sds->cell_size[0]; + frame_shift_f[1] = frame_shift_f[1] / sds->cell_size[1]; + frame_shift_f[2] = frame_shift_f[2] / sds->cell_size[2]; /* add to total shift */ VECADD(sds->shift_f, sds->shift_f, frame_shift_f); /* convert to integer */ @@ -1625,12 +1625,12 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd copy_v3_v3_int(sds->shift, total_shift); /* calculate new domain boundary points so that smoke doesnt slide on sub-cell movement */ - sds->p0[0] = sds->dp0[0] - sds->cell_size[0]*(sds->shift_f[0]-total_shift[0] - 0.5f); - sds->p0[1] = sds->dp0[1] - sds->cell_size[1]*(sds->shift_f[1]-total_shift[1] - 0.5f); - sds->p0[2] = sds->dp0[2] - sds->cell_size[2]*(sds->shift_f[2]-total_shift[2] - 0.5f); - sds->p1[0] = sds->p0[0] + sds->cell_size[0]*sds->base_res[0]; - sds->p1[1] = sds->p0[1] + sds->cell_size[1]*sds->base_res[1]; - sds->p1[2] = sds->p0[2] + sds->cell_size[2]*sds->base_res[2]; + sds->p0[0] = sds->dp0[0] - sds->cell_size[0] * (sds->shift_f[0] - total_shift[0] - 0.5f); + sds->p0[1] = sds->dp0[1] - sds->cell_size[1] * (sds->shift_f[1] - total_shift[1] - 0.5f); + sds->p0[2] = sds->dp0[2] - sds->cell_size[2] * (sds->shift_f[2] - total_shift[2] - 0.5f); + sds->p1[0] = sds->p0[0] + sds->cell_size[0] * sds->base_res[0]; + sds->p1[1] = sds->p0[1] + sds->cell_size[1] * sds->base_res[1]; + sds->p1[2] = sds->p0[2] + sds->cell_size[2] * sds->base_res[2]; } flowobjs = get_collisionobjects(scene, ob, sds->fluid_group, &numflowobj, eModifierType_Smoke); @@ -1639,13 +1639,13 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd emaps = MEM_callocN(sizeof(struct EmissionMap) * numflowobj, "smoke_flow_maps"); /* Prepare flow emission maps */ - for(flowIndex = 0; flowIndex < numflowobj; flowIndex++) + for (flowIndex = 0; flowIndex < numflowobj; flowIndex++) { - Object *collob= flowobjs[flowIndex]; - SmokeModifierData *smd2 = (SmokeModifierData*)modifiers_findByType(collob, eModifierType_Smoke); + Object *collob = flowobjs[flowIndex]; + SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(collob, eModifierType_Smoke); // check for initialized smoke object - if((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) + if ((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) { // we got nice flow object SmokeFlowSettings *sfs = smd2->flow; @@ -1717,18 +1717,18 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd /* Apply emission data */ if (sds->fluid) { - for(flowIndex = 0; flowIndex < numflowobj; flowIndex++) + for (flowIndex = 0; flowIndex < numflowobj; flowIndex++) { - Object *collob= flowobjs[flowIndex]; - SmokeModifierData *smd2 = (SmokeModifierData*)modifiers_findByType(collob, eModifierType_Smoke); + Object *collob = flowobjs[flowIndex]; + SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(collob, eModifierType_Smoke); // check for initialized smoke object - if((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) + if ((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) { // we got nice flow object SmokeFlowSettings *sfs = smd2->flow; EmissionMap *em = &emaps[flowIndex]; - + float *density = smoke_get_density(sds->fluid); float *color_r = smoke_get_color_r(sds->fluid); float *color_g = smoke_get_color_g(sds->fluid); @@ -1745,7 +1745,7 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd float *velocity_x = smoke_get_velocity_x(sds->fluid); float *velocity_y = smoke_get_velocity_y(sds->fluid); float *velocity_z = smoke_get_velocity_z(sds->fluid); - //unsigned char *obstacle = smoke_get_obstacle(sds->fluid); + //unsigned char *obstacle = smoke_get_obstacle(sds->fluid); // DG TODO UNUSED unsigned char *obstacleAnim = smoke_get_obstacle_anim(sds->fluid); int bigres[3]; short high_emission_smoothing = (sds->flags & MOD_SMOKE_HIGH_SMOOTH); @@ -1756,33 +1756,33 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd size_t e_index, d_index, index_big; // loop through every emission map cell - for(gx = em->min[0]; gx < em->max[0]; gx++) - for(gy = em->min[1]; gy < em->max[1]; gy++) - for(gz = em->min[2]; gz < em->max[2]; gz++) + for (gx = em->min[0]; gx < em->max[0]; gx++) + for (gy = em->min[1]; gy < em->max[1]; gy++) + for (gz = em->min[2]; gz < em->max[2]; gz++) { /* get emission map index */ - ex = gx-em->min[0]; - ey = gy-em->min[1]; - ez = gz-em->min[2]; + ex = gx - em->min[0]; + ey = gy - em->min[1]; + ez = gz - em->min[2]; e_index = smoke_get_index(ex, em->res[0], ey, em->res[1], ez); if (!emission_map[e_index]) continue; /* get domain index */ - dx = gx-sds->res_min[0]; - dy = gy-sds->res_min[1]; - dz = gz-sds->res_min[2]; + dx = gx - sds->res_min[0]; + dy = gy - sds->res_min[1]; + dz = gz - sds->res_min[2]; d_index = smoke_get_index(dx, sds->res[0], dy, sds->res[1], dz); - if(sfs->type == MOD_SMOKE_FLOW_TYPE_OUTFLOW) { // outflow + if (sfs->type == MOD_SMOKE_FLOW_TYPE_OUTFLOW) { // outflow apply_outflow_fields(d_index, density, heat, fuel, react, color_r, color_g, color_b); } else { // inflow apply_inflow_fields(sfs, emission_map[e_index], d_index, density, heat, fuel, react, color_r, color_g, color_b); /* initial velocity */ - if(sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY) { - velocity_x[d_index] = ADD_IF_LOWER(velocity_x[d_index], velocity_map[e_index*3]); - velocity_y[d_index] = ADD_IF_LOWER(velocity_y[d_index], velocity_map[e_index*3+1]); - velocity_z[d_index] = ADD_IF_LOWER(velocity_z[d_index], velocity_map[e_index*3+2]); + if (sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY) { + velocity_x[d_index] = ADD_IF_LOWER(velocity_x[d_index], velocity_map[e_index * 3]); + velocity_y[d_index] = ADD_IF_LOWER(velocity_y[d_index], velocity_map[e_index * 3 + 1]); + velocity_z[d_index] = ADD_IF_LOWER(velocity_z[d_index], velocity_map[e_index * 3 + 2]); } } @@ -1792,64 +1792,63 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd float c000, c001, c010, c011, c100, c101, c110, c111; smoke_turbulence_get_res(sds->wt, bigres); - block_size = sds->amplify + 1; // high res block size + block_size = sds->amplify + 1; // high res block size - c000 = (ex>0 && ey>0 && ez>0) ? emission_map[smoke_get_index(ex-1, em->res[0], ey-1, em->res[1], ez-1)] : 0; - c001 = (ex>0 && ey>0) ? emission_map[smoke_get_index(ex-1, em->res[0], ey-1, em->res[1], ez)] : 0; - c010 = (ex>0 && ez>0) ? emission_map[smoke_get_index(ex-1, em->res[0], ey, em->res[1], ez-1)] : 0; - c011 = (ex>0) ? emission_map[smoke_get_index(ex-1, em->res[0], ey, em->res[1], ez)] : 0; + c000 = (ex > 0 && ey > 0 && ez > 0) ? emission_map[smoke_get_index(ex - 1, em->res[0], ey - 1, em->res[1], ez - 1)] : 0; + c001 = (ex > 0 && ey > 0) ? emission_map[smoke_get_index(ex - 1, em->res[0], ey - 1, em->res[1], ez)] : 0; + c010 = (ex > 0 && ez > 0) ? emission_map[smoke_get_index(ex - 1, em->res[0], ey, em->res[1], ez - 1)] : 0; + c011 = (ex > 0) ? emission_map[smoke_get_index(ex - 1, em->res[0], ey, em->res[1], ez)] : 0; - c100 = (ey>0 && ez>0) ? emission_map[smoke_get_index(ex, em->res[0], ey-1, em->res[1], ez-1)] : 0; - c101 = (ey>0) ? emission_map[smoke_get_index(ex, em->res[0], ey-1, em->res[1], ez)] : 0; - c110 = (ez>0) ? emission_map[smoke_get_index(ex, em->res[0], ey, em->res[1], ez-1)] : 0; + c100 = (ey > 0 && ez > 0) ? emission_map[smoke_get_index(ex, em->res[0], ey - 1, em->res[1], ez - 1)] : 0; + c101 = (ey > 0) ? emission_map[smoke_get_index(ex, em->res[0], ey - 1, em->res[1], ez)] : 0; + c110 = (ez > 0) ? emission_map[smoke_get_index(ex, em->res[0], ey, em->res[1], ez - 1)] : 0; c111 = emission_map[smoke_get_index(ex, em->res[0], ey, em->res[1], ez)]; // this cell - for(ii = 0; ii < block_size; ii++) - for(jj = 0; jj < block_size; jj++) - for(kk = 0; kk < block_size; kk++) + for (ii = 0; ii < block_size; ii++) + for (jj = 0; jj < block_size; jj++) + for (kk = 0; kk < block_size; kk++) { - float fx,fy,fz, interpolated_value; + float fx, fy, fz, interpolated_value; int shift_x, shift_y, shift_z; /* - * Do volume interpolation if emitter smoothing - * is enabled - */ + * Do volume interpolation if emitter smoothing + * is enabled + */ if (high_emission_smoothing) { /* get relative block position * for interpolation smoothing */ - fx = (float)ii/block_size + 0.5f/block_size; - fy = (float)jj/block_size + 0.5f/block_size; - fz = (float)kk/block_size + 0.5f/block_size; + fx = (float)ii / block_size + 0.5f / block_size; + fy = (float)jj / block_size + 0.5f / block_size; + fz = (float)kk / block_size + 0.5f / block_size; /* calculate trilinear interpolation */ - interpolated_value = c000 * (1-fx) * (1-fy) * (1-fz) + - c100 * fx * (1-fy) * (1-fz) + - c010 * (1-fx) * fy * (1-fz) + - c001 * (1-fx) * (1-fy) * fz + - c101 * fx * (1-fy) * fz + - c011 * (1-fx) * fy * fz + - c110 * fx * fy * (1-fz) + - c111 * fx * fy * fz; + interpolated_value = c000 * (1 - fx) * (1 - fy) * (1 - fz) + + c100 * fx * (1 - fy) * (1 - fz) + + c010 * (1 - fx) * fy * (1 - fz) + + c001 * (1 - fx) * (1 - fy) * fz + + c101 * fx * (1 - fy) * fz + + c011 * (1 - fx) * fy * fz + + c110 * fx * fy * (1 - fz) + + c111 * fx * fy * fz; /* add some contrast / sharpness * depending on hi-res block size */ - interpolated_value = (interpolated_value-0.4f)*(block_size/2) + 0.4f; + interpolated_value = (interpolated_value - 0.4f) * (block_size / 2) + 0.4f; CLAMP(interpolated_value, 0.0f, 1.0f); /* shift smoke block index * (because pixel center is actually * in halfway of the low res block) */ - shift_x = (dx < 1) ? 0 : block_size/2; - shift_y = (dy < 1) ? 0 : block_size/2; - shift_z = (dz < 1) ? 0 : block_size/2; + shift_x = (dx < 1) ? 0 : block_size / 2; + shift_y = (dy < 1) ? 0 : block_size / 2; + shift_z = (dz < 1) ? 0 : block_size / 2; } - else - { + else { /* without interpolation use same low resolution * block value for all hi-res blocks */ interpolated_value = c111; @@ -1859,9 +1858,9 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd } /* get shifted index for current high resolution block */ - index_big = smoke_get_index(block_size * dx + ii - shift_x, bigres[0], block_size * dy + jj - shift_y, bigres[1], block_size * dz + kk - shift_z); + index_big = smoke_get_index(block_size * dx + ii - shift_x, bigres[0], block_size * dy + jj - shift_y, bigres[1], block_size * dz + kk - shift_z); - if(sfs->type == MOD_SMOKE_FLOW_TYPE_OUTFLOW) { // outflow + if (sfs->type == MOD_SMOKE_FLOW_TYPE_OUTFLOW) { // outflow if (interpolated_value) { apply_outflow_fields(index_big, bigdensity, NULL, bigfuel, bigreact, bigcolor_r, bigcolor_g, bigcolor_b); } @@ -1880,9 +1879,9 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd } } - if(flowobjs) + if (flowobjs) MEM_freeN(flowobjs); - if(emaps) + if (emaps) MEM_freeN(emaps); } @@ -1893,7 +1892,7 @@ static void update_effectors(Scene *scene, Object *ob, SmokeDomainSettings *sds, sds->effector_weights->weight[PFIELD_SMOKEFLOW] = 0.0f; effectors = pdInitEffectors(scene, ob, NULL, sds->effector_weights); - if(effectors) + if (effectors) { float *density = smoke_get_density(sds->fluid); float *force_x = smoke_get_force_x(sds->fluid); @@ -1907,49 +1906,49 @@ static void update_effectors(Scene *scene, Object *ob, SmokeDomainSettings *sds, // precalculate wind forces #pragma omp parallel for schedule(static) - for(x = 0; x < sds->res[0]; x++) + for (x = 0; x < sds->res[0]; x++) { int y, z; - for(y = 0; y < sds->res[1]; y++) - for(z = 0; z < sds->res[2]; z++) - { - EffectedPoint epoint; - float mag; - float voxelCenter[3] = {0,0,0}, vel[3] = {0,0,0}, retvel[3] = {0,0,0}; - unsigned int index = smoke_get_index(x, sds->res[0], y, sds->res[1], z); - - if((density[index] < FLT_EPSILON) || obstacle[index]) - continue; - - vel[0] = velocity_x[index]; - vel[1] = velocity_y[index]; - vel[2] = velocity_z[index]; - - /* convert vel to global space */ - mag = len_v3(vel); - mul_mat3_m4_v3(sds->obmat, vel); - normalize_v3(vel); - mul_v3_fl(vel, mag); - - voxelCenter[0] = sds->p0[0] + sds->cell_size[0] * ((float)(x+sds->res_min[0]) + 0.5f); - voxelCenter[1] = sds->p0[1] + sds->cell_size[1] * ((float)(y+sds->res_min[1]) + 0.5f); - voxelCenter[2] = sds->p0[2] + sds->cell_size[2] * ((float)(z+sds->res_min[2]) + 0.5f); - mul_m4_v3(sds->obmat, voxelCenter); - - pd_point_from_loc(scene, voxelCenter, vel, index, &epoint); - pdDoEffectors(effectors, NULL, sds->effector_weights, &epoint, retvel, NULL); - - /* convert retvel to local space */ - mag = len_v3(retvel); - mul_mat3_m4_v3(sds->imat, retvel); - normalize_v3(retvel); - mul_v3_fl(retvel, mag); - - // TODO dg - do in force! - force_x[index] = MIN2(MAX2(-1.0, retvel[0] * 0.2), 1.0); - force_y[index] = MIN2(MAX2(-1.0, retvel[1] * 0.2), 1.0); - force_z[index] = MIN2(MAX2(-1.0, retvel[2] * 0.2), 1.0); - } + for (y = 0; y < sds->res[1]; y++) + for (z = 0; z < sds->res[2]; z++) + { + EffectedPoint epoint; + float mag; + float voxelCenter[3] = {0, 0, 0}, vel[3] = {0, 0, 0}, retvel[3] = {0, 0, 0}; + unsigned int index = smoke_get_index(x, sds->res[0], y, sds->res[1], z); + + if ((density[index] < FLT_EPSILON) || obstacle[index]) + continue; + + vel[0] = velocity_x[index]; + vel[1] = velocity_y[index]; + vel[2] = velocity_z[index]; + + /* convert vel to global space */ + mag = len_v3(vel); + mul_mat3_m4_v3(sds->obmat, vel); + normalize_v3(vel); + mul_v3_fl(vel, mag); + + voxelCenter[0] = sds->p0[0] + sds->cell_size[0] * ((float)(x + sds->res_min[0]) + 0.5f); + voxelCenter[1] = sds->p0[1] + sds->cell_size[1] * ((float)(y + sds->res_min[1]) + 0.5f); + voxelCenter[2] = sds->p0[2] + sds->cell_size[2] * ((float)(z + sds->res_min[2]) + 0.5f); + mul_m4_v3(sds->obmat, voxelCenter); + + pd_point_from_loc(scene, voxelCenter, vel, index, &epoint); + pdDoEffectors(effectors, NULL, sds->effector_weights, &epoint, retvel, NULL); + + /* convert retvel to local space */ + mag = len_v3(retvel); + mul_mat3_m4_v3(sds->imat, retvel); + normalize_v3(retvel); + mul_v3_fl(retvel, mag); + + // TODO dg - do in force! + force_x[index] = MIN2(MAX2(-1.0, retvel[0] * 0.2), 1.0); + force_y[index] = MIN2(MAX2(-1.0, retvel[1] * 0.2), 1.0); + force_z[index] = MIN2(MAX2(-1.0, retvel[2] * 0.2), 1.0); + } } } @@ -1973,7 +1972,7 @@ static void step(Scene *scene, Object *ob, SmokeModifierData *smd, DerivedMesh * float gravity_mag; #if 0 /* UNUSED */ - /* get max velocity and lower the dt value if it is too high */ + /* get max velocity and lower the dt value if it is too high */ size_t size = sds->res[0] * sds->res[1] * sds->res[2]; float *velX = smoke_get_velocity_x(sds->fluid); float *velY = smoke_get_velocity_y(sds->fluid); @@ -1990,7 +1989,7 @@ static void step(Scene *scene, Object *ob, SmokeModifierData *smd, DerivedMesh * if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) { copy_v3_v3(gravity, scene->physics_settings.gravity); /* map default value to 1.0 */ - mul_v3_fl(gravity, 1.0f/9.810f); + mul_v3_fl(gravity, 1.0f / 9.810f); } /* convert gravity to domain space */ gravity_mag = len_v3(gravity); @@ -2005,8 +2004,8 @@ static void step(Scene *scene, Object *ob, SmokeModifierData *smd, DerivedMesh * #if 0 for (i = 0; i < size; i++) { - float vtemp = (velX[i]*velX[i]+velY[i]*velY[i]+velZ[i]*velZ[i]); - if(vtemp > maxVelMag) + float vtemp = (velX[i] * velX[i] + velY[i] * velY[i] + velZ[i] * velZ[i]); + if (vtemp > maxVelMag) maxVelMag = vtemp; } #endif @@ -2017,13 +2016,13 @@ static void step(Scene *scene, Object *ob, SmokeModifierData *smd, DerivedMesh * totalSubsteps = (totalSubsteps > maxSubSteps) ? maxSubSteps : totalSubsteps; /* Disable substeps for now, since it results in numerical instability */ - totalSubsteps = 1.0f; + totalSubsteps = 1.0f; dtSubdiv = (float)dt / (float)totalSubsteps; // printf("totalSubsteps: %d, maxVelMag: %f, dt: %f\n", totalSubsteps, maxVelMag, dt); - for(substep = 0; substep < totalSubsteps; substep++) + for (substep = 0; substep < totalSubsteps; substep++) { // calc animated obstacle velocities update_flowsfluids(scene, ob, sds, smd->time, dtSubdiv); @@ -2059,7 +2058,7 @@ static DerivedMesh *createDomainGeometry(SmokeDomainSettings *sds, Object *ob) num_verts = 0; num_faces = 0; } - + result = CDDM_new(num_verts, 0, 0, num_faces * 4, num_faces); mverts = CDDM_get_verts(result); mpolys = CDDM_get_polys(result); @@ -2104,7 +2103,7 @@ static DerivedMesh *createDomainGeometry(SmokeDomainSettings *sds, Object *ob) ml[0].v = 1; ml[1].v = 0; ml[2].v = 4; ml[3].v = 5; /* calculate required shift to match domain's global position - * it was originally simulated at (if object moves without smoke step) */ + * it was originally simulated at (if object moves without smoke step) */ invert_m4_m4(ob->imat, ob->obmat); mul_m4_v3(ob->obmat, ob_loc); mul_m4_v3(sds->obmat, ob_cache_loc); @@ -2112,7 +2111,7 @@ static DerivedMesh *createDomainGeometry(SmokeDomainSettings *sds, Object *ob) /* convert shift to local space and apply to vertices */ mul_mat3_m4_v3(ob->imat, sds->obj_shift_f); /* apply */ - for (i=0; i<num_verts; i++) { + for (i = 0; i < num_verts; i++) { add_v3_v3(mverts[i].co, sds->obj_shift_f); } } @@ -2123,34 +2122,34 @@ static DerivedMesh *createDomainGeometry(SmokeDomainSettings *sds, Object *ob) } static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm) -{ - if((smd->type & MOD_SMOKE_TYPE_FLOW)) +{ + if ((smd->type & MOD_SMOKE_TYPE_FLOW)) { - if(scene->r.cfra >= smd->time) + if (scene->r.cfra >= smd->time) smokeModifier_init(smd, ob, scene, dm); if (smd->flow->dm) smd->flow->dm->release(smd->flow->dm); smd->flow->dm = CDDM_copy(dm); DM_ensure_tessface(smd->flow->dm); - if(scene->r.cfra > smd->time) + if (scene->r.cfra > smd->time) { smd->time = scene->r.cfra; } - else if(scene->r.cfra < smd->time) + else if (scene->r.cfra < smd->time) { smd->time = scene->r.cfra; smokeModifier_reset(smd); } } - else if(smd->type & MOD_SMOKE_TYPE_COLL) + else if (smd->type & MOD_SMOKE_TYPE_COLL) { - if(scene->r.cfra >= smd->time) + if (scene->r.cfra >= smd->time) smokeModifier_init(smd, ob, scene, dm); - if(smd->coll) + if (smd->coll) { - if (smd->coll->dm) + if (smd->coll->dm) smd->coll->dm->release(smd->coll->dm); smd->coll->dm = CDDM_copy(dm); @@ -2158,12 +2157,12 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object * } smd->time = scene->r.cfra; - if(scene->r.cfra < smd->time) + if (scene->r.cfra < smd->time) { smokeModifier_reset(smd); } } - else if(smd->type & MOD_SMOKE_TYPE_DOMAIN) + else if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { SmokeDomainSettings *sds = smd->domain; PointCache *cache = NULL; @@ -2179,7 +2178,7 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object * BKE_ptcache_id_from_smoke(&pid, ob, smd); BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, ×cale); - if(!smd->domain->fluid || framenr == startframe) + if (!smd->domain->fluid || framenr == startframe) { BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); smokeModifier_reset(smd); @@ -2187,7 +2186,7 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object * cache->flag &= ~PTCACHE_REDO_NEEDED; } - if(!smd->domain->fluid && (framenr != startframe) && (smd->domain->flags & MOD_SMOKE_FILE_LOAD)==0 && (cache->flag & PTCACHE_BAKED)==0) + if (!smd->domain->fluid && (framenr != startframe) && (smd->domain->flags & MOD_SMOKE_FILE_LOAD) == 0 && (cache->flag & PTCACHE_BAKED) == 0) return; smd->domain->flags &= ~MOD_SMOKE_FILE_LOAD; @@ -2197,21 +2196,21 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object * if ((smd->time == framenr) && (framenr != scene->r.cfra)) return; - if(smokeModifier_init(smd, ob, scene, dm)==0) + if (smokeModifier_init(smd, ob, scene, dm) == 0) { printf("bad smokeModifier_init\n"); return; } /* try to read from cache */ - if(BKE_ptcache_read(&pid, (float)framenr) == PTCACHE_READ_EXACT) { + if (BKE_ptcache_read(&pid, (float)framenr) == PTCACHE_READ_EXACT) { BKE_ptcache_validate(cache, framenr); smd->time = framenr; return; } - + /* only calculate something when we advanced a single frame */ - if(framenr != (int)smd->time+1) + if (framenr != (int)smd->time + 1) return; /* don't simulate if viewing start frame, but scene frame is not real start frame */ @@ -2221,20 +2220,20 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object * tstart(); /* if on second frame, write cache for first frame */ - if((int)smd->time == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0)) { + if ((int)smd->time == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact == 0)) { // create shadows straight after domain initialization so we get nice shadows for startframe, too smoke_calc_transparency(sds, scene); - if(sds->wt && sds->total_cells>1) + if (sds->wt && sds->total_cells > 1) { - if(sds->flags & MOD_SMOKE_DISSOLVE) + if (sds->flags & MOD_SMOKE_DISSOLVE) smoke_dissolve_wavelet(sds->wt, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG); smoke_turbulence_step(sds->wt, sds->fluid); } BKE_ptcache_write(&pid, startframe); } - + // set new time smd->time = scene->r.cfra; @@ -2242,26 +2241,26 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object * // simulate the actual smoke (c++ code in intern/smoke) // DG: interesting commenting this line + deactivating loading of noise files - if(framenr!=startframe) + if (framenr != startframe) { - if(sds->flags & MOD_SMOKE_DISSOLVE) + if (sds->flags & MOD_SMOKE_DISSOLVE) smoke_dissolve(sds->fluid, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG); - + step(scene, ob, smd, dm, scene->r.frs_sec / scene->r.frs_sec_base); } // create shadows before writing cache so they get stored smoke_calc_transparency(sds, scene); - if(sds->wt) + if (sds->wt) { - if(sds->flags & MOD_SMOKE_DISSOLVE) + if (sds->flags & MOD_SMOKE_DISSOLVE) smoke_dissolve_wavelet(sds->wt, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG); smoke_turbulence_step(sds->wt, sds->fluid); } - + BKE_ptcache_validate(cache, framenr); - if(framenr != startframe) + if (framenr != startframe) BKE_ptcache_write(&pid, framenr); tend(); @@ -2269,14 +2268,13 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object * } } -struct DerivedMesh *smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm) -{ +struct DerivedMesh *smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm){ smokeModifier_process(smd, scene, ob, dm); /* return generated geometry for adaptive domain */ - if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain && - smd->domain->flags & MOD_SMOKE_ADAPTIVE_DOMAIN && - smd->domain->base_res[0]) + if (smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain && + smd->domain->flags & MOD_SMOKE_ADAPTIVE_DOMAIN && + smd->domain->base_res[0]) { return createDomainGeometry(smd->domain, ob); } @@ -2288,13 +2286,13 @@ static float calc_voxel_transp(float *result, float *input, int res[3], int *pix const size_t index = smoke_get_index(pixel[0], res[0], pixel[1], res[1], pixel[2]); // T_ray *= T_vox - *tRay *= exp(input[index]*correct); - - if(result[index] < 0.0f) + *tRay *= exp(input[index] * correct); + + if (result[index] < 0.0f) { -// #pragma omp critical - result[index] = *tRay; - } +// #pragma omp critical + result[index] = *tRay; + } return *tRay; } @@ -2326,7 +2324,7 @@ static void bresenham_linie_3D(int x1, int y1, int z1, int x2, int y2, int z2, f err_1 = dy2 - l; err_2 = dz2 - l; for (i = 0; i < l; i++) { - if(cb(result, input, res, pixel, tRay, correct) <= FLT_EPSILON) + if (cb(result, input, res, pixel, tRay, correct) <= FLT_EPSILON) break; if (err_1 > 0) { pixel[1] += y_inc; @@ -2340,12 +2338,12 @@ static void bresenham_linie_3D(int x1, int y1, int z1, int x2, int y2, int z2, f err_2 += dz2; pixel[0] += x_inc; } - } + } else if ((m >= l) && (m >= n)) { err_1 = dx2 - m; err_2 = dz2 - m; for (i = 0; i < m; i++) { - if(cb(result, input, res, pixel, tRay, correct) <= FLT_EPSILON) + if (cb(result, input, res, pixel, tRay, correct) <= FLT_EPSILON) break; if (err_1 > 0) { pixel[0] += x_inc; @@ -2359,12 +2357,12 @@ static void bresenham_linie_3D(int x1, int y1, int z1, int x2, int y2, int z2, f err_2 += dz2; pixel[1] += y_inc; } - } + } else { err_1 = dy2 - n; err_2 = dx2 - n; for (i = 0; i < n; i++) { - if(cb(result, input, res, pixel, tRay, correct) <= FLT_EPSILON) + if (cb(result, input, res, pixel, tRay, correct) <= FLT_EPSILON) break; if (err_1 > 0) { pixel[1] += y_inc; @@ -2386,9 +2384,9 @@ static void smoke_calc_transparency(SmokeDomainSettings *sds, Scene *scene) { float bv[6] = {0}; float light[3]; - int a, z, slabsize=sds->res[0]*sds->res[1], size= sds->res[0]*sds->res[1]*sds->res[2]; + int a, z, slabsize = sds->res[0] * sds->res[1], size = sds->res[0] * sds->res[1] * sds->res[2]; float *density = smoke_get_density(sds->fluid); - float correct = -7.0*sds->dx; + float correct = -7.0 * sds->dx; if (!get_lamp(scene, light)) return; @@ -2398,8 +2396,8 @@ static void smoke_calc_transparency(SmokeDomainSettings *sds, Scene *scene) light[1] = (light[1] - sds->p0[1]) / sds->cell_size[1] - 0.5f; light[2] = (light[2] - sds->p0[2]) / sds->cell_size[2] - 0.5f; - for(a=0; a<size; a++) - sds->shadow[a]= -1.0f; + for (a = 0; a < size; a++) + sds->shadow[a] = -1.0f; /* calculate domain bounds in sim cell space */ // 0,2,4 = 0.0f @@ -2408,27 +2406,27 @@ static void smoke_calc_transparency(SmokeDomainSettings *sds, Scene *scene) bv[5] = (float)sds->res[2]; // z // #pragma omp parallel for schedule(static,1) - for(z = 0; z < sds->res[2]; z++) + for (z = 0; z < sds->res[2]; z++) { - size_t index = z*slabsize; - int x,y; + size_t index = z * slabsize; + int x, y; - for(y = 0; y < sds->res[1]; y++) - for(x = 0; x < sds->res[0]; x++, index++) + for (y = 0; y < sds->res[1]; y++) + for (x = 0; x < sds->res[0]; x++, index++) { float voxelCenter[3]; float pos[3]; int cell[3]; float tRay = 1.0; - if(sds->shadow[index] >= 0.0f) - continue; + if (sds->shadow[index] >= 0.0f) + continue; voxelCenter[0] = (float)x; voxelCenter[1] = (float)y; voxelCenter[2] = (float)z; // get starting cell (light pos) - if(BLI_bvhtree_bb_raycast(bv, light, voxelCenter, pos) > FLT_EPSILON) + if (BLI_bvhtree_bb_raycast(bv, light, voxelCenter, pos) > FLT_EPSILON) { // we're ouside -> use point on side of domain cell[0] = (int)floor(pos[0]); @@ -2442,27 +2440,27 @@ static void smoke_calc_transparency(SmokeDomainSettings *sds, Scene *scene) cell[2] = (int)floor(light[2]); } /* clamp within grid bounds */ - CLAMP(cell[0], 0, sds->res[0]-1); - CLAMP(cell[1], 0, sds->res[1]-1); - CLAMP(cell[2], 0, sds->res[2]-1); + CLAMP(cell[0], 0, sds->res[0] - 1); + CLAMP(cell[1], 0, sds->res[1] - 1); + CLAMP(cell[2], 0, sds->res[2] - 1); bresenham_linie_3D(cell[0], cell[1], cell[2], x, y, z, &tRay, calc_voxel_transp, sds->shadow, density, sds->res, correct); // convention -> from a RGBA float array, use G value for tRay // #pragma omp critical - sds->shadow[index] = tRay; + sds->shadow[index] = tRay; } } } /* get smoke velocity and density at given coordinates -* returns fluid density or -1.0f if outside domain*/ + * returns fluid density or -1.0f if outside domain*/ float smoke_get_velocity_at(struct Object *ob, float position[3], float velocity[3]) { - SmokeModifierData *smd = (SmokeModifierData*)modifiers_findByType(ob, eModifierType_Smoke); + SmokeModifierData *smd = (SmokeModifierData *)modifiers_findByType(ob, eModifierType_Smoke); zero_v3(velocity); - if(smd && (smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain && smd->domain->fluid) { + if (smd && (smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain && smd->domain->fluid) { SmokeDomainSettings *sds = smd->domain; float time_mult = 25.f * DT_DEFAULT; float vel_mag; diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index e7efd7936c0..82fef00b1e6 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -1221,7 +1221,7 @@ static void harmonic_ray_callback(void *userdata, int index, const BVHTreeRay *r else normal_quad_v3(no, face[0], face[1], face[2], face[3]); - dist = len_v3v3(ray->origin, co)/len_v3(isec->vec); + dist = len_v3v3(ray->origin, co) / len_v3(isec->vec); if (dist < hit->dist) { hit->index = index; hit->dist = dist; @@ -1257,7 +1257,7 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb, float if (BLI_bvhtree_ray_cast(mdb->bvhtree, isect_mdef.start, isect_mdef.vec, 0.0, &hit, harmonic_ray_callback, data) != -1) { - len= isect_mdef.labda; + len = isect_mdef.labda; isect_mdef.face = mface = mface1 + hit.index; /* create MDefBoundIsect */ diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 0e1fd87c985..3203237496f 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -3094,14 +3094,10 @@ static int widget_roundbox_set(uiBut *but, rcti *rect) if (but->active) { int direction = ui_button_open_menu_direction(but); - if (direction == UI_TOP) - roundbox &= ~(UI_CNR_TOP_RIGHT|UI_CNR_TOP_LEFT); - else if (direction == UI_DOWN) - roundbox &= ~(UI_CNR_BOTTOM_RIGHT|UI_CNR_BOTTOM_LEFT); - else if (direction == UI_LEFT) - roundbox &= ~(UI_CNR_TOP_LEFT|UI_CNR_BOTTOM_LEFT); - else if (direction == UI_RIGHT) - roundbox &= ~(UI_CNR_TOP_RIGHT|UI_CNR_BOTTOM_RIGHT); + if (direction == UI_TOP) roundbox &= ~(UI_CNR_TOP_RIGHT | UI_CNR_TOP_LEFT); + else if (direction == UI_DOWN) roundbox &= ~(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT); + else if (direction == UI_LEFT) roundbox &= ~(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT); + else if (direction == UI_RIGHT) roundbox &= ~(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT); } return roundbox; diff --git a/source/blender/editors/object/object_iterators.c b/source/blender/editors/object/object_iterators.c index 1d38db9d59b..c1841711435 100644 --- a/source/blender/editors/object/object_iterators.c +++ b/source/blender/editors/object/object_iterators.c @@ -187,8 +187,7 @@ static void mesh_foreachScreenFace__mapFunc(void *userData, int index, const flo if (efa && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { float screen_co[2]; - if (ED_view3d_project_float_object(data->vc.ar, cent, screen_co, data->clip_flag) == V3D_PROJ_RET_OK) - { + if (ED_view3d_project_float_object(data->vc.ar, cent, screen_co, data->clip_flag) == V3D_PROJ_RET_OK) { data->func(data->userData, efa, screen_co, index); } } @@ -297,8 +296,7 @@ void mball_foreachScreenElem( for (ml = mb->editelems->first; ml; ml = ml->next) { float screen_co[2]; - if (ED_view3d_project_float_object(vc->ar, &ml->x, screen_co, clip_flag) == V3D_PROJ_RET_OK) - { + if (ED_view3d_project_float_object(vc->ar, &ml->x, screen_co, clip_flag) == V3D_PROJ_RET_OK) { func(userData, ml, screen_co); } } diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index b5643cdb9cb..a92cfa472aa 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -533,7 +533,7 @@ static int ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGrou } /* loop through the vertices*/ - for(i = 0, dv_src = dv_array_src, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, dv_src++, mv_src++, mv_dst++) { + for (i = 0, dv_src = dv_array_src, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, dv_src++, mv_src++, mv_dst++) { if (*dv_dst == NULL) { continue; @@ -553,7 +553,7 @@ static int ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGrou bvhtree_from_mesh_verts(&tree_mesh_vertices_src, dmesh_src, FLT_EPSILON, 2, 6); /* loop trough vertices */ - for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++){ + for (i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++) { if (*dv_dst == NULL) { continue; @@ -592,7 +592,7 @@ static int ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGrou bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, FLT_EPSILON, 2, 6); /* loop through the vertices */ - for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++) { + for (i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++) { if (*dv_dst == NULL) { continue; @@ -652,7 +652,7 @@ static int ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGrou bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, FLT_EPSILON, 2, 6); /* loop through the vertices */ - for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++){ + for (i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++) { if (*dv_dst == NULL) { continue; diff --git a/source/blender/editors/physics/dynamicpaint_ops.c b/source/blender/editors/physics/dynamicpaint_ops.c index 70fe87e5c01..5b69e6745c0 100644 --- a/source/blender/editors/physics/dynamicpaint_ops.c +++ b/source/blender/editors/physics/dynamicpaint_ops.c @@ -73,9 +73,9 @@ static int surface_slot_add_exec(bContext *C, wmOperator *UNUSED(op)) /* set preview for this surface only and set active */ canvas->active_sur = 0; - for (surface=surface->prev; surface; surface=surface->prev) { - surface->flags &= ~MOD_DPAINT_PREVIEW; - canvas->active_sur++; + for (surface = surface->prev; surface; surface = surface->prev) { + surface->flags &= ~MOD_DPAINT_PREVIEW; + canvas->active_sur++; } return OPERATOR_FINISHED; @@ -94,26 +94,26 @@ void DPAINT_OT_surface_slot_add(wmOperatorType *ot) ot->poll = ED_operator_object_active_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int surface_slot_remove_exec(bContext *C, wmOperator *UNUSED(op)) { DynamicPaintModifierData *pmd = NULL; - Object *cObject = ED_object_context(C); + Object *obj_ctx = ED_object_context(C); DynamicPaintCanvasSettings *canvas; DynamicPaintSurface *surface; - int id=0; + int id = 0; /* Make sure we're dealing with a canvas */ - pmd = (DynamicPaintModifierData *)modifiers_findByType(cObject, eModifierType_DynamicPaint); + pmd = (DynamicPaintModifierData *)modifiers_findByType(obj_ctx, eModifierType_DynamicPaint); if (!pmd || !pmd->canvas) return OPERATOR_CANCELLED; canvas = pmd->canvas; surface = canvas->surfaces.first; /* find active surface and remove it */ - for (; surface; surface=surface->next) { + for (; surface; surface = surface->next) { if (id == canvas->active_sur) { canvas->active_sur -= 1; dynamicPaint_freeSurface(surface); @@ -123,8 +123,8 @@ static int surface_slot_remove_exec(bContext *C, wmOperator *UNUSED(op)) } dynamicPaint_resetPreview(canvas); - DAG_id_tag_update(&cObject->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, cObject); + DAG_id_tag_update(&obj_ctx->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obj_ctx); return OPERATOR_FINISHED; } @@ -142,7 +142,7 @@ void DPAINT_OT_surface_slot_remove(wmOperatorType *ot) ot->poll = ED_operator_object_active_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int type_toggle_exec(bContext *C, wmOperator *op) @@ -151,7 +151,7 @@ static int type_toggle_exec(bContext *C, wmOperator *op) Object *cObject = ED_object_context(C); Scene *scene = CTX_data_scene(C); DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)modifiers_findByType(cObject, eModifierType_DynamicPaint); - int type= RNA_enum_get(op->ptr, "type"); + int type = RNA_enum_get(op->ptr, "type"); if (!pmd) return OPERATOR_CANCELLED; @@ -170,7 +170,7 @@ static int type_toggle_exec(bContext *C, wmOperator *op) /* update dependency */ DAG_id_tag_update(&cObject->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, cObject); + WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, cObject); DAG_scene_sort(CTX_data_main(C), scene); return OPERATOR_FINISHED; @@ -190,10 +190,10 @@ void DPAINT_OT_type_toggle(wmOperatorType *ot) ot->poll = ED_operator_object_active_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - prop= RNA_def_enum(ot->srna, "type", prop_dynamicpaint_type_items, MOD_DYNAMICPAINT_TYPE_CANVAS, "Type", ""); + prop = RNA_def_enum(ot->srna, "type", prop_dynamicpaint_type_items, MOD_DYNAMICPAINT_TYPE_CANVAS, "Type", ""); ot->prop = prop; } @@ -203,7 +203,7 @@ static int output_toggle_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); DynamicPaintSurface *surface; DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)modifiers_findByType(ob, eModifierType_DynamicPaint); - int output= RNA_enum_get(op->ptr, "output"); /* currently only 1/0 */ + int output = RNA_enum_get(op->ptr, "output"); /* currently only 1/0 */ if (!pmd || !pmd->canvas) return OPERATOR_CANCELLED; surface = get_activeSurface(pmd->canvas); @@ -258,7 +258,7 @@ void DPAINT_OT_output_toggle(wmOperatorType *ot) ot->poll = ED_operator_object_active_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ ot->prop = RNA_def_enum(ot->srna, "output", prop_output_toggle_types, 0, "Output Toggle", ""); @@ -274,7 +274,7 @@ void DPAINT_OT_output_toggle(wmOperatorType *ot) static int dynamicPaint_bakeImageSequence(bContext *C, DynamicPaintSurface *surface, Object *cObject) { DynamicPaintCanvasSettings *canvas = surface->canvas; - Scene *scene= CTX_data_scene(C); + Scene *scene = CTX_data_scene(C); wmWindow *win = CTX_wm_window(C); int frame = 1; int frames; @@ -291,7 +291,7 @@ static int dynamicPaint_bakeImageSequence(bContext *C, DynamicPaintSurface *surf if (!dynamicPaint_createUVSurface(surface)) return 0; /* Loop through selected frames */ - for (frame=surface->start_frame; frame<=surface->end_frame; frame++) { + for (frame = surface->start_frame; frame <= surface->end_frame; frame++) { float progress = (frame - surface->start_frame) / (float)frames * 100; surface->current_frame = frame; diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 4f57b2249d1..c7ad82dec85 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -1259,8 +1259,7 @@ static void save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveI BKE_image_release_renderresult(scene, ima); } else { - if (BKE_imbuf_write_as(colormanaged_ibuf, simopts->filepath, &simopts->im_format, save_copy)) - { + if (BKE_imbuf_write_as(colormanaged_ibuf, simopts->filepath, &simopts->im_format, save_copy)) { ok = TRUE; } } diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index 8cc55363a5e..ebb48960b80 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -133,7 +133,7 @@ static int intersect_edges(float *points, float a, float b, float c, float d, fl int i; float t; int numpoints = 0; - + for (i = 0; i < 12; i++) { t = -(a * edges[i][0][0] + b * edges[i][0][1] + c * edges[i][0][2] + d) / (a * edges[i][1][0] + b * edges[i][1][1] + c * edges[i][1][2]); @@ -280,21 +280,22 @@ void draw_smoke_volume(SmokeDomainSettings *sds, Object *ob, #define FIRE_THRESH 7 #define MAX_FIRE_ALPHA 0.06f #define FULL_ON_FIRE 100 - spec_data = malloc(SPEC_WIDTH*4 * sizeof(unsigned char)); + spec_data = malloc(SPEC_WIDTH * 4 * sizeof(unsigned char)); flame_get_spectrum(spec_data, SPEC_WIDTH, 1500, 3000); - spec_pixels = malloc(SPEC_WIDTH*4*16*16 * sizeof(float)); - for (i=0;i<16;i++){ - for (j=0;j<16;j++) { - for (k=0;k<SPEC_WIDTH;k++) { - int index = (j*SPEC_WIDTH*16+i*SPEC_WIDTH+k)*4; - if (k>=FIRE_THRESH) { - spec_pixels[index] = ((float)spec_data[k*4])/255.0f; - spec_pixels[index+1] = ((float)spec_data[k*4+1])/255.0f; - spec_pixels[index+2] = ((float)spec_data[k*4+2])/255.0f; - spec_pixels[index+3] = MAX_FIRE_ALPHA*( - (k>FULL_ON_FIRE) ? 1.0f : (k-FIRE_THRESH)/((float)FULL_ON_FIRE-FIRE_THRESH)); - } else { - spec_pixels[index] = spec_pixels[index+1] = spec_pixels[index+2] = spec_pixels[index+3] = 0.0f; + spec_pixels = malloc(SPEC_WIDTH * 4 * 16 * 16 * sizeof(float)); + for (i = 0; i < 16; i++) { + for (j = 0; j < 16; j++) { + for (k = 0; k < SPEC_WIDTH; k++) { + int index = (j * SPEC_WIDTH * 16 + i * SPEC_WIDTH + k) * 4; + if (k >= FIRE_THRESH) { + spec_pixels[index] = ((float)spec_data[k * 4]) / 255.0f; + spec_pixels[index + 1] = ((float)spec_data[k * 4 + 1]) / 255.0f; + spec_pixels[index + 2] = ((float)spec_data[k * 4 + 2]) / 255.0f; + spec_pixels[index + 3] = MAX_FIRE_ALPHA * ( + (k > FULL_ON_FIRE) ? 1.0f : (k - FIRE_THRESH) / ((float)FULL_ON_FIRE - FIRE_THRESH)); + } + else { + spec_pixels[index] = spec_pixels[index + 1] = spec_pixels[index + 2] = spec_pixels[index + 3] = 0.0f; } } } @@ -372,7 +373,7 @@ void draw_smoke_volume(SmokeDomainSettings *sds, Object *ob, edges[11][1][0] = size[0]; glGetBooleanv(GL_BLEND, (GLboolean *)&gl_blend); - glGetBooleanv(GL_DEPTH_TEST, (GLboolean *)&gl_depth); + glGetBooleanv(GL_DEPTH_TEST, (GLboolean *)&gl_depth); glDepthMask(GL_FALSE); glDisable(GL_DEPTH_TEST); @@ -382,9 +383,9 @@ void draw_smoke_volume(SmokeDomainSettings *sds, Object *ob, for (i = 0; i < 8; i++) { float x, y, z; - x = cv[i][0] - viewnormal[0]*size[0]*0.5f; - y = cv[i][1] - viewnormal[1]*size[1]*0.5f; - z = cv[i][2] - viewnormal[2]*size[2]*0.5f; + x = cv[i][0] - viewnormal[0] * size[0] * 0.5f; + y = cv[i][1] - viewnormal[1] * size[1] * 0.5f; + z = cv[i][2] - viewnormal[2] * size[2] * 0.5f; if ((x >= min[0]) && (x <= max[0]) && (y >= min[1]) && (y <= max[1]) && @@ -448,7 +449,7 @@ void draw_smoke_volume(SmokeDomainSettings *sds, Object *ob, /* d0 = (viewnormal[0]*cv[i][0] + viewnormal[1]*cv[i][1] + viewnormal[2]*cv[i][2]); */ /* UNUSED */ ds = (ABS(viewnormal[0]) * size[0] + ABS(viewnormal[1]) * size[1] + ABS(viewnormal[2]) * size[2]); - dd = MAX3(sds->global_size[0],sds->global_size[1],sds->global_size[2])/128.f; + dd = MAX3(sds->global_size[0], sds->global_size[1], sds->global_size[2]) / 128.f; n = 0; good_index = i; @@ -500,7 +501,7 @@ void draw_smoke_volume(SmokeDomainSettings *sds, Object *ob, glTexCoord3d((points[i * 3 + 0] - min[0]) * cor[0] / size[0], (points[i * 3 + 1] - min[1]) * cor[1] / size[1], (points[i * 3 + 2] - min[2]) * cor[2] / size[2]); - glVertex3f(points[i * 3 + 0]/ob->size[0], points[i * 3 + 1]/ob->size[1], points[i * 3 + 2]/ob->size[2]); + glVertex3f(points[i * 3 + 0] / ob->size[0], points[i * 3 + 1] / ob->size[1], points[i * 3 + 2] / ob->size[2]); } glEnd(); @@ -513,7 +514,7 @@ void draw_smoke_volume(SmokeDomainSettings *sds, Object *ob, glTexCoord3d((points[i * 3 + 0] - min[0]) * cor[0] / size[0], (points[i * 3 + 1] - min[1]) * cor[1] / size[1], (points[i * 3 + 2] - min[2]) * cor[2] / size[2]); - glVertex3f(points[i * 3 + 0]/ob->size[0], points[i * 3 + 1]/ob->size[1], points[i * 3 + 2]/ob->size[2]); + glVertex3f(points[i * 3 + 0] / ob->size[0], points[i * 3 + 1] / ob->size[1], points[i * 3 + 2] / ob->size[2]); } glEnd(); } @@ -549,15 +550,15 @@ void draw_smoke_volume(SmokeDomainSettings *sds, Object *ob, if (gl_depth) { glEnable(GL_DEPTH_TEST); - glDepthMask(GL_TRUE); + glDepthMask(GL_TRUE); } } #ifdef SMOKE_DEBUG_VELOCITY void draw_smoke_velocity(SmokeDomainSettings *domain, Object *ob) { - float x,y,z; - float x0,y0,z0; + float x, y, z; + float x0, y0, z0; int *base_res = domain->base_res; int *res = domain->res; int *res_min = domain->res_min; @@ -568,27 +569,27 @@ void draw_smoke_velocity(SmokeDomainSettings *domain, Object *ob) float min[3]; float *cell_size = domain->cell_size; - float step_size = ((float)MAX3(base_res[0], base_res[1], base_res[2]))/16.f; + float step_size = ((float)MAX3(base_res[0], base_res[1], base_res[2])) / 16.f; float vf = domain->scale / 16.f * 2.f; /* velocity factor */ glLineWidth(1.0f); /* set first position so that it doesn't jump when domain moves */ - x0 = res_min[0] + fmod(-(float)domain->shift[0]+res_min[0],step_size); - y0 = res_min[1] + fmod(-(float)domain->shift[1]+res_min[1],step_size); - z0 = res_min[2] + fmod(-(float)domain->shift[2]+res_min[2],step_size); - if (x0<res_min[0]) x0+=step_size; - if (y0<res_min[1]) y0+=step_size; - if (z0<res_min[2]) z0+=step_size; + x0 = res_min[0] + fmod(-(float)domain->shift[0] + res_min[0], step_size); + y0 = res_min[1] + fmod(-(float)domain->shift[1] + res_min[1], step_size); + z0 = res_min[2] + fmod(-(float)domain->shift[2] + res_min[2], step_size); + if (x0 < res_min[0]) x0 += step_size; + if (y0 < res_min[1]) y0 += step_size; + if (z0 < res_min[2]) z0 += step_size; add_v3_v3v3(min, domain->p0, domain->obj_shift_f); - for (x=floor(x0); x<res_max[0]; x+=step_size) - for (y=floor(y0); y<res_max[1]; y+=step_size) - for (z=floor(z0); z<res_max[2]; z+=step_size) { - int index = (floor(x)-res_min[0]) + (floor(y)-res_min[1])*res[0] + (floor(z)-res_min[2])*res[0]*res[1]; + for (x = floor(x0); x < res_max[0]; x += step_size) + for (y = floor(y0); y < res_max[1]; y += step_size) + for (z = floor(z0); z < res_max[2]; z += step_size) { + int index = (floor(x) - res_min[0]) + (floor(y) - res_min[1]) * res[0] + (floor(z) - res_min[2]) * res[0] * res[1]; - float pos[3] = {min[0]+((float)x + 0.5f)*cell_size[0], min[1]+((float)y + 0.5f)*cell_size[1], min[2]+((float)z + 0.5f)*cell_size[2]}; - float vel = sqrtf(vel_x[index]*vel_x[index] + vel_y[index]*vel_y[index] + vel_z[index]*vel_z[index]); + float pos[3] = {min[0] + ((float)x + 0.5f) * cell_size[0], min[1] + ((float)y + 0.5f) * cell_size[1], min[2] + ((float)z + 0.5f) * cell_size[2]}; + float vel = sqrtf(vel_x[index] * vel_x[index] + vel_y[index] * vel_y[index] + vel_z[index] * vel_z[index]); /* draw heat as scaled "arrows" */ if (vel >= 0.01f) { @@ -599,21 +600,21 @@ void draw_smoke_velocity(SmokeDomainSettings *domain, Object *ob) glBegin(GL_LINES); glVertex3f(pos[0], pos[1], pos[2]); - glVertex3f(pos[0]+vel_x[index]*vf, pos[1]+vel_y[index]*vf, pos[2]+vel_z[index]*vf); + glVertex3f(pos[0] + vel_x[index] * vf, pos[1] + vel_y[index] * vf, pos[2] + vel_z[index] * vf); glEnd(); glBegin(GL_POINTS); - glVertex3f(pos[0]+vel_x[index]*vf, pos[1]+vel_y[index]*vf, pos[2]+vel_z[index]*vf); + glVertex3f(pos[0] + vel_x[index] * vf, pos[1] + vel_y[index] * vf, pos[2] + vel_z[index] * vf); glEnd(); } - } + } } #endif #ifdef SMOKE_DEBUG_HEAT void draw_smoke_heat(SmokeDomainSettings *domain, Object *ob) { - float x,y,z; - float x0,y0,z0; + float x, y, z; + float x0, y0, z0; int *base_res = domain->base_res; int *res = domain->res; int *res_min = domain->res_min; @@ -622,24 +623,24 @@ void draw_smoke_heat(SmokeDomainSettings *domain, Object *ob) float min[3]; float *cell_size = domain->cell_size; - float step_size = ((float)MAX3(base_res[0], base_res[1], base_res[2]))/16.f; + float step_size = ((float)MAX3(base_res[0], base_res[1], base_res[2])) / 16.f; float vf = domain->scale / 16.f * 2.f; /* velocity factor */ /* set first position so that it doesn't jump when domain moves */ - x0 = res_min[0] + fmod(-(float)domain->shift[0]+res_min[0],step_size); - y0 = res_min[1] + fmod(-(float)domain->shift[1]+res_min[1],step_size); - z0 = res_min[2] + fmod(-(float)domain->shift[2]+res_min[2],step_size); - if (x0<res_min[0]) x0+=step_size; - if (y0<res_min[1]) y0+=step_size; - if (z0<res_min[2]) z0+=step_size; + x0 = res_min[0] + fmod(-(float)domain->shift[0] + res_min[0], step_size); + y0 = res_min[1] + fmod(-(float)domain->shift[1] + res_min[1], step_size); + z0 = res_min[2] + fmod(-(float)domain->shift[2] + res_min[2], step_size); + if (x0 < res_min[0]) x0 += step_size; + if (y0 < res_min[1]) y0 += step_size; + if (z0 < res_min[2]) z0 += step_size; add_v3_v3v3(min, domain->p0, domain->obj_shift_f); - for (x=floor(x0); x<res_max[0]; x+=step_size) - for (y=floor(y0); y<res_max[1]; y+=step_size) - for (z=floor(z0); z<res_max[2]; z+=step_size) { - int index = (floor(x)-res_min[0]) + (floor(y)-res_min[1])*res[0] + (floor(z)-res_min[2])*res[0]*res[1]; + for (x = floor(x0); x < res_max[0]; x += step_size) + for (y = floor(y0); y < res_max[1]; y += step_size) + for (z = floor(z0); z < res_max[2]; z += step_size) { + int index = (floor(x) - res_min[0]) + (floor(y) - res_min[1]) * res[0] + (floor(z) - res_min[2]) * res[0] * res[1]; - float pos[3] = {min[0]+((float)x + 0.5f)*cell_size[0], min[1]+((float)y + 0.5f)*cell_size[1], min[2]+((float)z + 0.5f)*cell_size[2]}; + float pos[3] = {min[0] + ((float)x + 0.5f) * cell_size[0], min[1] + ((float)y + 0.5f) * cell_size[1], min[2] + ((float)z + 0.5f) * cell_size[2]}; /* draw heat as different sized points */ if (heat[index] >= 0.01f) { @@ -652,6 +653,6 @@ void draw_smoke_heat(SmokeDomainSettings *domain, Object *ob) glVertex3f(pos[0], pos[1], pos[2]); glEnd(); } - } + } } #endif |