diff options
Diffstat (limited to 'source/blender/blenkernel/intern')
62 files changed, 2115 insertions, 2015 deletions
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c index f5718974f9f..53e4a973cd4 100644 --- a/source/blender/blenkernel/intern/CCGSubSurf.c +++ b/source/blender/blenkernel/intern/CCGSubSurf.c @@ -1272,7 +1272,9 @@ CCGError ccgSubSurf_syncFace(CCGSubSurf *ss, CCGFaceHDL fHDL, int numVerts, CCGV if (f->numVerts != numVerts || memcmp(FACE_getVerts(f), ss->tempVerts, sizeof(*ss->tempVerts) * numVerts) || memcmp(FACE_getEdges(f), ss->tempEdges, sizeof(*ss->tempEdges) * numVerts)) + { topologyChanged = 1; + } } if (!f || topologyChanged) { diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index c28958d5b0d..0fd030be39c 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1223,7 +1223,7 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, for (i=0; i<dm->numPolyData; i++, mp++) { ml = mloop + mp->loopstart; - BLI_array_growitems(wtcol_l, mp->totloop); + BLI_array_grow_items(wtcol_l, mp->totloop); for (j = 0; j < mp->totloop; j++, ml++, totloop++) { copy_v4_v4_char((char *)&wtcol_l[totloop], (char *)&wtcol_v[4 * ml->v]); @@ -2279,8 +2279,10 @@ DerivedMesh *editbmesh_get_derived_cage_and_final(Scene *scene, Object *obedit, * the data we need, rebuild the derived mesh */ if (!em->derivedCage || - (em->lastDataMask & dataMask) != dataMask) + (em->lastDataMask & dataMask) != dataMask) + { editbmesh_build_data(scene, obedit, em, dataMask); + } *final_r = em->derivedFinal; return em->derivedCage; @@ -2292,8 +2294,10 @@ DerivedMesh *editbmesh_get_derived_cage(Scene *scene, Object *obedit, BMEditMesh * the data we need, rebuild the derived mesh */ if (!em->derivedCage || - (em->lastDataMask & dataMask) != dataMask) + (em->lastDataMask & dataMask) != dataMask) + { editbmesh_build_data(scene, obedit, em, dataMask); + } return em->derivedCage; } @@ -2701,8 +2705,7 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm) if (nr_tris_to_pile==1 || nr_tris_to_pile==2) { const int indices[] = {offs+0, offs+1, offs+2, offs+0, offs+2, (offs+3)&0x3 }; int t; - for ( t=0; t<nr_tris_to_pile; t++ ) - { + for ( t=0; t<nr_tris_to_pile; t++ ) { float f2x_area_uv; float * p0 = verts[indices[t*3+0]]; float * p1 = verts[indices[t*3+1]]; diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 1ec9f7d8a10..38c73ba72b9 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -482,7 +482,7 @@ void calc_curvepath(Object *ob) if (ob==NULL || ob->type != OB_CURVE) return; cu= ob->data; - nurbs= BKE_curve_nurbs(cu); + nurbs= BKE_curve_nurbs_get(cu); nu= nurbs->first; if (cu->path) free_path(cu->path); @@ -1350,9 +1350,11 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p /* some hair paths might be non-existent so they can't be used for duplication */ if (hair && - ((a < totpart && psys->pathcache[a]->steps < 0) || - (a >= totpart && psys->childcache[a-totpart]->steps < 0))) + ((a < totpart && psys->pathcache[a]->steps < 0) || + (a >= totpart && psys->childcache[a-totpart]->steps < 0))) + { continue; + } if (part->ren_as==PART_DRAW_GR) { /* prevent divide by zero below [#28336] */ diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 75b9ae59e26..be53e3ddcba 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -1250,8 +1250,7 @@ static void animsys_evaluate_fcurves (PointerRNA *ptr, ListBase *list, AnimMappe FCurve *fcu; /* calculate then execute each curve */ - for (fcu= list->first; fcu; fcu= fcu->next) - { + for (fcu= list->first; fcu; fcu= fcu->next) { /* check if this F-Curve doesn't belong to a muted group */ if ((fcu->grp == NULL) || (fcu->grp->flag & AGRP_MUTED)==0) { /* check if this curve should be skipped */ @@ -1274,8 +1273,7 @@ static void animsys_evaluate_drivers (PointerRNA *ptr, AnimData *adt, float ctim /* drivers are stored as F-Curves, but we cannot use the standard code, as we need to check if * the depsgraph requested that this driver be evaluated... */ - for (fcu= adt->drivers.first; fcu; fcu= fcu->next) - { + for (fcu= adt->drivers.first; fcu; fcu= fcu->next) { ChannelDriver *driver= fcu->driver; short ok= 0; @@ -1351,8 +1349,7 @@ void animsys_evaluate_action_group (PointerRNA *ptr, bAction *act, bActionGroup return; /* calculate then execute each curve */ - for (fcu= agrp->channels.first; (fcu) && (fcu->grp == agrp); fcu= fcu->next) - { + for (fcu= agrp->channels.first; (fcu) && (fcu->grp == agrp); fcu= fcu->next) { /* check if this curve should be skipped */ if ((fcu->flag & (FCURVE_MUTED|FCURVE_DISABLED)) == 0) { calculate_fcurve(fcu, ctime); @@ -1968,8 +1965,7 @@ void nladata_flush_channels (ListBase *channels) float value= nec->value; /* write values - see animsys_write_rna_setting() to sync the code */ - switch (RNA_property_type(prop)) - { + switch (RNA_property_type(prop)) { case PROP_BOOLEAN: if (RNA_property_array_length(ptr, prop)) RNA_property_boolean_set_index(ptr, prop, array_index, ANIMSYS_FLOAT_AS_BOOL(value)); @@ -2217,7 +2213,9 @@ void BKE_animsys_evaluate_animdata (Scene *scene, ID *id, AnimData *adt, float c * or be layered on top of existing animation data. * - Drivers should be in the appropriate order to be evaluated without problems... */ - if ((recalc & ADT_RECALC_DRIVERS) /*&& (adt->recalc & ADT_RECALC_DRIVERS)*/) // XXX for now, don't check yet, as depsgraph hasn't been updated + if ((recalc & ADT_RECALC_DRIVERS) + /* XXX for now, don't check yet, as depsgraph hasn't been updated */ + /* && (adt->recalc & ADT_RECALC_DRIVERS)*/) { animsys_evaluate_drivers(&id_ptr, adt, ctime); } diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 0f3e27a9b6e..d1d6833e903 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -566,13 +566,13 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) if (bone->segments > MAX_BBONE_SUBDIV) bone->segments = MAX_BBONE_SUBDIV; - forward_diff_bezier(0.0, h1[0], h2[0], 0.0, data[0], + BKE_curve_forward_diff_bezier(0.0, h1[0], h2[0], 0.0, data[0], MAX_BBONE_SUBDIV, 4*sizeof(float)); - forward_diff_bezier(0.0, h1[1], length + h2[1], length, data[0]+1, + BKE_curve_forward_diff_bezier(0.0, h1[1], length + h2[1], length, data[0]+1, MAX_BBONE_SUBDIV, 4*sizeof(float)); - forward_diff_bezier(0.0, h1[2], h2[2], 0.0, data[0]+2, + BKE_curve_forward_diff_bezier(0.0, h1[2], h2[2], 0.0, data[0]+2, MAX_BBONE_SUBDIV, 4*sizeof(float)); - forward_diff_bezier(roll1, roll1 + 0.390464f*(roll2-roll1), roll2 - 0.390464f*(roll2-roll1), roll2, data[0]+3, + BKE_curve_forward_diff_bezier(roll1, roll1 + 0.390464f*(roll2-roll1), roll2 - 0.390464f*(roll2-roll1), roll2, data[0]+3, MAX_BBONE_SUBDIV, 4*sizeof(float)); equalize_bezier(data[0], bone->segments); /* note: does stride 4! */ @@ -1372,7 +1372,7 @@ void armature_mat_pose_to_bone_ex(Object *ob, bPoseChannel *pchan, float inmat[] /* same as object_mat3_to_rot() */ void pchan_mat3_to_rot(bPoseChannel *pchan, float mat[][3], short use_compat) { - switch(pchan->rotmode) { + switch (pchan->rotmode) { case ROT_MODE_QUAT: mat3_to_quat(pchan->quat, mat); break; diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c index a556c99dc7d..fbcabccd2b9 100644 --- a/source/blender/blenkernel/intern/boids.c +++ b/source/blender/blenkernel/intern/boids.c @@ -962,7 +962,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) set_boid_values(&val, bbd->part->boids, pa); /* go through rules */ - switch(state->ruleset_type) { + switch (state->ruleset_type) { case eBoidRulesetType_Fuzzy: { for (rule = state->rules.first; rule; rule = rule->next) { @@ -1258,7 +1258,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) bpa->ground = boid_find_ground(bbd, pa, ground_co, ground_nor); /* change modes, constrain movement & keep track of down vector */ - switch(bpa->data.mode) { + switch (bpa->data.mode) { case eBoidMode_InAir: { float grav[3]; @@ -1437,7 +1437,7 @@ BoidRule *boid_new_rule(int type) if (type <= 0) return NULL; - switch(type) { + switch (type) { case eBoidRuleType_Goal: case eBoidRuleType_Avoid: rule = MEM_callocN(sizeof(BoidRuleGoalAvoid), "BoidRuleGoalAvoid"); diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index e7ba09d3959..3df6de2fd24 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -337,7 +337,7 @@ void brush_reset_sculpt(Brush *br) brush_set_defaults(br); brush_curve_preset(br, CURVE_PRESET_SMOOTH); - switch(br->sculpt_tool) { + switch (br->sculpt_tool) { case SCULPT_TOOL_CLAY: br->flag |= BRUSH_FRONTFACE; break; diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index 009b7ca7f99..df80ce6e87c 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -649,8 +649,7 @@ BVHTree* bvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *mesh, float BVHTree *tree = bvhcache_find(&mesh->bvhCache, BVHTREE_FROM_EDGES); //Not in cache - if (tree == NULL) - { + if (tree == NULL) { int i; int numEdges= mesh->getNumEdges(mesh); MVert *vert = mesh->getVertDataArray(mesh, CD_MVERT); @@ -675,8 +674,7 @@ BVHTree* bvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *mesh, float } } } - else - { + else { // printf("BVHTree is already build, using cached tree\n"); } diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index a0c273cf962..97baaad430b 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -191,8 +191,7 @@ static BVHTree *bvhselftree_build_from_cloth (ClothModifierData *clmd, float eps bvhtree = BLI_bvhtree_new(cloth->numverts, epsilon, 4, 6); // fill tree - for (i = 0; i < cloth->numverts; i++, verts++) - { + for (i = 0; i < cloth->numverts; i++, verts++) { copy_v3_v3(&co[0*3], verts->xold); BLI_bvhtree_insert(bvhtree, i, co, 1); @@ -232,8 +231,7 @@ static BVHTree *bvhtree_build_from_cloth (ClothModifierData *clmd, float epsilon bvhtree = BLI_bvhtree_new(cloth->numfaces, epsilon, 4, 26); // fill tree - for (i = 0; i < cloth->numfaces; i++, mfaces++) - { + for (i = 0; i < cloth->numfaces; i++, mfaces++) { copy_v3_v3(&co[0*3], verts[mfaces->v1].xold); copy_v3_v3(&co[1*3], verts[mfaces->v2].xold); copy_v3_v3(&co[2*3], verts[mfaces->v3].xold); @@ -266,10 +264,8 @@ void bvhtree_update_from_cloth(ClothModifierData *clmd, int moving) mfaces = cloth->mfaces; // update vertex position in bvh tree - if (verts && mfaces) - { - for (i = 0; i < cloth->numfaces; i++, mfaces++) - { + if (verts && mfaces) { + for (i = 0; i < cloth->numfaces; i++, mfaces++) { copy_v3_v3(&co[0*3], verts[mfaces->v1].txold); copy_v3_v3(&co[1*3], verts[mfaces->v2].txold); copy_v3_v3(&co[2*3], verts[mfaces->v3].txold); @@ -278,8 +274,7 @@ void bvhtree_update_from_cloth(ClothModifierData *clmd, int moving) copy_v3_v3(&co[3*3], verts[mfaces->v4].txold); // copy new locations into array - if (moving) - { + if (moving) { // update moving positions copy_v3_v3(&co_moving[0*3], verts[mfaces->v1].tx); copy_v3_v3(&co_moving[1*3], verts[mfaces->v2].tx); @@ -319,15 +314,12 @@ void bvhselftree_update_from_cloth(ClothModifierData *clmd, int moving) mfaces = cloth->mfaces; // update vertex position in bvh tree - if (verts && mfaces) - { - for (i = 0; i < cloth->numverts; i++, verts++) - { + if (verts && mfaces) { + for (i = 0; i < cloth->numverts; i++, verts++) { copy_v3_v3(&co[0*3], verts->txold); // copy new locations into array - if (moving) - { + if (moving) { // update moving positions copy_v3_v3(&co_moving[0*3], verts->tx); @@ -558,11 +550,9 @@ void cloth_free_modifier(ClothModifierData *clmd ) cloth = clmd->clothObject; - if ( cloth ) - { + if ( cloth ) { // If our solver provides a free function, call it - if ( solvers [clmd->sim_parms->solver_type].free ) - { + if ( solvers [clmd->sim_parms->solver_type].free ) { solvers [clmd->sim_parms->solver_type].free ( clmd ); } @@ -574,11 +564,9 @@ void cloth_free_modifier(ClothModifierData *clmd ) cloth->numverts = 0; // Free the springs. - if ( cloth->springs != NULL ) - { + if ( cloth->springs != NULL ) { LinkNode *search = cloth->springs; - while (search) - { + while (search) { ClothSpring *spring = search->link; MEM_freeN ( spring ); @@ -628,14 +616,12 @@ void cloth_free_modifier_extern ( ClothModifierData *clmd ) cloth = clmd->clothObject; - if ( cloth ) - { + if ( cloth ) { if (G.rt > 0) printf("cloth_free_modifier_extern in\n"); // If our solver provides a free function, call it - if ( solvers [clmd->sim_parms->solver_type].free ) - { + if ( solvers [clmd->sim_parms->solver_type].free ) { solvers [clmd->sim_parms->solver_type].free ( clmd ); } @@ -647,11 +633,9 @@ void cloth_free_modifier_extern ( ClothModifierData *clmd ) cloth->numverts = 0; // Free the springs. - if ( cloth->springs != NULL ) - { + if ( cloth->springs != NULL ) { LinkNode *search = cloth->springs; - while (search) - { + while (search) { ClothSpring *spring = search->link; MEM_freeN ( spring ); @@ -708,8 +692,7 @@ static void cloth_to_object (Object *ob, ClothModifierData *clmd, float (*verte /* inverse matrix is not uptodate... */ invert_m4_m4(ob->imat, ob->obmat); - for (i = 0; i < cloth->numverts; i++) - { + for (i = 0; i < cloth->numverts; i++) { copy_v3_v3 (vertexCos[i], cloth->verts[i].x); mul_m4_v3(ob->imat, vertexCos[i]); /* cloth is in global coords */ } @@ -749,17 +732,12 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) verts = clothObj->verts; - if (cloth_uses_vgroup(clmd)) - { - for ( i = 0; i < numverts; i++, verts++ ) - { + if (cloth_uses_vgroup(clmd)) { + for ( i = 0; i < numverts; i++, verts++ ) { dvert = dm->getVertData ( dm, i, CD_MDEFORMVERT ); - if ( dvert ) - { - for ( j = 0; j < dvert->totweight; j++ ) - { - if (( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_mass-1)) && (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL )) - { + if ( dvert ) { + for ( j = 0; j < dvert->totweight; j++ ) { + if (( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_mass-1)) && (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL )) { verts->goal = dvert->dw [j].weight; /* goalfac= 1.0f; */ /* UNUSED */ @@ -769,22 +747,18 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) */ verts->goal = ( float ) pow ( verts->goal , 4.0f ); - if ( verts->goal >=SOFTGOALSNAP ) - { + if ( verts->goal >=SOFTGOALSNAP ) { verts->flags |= CLOTH_VERT_FLAG_PINNED; } } - if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING ) - { - if ( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_struct-1)) - { + if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING ) { + if ( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_struct-1)) { verts->struct_stiff = dvert->dw [j].weight; verts->shear_stiff = dvert->dw [j].weight; } - if ( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_bend-1)) - { + if ( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_bend-1)) { verts->bend_stiff = dvert->dw [j].weight; } } @@ -812,8 +786,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d float maxdist = 0; // If we have a clothObject, free it. - if ( clmd->clothObject != NULL ) - { + if ( clmd->clothObject != NULL ) { cloth_free_modifier ( clmd ); if (G.rt > 0) printf("cloth_free_modifier cloth_from_object\n"); @@ -821,8 +794,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d // Allocate a new cloth object. clmd->clothObject = MEM_callocN ( sizeof ( Cloth ), "cloth" ); - if ( clmd->clothObject ) - { + if ( clmd->clothObject ) { clmd->clothObject->old_solver_type = 255; // clmd->clothObject->old_collision_type = 255; cloth = clmd->clothObject; @@ -851,10 +823,8 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d verts = clmd->clothObject->verts; // set initial values - for ( i = 0; i < dm->getNumVerts(dm); i++, verts++ ) - { - if (first) - { + for ( i = 0; i < dm->getNumVerts(dm); i++, verts++ ) { + if (first) { copy_v3_v3( verts->x, mvert[i].co ); mul_m4_v3( ob->obmat, verts->x ); @@ -891,18 +861,15 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d // has to be happen before springs are build! cloth_apply_vgroup (clmd, dm); - if ( !cloth_build_springs ( clmd, dm ) ) - { + if ( !cloth_build_springs ( clmd, dm ) ) { cloth_free_modifier ( clmd ); modifier_setError(&(clmd->modifier), "%s", TIP_("Can't build springs.")); printf("cloth_free_modifier cloth_build_springs\n"); return 0; } - for ( i = 0; i < dm->getNumVerts(dm); i++) - { - if ((!(cloth->verts[i].flags & CLOTH_VERT_FLAG_PINNED)) && (cloth->verts[i].goal > ALMOST_ZERO)) - { + for ( i = 0; i < dm->getNumVerts(dm); i++) { + if ((!(cloth->verts[i].flags & CLOTH_VERT_FLAG_PINNED)) && (cloth->verts[i].goal > ALMOST_ZERO)) { cloth_add_spring (clmd, i, i, 0.0, CLOTH_SPRING_TYPE_GOAL); } } @@ -917,8 +884,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d clmd->clothObject->bvhtree = bvhtree_build_from_cloth ( clmd, MAX2(clmd->coll_parms->epsilon, clmd->coll_parms->distance_repel) ); - for (i = 0; i < dm->getNumVerts(dm); i++) - { + for (i = 0; i < dm->getNumVerts(dm); i++) { maxdist = MAX2(maxdist, clmd->coll_parms->selfepsilon* ( cloth->verts[i].avg_spring_len*2.0f)); } @@ -937,8 +903,7 @@ static void cloth_from_mesh ( ClothModifierData *clmd, DerivedMesh *dm ) /* Allocate our vertices. */ clmd->clothObject->numverts = numverts; clmd->clothObject->verts = MEM_callocN ( sizeof ( ClothVertex ) * clmd->clothObject->numverts, "clothVertex" ); - if ( clmd->clothObject->verts == NULL ) - { + if ( clmd->clothObject->verts == NULL ) { cloth_free_modifier ( clmd ); modifier_setError(&(clmd->modifier), "%s", TIP_("Out of memory on allocating clmd->clothObject->verts.")); printf("cloth_free_modifier clmd->clothObject->verts\n"); @@ -948,8 +913,7 @@ static void cloth_from_mesh ( ClothModifierData *clmd, DerivedMesh *dm ) // save face information clmd->clothObject->numfaces = numfaces; clmd->clothObject->mfaces = MEM_callocN ( sizeof ( MFace ) * clmd->clothObject->numfaces, "clothMFaces" ); - if ( clmd->clothObject->mfaces == NULL ) - { + if ( clmd->clothObject->mfaces == NULL ) { cloth_free_modifier ( clmd ); modifier_setError(&(clmd->modifier), "%s", TIP_("Out of memory on allocating clmd->clothObject->mfaces.")); printf("cloth_free_modifier clmd->clothObject->mfaces\n"); @@ -977,8 +941,7 @@ int cloth_add_spring ( ClothModifierData *clmd, unsigned int indexA, unsigned in Cloth *cloth = clmd->clothObject; ClothSpring *spring = NULL; - if (cloth) - { + if (cloth) { // TODO: look if this spring is already there spring = ( ClothSpring * ) MEM_callocN ( sizeof ( ClothSpring ), "cloth spring" ); @@ -1006,11 +969,9 @@ static void cloth_free_errorsprings(Cloth *cloth, EdgeHash *UNUSED(edgehash), Li { unsigned int i = 0; - if ( cloth->springs != NULL ) - { + if ( cloth->springs != NULL ) { LinkNode *search = cloth->springs; - while (search) - { + while (search) { ClothSpring *spring = search->link; MEM_freeN ( spring ); @@ -1021,10 +982,8 @@ static void cloth_free_errorsprings(Cloth *cloth, EdgeHash *UNUSED(edgehash), Li cloth->springs = NULL; } - if (edgelist) - { - for ( i = 0; i < cloth->numverts; i++ ) - { + if (edgelist) { + for ( i = 0; i < cloth->numverts; i++ ) { BLI_linklist_free ( edgelist[i],NULL ); } @@ -1062,8 +1021,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) if (!edgelist) return 0; - for ( i = 0; i < numverts; i++ ) - { + for ( i = 0; i < numverts; i++ ) { edgelist[i] = NULL; } @@ -1074,12 +1032,10 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) edgehash = BLI_edgehash_new(); // structural springs - for ( i = 0; i < numedges; i++ ) - { + for ( i = 0; i < numedges; i++ ) { spring = ( ClothSpring * ) MEM_callocN ( sizeof ( ClothSpring ), "cloth spring" ); - if ( spring ) - { + if ( spring ) { spring->ij = MIN2(medge[i].v1, medge[i].v2); spring->kl = MAX2(medge[i].v2, medge[i].v1); spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest); @@ -1104,22 +1060,19 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) if (struct_springs > 0) clmd->sim_parms->avg_spring_len /= struct_springs; - for (i = 0; i < numverts; i++) - { + for (i = 0; i < numverts; i++) { cloth->verts[i].avg_spring_len = cloth->verts[i].avg_spring_len * 0.49f / ((float)cloth->verts[i].spring_count); } // shear springs - for ( i = 0; i < numfaces; i++ ) - { + for ( i = 0; i < numfaces; i++ ) { // triangle faces already have shear springs due to structural geometry if ( !mface[i].v4 ) continue; spring = ( ClothSpring *) MEM_callocN ( sizeof ( ClothSpring ), "cloth spring" ); - if (!spring) - { + if (!spring) { cloth_free_errorsprings(cloth, edgehash, edgelist); return 0; } @@ -1140,8 +1093,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) // if ( mface[i].v4 ) --> Quad face spring = ( ClothSpring * ) MEM_callocN ( sizeof ( ClothSpring ), "cloth spring" ); - if (!spring) - { + if (!spring) { cloth_free_errorsprings(cloth, edgehash, edgelist); return 0; } @@ -1162,15 +1114,13 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) if (numfaces) { // bending springs search2 = cloth->springs; - for ( i = struct_springs; i < struct_springs+shear_springs; i++ ) - { + for ( i = struct_springs; i < struct_springs+shear_springs; i++ ) { if ( !search2 ) break; tspring2 = search2->link; search = edgelist[tspring2->kl]; - while ( search ) - { + while ( search ) { tspring = search->link; index2 = ( ( tspring->ij==tspring2->kl ) ? ( tspring->kl ) : ( tspring->ij ) ); @@ -1181,8 +1131,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) { spring = ( ClothSpring * ) MEM_callocN ( sizeof ( ClothSpring ), "cloth spring" ); - if (!spring) - { + if (!spring) { cloth_free_errorsprings(cloth, edgehash, edgelist); return 0; } @@ -1212,16 +1161,14 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) /* of the strands. -jahka */ search = cloth->springs; search2 = search->next; - while (search && search2) - { + while (search && search2) { tspring = search->link; tspring2 = search2->link; if (tspring->ij == tspring2->kl) { spring = ( ClothSpring * ) MEM_callocN ( sizeof ( ClothSpring ), "cloth spring" ); - if (!spring) - { + if (!spring) { cloth_free_errorsprings(cloth, edgehash, edgelist); return 0; } @@ -1242,13 +1189,12 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) } /* insert other near springs in edgehash AFTER bending springs are calculated (for selfcolls) */ - for ( i = 0; i < numedges; i++ ) // struct springs + for (i = 0; i < numedges; i++) { /* struct springs */ BLI_edgehash_insert ( edgehash, MIN2(medge[i].v1, medge[i].v2), MAX2(medge[i].v2, medge[i].v1), NULL ); - - for ( i = 0; i < numfaces; i++ ) // edge springs - { - if (mface[i].v4) - { + } + + for (i = 0; i < numfaces; i++) { /* edge springs */ + if (mface[i].v4) { BLI_edgehash_insert ( edgehash, MIN2(mface[i].v1, mface[i].v3), MAX2(mface[i].v3, mface[i].v1), NULL ); BLI_edgehash_insert ( edgehash, MIN2(mface[i].v2, mface[i].v4), MAX2(mface[i].v2, mface[i].v4), NULL ); @@ -1258,10 +1204,8 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) cloth->numsprings = struct_springs + shear_springs + bend_springs; - if ( edgelist ) - { - for ( i = 0; i < numverts; i++ ) - { + if ( edgelist ) { + for ( i = 0; i < numverts; i++ ) { BLI_linklist_free ( edgelist[i],NULL ); } diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 5b03f73e120..264a251c317 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -80,8 +80,7 @@ void collision_move_object(CollisionModifierData *collmd, float step, float prev float tv[3] = {0, 0, 0}; unsigned int i = 0; - for ( i = 0; i < collmd->numverts; i++ ) - { + for ( i = 0; i < collmd->numverts; i++ ) { sub_v3_v3v3 ( tv, collmd->xnew[i].co, collmd->x[i].co ); VECADDS ( collmd->current_x[i].co, collmd->x[i].co, tv, prevstep ); VECADDS ( collmd->current_xnew[i].co, collmd->x[i].co, tv, step ); @@ -101,8 +100,7 @@ BVHTree *bvhtree_build_from_mvert ( MFace *mfaces, unsigned int numfaces, MVert tree = BLI_bvhtree_new ( numfaces*2, epsilon, 4, 26 ); // fill tree - for ( i = 0; i < numfaces; i++, tface++ ) - { + for ( i = 0; i < numfaces; i++, tface++ ) { copy_v3_v3 ( &co[0*3], x[tface->v1].co ); copy_v3_v3 ( &co[1*3], x[tface->v2].co ); copy_v3_v3 ( &co[2*3], x[tface->v3].co ); @@ -128,10 +126,8 @@ void bvhtree_update_from_mvert ( BVHTree * bvhtree, MFace *faces, int numfaces, if ( !bvhtree ) return; - if ( x ) - { - for ( i = 0; i < numfaces; i++, mfaces++ ) - { + if ( x ) { + for ( i = 0; i < numfaces; i++, mfaces++ ) { copy_v3_v3 ( &co[0*3], x[mfaces->v1].co ); copy_v3_v3 ( &co[1*3], x[mfaces->v2].co ); copy_v3_v3 ( &co[2*3], x[mfaces->v3].co ); @@ -139,8 +135,7 @@ void bvhtree_update_from_mvert ( BVHTree * bvhtree, MFace *faces, int numfaces, copy_v3_v3 ( &co[3*3], x[mfaces->v4].co ); // copy new locations into array - if ( moving && xnew ) - { + if ( moving && xnew ) { // update moving positions copy_v3_v3 ( &co_moving[0*3], xnew[mfaces->v1].co ); copy_v3_v3 ( &co_moving[1*3], xnew[mfaces->v2].co ); @@ -150,8 +145,7 @@ void bvhtree_update_from_mvert ( BVHTree * bvhtree, MFace *faces, int numfaces, ret = BLI_bvhtree_update_node ( bvhtree, i, co, co_moving, ( mfaces->v4 ? 4 : 3 ) ); } - else - { + else { ret = BLI_bvhtree_update_node ( bvhtree, i, co, NULL, ( mfaces->v4 ? 4 : 3 ) ); } @@ -465,8 +459,7 @@ static void collision_compute_barycentric ( float pv[3], float p1[3], float p2[3 d = ( a * c - b * b ); - if ( ABS ( d ) < (double)ALMOST_ZERO ) - { + if ( ABS ( d ) < (double)ALMOST_ZERO ) { *w1 = *w2 = *w3 = 1.0 / 3.0; return; } @@ -504,8 +497,7 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM cloth1 = clmd->clothObject; - for ( ; collpair != collision_end; collpair++ ) - { + for ( ; collpair != collision_end; collpair++ ) { // only handle static collisions here if ( collpair->flag & COLLISION_IN_FUTURE ) continue; @@ -540,8 +532,7 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM // TODO // If v_n_mag < 0 the edges are approaching each other. - if ( magrelVel > ALMOST_ZERO ) - { + if ( magrelVel > ALMOST_ZERO ) { // Calculate Impulse magnitude to stop all motion in normal direction. float magtangent = 0, repulse = 0, d = 0; double impulse = 0.0; @@ -558,8 +549,7 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM magtangent = MIN2 ( clmd->coll_parms->friction * 0.01f * magrelVel, sqrtf( dot_v3v3( vrel_t_pre,vrel_t_pre ) ) ); // Apply friction impulse. - if ( magtangent > ALMOST_ZERO ) - { + if ( magtangent > ALMOST_ZERO ) { normalize_v3( vrel_t_pre ); impulse = magtangent / ( 1.0f + w1*w1 + w2*w2 + w3*w3 ); // 2.0 * @@ -587,8 +577,7 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; d = clmd->coll_parms->epsilon*8.0f/9.0f + epsilon2*8.0f/9.0f - collpair->distance; - if ( ( magrelVel < 0.1f*d*spf ) && ( d > ALMOST_ZERO ) ) - { + if ( ( magrelVel < 0.1f*d*spf ) && ( d > ALMOST_ZERO ) ) { repulse = MIN2 ( d*1.0f/spf, 0.1f*d*spf - magrelVel ); // stay on the safe side and clamp repulse @@ -685,10 +674,8 @@ static CollPair* cloth_edge_collision ( ModifierData *md1, ModifierData *md2, face2 = & ( collmd->mfaces[overlap->indexB] ); // check all 4 possible collisions - for ( i = 0; i < 4; i++ ) - { - if ( i == 0 ) - { + for ( i = 0; i < 4; i++ ) { + if ( i == 0 ) { // fill faceA ap1 = face1->v1; ap2 = face1->v2; @@ -699,10 +686,8 @@ static CollPair* cloth_edge_collision ( ModifierData *md1, ModifierData *md2, bp2 = face2->v2; bp3 = face2->v3; } - else if ( i == 1 ) - { - if ( face1->v4 ) - { + else if ( i == 1 ) { + if ( face1->v4 ) { // fill faceA ap1 = face1->v1; ap2 = face1->v3; @@ -717,10 +702,8 @@ static CollPair* cloth_edge_collision ( ModifierData *md1, ModifierData *md2, continue; } } - if ( i == 2 ) - { - if ( face2->v4 ) - { + if ( i == 2 ) { + if ( face2->v4 ) { // fill faceA ap1 = face1->v1; ap2 = face1->v2; @@ -735,10 +718,8 @@ static CollPair* cloth_edge_collision ( ModifierData *md1, ModifierData *md2, continue; } } - else if ( i == 3 ) - { - if ( face1->v4 && face2->v4 ) - { + else if ( i == 3 ) { + if ( face1->v4 && face2->v4 ) { // fill faceA ap1 = face1->v1; ap2 = face1->v3; @@ -847,8 +828,7 @@ static int cloth_edge_collision_response_moving ( ClothModifierData *clmd, Colli cloth1 = clmd->clothObject; - for ( ; collpair != collision_end; collpair++ ) - { + for ( ; collpair != collision_end; collpair++ ) { if (!(collpair->flag & COLLISION_IS_EDGES)) continue; @@ -865,8 +845,7 @@ static int cloth_edge_collision_response_moving ( ClothModifierData *clmd, Colli magrelVel = dot_v3v3 ( relativeVelocity, collpair->normal ); // If v_n_mag < 0 the edges are approaching each other. - if ( magrelVel > ALMOST_ZERO ) - { + if ( magrelVel > ALMOST_ZERO ) { // Calculate Impulse magnitude to stop all motion in normal direction. float magtangent = 0, repulse = 0, d = 0; double impulse = 0.0; @@ -885,8 +864,7 @@ static int cloth_edge_collision_response_moving ( ClothModifierData *clmd, Colli magtangent = MIN2 ( clmd->coll_parms->friction * 0.01 * magrelVel,sqrt ( dot_v3v3 ( vrel_t_pre,vrel_t_pre ) ) ); // Apply friction impulse. - if ( magtangent > ALMOST_ZERO ) - { + if ( magtangent > ALMOST_ZERO ) { normalize_v3( vrel_t_pre ); impulse = magtangent; @@ -906,8 +884,7 @@ static int cloth_edge_collision_response_moving ( ClothModifierData *clmd, Colli spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; d = collpair->distance; - if ( ( magrelVel < 0.1*d*spf && ( d > ALMOST_ZERO ) ) ) - { + if ( ( magrelVel < 0.1*d*spf && ( d > ALMOST_ZERO ) ) ) { repulse = MIN2 ( d*1.0/spf, 0.1*d*spf - magrelVel ); // stay on the safe side and clamp repulse @@ -949,8 +926,7 @@ static int cloth_collision_response_moving ( ClothModifierData *clmd, CollisionM cloth1 = clmd->clothObject; - for ( ; collpair != collision_end; collpair++ ) - { + for ( ; collpair != collision_end; collpair++ ) { if (collpair->flag & COLLISION_IS_EDGES) continue; @@ -967,8 +943,7 @@ static int cloth_collision_response_moving ( ClothModifierData *clmd, CollisionM magrelVel = dot_v3v3 ( relativeVelocity, collpair->normal ); // If v_n_mag < 0 the edges are approaching each other. - if ( magrelVel > ALMOST_ZERO ) - { + if ( magrelVel > ALMOST_ZERO ) { // Calculate Impulse magnitude to stop all motion in normal direction. float magtangent = 0, repulse = 0, d = 0; double impulse = 0.0; @@ -985,8 +960,7 @@ static int cloth_collision_response_moving ( ClothModifierData *clmd, CollisionM magtangent = MIN2 ( clmd->coll_parms->friction * 0.01 * magrelVel,sqrt ( dot_v3v3 ( vrel_t_pre,vrel_t_pre ) ) ); // Apply friction impulse. - if ( magtangent > ALMOST_ZERO ) - { + if ( magtangent > ALMOST_ZERO ) { normalize_v3( vrel_t_pre ); impulse = magtangent; // 2.0 * @@ -1006,8 +980,7 @@ static int cloth_collision_response_moving ( ClothModifierData *clmd, CollisionM spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; d = -collpair->distance; - if ( ( magrelVel < 0.1*d*spf ) && ( d > ALMOST_ZERO ) ) - { + if ( ( magrelVel < 0.1*d*spf ) && ( d > ALMOST_ZERO ) ) { repulse = MIN2 ( d*1.0/spf, 0.1*d*spf - magrelVel ); // stay on the safe side and clamp repulse @@ -1034,8 +1007,7 @@ static int cloth_collision_response_moving ( ClothModifierData *clmd, CollisionM magrelVel = dot_v3v3 ( relativeVelocity, collpair->normal ); // If v_n_mag < 0 the edges are approaching each other. - if ( magrelVel > ALMOST_ZERO ) - { + if ( magrelVel > ALMOST_ZERO ) { // Calculate Impulse magnitude to stop all motion in normal direction. float magtangent = 0, repulse = 0, d = 0; double impulse = 0.0; @@ -1052,8 +1024,7 @@ static int cloth_collision_response_moving ( ClothModifierData *clmd, CollisionM magtangent = MIN2 ( clmd->coll_parms->friction * 0.01 * magrelVel,sqrt ( dot_v3v3 ( vrel_t_pre,vrel_t_pre ) ) ); // Apply friction impulse. - if ( magtangent > ALMOST_ZERO ) - { + if ( magtangent > ALMOST_ZERO ) { normalize_v3( vrel_t_pre ); impulse = magtangent; // 2.0 * @@ -1072,8 +1043,7 @@ static int cloth_collision_response_moving ( ClothModifierData *clmd, CollisionM spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; d = -collpair->distance; - if ( ( magrelVel < 0.1*d*spf ) && ( d > ALMOST_ZERO ) ) - { + if ( ( magrelVel < 0.1*d*spf ) && ( d > ALMOST_ZERO ) ) { repulse = MIN2 ( d*1.0/spf, 0.1*d*spf - magrelVel ); // stay on the safe side and clamp repulse @@ -1202,10 +1172,8 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTree face2 = & ( collmd->mfaces[overlap->indexB] ); // check all 4 possible collisions - for ( i = 0; i < 4; i++ ) - { - if ( i == 0 ) - { + for ( i = 0; i < 4; i++ ) { + if ( i == 0 ) { // fill faceA ap1 = face1->v1; ap2 = face1->v2; @@ -1216,10 +1184,8 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTree bp2 = face2->v2; bp3 = face2->v3; } - else if ( i == 1 ) - { - if ( face1->v4 ) - { + else if ( i == 1 ) { + if ( face1->v4 ) { // fill faceA ap1 = face1->v1; ap2 = face1->v3; @@ -1234,10 +1200,8 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTree continue; } } - if ( i == 2 ) - { - if ( face2->v4 ) - { + if ( i == 2 ) { + if ( face2->v4 ) { // fill faceA ap1 = face1->v1; ap2 = face1->v2; @@ -1252,10 +1216,8 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTree continue; } } - else if ( i == 3 ) - { - if ( face1->v4 && face2->v4 ) - { + else if ( i == 3 ) { + if ( face1->v4 && face2->v4 ) { // fill faceA ap1 = face1->v1; ap2 = face1->v3; @@ -1417,10 +1379,8 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, face2 = & ( collmd->mfaces[overlap->indexB] ); // check all 4 possible collisions - for ( i = 0; i < 4; i++ ) - { - if ( i == 0 ) - { + for ( i = 0; i < 4; i++ ) { + if ( i == 0 ) { // fill faceA collpair->ap1 = face1->v1; collpair->ap2 = face1->v2; @@ -1431,10 +1391,8 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, collpair->bp2 = face2->v2; collpair->bp3 = face2->v3; } - else if ( i == 1 ) - { - if ( face1->v4 ) - { + else if ( i == 1 ) { + if ( face1->v4 ) { // fill faceA collpair->ap1 = face1->v1; collpair->ap2 = face1->v4; @@ -1448,10 +1406,8 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, else i++; } - if ( i == 2 ) - { - if ( face2->v4 ) - { + if ( i == 2 ) { + if ( face2->v4 ) { // fill faceA collpair->ap1 = face1->v1; collpair->ap2 = face1->v2; @@ -1465,10 +1421,8 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, else break; } - else if ( i == 3 ) - { - if ( face1->v4 && face2->v4 ) - { + else if ( i == 3 ) { + if ( face1->v4 && face2->v4 ) { // fill faceA collpair->ap1 = face1->v1; collpair->ap2 = face1->v4; @@ -1513,8 +1467,7 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, distance = 2.0 * (double)( epsilon1 + epsilon2 + ALMOST_ZERO ); #endif - if ( distance <= ( epsilon1 + epsilon2 + ALMOST_ZERO ) ) - { + if ( distance <= ( epsilon1 + epsilon2 + ALMOST_ZERO ) ) { normalize_v3_v3( collpair->normal, collpair->vector ); collpair->distance = distance; @@ -2283,14 +2236,12 @@ static void cloth_bvh_objcollisions_nearcheck ( ClothModifierData * clmd, Collis #ifdef WITH_ELTOPO machine_epsilon_offset(clmd->clothObject); - for ( i = 0; i < numresult; i++ ) - { + for ( i = 0; i < numresult; i++ ) { *collisions_index = cloth_collision ( (ModifierData *)clmd, (ModifierData *)collmd, overlap+i, *collisions_index, dt, tri_visithash, arena ); } - for ( i = 0; i < numresult; i++ ) - { + for ( i = 0; i < numresult; i++ ) { *collisions_index = cloth_edge_collision ( (ModifierData *)clmd, (ModifierData *)collmd, overlap+i, *collisions_index, visithash, arena ); } @@ -2298,8 +2249,7 @@ static void cloth_bvh_objcollisions_nearcheck ( ClothModifierData * clmd, Collis BLI_ghash_free(tri_visithash, NULL, NULL); BLI_memarena_free(arena); #else /* WITH_ELTOPO */ - for ( i = 0; i < numresult; i++ ) - { + for ( i = 0; i < numresult; i++ ) { *collisions_index = cloth_collision ( (ModifierData *)clmd, (ModifierData *)collmd, overlap+i, *collisions_index, dt ); } @@ -2323,12 +2273,10 @@ static int cloth_bvh_objcollisions_resolve ( ClothModifierData * clmd, Collision // process all collisions (calculate impulses, TODO: also repulses if distance too short) result = 1; - for ( j = 0; j < 5; j++ ) // 5 is just a value that ensures convergence - { + for ( j = 0; j < 5; j++ ) { /* 5 is just a value that ensures convergence */ result = 0; - if ( collmd->bvhtree ) - { + if ( collmd->bvhtree ) { #ifdef WITH_ELTOPO result += cloth_collision_response_moving(clmd, collmd, collisions, collisions_index); result += cloth_edge_collision_response_moving(clmd, collmd, collisions, collisions_index); @@ -2339,14 +2287,11 @@ static int cloth_bvh_objcollisions_resolve ( ClothModifierData * clmd, Collision { #else // apply impulses in parallel - if ( result ) - { + if (result) { #endif - for ( i = 0; i < numverts; i++ ) - { + for (i = 0; i < numverts; i++) { // calculate "velocities" (just xnew = xold + v; no dt in v) - if ( verts[i].impulse_count ) - { + if (verts[i].impulse_count) { VECADDMUL ( verts[i].tv, verts[i].impulse, 1.0f / verts[i].impulse_count ); copy_v3_v3 ( verts[i].impulse, tnull ); verts[i].impulse_count = 0; @@ -2402,8 +2347,7 @@ int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, fl collisions_index = MEM_callocN(sizeof(CollPair *) *numcollobj , "CollPair"); // check all collision objects - for (i = 0; i < numcollobj; i++) - { + for (i = 0; i < numcollobj; i++) { Object *collob= collobjs[i]; CollisionModifierData *collmd = (CollisionModifierData*)modifiers_findByType(collob, eModifierType_Collision); BVHTreeOverlap *overlap = NULL; @@ -2435,8 +2379,7 @@ int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, fl } rounds++; - for (i = 0; i < numcollobj; i++) - { + for (i = 0; i < numcollobj; i++) { if ( collisions[i] ) MEM_freeN ( collisions[i] ); } @@ -2449,12 +2392,9 @@ int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, fl //////////////////////////////////////////////////////////// // verts come from clmd - for ( i = 0; i < numverts; i++ ) - { - if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL ) - { - if ( verts [i].flags & CLOTH_VERT_FLAG_PINNED ) - { + for ( i = 0; i < numverts; i++ ) { + if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL ) { + if ( verts [i].flags & CLOTH_VERT_FLAG_PINNED ) { continue; } } @@ -2467,10 +2407,8 @@ int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, fl //////////////////////////////////////////////////////////// // Test on *simple* selfcollisions //////////////////////////////////////////////////////////// - if ( clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF ) - { - for (l = 0; l < (unsigned int)clmd->coll_parms->self_loop_count; l++) - { + if ( clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF ) { + for (l = 0; l < (unsigned int)clmd->coll_parms->self_loop_count; l++) { // TODO: add coll quality rounds again BVHTreeOverlap *overlap = NULL; unsigned int result = 0; @@ -2483,14 +2421,12 @@ int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, fl verts = cloth->verts; - if ( cloth->bvhselftree ) - { - // search for overlapping collision pairs + if ( cloth->bvhselftree ) { + // search for overlapping collision pairs overlap = BLI_bvhtree_overlap ( cloth->bvhselftree, cloth->bvhselftree, &result ); // #pragma omp parallel for private(k, i, j) schedule(static) - for ( k = 0; k < result; k++ ) - { + for ( k = 0; k < result; k++ ) { float temp[3]; float length = 0; float mindistance; @@ -2500,8 +2436,7 @@ int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, fl mindistance = clmd->coll_parms->selfepsilon* ( cloth->verts[i].avg_spring_len + cloth->verts[j].avg_spring_len ); - if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL ) - { + if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL ) { if ( ( cloth->verts [i].flags & CLOTH_VERT_FLAG_PINNED ) && ( cloth->verts [j].flags & CLOTH_VERT_FLAG_PINNED ) ) { @@ -2514,29 +2449,24 @@ int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, fl if ( ( ABS ( temp[0] ) > mindistance ) || ( ABS ( temp[1] ) > mindistance ) || ( ABS ( temp[2] ) > mindistance ) ) continue; // check for adjacent points (i must be smaller j) - if ( BLI_edgehash_haskey ( cloth->edgehash, MIN2(i, j), MAX2(i, j) ) ) - { + if ( BLI_edgehash_haskey ( cloth->edgehash, MIN2(i, j), MAX2(i, j) ) ) { continue; } length = normalize_v3( temp ); - if ( length < mindistance ) - { + if ( length < mindistance ) { float correction = mindistance - length; - if ( cloth->verts [i].flags & CLOTH_VERT_FLAG_PINNED ) - { + if ( cloth->verts [i].flags & CLOTH_VERT_FLAG_PINNED ) { mul_v3_fl( temp, -correction ); VECADD ( verts[j].tx, verts[j].tx, temp ); } - else if ( cloth->verts [j].flags & CLOTH_VERT_FLAG_PINNED ) - { + else if ( cloth->verts [j].flags & CLOTH_VERT_FLAG_PINNED ) { mul_v3_fl( temp, correction ); VECADD ( verts[i].tx, verts[i].tx, temp ); } - else - { + else { mul_v3_fl( temp, correction * -0.5 ); VECADD ( verts[j].tx, verts[j].tx, temp ); @@ -2560,12 +2490,9 @@ int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, fl //////////////////////////////////////////////////////////// // SELFCOLLISIONS: update velocities //////////////////////////////////////////////////////////// - if ( ret2 ) - { - for ( i = 0; i < cloth->numverts; i++ ) - { - if ( ! ( verts [i].flags & CLOTH_VERT_FLAG_PINNED ) ) - { + if ( ret2 ) { + for ( i = 0; i < cloth->numverts; i++ ) { + if ( ! ( verts [i].flags & CLOTH_VERT_FLAG_PINNED ) ) { sub_v3_v3v3 ( verts[i].tv, verts[i].tx, verts[i].txold ); } } diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 25391a34689..6dc1b2a4b00 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -202,7 +202,7 @@ void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope) if (cuma->curve) MEM_freeN(cuma->curve); - switch(preset) { + switch (preset) { case CURVE_PRESET_LINE: cuma->totpoint= 2; break; case CURVE_PRESET_SHARP: cuma->totpoint= 4; break; case CURVE_PRESET_SMOOTH: cuma->totpoint= 4; break; @@ -214,7 +214,7 @@ void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope) cuma->curve= MEM_callocN(cuma->totpoint*sizeof(CurveMapPoint), "curve points"); - switch(preset) { + switch (preset) { case CURVE_PRESET_LINE: cuma->curve[0].x= clipr->xmin; cuma->curve[0].y= clipr->ymax; @@ -252,10 +252,9 @@ void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope) case CURVE_PRESET_MID9: { int i; - for (i=0; i < cuma->totpoint; i++) - { - cuma->curve[i].x= i / ((float)cuma->totpoint-1); - cuma->curve[i].y= 0.5; + for (i = 0; i < cuma->totpoint; i++) { + cuma->curve[i].x = i / ((float)cuma->totpoint - 1); + cuma->curve[i].y = 0.5; } } break; @@ -500,8 +499,8 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr) for (a=0; a<cuma->totpoint-1; a++, fp += 2*CM_RESOL) { correct_bezpart(bezt[a].vec[1], bezt[a].vec[2], bezt[a+1].vec[0], bezt[a+1].vec[1]); - forward_diff_bezier(bezt[a].vec[1][0], bezt[a].vec[2][0], bezt[a+1].vec[0][0], bezt[a+1].vec[1][0], fp, CM_RESOL-1, 2*sizeof(float)); - forward_diff_bezier(bezt[a].vec[1][1], bezt[a].vec[2][1], bezt[a+1].vec[0][1], bezt[a+1].vec[1][1], fp+1, CM_RESOL-1, 2*sizeof(float)); + BKE_curve_forward_diff_bezier(bezt[a].vec[1][0], bezt[a].vec[2][0], bezt[a+1].vec[0][0], bezt[a+1].vec[1][0], fp, CM_RESOL-1, 2*sizeof(float)); + BKE_curve_forward_diff_bezier(bezt[a].vec[1][1], bezt[a].vec[2][1], bezt[a+1].vec[0][1], bezt[a+1].vec[1][1], fp+1, CM_RESOL-1, 2*sizeof(float)); } /* store first and last handle for extrapolation, unit length */ diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 0a6e8a163cc..82a908eaf57 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -3439,8 +3439,7 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr { bShrinkwrapConstraint *scon = (bShrinkwrapConstraint *) con->data; - if ( VALID_CONS_TARGET(ct) && (ct->tar->type == OB_MESH) ) - { + if ( VALID_CONS_TARGET(ct) && (ct->tar->type == OB_MESH) ) { int fail = FALSE; float co[3] = {0.0f, 0.0f, 0.0f}; float no[3] = {0.0f, 0.0f, 0.0f}; @@ -3461,12 +3460,10 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr unit_m4(ct->matrix); - if (target != NULL) - { + if (target != NULL) { space_transform_from_matrixs(&transform, cob->matrix, ct->tar->obmat); - switch(scon->shrinkType) - { + switch (scon->shrinkType) { case MOD_SHRINKWRAP_NEAREST_SURFACE: case MOD_SHRINKWRAP_NEAREST_VERTEX: @@ -3475,8 +3472,7 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr else bvhtree_from_mesh_faces(&treeData, target, 0.0, 2, 6); - if (treeData.tree == NULL) - { + if (treeData.tree == NULL) { fail = TRUE; break; } @@ -3506,14 +3502,12 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr bvhtree_from_mesh_faces(&treeData, target, scon->dist, 4, 6); - if (treeData.tree == NULL) - { + if (treeData.tree == NULL) { fail = TRUE; break; } - if (normal_projection_project_vertex(0, co, no, &transform, treeData.tree, &hit, treeData.raycast_callback, &treeData) == FALSE) - { + if (normal_projection_project_vertex(0, co, no, &transform, treeData.tree, &hit, treeData.raycast_callback, &treeData) == FALSE) { fail = TRUE; break; } @@ -3542,8 +3536,7 @@ static void shrinkwrap_evaluate (bConstraint *UNUSED(con), bConstraintOb *cob, L bConstraintTarget *ct= targets->first; /* only evaluate if there is a target */ - if (VALID_CONS_TARGET(ct)) - { + if (VALID_CONS_TARGET(ct)) { copy_v3_v3(cob->matrix[3], ct->matrix[3]); } } diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index e9dd4d01b0e..7a5b4ef9b24 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -777,7 +777,7 @@ int CTX_data_mode_enum(const bContext *C) Object *obedit= CTX_data_edit_object(C); if (obedit) { - switch(obedit->type) { + switch (obedit->type) { case OB_MESH: return CTX_MODE_EDIT_MESH; case OB_CURVE: diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 9232fe8ec04..e0cadac586b 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -70,7 +70,7 @@ static int cu_isectLL(const float v1[3], const float v2[3], const float v3[3], c short cox, short coy, float *labda, float *mu, float vec[3]); -void unlink_curve(Curve *cu) +void BKE_curve_unlink(Curve *cu) { int a; @@ -95,7 +95,7 @@ void unlink_curve(Curve *cu) } /* frees editcurve entirely */ -void BKE_free_editfont(Curve *cu) +void BKE_curve_editfont_free(Curve *cu) { if (cu->editfont) { EditFont *ef= cu->editfont; @@ -112,7 +112,7 @@ void BKE_free_editfont(Curve *cu) } } -void free_curve_editNurb_keyIndex(EditNurb *editnurb) +void BKE_curve_editNurb_keyIndex_free(EditNurb *editnurb) { if (!editnurb->keyindex) { return; @@ -121,26 +121,26 @@ void free_curve_editNurb_keyIndex(EditNurb *editnurb) editnurb->keyindex= NULL; } -void free_curve_editNurb (Curve *cu) +void BKE_curve_editNurb_free (Curve *cu) { if (cu->editnurb) { - freeNurblist(&cu->editnurb->nurbs); - free_curve_editNurb_keyIndex(cu->editnurb); + BKE_nurbList_free(&cu->editnurb->nurbs); + BKE_curve_editNurb_keyIndex_free(cu->editnurb); MEM_freeN(cu->editnurb); cu->editnurb= NULL; } } /* don't free curve itself */ -void free_curve(Curve *cu) +void BKE_curve_free(Curve *cu) { - freeNurblist(&cu->nurb); + BKE_nurbList_free(&cu->nurb); BLI_freelistN(&cu->bev); freedisplist(&cu->disp); - BKE_free_editfont(cu); + BKE_curve_editfont_free(cu); - free_curve_editNurb(cu); - unlink_curve(cu); + BKE_curve_editNurb_free(cu); + BKE_curve_unlink(cu); BKE_free_animdata((ID *)cu); if (cu->mat) MEM_freeN(cu->mat); @@ -151,7 +151,7 @@ void free_curve(Curve *cu) if (cu->tb) MEM_freeN(cu->tb); } -Curve *add_curve(const char *name, int type) +Curve *BKE_curve_add(const char *name, int type) { Curve *cu; @@ -187,14 +187,14 @@ Curve *add_curve(const char *name, int type) return cu; } -Curve *copy_curve(Curve *cu) +Curve *BKE_curve_copy(Curve *cu) { Curve *cun; int a; cun= copy_libblock(&cu->id); cun->nurb.first= cun->nurb.last= NULL; - duplicateNurblist( &(cun->nurb), &(cu->nurb)); + BKE_nurbList_duplicate( &(cun->nurb), &(cu->nurb)); cun->mat= MEM_dupallocN(cu->mat); for (a=0; a<cun->totcol; a++) { @@ -242,7 +242,7 @@ static void extern_local_curve(Curve *cu) } } -void make_local_curve(Curve *cu) +void BKE_curve_make_local(Curve *cu) { Main *bmain= G.main; Object *ob; @@ -273,7 +273,7 @@ void make_local_curve(Curve *cu) extern_local_curve(cu); } else if (is_local && is_lib) { - Curve *cu_new= copy_curve(cu); + Curve *cu_new= BKE_curve_copy(cu); cu_new->id.us= 0; BKE_id_lib_local_paths(bmain, cu->id.lib, &cu_new->id); @@ -291,7 +291,7 @@ void make_local_curve(Curve *cu) } /* Get list of nurbs from editnurbs structure */ -ListBase *curve_editnurbs(Curve *cu) +ListBase *BKE_curve_editNurbs_get(Curve *cu) { if (cu->editnurb) { return &cu->editnurb->nurbs; @@ -300,7 +300,7 @@ ListBase *curve_editnurbs(Curve *cu) return NULL; } -short curve_type(Curve *cu) +short BKE_curve_type_get(Curve *cu) { Nurb *nu; int type= cu->type; @@ -322,9 +322,9 @@ short curve_type(Curve *cu) return type; } -void update_curve_dimension(Curve *cu) +void BKE_curve_curve_dimension_update(Curve *cu) { - ListBase *nurbs= BKE_curve_nurbs(cu); + ListBase *nurbs= BKE_curve_nurbs_get(cu); Nurb *nu= nurbs->first; if (cu->flag&CU_3D) { @@ -335,24 +335,24 @@ void update_curve_dimension(Curve *cu) else { for ( ; nu; nu= nu->next) { nu->flag |= CU_2D; - test2DNurb(nu); + BKE_nurb_test2D(nu); /* since the handles are moved they need to be auto-located again */ if (nu->type == CU_BEZIER) - calchandlesNurb(nu); + BKE_nurb_handles_calc(nu); } } } -void test_curve_type(Object *ob) +void BKE_curve_type_test(Object *ob) { - ob->type= curve_type(ob->data); + ob->type= BKE_curve_type_get(ob->data); if (ob->type==OB_CURVE) - update_curve_dimension((Curve *)ob->data); + BKE_curve_curve_dimension_update((Curve *)ob->data); } -void tex_space_curve(Curve *cu) +void BKE_curve_tex_space_calc(Curve *cu) { DispList *dl; BoundBox *bb; @@ -408,7 +408,7 @@ void tex_space_curve(Curve *cu) } } -int count_curveverts(ListBase *nurb) +int BKE_nurbList_verts_count(ListBase *nurb) { Nurb *nu; int tot=0; @@ -423,7 +423,7 @@ int count_curveverts(ListBase *nurb) return tot; } -int count_curveverts_without_handles(ListBase *nurb) +int BKE_nurbList_verts_count_without_handles(ListBase *nurb) { Nurb *nu; int tot=0; @@ -440,7 +440,7 @@ int count_curveverts_without_handles(ListBase *nurb) /* **************** NURBS ROUTINES ******************** */ -void freeNurb(Nurb *nu) +void BKE_nurb_free(Nurb *nu) { if (nu==NULL) return; @@ -460,7 +460,7 @@ void freeNurb(Nurb *nu) } -void freeNurblist(ListBase *lb) +void BKE_nurbList_free(ListBase *lb) { Nurb *nu, *next; @@ -469,13 +469,13 @@ void freeNurblist(ListBase *lb) nu= lb->first; while (nu) { next= nu->next; - freeNurb(nu); + BKE_nurb_free(nu); nu= next; } lb->first= lb->last= NULL; } -Nurb *duplicateNurb(Nurb *nu) +Nurb *BKE_nurb_duplicate(Nurb *nu) { Nurb *newnu; int len; @@ -515,22 +515,22 @@ Nurb *duplicateNurb(Nurb *nu) return newnu; } -void duplicateNurblist(ListBase *lb1, ListBase *lb2) +void BKE_nurbList_duplicate(ListBase *lb1, ListBase *lb2) { Nurb *nu, *nun; - freeNurblist(lb1); + BKE_nurbList_free(lb1); nu= lb2->first; while (nu) { - nun= duplicateNurb(nu); + nun= BKE_nurb_duplicate(nu); BLI_addtail(lb1, nun); nu= nu->next; } } -void test2DNurb(Nurb *nu) +void BKE_nurb_test2D(Nurb *nu) { BezTriple *bezt; BPoint *bp; @@ -559,7 +559,7 @@ void test2DNurb(Nurb *nu) } } -void minmaxNurb(Nurb *nu, float *min, float *max) +void BKE_nurb_minmax(Nurb *nu, float *min, float *max) { BezTriple *bezt; BPoint *bp; @@ -586,7 +586,7 @@ void minmaxNurb(Nurb *nu, float *min, float *max) } /* be sure to call makeknots after this */ -void addNurbPoints(Nurb *nu, int number) +void BKE_nurb_points_add(Nurb *nu, int number) { BPoint *tmp= nu->bp; int i; @@ -606,7 +606,7 @@ void addNurbPoints(Nurb *nu, int number) nu->pntsu += number; } -void addNurbPointsBezier(Nurb *nu, int number) +void BKE_nurb_bezierPoints_add(Nurb *nu, int number) { BezTriple *tmp= nu->bezt; int i; @@ -636,7 +636,7 @@ static void calcknots(float *knots, const short pnts, const short order, const s float k; int a; - switch(flag & (CU_NURB_ENDPOINT|CU_NURB_BEZIER)) { + switch (flag & (CU_NURB_ENDPOINT|CU_NURB_BEZIER)) { case CU_NURB_ENDPOINT: k= 0.0; for (a=1; a <= pnts_order; a++) { @@ -706,7 +706,7 @@ static void makeknots(Nurb *nu, short uv) if (nu->type == CU_NURBS) { if (uv == 1) { if (nu->knotsu) MEM_freeN(nu->knotsu); - if (check_valid_nurb_u(nu)) { + if (BKE_nurb_check_valid_u(nu)) { nu->knotsu= MEM_callocN(4+sizeof(float)*KNOTSU(nu), "makeknots"); if (nu->flagu & CU_NURB_CYCLIC) { calcknots(nu->knotsu, nu->pntsu, nu->orderu, 0); /* cyclic should be uniform */ @@ -721,7 +721,7 @@ static void makeknots(Nurb *nu, short uv) } else if (uv == 2) { if (nu->knotsv) MEM_freeN(nu->knotsv); - if (check_valid_nurb_v(nu)) { + if (BKE_nurb_check_valid_v(nu)) { nu->knotsv= MEM_callocN(4+sizeof(float)*KNOTSV(nu), "makeknots"); if (nu->flagv & CU_NURB_CYCLIC) { calcknots(nu->knotsv, nu->pntsv, nu->orderv, 0); /* cyclic should be uniform */ @@ -736,12 +736,12 @@ static void makeknots(Nurb *nu, short uv) } } -void nurbs_knot_calc_u(Nurb *nu) +void BKE_nurb_knot_calc_u(Nurb *nu) { makeknots(nu, 1); } -void nurbs_knot_calc_v(Nurb *nu) +void BKE_nurb_knot_calc_v(Nurb *nu) { makeknots(nu, 2); } @@ -809,7 +809,7 @@ static void basisNurb(float t, short order, short pnts, float *knots, float *bas } -void makeNurbfaces(Nurb *nu, float *coord_array, int rowstride, int resolu, int resolv) +void BKE_nurb_makeFaces(Nurb *nu, float *coord_array, int rowstride, int resolu, int resolv) /* coord_array has to be 3*4*resolu*resolv in size, and zero-ed */ { BPoint *bp; @@ -972,7 +972,7 @@ void makeNurbfaces(Nurb *nu, float *coord_array, int rowstride, int resolu, int MEM_freeN(jend); } -void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, float *weight_array, int resolu, int stride) +void BKE_nurb_makeCurve(Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, float *weight_array, int resolu, int stride) /* coord_array has to be 3*4*pntsu*resolu in size and zero-ed * tilt_array and radius_array will be written to if valid */ { @@ -1074,7 +1074,7 @@ void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radiu } /* forward differencing method for bezier curve */ -void forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride) +void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride) { float rt0,rt1,rt2,rt3,f; int a; @@ -1122,7 +1122,7 @@ static void forward_diff_bezier_cotangent(float *p0, float *p1, float *p2, float /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -float *make_orco_surf(Object *ob) +float *BKE_curve_surf_make_orco(Object *ob) { /* Note: this function is used in convertblender only atm, so * suppose nonzero curve's render resolution should always be used */ @@ -1190,7 +1190,7 @@ float *make_orco_surf(Object *ob) float *_tdata= MEM_callocN((nu->pntsu*resolu) * (nu->pntsv*resolv) *3*sizeof(float), "temp data"); float *tdata= _tdata; - makeNurbfaces(nu, tdata, 0, resolu, resolv); + BKE_nurb_makeFaces(nu, tdata, 0, resolu, resolv); for (b=0; b<sizeu; b++) { int use_b= b; @@ -1224,7 +1224,7 @@ float *make_orco_surf(Object *ob) /* NOTE: This routine is tied to the order of vertex * built by displist and as passed to the renderer. */ -float *make_orco_curve(Scene *scene, Object *ob) +float *BKE_curve_make_orco(Scene *scene, Object *ob) { Curve *cu = ob->data; DispList *dl; @@ -1312,7 +1312,7 @@ float *make_orco_curve(Scene *scene, Object *ob) /* ***************** BEVEL ****************** */ -void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender) +void BKE_curve_bevel_make(Scene *scene, Object *ob, ListBase *disp, int forRender) { DispList *dl, *dlnew; Curve *bevcu, *cu; @@ -2038,7 +2038,7 @@ static void make_bevel_list_3D_tangent(BevList *bl) static void make_bevel_list_3D(BevList *bl, int smooth_iter, int twist_mode) { - switch(twist_mode) { + switch (twist_mode) { case CU_TWIST_TANGENT: make_bevel_list_3D_tangent(bl); break; @@ -2083,7 +2083,7 @@ static void make_bevel_list_segment_3D(BevList *bl) -void makeBevelList(Object *ob) +void BKE_curve_bevelList_make(Object *ob) { /* * - convert all curves to polys, with indication of resol and flags for double-vertices @@ -2112,7 +2112,7 @@ void makeBevelList(Object *ob) BLI_freelistN(&(cu->bev)); if (cu->editnurb && ob->type!=OB_FONT) { - ListBase *nurbs= curve_editnurbs(cu); + ListBase *nurbs= BKE_curve_editNurbs_get(cu); nu = nurbs->first; } else { @@ -2128,7 +2128,7 @@ void makeBevelList(Object *ob) /* check we are a single point? also check we are not a surface and that the orderu is sane, * enforced in the UI but can go wrong possibly */ - if (!check_valid_nurb_u(nu)) { + if (!BKE_nurb_check_valid_u(nu)) { bl= MEM_callocN(sizeof(BevList)+1*sizeof(BevPoint), "makeBevelList1"); BLI_addtail(&(cu->bev), bl); bl->nr= 0; @@ -2201,7 +2201,7 @@ void makeBevelList(Object *ob) /* BevPoint must stay aligned to 4 so sizeof(BevPoint)/sizeof(float) works */ for (j=0; j<3; j++) { - forward_diff_bezier( prevbezt->vec[1][j], prevbezt->vec[2][j], + BKE_curve_forward_diff_bezier( prevbezt->vec[1][j], prevbezt->vec[2][j], bezt->vec[0][j], bezt->vec[1][j], &(bevp->vec[j]), resolu, sizeof(BevPoint)); } @@ -2256,7 +2256,7 @@ void makeBevelList(Object *ob) else bl->poly= -1; bevp= (BevPoint *)(bl+1); - makeNurbcurve( nu, &bevp->vec[0], + BKE_nurb_makeCurve( nu, &bevp->vec[0], do_tilt ? &bevp->alfa : NULL, do_radius ? &bevp->radius : NULL, do_weight ? &bevp->weight : NULL, @@ -2719,18 +2719,18 @@ static void calchandlesNurb_intern(Nurb *nu, int skip_align) } } -void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode) +void BKE_nurb_handle_calc(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode) { calchandleNurb_intern(bezt, prev, next, mode, FALSE); } -void calchandlesNurb(Nurb *nu) /* first, if needed, set handle flags */ +void BKE_nurb_handles_calc(Nurb *nu) /* first, if needed, set handle flags */ { calchandlesNurb_intern(nu, FALSE); } -void testhandlesNurb(Nurb *nu) +void BKE_nurb_handles_test(Nurb *nu) { /* use when something has changed with handles. * it treats all BezTriples with the following rules: @@ -2770,10 +2770,10 @@ void testhandlesNurb(Nurb *nu) bezt++; } - calchandlesNurb(nu); + BKE_nurb_handles_calc(nu); } -void autocalchandlesNurb(Nurb *nu, int flag) +void BKE_nurb_handles_autocalc(Nurb *nu, int flag) { /* checks handle coordinates and calculates type */ @@ -2841,21 +2841,21 @@ void autocalchandlesNurb(Nurb *nu, int flag) bezt2++; } - calchandlesNurb(nu); + BKE_nurb_handles_calc(nu); } -void autocalchandlesNurb_all(ListBase *editnurb, int flag) +void BKE_nurbList_handles_autocalc(ListBase *editnurb, int flag) { Nurb *nu; nu= editnurb->first; while (nu) { - autocalchandlesNurb(nu, flag); + BKE_nurb_handles_autocalc(nu, flag); nu= nu->next; } } -void sethandlesNurb(ListBase *editnurb, short code) +void BKE_nurbList_handles_set(ListBase *editnurb, short code) { /* code==1: set autohandle */ /* code==2: set vectorhandle */ @@ -2884,7 +2884,7 @@ void sethandlesNurb(ListBase *editnurb, short code) } bezt++; } - calchandlesNurb(nu); + BKE_nurb_handles_calc(nu); } nu= nu->next; } @@ -2928,7 +2928,7 @@ void sethandlesNurb(ListBase *editnurb, short code) bezt++; } - calchandlesNurb(nu); + BKE_nurb_handles_calc(nu); } nu= nu->next; } @@ -2958,7 +2958,7 @@ static void swapdata(void *adr1, void *adr2, int len) } } -void switchdirectionNurb(Nurb *nu) +void BKE_nurb_direction_switch(Nurb *nu) { BezTriple *bezt1, *bezt2; BPoint *bp1, *bp2; @@ -3064,9 +3064,9 @@ void switchdirectionNurb(Nurb *nu) } -float (*curve_getVertexCos(Curve *UNUSED(cu), ListBase *lb, int *numVerts_r))[3] +float (*BKE_curve_vertexCos_get(Curve *UNUSED(cu), ListBase *lb, int *numVerts_r))[3] { - int i, numVerts = *numVerts_r = count_curveverts(lb); + int i, numVerts = *numVerts_r = BKE_nurbList_verts_count(lb); float *co, (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "cu_vcos"); Nurb *nu; @@ -3093,7 +3093,7 @@ float (*curve_getVertexCos(Curve *UNUSED(cu), ListBase *lb, int *numVerts_r))[3] return cos; } -void curve_applyVertexCos(Curve *UNUSED(cu), ListBase *lb, float (*vertexCos)[3]) +void BK_curve_vertexCos_apply(Curve *UNUSED(cu), ListBase *lb, float (*vertexCos)[3]) { float *co = vertexCos[0]; Nurb *nu; @@ -3121,9 +3121,9 @@ void curve_applyVertexCos(Curve *UNUSED(cu), ListBase *lb, float (*vertexCos)[3] } } -float (*curve_getKeyVertexCos(Curve *UNUSED(cu), ListBase *lb, float *key))[3] +float (*BKE_curve_keyVertexCos_get(Curve *UNUSED(cu), ListBase *lb, float *key))[3] { - int i, numVerts = count_curveverts(lb); + int i, numVerts = BKE_nurbList_verts_count(lb); float *co, (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "cu_vcos"); Nurb *nu; @@ -3152,7 +3152,7 @@ float (*curve_getKeyVertexCos(Curve *UNUSED(cu), ListBase *lb, float *key))[3] return cos; } -void curve_applyKeyVertexTilts(Curve *UNUSED(cu), ListBase *lb, float *key) +void BKE_curve_keyVertexTilts_apply(Curve *UNUSED(cu), ListBase *lb, float *key) { Nurb *nu; int i; @@ -3179,7 +3179,7 @@ void curve_applyKeyVertexTilts(Curve *UNUSED(cu), ListBase *lb, float *key) } } -int check_valid_nurb_u( struct Nurb *nu ) +int BKE_nurb_check_valid_u( struct Nurb *nu ) { if (nu==NULL) return 0; if (nu->pntsu <= 1) return 0; @@ -3194,7 +3194,7 @@ int check_valid_nurb_u( struct Nurb *nu ) } return 1; } -int check_valid_nurb_v( struct Nurb *nu) +int BKE_nurb_check_valid_v( struct Nurb *nu) { if (nu==NULL) return 0; if (nu->pntsv <= 1) return 0; @@ -3210,7 +3210,7 @@ int check_valid_nurb_v( struct Nurb *nu) return 1; } -int clamp_nurb_order_u( struct Nurb *nu ) +int BKE_nurb_order_clamp_u( struct Nurb *nu ) { int change = 0; if (nu->pntsu<nu->orderu) { @@ -3224,7 +3224,7 @@ int clamp_nurb_order_u( struct Nurb *nu ) return change; } -int clamp_nurb_order_v( struct Nurb *nu) +int BKE_nurb_order_clamp_v( struct Nurb *nu) { int change = 0; if (nu->pntsv<nu->orderv) { @@ -3239,10 +3239,10 @@ int clamp_nurb_order_v( struct Nurb *nu) } /* Get edit nurbs or normal nurbs list */ -ListBase *BKE_curve_nurbs(Curve *cu) +ListBase *BKE_curve_nurbs_get(Curve *cu) { if (cu->editnurb) { - return curve_editnurbs(cu); + return BKE_curve_editNurbs_get(cu); } return &cu->nurb; @@ -3250,20 +3250,20 @@ ListBase *BKE_curve_nurbs(Curve *cu) /* basic vertex data functions */ -int minmax_curve(Curve *cu, float min[3], float max[3]) +int BKE_curve_minmax(Curve *cu, float min[3], float max[3]) { - ListBase *nurb_lb= BKE_curve_nurbs(cu); + ListBase *nurb_lb= BKE_curve_nurbs_get(cu); Nurb *nu; for (nu= nurb_lb->first; nu; nu= nu->next) - minmaxNurb(nu, min, max); + BKE_nurb_minmax(nu, min, max); return (nurb_lb->first != NULL); } -int curve_center_median(Curve *cu, float cent[3]) +int BKE_curve_center_median(Curve *cu, float cent[3]) { - ListBase *nurb_lb= BKE_curve_nurbs(cu); + ListBase *nurb_lb= BKE_curve_nurbs_get(cu); Nurb *nu; int total= 0; @@ -3297,11 +3297,11 @@ int curve_center_median(Curve *cu, float cent[3]) return (total != 0); } -int curve_center_bounds(Curve *cu, float cent[3]) +int BKE_curve_center_bounds(Curve *cu, float cent[3]) { float min[3], max[3]; INIT_MINMAX(min, max); - if (minmax_curve(cu, min, max)) { + if (BKE_curve_minmax(cu, min, max)) { mid_v3_v3v3(cent, min, max); return 1; } @@ -3309,9 +3309,9 @@ int curve_center_bounds(Curve *cu, float cent[3]) return 0; } -void curve_translate(Curve *cu, float offset[3], int do_keys) +void BKE_curve_translate(Curve *cu, float offset[3], int do_keys) { - ListBase *nurb_lb= BKE_curve_nurbs(cu); + ListBase *nurb_lb= BKE_curve_nurbs_get(cu); Nurb *nu; int i; @@ -3346,9 +3346,9 @@ void curve_translate(Curve *cu, float offset[3], int do_keys) } } -void curve_delete_material_index(Curve *cu, int index) +void BKE_curve_delete_material_index(Curve *cu, int index) { - const int curvetype= curve_type(cu); + const int curvetype= BKE_curve_type_get(cu); if (curvetype == OB_FONT) { struct CharInfo *info= cu->strinfo; diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 1514716d717..ee8e57d5a3e 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -2337,7 +2337,10 @@ int CustomData_layer_has_math(struct CustomData *data, int layer_n) const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[layer_n].type); if (typeInfo->equal && typeInfo->add && typeInfo->multiply && - typeInfo->initminmax && typeInfo->dominmax) return 1; + typeInfo->initminmax && typeInfo->dominmax) + { + return 1; + } return 0; } @@ -2684,7 +2687,9 @@ int CustomData_verify_versions(struct CustomData *data, int index) if (!typeInfo->defaultname && (index > 0) && data->layers[index-1].type == layer->type) + { keeplayer = 0; /* multiple layers of which we only support one */ + } } if (!keeplayer) { diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 1232177fa10..3e0c947ff4a 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -479,7 +479,7 @@ void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_ /* first case; separator . - _ with extensions r R l L */ if (is_char_sep(name[len - 2]) ) { - switch(name[len - 1]) { + switch (name[len - 1]) { case 'l': prefix[len - 1] = 0; strcpy(replace, "r"); @@ -500,7 +500,7 @@ void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_ } /* case; beginning with r R l L , with separator after it */ else if (is_char_sep(name[1]) ) { - switch(name[0]) { + switch (name[0]) { case 'l': strcpy(replace, "r"); BLI_strncpy(suffix, name + 1, sizeof(suffix)); diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index aa6d42977ca..045d85242f1 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -462,7 +462,7 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O if (ob->parent) { node2 = dag_get_node(dag,ob->parent); - switch(ob->partype) { + switch (ob->partype) { case PARSKEL: dag_add_relation(dag,node2,node,DAG_RL_DATA_DATA|DAG_RL_OB_OB, "Parent"); break; @@ -539,7 +539,7 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O break; case OB_MBALL: { - Object *mom= find_basis_mball(scene, ob); + Object *mom= BKE_metaball_basis_find(scene, ob); if (mom!=ob) { node2 = dag_get_node(dag, mom); @@ -2245,7 +2245,7 @@ static void dag_object_time_update_flags(Object *ob) Curve *cu; Lattice *lt; - switch(ob->type) { + switch (ob->type) { case OB_MESH: me= ob->data; if (me->key) { diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 01d5d6ef2ad..3d79386e19a 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -1,4 +1,5 @@ /* + * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or @@ -228,7 +229,7 @@ void count_displist(ListBase *lb, int *totvert, int *totface) dl= lb->first; while (dl) { - switch(dl->type) { + switch (dl->type) { case DL_SURF: *totvert+= dl->nr*dl->parts; *totface+= (dl->nr-1)*(dl->parts-1); @@ -296,7 +297,7 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase, i else resolu= nu->resolu; - if (!check_valid_nurb_u(nu)); + if (!BKE_nurb_check_valid_u(nu)); else if (nu->type == CU_BEZIER) { /* count */ @@ -351,7 +352,7 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase, i else { int j; for (j=0; j<3; j++) { - forward_diff_bezier( prevbezt->vec[1][j], + BKE_curve_forward_diff_bezier( prevbezt->vec[1][j], prevbezt->vec[2][j], bezt->vec[0][j], bezt->vec[1][j], @@ -384,7 +385,7 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase, i data= dl->verts; if (nu->flagu & CU_NURB_CYCLIC) dl->type= DL_POLY; else dl->type= DL_SEGM; - makeNurbcurve(nu, data, NULL, NULL, NULL, resolu, 3*sizeof(float)); + BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, 3*sizeof(float)); } else if (nu->type == CU_POLY) { len= nu->pntsu; @@ -672,9 +673,9 @@ void makeDispListMBall(Scene *scene, Object *ob) freedisplist(&(ob->disp)); if (ob->type==OB_MBALL) { - if (ob==find_basis_mball(scene, ob)) { - metaball_polygonize(scene, ob, &ob->disp); - tex_space_mball(ob); + if (ob==BKE_metaball_basis_find(scene, ob)) { + BKE_metaball_polygonize(scene, ob, &ob->disp); + BKE_metaball_tex_space_calc(ob); object_deform_mball(ob, &ob->disp); } @@ -685,8 +686,8 @@ void makeDispListMBall(Scene *scene, Object *ob) void makeDispListMBall_forRender(Scene *scene, Object *ob, ListBase *dispbase) { - metaball_polygonize(scene, ob, dispbase); - tex_space_mball(ob); + BKE_metaball_polygonize(scene, ob, dispbase); + BKE_metaball_tex_space_calc(ob); object_deform_mball(ob, dispbase); } @@ -730,7 +731,7 @@ static void curve_calc_modifiers_pre(Scene *scene, Object *ob, int forRender, fl ModifierData *md = modifiers_getVirtualModifierList(ob); ModifierData *pretessellatePoint; Curve *cu= ob->data; - ListBase *nurb= BKE_curve_nurbs(cu); + ListBase *nurb= BKE_curve_nurbs_get(cu); int numVerts = 0; int editmode = (!forRender && cu->editnurb); float (*originalVerts)[3] = NULL; @@ -753,9 +754,9 @@ static void curve_calc_modifiers_pre(Scene *scene, Object *ob, int forRender, fl * tilts, which is passed through in the modifier stack. * this is also the reason curves do not use a virtual * shape key modifier yet. */ - deformedVerts= curve_getKeyVertexCos(cu, nurb, keyVerts); + deformedVerts= BKE_curve_keyVertexCos_get(cu, nurb, keyVerts); originalVerts= MEM_dupallocN(deformedVerts); - numVerts = count_curveverts_without_handles(nurb); + numVerts = BKE_nurbList_verts_count_without_handles(nurb); } } @@ -770,7 +771,7 @@ static void curve_calc_modifiers_pre(Scene *scene, Object *ob, int forRender, fl if (mti->type!=eModifierTypeType_OnlyDeform) continue; if (!deformedVerts) { - deformedVerts = curve_getVertexCos(cu, nurb, &numVerts); + deformedVerts = BKE_curve_vertexCos_get(cu, nurb, &numVerts); originalVerts = MEM_dupallocN(deformedVerts); } @@ -782,9 +783,9 @@ static void curve_calc_modifiers_pre(Scene *scene, Object *ob, int forRender, fl } if (deformedVerts) - curve_applyVertexCos(cu, nurb, deformedVerts); + BK_curve_vertexCos_apply(cu, nurb, deformedVerts); if (keyVerts) /* these are not passed through modifier stack */ - curve_applyKeyVertexTilts(cu, nurb, keyVerts); + BKE_curve_keyVertexTilts_apply(cu, nurb, keyVerts); if (keyVerts) MEM_freeN(keyVerts); @@ -834,7 +835,7 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba ModifierData *md = modifiers_getVirtualModifierList(ob); ModifierData *pretessellatePoint; Curve *cu= ob->data; - ListBase *nurb= BKE_curve_nurbs(cu); + ListBase *nurb= BKE_curve_nurbs_get(cu); int required_mode = 0, totvert = 0; int editmode = (!forRender && cu->editnurb); DerivedMesh *dm= NULL, *ndm; @@ -956,7 +957,7 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba } if (deformedVerts) { - curve_applyVertexCos(ob->data, nurb, originalVerts); + BK_curve_vertexCos_apply(ob->data, nurb, originalVerts); MEM_freeN(originalVerts); MEM_freeN(deformedVerts); } @@ -1023,7 +1024,7 @@ static void add_orco_dm(Scene *scene, Object *ob, DerivedMesh *dm, DerivedMesh * dm->getVertCos(dm, orco); } else { - orco= (float(*)[3])make_orco_curve(scene, ob); + orco= (float(*)[3])BKE_curve_make_orco(scene, ob); } for (a=0; a<totvert; a++) { @@ -1108,7 +1109,7 @@ void makeDispListSurf(Scene *scene, Object *ob, ListBase *dispbase, float (*deformedVerts)[3]; if (!forRender && cu->editnurb) - nubase= curve_editnurbs(cu); + nubase= BKE_curve_editNurbs_get(cu); else nubase= &cu->nurb; @@ -1144,7 +1145,7 @@ void makeDispListSurf(Scene *scene, Object *ob, ListBase *dispbase, if (nu->flagu & CU_NURB_CYCLIC) dl->type= DL_POLY; else dl->type= DL_SEGM; - makeNurbcurve(nu, data, NULL, NULL, NULL, resolu, 3*sizeof(float)); + BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, 3*sizeof(float)); } else { len= (nu->pntsu*resolu) * (nu->pntsv*resolv); @@ -1168,7 +1169,7 @@ void makeDispListSurf(Scene *scene, Object *ob, ListBase *dispbase, if (nu->flagv & CU_NURB_CYCLIC) dl->flag|= DL_CYCL_U; /* reverse too! */ if (nu->flagu & CU_NURB_CYCLIC) dl->flag|= DL_CYCL_V; - makeNurbfaces(nu, data, 0, resolu, resolv); + BKE_nurb_makeFaces(nu, data, 0, resolu, resolv); /* gl array drawing: using indices */ displist_surf_indices(dl); @@ -1182,7 +1183,7 @@ void makeDispListSurf(Scene *scene, Object *ob, ListBase *dispbase, copy_displist(&cu->disp, dispbase); if (!forRender) { - tex_space_curve(cu); + BKE_curve_tex_space_calc(cu); } if (!forOrco) @@ -1262,7 +1263,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba float (*deformedVerts)[3]; int numVerts; - nubase= BKE_curve_nurbs(cu); + nubase= BKE_curve_nurbs_get(cu); BLI_freelistN(&(cu->bev)); @@ -1273,10 +1274,10 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba if (!forOrco) curve_calc_modifiers_pre(scene, ob, forRender, &originalVerts, &deformedVerts, &numVerts); - makeBevelList(ob); + BKE_curve_bevelList_make(ob); /* If curve has no bevel will return nothing */ - makebevelcurve(scene, ob, &dlbev, forRender); + BKE_curve_bevel_make(scene, ob, &dlbev, forRender); /* no bevel or extrude, and no width correction? */ if (!dlbev.first && cu->width==1.0f) { @@ -1410,7 +1411,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba copy_displist(&cu->disp, dispbase); if (!forRender) { - tex_space_curve(cu); + BKE_curve_tex_space_calc(cu); } if (!forOrco) curve_calc_modifiers_post(scene, ob, dispbase, derivedFinal, forRender, originalVerts, deformedVerts); diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 9ce4d68eeed..e6f38a3a334 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -231,13 +231,22 @@ static int dynamicPaint_surfaceNumOfPoints(DynamicPaintSurface *surface) /* checks whether surface's format/type has realtime preview */ int dynamicPaint_surfaceHasColorPreview(DynamicPaintSurface *surface) { - if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) return 0; + if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { + return 0; + } else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WAVE) return 0; - else return 1; + surface->type == MOD_DPAINT_SURFACE_T_WAVE) + { + return 0; + } + else { + return 1; + } + } + else { + return 1; } - else return 1; } /* get currently active surface (in user interface) */ @@ -393,11 +402,15 @@ void dynamicPaintSurface_updateType(struct DynamicPaintSurface *surface) static int surface_totalSamples(DynamicPaintSurface *surface) { if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ && - surface->flags & MOD_DPAINT_ANTIALIAS) - return (surface->data->total_points*5); + surface->flags & MOD_DPAINT_ANTIALIAS) + { + return (surface->data->total_points * 5); + } if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX && - surface->flags & MOD_DPAINT_ANTIALIAS && surface->data->adj_data) + surface->flags & MOD_DPAINT_ANTIALIAS && surface->data->adj_data) + { return (surface->data->total_points+surface->data->adj_data->total_targets); + } return surface->data->total_points; } @@ -548,8 +561,7 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, Scene *scene) else base = scene->base.first; - while (base || go) - { + while (base || go) { brushObj = NULL; /* select object */ @@ -559,8 +571,7 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, Scene *scene) else brushObj = base->object; - if (!brushObj) - { + if (!brushObj) { if (surface->brush_group) go = go->next; else base= base->next; continue; @@ -572,12 +583,10 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, Scene *scene) base= base->next; md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); - if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) - { + if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) { DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)md; - if (pmd2->brush) - { + if (pmd2->brush) { DynamicPaintBrushSettings *brush = pmd2->brush; if (brush->flags & MOD_DPAINT_USES_VELOCITY) @@ -888,8 +897,10 @@ void surface_freeUnusedData(DynamicPaintSurface *surface) /* free bakedata if not active or surface is baked */ if (!(surface->flags & MOD_DPAINT_ACTIVE) || - (surface->pointcache && surface->pointcache->flag & PTCACHE_BAKED)) + (surface->pointcache && surface->pointcache->flag & PTCACHE_BAKED)) + { free_bakeData(surface->data); + } } void dynamicPaint_freeSurfaceData(DynamicPaintSurface *surface) @@ -1219,9 +1230,13 @@ static int surface_usesAdjData(DynamicPaintSurface *surface) { if (surface_usesAdjDistance(surface)) return 1; if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX && - surface->flags & MOD_DPAINT_ANTIALIAS) return 1; - - return 0; + surface->flags & MOD_DPAINT_ANTIALIAS) + { + return 1; + } + else { + return 0; + } } /* initialize surface adjacency data */ @@ -1294,10 +1309,12 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for /* now check if total number of edges+faces for * each vertex is even, if not -> vertex is on mesh edge */ for (i=0; i<sData->total_points; i++) { - if ((temp_data[i]%2) || - temp_data[i] < 4) + if ((temp_data[i] % 2) || + (temp_data[i] < 4)) + { ad->flags[i] |= ADJ_ON_MESH_EDGE; - + } + /* reset temp data */ temp_data[i] = 0; } @@ -1863,8 +1880,10 @@ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene /* restore canvas derivedmesh if required */ if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE && - surface->flags & MOD_DPAINT_DISP_INCREMENTAL && surface->next) + surface->flags & MOD_DPAINT_DISP_INCREMENTAL && surface->next) + { canvas_copyDerivedMesh(canvas, dm); + } BKE_ptcache_validate(cache, surface->current_frame); BKE_ptcache_write(&pid, surface->current_frame); @@ -2042,9 +2061,12 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh //printf("connected UV : %f,%f & %f,%f - %f,%f & %f,%f\n", s_uv1[0], s_uv1[1], s_uv2[0], s_uv2[1], t_uv1[0], t_uv1[1], t_uv2[0], t_uv2[1]); if (((s_uv1[0] == t_uv1[0] && s_uv1[1] == t_uv1[1]) && - (s_uv2[0] == t_uv2[0] && s_uv2[1] == t_uv2[1]) ) || - ((s_uv2[0] == t_uv1[0] && s_uv2[1] == t_uv1[1]) && - (s_uv1[0] == t_uv2[0] && s_uv1[1] == t_uv2[1]) )) return ((px+neighX[n_index]) + w*(py+neighY[n_index])); + (s_uv2[0] == t_uv2[0] && s_uv2[1] == t_uv2[1]) ) || + ((s_uv2[0] == t_uv1[0] && s_uv2[1] == t_uv1[1]) && + (s_uv1[0] == t_uv2[0] && s_uv1[1] == t_uv2[1]) )) + { + return ((px+neighX[n_index]) + w*(py+neighY[n_index])); + } /* * Find a point that is relatively at same edge position @@ -2185,11 +2207,9 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) */ if (!error) { #pragma omp parallel for schedule(static) - for (ty = 0; ty < h; ty++) - { + for (ty = 0; ty < h; ty++) { int tx; - for (tx = 0; tx < w; tx++) - { + for (tx = 0; tx < w; tx++) { int i, sample; int index = tx+w*ty; PaintUVPoint *tPoint = (&tempPoints[index]); @@ -2257,8 +2277,7 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) /* If collision wasn't found but the face is a quad * do another check for the second half */ - if ((!isInside) && mface[i].v4) - { + if ((!isInside) && mface[i].v4) { /* change d2 to test the other half */ sub_v2_v2v2(d2, tface[i].uv[3], tface[i].uv[0]); // uv3 - uv0 @@ -2330,11 +2349,9 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) * (To avoid seams on uv island edges) */ #pragma omp parallel for schedule(static) - for (ty = 0; ty < h; ty++) - { + for (ty = 0; ty < h; ty++) { int tx; - for (tx = 0; tx < w; tx++) - { + for (tx = 0; tx < w; tx++) { int index = tx+w*ty; PaintUVPoint *tPoint = (&tempPoints[index]); @@ -2408,11 +2425,9 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) * When base loop is over convert found neighbor indexes to real ones * Also count the final number of active surface points */ - for (ty = 0; ty < h; ty++) - { + for (ty = 0; ty < h; ty++) { int tx; - for (tx = 0; tx < w; tx++) - { + for (tx = 0; tx < w; tx++) { int index = tx+w*ty; PaintUVPoint *tPoint = (&tempPoints[index]); @@ -2440,11 +2455,9 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface) if (sData->adj_data) { PaintAdjData *ed = sData->adj_data; unsigned int n_pos = 0; - for (ty = 0; ty < h; ty++) - { + for (ty = 0; ty < h; ty++) { int tx; - for (tx = 0; tx < w; tx++) - { + for (tx = 0; tx < w; tx++) { int i, index = tx+w*ty; if (tempPoints[index].face_index != -1) { @@ -2576,8 +2589,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char* filenam if (ibuf == NULL) {setError(surface->canvas, "Image save failed: Not enough free memory.");return;} #pragma omp parallel for schedule(static) - for (index = 0; index < sData->total_points; index++) - { + for (index = 0; index < sData->total_points; index++) { int pos=f_data->uv_p[index].pixel_index*4; /* image buffer position */ /* Set values of preferred type */ @@ -2759,8 +2771,7 @@ static void mesh_faces_spherecast_dp(void *userdata, int index, const BVHTreeRay { float dist = bvhtree_ray_tri_intersection(ray, hit->dist, t0, t1, t2); - if (dist >= 0 && dist < hit->dist) - { + if (dist >= 0 && dist < hit->dist) { hit->index = index; hit->dist = dist; hit->no[0] = (quad) ? 1.0f : 0.0f; @@ -2780,7 +2791,7 @@ static void mesh_faces_spherecast_dp(void *userdata, int index, const BVHTreeRay * To optimize brush detection speed this doesn't calculate hit normal. * If ray hit the second half of a quad, no[0] is set to 1.0f, else 0.0f */ -static void mesh_faces_nearest_point_dp(void *userdata, int index, const float *co, BVHTreeNearest *nearest) +static void mesh_faces_nearest_point_dp(void *userdata, int index, const float co[3], BVHTreeNearest *nearest) { const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata; MVert *vert = data->vert; @@ -2799,8 +2810,7 @@ static void mesh_faces_nearest_point_dp(void *userdata, int index, const float * int vertex, edge; dist = nearest_point_in_tri_surface(t0, t1, t2, co, &vertex, &edge, nearest_tmp); - if (dist < nearest->dist) - { + if (dist < nearest->dist) { nearest->index = index; nearest->dist = dist; copy_v3_v3(nearest->co, nearest_tmp); @@ -3188,8 +3198,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* check bounding box collision */ if (grid && meshBrush_boundsIntersect(&grid->grid_bounds, &mesh_bb, brush, brush_radius)) /* Build a bvh tree from transformed vertices */ - if (bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 8)) - { + if (bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 8)) { int c_index; int total_cells = grid->dim[0]*grid->dim[1]*grid->dim[2]; @@ -3203,8 +3212,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* loop through cell points and process brush */ #pragma omp parallel for schedule(static) - for (id = 0; id < grid->s_num[c_index]; id++) - { + for (id = 0; id < grid->s_num[c_index]; id++) { int index = grid->t_index[grid->s_pos[c_index] + id]; int ss, samples = bData->s_num[index]; float total_sample = (float)samples; @@ -3220,8 +3228,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, total_sample = gaussianTotal; /* Supersampling */ - for (ss=0; ss<samples; ss++) - { + for (ss=0; ss<samples; ss++) { float ray_start[3], ray_dir[3]; float sample_factor = 0.0f; @@ -3263,8 +3270,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* Check volume collision */ if (brush->collision == MOD_DPAINT_COL_VOLUME || brush->collision == MOD_DPAINT_COL_VOLDIST) - if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1) - { + if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1) { /* We hit a triangle, now check if collision point normal is facing the point */ /* For optimization sake, hit point normal isn't calculated in ray cast loop */ @@ -3277,8 +3283,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* If ray and hit face normal are facing same direction * hit point is inside a closed mesh. */ - if (dot>=0) - { + if (dot>=0) { float dist = hit.dist; int f_index = hit.index; @@ -3342,8 +3347,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, hit.dist = brush_radius; /* Do a face normal directional raycast, and use that distance */ - if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, proj_ray, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1) - { + if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, proj_ray, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1) { proxDist = hit.dist; madd_v3_v3v3fl(hitCo, ray_start, proj_ray, hit.dist); /* Calculate final hit coordinates */ hQuad = (hit.no[0] == 1.0f); @@ -3446,8 +3450,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* * Process hit color and alpha */ - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) - { + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { float sampleColor[3]; float alpha_factor = 1.0f; @@ -3589,8 +3592,7 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, BLI_begin_threaded_malloc(); /* only continue if particle bb is close enough to canvas bb */ - if (boundsIntersectDist(&grid->grid_bounds, &part_bb, range)) - { + if (boundsIntersectDist(&grid->grid_bounds, &part_bb, range)) { int c_index; int total_cells = grid->dim[0]*grid->dim[1]*grid->dim[2]; @@ -3603,13 +3605,14 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* check cell bounding box */ if (!grid->s_num[c_index] || - !boundsIntersectDist(&grid->bounds[c_index], &part_bb, range)) + !boundsIntersectDist(&grid->bounds[c_index], &part_bb, range)) + { continue; + } /* loop through cell points */ #pragma omp parallel for schedule(static) - for (id = 0; id < grid->s_num[c_index]; id++) - { + for (id = 0; id < grid->s_num[c_index]; id++) { int index = grid->t_index[grid->s_pos[c_index] + id]; float disp_intersect = 0.0f; float radius = 0.0f; @@ -3714,8 +3717,7 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, } } - if (strength > 0.001f) - { + if (strength > 0.001f) { float paintColor[4] = {0.0f}; float depth = 0.0f; @@ -3781,8 +3783,7 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po * Loop through every surface point */ #pragma omp parallel for schedule(static) - for (index = 0; index < sData->total_points; index++) - { + for (index = 0; index < sData->total_points; index++) { float distance = len_v3v3(pointCoord, bData->realCoord[bData->s_pos[index]].v); float colorband[4] = {0.0f}; float strength; @@ -3891,8 +3892,7 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int if (!bNeighs) return; #pragma omp parallel for schedule(static) - for (index = 0; index < sData->total_points; index++) - { + for (index = 0; index < sData->total_points; index++) { int i; int numOfNeighs = adj_data->n_num[index]; @@ -3911,8 +3911,7 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int /* calculate average values (single thread) */ bData->average_dist = 0.0f; - for (index = 0; index < sData->total_points; index++) - { + for (index = 0; index < sData->total_points; index++) { int i; int numOfNeighs = adj_data->n_num[index]; @@ -4080,8 +4079,7 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s if (*force) { #pragma omp parallel for schedule(static) - for (index = 0; index < sData->total_points; index++) - { + for (index = 0; index < sData->total_points; index++) { float forc[3] = {0}; /* apply force fields */ @@ -4121,8 +4119,7 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s } /* calculate average values (single thread) */ - for (index = 0; index < sData->total_points; index++) - { + for (index = 0; index < sData->total_points; index++) { average_force += (*force)[index*4+3]; } average_force /= sData->total_points; @@ -4171,8 +4168,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint)); #pragma omp parallel for schedule(static) - for (index = 0; index < sData->total_points; index++) - { + for (index = 0; index < sData->total_points; index++) { int i; int numOfNeighs = sData->adj_data->n_num[index]; PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; @@ -4214,8 +4210,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint)); #pragma omp parallel for schedule(static) - for (index = 0; index < sData->total_points; index++) - { + for (index = 0; index < sData->total_points; index++) { int i; int numOfNeighs = sData->adj_data->n_num[index]; float totalAlpha = 0.0f; @@ -4256,8 +4251,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force /* * Drip Effect */ - if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP && force) - { + if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP && force) { float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*timescale/2.0f; /* Copy current surface to the previous points array to read unmodified values */ memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint)); @@ -4335,8 +4329,7 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale) if (!prevPoint) return; /* calculate average neigh distance (single thread) */ - for (index = 0; index < sData->total_points; index++) - { + for (index = 0; index < sData->total_points; index++) { int i; int numOfNeighs = sData->adj_data->n_num[index]; @@ -4435,8 +4428,7 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time int index; #pragma omp parallel for schedule(static) - for (index=0; index<sData->total_points; index++) - { + for (index=0; index<sData->total_points; index++) { /* Do drying dissolve effects */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index]; @@ -4651,8 +4643,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc * Prepare each surface point for a new step */ #pragma omp parallel for schedule(static) - for (index=0; index<sData->total_points; index++) - { + for (index=0; index<sData->total_points; index++) { float prev_point[3] = {0.0f, 0.0f, 0.0f}; if (do_velocity_data && !new_bdata) { copy_v3_v3(prev_point, bData->realCoord[bData->s_pos[index]].v); @@ -4796,8 +4787,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su else base = scene->base.first; - while (base || go) - { + while (base || go) { brushObj = NULL; /* select object */ if (surface->brush_group) { @@ -4821,12 +4811,10 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su /* check if target has an active dp modifier */ md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); - if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) - { + if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) { DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)md; /* make sure we're dealing with a brush */ - if (pmd2->brush) - { + if (pmd2->brush) { DynamicPaintBrushSettings *brush = pmd2->brush; BrushMaterials bMats = {0}; diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 857f6e75e2c..263f89a363e 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -162,7 +162,7 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) /* no need to ensure the loop order, we know its ok */ else if (f->len == 3) { - BLI_array_growone(looptris); + BLI_array_grow_one(looptris); l = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, f); for (j=0; l; l=BM_iter_step(&liter), j++) { looptris[i][j] = l; @@ -171,7 +171,7 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) } else if (f->len == 4) { BMLoop *ltmp[4]; - BLI_array_growitems(looptris, 2); + BLI_array_grow_items(looptris, 2); l = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, f); for (j=0; l; l=BM_iter_step(&liter), j++) { @@ -219,7 +219,7 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) BLI_addfilledge(&sf_ctx, firstv, v); totfilltri = BLI_edgefill_ex(&sf_ctx, FALSE, f->no); - BLI_array_growitems(looptris, totfilltri); + BLI_array_grow_items(looptris, totfilltri); for (efa = sf_ctx.fillfacebase.first; efa; efa=efa->next) { BMLoop *l1= efa->v1->tmp.p; diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 4f320b41184..c275d4ef0ac 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -129,7 +129,7 @@ PartDeflect *object_add_collision_fields(int type) pd->f_damp = 1.0f; /* set sensible defaults based on type */ - switch(type) { + switch (type) { case PFIELD_VORTEX: pd->shape = PFIELD_SHAPE_PLANE; break; @@ -419,8 +419,7 @@ static float eff_calc_visibility(ListBase *colliders, EffectorCache *eff, Effect len = normalize_v3(norm); // check all collision objects - for (col = colls->first; col; col = col->next) - { + for (col = colls->first; col; col = col->next) { CollisionModifierData *collmd = col->collmd; if (col->ob == eff->ob) @@ -506,7 +505,8 @@ float effector_falloff(EffectorCache *eff, EffectorData *efd, EffectedPoint *UNU falloff=0.0f; else if (eff->pd->zdir == PFIELD_Z_NEG && fac > 0.0f) falloff=0.0f; - else switch(eff->pd->falloff) { + else { + switch (eff->pd->falloff) { case PFIELD_FALL_SPHERE: falloff*= falloff_func_dist(eff->pd, efd->distance); break; @@ -529,6 +529,7 @@ float effector_falloff(EffectorCache *eff, EffectorData *efd, EffectedPoint *UNU falloff*= falloff_func_rad(eff->pd, r_fac); break; + } } return falloff; @@ -835,7 +836,7 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected copy_v3_v3(force, efd->vec_to_point); - switch(pd->forcefield) { + switch (pd->forcefield) { case PFIELD_WIND: copy_v3_v3(force, efd->nor); mul_v3_fl(force, strength * efd->falloff); diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index bb8cfe37a88..e85432581d5 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -800,7 +800,7 @@ void calchandles_fcurve (FCurve *fcu) if (bezt->vec[2][0] < bezt->vec[1][0]) bezt->vec[2][0]= bezt->vec[1][0]; /* calculate auto-handles */ - calchandleNurb(bezt, prev, next, 1); /* 1==special autohandle */ + BKE_nurb_handle_calc(bezt, prev, next, 1); /* 1==special autohandle */ /* for automatic ease in and out */ if (ELEM(bezt->h1,HD_AUTO,HD_AUTO_ANIM) && ELEM(bezt->h2,HD_AUTO,HD_AUTO_ANIM)) { @@ -1655,8 +1655,7 @@ static float evaluate_driver (ChannelDriver *driver, const float evaltime) { driver->curval= 0.0f; } - else - { + else { /* this evaluates the expression using Python,and returns its result: * - on errors it reports, then returns 0.0f */ diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index ed5cf5e7924..0b722aabd4c 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -318,8 +318,7 @@ static void fcm_fn_generator_evaluate (FCurve *UNUSED(fcu), FModifier *fcm, floa /* get function pointer to the func to use: * WARNING: must perform special argument validation hereto guard against crashes */ - switch (data->type) - { + switch (data->type) { /* simple ones */ case FCM_GENERATOR_FN_SIN: /* sine wave */ fn= sin; diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index b2759f18e9b..5d7960a9823 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -68,8 +68,7 @@ void free_vfont(struct VFont *vf) if (vf == NULL) return; if (vf->data) { - while (vf->data->characters.first) - { + while (vf->data->characters.first) { VChar *che = vf->data->characters.first; while (che->nurbsbase.first) { @@ -136,8 +135,7 @@ struct TmpFont *vfont_find_tmpfont(VFont *vfont) // Try finding the font from font list tmpfnt = ttfdata.first; - while (tmpfnt) - { + while (tmpfnt) { if (tmpfnt->vfont == vfont) break; tmpfnt = tmpfnt->next; @@ -280,7 +278,7 @@ VFont *load_vfont(Main *bmain, const char *name) static VFont *which_vfont(Curve *cu, CharInfo *info) { - switch(info->flag & (CU_CHINFO_BOLD|CU_CHINFO_ITALIC)) { + switch (info->flag & (CU_CHINFO_BOLD|CU_CHINFO_ITALIC)) { case CU_CHINFO_BOLD: if (cu->vfontb) return(cu->vfontb); else return(cu->vfont); case CU_CHINFO_ITALIC: @@ -397,8 +395,7 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo nu1 = che->nurbsbase.first; // Create the character - while (nu1) - { + while (nu1) { bezt1 = nu1->bezt; if (bezt1) { nu2 =(Nurb*) MEM_mallocN(sizeof(Nurb),"duplichar_nurb"); @@ -822,10 +819,15 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m } } else if ((cu->spacemode==CU_JUSTIFY) && (cu->tb[0].w != 0.0f)) { - float curofs= 0.0f; - for (i=0; i<=slen; i++) { - for (j=i; (mem[j]) && (mem[j]!='\n') && - (mem[j]!='\r') && (chartransdata[j].dobreak==0) && (j<slen); j++); + float curofs = 0.0f; + for (i = 0; i <= slen; i++) { + for (j=i; (mem[j]) && (mem[j]!='\n') && + (mem[j] != '\r') && (chartransdata[j].dobreak == 0) && (j < slen); + j++) + { + /* pass */ + } + if ((mem[j]!='\r') && (mem[j]!='\n') && ((chartransdata[j].dobreak!=0))) { if (mem[i]==' ') curofs += (linedata3[ct->linenr]-linedata[ct->linenr])/linedata4[ct->linenr]; @@ -833,7 +835,7 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m } if (mem[i]=='\n' || mem[i]=='\r' || chartransdata[i].dobreak) curofs= 0; ct++; - } + } } } @@ -950,7 +952,7 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m if ((mode==FO_CURSUP || mode==FO_PAGEUP) && ct->linenr==0); else if ((mode==FO_CURSDOWN || mode==FO_PAGEDOWN) && ct->linenr==lnr); else { - switch(mode) { + switch (mode) { case FO_CURSUP: lnr= ct->linenr-1; break; case FO_CURSDOWN: lnr= ct->linenr+1; break; case FO_PAGEUP: lnr= ct->linenr-10; break; @@ -1009,7 +1011,7 @@ struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int m if (mode == FO_EDIT) { /* make nurbdata */ - freeNurblist(&cu->nurb); + BKE_nurbList_free(&cu->nurb); ct= chartransdata; if (cu->sepchar==0) { diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index bb51325a6ef..dfe73ae20db 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -581,8 +581,7 @@ void IDP_FreeIterBeforeEnd(void *vself) static void IDP_FreeGroup(IDProperty *prop) { IDProperty *loop; - for (loop=prop->data.group.first; loop; loop=loop->next) - { + for (loop=prop->data.group.first; loop; loop=loop->next) { IDP_FreeProperty(loop); } BLI_freelistN(&prop->data.group); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 6e0330f5316..5c9c942cc6c 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -578,7 +578,7 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char BLI_strncpy(ibuf->name, name, sizeof(ibuf->name)); ibuf->userflags |= IB_BITMAPDIRTY; - switch(uvtestgrid) { + switch (uvtestgrid) { case 1: BKE_image_buf_fill_checker(rect, rect_float, width, height); break; @@ -929,7 +929,7 @@ char BKE_ftype_to_imtype(const int ftype) int BKE_imtype_is_movie(const char imtype) { - switch(imtype) { + switch (imtype) { case R_IMF_IMTYPE_AVIRAW: case R_IMF_IMTYPE_AVIJPEG: case R_IMF_IMTYPE_AVICODEC: @@ -946,7 +946,7 @@ int BKE_imtype_is_movie(const char imtype) int BKE_imtype_supports_zbuf(const char imtype) { - switch(imtype) { + switch (imtype) { case R_IMF_IMTYPE_IRIZ: case R_IMF_IMTYPE_OPENEXR: /* but not R_IMF_IMTYPE_MULTILAYER */ return 1; @@ -956,7 +956,7 @@ int BKE_imtype_supports_zbuf(const char imtype) int BKE_imtype_supports_compress(const char imtype) { - switch(imtype) { + switch (imtype) { case R_IMF_IMTYPE_PNG: return 1; } @@ -965,7 +965,7 @@ int BKE_imtype_supports_compress(const char imtype) int BKE_imtype_supports_quality(const char imtype) { - switch(imtype) { + switch (imtype) { case R_IMF_IMTYPE_JPEG90: case R_IMF_IMTYPE_JP2: case R_IMF_IMTYPE_AVIJPEG: @@ -979,7 +979,7 @@ char BKE_imtype_valid_channels(const char imtype) char chan_flag= IMA_CHAN_FLAG_RGB; /* assume all support rgb */ /* alpha */ - switch(imtype) { + switch (imtype) { case R_IMF_IMTYPE_TARGA: case R_IMF_IMTYPE_IRIS: case R_IMF_IMTYPE_PNG: @@ -995,7 +995,7 @@ char BKE_imtype_valid_channels(const char imtype) } /* bw */ - switch(imtype) { + switch (imtype) { case R_IMF_IMTYPE_PNG: case R_IMF_IMTYPE_JPEG90: case R_IMF_IMTYPE_TARGA: @@ -1110,8 +1110,11 @@ int BKE_add_image_extension(char *string, const char imtype) } #ifdef WITH_TIFF else if (imtype==R_IMF_IMTYPE_TIFF) { - if (!BLI_testextensie(string, ".tif") && - !BLI_testextensie(string, ".tiff")) extension= ".tif"; + if (!BLI_testextensie(string, ".tif") && + !BLI_testextensie(string, ".tiff")) + { + extension= ".tif"; + } } #endif #ifdef WITH_OPENEXR @@ -1791,7 +1794,7 @@ void BKE_image_signal(Image *ima, ImageUser *iuser, int signal) if (ima==NULL) return; - switch(signal) { + switch (signal) { case IMA_SIGNAL_FREE: image_free_buffers(ima); if (iuser) diff --git a/source/blender/blenkernel/intern/image_gen.c b/source/blender/blenkernel/intern/image_gen.c index 675c0771140..1441bd7b12b 100644 --- a/source/blender/blenkernel/intern/image_gen.c +++ b/source/blender/blenkernel/intern/image_gen.c @@ -169,12 +169,10 @@ static void checker_board_color_fill(unsigned char *rect, float *rect_float, int hue_step= power_of_2_max_i(width / 8); if (hue_step < 8) hue_step= 8; - for (y= 0; y < height; y++) - { + for (y= 0; y < height; y++) { val= 0.1 + (y * (0.4 / height)); /* use a number lower then 1.0 else its too bright */ - for (x= 0; x < width; x++) - { + for (x= 0; x < width; x++) { hue= (float)((double)(x/hue_step) * 1.0 / width * hue_step); hsv_to_rgb(hue, sat, val, &r, &g, &b); @@ -291,12 +289,10 @@ static void checker_board_text(unsigned char *rect, float *rect_float, int width BLF_buffer(mono, rect_float, rect, width, height, 4); - for (y= 0; y < height; y+=step) - { + for (y= 0; y < height; y+=step) { text[1]= '1'; - for (x= 0; x < width; x+=step) - { + for (x= 0; x < width; x+=step) { /* hard coded offset */ pen_x = x + 33; pen_y = y + 44; diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c index a4edc1e531a..b593419db9f 100644 --- a/source/blender/blenkernel/intern/implicit.c +++ b/source/blender/blenkernel/intern/implicit.c @@ -178,8 +178,7 @@ static void print_fvector(float m3[3]) DO_INLINE void print_lfvector(float (*fLongVector)[3], unsigned int verts) { unsigned int i = 0; - for (i = 0; i < verts; i++) - { + for (i = 0; i < verts; i++) { print_fvector(fLongVector[i]); } } @@ -193,8 +192,7 @@ DO_INLINE lfVector *create_lfvector(unsigned int verts) /* delete long vector */ DO_INLINE void del_lfvector(float (*fLongVector)[3]) { - if (fLongVector != NULL) - { + if (fLongVector != NULL) { MEM_freeN (fLongVector); // cloth_aligned_free(&MEMORY_BASE, fLongVector); } @@ -208,8 +206,7 @@ DO_INLINE void cp_lfvector(float (*to)[3], float (*from)[3], unsigned int verts) DO_INLINE void init_lfvector(float (*fLongVector)[3], float vector[3], unsigned int verts) { unsigned int i = 0; - for (i = 0; i < verts; i++) - { + for (i = 0; i < verts; i++) { copy_v3_v3(fLongVector[i], vector); } } @@ -223,8 +220,7 @@ DO_INLINE void mul_lfvectorS(float (*to)[3], float (*fLongVector)[3], float scal { unsigned int i = 0; - for (i = 0; i < verts; i++) - { + for (i = 0; i < verts; i++) { mul_fvector_S(to[i], fLongVector[i], scalar); } } @@ -233,8 +229,7 @@ DO_INLINE void mul_lfvectorS(float (*to)[3], float (*fLongVector)[3], float scal DO_INLINE void submul_lfvectorS(float (*to)[3], float (*fLongVector)[3], float scalar, unsigned int verts) { unsigned int i = 0; - for (i = 0; i < verts; i++) - { + for (i = 0; i < verts; i++) { VECSUBMUL(to[i], fLongVector[i], scalar); } } @@ -258,8 +253,7 @@ DO_INLINE void add_lfvector_lfvector(float (*to)[3], float (*fLongVectorA)[3], f { unsigned int i = 0; - for (i = 0; i < verts; i++) - { + for (i = 0; i < verts; i++) { VECADD(to[i], fLongVectorA[i], fLongVectorB[i]); } @@ -269,8 +263,7 @@ DO_INLINE void add_lfvector_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], { unsigned int i = 0; - for (i = 0; i < verts; i++) - { + for (i = 0; i < verts; i++) { VECADDS(to[i], fLongVectorA[i], fLongVectorB[i], bS); } @@ -280,8 +273,7 @@ DO_INLINE void add_lfvectorS_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], { unsigned int i = 0; - for (i = 0; i < verts; i++) - { + for (i = 0; i < verts; i++) { VECADDSS(to[i], fLongVectorA[i], aS, fLongVectorB[i], bS); } } @@ -289,8 +281,7 @@ DO_INLINE void add_lfvectorS_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], DO_INLINE void sub_lfvector_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], float (*fLongVectorB)[3], float bS, unsigned int verts) { unsigned int i = 0; - for (i = 0; i < verts; i++) - { + for (i = 0; i < verts; i++) { VECSUBS(to[i], fLongVectorA[i], fLongVectorB[i], bS); } @@ -300,8 +291,7 @@ DO_INLINE void sub_lfvector_lfvector(float (*to)[3], float (*fLongVectorA)[3], f { unsigned int i = 0; - for (i = 0; i < verts; i++) - { + for (i = 0; i < verts; i++) { sub_v3_v3v3(to[i], fLongVectorA[i], fLongVectorB[i]); } @@ -350,15 +340,12 @@ DO_INLINE void inverse_fmatrix(float to[3][3], float from[3][3]) unsigned int i, j; float d; - if ((d=det_fmatrix(from))==0) - { + if ((d=det_fmatrix(from)) == 0) { printf("can't build inverse"); exit(0); } - for (i=0;i<3;i++) - { - for (j=0;j<3;j++) - { + for (i=0;i<3;i++) { + for (j=0;j<3;j++) { int i1=(i+1)%3; int i2=(i+2)%3; int j1=(j+1)%3; @@ -535,8 +522,7 @@ DO_INLINE fmatrix3x3 *create_bfmatrix(unsigned int verts, unsigned int springs) /* delete big matrix */ DO_INLINE void del_bfmatrix(fmatrix3x3 *matrix) { - if (matrix != NULL) - { + if (matrix != NULL) { MEM_freeN (matrix); } } @@ -554,8 +540,7 @@ DO_INLINE void init_bfmatrix(fmatrix3x3 *matrix, float m3[3][3]) { unsigned int i; - for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) - { + for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) { cp_fmatrix(matrix[i].m, m3); } } @@ -567,12 +552,10 @@ DO_INLINE void initdiag_bfmatrix(fmatrix3x3 *matrix, float m3[3][3]) unsigned int i,j; float tmatrix[3][3] = {{0,0,0},{0,0,0},{0,0,0}}; - for (i = 0; i < matrix[0].vcount; i++) - { + for (i = 0; i < matrix[0].vcount; i++) { cp_fmatrix(matrix[i].m, m3); } - for (j = matrix[0].vcount; j < matrix[0].vcount+matrix[0].scount; j++) - { + for (j = matrix[0].vcount; j < matrix[0].vcount+matrix[0].scount; j++) { cp_fmatrix(matrix[j].m, tmatrix); } } @@ -581,8 +564,7 @@ DO_INLINE void initdiag_bfmatrix(fmatrix3x3 *matrix, float m3[3][3]) DO_INLINE void mul_bfmatrix_S(fmatrix3x3 *matrix, float scalar) { unsigned int i = 0; - for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) - { + for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) { mul_fmatrix_S(matrix[i].m, scalar); } } @@ -601,15 +583,13 @@ DO_INLINE void mul_bfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, lfVector { #pragma omp section { - for (i = from[0].vcount; i < from[0].vcount+from[0].scount; i++) - { + for (i = from[0].vcount; i < from[0].vcount+from[0].scount; i++) { muladd_fmatrix_fvector(to[from[i].c], from[i].m, fLongVector[from[i].r]); } } #pragma omp section { - for (i = 0; i < from[0].vcount+from[0].scount; i++) - { + for (i = 0; i < from[0].vcount+from[0].scount; i++) { muladd_fmatrix_fvector(temp[from[i].r], from[i].m, fLongVector[from[i].c]); } } @@ -627,8 +607,7 @@ DO_INLINE void mul_prevfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, lfVec { unsigned int i = 0; - for (i = 0; i < from[0].vcount; i++) - { + for (i = 0; i < from[0].vcount; i++) { mul_fmatrix_fvector(to[from[i].r], from[i].m, fLongVector[from[i].c]); } } @@ -639,8 +618,7 @@ DO_INLINE void add_bfmatrix_bfmatrix( fmatrix3x3 *to, fmatrix3x3 *from, fmatrix unsigned int i = 0; /* process diagonal elements */ - for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) - { + for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) { add_fmatrix_fmatrix(to[i].m, from[i].m, matrix[i].m); } @@ -651,8 +629,7 @@ DO_INLINE void addadd_bfmatrix_bfmatrix( fmatrix3x3 *to, fmatrix3x3 *from, fmat unsigned int i = 0; /* process diagonal elements */ - for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) - { + for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) { addadd_fmatrix_fmatrix(to[i].m, from[i].m, matrix[i].m); } @@ -663,8 +640,7 @@ DO_INLINE void subadd_bfmatrix_bfmatrix( fmatrix3x3 *to, fmatrix3x3 *from, fmat unsigned int i = 0; /* process diagonal elements */ - for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) - { + for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) { subadd_fmatrix_fmatrix(to[i].m, from[i].m, matrix[i].m); } @@ -675,8 +651,7 @@ DO_INLINE void sub_bfmatrix_bfmatrix( fmatrix3x3 *to, fmatrix3x3 *from, fmatrix unsigned int i = 0; /* process diagonal elements */ - for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) - { + for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) { sub_fmatrix_fmatrix(to[i].m, from[i].m, matrix[i].m); } @@ -687,8 +662,7 @@ DO_INLINE void sub_bfmatrix_Smatrix( fmatrix3x3 *to, fmatrix3x3 *from, fmatrix3 unsigned int i = 0; /* process diagonal elements */ - for (i = 0; i < matrix[0].vcount; i++) - { + for (i = 0; i < matrix[0].vcount; i++) { sub_fmatrix_fmatrix(to[matrix[i].c].m, from[matrix[i].c].m, matrix[i].m); } @@ -699,8 +673,7 @@ DO_INLINE void addsub_bfmatrix_bfmatrix( fmatrix3x3 *to, fmatrix3x3 *from, fmat unsigned int i = 0; /* process diagonal elements */ - for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) - { + for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) { addsub_fmatrix_fmatrix(to[i].m, from[i].m, matrix[i].m); } @@ -713,8 +686,7 @@ DO_INLINE void subadd_bfmatrixS_bfmatrixS( fmatrix3x3 *to, fmatrix3x3 *from, flo unsigned int i = 0; /* process diagonal elements */ - for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) - { + for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) { subadd_fmatrixS_fmatrixS(to[i].m, from[i].m, aS, matrix[i].m, bS); } @@ -772,12 +744,10 @@ int implicit_init (Object *UNUSED(ob), ClothModifierData *clmd) id->dV = create_lfvector(cloth->numverts); id->z = create_lfvector(cloth->numverts); - for (i=0;i<cloth->numverts;i++) - { + for (i=0;i<cloth->numverts;i++) { id->A[i].r = id->A[i].c = id->dFdV[i].r = id->dFdV[i].c = id->dFdX[i].r = id->dFdX[i].c = id->P[i].c = id->P[i].r = id->Pinv[i].c = id->Pinv[i].r = id->bigI[i].c = id->bigI[i].r = id->M[i].r = id->M[i].c = i; - if (verts [i].flags & CLOTH_VERT_FLAG_PINNED) - { + if (verts [i].flags & CLOTH_VERT_FLAG_PINNED) { id->S[pinned].pinned = 1; id->S[pinned].c = id->S[pinned].r = i; pinned++; @@ -791,8 +761,7 @@ int implicit_init (Object *UNUSED(ob), ClothModifierData *clmd) // init springs search = cloth->springs; - for (i=0;i<cloth->numsprings;i++) - { + for (i=0;i<cloth->numsprings;i++) { spring = search->link; // dFdV_start[i].r = big_I[i].r = big_zero[i].r = @@ -810,8 +779,7 @@ int implicit_init (Object *UNUSED(ob), ClothModifierData *clmd) initdiag_bfmatrix(id->bigI, I); - for (i = 0; i < cloth->numverts; i++) - { + for (i = 0; i < cloth->numverts; i++) { copy_v3_v3(id->X[i], verts[i].x); } @@ -823,12 +791,10 @@ int implicit_free (ClothModifierData *clmd) Cloth *cloth; cloth = (Cloth *)clmd->clothObject; - if (cloth) - { + if (cloth) { id = cloth->implicit; - if (id) - { + if (id) { del_bfmatrix(id->A); del_bfmatrix(id->dFdV); del_bfmatrix(id->dFdX); @@ -886,12 +852,10 @@ DO_INLINE float fbstar_jacobi(float length, float L, float kb, float cb) float tempfb = kb * fb(length, L); float fbstar = cb * (length - L); - if (tempfb < fbstar) - { + if (tempfb < fbstar) { return cb; } - else - { + else { return kb * fbderiv(length, L); } } @@ -900,8 +864,7 @@ DO_INLINE void filter(lfVector *V, fmatrix3x3 *S) { unsigned int i=0; - for (i=0;i<S[0].vcount;i++) - { + for (i = 0; i < S[0].vcount; i++) { mul_fvector_fmatrix(V[S[i].r], V[S[i].r], S[i].m); } } @@ -936,8 +899,7 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z s = dot_lfvector(r, r, numverts); starget = s * sqrt(conjgrad_epsilon); - while (s>starget && conjgrad_loopcount < conjgrad_looplimit) - { + while (s>starget && conjgrad_loopcount < conjgrad_looplimit) { // Mul(q,A,d); // q = A*d; mul_bfmatrix_lfvector(q, lA, d); @@ -979,8 +941,7 @@ DO_INLINE void BuildPPinv(fmatrix3x3 *lA, fmatrix3x3 *P, fmatrix3x3 *Pinv) // Take only the diagonal blocks of A // #pragma omp parallel for private(i) if (lA[0].vcount > CLOTH_OPENMP_LIMIT) - for (i = 0; i<lA[0].vcount; i++) - { + for (i = 0; i<lA[0].vcount; i++) { // block diagonalizer cp_fmatrix(P[i].m, lA[i].m); inverse_fmatrix(Pinv[i].m, P[i].m); @@ -1255,8 +1216,7 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, s->flags &= ~CLOTH_SPRING_FLAG_NEEDED; - if (length > ALMOST_ZERO) - { + if (length > ALMOST_ZERO) { /* if (length>L) { @@ -1270,16 +1230,13 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, */ mul_fvector_S(dir, extent, 1.0f/length); } - else - { + else { mul_fvector_S(dir, extent, 0.0f); } // calculate force of structural + shear springs - if ((s->type & CLOTH_SPRING_TYPE_STRUCTURAL) || (s->type & CLOTH_SPRING_TYPE_SHEAR)) - { - if (length > L || no_compress) - { + if ((s->type & CLOTH_SPRING_TYPE_STRUCTURAL) || (s->type & CLOTH_SPRING_TYPE_SHEAR)) { + if (length > L || no_compress) { s->flags |= CLOTH_SPRING_FLAG_NEEDED; k = clmd->sim_parms->structural; @@ -1337,10 +1294,8 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, // dfdx_spring(s->dfdx, dir, length, 0.0, k); // dfdv_damp(s->dfdv, dir, MIN2(1.0, (clmd->sim_parms->goalfrict/100.0))); } - else // calculate force of bending springs - { - if (length < L) - { + else { /* calculate force of bending springs */ + if (length < L) { s->flags |= CLOTH_SPRING_FLAG_NEEDED; k = clmd->sim_parms->bending; @@ -1358,10 +1313,8 @@ DO_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, DO_INLINE void cloth_apply_spring_force(ClothModifierData *UNUSED(clmd), ClothSpring *s, lfVector *lF, lfVector *UNUSED(X), lfVector *UNUSED(V), fmatrix3x3 *dFdV, fmatrix3x3 *dFdX) { - if (s->flags & CLOTH_SPRING_FLAG_NEEDED) - { - if (!(s->type & CLOTH_SPRING_TYPE_BENDING)) - { + if (s->flags & CLOTH_SPRING_FLAG_NEEDED) { + if (!(s->type & CLOTH_SPRING_TYPE_BENDING)) { sub_fmatrix_fmatrix(dFdV[s->ij].m, dFdV[s->ij].m, s->dfdv); sub_fmatrix_fmatrix(dFdV[s->kl].m, dFdV[s->kl].m, s->dfdv); add_fmatrix_fmatrix(dFdV[s->matrix_index].m, dFdV[s->matrix_index].m, s->dfdv); @@ -1486,8 +1439,7 @@ static void hair_velocity_smoothing(ClothModifierData *clmd, lfVector *lF, lfVec } /* gather colliders */ - if (colliders && collfac > 0.0f) for (col = colliders->first; col; col = col->next) - { + if (colliders && collfac > 0.0f) for (col = colliders->first; col; col = col->next) { MVert *loc0 = col->collmd->x; MVert *loc1 = col->collmd->xnew; float vel[3]; @@ -1593,8 +1545,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), lfVec /* multiply lF with mass matrix * force = mass * acceleration (in this case: gravity) */ - for (i = 0; i < numverts; i++) - { + for (i = 0; i < numverts; i++) { float temp[3]; copy_v3_v3(temp, lF[i]); mul_fmatrix_fvector(lF[i], M[i].m, temp); @@ -1603,8 +1554,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), lfVec submul_lfvectorS(lF, lV, spring_air, numverts); /* handle external forces like wind */ - if (effectors) - { + if (effectors) { // 0 = force, 1 = normalized force winvec = create_lfvector(cloth->numverts); @@ -1612,14 +1562,12 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), lfVec printf("winvec: out of memory in implicit.c\n"); // precalculate wind forces - for (i = 0; i < cloth->numverts; i++) - { + for (i = 0; i < cloth->numverts; i++) { pd_point_from_loc(clmd->scene, (float*)lX[i], (float*)lV[i], i, &epoint); pdDoEffectors(effectors, NULL, clmd->sim_parms->effector_weights, &epoint, winvec[i], NULL); } - for (i = 0; i < cloth->numfaces; i++) - { + for (i = 0; i < cloth->numfaces; i++) { float trinormal[3]={0,0,0}; // normalized triangle normal float triunnormal[3]={0,0,0}; // not-normalized-triangle normal float tmp[3]={0,0,0}; @@ -1650,8 +1598,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), lfVec VECADDS(lF[mfaces[i].v3], lF[mfaces[i].v3], tmp, factor); // add wind from v4 - if (mfaces[i].v4) - { + if (mfaces[i].v4) { copy_v3_v3(tmp, trinormal); mul_v3_fl(tmp, calculateVertexWindForce(winvec[mfaces[i].v4], triunnormal)); VECADDS(lF[mfaces[i].v4], lF[mfaces[i].v4], tmp, factor); @@ -1692,8 +1639,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), lfVec // calculate spring forces search = cloth->springs; - while (search) - { + while (search) { // only handle active springs // if (((clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED) && !(springs[i].flags & CSPRING_FLAG_DEACTIVATE))|| !(clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED)) {} cloth_calc_spring_force(clmd, search->link, lF, lX, lV, dFdV, dFdX, time); @@ -1703,8 +1649,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), lfVec // apply spring forces search = cloth->springs; - while (search) - { + while (search) { // only handle active springs // if (((clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED) && !(springs[i].flags & CSPRING_FLAG_DEACTIVATE))|| !(clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED)) cloth_apply_spring_force(clmd, search->link, lF, lX, lV, dFdV, dFdX); @@ -1836,21 +1781,17 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase Implicit_Data *id = cloth->implicit; int do_extra_solve; - if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) /* do goal stuff */ - { - for (i = 0; i < numverts; i++) - { + if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) { /* do goal stuff */ + for (i = 0; i < numverts; i++) { // update velocities with constrained velocities from pinned verts - if (verts [i].flags & CLOTH_VERT_FLAG_PINNED) - { + if (verts [i].flags & CLOTH_VERT_FLAG_PINNED) { sub_v3_v3v3(id->V[i], verts[i].xconst, verts[i].xold); // mul_v3_fl(id->V[i], clmd->sim_parms->stepsPerFrame); } } } - while (step < tf) - { + while (step < tf) { // damping velocity for artistic reasons mul_lfvectorS(id->V, id->V, clmd->sim_parms->vel_damping, numverts); @@ -1864,13 +1805,10 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase add_lfvector_lfvectorS(id->Xnew, id->X, id->Vnew, dt, numverts); /* move pinned verts to correct position */ - for (i = 0; i < numverts; i++) - { - if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) - { - if (verts [i].flags & CLOTH_VERT_FLAG_PINNED) - { - float tvect[3] = {.0,.0,.0}; + for (i = 0; i < numverts; i++) { + if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) { + if (verts[i].flags & CLOTH_VERT_FLAG_PINNED) { + float tvect[3] = {0.0f, 0.0f, 0.0f}; sub_v3_v3v3(tvect, verts[i].xconst, verts[i].xold); mul_fvector_S(tvect, tvect, step+dt); VECADD(tvect, tvect, verts[i].xold); @@ -1881,14 +1819,12 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase copy_v3_v3(verts[i].txold, id->X[i]); } - if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED && clmd->clothObject->bvhtree) - { + if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED && clmd->clothObject->bvhtree) { // collisions // itstart(); // update verts to current positions - for (i = 0; i < numverts; i++) - { + for (i = 0; i < numverts; i++) { copy_v3_v3(verts[i].tx, id->Xnew[i]); sub_v3_v3v3(verts[i].tv, verts[i].tx, verts[i].txold); @@ -1904,8 +1840,7 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase do_extra_solve = cloth_bvh_objcollision(ob, clmd, step/clmd->sim_parms->timescale, dt/clmd->sim_parms->timescale); // copy corrected positions back to simulation - for (i = 0; i < numverts; i++) - { + for (i = 0; i < numverts; i++) { // correct velocity again, just to be sure we had to change it due to adaptive collisions sub_v3_v3v3(verts[i].tv, verts[i].tx, id->X[i]); } @@ -1913,11 +1848,9 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase //if (do_extra_solve) // cloth_calc_helper_forces(ob, clmd, initial_cos, step/clmd->sim_parms->timescale, dt/clmd->sim_parms->timescale); - for (i = 0; i < numverts; i++) - { + for (i = 0; i < numverts; i++) { - if (do_extra_solve) - { + if (do_extra_solve) { if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) && (verts [i].flags & CLOTH_VERT_FLAG_PINNED)) continue; @@ -1933,8 +1866,7 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase // if there were collisions, advance the velocity from v_n+1/2 to v_n+1 - if (do_extra_solve) - { + if (do_extra_solve) { // V = Vnew; cp_lfvector(id->V, id->Vnew, numverts); @@ -1944,8 +1876,7 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase simulate_implicit_euler(id->Vnew, id->X, id->V, id->F, id->dFdV, id->dFdX, dt / 2.0f, id->A, id->B, id->dV, id->S, id->z, id->olddV, id->P, id->Pinv, id->M, id->bigI); } } - else - { + else { // X = Xnew; cp_lfvector(id->X, id->Xnew, numverts); } @@ -1959,16 +1890,13 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase step += dt; } - for (i = 0; i < numverts; i++) - { - if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) && (verts [i].flags & CLOTH_VERT_FLAG_PINNED)) - { + for (i = 0; i < numverts; i++) { + if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) && (verts [i].flags & CLOTH_VERT_FLAG_PINNED)) { copy_v3_v3(verts[i].txold, verts[i].xconst); // TODO: test --> should be .x copy_v3_v3(verts[i].x, verts[i].xconst); copy_v3_v3(verts[i].v, id->V[i]); } - else - { + else { copy_v3_v3(verts[i].txold, id->X[i]); copy_v3_v3(verts[i].x, id->X[i]); copy_v3_v3(verts[i].v, id->V[i]); @@ -1987,8 +1915,7 @@ void implicit_set_positions (ClothModifierData *clmd) unsigned int numverts = cloth->numverts, i; Implicit_Data *id = cloth->implicit; - for (i = 0; i < numverts; i++) - { + for (i = 0; i < numverts; i++) { copy_v3_v3(id->X[i], verts[i].x); copy_v3_v3(id->V[i], verts[i].v); } diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 2fd1d291363..c33bb973385 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -1906,7 +1906,7 @@ void do_versions_ipos_to_animato(Main *main) AnimData *adt= BKE_id_add_animdata(id); - SEQ_BEGIN(ed, seq) { + SEQ_BEGIN (ed, seq) { IpoCurve *icu = (seq->ipo) ? seq->ipo->curve.first : NULL; short adrcode = SEQ_FAC1; diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 0a1c0467244..54a2613991a 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -1594,7 +1594,7 @@ void curve_to_key(Curve *cu, KeyBlock *kb, ListBase *nurb) int a, tot; /* count */ - tot = count_curveverts(nurb); + tot = BKE_nurbList_verts_count(nurb); if (tot == 0) return; if (kb->data) MEM_freeN(kb->data); @@ -1647,7 +1647,7 @@ void key_to_curve(KeyBlock *kb, Curve *UNUSED(cu), ListBase *nurb) nu = nurb->first; fp = kb->data; - tot = count_curveverts(nurb); + tot = BKE_nurbList_verts_count(nurb); tot = MIN2(kb->totelem, tot); @@ -1742,7 +1742,7 @@ float (*key_to_vertcos(Object * ob, KeyBlock * kb))[3] } else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { Curve *cu = (Curve *)ob->data; - tot = count_curveverts(&cu->nurb); + tot = BKE_nurbList_verts_count(&cu->nurb); } if (tot == 0) return NULL; @@ -1822,7 +1822,7 @@ void vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3]) else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { Curve *cu = (Curve *)ob->data; elemsize = cu->key->elemsize; - tot = count_curveverts(&cu->nurb); + tot = BKE_nurbList_verts_count(&cu->nurb); } if (tot == 0) { diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index f182d7bcb7c..12f11a9dee1 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -342,7 +342,7 @@ void init_latt_deform(Object *oblatt, Object *ob) } } -void calc_latt_deform(Object *ob, float *co, float weight) +void calc_latt_deform(Object *ob, float co[3], float weight) { Lattice *lt= ob->data; float u, v, w, tu[4], tv[4], tw[4]; diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 7e756e853b1..71266275fbd 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -182,7 +182,7 @@ int id_make_local(ID *id, int test) if (id->flag & LIB_INDIRECT) return 0; - switch(GS(id->name)) { + switch (GS(id->name)) { case ID_SCE: return 0; /* not implemented */ case ID_LI: @@ -198,12 +198,12 @@ int id_make_local(ID *id, int test) return 1; case ID_CU: if (!test) { - make_local_curve((Curve*)id); + BKE_curve_make_local((Curve*)id); make_local_key(((Curve*)id)->key); } return 1; case ID_MB: - if (!test) make_local_mball((MetaBall*)id); + if (!test) BKE_metaball_make_local((MetaBall*)id); return 1; case ID_MA: if (!test) make_local_material((Material*)id); @@ -279,7 +279,7 @@ int id_copy(ID *id, ID **newid, int test) /* conventions: * - make shallow copy, only this ID block * - id.us of the new ID is set to 1 */ - switch(GS(id->name)) { + switch (GS(id->name)) { case ID_SCE: return 0; /* can't be copied from here */ case ID_LI: @@ -291,10 +291,10 @@ int id_copy(ID *id, ID **newid, int test) if (!test) *newid= (ID*)copy_mesh((Mesh*)id); return 1; case ID_CU: - if (!test) *newid= (ID*)copy_curve((Curve*)id); + if (!test) *newid= (ID*)BKE_curve_copy((Curve*)id); return 1; case ID_MB: - if (!test) *newid= (ID*)copy_mball((MetaBall*)id); + if (!test) *newid= (ID*)BKE_metaball_copy((MetaBall*)id); return 1; case ID_MA: if (!test) *newid= (ID*)copy_material((Material*)id); @@ -368,7 +368,7 @@ int id_unlink(ID *id, int test) Main *mainlib= G.main; ListBase *lb; - switch(GS(id->name)) { + switch (GS(id->name)) { case ID_TXT: if (test) return 1; unlink_text(mainlib, (Text*)id); @@ -425,7 +425,7 @@ int id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) ListBase *which_libbase(Main *mainlib, short type) { - switch( type ) { + switch ( type ) { case ID_SCE: return &(mainlib->scene); case ID_LI: @@ -589,7 +589,7 @@ static ID *alloc_libblock_notest(short type) { ID *id= NULL; - switch( type ) { + switch ( type ) { case ID_SCE: id= MEM_callocN(sizeof(Scene), "scene"); break; @@ -796,7 +796,7 @@ void free_libblock(ListBase *lb, void *idv) BPY_id_release(id); #endif - switch( GS(id->name) ) { /* GetShort from util.h */ + switch ( GS(id->name) ) { /* GetShort from util.h */ case ID_SCE: free_scene((Scene *)id); break; @@ -810,10 +810,10 @@ void free_libblock(ListBase *lb, void *idv) free_mesh((Mesh *)id, 1); break; case ID_CU: - free_curve((Curve *)id); + BKE_curve_free((Curve *)id); break; case ID_MB: - free_mball((MetaBall *)id); + BKE_metaball_free((MetaBall *)id); break; case ID_MA: free_material((Material *)id); @@ -886,7 +886,7 @@ void free_libblock(ListBase *lb, void *idv) free_gpencil_data((bGPdata *)id); break; case ID_MC: - free_movieclip((MovieClip *)id); + BKE_movieclip_free((MovieClip *)id); break; } @@ -1010,8 +1010,7 @@ static void IDnames_to_dyn_pupstring(DynStr *pupds, ListBase *lb, ID *link, shor BLI_dynstr_append(pupds, numstr); /* icon */ - switch(GS(id->name)) - { + switch (GS(id->name)) { case ID_MA: /* fall through */ case ID_TE: /* fall through */ case ID_IM: /* fall through */ diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 6d44282c60a..2dfd41f299a 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -493,7 +493,7 @@ short *give_totcolp(Object *ob) /* same as above but for ID's */ Material ***give_matarar_id(ID *id) { - switch(GS(id->name)) { + switch (GS(id->name)) { case ID_ME: return &(((Mesh *)id)->mat); break; @@ -509,7 +509,7 @@ Material ***give_matarar_id(ID *id) short *give_totcolp_id(ID *id) { - switch(GS(id->name)) { + switch (GS(id->name)) { case ID_ME: return &(((Mesh *)id)->totcol); break; @@ -525,12 +525,12 @@ short *give_totcolp_id(ID *id) static void data_delete_material_index_id(ID *id, short index) { - switch(GS(id->name)) { + switch (GS(id->name)) { case ID_ME: mesh_delete_material_index((Mesh *)id, index); break; case ID_CU: - curve_delete_material_index((Curve *)id, index); + BKE_curve_delete_material_index((Curve *)id, index); break; case ID_MB: /* meta-elems don't have materials atm */ diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index c06d796d562..73e3576b57f 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -65,6 +65,106 @@ #include "BKE_object.h" #include "BKE_material.h" +/* Data types */ + +typedef struct point { /* a three-dimensional point */ + float x, y, z; /* its coordinates */ +} MB_POINT; + +typedef struct vertex { /* surface vertex */ + MB_POINT position, normal; /* position and surface normal */ +} VERTEX; + +typedef struct vertices { /* list of vertices in polygonization */ + int count, max; /* # vertices, max # allowed */ + VERTEX *ptr; /* dynamically allocated */ +} VERTICES; + +typedef struct corner { /* corner of a cube */ + int i, j, k; /* (i, j, k) is index within lattice */ + float x, y, z, value; /* location and function value */ + struct corner *next; +} CORNER; + +typedef struct cube { /* partitioning cell (cube) */ + int i, j, k; /* lattice location of cube */ + CORNER *corners[8]; /* eight corners */ +} CUBE; + +typedef struct cubes { /* linked list of cubes acting as stack */ + CUBE cube; /* a single cube */ + struct cubes *next; /* remaining elements */ +} CUBES; + +typedef struct centerlist { /* list of cube locations */ + int i, j, k; /* cube location */ + struct centerlist *next; /* remaining elements */ +} CENTERLIST; + +typedef struct edgelist { /* list of edges */ + int i1, j1, k1, i2, j2, k2; /* edge corner ids */ + int vid; /* vertex id */ + struct edgelist *next; /* remaining elements */ +} EDGELIST; + +typedef struct intlist { /* list of integers */ + int i; /* an integer */ + struct intlist *next; /* remaining elements */ +} INTLIST; + +typedef struct intlists { /* list of list of integers */ + INTLIST *list; /* a list of integers */ + struct intlists *next; /* remaining elements */ +} INTLISTS; + +typedef struct process { /* parameters, function, storage */ + /* what happens here? floats, I think. */ + /* float (*function)(void); */ /* implicit surface function */ + float (*function)(float, float, float); + float size, delta; /* cube size, normal delta */ + int bounds; /* cube range within lattice */ + CUBES *cubes; /* active cubes */ + VERTICES vertices; /* surface vertices */ + CENTERLIST **centers; /* cube center hash table */ + CORNER **corners; /* corner value hash table */ + EDGELIST **edges; /* edge and vertex id hash table */ +} PROCESS; + +/* dividing scene using octal tree makes polygonisation faster */ +typedef struct ml_pointer { + struct ml_pointer *next, *prev; + struct MetaElem *ml; +} ml_pointer; + +typedef struct octal_node { + struct octal_node *nodes[8]; /* children of current node */ + struct octal_node *parent; /* parent of current node */ + struct ListBase elems; /* ListBase of MetaElem pointers (ml_pointer) */ + float x_min, y_min, z_min; /* 1st border point */ + float x_max, y_max, z_max; /* 7th border point */ + float x,y,z; /* center of node */ + int pos, neg; /* number of positive and negative MetaElements in the node */ + int count; /* number of MetaElems, which belongs to the node */ +} octal_node; + +typedef struct octal_tree { + struct octal_node *first; /* first node */ + int pos, neg; /* number of positive and negative MetaElements in the scene */ + short depth; /* number of scene subdivision */ +} octal_tree; + +struct pgn_elements { + struct pgn_elements *next, *prev; + char *data; +}; + +/* Forward declarations */ +static int vertid(CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb); +static int setcenter(CENTERLIST *table[], int i, int j, int k); +static CORNER *setcorner(PROCESS* p, int i, int j, int k); +static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, + float (*function)(float, float, float), MB_POINT *p, MetaBall *mb, int f); + /* Global variables */ static float thresh= 0.6f; @@ -73,7 +173,7 @@ static MetaElem **mainb; static octal_tree *metaball_tree = NULL; /* Functions */ -void unlink_mball(MetaBall *mb) +void BKE_metaball_unlink(MetaBall *mb) { int a; @@ -85,9 +185,9 @@ void unlink_mball(MetaBall *mb) /* do not free mball itself */ -void free_mball(MetaBall *mb) +void BKE_metaball_free(MetaBall *mb) { - unlink_mball(mb); + BKE_metaball_unlink(mb); if (mb->adt) { BKE_free_animdata((ID *)mb); @@ -99,7 +199,7 @@ void free_mball(MetaBall *mb) if (mb->disp.first) freedisplist(&mb->disp); } -MetaBall *add_mball(const char *name) +MetaBall *BKE_metaball_add(const char *name) { MetaBall *mb; @@ -115,7 +215,7 @@ MetaBall *add_mball(const char *name) return mb; } -MetaBall *copy_mball(MetaBall *mb) +MetaBall *BKE_metaball_copy(MetaBall *mb) { MetaBall *mbn; int a; @@ -143,7 +243,7 @@ static void extern_local_mball(MetaBall *mb) } } -void make_local_mball(MetaBall *mb) +void BKE_metaball_make_local(MetaBall *mb) { Main *bmain= G.main; Object *ob; @@ -174,7 +274,7 @@ void make_local_mball(MetaBall *mb) extern_local_mball(mb); } else if (is_local && is_lib) { - MetaBall *mb_new= copy_mball(mb); + MetaBall *mb_new= BKE_metaball_copy(mb); mb_new->id.us= 0; /* Remap paths of new ID using old library as base. */ @@ -194,7 +294,7 @@ void make_local_mball(MetaBall *mb) /* most simple meta-element adding function * don't do context manipulation here (rna uses) */ -MetaElem *add_metaball_element(MetaBall *mb, const int type) +MetaElem *BKE_metaball_element_add(MetaBall *mb, const int type) { MetaElem *ml= MEM_callocN(sizeof(MetaElem), "metaelem"); @@ -204,7 +304,7 @@ MetaElem *add_metaball_element(MetaBall *mb, const int type) ml->s= 2.0; ml->flag= MB_SCALE_RAD; - switch(type) { + switch (type) { case MB_BALL: ml->type = MB_BALL; ml->expx= ml->expy= ml->expz= 1.0; @@ -246,7 +346,7 @@ MetaElem *add_metaball_element(MetaBall *mb, const int type) * basic MetaBall (usually with name Meta). All other MetaBalls (with * names Meta.001, Meta.002, etc) are included in this Bounding Box. */ -void tex_space_mball(Object *ob) +void BKE_metaball_tex_space_calc(Object *ob) { DispList *dl; BoundBox *bb; @@ -290,7 +390,7 @@ void tex_space_mball(Object *ob) boundbox_set_from_min_max(bb, min, max); } -float *make_orco_mball(Object *ob, ListBase *dispbase) +float *BKE_metaball_make_orco(Object *ob, ListBase *dispbase) { BoundBox *bb; DispList *dl; @@ -342,7 +442,7 @@ float *make_orco_mball(Object *ob, ListBase *dispbase) * It test last character of Object ID name. If last character * is digit it return 0, else it return 1. */ -int is_basis_mball(Object *ob) +int BKE_metaball_is_basis(Object *ob) { int len; @@ -353,7 +453,7 @@ int is_basis_mball(Object *ob) } /* return nonzero if ob1 is a basis mball for ob */ -int is_mball_basis_for (Object *ob1, Object *ob2) +int BKE_metaball_is_basis_for (Object *ob1, Object *ob2) { int basis1nr, basis2nr; char basis1name[MAX_ID_NAME], basis2name[MAX_ID_NAME]; @@ -361,7 +461,7 @@ int is_mball_basis_for (Object *ob1, Object *ob2) BLI_split_name_num(basis1name, &basis1nr, ob1->id.name+2, '.'); BLI_split_name_num(basis2name, &basis2nr, ob2->id.name+2, '.'); - if (!strcmp(basis1name, basis2name)) return is_basis_mball(ob1); + if (!strcmp(basis1name, basis2name)) return BKE_metaball_is_basis(ob1); else return 0; } @@ -371,7 +471,7 @@ int is_mball_basis_for (Object *ob1, Object *ob2) * are copied to all metaballs in same "group" (metaballs with same base name: MBall, * MBall.001, MBall.002, etc). The most important is to copy properties to the base metaball, * because this metaball influence polygonisation of metaballs. */ -void copy_mball_properties(Scene *scene, Object *active_object) +void BKE_metaball_properties_copy(Scene *scene, Object *active_object) { Scene *sce_iter= scene; Base *base; @@ -416,7 +516,7 @@ void copy_mball_properties(Scene *scene, Object *active_object) * * warning!, is_basis_mball() can fail on returned object, see long note above. */ -Object *find_basis_mball(Scene *scene, Object *basis) +Object *BKE_metaball_basis_find(Scene *scene, Object *basis) { Scene *sce_iter= scene; Base *base; @@ -522,14 +622,14 @@ Object *find_basis_mball(Scene *scene, Object *basis) /* **************** POLYGONIZATION ************************ */ -void calc_mballco(MetaElem *ml, float vec[3]) +static void calc_mballco(MetaElem *ml, float vec[3]) { if (ml->mat) { mul_m4_v3((float (*)[4])ml->mat, vec); } } -float densfunc(MetaElem *ball, float x, float y, float z) +static float densfunc(MetaElem *ball, float x, float y, float z) { float dist2 = 0.0, dx, dy, dz; float vec[3]; @@ -605,7 +705,7 @@ float densfunc(MetaElem *ball, float x, float y, float z) } } -octal_node* find_metaball_octal_node(octal_node *node, float x, float y, float z, short depth) +static octal_node* find_metaball_octal_node(octal_node *node, float x, float y, float z, short depth) { if (!depth) return node; @@ -673,7 +773,7 @@ octal_node* find_metaball_octal_node(octal_node *node, float x, float y, float z return node; } -float metaball(float x, float y, float z) +static float metaball(float x, float y, float z) /* float x, y, z; */ { struct octal_node *node; @@ -713,7 +813,7 @@ static int *indices=NULL; static int totindex, curindex; -void accum_mballfaces(int i1, int i2, int i3, int i4) +static void accum_mballfaces(int i1, int i2, int i3, int i4) { int *newi, *cur; /* static int i=0; I would like to delete altogether, but I don't dare to, yet */ @@ -746,7 +846,7 @@ void accum_mballfaces(int i1, int i2, int i3, int i4) } /* ******************* MEMORY MANAGEMENT *********************** */ -void *new_pgn_element(int size) +static void *new_pgn_element(int size) { /* during polygonize 1000s of elements are allocated * and never freed in between. Freeing only done at the end. @@ -789,7 +889,7 @@ void *new_pgn_element(int size) return cur->data; } -void freepolygonize(PROCESS *p) +static void freepolygonize(PROCESS *p) { MEM_freeN(p->corners); MEM_freeN(p->edges); @@ -832,7 +932,7 @@ static int rightface[12] = { /* docube: triangulate the cube directly, without decomposition */ -void docube(CUBE *cube, PROCESS *p, MetaBall *mb) +static void docube(CUBE *cube, PROCESS *p, MetaBall *mb) { INTLISTS *polys; CORNER *c1, *c2; @@ -853,7 +953,7 @@ void docube(CUBE *cube, PROCESS *p, MetaBall *mb) count++; } if (count>2) { - switch(count) { + switch (count) { case 3: accum_mballfaces(indexar[2], indexar[1], indexar[0], 0); break; @@ -900,7 +1000,7 @@ void docube(CUBE *cube, PROCESS *p, MetaBall *mb) * if surface crosses face, compute other four corners of adjacent cube * and add new cube to cube stack */ -void testface(int i, int j, int k, CUBE* old, int bit, int c1, int c2, int c3, int c4, PROCESS *p) +static void testface(int i, int j, int k, CUBE* old, int bit, int c1, int c2, int c3, int c4, PROCESS *p) { CUBE newc; CUBES *oldcubes = p->cubes; @@ -951,7 +1051,7 @@ void testface(int i, int j, int k, CUBE* old, int bit, int c1, int c2, int c3, i /* setcorner: return corner with the given lattice location * set (and cache) its function value */ -CORNER *setcorner (PROCESS* p, int i, int j, int k) +static CORNER *setcorner (PROCESS* p, int i, int j, int k) { /* for speed, do corner value caching here */ CORNER *c; @@ -986,7 +1086,7 @@ CORNER *setcorner (PROCESS* p, int i, int j, int k) /* nextcwedge: return next clockwise edge from given edge around given face */ -int nextcwedge (int edge, int face) +static int nextcwedge (int edge, int face) { switch (edge) { case LB: @@ -1020,7 +1120,7 @@ int nextcwedge (int edge, int face) /* otherface: return face adjoining edge that is not the given face */ -int otherface (int edge, int face) +static int otherface (int edge, int face) { int other = leftface[edge]; return face == other? rightface[edge] : other; @@ -1029,7 +1129,7 @@ int otherface (int edge, int face) /* makecubetable: create the 256 entry table for cubical polygonization */ -void makecubetable (void) +static void makecubetable (void) { static int isdone= 0; int i, e, c, done[12], pos[8]; @@ -1070,7 +1170,7 @@ void makecubetable (void) } } -void BKE_freecubetable(void) +void BKE_metaball_cubeTable_free(void) { int i; INTLISTS *lists, *nlists; @@ -1100,7 +1200,7 @@ void BKE_freecubetable(void) /* setcenter: set (i,j,k) entry of table[] * return 1 if already set; otherwise, set and return 0 */ -int setcenter(CENTERLIST *table[], int i, int j, int k) +static int setcenter(CENTERLIST *table[], int i, int j, int k) { int index; CENTERLIST *newc, *l, *q; @@ -1125,7 +1225,7 @@ int setcenter(CENTERLIST *table[], int i, int j, int k) /* setedge: set vertex id for edge */ -void setedge (EDGELIST *table[], +static void setedge (EDGELIST *table[], int i1, int j1, int k1, int i2, int j2, int k2, @@ -1161,7 +1261,7 @@ void setedge (EDGELIST *table[], /* getedge: return vertex id for edge; return -1 if not set */ -int getedge (EDGELIST *table[], +static int getedge (EDGELIST *table[], int i1, int j1, int k1, int i2, int j2, int k2) { @@ -1179,10 +1279,13 @@ int getedge (EDGELIST *table[], k2=t; } q = table[HASH(i1, j1, k1)+HASH(i2, j2, k2)]; - for (; q != NULL; q = q->next) + for (; q != NULL; q = q->next) { if (q->i1 == i1 && q->j1 == j1 && q->k1 == k1 && q->i2 == i2 && q->j2 == j2 && q->k2 == k2) + { return q->vid; + } + } return -1; } @@ -1199,7 +1302,7 @@ int getedge (EDGELIST *table[], /* addtovertices: add v to sequence of vertices */ -void addtovertices (VERTICES *vertices, VERTEX v) +static void addtovertices (VERTICES *vertices, VERTEX v) { if (vertices->count == vertices->max) { int i; @@ -1217,7 +1320,7 @@ void addtovertices (VERTICES *vertices, VERTEX v) /* vnormal: compute unit length surface normal at point */ -void vnormal (MB_POINT *point, PROCESS *p, MB_POINT *v) +static void vnormal (MB_POINT *point, PROCESS *p, MB_POINT *v) { float delta= 0.2f*p->delta; float f = p->function(point->x, point->y, point->z); @@ -1267,7 +1370,7 @@ void vnormal (MB_POINT *point, PROCESS *p, MB_POINT *v) } -int vertid (CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb) +static int vertid (CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb) { VERTEX v; MB_POINT a, b; @@ -1296,7 +1399,7 @@ int vertid (CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb) /* converge: from two points of differing sign, converge to zero crossing */ /* watch it: p1 and p2 are used to calculate */ -void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, +static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, float (*function)(float, float, float), MB_POINT *p, MetaBall *mb, int f) { int i = 0; @@ -1396,7 +1499,7 @@ void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, } /* ************************************** */ -void add_cube(PROCESS *mbproc, int i, int j, int k, int count) +static void add_cube(PROCESS *mbproc, int i, int j, int k, int count) { CUBES *ncube; int n; @@ -1426,7 +1529,7 @@ void add_cube(PROCESS *mbproc, int i, int j, int k, int count) } -void find_first_points(PROCESS *mbproc, MetaBall *mb, int a) +static void find_first_points(PROCESS *mbproc, MetaBall *mb, int a) { MB_POINT IN, in, OUT, out; /*point;*/ MetaElem *ml; @@ -1546,7 +1649,7 @@ void find_first_points(PROCESS *mbproc, MetaBall *mb, int a) } } -void polygonize(PROCESS *mbproc, MetaBall *mb) +static void polygonize(PROCESS *mbproc, MetaBall *mb) { CUBE c; int a; @@ -1586,7 +1689,7 @@ void polygonize(PROCESS *mbproc, MetaBall *mb) } } -float init_meta(Scene *scene, Object *ob) /* return totsize */ +static float init_meta(Scene *scene, Object *ob) /* return totsize */ { Scene *sce_iter= scene; Base *base; @@ -1812,7 +1915,7 @@ float init_meta(Scene *scene, Object *ob) /* return totsize */ /* if MetaElem lies in node, then node includes MetaElem pointer (ml_p) * pointing at MetaElem (ml) */ -void fill_metaball_octal_node(octal_node *node, MetaElem *ml, short i) +static void fill_metaball_octal_node(octal_node *node, MetaElem *ml, short i) { ml_pointer *ml_p; @@ -1844,7 +1947,7 @@ void fill_metaball_octal_node(octal_node *node, MetaElem *ml, short i) * +------+------+ * */ -void subdivide_metaball_octal_node(octal_node *node, float size_x, float size_y, float size_z, short depth) +static void subdivide_metaball_octal_node(octal_node *node, float size_x, float size_y, float size_z, short depth) { MetaElem *ml; ml_pointer *ml_p; @@ -2101,7 +2204,7 @@ void subdivide_metaball_octal_node(octal_node *node, float size_x, float size_y, } /* free all octal nodes recursively */ -void free_metaball_octal_node(octal_node *node) +static void free_metaball_octal_node(octal_node *node) { int a; for (a=0;a<8;a++) { @@ -2112,7 +2215,7 @@ void free_metaball_octal_node(octal_node *node) } /* If scene include more then one MetaElem, then octree is used */ -void init_metaball_octal_tree(int depth) +static void init_metaball_octal_tree(int depth) { struct octal_node *node; ml_pointer *ml_p; @@ -2170,7 +2273,7 @@ void init_metaball_octal_tree(int depth) subdivide_metaball_octal_node(node, size[0], size[1], size[2], metaball_tree->depth); } -void metaball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) +void BKE_metaball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) { PROCESS mbproc; MetaBall *mb; diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 514380dc980..c7f6bf93831 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -128,18 +128,22 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 CustomDataLayer *l1, *l2; int i, i1=0, i2=0, tot, j; - for (i=0; i<c1->totlayer; i++) { - if (ELEM7(c1->layers[i].type, CD_MVERT, CD_MEDGE, CD_MPOLY, - CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT)) + for (i = 0; i < c1->totlayer; i++) { + if (ELEM7(c1->layers[i].type, CD_MVERT, CD_MEDGE, CD_MPOLY, + CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT)) + { i1++; + } } - - for (i=0; i<c2->totlayer; i++) { - if (ELEM7(c2->layers[i].type, CD_MVERT, CD_MEDGE, CD_MPOLY, - CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT)) + + for (i = 0; i < c2->totlayer; i++) { + if (ELEM7(c2->layers[i].type, CD_MVERT, CD_MEDGE, CD_MPOLY, + CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT)) + { i2++; + } } - + if (i1 != i2) return MESHCMP_CDLAYERS_MISMATCH; @@ -148,12 +152,16 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 i1 = 0; i2 = 0; for (i=0; i < tot; i++) { while (i1 < c1->totlayer && !ELEM7(l1->type, CD_MVERT, CD_MEDGE, CD_MPOLY, - CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT)) + CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT)) + { i1++, l1++; + } - while (i2 < c2->totlayer && !ELEM7(l2->type, CD_MVERT, CD_MEDGE, CD_MPOLY, - CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT)) + while (i2 < c2->totlayer && !ELEM7(l2->type, CD_MVERT, CD_MEDGE, CD_MPOLY, + CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT)) + { i2++, l2++; + } if (l1->type == CD_MVERT) { MVert *v1 = l1->data; @@ -1128,7 +1136,7 @@ void mesh_strip_loose_edges(Mesh *me) MEdge *e; MLoop *l; int a, b; - unsigned int *new_idx = MEM_mallocN(sizeof(int) * me->totedge, "strip_loose_edges old2new idx mapping for loops."); + unsigned int *new_idx = MEM_mallocN(sizeof(int) * me->totedge, __func__); for (a = b = 0, e = me->medge; a < me->totedge; a++, e++) { if (e->v1 != e->v2) { @@ -1154,6 +1162,8 @@ void mesh_strip_loose_edges(Mesh *me) for (a = 0, l = me->mloop; a < me->totloop; a++, l++) { l->e = new_idx[l->e]; } + + MEM_freeN(new_idx); } void mball_to_mesh(ListBase *lb, Mesh *me) @@ -1606,7 +1616,7 @@ void mesh_to_curve(Scene *scene, Object *ob) BLI_edgehash_free(eh, NULL); if (edges.first) { - Curve *cu = add_curve(ob->id.name+2, OB_CURVE); + Curve *cu = BKE_curve_add(ob->id.name+2, OB_CURVE); cu->flag |= CU_3D; while (edges.first) { @@ -1865,8 +1875,8 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys, BLI_array_empty(vertcos); BLI_array_empty(vertnos); - BLI_array_growitems(vertcos, mp->totloop); - BLI_array_growitems(vertnos, mp->totloop); + BLI_array_grow_items(vertcos, mp->totloop); + BLI_array_grow_items(vertnos, mp->totloop); for (j=0; j < mp->totloop; j++) { int vindex = ml[j].v; @@ -1875,7 +1885,7 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys, } BLI_array_empty(edgevecbuf); - BLI_array_growitems(edgevecbuf, mp->totloop); + BLI_array_grow_items(edgevecbuf, mp->totloop); accumulate_vertex_normals_poly(vertnos, pnors[i], vertcos, edgevecbuf, mp->totloop); } @@ -2412,8 +2422,8 @@ int mesh_recalcTessellation(CustomData *fdata, #ifdef USE_TESSFACE_SPEEDUP #define ML_TO_MF(i1, i2, i3) \ - BLI_array_growone(mface_to_poly_map); \ - BLI_array_growone(mface); \ + BLI_array_grow_one(mface_to_poly_map); \ + BLI_array_grow_one(mface); \ mface_to_poly_map[mface_index] = poly_index; \ mf= &mface[mface_index]; \ /* set loop indices, transformed to vert indices later */ \ @@ -2431,8 +2441,8 @@ int mesh_recalcTessellation(CustomData *fdata, /* ALMOST IDENTICAL TO DEFINE ABOVE (see EXCEPTION) */ #define ML_TO_MF_QUAD() \ - BLI_array_growone(mface_to_poly_map); \ - BLI_array_growone(mface); \ + BLI_array_grow_one(mface_to_poly_map); \ + BLI_array_grow_one(mface); \ mface_to_poly_map[mface_index] = poly_index; \ mf= &mface[mface_index]; \ /* set loop indices, transformed to vert indices later */ \ @@ -2490,10 +2500,10 @@ int mesh_recalcTessellation(CustomData *fdata, totfilltri = BLI_edgefill(&sf_ctx, FALSE); if (totfilltri) { - BLI_array_growitems(mface_to_poly_map, totfilltri); - BLI_array_growitems(mface, totfilltri); + BLI_array_grow_items(mface_to_poly_map, totfilltri); + BLI_array_grow_items(mface, totfilltri); if (poly_orig_index) { - BLI_array_growitems(mface_orig_index, totfilltri); + BLI_array_grow_items(mface_orig_index, totfilltri); } for (f = sf_ctx.fillfacebase.first; f; f = f->next, mf++) { @@ -2662,7 +2672,7 @@ int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, k = 0; for (i = 0; i<totpoly; i++, mp++) { if (ELEM(mp->totloop, 3, 4)) { - BLI_array_growone(mface); + BLI_array_grow_one(mface); mf = &mface[k]; mf->mat_nr = mp->mat_nr; @@ -3052,10 +3062,13 @@ void mesh_flush_hidden_from_verts(const MVert *mvert, for (i = 0; i < totedge; i++) { MEdge *e = &medge[i]; if (mvert[e->v1].flag & ME_HIDE || - mvert[e->v2].flag & ME_HIDE) + mvert[e->v2].flag & ME_HIDE) + { e->flag |= ME_HIDE; - else + } + else { e->flag &= ~ME_HIDE; + } } for (i = 0; i < totpoly; i++) { MPoly *p = &mpoly[i]; diff --git a/source/blender/blenkernel/intern/modifiers_bmesh.c b/source/blender/blenkernel/intern/modifiers_bmesh.c index 573b8a725b3..99bb3468320 100644 --- a/source/blender/blenkernel/intern/modifiers_bmesh.c +++ b/source/blender/blenkernel/intern/modifiers_bmesh.c @@ -117,8 +117,8 @@ void DM_to_bmesh_ex(DerivedMesh *dm, BMesh *bm) BLI_array_empty(verts); BLI_array_empty(edges); - BLI_array_growitems(verts, mp->totloop); - BLI_array_growitems(edges, mp->totloop); + BLI_array_grow_items(verts, mp->totloop); + BLI_array_grow_items(edges, mp->totloop); ml = mloop + mp->loopstart; for (j = 0; j < mp->totloop; j++, ml++) { diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 9a640bcb8eb..d548d7589bb 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -450,7 +450,7 @@ static MovieClip *movieclip_alloc(const char *name) * otherwise creates new. * does not load ibuf itself * pass on optional frame for #name images */ -MovieClip *BKE_add_movieclip_file(const char *name) +MovieClip *BKE_movieclip_file_add(const char *name) { MovieClip *clip; MovieClipUser user; @@ -517,7 +517,7 @@ static void real_ibuf_size(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, in *height = ibuf->y; if (clip->flag & MCLIP_USE_PROXY) { - switch(user->render_size) { + switch (user->render_size) { case MCLIP_PROXY_RENDER_SIZE_25: (*width) *= 4; (*height) *= 4; @@ -925,8 +925,8 @@ void BKE_movieclip_get_size(MovieClip *clip, MovieClipUser *user, int *width, in real_ibuf_size(clip, user, ibuf, width, height); } else { - *width = 0; - *height = 0; + *width = clip->lastsize[0]; + *height = clip->lastsize[1]; } if (ibuf) @@ -1149,14 +1149,14 @@ void BKE_movieclip_build_proxy_frame(MovieClip *clip, int clip_flag, struct Movi } } -void free_movieclip(MovieClip *clip) +void BKE_movieclip_free(MovieClip *clip) { free_buffers(clip); BKE_tracking_free(&clip->tracking); } -void unlink_movieclip(Main *bmain, MovieClip *clip) +void BKE_movieclip_unlink(Main *bmain, MovieClip *clip) { bScreen *scr; ScrArea *area; diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 7580f2eee4d..d7212e5eaf9 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -835,7 +835,7 @@ static void multires_subdivide(MultiresModifierData *mmd, Object *ob, int totlvl MDisps *mdisps; int lvl= mmd->totlvl; - if (totlvl > multires_max_levels) + if ((totlvl > multires_max_levels) || (me->totpoly == 0)) return; multires_force_update(ob); @@ -1017,7 +1017,7 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm column_vectors_to_mat3(mat, tx, ty, no); - switch(op) { + switch (op) { case APPLY_DISPLACEMENTS: /* Convert displacement to object space * and add to grid points */ diff --git a/source/blender/blenkernel/intern/navmesh_conversion.c b/source/blender/blenkernel/intern/navmesh_conversion.c index 34e0be1de92..23d2f50c3f7 100644 --- a/source/blender/blenkernel/intern/navmesh_conversion.c +++ b/source/blender/blenkernel/intern/navmesh_conversion.c @@ -57,8 +57,7 @@ BLI_INLINE int left(const float* a, const float* b, const float* c) int polyNumVerts(const unsigned short* p, const int vertsPerPoly) { int i, nv = 0; - for (i=0; i<vertsPerPoly; i++) - { + for (i=0; i<vertsPerPoly; i++) { if (p[i]==0xffff) break; nv++; @@ -71,8 +70,7 @@ int polyIsConvex(const unsigned short* p, const int vertsPerPoly, const float* v int j, nv = polyNumVerts(p, vertsPerPoly); if (nv<3) return 0; - for (j=0; j<nv; j++) - { + for (j=0; j<nv; j++) { const float* v = &verts[3*p[j]]; const float* v_next = &verts[3*p[(j+1)%nv]]; const float* v_prev = &verts[3*p[(nv+j-1)%nv]]; @@ -119,8 +117,7 @@ int buildRawVertIndicesData(DerivedMesh* dm, int *nverts_r, float **verts_r, MFace *faces; nverts = dm->getNumVerts(dm); - if (nverts>=0xffff) - { + if (nverts>=0xffff) { printf("Converting navmesh: Error! Too many vertices. Max number of vertices %d\n", 0xffff); return 0; } @@ -128,8 +125,7 @@ int buildRawVertIndicesData(DerivedMesh* dm, int *nverts_r, float **verts_r, dm->getVertCos(dm, (float(*)[3])verts); //flip coordinates - for (vi=0; vi<nverts; vi++) - { + for (vi=0; vi<nverts; vi++) { SWAP(float, verts[3*vi+1], verts[3*vi+2]); } @@ -137,8 +133,7 @@ int buildRawVertIndicesData(DerivedMesh* dm, int *nverts_r, float **verts_r, nfaces = dm->getNumTessFaces(dm); faces = dm->getTessFaceArray(dm); ntris = nfaces; - for (fi=0; fi<nfaces; fi++) - { + for (fi=0; fi<nfaces; fi++) { MFace* face = &faces[fi]; if (face->v4) ntris++; @@ -149,15 +144,13 @@ int buildRawVertIndicesData(DerivedMesh* dm, int *nverts_r, float **verts_r, tris = MEM_callocN(sizeof(unsigned short)*3*ntris, "buildRawVertIndicesData tris"); tri = tris; triIdx = 0; - for (fi=0; fi<nfaces; fi++) - { + for (fi=0; fi<nfaces; fi++) { MFace* face = &faces[fi]; tri[3*triIdx+0] = (unsigned short) face->v1; tri[3*triIdx+1] = (unsigned short) face->v3; tri[3*triIdx+2] = (unsigned short) face->v2; trisToFacesMap[triIdx++]=fi; - if (face->v4) - { + if (face->v4) { tri[3*triIdx+0] = (unsigned short) face->v1; tri[3*triIdx+1] = (unsigned short) face->v4; tri[3*triIdx+2] = (unsigned short) face->v3; @@ -187,8 +180,7 @@ int buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, unsigned short* newPoly = MEM_callocN(sizeof(unsigned short)*capacity, "buildPolygonsByDetailedMeshes newPoly"); memset(newPoly, 0xff, sizeof(unsigned short)*capacity); - for (polyidx=0; polyidx<npolys; polyidx++) - { + for (polyidx=0; polyidx<npolys; polyidx++) { size_t i; int j, k; int nv = 0; @@ -202,22 +194,18 @@ int buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, int adjustedNv; int allBorderTraversed; - for (j=0; j<dtrisNum && btri==-1;j++) - { + for (j=0; j<dtrisNum && btri==-1;j++) { int curpolytri = dtrisBase+j; - for (k=0; k<3; k++) - { + for (k=0; k<3; k++) { unsigned short neighbortri = dtris[curpolytri*3*2+3+k]; - if ( neighbortri==0xffff || dtrisToPolysMap[neighbortri]!=polyidx+1) - { + if ( neighbortri==0xffff || dtrisToPolysMap[neighbortri]!=polyidx+1) { btri = curpolytri; bedge = k; break; } } } - if (btri==-1 || bedge==-1) - { + if (btri==-1 || bedge==-1) { //can't find triangle with border edge MEM_freeN(traversedTris); MEM_freeN(newPoly); @@ -229,13 +217,10 @@ int buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, tri = btri; edge = (bedge+1)%3; traversedTris[tri-dtrisBase] = 1; - while (tri!=btri || edge!=bedge) - { + while (tri != btri || edge != bedge) { int neighbortri = dtris[tri*3*2+3+edge]; - if (neighbortri==0xffff || dtrisToPolysMap[neighbortri]!=polyidx+1) - { - if (nv==capacity) - { + if (neighbortri==0xffff || dtrisToPolysMap[neighbortri]!=polyidx+1) { + if (nv==capacity) { unsigned short* newPolyBig; capacity += vertsPerPoly; newPolyBig = MEM_callocN(sizeof(unsigned short)*capacity, "buildPolygonsByDetailedMeshes newPolyBig"); @@ -251,16 +236,13 @@ int buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, else { //move to next tri int twinedge = -1; - for (k=0; k<3; k++) - { - if (dtris[neighbortri*3*2+3+k] == tri) - { + for (k=0; k<3; k++) { + if (dtris[neighbortri*3*2+3+k] == tri) { twinedge = k; break; } } - if (twinedge==-1) - { + if (twinedge==-1) { printf("Converting navmesh: Error! Can't find neighbor edge - invalid adjacency info\n"); MEM_freeN(traversedTris); goto returnLabel; @@ -273,8 +255,7 @@ int buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, adjustedPoly = MEM_callocN(sizeof(unsigned short)*nv, "buildPolygonsByDetailedMeshes adjustedPoly"); adjustedNv = 0; - for (i=0; i<nv; i++) - { + for (i=0; i<nv; i++) { unsigned short prev = newPoly[(nv+i-1)%nv]; unsigned short cur = newPoly[i]; unsigned short next = newPoly[(i+1)%nv]; @@ -288,17 +269,13 @@ int buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, nv = adjustedNv; allBorderTraversed = 1; - for (i=0; i<dtrisNum; i++) - { - if (traversedTris[i]==0) - { + for (i=0; i<dtrisNum; i++) { + if (traversedTris[i]==0) { //check whether it has border edges int curpolytri = dtrisBase+i; - for (k=0; k<3; k++) - { + for (k=0; k<3; k++) { unsigned short neighbortri = dtris[curpolytri*3*2+3+k]; - if ( neighbortri==0xffff || dtrisToPolysMap[neighbortri]!=polyidx+1) - { + if ( neighbortri==0xffff || dtrisToPolysMap[neighbortri]!=polyidx+1) { allBorderTraversed = 0; break; } @@ -306,10 +283,8 @@ int buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, } } - if (nv<=vertsPerPoly && allBorderTraversed) - { - for (i=0; i<nv; i++) - { + if (nv<=vertsPerPoly && allBorderTraversed) { + for (i=0; i<nv; i++) { polys[polyidx*vertsPerPoly*2+i] = newPoly[i]; } } @@ -353,8 +328,7 @@ int buildNavMeshData(const int nverts, const float* verts, unsigned short *dtris, *dmeshes, *polys; int *dtrisToPolysMap, *dtrisToTrisMap; - if (!recastData) - { + if (!recastData) { printf("Converting navmesh: Error! Can't find recast custom data\n"); return 0; } @@ -370,17 +344,14 @@ int buildNavMeshData(const int nverts, const float* verts, //search first valid triangle - triangle of convex polygon validTriStart = -1; - for (i=0; i< ntris; i++) - { - if (recastData[trisToFacesMap[trisMapping[i]]]>0) - { + for (i=0; i< ntris; i++) { + if (recastData[trisToFacesMap[trisMapping[i]]]>0) { validTriStart = i; break; } } - if (validTriStart<0) - { + if (validTriStart<0) { printf("Converting navmesh: Error! No valid polygons in mesh\n"); MEM_freeN(trisMapping); return 0; @@ -396,8 +367,7 @@ int buildNavMeshData(const int nverts, const float* verts, //and reserve memory for adjacency info dtris = MEM_callocN(sizeof(unsigned short)*3*2*ndtris, "buildNavMeshData dtris"); memset(dtris, 0xffff, sizeof(unsigned short)*3*2*ndtris); - for (i=0; i<ndtris; i++) - { + for (i=0; i<ndtris; i++) { memcpy(dtris+3*2*i, tris+3*dtrisToTrisMap[i], sizeof(unsigned short)*3); } @@ -405,11 +375,9 @@ int buildNavMeshData(const int nverts, const float* verts, prevPolyIdx = -1; newPolyIdx = 0; dtrisToPolysMap = MEM_callocN(sizeof(int)*ndtris, "buildNavMeshData dtrisToPolysMap"); - for (i=0; i<ndtris; i++) - { + for (i=0; i<ndtris; i++) { curPolyIdx = recastData[trisToFacesMap[dtrisToTrisMap[i]]]; - if (curPolyIdx!=prevPolyIdx) - { + if (curPolyIdx!=prevPolyIdx) { newPolyIdx++; prevPolyIdx=curPolyIdx; } @@ -426,13 +394,10 @@ int buildNavMeshData(const int nverts, const float* verts, memset(dmeshes, 0, npolys*4*sizeof(unsigned short)); dmesh = NULL; prevpolyidx = 0; - for (i=0; i<ndtris; i++) - { + for (i=0; i<ndtris; i++) { int curpolyidx = dtrisToPolysMap[i]; - if (curpolyidx!=prevpolyidx) - { - if (curpolyidx!=prevpolyidx+1) - { + if (curpolyidx!=prevpolyidx) { + if (curpolyidx!=prevpolyidx+1) { printf("Converting navmesh: Error! Wrong order of detailed mesh faces\n"); return 0; } @@ -476,8 +441,7 @@ int buildNavMeshDataByDerivedMesh(DerivedMesh *dm, int *vertsPerPoly, unsigned short *tris=NULL; res = buildRawVertIndicesData(dm, nverts, verts, &ntris, &tris, trisToFacesMap, &recastData); - if (!res) - { + if (!res) { printf("Converting navmesh: Error! Can't get vertices and indices from mesh\n"); goto exit; } @@ -485,8 +449,7 @@ int buildNavMeshDataByDerivedMesh(DerivedMesh *dm, int *vertsPerPoly, res = buildNavMeshData(*nverts, *verts, ntris, tris, recastData, *trisToFacesMap, ndtris, dtris, npolys, dmeshes,polys, vertsPerPoly, dtrisToPolysMap, dtrisToTrisMap); - if (!res) - { + if (!res) { printf("Converting navmesh: Error! Can't get vertices and indices from mesh\n"); goto exit; } @@ -501,12 +464,10 @@ exit: int polyFindVertex(const unsigned short* p, const int vertsPerPoly, unsigned short vertexIdx) { int i, res = -1; - for (i=0; i<vertsPerPoly; i++) - { + for (i=0; i<vertsPerPoly; i++) { if (p[i]==0xffff) break; - if (p[i]==vertexIdx) - { + if (p[i] == vertexIdx) { res = i; break; } diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 56fec119cce..5dfeb37b2ee 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -357,7 +357,7 @@ NlaStrip *add_nla_soundstrip (Scene *scene, Speaker *speaker) strip->end = (float)ceil((double)info.length * FPS); } - else + else #endif { strip->end = 10.0f; @@ -373,7 +373,7 @@ NlaStrip *add_nla_soundstrip (Scene *scene, Speaker *speaker) strip->extendmode = NLASTRIP_EXTEND_NOTHING; /* nothing to extend... */ /* strip should be referenced as-is */ - strip->scale= 1.0f; + strip->scale = 1.0f; strip->repeat = 1.0f; /* return this strip */ diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 07b2728ba1d..5e025b986c2 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -319,8 +319,8 @@ void free_object(Object *ob) id->us--; if (id->us==0) { if (ob->type==OB_MESH) unlink_mesh(ob->data); - else if (ob->type==OB_CURVE) unlink_curve(ob->data); - else if (ob->type==OB_MBALL) unlink_mball(ob->data); + else if (ob->type==OB_CURVE) BKE_curve_unlink(ob->data); + else if (ob->type==OB_MBALL) BKE_metaball_unlink(ob->data); } ob->data= NULL; } @@ -459,7 +459,7 @@ void unlink_object(Object *ob) } } else if (ELEM(OB_MBALL, ob->type, obt->type)) { - if (is_mball_basis_for (obt, ob)) + if (BKE_metaball_is_basis_for (obt, ob)) obt->recalc|= OB_RECALC_DATA; } @@ -625,10 +625,11 @@ void unlink_object(Object *ob) #endif if (sce->ed) { Sequence *seq; - SEQ_BEGIN(sce->ed, seq) - if (seq->scene_camera==ob) { - seq->scene_camera= NULL; + SEQ_BEGIN (sce->ed, seq) { + if (seq->scene_camera == ob) { + seq->scene_camera = NULL; } + } SEQ_END } } @@ -748,10 +749,10 @@ static void *add_obdata_from_type(int type) { switch (type) { case OB_MESH: return add_mesh("Mesh"); - case OB_CURVE: return add_curve("Curve", OB_CURVE); - case OB_SURF: return add_curve("Surf", OB_SURF); - case OB_FONT: return add_curve("Text", OB_FONT); - case OB_MBALL: return add_mball("Meta"); + case OB_CURVE: return BKE_curve_add("Curve", OB_CURVE); + case OB_SURF: return BKE_curve_add("Surf", OB_SURF); + case OB_FONT: return BKE_curve_add("Text", OB_FONT); + case OB_MBALL: return BKE_metaball_add("Meta"); case OB_CAMERA: return add_camera("Camera"); case OB_LAMP: return add_lamp("Lamp"); case OB_LATTICE: return add_lattice("Lattice"); @@ -1484,7 +1485,7 @@ void object_rot_to_mat3(Object *ob, float mat[][3]) void object_mat3_to_rot(Object *ob, float mat[][3], short use_compat) { - switch(ob->rotmode) { + switch (ob->rotmode) { case ROT_MODE_QUAT: { float dquat[4]; @@ -1822,7 +1823,7 @@ static void give_parvert(Object *par, int nr, float vec[3]) ListBase *nurbs; cu= par->data; - nurbs= BKE_curve_nurbs(cu); + nurbs= BKE_curve_nurbs_get(cu); nu= nurbs->first; count= 0; @@ -2026,7 +2027,7 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[ if (ob->partype & PARSLOW) copy_m4_m4(slowmat, obmat); - switch(ob->partype & PARTYPE) { + switch (ob->partype & PARTYPE) { case PAROBJECT: ok= 0; if (par->type==OB_CURVE) { @@ -2261,14 +2262,14 @@ void minmax_object(Object *ob, float min[3], float max[3]) int a; short change= FALSE; - switch(ob->type) { + switch (ob->type) { case OB_CURVE: case OB_FONT: case OB_SURF: { Curve *cu= ob->data; - if (cu->bb==NULL) tex_space_curve(cu); + if (cu->bb==NULL) BKE_curve_tex_space_calc(cu); bb= *(cu->bb); for (a=0; a<8; a++) { @@ -2569,7 +2570,7 @@ void object_handle_update(Scene *scene, Object *ob) } /* includes all keys and modifiers */ - switch(ob->type) { + switch (ob->type) { case OB_MESH: { #if 0 // XXX, comment for 2.56a release, background wont set 'scene->customdata_mask' @@ -2785,8 +2786,7 @@ int ray_hit_boundbox(struct BoundBox *bb, float ray_start[3], float ray_normal[3 int result = 0; int i; - for (i = 0; i < 12 && result == 0; i++) - { + for (i = 0; i < 12 && result == 0; i++) { float lambda; int v1, v2, v3; v1 = triangle_indexes[i][0]; @@ -2813,8 +2813,7 @@ int object_insert_ptcache(Object *ob) BLI_sortlist(&ob->pc_ids, pc_cmp); - for (link=ob->pc_ids.first, i = 0; link; link=link->next, i++) - { + for (link=ob->pc_ids.first, i = 0; link; link=link->next, i++) { int index = GET_INT_FROM_POINTER(link->data); if (i < index) @@ -2932,7 +2931,7 @@ static KeyBlock *insert_curvekey(Scene *scene, Object *ob, const char *name, int Curve *cu= ob->data; Key *key= cu->key; KeyBlock *kb; - ListBase *lb= BKE_curve_nurbs(cu); + ListBase *lb= BKE_curve_nurbs_get(cu); int newkey= 0; if (key==NULL) { @@ -2959,7 +2958,7 @@ static KeyBlock *insert_curvekey(Scene *scene, Object *ob, const char *name, int /* create new block with prepared data */ kb = add_keyblock_ctime(key, name, FALSE); - kb->totelem= count_curveverts(lb); + kb->totelem= BKE_nurbList_verts_count(lb); kb->data= data; } diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index 907de7888cb..5ba1b3d86c3 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -196,15 +196,13 @@ static float Ph(struct Ocean* o, float kx,float kz ) float tmp; float k2 = kx*kx + kz*kz; - if (k2 == 0.0f) - { + if (k2 == 0.0f) { return 0.0f; // no DC component } // damp out the waves going in the direction opposite the wind tmp = (o->_wx * kx + o->_wz * kz)/sqrtf(k2); - if (tmp < 0) - { + if (tmp < 0) { tmp *= o->_damp_reflections; } @@ -421,18 +419,15 @@ void BKE_ocean_eval_uv_catrom(struct Ocean *oc, struct OceanResult *ocr, float u frac_z) { - if (oc->_do_disp_y) - { + if (oc->_do_disp_y) { ocr->disp[1] = INTERP(oc->_disp_y); } - if (oc->_do_normals) - { + if (oc->_do_normals) { ocr->normal[0] = INTERP(oc->_N_x); ocr->normal[1] = oc->_N_y/*INTERP(oc->_N_y) (MEM01)*/; ocr->normal[2] = INTERP(oc->_N_z); } - if (oc->_do_chop) - { + if (oc->_do_chop) { ocr->disp[0] = INTERP(oc->_disp_x); ocr->disp[2] = INTERP(oc->_disp_z); } @@ -441,8 +436,7 @@ void BKE_ocean_eval_uv_catrom(struct Ocean *oc, struct OceanResult *ocr, float u ocr->disp[2] = 0.0; } - if (oc->_do_jacobian) - { + if (oc->_do_jacobian) { compute_eigenstuff(ocr, INTERP(oc->_Jxx),INTERP(oc->_Jzz),INTERP(oc->_Jxz)); } } @@ -474,8 +468,7 @@ void BKE_ocean_eval_ij(struct Ocean *oc, struct OceanResult *ocr, int i,int j) ocr->disp[1] = oc->_do_disp_y ? oc->_disp_y[i*oc->_N+j] : 0.0f; - if (oc->_do_chop) - { + if (oc->_do_chop) { ocr->disp[0] = oc->_disp_x[i*oc->_N+j]; ocr->disp[2] = oc->_disp_z[i*oc->_N+j]; } @@ -484,8 +477,7 @@ void BKE_ocean_eval_ij(struct Ocean *oc, struct OceanResult *ocr, int i,int j) ocr->disp[2] = 0.0f; } - if (oc->_do_normals) - { + if (oc->_do_normals) { ocr->normal[0] = oc->_N_x[i*oc->_N+j]; ocr->normal[1] = oc->_N_y/*oc->_N_y[i*oc->_N+j] (MEM01)*/; ocr->normal[2] = oc->_N_z[i*oc->_N+j]; @@ -493,8 +485,7 @@ void BKE_ocean_eval_ij(struct Ocean *oc, struct OceanResult *ocr, int i,int j) normalize_v3(ocr->normal); } - if (oc->_do_jacobian) - { + if (oc->_do_jacobian) { compute_eigenstuff(ocr, oc->_Jxx[i*oc->_N+j],oc->_Jzz[i*oc->_N+j],oc->_Jxz[i*oc->_N+j]); } @@ -511,12 +502,10 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount // compute a new htilda #pragma omp parallel for private(i, j) - for (i = 0 ; i < o->_M ; ++i) - { + for (i = 0 ; i < o->_M ; ++i) { // note the <= _N/2 here, see the fftw doco about // the mechanics of the complex->real fft storage - for ( j = 0 ; j <= o->_N / 2 ; ++j) - { + for ( j = 0 ; j <= o->_N / 2 ; ++j) { fftw_complex exp_param1; fftw_complex exp_param2; fftw_complex conj_param; @@ -541,8 +530,7 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount #pragma omp section { - if (o->_do_disp_y) - { + if (o->_do_disp_y) { // y displacement fftw_execute(o->_disp_y_plan); } @@ -550,13 +538,10 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount #pragma omp section { - if (o->_do_chop) - { + if (o->_do_chop) { // x displacement - for ( i = 0 ; i < o->_M ; ++i) - { - for ( j = 0 ; j <= o->_N / 2 ; ++j) - { + for ( i = 0 ; i < o->_M ; ++i) { + for ( j = 0 ; j <= o->_N / 2 ; ++j) { fftw_complex mul_param; fftw_complex minus_i; @@ -575,13 +560,10 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount #pragma omp section { - if (o->_do_chop) - { + if (o->_do_chop) { // z displacement - for ( i = 0 ; i < o->_M ; ++i) - { - for ( j = 0 ; j <= o->_N / 2 ; ++j) - { + for ( i = 0 ; i < o->_M ; ++i) { + for ( j = 0 ; j <= o->_N / 2 ; ++j) { fftw_complex mul_param; fftw_complex minus_i; @@ -600,13 +582,10 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount #pragma omp section { - if (o->_do_jacobian) - { + if (o->_do_jacobian) { // Jxx - for ( i = 0 ; i < o->_M ; ++i) - { - for ( j = 0 ; j <= o->_N / 2 ; ++j) - { + for ( i = 0 ; i < o->_M ; ++i) { + for ( j = 0 ; j <= o->_N / 2 ; ++j) { fftw_complex mul_param; //init_complex(mul_param, -scale, 0); @@ -620,10 +599,8 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount } fftw_execute(o->_Jxx_plan); - for ( i = 0 ; i < o->_M ; ++i) - { - for ( j = 0 ; j < o->_N ; ++j) - { + for ( i = 0 ; i < o->_M ; ++i) { + for ( j = 0 ; j < o->_N ; ++j) { o->_Jxx[i*o->_N+j] += 1.0; } } @@ -632,13 +609,10 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount #pragma omp section { - if (o->_do_jacobian) - { + if (o->_do_jacobian) { // Jzz - for ( i = 0 ; i < o->_M ; ++i) - { - for ( j = 0 ; j <= o->_N / 2 ; ++j) - { + for ( i = 0 ; i < o->_M ; ++i) { + for ( j = 0 ; j <= o->_N / 2 ; ++j) { fftw_complex mul_param; //init_complex(mul_param, -scale, 0); @@ -651,10 +625,8 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount } } fftw_execute(o->_Jzz_plan); - for ( i = 0 ; i < o->_M ; ++i) - { - for ( j = 0 ; j < o->_N ; ++j) - { + for ( i = 0 ; i < o->_M ; ++i) { + for ( j = 0 ; j < o->_N ; ++j) { o->_Jzz[i*o->_N+j] += 1.0; } } @@ -663,13 +635,10 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount #pragma omp section { - if (o->_do_jacobian) - { + if (o->_do_jacobian) { // Jxz - for ( i = 0 ; i < o->_M ; ++i) - { - for ( j = 0 ; j <= o->_N / 2 ; ++j) - { + for ( i = 0 ; i < o->_M ; ++i) { + for ( j = 0 ; j <= o->_N / 2 ; ++j) { fftw_complex mul_param; //init_complex(mul_param, -scale, 0); @@ -688,12 +657,9 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount #pragma omp section { // fft normals - if (o->_do_normals) - { - for ( i = 0 ; i < o->_M ; ++i) - { - for ( j = 0 ; j <= o->_N / 2 ; ++j) - { + if (o->_do_normals) { + for ( i = 0 ; i < o->_M ; ++i) { + for ( j = 0 ; j <= o->_N / 2 ; ++j) { fftw_complex mul_param; init_complex(mul_param, 0.0, -1.0); @@ -709,12 +675,9 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount #pragma omp section { - if (o->_do_normals) - { - for ( i = 0 ; i < o->_M ; ++i) - { - for ( j = 0 ; j <= o->_N / 2 ; ++j) - { + if (o->_do_normals) { + for ( i = 0 ; i < o->_M ; ++i) { + for ( j = 0 ; j <= o->_N / 2 ; ++j) { fftw_complex mul_param; init_complex(mul_param, 0.0, -1.0); @@ -757,12 +720,9 @@ static void set_height_normalize_factor(struct Ocean *oc) BLI_rw_mutex_lock(&oc->oceanmutex, THREAD_LOCK_READ); - for (i = 0; i < oc->_M; ++i) - { - for (j = 0; j < oc->_N; ++j) - { - if ( max_h < fabsf(oc->_disp_y[i*oc->_N+j])) - { + for (i = 0; i < oc->_M; ++i) { + for (j = 0; j < oc->_N; ++j) { + if ( max_h < fabsf(oc->_disp_y[i*oc->_N+j])) { max_h = fabsf(oc->_disp_y[i*oc->_N+j]); } } @@ -851,10 +811,8 @@ void BKE_init_ocean(struct Ocean* o, int M,int N, float Lx, float Lz, float V, f /*srand(seed);*/ BLI_srand(seed); - for (i = 0 ; i < o->_M ; ++i) - { - for (j = 0 ; j < o->_N ; ++j) - { + for (i = 0 ; i < o->_M ; ++i) { + for (j = 0 ; j < o->_N ; ++j) { float r1 = gaussRand(); float r2 = gaussRand(); @@ -921,14 +879,12 @@ void BKE_free_ocean_data(struct Ocean *oc) BLI_rw_mutex_lock(&oc->oceanmutex, THREAD_LOCK_WRITE); - if (oc->_do_disp_y) - { + if (oc->_do_disp_y) { fftw_destroy_plan(oc->_disp_y_plan); MEM_freeN(oc->_disp_y); } - if (oc->_do_normals) - { + if (oc->_do_normals) { MEM_freeN(oc->_fft_in_nx); MEM_freeN(oc->_fft_in_nz); fftw_destroy_plan(oc->_N_x_plan); @@ -938,8 +894,7 @@ void BKE_free_ocean_data(struct Ocean *oc) MEM_freeN(oc->_N_z); } - if (oc->_do_chop) - { + if (oc->_do_chop) { MEM_freeN(oc->_fft_in_x); MEM_freeN(oc->_fft_in_z); fftw_destroy_plan(oc->_disp_x_plan); @@ -948,8 +903,7 @@ void BKE_free_ocean_data(struct Ocean *oc) MEM_freeN(oc->_disp_z); } - if (oc->_do_jacobian) - { + if (oc->_do_jacobian) { MEM_freeN(oc->_fft_in_jxx); MEM_freeN(oc->_fft_in_jzz); MEM_freeN(oc->_fft_in_jxz); @@ -1002,7 +956,7 @@ static void cache_filename(char *string, const char *path, const char *relbase, char cachepath[FILE_MAX]; const char *fname; - switch(type) { + switch (type) { case CACHE_TYPE_FOAM: fname= "foam_"; break; @@ -1043,8 +997,7 @@ void BKE_free_ocean_cache(struct OceanCache *och) if (!och) return; if (och->ibufs_disp) { - for (i=och->start, f=0; i<=och->end; i++, f++) - { + for (i=och->start, f=0; i<=och->end; i++, f++) { if (och->ibufs_disp[f]) { IMB_freeImBuf(och->ibufs_disp[f]); } @@ -1053,8 +1006,7 @@ void BKE_free_ocean_cache(struct OceanCache *och) } if (och->ibufs_foam) { - for (i=och->start, f=0; i<=och->end; i++, f++) - { + for (i=och->start, f=0; i<=och->end; i++, f++) { if (och->ibufs_foam[f]) { IMB_freeImBuf(och->ibufs_foam[f]); } @@ -1063,8 +1015,7 @@ void BKE_free_ocean_cache(struct OceanCache *och) } if (och->ibufs_norm) { - for (i=och->start, f=0; i<=och->end; i++, f++) - { + for (i=och->start, f=0; i<=och->end; i++, f++) { if (och->ibufs_norm[f]) { IMB_freeImBuf(och->ibufs_norm[f]); } diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index b55033b8493..e0c61fbcc90 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -72,7 +72,7 @@ int seekPackedFile(PackedFile *pf, int offset, int whence) if (pf) { oldseek = pf->seek; - switch(whence) { + switch (whence) { case SEEK_CUR: seek = oldseek + offset; break; diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 27f5f7d9eb1..f417f9b79fb 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -59,7 +59,7 @@ Paint *paint_get_active(Scene *sce) ToolSettings *ts = sce->toolsettings; if (sce->basact && sce->basact->object) { - switch(sce->basact->object->mode) { + switch (sce->basact->object->mode) { case OB_MODE_SCULPT: return &ts->sculpt->paint; case OB_MODE_VERTEX_PAINT: diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index a154a1f8926..febe4277010 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -1572,7 +1572,7 @@ static float psys_interpolate_value_from_verts(DerivedMesh *dm, short from, int if (values==0 || index==-1) return 0.0; - switch(from) { + switch (from) { case PART_FROM_VERT: return values[index]; case PART_FROM_FACE: @@ -1936,7 +1936,7 @@ static void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float copy_v3_v3(result, state->co); sub_v3_v3v3(par_vec, par->co, state->co); - switch(type) { + switch (type) { case PART_KINK_CURL: { negate_v3(par_vec); @@ -2846,7 +2846,7 @@ static void cache_key_incremental_rotation(ParticleCacheKey *key0, ParticleCache { float cosangle, angle, tangent[3], normal[3], q[4]; - switch(i) { + switch (i) { case 0: /* start from second key */ break; @@ -3778,7 +3778,7 @@ static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSetti if (ELEM(texco, TEXCO_UV, TEXCO_ORCO) && (ELEM(part->from, PART_FROM_FACE, PART_FROM_VOLUME) == 0 || part->distr == PART_DISTR_GRID)) texco = TEXCO_GLOB; - switch(texco) { + switch (texco) { case TEXCO_GLOB: copy_v3_v3(texvec, par->state.co); break; @@ -3846,7 +3846,7 @@ void psys_get_texture(ParticleSimulationData *sim, ParticleData *pa, ParticleTex if (texco == TEXCO_UV && (ELEM(part->from, PART_FROM_FACE, PART_FROM_VOLUME) == 0 || part->distr == PART_DISTR_GRID)) texco = TEXCO_GLOB; - switch(texco) { + switch (texco) { case TEXCO_GLOB: copy_v3_v3(texvec, pa->state.co); break; diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 4ce24953c89..d3644657de7 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -787,7 +787,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch pa->num = i = ctx->index[p]; mface = dm->getTessFaceData(dm,i,CD_MFACE); - switch(distr) { + switch (distr) { case PART_DISTR_JIT: if (ctx->jitlevel == 1) { if (mface->v4) @@ -855,13 +855,15 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch } if (intersect==0) pa->foffset=0.0; - else switch(distr) { - case PART_DISTR_JIT: - pa->foffset*= ctx->jit[p%(2*ctx->jitlevel)]; - break; - case PART_DISTR_RAND: - pa->foffset*=BLI_frand(); - break; + else { + switch (distr) { + case PART_DISTR_JIT: + pa->foffset *= ctx->jit[p % (2 * ctx->jitlevel)]; + break; + case PART_DISTR_RAND: + pa->foffset *= BLI_frand(); + break; + } } } } @@ -1575,7 +1577,7 @@ static void initialize_all_particles(ParticleSimulationData *sim) static void get_angular_velocity_vector(short avemode, ParticleKey *state, float *vec) { - switch(avemode) { + switch (avemode) { case PART_AVE_VELOCITY: copy_v3_v3(vec, state->vel); break; @@ -1779,7 +1781,7 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P if (part->rotmode) { /* create vector into which rotation is aligned */ - switch(part->rotmode) { + switch (part->rotmode) { case PART_ROT_NOR: copy_v3_v3(rot_vec, nor); break; @@ -2141,7 +2143,7 @@ static void integrate_particle(ParticleSettings *part, ParticleData *pa, float d if (pa->prev_state.time < 0.f && integrator == PART_INT_VERLET) integrator = PART_INT_EULER; - switch(integrator) { + switch (integrator) { case PART_INT_EULER: steps=1; break; @@ -2175,7 +2177,7 @@ static void integrate_particle(ParticleSettings *part, ParticleData *pa, float d /* calculate next state */ add_v3_v3(states[i].vel, impulse); - switch(integrator) { + switch (integrator) { case PART_INT_EULER: madd_v3_v3v3fl(pa->state.co, states->co, states->vel, dtime); madd_v3_v3v3fl(pa->state.vel, states->vel, acceleration, dtime); @@ -2193,7 +2195,7 @@ static void integrate_particle(ParticleSettings *part, ParticleData *pa, float d } break; case PART_INT_RK4: - switch(i) { + switch (i) { case 0: copy_v3_v3(dx[0], states->vel); mul_v3_fl(dx[0], dtime); @@ -2859,7 +2861,7 @@ static float collision_point_distance_with_normal(float p[3], ParticleCollisionE if (fac >= 0.f) collision_interpolate_element(pce, 0.f, fac, col); - switch(pce->tot) { + switch (pce->tot) { case 1: { sub_v3_v3v3(nor, p, pce->x0); @@ -2884,7 +2886,7 @@ static void collision_point_on_surface(float p[3], ParticleCollisionElement *pce { collision_interpolate_element(pce, 0.f, fac, col); - switch(pce->tot) { + switch (pce->tot) { case 1: { sub_v3_v3v3(co, p, pce->x0); @@ -3833,7 +3835,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) sim->colliders = get_collider_cache(sim->scene, sim->ob, NULL); /* initialize physics type specific stuff */ - switch(part->phystype) { + switch (part->phystype) { case PART_PHYS_BOIDS: { ParticleTarget *pt = psys->targets.first; @@ -3908,7 +3910,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) pa->state.time = -1.f; } - switch(part->phystype) { + switch (part->phystype) { case PART_PHYS_NEWTON: { LOOP_DYNAMIC_PARTICLES { @@ -4499,7 +4501,7 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys) /* setup necessary physics type dependent additional data if it doesn't yet exist */ psys_prepare_physics(&sim); - switch(part->type) { + switch (part->type) { case PART_HAIR: { /* nothing to do so bail out early */ @@ -4551,7 +4553,7 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys) } default: { - switch(part->phystype) { + switch (part->phystype) { case PART_PHYS_NO: case PART_PHYS_KEYED: { diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index dbcef9ad4c8..39293084dc0 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -433,7 +433,7 @@ static void ptcache_particle_extra_read(void *psys_v, PTCacheMem *pm, float UNUS PTCacheExtra *extra = pm->extradata.first; for (; extra; extra=extra->next) { - switch(extra->type) { + switch (extra->type) { case BPHYS_EXTRA_FLUID_SPRINGS: { if (psys->fluid_springs) @@ -690,14 +690,20 @@ static int ptcache_dynamicpaint_write(PTCacheFile *pf, void *dp_v) /* cache type */ ptcache_file_write(pf, &surface->type, 1, sizeof(int)); - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) - in_len = sizeof(PaintPoint)*total_points; + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { + in_len = sizeof(PaintPoint) * total_points; + } else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) - in_len = sizeof(float)*total_points; - else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) - in_len = sizeof(PaintWavePoint)*total_points; - else return 0; + surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) + { + in_len = sizeof(float) * total_points; + } + else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) { + in_len = sizeof(PaintWavePoint) * total_points; + } + else { + return 0; + } out = (unsigned char *)MEM_callocN(LZO_OUT_LEN(in_len), "pointcache_lzo_buffer"); @@ -727,14 +733,20 @@ static int ptcache_dynamicpaint_read(PTCacheFile *pf, void *dp_v) return 0; /* read surface data */ - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { data_len = sizeof(PaintPoint); + } else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) + surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) + { data_len = sizeof(float); - else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) + } + else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) { data_len = sizeof(PaintWavePoint); - else return 0; + } + else { + return 0; + } ptcache_file_compressed_read(pf, (unsigned char*)surface->data->type_data, data_len*surface->data->total_points); @@ -989,8 +1001,7 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob, Scene *scene, int dup } else if (md->type == eModifierType_Smoke) { SmokeModifierData *smd = (SmokeModifierData *)md; - if (smd->type & MOD_SMOKE_TYPE_DOMAIN) - { + if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { pid= MEM_callocN(sizeof(PTCacheID), "PTCacheID"); BKE_ptcache_id_from_smoke(pid, ob, (SmokeModifierData*)md); BLI_addtail(lb, pid); @@ -998,8 +1009,7 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob, Scene *scene, int dup } else if (md->type == eModifierType_DynamicPaint) { DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; - if (pmd->canvas) - { + if (pmd->canvas) { DynamicPaintSurface *surface = pmd->canvas->surfaces.first; for (; surface; surface=surface->next) { @@ -1205,8 +1215,7 @@ static int ptcache_file_compressed_read(PTCacheFile *pf, unsigned char *result, r = lzo1x_decompress_safe(in, (lzo_uint)in_len, result, (lzo_uint *)&out_len, NULL); #endif #ifdef WITH_LZMA - if (compressed == 2) - { + if (compressed == 2) { size_t sizeOfIt; size_t leni = in_len, leno = len; ptcache_file_read(pf, &size, 1, sizeof(unsigned int)); @@ -1270,8 +1279,7 @@ static int ptcache_file_compressed_write(PTCacheFile *pf, unsigned char *in, uns else ptcache_file_write(pf, in, in_len, sizeof(unsigned char)); - if (compressed == 2) - { + if (compressed == 2) { unsigned int size = sizeOfIt; ptcache_file_write(pf, &sizeOfIt, 1, sizeof(unsigned int)); ptcache_file_write(pf, props, size, sizeof(unsigned char)); @@ -2313,7 +2321,7 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra if (timescale) { time= BKE_curframe(scene); - nexttime= BKE_frame_to_ctime(scene, CFRA+1); + nexttime = BKE_frame_to_ctime(scene, CFRA + 1.0f); *timescale= MAX2(nexttime - time, 0.0f); } @@ -2505,16 +2513,14 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode) } if (md->type == eModifierType_Smoke) { SmokeModifierData *smd = (SmokeModifierData *)md; - if (smd->type & MOD_SMOKE_TYPE_DOMAIN) - { + if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { BKE_ptcache_id_from_smoke(&pid, ob, (SmokeModifierData*)md); reset |= BKE_ptcache_id_reset(scene, &pid, mode); } } if (md->type == eModifierType_DynamicPaint) { DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; - if (pmd->canvas) - { + if (pmd->canvas) { DynamicPaintSurface *surface = pmd->canvas->surfaces.first; for (; surface; surface=surface->next) { @@ -2813,8 +2819,7 @@ void BKE_ptcache_bake(PTCacheBaker* baker) PTCacheID *pid2; BKE_ptcache_ids_from_object(&pidlist2, pid->ob, scene, MAX_DUPLI_RECUR); for (pid2=pidlist2.first; pid2; pid2=pid2->next) { - if (pid2->type == PTCACHE_TYPE_SMOKE_DOMAIN) - { + if (pid2->type == PTCACHE_TYPE_SMOKE_DOMAIN) { if (pid2->cache && !(pid2->cache->flag & PTCACHE_BAKED)) { if (bake || pid2->cache->flag & PTCACHE_REDO_NEEDED) BKE_ptcache_id_clear(pid2, PTCACHE_CLEAR_ALL, 0); @@ -3246,8 +3251,7 @@ void BKE_ptcache_update_info(PTCacheID *pid) } if (cache->flag & PTCACHE_DISK_CACHE) { - if (pid->type == PTCACHE_TYPE_SMOKE_DOMAIN) - { + if (pid->type == PTCACHE_TYPE_SMOKE_DOMAIN) { int totpoint = pid->totpoint(pid->calldata, 0); if (cache->totpoint > totpoint) diff --git a/source/blender/blenkernel/intern/property.c b/source/blender/blenkernel/intern/property.c index 066de61575d..e7247be7f51 100644 --- a/source/blender/blenkernel/intern/property.c +++ b/source/blender/blenkernel/intern/property.c @@ -99,7 +99,7 @@ void init_property(bProperty *prop) prop->data= 0; - switch(prop->type) { + switch (prop->type) { case GPROP_BOOL: case GPROP_INT: case GPROP_FLOAT: @@ -206,7 +206,7 @@ int compare_property(bProperty *prop, const char *str) // extern int Gdfra; /* sector.c */ float fvalue, ftest; - switch(prop->type) { + switch (prop->type) { case GPROP_BOOL: if (BLI_strcasecmp(str, "true")==0) { if (prop->data==1) return 0; @@ -242,7 +242,7 @@ void set_property(bProperty *prop, const char *str) { // extern int Gdfra; /* sector.c */ - switch(prop->type) { + switch (prop->type) { case GPROP_BOOL: if (BLI_strcasecmp(str, "true")==0) prop->data= 1; else if (BLI_strcasecmp(str, "false")==0) prop->data= 0; @@ -266,7 +266,7 @@ void add_property(bProperty *prop, const char *str) { // extern int Gdfra; /* sector.c */ - switch(prop->type) { + switch (prop->type) { case GPROP_BOOL: case GPROP_INT: prop->data+= atoi(str); @@ -288,7 +288,7 @@ void set_property_valstr(bProperty *prop, char *str) if (str == NULL) return; - switch(prop->type) { + switch (prop->type) { case GPROP_BOOL: case GPROP_INT: sprintf(str, "%d", prop->data); diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c index b3e288dfc74..a7df6b10f06 100644 --- a/source/blender/blenkernel/intern/report.c +++ b/source/blender/blenkernel/intern/report.c @@ -43,7 +43,7 @@ static const char *report_type_str(int type) { - switch(type) { + switch (type) { case RPT_DEBUG: return "Debug"; case RPT_INFO: return "Info"; case RPT_OPERATOR: return "Operator"; diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index 8123cbf3f0b..b5bb6b76c61 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -110,7 +110,7 @@ void init_sensor(bSensor *sens) sens->data= NULL; sens->pulse = 0; - switch(sens->type) { + switch (sens->type) { case SENS_ALWAYS: sens->pulse = 0; break; @@ -272,7 +272,7 @@ void init_controller(bController *cont) if (cont->data) MEM_freeN(cont->data); cont->data= NULL; - switch(cont->type) { + switch (cont->type) { case CONT_EXPRESSION: cont->data= MEM_callocN(sizeof(bExpressionCont), "expcont"); break; @@ -400,7 +400,7 @@ void init_actuator(bActuator *act) if (act->data) MEM_freeN(act->data); act->data= NULL; - switch(act->type) { + switch (act->type) { case ACT_ACTION: case ACT_SHAPEACTION: act->data= MEM_callocN(sizeof(bActionActuator), "actionact"); @@ -647,7 +647,7 @@ void sca_remove_ob_poin(Object *obt, Object *ob) sens= obt->sensors.first; while (sens) { - switch(sens->type) { + switch (sens->type) { case SENS_MESSAGE: ms= sens->data; if (ms->fromObject==ob) ms->fromObject= NULL; @@ -657,7 +657,7 @@ void sca_remove_ob_poin(Object *obt, Object *ob) act= obt->actuators.first; while (act) { - switch(act->type) { + switch (act->type) { case ACT_CAMERA: ca= act->data; if (ca->ob==ob) ca->ob= NULL; diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index 8015e53e4c9..d3eade834e6 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -2112,7 +2112,7 @@ static void transform_image(int x, int y, struct ImBuf *ibuf1, struct ImBuf *out yt += (yo / 2.0f); //interpolate - switch(interpolation) { + switch (interpolation) { case 0: neareast_interpolation(ibuf1,out, xt,yt,xi,yi); break; diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 2d4397d16cd..9291cb90dff 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -259,8 +259,7 @@ void seq_free_editing(Scene *scene) if (ed == NULL) return; - SEQ_BEGIN(ed, seq) - { + SEQ_BEGIN (ed, seq) { seq_free_sequence(scene, seq); } SEQ_END @@ -363,7 +362,7 @@ unsigned int seq_hash_render_data(const SeqRenderData *a) /* ************************* iterator ************************** */ /* *************** (replaces old WHILE_SEQ) ********************* */ -/* **************** use now SEQ_BEGIN() SEQ_END ***************** */ +/* **************** use now SEQ_BEGIN () SEQ_END ***************** */ /* sequence strip iterator: * - builds a full array, recursively into meta strips */ @@ -515,8 +514,17 @@ void build_seqar_cb(ListBase *seqbase, Sequence ***seqar, int *totseq, *seqar = tseqar; } +static int metaseq_start(Sequence *metaseq) +{ + return metaseq->start + metaseq->startofs; +} -static void seq_update_sound_bounds_recursive(Scene *scene, Sequence *metaseq) +static int metaseq_end(Sequence *metaseq) +{ + return metaseq->start + metaseq->len - metaseq->endofs; +} + +static void seq_update_sound_bounds_recursive_rec(Scene *scene, Sequence *metaseq, int start, int end) { Sequence *seq; @@ -524,23 +532,28 @@ static void seq_update_sound_bounds_recursive(Scene *scene, Sequence *metaseq) * since sound is played outside of evaluating the imbufs, */ for (seq = metaseq->seqbase.first; seq; seq = seq->next) { if (seq->type == SEQ_META) { - seq_update_sound_bounds_recursive(scene, seq); + seq_update_sound_bounds_recursive_rec(scene, seq, MAX2(start, metaseq_start(seq)), MIN2(end, metaseq_end(seq))); } else if (ELEM(seq->type, SEQ_SOUND, SEQ_SCENE)) { if (seq->scene_sound) { int startofs = seq->startofs; int endofs = seq->endofs; - if (seq->startofs + seq->start < metaseq->start + metaseq->startofs) - startofs = metaseq->start + metaseq->startofs - seq->start; + if (seq->startofs + seq->start < start) + startofs = start - seq->start; - if (seq->start + seq->len - seq->endofs > metaseq->start + metaseq->len - metaseq->endofs) - endofs = seq->start + seq->len - metaseq->start - metaseq->len + metaseq->endofs; + if (seq->start + seq->len - seq->endofs > end) + endofs = seq->start + seq->len - end; sound_move_scene_sound(scene, seq->scene_sound, seq->start + startofs, seq->start + seq->len - endofs, startofs); } } } } +static void seq_update_sound_bounds_recursive(Scene *scene, Sequence *metaseq) +{ + seq_update_sound_bounds_recursive_rec(scene, metaseq, metaseq_start(metaseq), metaseq_end(metaseq)); +} + void calc_sequence_disp(Scene *scene, Sequence *seq) { if (seq->startofs && seq->startstill) seq->startstill = 0; @@ -3099,13 +3112,17 @@ int seqbase_isolated_sel_check(ListBase *seqbase) if ( (seq->seq1 && (seq->seq1->flag & SELECT) == 0) || (seq->seq2 && (seq->seq2->flag & SELECT) == 0) || (seq->seq3 && (seq->seq3->flag & SELECT) == 0) ) + { return FALSE; + } } else { if ( (seq->seq1 && (seq->seq1->flag & SELECT)) || (seq->seq2 && (seq->seq2->flag & SELECT)) || (seq->seq3 && (seq->seq3->flag & SELECT)) ) + { return FALSE; + } } } diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 4006837efd6..e201209ec3f 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -146,8 +146,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) BENCH(bvhtree_from_mesh_verts(&treeData, calc->target, 0.0, 2, 6)); - if (treeData.tree == NULL) - { + if (treeData.tree == NULL) { OUT_OF_MEMORY(); return; } @@ -158,8 +157,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) #ifndef __APPLE__ #pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(treeData,calc) schedule(static) #endif - for (i = 0; i<calc->numVerts; ++i) - { + for (i = 0; i<calc->numVerts; ++i) { float *co = calc->vertexCos[i]; float tmp_co[3]; float weight = defvert_array_find_weight_safe(calc->dvert, i, calc->vgroup); @@ -189,8 +187,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) //Found the nearest vertex - if (nearest.index != -1) - { + if (nearest.index != -1) { //Adjusting the vertex weight, so that after interpolating it keeps a certain distance from the nearest position float dist = sasqrt(nearest.dist); if (dist > FLT_EPSILON) weight *= (dist - calc->keepDist)/dist; @@ -224,8 +221,7 @@ int normal_projection_project_vertex(char options, const float *vert, const floa memcpy( &hit_tmp, hit, sizeof(hit_tmp) ); //Apply space transform (TODO readjust dist) - if (transf) - { + if (transf) { copy_v3_v3( tmp_co, vert ); space_transform_apply( transf, tmp_co ); co = tmp_co; @@ -298,8 +294,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) //Prepare data to retrieve the direction in which we should project each vertex - if (calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) - { + if (calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) { if (calc->vert == NULL) return; } else { @@ -316,8 +311,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) return; } - if (calc->smd->auxTarget) - { + if (calc->smd->auxTarget) { auxMesh = object_get_derived_final(calc->smd->auxTarget); if (!auxMesh) return; @@ -332,16 +326,14 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) #ifndef __APPLE__ #pragma omp parallel for private(i,hit) schedule(static) #endif - for (i = 0; i<calc->numVerts; ++i) - { + for (i = 0; i<calc->numVerts; ++i) { float *co = calc->vertexCos[i]; float tmp_co[3], tmp_no[3]; float weight = defvert_array_find_weight_safe(calc->dvert, i, calc->vgroup); if (weight == 0.0f) continue; - if (calc->vert) - { + if (calc->vert) { /* calc->vert contains verts from derivedMesh */ /* this coordinated are deformed by vertexCos only for normal projection (to get correct normals) */ /* for other cases calc->varts contains undeformed coordinates and vertexCos should be used */ @@ -364,8 +356,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) hit.dist = 10000.0f; //TODO: we should use FLT_MAX here, but sweepsphere code isn't prepared for that //Project over positive direction of axis - if (use_normal & MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR) - { + if (use_normal & MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR) { if (auxData.tree) normal_projection_project_vertex(0, tmp_co, tmp_no, &local2aux, auxData.tree, &hit, auxData.raycast_callback, &auxData); @@ -374,8 +365,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) } //Project over negative direction of axis - if (use_normal & MOD_SHRINKWRAP_PROJECT_ALLOW_NEG_DIR && hit.index == -1) - { + if (use_normal & MOD_SHRINKWRAP_PROJECT_ALLOW_NEG_DIR && hit.index == -1) { float inv_no[3]; negate_v3_v3(inv_no, tmp_no); @@ -386,8 +376,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) } - if (hit.index != -1) - { + if (hit.index != -1) { madd_v3_v3v3fl(hit.co, hit.co, tmp_no, calc->keepDist); interp_v3_v3v3(co, co, hit.co, weight); } @@ -414,8 +403,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) //Create a bvh-tree of the given target BENCH(bvhtree_from_mesh_faces( &treeData, calc->target, 0.0, 2, 6)); - if (treeData.tree == NULL) - { + if (treeData.tree == NULL) { OUT_OF_MEMORY(); return; } @@ -429,8 +417,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) #ifndef __APPLE__ #pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(calc,treeData) schedule(static) #endif - for (i = 0; i<calc->numVerts; ++i) - { + for (i = 0; i<calc->numVerts; ++i) { float *co = calc->vertexCos[i]; float tmp_co[3]; float weight = defvert_array_find_weight_safe(calc->dvert, i, calc->vgroup); @@ -458,10 +445,8 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) BLI_bvhtree_find_nearest(treeData.tree, tmp_co, &nearest, treeData.nearest_callback, &treeData); //Found the nearest vertex - if (nearest.index != -1) - { - if (calc->smd->shrinkOpts & MOD_SHRINKWRAP_KEEP_ABOVE_SURFACE) - { + if (nearest.index != -1) { + if (calc->smd->shrinkOpts & MOD_SHRINKWRAP_KEEP_ABOVE_SURFACE) { //Make the vertex stay on the front side of the face madd_v3_v3v3fl(tmp_co, nearest.co, nearest.no, calc->keepDist); } @@ -511,8 +496,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM } - if (smd->target) - { + if (smd->target) { calc.target = object_get_derived_final(smd->target); //TODO there might be several "bugs" on non-uniform scales matrixs @@ -528,28 +512,24 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM calc.vgroup = defgroup_name_index(calc.ob, smd->vgroup_name); - if (dm != NULL && smd->shrinkType == MOD_SHRINKWRAP_PROJECT) - { + if (dm != NULL && smd->shrinkType == MOD_SHRINKWRAP_PROJECT) { //Setup arrays to get vertexs positions, normals and deform weights calc.vert = dm->getVertDataArray(dm, CD_MVERT); calc.dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); //Using vertexs positions/normals as if a subsurface was applied - if (smd->subsurfLevels) - { + if (smd->subsurfLevels) { SubsurfModifierData ssmd= {{NULL}}; ssmd.subdivType = ME_CC_SUBSURF; //catmull clark ssmd.levels = smd->subsurfLevels; //levels ss_mesh = subsurf_make_derived_from_derived(dm, &ssmd, FALSE, NULL, 0, 0, (ob->mode & OB_MODE_EDIT)); - if (ss_mesh) - { + if (ss_mesh) { calc.vert = ss_mesh->getVertDataArray(ss_mesh, CD_MVERT); - if (calc.vert) - { - //TRICKY: this code assumes subsurface will have the transformed original vertices - //in their original order at the end of the vert array. + if (calc.vert) { + /* TRICKY: this code assumes subsurface will have the transformed original vertices + * in their original order at the end of the vert array. */ calc.vert = calc.vert + ss_mesh->getNumVerts(ss_mesh) - dm->getNumVerts(dm); } } @@ -562,8 +542,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM //Projecting target defined - lets work! if (calc.target) { - switch(smd->shrinkType) - { + switch (smd->shrinkType) { case MOD_SHRINKWRAP_NEAREST_SURFACE: BENCH(shrinkwrap_calc_nearest_surface_point(&calc)); break; diff --git a/source/blender/blenkernel/intern/sketch.c b/source/blender/blenkernel/intern/sketch.c index 71ea85de716..32681c3a041 100644 --- a/source/blender/blenkernel/intern/sketch.c +++ b/source/blender/blenkernel/intern/sketch.c @@ -44,8 +44,7 @@ void freeSketch(SK_Sketch *sketch) { SK_Stroke *stk, *next; - for (stk = sketch->strokes.first; stk; stk = next) - { + for (stk = sketch->strokes.first; stk; stk = next) { next = stk->next; sk_freeStroke(stk); @@ -119,8 +118,7 @@ SK_Stroke* sk_createStroke(void) void sk_shrinkStrokeBuffer(SK_Stroke *stk) { - if (stk->nb_points < stk->buf_size) - { + if (stk->nb_points < stk->buf_size) { SK_Point *old_points = stk->points; stk->buf_size = stk->nb_points; @@ -135,8 +133,7 @@ void sk_shrinkStrokeBuffer(SK_Stroke *stk) void sk_growStrokeBuffer(SK_Stroke *stk) { - if (stk->nb_points == stk->buf_size) - { + if (stk->nb_points == stk->buf_size) { SK_Point *old_points = stk->points; stk->buf_size *= 2; @@ -151,12 +148,10 @@ void sk_growStrokeBuffer(SK_Stroke *stk) void sk_growStrokeBufferN(SK_Stroke *stk, int n) { - if (stk->nb_points + n > stk->buf_size) - { + if (stk->nb_points + n > stk->buf_size) { SK_Point *old_points = stk->points; - while (stk->nb_points + n > stk->buf_size) - { + while (stk->nb_points + n > stk->buf_size) { stk->buf_size *= 2; } @@ -202,8 +197,7 @@ void sk_insertStrokePoints(SK_Stroke *stk, SK_Point *pts, int len, int start, in sk_growStrokeBufferN(stk, len - size); - if (len != size) - { + if (len != size) { int tail_size = stk->nb_points - end + 1; memmove(stk->points + start + len, stk->points + end + 1, tail_size * sizeof(SK_Point)); @@ -218,8 +212,7 @@ void sk_trimStroke(SK_Stroke *stk, int start, int end) { int size = end - start + 1; - if (start > 0) - { + if (start > 0) { memmove(stk->points, stk->points + start, size * sizeof(SK_Point)); } @@ -253,8 +246,7 @@ void sk_straightenStroke(SK_Stroke *stk, int start, int end, float p_start[3], f sk_insertStrokePoint(stk, &pt1, start + 1); /* insert after start */ sk_insertStrokePoint(stk, &pt2, end + 1); /* insert before end (since end was pushed back already) */ - for (i = 1; i < total; i++) - { + for (i = 1; i < total; i++) { float delta = (float)i / (float)total; float *p = stk->points[start + 1 + i].p; @@ -269,30 +261,23 @@ void sk_polygonizeStroke(SK_Stroke *stk, int start, int end) int i; /* find first exact points outside of range */ - for (;start > 0; start--) - { - if (stk->points[start].type == PT_EXACT) - { + for (;start > 0; start--) { + if (stk->points[start].type == PT_EXACT) { break; } } - for (;end < stk->nb_points - 1; end++) - { - if (stk->points[end].type == PT_EXACT) - { + for (;end < stk->nb_points - 1; end++) { + if (stk->points[end].type == PT_EXACT) { break; } } offset = start + 1; - for (i = start + 1; i < end; i++) - { - if (stk->points[i].type == PT_EXACT) - { - if (offset != i) - { + for (i = start + 1; i < end; i++) { + if (stk->points[i].type == PT_EXACT) { + if (offset != i) { memcpy(stk->points + offset, stk->points + i, sizeof(SK_Point)); } @@ -301,8 +286,7 @@ void sk_polygonizeStroke(SK_Stroke *stk, int start, int end) } /* some points were removes, move end of array */ - if (offset < end) - { + if (offset < end) { int size = stk->nb_points - end; memmove(stk->points + offset, stk->points + end, size * sizeof(SK_Point)); stk->nb_points = offset + size; @@ -323,8 +307,7 @@ void sk_flattenStroke(SK_Stroke *stk, int start, int end) project_v3_v3v3(normal, distance, normal); limit = normalize_v3(normal); - for (i = 1; i < total - 1; i++) - { + for (i = 1; i < total - 1; i++) { float d = limit * i / total; float offset[3]; float *p = stk->points[start + i].p; @@ -342,8 +325,7 @@ void sk_flattenStroke(SK_Stroke *stk, int start, int end) void sk_removeStroke(SK_Sketch *sketch, SK_Stroke *stk) { - if (sketch->active_stroke == stk) - { + if (sketch->active_stroke == stk) { sketch->active_stroke = NULL; } @@ -358,8 +340,7 @@ void sk_reverseStroke(SK_Stroke *stk) sk_allocStrokeBuffer(stk); - for (i = 0; i < stk->nb_points; i++) - { + for (i = 0; i < stk->nb_points; i++) { sk_copyPoint(stk->points + i, old_points + stk->nb_points - 1 - i); } @@ -376,8 +357,7 @@ void sk_filterStroke(SK_Stroke *stk, int start, int end) char work; int i; - if (start == -1) - { + if (start == -1) { start = 0; end = stk->nb_points - 1; } @@ -386,8 +366,7 @@ void sk_filterStroke(SK_Stroke *stk, int start, int end) stk->nb_points = 0; /* adding points before range */ - for (i = 0; i < start; i++) - { + for (i = 0; i < start; i++) { sk_appendStrokePoint(stk, old_points + i); } @@ -398,8 +377,7 @@ void sk_filterStroke(SK_Stroke *stk, int start, int end) work = 1; /* while still reducing */ - while (work) - { + while (work) { int ls, le; work = 0; @@ -407,15 +385,13 @@ void sk_filterStroke(SK_Stroke *stk, int start, int end) le = start+1; /* while not over interval */ - while (ls < end) - { + while (ls < end) { int max_i = 0; short v1[2]; float max_dist = 16; /* more than 4 pixels */ /* find the next marked point */ - while (marked[le] == 0) - { + while (marked[le] == 0) { le++; } @@ -424,8 +400,7 @@ void sk_filterStroke(SK_Stroke *stk, int start, int end) v1[0] = old_points[ls].p2d[1] - old_points[le].p2d[1]; - for ( i = ls + 1; i < le; i++ ) - { + for ( i = ls + 1; i < le; i++ ) { float mul; float dist; short v2[2]; @@ -433,8 +408,7 @@ void sk_filterStroke(SK_Stroke *stk, int start, int end) v2[0] = old_points[i].p2d[0] - old_points[ls].p2d[0]; v2[1] = old_points[i].p2d[1] - old_points[ls].p2d[1]; - if (v2[0] == 0 && v2[1] == 0) - { + if (v2[0] == 0 && v2[1] == 0) { continue; } @@ -442,15 +416,13 @@ void sk_filterStroke(SK_Stroke *stk, int start, int end) dist = mul * mul * (v2[0]*v2[0] + v2[1]*v2[1]); - if (dist > max_dist) - { + if (dist > max_dist) { max_dist = dist; max_i = i; } } - if (max_i != 0) - { + if (max_i != 0) { work = 1; marked[max_i] = 1; } @@ -462,10 +434,8 @@ void sk_filterStroke(SK_Stroke *stk, int start, int end) /* adding points after range */ - for (i = start; i <= end; i++) - { - if (marked[i]) - { + for (i = start; i <= end; i++) { + if (marked[i]) { sk_appendStrokePoint(stk, old_points + i); } } @@ -473,8 +443,7 @@ void sk_filterStroke(SK_Stroke *stk, int start, int end) MEM_freeN(marked); /* adding points after range */ - for (i = end + 1; i < nb_points; i++) - { + for (i = end + 1; i < nb_points; i++) { sk_appendStrokePoint(stk, old_points + i); } @@ -490,13 +459,11 @@ void sk_filterLastContinuousStroke(SK_Stroke *stk) end = stk->nb_points -1; - for (start = end - 1; start > 0 && stk->points[start].type == PT_CONTINUOUS; start--) - { + for (start = end - 1; start > 0 && stk->points[start].type == PT_CONTINUOUS; start--) { /* nothing to do here*/ } - if (end - start > 1) - { + if (end - start > 1) { sk_filterStroke(stk, start, end); } } @@ -505,8 +472,7 @@ SK_Point *sk_lastStrokePoint(SK_Stroke *stk) { SK_Point *pt = NULL; - if (stk->nb_points > 0) - { + if (stk->nb_points > 0) { pt = stk->points + (stk->nb_points - 1); } @@ -520,8 +486,7 @@ void sk_endContinuousStroke(SK_Stroke *stk) void sk_updateNextPoint(SK_Sketch *sketch, SK_Stroke *stk) { - if (stk) - { + if (stk) { memcpy(&sketch->next_point, stk->points[stk->nb_points - 1].p, sizeof(SK_Point)); } } @@ -529,8 +494,7 @@ void sk_updateNextPoint(SK_Sketch *sketch, SK_Stroke *stk) int sk_stroke_filtermval(SK_DrawData *dd) { int retval = 0; - if (ABS(dd->mval[0] - dd->previous_mval[0]) + ABS(dd->mval[1] - dd->previous_mval[1]) > U.gp_manhattendist) - { + if (ABS(dd->mval[0] - dd->previous_mval[0]) + ABS(dd->mval[1] - dd->previous_mval[1]) > U.gp_manhattendist) { retval = 1; } @@ -551,12 +515,10 @@ void sk_deleteSelectedStrokes(SK_Sketch *sketch) { SK_Stroke *stk, *next; - for (stk = sketch->strokes.first; stk; stk = next) - { + for (stk = sketch->strokes.first; stk; stk = next) { next = stk->next; - if (stk->selected == 1) - { + if (stk->selected == 1) { sk_removeStroke(sketch, stk); } } @@ -566,31 +528,26 @@ void sk_selectAllSketch(SK_Sketch *sketch, int mode) { SK_Stroke *stk = NULL; - if (mode == -1) - { - for (stk = sketch->strokes.first; stk; stk = stk->next) - { + if (mode == -1) { + for (stk = sketch->strokes.first; stk; stk = stk->next) { stk->selected = 0; } } else if (mode == 0) { - for (stk = sketch->strokes.first; stk; stk = stk->next) - { + for (stk = sketch->strokes.first; stk; stk = stk->next) { stk->selected = 1; } } else if (mode == 1) { int selected = 1; - for (stk = sketch->strokes.first; stk; stk = stk->next) - { + for (stk = sketch->strokes.first; stk; stk = stk->next) { selected &= stk->selected; } selected ^= 1; - for (stk = sketch->strokes.first; stk; stk = stk->next) - { + for (stk = sketch->strokes.first; stk; stk = stk->next) { stk->selected = selected; } } diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 9d13397859d..f3939a2ebfc 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -21,6 +21,7 @@ * The Original Code is: all of this file. * * Contributor(s): Daniel Genrich + * Blender Foundation * * ***** END GPL LICENSE BLOCK ***** */ @@ -53,6 +54,7 @@ #include "BKE_bvhutils.h" #include "BKE_cdderivedmesh.h" +#include "BKE_collision.h" #include "BKE_customdata.h" #include "BKE_DerivedMesh.h" #include "BKE_effect.h" @@ -118,7 +120,6 @@ static void tend ( void ) gettimeofday ( &_tend,&tz ); } -#if 0 // unused static double tval() { double t1, t2; @@ -127,14 +128,16 @@ static double tval() return t2-t1; } #endif -#endif struct Object; struct Scene; struct DerivedMesh; struct SmokeModifierData; -#define TRI_UVOFFSET (1.0 / 4.0) +#define TRI_UVOFFSET (1./4.) + +// timestep default value for nice appearance 0.1f +#define DT_DEFAULT 0.1f /* forward declerations */ static void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *tris, int numfaces, int numtris, int **tridivs, float cell_len); @@ -159,7 +162,7 @@ void smokeModifier_do(SmokeModifierData *UNUSED(smd), Scene *UNUSED(scene), Obje 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) { size_t i; float min[3] = {FLT_MAX, FLT_MAX, FLT_MAX}, max[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX}; @@ -171,7 +174,7 @@ static int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, res = smd->domain->maxres; // get BB of domain - for (i = 0; i < dm->getNumVerts(dm); i++) + for(i = 0; i < dm->getNumVerts(dm); i++) { float tmp[3]; @@ -198,32 +201,32 @@ static int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, // printf("size: %f, %f, %f\n", size[0], size[1], size[2]); // 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 0; - if (size[0] > size[1]) + if(size[0] > size[1]) { - if (size[0] > size[2]) + if(size[0] > size[2]) { scale = res / size[0]; - smd->domain->dx = size[0] / res; + smd->domain->dx = size[0] / res; // dx is in global coords smd->domain->res[0] = res; smd->domain->res[1] = (int)(size[1] * scale + 0.5); smd->domain->res[2] = (int)(size[2] * scale + 0.5); } else { scale = res / size[2]; - smd->domain->dx = size[2] / res; + smd->domain->dx = size[2] / res; // dx is in global coords smd->domain->res[2] = res; smd->domain->res[0] = (int)(size[0] * scale + 0.5); smd->domain->res[1] = (int)(size[1] * scale + 0.5); } } else { - if (size[1] > size[2]) + if(size[1] > size[2]) { scale = res / size[1]; - smd->domain->dx = size[1] / res; + smd->domain->dx = size[1] / res; // dx is in global coords smd->domain->res[1] = res; smd->domain->res[0] = (int)(size[0] * scale + 0.5); smd->domain->res[2] = (int)(size[2] * scale + 0.5); @@ -243,10 +246,10 @@ static int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, // printf("res[0]: %d, res[1]: %d, res[2]: %d\n", smd->domain->res[0], smd->domain->res[1], smd->domain->res[2]); // dt max is 0.1 - smd->domain->fluid = smoke_init(smd->domain->res, smd->domain->p0); + smd->domain->fluid = smoke_init(smd->domain->res, smd->domain->p0, DT_DEFAULT); smd->time = scene->r.cfra; - if (smd->domain->flags & MOD_SMOKE_HIGHRES) + if(smd->domain->flags & MOD_SMOKE_HIGHRES) { smd->domain->wt = smoke_turbulence_init(smd->domain->res, smd->domain->amplify + 1, smd->domain->noise); smd->domain->res_wt[0] = smd->domain->res[0] * (smd->domain->amplify + 1); @@ -257,19 +260,19 @@ static int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, // printf("(smd->domain->flags & MOD_SMOKE_HIGHRES)\n"); } - if (!smd->domain->shadow) + if(!smd->domain->shadow) smd->domain->shadow = MEM_callocN(sizeof(float) * smd->domain->res[0] * smd->domain->res[1] * smd->domain->res[2], "SmokeDomainShadow"); smoke_initBlenderRNA(smd->domain->fluid, &(smd->domain->alpha), &(smd->domain->beta), &(smd->domain->time_scale), &(smd->domain->vorticity), &(smd->domain->border_collisions)); - if (smd->domain->wt) + if(smd->domain->wt) { smoke_initWaveletBlenderRNA(smd->domain->wt, &(smd->domain->strength)); // printf("smoke_initWaveletBlenderRNA\n"); } return 1; } - else if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) + else if((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) { // handle flow object here // XXX TODO @@ -288,7 +291,7 @@ static int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, } /* - if (!smd->flow->bvh) + if(!smd->flow->bvh) { // smd->flow->bvh = MEM_callocN(sizeof(BVHTreeFromMesh), "smoke_bvhfromfaces"); // bvhtree_from_mesh_faces(smd->flow->bvh, dm, 0.0, 2, 6); @@ -301,28 +304,33 @@ static int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, return 1; } - else if ((smd->type & MOD_SMOKE_TYPE_COLL)) + else if((smd->type & MOD_SMOKE_TYPE_COLL)) { - smd->time = scene->r.cfra; - // todo: delete this when loading colls work -dg - if (!smd->coll) + + if(!smd->coll) + { smokeModifier_createType(smd); + } - if (!smd->coll->points) + if(!smd->coll->points) { // init collision points SmokeCollSettings *scs = smd->coll; + smd->time = scene->r.cfra; + // copy obmat copy_m4_m4(scs->mat, ob->obmat); copy_m4_m4(scs->mat_old, ob->obmat); DM_ensure_tessface(dm); fill_scs_points(ob, dm, scs); + + // DEBUG printf("scs->dx: %f\n", scs->dx); } - if (!smd->coll->bvhtree) + if(!smd->coll->bvhtree) { smd->coll->bvhtree = NULL; // bvhtree_build_from_smoke ( ob->obmat, dm->getTessFaceArray(dm), dm->getNumTessFaces(dm), dm->getVertArray(dm), dm->getNumVerts(dm), 0.0 ); } @@ -337,50 +345,52 @@ static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) MVert *mvert = dm->getVertArray(dm); MFace *mface = dm->getTessFaceArray(dm); int i = 0, divs = 0; - int *tridivs = NULL; - float cell_len = 1.0 / 50.0; // for res = 50 + + // DG TODO: need to do this dynamically according to the domain object! + float cell_len = scs->dx; int newdivs = 0; int quads = 0, facecounter = 0; // count quads - for (i = 0; i < dm->getNumTessFaces(dm); i++) + for(i = 0; i < dm->getNumTessFaces(dm); i++) { - if (mface[i].v4) + if(mface[i].v4) quads++; } - calcTriangleDivs(ob, mvert, dm->getNumVerts(dm), mface, dm->getNumTessFaces(dm), dm->getNumTessFaces(dm) + quads, &tridivs, cell_len); + scs->numtris = dm->getNumTessFaces(dm) + quads; + scs->tridivs = NULL; + calcTriangleDivs(ob, mvert, dm->getNumVerts(dm), mface, dm->getNumTessFaces(dm), scs->numtris, &(scs->tridivs), cell_len); // count triangle divisions - for (i = 0; i < dm->getNumTessFaces(dm) + quads; i++) + for(i = 0; i < dm->getNumTessFaces(dm) + quads; i++) { - divs += (tridivs[3 * i] + 1) * (tridivs[3 * i + 1] + 1) * (tridivs[3 * i + 2] + 1); + divs += (scs->tridivs[3 * i] + 1) * (scs->tridivs[3 * i + 1] + 1) * (scs->tridivs[3 * i + 2] + 1); } - // printf("divs: %d\n", divs); - scs->points = MEM_callocN(sizeof(float) * (dm->getNumVerts(dm) + divs) * 3, "SmokeCollPoints"); + scs->points_old = MEM_callocN(sizeof(float) * (dm->getNumVerts(dm) + divs) * 3, "SmokeCollPointsOld"); - for (i = 0; i < dm->getNumVerts(dm); i++) + for(i = 0; i < dm->getNumVerts(dm); i++) { float tmpvec[3]; copy_v3_v3(tmpvec, mvert[i].co); - mul_m4_v3(ob->obmat, tmpvec); + // mul_m4_v3(ob->obmat, tmpvec); // DG: use local coordinates, we save MAT anyway copy_v3_v3(&scs->points[i * 3], tmpvec); } - for (i = 0, facecounter = 0; i < dm->getNumTessFaces(dm); i++) + for(i = 0, facecounter = 0; i < dm->getNumTessFaces(dm); i++) { int again = 0; do { int j, k; - int divs1 = tridivs[3 * facecounter + 0]; - int divs2 = tridivs[3 * facecounter + 1]; - //int divs3 = tridivs[3 * facecounter + 2]; + int divs1 = scs->tridivs[3 * facecounter + 0]; + int divs2 = scs->tridivs[3 * facecounter + 1]; + //int divs3 = scs->tridivs[3 * facecounter + 2]; float side1[3], side2[3], trinormorg[3], trinorm[3]; - if (again == 1 && mface[i].v4) + if(again == 1 && mface[i].v4) { sub_v3_v3v3(side1, mvert[ mface[i].v3 ].co, mvert[ mface[i].v1 ].co); sub_v3_v3v3(side2, mvert[ mface[i].v4 ].co, mvert[ mface[i].v1 ].co); @@ -395,23 +405,23 @@ static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) copy_v3_v3(trinorm, trinormorg); mul_v3_fl(trinorm, 0.25 * cell_len); - for (j = 0; j <= divs1; j++) + for(j = 0; j <= divs1; j++) { - for (k = 0; k <= divs2; k++) + for(k = 0; k <= divs2; k++) { float p1[3], p2[3], p3[3], p[3]={0,0,0}; const float uf = (float)(j + TRI_UVOFFSET) / (float)(divs1 + 0.0); const float vf = (float)(k + TRI_UVOFFSET) / (float)(divs2 + 0.0); float tmpvec[3]; - if (uf+vf > 1.0) + if(uf+vf > 1.0) { // printf("bigger - divs1: %d, divs2: %d\n", divs1, divs2); continue; } copy_v3_v3(p1, mvert[ mface[i].v1 ].co); - if (again == 1 && mface[i].v4) + if(again == 1 && mface[i].v4) { copy_v3_v3(p2, mvert[ mface[i].v3 ].co); copy_v3_v3(p3, mvert[ mface[i].v4 ].co); @@ -428,40 +438,211 @@ static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) add_v3_v3v3(p, p1, p2); add_v3_v3(p, p3); - if (newdivs > divs) + if(newdivs > divs) printf("mem problem\n"); // mMovPoints.push_back(p + trinorm); add_v3_v3v3(tmpvec, p, trinorm); - mul_m4_v3(ob->obmat, tmpvec); + // mul_m4_v3(ob->obmat, tmpvec); // DG: use local coordinates, we save MAT anyway copy_v3_v3(&scs->points[3 * (dm->getNumVerts(dm) + newdivs)], tmpvec); newdivs++; - if (newdivs > divs) + if(newdivs > divs) printf("mem problem\n"); // mMovPoints.push_back(p - trinorm); copy_v3_v3(tmpvec, p); sub_v3_v3(tmpvec, trinorm); - mul_m4_v3(ob->obmat, tmpvec); + // mul_m4_v3(ob->obmat, tmpvec); // DG: use local coordinates, we save MAT anyway copy_v3_v3(&scs->points[3 * (dm->getNumVerts(dm) + newdivs)], tmpvec); newdivs++; } } - if (again == 0 && mface[i].v4) + if(again == 0 && mface[i].v4) again++; else again = 0; facecounter++; - } while (again!=0); + } while(again!=0); } + scs->numverts = dm->getNumVerts(dm); + // DG TODO: also save triangle count? + scs->numpoints = dm->getNumVerts(dm) + newdivs; - MEM_freeN(tridivs); + for(i = 0; i < scs->numpoints * 3; i++) + { + scs->points_old[i] = scs->points[i]; + } +} + + +static void fill_scs_points_anim(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) +{ + MVert *mvert = dm->getVertArray(dm); + MFace *mface = dm->getTessFaceArray(dm); + int quads = 0, numtris = 0, facecounter = 0; + unsigned int i = 0; + int divs = 0, newdivs = 0; + + // DG TODO: need to do this dynamically according to the domain object! + float cell_len = scs->dx; + + // count quads + for(i = 0; i < dm->getNumTessFaces(dm); i++) + { + if(mface[i].v4) + quads++; + } + + numtris = dm->getNumTessFaces(dm) + quads; + + // check if mesh changed topology + if(scs->numtris != numtris) + return; + if(scs->numverts != dm->getNumVerts(dm)) + return; + + // update new positions + for(i = 0; i < dm->getNumVerts(dm); i++) + { + float tmpvec[3]; + copy_v3_v3(tmpvec, mvert[i].co); + copy_v3_v3(&scs->points[i * 3], tmpvec); + } + + // for every triangle // update div points + for(i = 0, facecounter = 0; i < dm->getNumTessFaces(dm); i++) + { + int again = 0; + do + { + int j, k; + int divs1 = scs->tridivs[3 * facecounter + 0]; + int divs2 = scs->tridivs[3 * facecounter + 1]; + float srcside1[3], srcside2[3], destside1[3], destside2[3], src_trinormorg[3], dest_trinormorg[3], src_trinorm[3], dest_trinorm[3]; + + if(again == 1 && mface[i].v4) + { + sub_v3_v3v3(srcside1, &scs->points_old[mface[i].v3 * 3], &scs->points_old[mface[i].v1 * 3]); + sub_v3_v3v3(destside1, &scs->points[mface[i].v3 * 3], &scs->points[mface[i].v1 * 3]); + + sub_v3_v3v3(srcside2, &scs->points_old[mface[i].v4 * 3], &scs->points_old[mface[i].v1 * 3]); + sub_v3_v3v3(destside2, &scs->points[mface[i].v4 * 3], &scs->points[mface[i].v1 * 3]); + } + else { + sub_v3_v3v3(srcside1, &scs->points_old[mface[i].v2 * 3], &scs->points_old[mface[i].v1 * 3]); + sub_v3_v3v3(destside1, &scs->points[mface[i].v2 * 3], &scs->points[mface[i].v1 * 3]); + + sub_v3_v3v3(srcside2, &scs->points_old[mface[i].v3 * 3], &scs->points_old[mface[i].v1 * 3]); + sub_v3_v3v3(destside2, &scs->points[mface[i].v3 * 3], &scs->points[mface[i].v1 * 3]); + } + + cross_v3_v3v3(src_trinormorg, srcside1, srcside2); + cross_v3_v3v3(dest_trinormorg, destside1, destside2); + + normalize_v3(src_trinormorg); + normalize_v3(dest_trinormorg); + + copy_v3_v3(src_trinorm, src_trinormorg); + copy_v3_v3(dest_trinorm, dest_trinormorg); + + mul_v3_fl(src_trinorm, 0.25 * cell_len); + mul_v3_fl(dest_trinorm, 0.25 * cell_len); + + for(j = 0; j <= divs1; j++) + { + for(k = 0; k <= divs2; k++) + { + float src_p1[3], src_p2[3], src_p3[3], src_p[3]={0,0,0}; + float dest_p1[3], dest_p2[3], dest_p3[3], dest_p[3]={0,0,0}; + const float uf = (float)(j + TRI_UVOFFSET) / (float)(divs1 + 0.0); + const float vf = (float)(k + TRI_UVOFFSET) / (float)(divs2 + 0.0); + float src_tmpvec[3], dest_tmpvec[3]; + + if(uf+vf > 1.0) + { + // printf("bigger - divs1: %d, divs2: %d\n", divs1, divs2); + continue; + } + + copy_v3_v3(src_p1, &scs->points_old[mface[i].v1 * 3]); + copy_v3_v3(dest_p1, &scs->points[mface[i].v1 * 3]); + if(again == 1 && mface[i].v4) + { + copy_v3_v3(src_p2, &scs->points_old[mface[i].v3 * 3]); + copy_v3_v3(dest_p2, &scs->points[mface[i].v3 * 3]); + + copy_v3_v3(src_p3,&scs->points_old[mface[i].v4 * 3]); + copy_v3_v3(dest_p3, &scs->points[mface[i].v4 * 3]); + } + else { + copy_v3_v3(src_p2, &scs->points_old[mface[i].v2 * 3]); + copy_v3_v3(dest_p2, &scs->points[mface[i].v2 * 3]); + copy_v3_v3(src_p3, &scs->points_old[mface[i].v3 * 3]); + copy_v3_v3(dest_p3, &scs->points[mface[i].v3 * 3]); + } + + mul_v3_fl(src_p1, (1.0-uf-vf)); + mul_v3_fl(dest_p1, (1.0-uf-vf)); + + mul_v3_fl(src_p2, uf); + mul_v3_fl(dest_p2, uf); + + mul_v3_fl(src_p3, vf); + mul_v3_fl(dest_p3, vf); + + add_v3_v3v3(src_p, src_p1, src_p2); + add_v3_v3v3(dest_p, dest_p1, dest_p2); + + add_v3_v3(src_p, src_p3); + add_v3_v3(dest_p, dest_p3); + + if(newdivs > divs) + printf("mem problem\n"); + + // mMovPoints.push_back(p + trinorm); + add_v3_v3v3(src_tmpvec, src_p, src_trinorm); + add_v3_v3v3(dest_tmpvec, dest_p, dest_trinorm); + + // mul_m4_v3(ob->obmat, tmpvec); // DG: use local coordinates, we save MAT anyway + copy_v3_v3(&scs->points_old[3 * (dm->getNumVerts(dm) + newdivs)], src_tmpvec); + copy_v3_v3(&scs->points[3 * (dm->getNumVerts(dm) + newdivs)], dest_tmpvec); + newdivs++; + + if(newdivs > divs) + printf("mem problem\n"); + + // mMovPoints.push_back(p - trinorm); + copy_v3_v3(src_tmpvec, src_p); + copy_v3_v3(dest_tmpvec, dest_p); + + sub_v3_v3(src_tmpvec, src_trinorm); + sub_v3_v3(dest_tmpvec, dest_trinorm); + + // mul_m4_v3(ob->obmat, tmpvec); // DG: use local coordinates, we save MAT anyway + copy_v3_v3(&scs->points_old[3 * (dm->getNumVerts(dm) + newdivs)], src_tmpvec); + copy_v3_v3(&scs->points[3 * (dm->getNumVerts(dm) + newdivs)], dest_tmpvec); + newdivs++; + } + } + + if(again == 0 && mface[i].v4) + again++; + else + again = 0; + + facecounter++; + + } while(again!=0); + } + + // scs->numpoints = dm->getNumVerts(dm) + newdivs; + } /*! init triangle divisions */ @@ -472,22 +653,22 @@ static void calcTriangleDivs(Object *ob, MVert *verts, int UNUSED(numverts), MFa // mTriangleDivs3.resize( faces.size() ); size_t i = 0, facecounter = 0; - float maxscale[3] = {1,1,1}; // = channelFindMaxVf(mcScale); + float maxscale[3] = {1,1,1}; // = channelFindMaxVf(mcScale); get max scale value float maxpart = ABS(maxscale[0]); float scaleFac = 0; float fsTri = 0; - if (ABS(maxscale[1])>maxpart) maxpart = ABS(maxscale[1]); - if (ABS(maxscale[2])>maxpart) maxpart = ABS(maxscale[2]); + if(ABS(maxscale[1])>maxpart) maxpart = ABS(maxscale[1]); + if(ABS(maxscale[2])>maxpart) maxpart = ABS(maxscale[2]); scaleFac = 1.0 / maxpart; // featureSize = mLevel[mMaxRefine].nodeSize - fsTri = cell_len * 0.5 * scaleFac; + fsTri = cell_len * 0.75 * scaleFac; // fsTri = cell_len * 0.9; - if (*tridivs) + if(*tridivs) MEM_freeN(*tridivs); *tridivs = MEM_callocN(sizeof(int) * numtris * 3, "Smoke_Tridivs"); - for (i = 0, facecounter = 0; i < numfaces; i++) + for(i = 0, facecounter = 0; i < numfaces; i++) { float p0[3], p1[3], p2[3]; float side1[3]; @@ -506,21 +687,22 @@ static void calcTriangleDivs(Object *ob, MVert *verts, int UNUSED(numverts), MFa sub_v3_v3v3(side2, p2, p0); sub_v3_v3v3(side3, p1, p2); - if (dot_v3v3(side1, side1) > fsTri*fsTri) + if(dot_v3v3(side1, side1) > fsTri*fsTri) { float tmp = normalize_v3(side1); divs1 = (int)ceil(tmp/fsTri); } - if (dot_v3v3(side2, side2) > fsTri*fsTri) + if(dot_v3v3(side2, side2) > fsTri*fsTri) { float tmp = normalize_v3(side2); divs2 = (int)ceil(tmp/fsTri); - /* + /* // debug - if (i==0) + if(i==0) printf("b tmp: %f, fsTri: %f, divs2: %d\n", tmp, fsTri, divs2); */ + } (*tridivs)[3 * facecounter + 0] = divs1; @@ -528,7 +710,7 @@ static void calcTriangleDivs(Object *ob, MVert *verts, int UNUSED(numverts), MFa (*tridivs)[3 * facecounter + 2] = divs3; // TODO quad case - if (faces[i].v4) + if(faces[i].v4) { divs1=0, divs2=0, divs3=0; @@ -545,12 +727,12 @@ static void calcTriangleDivs(Object *ob, MVert *verts, int UNUSED(numverts), MFa sub_v3_v3v3(side2, p2, p0); sub_v3_v3v3(side3, p1, p2); - if (dot_v3v3(side1, side1) > fsTri*fsTri) + if(dot_v3v3(side1, side1) > fsTri*fsTri) { float tmp = normalize_v3(side1); divs1 = (int)ceil(tmp/fsTri); } - if (dot_v3v3(side2, side2) > fsTri*fsTri) + if(dot_v3v3(side2, side2) > fsTri*fsTri) { float tmp = normalize_v3(side2); divs2 = (int)ceil(tmp/fsTri); @@ -568,19 +750,19 @@ static void calcTriangleDivs(Object *ob, MVert *verts, int UNUSED(numverts), MFa static void smokeModifier_freeDomain(SmokeModifierData *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); - if (smd->domain->wt) + if(smd->domain->wt) smoke_turbulence_free(smd->domain->wt); - if (smd->domain->effector_weights) + if(smd->domain->effector_weights) MEM_freeN(smd->domain->effector_weights); smd->domain->effector_weights = NULL; @@ -594,10 +776,10 @@ static void smokeModifier_freeDomain(SmokeModifierData *smd) static void smokeModifier_freeFlow(SmokeModifierData *smd) { - if (smd->flow) + if(smd->flow) { /* - if (smd->flow->bvh) + if(smd->flow->bvh) { free_bvhtree_from_mesh(smd->flow->bvh); MEM_freeN(smd->flow->bvh); @@ -611,22 +793,37 @@ static void smokeModifier_freeFlow(SmokeModifierData *smd) static void smokeModifier_freeCollision(SmokeModifierData *smd) { - if (smd->coll) + if(smd->coll) { - if (smd->coll->points) + SmokeCollSettings *scs = smd->coll; + + if(scs->numpoints) { - MEM_freeN(smd->coll->points); - smd->coll->points = NULL; + if(scs->points) + { + MEM_freeN(scs->points); + scs->points = NULL; + } + if(scs->points_old) + { + MEM_freeN(scs->points_old); + scs->points_old = NULL; + } + if(scs->tridivs) + { + MEM_freeN(scs->tridivs); + scs->tridivs = NULL; + } } - if (smd->coll->bvhtree) + if(scs->bvhtree) { - BLI_bvhtree_free(smd->coll->bvhtree); - smd->coll->bvhtree = NULL; + BLI_bvhtree_free(scs->bvhtree); + scs->bvhtree = NULL; } #ifdef USE_SMOKE_COLLISION_DM - if (smd->coll->dm) + if(smd->coll->dm) smd->coll->dm->release(smd->coll->dm); smd->coll->dm = NULL; #endif @@ -638,7 +835,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; @@ -647,15 +844,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; @@ -667,10 +864,10 @@ void smokeModifier_reset(struct SmokeModifierData *smd) // printf("reset domain end\n"); } - else if (smd->flow) + else if(smd->flow) { /* - if (smd->flow->bvh) + if(smd->flow->bvh) { free_bvhtree_from_mesh(smd->flow->bvh); MEM_freeN(smd->flow->bvh); @@ -678,33 +875,33 @@ void smokeModifier_reset(struct SmokeModifierData *smd) smd->flow->bvh = NULL; */ } - else if (smd->coll) + else if(smd->coll) { - if (smd->coll->points) - { - MEM_freeN(smd->coll->points); - smd->coll->points = NULL; - } + SmokeCollSettings *scs = smd->coll; - if (smd->coll->bvhtree) + if(scs->numpoints && scs->points) { - BLI_bvhtree_free(smd->coll->bvhtree); - smd->coll->bvhtree = NULL; + MEM_freeN(scs->points); + scs->points = NULL; + + if(scs->points_old) + { + MEM_freeN(scs->points_old); + scs->points_old = NULL; + } + if(scs->tridivs) + { + MEM_freeN(scs->tridivs); + scs->tridivs = NULL; + } } - -#ifdef USE_SMOKE_COLLISION_DM - if (smd->coll->dm) - smd->coll->dm->release(smd->coll->dm); - smd->coll->dm = NULL; -#endif - } } } void smokeModifier_free (SmokeModifierData *smd) { - if (smd) + if(smd) { smokeModifier_freeDomain(smd); smokeModifier_freeFlow(smd); @@ -714,11 +911,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"); @@ -745,7 +942,7 @@ void smokeModifier_createType(struct SmokeModifierData *smd) smd->domain->beta = 0.1; smd->domain->time_scale = 1.0; smd->domain->vorticity = 2.0; - smd->domain->border_collisions = 1; // vertically non-colliding + smd->domain->border_collisions = SM_BORDER_OPEN; // open domain smd->domain->flags = MOD_SMOKE_DISSOLVE_LOG | MOD_SMOKE_HIGH_SMOOTH; smd->domain->strength = 2.0; smd->domain->noise = MOD_SMOKE_NOISEWAVE; @@ -755,9 +952,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"); @@ -773,17 +970,23 @@ 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"); smd->coll->smd = smd; smd->coll->points = NULL; + smd->coll->points_old = NULL; + smd->coll->tridivs = NULL; + smd->coll->vel = NULL; smd->coll->numpoints = 0; + smd->coll->numtris = 0; smd->coll->bvhtree = NULL; + smd->coll->type = 0; // static obstacle + smd->coll->dx = 1.0f / 50.0f; #ifdef USE_SMOKE_COLLISION_DM smd->coll->dm = NULL; @@ -818,7 +1021,7 @@ void smokeModifier_copy(struct SmokeModifierData *smd, struct SmokeModifierData MEM_freeN(tsmd->domain->effector_weights); tsmd->domain->effector_weights = MEM_dupallocN(smd->domain->effector_weights); - } + } else if (tsmd->flow) { tsmd->flow->density = smd->flow->density; tsmd->flow->temp = smd->flow->temp; @@ -845,15 +1048,15 @@ static int get_lamp(Scene *scene, float *light) 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; } @@ -865,497 +1068,603 @@ static int get_lamp(Scene *scene, float *light) static void smoke_calc_domain(Scene *scene, Object *ob, SmokeModifierData *smd) { +#if 0 SmokeDomainSettings *sds = smd->domain; GroupObject *go = NULL; - Base *base = NULL; + Base *base = NULL; - // do collisions, needs to be done before emission, so that smoke isn't emitted inside collision cells - if (1) + /* do collisions, needs to be done before emission, so that smoke isn't emitted inside collision cells */ + if(1) { - Object *otherobj = NULL; - ModifierData *md = NULL; + unsigned int i; + Object **collobjs = NULL; + unsigned int numcollobj = 0; + collobjs = get_collisionobjects(scene, ob, sds->coll_group, &numcollobj); - if (sds->coll_group) // we use groups since we have 2 domains - go = sds->coll_group->gobject.first; - else - base = scene->base.first; - - while (base || go) + for(i = 0; i < numcollobj; i++) { - otherobj = NULL; - if (sds->coll_group) - { - if (go->ob) - otherobj = go->ob; - } - else - otherobj = base->object; - if (!otherobj) - { - if (sds->coll_group) - go = go->next; - else - base= base->next; - continue; - } - md = modifiers_findByType(otherobj, eModifierType_Smoke); + Object *collob= collobjs[i]; + SmokeModifierData *smd2 = (SmokeModifierData*)modifiers_findByType(collob, eModifierType_Smoke); // check for active smoke modifier - if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) + // if(md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) + // SmokeModifierData *smd2 = (SmokeModifierData *)md; + + if((smd2->type & MOD_SMOKE_TYPE_COLL) && smd2->coll && smd2->coll->points && smd2->coll->points_old) { - SmokeModifierData *smd2 = (SmokeModifierData *)md; + // ??? anything to do here? + + // TODO: only something to do for ANIMATED obstacles: need to update positions + + } + } + + if(collobjs) + MEM_freeN(collobjs); + } + +#endif +} - if ((smd2->type & MOD_SMOKE_TYPE_COLL) && smd2->coll && smd2->coll->points) +/* Animated obstacles: dx_step = ((x_new - x_old) / totalsteps) * substep */ +static void update_obstacles(Scene *scene, Object *ob, SmokeDomainSettings *sds, float dt, int substep, int totalsteps) +{ + Object **collobjs = NULL; + unsigned int numcollobj = 0; + + unsigned int collIndex; + unsigned char *obstacles = smoke_get_obstacle(sds->fluid); + float *velx = NULL; + float *vely = NULL; + float *velz = NULL; + float *velxOrig = smoke_get_velocity_x(sds->fluid); + float *velyOrig = smoke_get_velocity_y(sds->fluid); + float *velzOrig = smoke_get_velocity_z(sds->fluid); + // float *density = smoke_get_density(sds->fluid); + unsigned int z; + + 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++) + { + if(obstacles[z]) + { + // density[z] = 0; + + velxOrig[z] = 0; + velyOrig[z] = 0; + velzOrig[z] = 0; + } + + if(obstacles[z] & 8) // Do not delete static obstacles + { + obstacles[z] = 0; + } + + velx[z] = 0; + vely[z] = 0; + velz[z] = 0; + } + + collobjs = get_collisionobjects(scene, ob, sds->coll_group, &numcollobj, eModifierType_Smoke); + + // update obstacle tags in cells + for(collIndex = 0; collIndex < numcollobj; collIndex++) + { + 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 && smd2->coll->points && smd2->coll->points_old) + { + SmokeCollSettings *scs = smd2->coll; + unsigned int i; + + /* + // DG TODO: support static cobstacles, but basicly we could even support static + rigid with one set of code + if(scs->type > SM_COLL_STATIC) + */ + + /* Handle collisions */ + for(i = 0; i < scs->numpoints; i++) + { + // 1. get corresponding cell + int cell[3]; + float pos[3], oldpos[3], vel[3]; + float cPos[3], cOldpos[3]; /* current position in substeps */ + int badcell = 0; + size_t index; + int j; + + // translate local points into global positions + copy_v3_v3(cPos, &scs->points[3 * i]); + mul_m4_v3(scs->mat, cPos); + copy_v3_v3(pos, cPos); + + copy_v3_v3(cOldpos, &scs->points_old[3 * i]); + mul_m4_v3(scs->mat_old, cOldpos); + copy_v3_v3(oldpos, cOldpos); + + /* support for rigid bodies, armatures etc */ { - // we got nice collision object - SmokeCollSettings *scs = smd2->coll; - size_t i, j; - unsigned char *obstacles = smoke_get_obstacle(smd->domain->fluid); + float tmp[3]; - for (i = 0; i < scs->numpoints; i++) - { - int badcell = 0; - size_t index = 0; - int cell[3]; + /* x_current = x_old + (x_new - x_old) * step_current / steps_total */ + float mulStep = (float)(((float)substep) / ((float)totalsteps)); - // 1. get corresponding cell - get_cell(smd->domain->p0, smd->domain->res, smd->domain->dx, &scs->points[3 * i], cell, 0); - - // check if cell is valid (in the domain boundary) - for (j = 0; j < 3; j++) - if ((cell[j] > sds->res[j] - 1) || (cell[j] < 0)) - { - badcell = 1; - break; - } - - if (badcell) - continue; - // 2. set cell values (heat, density and velocity) - index = smoke_get_index(cell[0], sds->res[0], cell[1], sds->res[1], cell[2]); - - // printf("cell[0]: %d, cell[1]: %d, cell[2]: %d\n", cell[0], cell[1], cell[2]); - // printf("res[0]: %d, res[1]: %d, res[2]: %d, index: %d\n\n", sds->res[0], sds->res[1], sds->res[2], index); - obstacles[index] = 1; - // for moving gobstacles - /* - const LbmFloat maxVelVal = 0.1666; - const LbmFloat maxusqr = maxVelVal*maxVelVal*3. *1.5; - - LbmVec objvel = vec2L((mMOIVertices[n]-mMOIVerticesOld[n]) /dvec); - { - const LbmFloat usqr = (objvel[0]*objvel[0]+objvel[1]*objvel[1]+objvel[2]*objvel[2])*1.5; - USQRMAXCHECK(usqr, objvel[0],objvel[1],objvel[2], mMaxVlen, mMxvx,mMxvy,mMxvz); - if (usqr>maxusqr) { - // cutoff at maxVelVal - for (int jj=0; jj<3; jj++) { - if (objvel[jj] > 0.0) objvel[jj] = maxVelVal; - if (objvel[jj] < 0.0) objvel[jj] = -maxVelVal; - } - } - } - const LbmFloat dp=dot(objvel, vec2L((*pNormals)[n]) ); - const LbmVec oldov=objvel; // debug - objvel = vec2L((*pNormals)[n]) *dp; - */ + sub_v3_v3v3(tmp, cPos, cOldpos); + mul_v3_fl(tmp, mulStep); + add_v3_v3(cOldpos, tmp); + } + + sub_v3_v3v3(vel, pos, oldpos); + /* Scale velocity to incorperate the object movement during this step */ + mul_v3_fl(vel, 1.0 / (totalsteps * dt)); + // mul_v3_fl(vel, 1.0 / dt); + + // DG TODO: cap velocity to maxVelMag (or maxvel) + + // oldpos + velocity * dt = newpos + get_cell(sds->p0, sds->res, sds->dx, cOldpos /* use current position here instead of "pos" */, cell, 0); + + // check if cell is valid (in the domain boundary) + for(j = 0; j < 3; j++) + if((cell[j] > sds->res[j] - 1) || (cell[j] < 0)) + { + badcell = 1; + break; } + + if(badcell) + continue; + + // 2. set cell values (heat, density and velocity) + index = smoke_get_index(cell[0], sds->res[0], cell[1], sds->res[1], cell[2]); + + // Don't overwrite existing obstacles + if(obstacles[index]) + continue; + + // printf("cell[0]: %d, cell[1]: %d, cell[2]: %d\n", cell[0], cell[1], cell[2]); + // printf("res[0]: %d, res[1]: %d, res[2]: %d, index: %d\n\n", sds->res[0], sds->res[1], sds->res[2], index); + obstacles[index] = 1 | 8 /* ANIMATED */; + + if(len_v3(vel) > FLT_EPSILON) + { + // Collision object is moving + + velx[index] = vel[0]; // use "+="? + vely[index] = vel[1]; + velz[index] = vel[2]; } } - - if (sds->coll_group) - go = go->next; - else - base= base->next; } } - // do flows and fluids - if (1) + if(collobjs) + MEM_freeN(collobjs); +} + +static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sds, float time) +{ + Object **flowobjs = NULL; + unsigned int numflowobj = 0; + unsigned int flowIndex; + + flowobjs = get_collisionobjects(scene, ob, sds->fluid_group, &numflowobj, eModifierType_Smoke); + + // update obstacle tags in cells + for(flowIndex = 0; flowIndex < numflowobj; flowIndex++) { - Object *otherobj = NULL; - ModifierData *md = NULL; - if (sds->fluid_group) // we use groups since we have 2 domains - go = sds->fluid_group->gobject.first; - else - base = scene->base.first; - while (base || go) - { - otherobj = NULL; - if (sds->fluid_group) - { - if (go->ob) - otherobj = go->ob; - } - else - otherobj = base->object; - if (!otherobj) - { - if (sds->fluid_group) - go = go->next; - else - base= base->next; + Object *collob= flowobjs[flowIndex]; + SmokeModifierData *smd2 = (SmokeModifierData*)modifiers_findByType(collob, eModifierType_Smoke); - continue; - } + // check for initialized smoke object + if((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) + { + // we got nice flow object + SmokeFlowSettings *sfs = smd2->flow; - md = modifiers_findByType(otherobj, eModifierType_Smoke); - - // check for active smoke modifier - if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) + if(sfs && sfs->psys && sfs->psys->part && sfs->psys->part->type==PART_EMITTER) // is particle system selected { - SmokeModifierData *smd2 = (SmokeModifierData *)md; - - // check for initialized smoke object - if ((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) + ParticleSimulationData sim; + ParticleSystem *psys = sfs->psys; + int totpart=psys->totpart, totchild; + int p = 0; + float *density = smoke_get_density(sds->fluid); + float *bigdensity = smoke_turbulence_get_density(sds->wt); + float *heat = smoke_get_heat(sds->fluid); + 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); + // DG TODO UNUSED unsigned char *obstacleAnim = smoke_get_obstacle_anim(sds->fluid); + int bigres[3]; + short absolute_flow = (sfs->flags & MOD_SMOKE_FLOW_ABSOLUTE); + short high_emission_smoothing = bigdensity ? (sds->flags & MOD_SMOKE_HIGH_SMOOTH) : 0; + + /* + * A temporary volume map used to store whole emissive + * area to be added to smoke density and interpolated + * for high resolution smoke. + */ + float *temp_emission_map = NULL; + + sim.scene = scene; + sim.ob = collob; + sim.psys = psys; + + // initialize temp emission map + if(!(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW)) { - // we got nice flow object - SmokeFlowSettings *sfs = smd2->flow; - - if (sfs && sfs->psys && sfs->psys->part && sfs->psys->part->type==PART_EMITTER) // is particle system selected + int i; + temp_emission_map = MEM_callocN(sizeof(float) * sds->res[0]*sds->res[1]*sds->res[2], "SmokeTempEmission"); + // set whole volume to 0.0f + for (i=0; i<sds->res[0]*sds->res[1]*sds->res[2]; i++) { + temp_emission_map[i] = 0.0f; + } + } + + // mostly copied from particle code + if(psys->part->type==PART_HAIR) + { + /* + if(psys->childcache) { - ParticleSimulationData sim; - ParticleSystem *psys = sfs->psys; - int totpart=psys->totpart, totchild; - int p = 0; - float *density = smoke_get_density(sds->fluid); - float *bigdensity = smoke_turbulence_get_density(sds->wt); - float *heat = smoke_get_heat(sds->fluid); - 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); - int bigres[3]; - short absolute_flow = (sfs->flags & MOD_SMOKE_FLOW_ABSOLUTE); - short high_emission_smoothing = bigdensity ? (smd->domain->flags & MOD_SMOKE_HIGH_SMOOTH) : 0; - - /* - * A temporary volume map used to store whole emissive - * area to be added to smoke density and interpolated - * for high resolution smoke. - */ - float *temp_emission_map = NULL; - - sim.scene = scene; - sim.ob = otherobj; - sim.psys = psys; - - // initialize temp emission map - if (!(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW)) + totchild = psys->totchildcache; + } + else + */ + + // TODO: PART_HAIR not supported whatsoever + totchild=0; + } + else + totchild=psys->totchild*psys->part->disp/100; + + for(p=0; p<totpart+totchild; p++) + { + int cell[3]; + size_t i = 0; + size_t index = 0; + int badcell = 0; + ParticleKey state; + + 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)) + continue; + } + + state.time = time; + if(psys_get_particle_state(&sim, p, &state, 0) == 0) + continue; + + // copy_v3_v3(pos, pa->state.co); + // mul_m4_v3(ob->imat, pos); + // 1. get corresponding cell + get_cell(sds->p0, sds->res, sds->dx, state.co, cell, 0); + // check if cell is valid (in the domain boundary) + for(i = 0; i < 3; i++) + { + if((cell[i] > sds->res[i] - 1) || (cell[i] < 0)) + { + badcell = 1; + break; + } + } + if(badcell) + continue; + // 2. set cell values (heat, density and velocity) + index = smoke_get_index(cell[0], sds->res[0], cell[1], sds->res[1], cell[2]); + if(!(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) && !(obstacle[index])) // this is inflow + { + // heat[index] += sfs->temp * 0.1; + // density[index] += sfs->density * 0.1; + heat[index] = sfs->temp; + + // Add emitter density to temp emission map + temp_emission_map[index] = sfs->density; + + // Uses particle velocity as initial velocity for smoke + if(sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY && (psys->part->phystype != PART_PHYS_NO)) { - int i; - temp_emission_map = MEM_callocN(sizeof(float) * sds->res[0]*sds->res[1]*sds->res[2], "SmokeTempEmission"); - // set whole volume to 0.0f - for (i=0; i<sds->res[0]*sds->res[1]*sds->res[2]; i++) { - temp_emission_map[i] = 0.0f; - } - } - - // mostly copied from particle code - if (psys->part->type==PART_HAIR) + velocity_x[index] = state.vel[0]*sfs->vel_multi; + velocity_y[index] = state.vel[1]*sfs->vel_multi; + velocity_z[index] = state.vel[2]*sfs->vel_multi; + } + } + else if(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) // outflow + { + heat[index] = 0.f; + density[index] = 0.f; + velocity_x[index] = 0.f; + velocity_y[index] = 0.f; + velocity_z[index] = 0.f; + // we need different handling for the high-res feature + if(bigdensity) { - /* - if (psys->childcache) - { - totchild = psys->totchildcache; - } - else - */ - - // TODO: PART_HAIR not supported whatsoever - totchild=0; + // init all surrounding cells according to amplification, too + int i, j, k; + smoke_turbulence_get_res(sds->wt, bigres); + + for(i = 0; i < sds->amplify + 1; i++) + for(j = 0; j < sds->amplify + 1; j++) + for(k = 0; k < sds->amplify + 1; k++) + { + index = smoke_get_index((sds->amplify + 1)* cell[0] + i, bigres[0], (sds->amplify + 1)* cell[1] + j, bigres[1], (sds->amplify + 1)* cell[2] + k); + bigdensity[index] = 0.f; + } } - else - totchild=psys->totchild*psys->part->disp/100; - - for (p=0; p<totpart+totchild; p++) - { - int cell[3]; - size_t i = 0; - size_t index = 0; - int badcell = 0; - ParticleKey state; + } + } // particles loop + + // apply emission values + if(!(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW)) + { + // initialize variables + int ii, jj, kk, x, y, z, block_size; + size_t index, index_big; + + smoke_turbulence_get_res(sds->wt, bigres); + block_size = sds->amplify + 1; // high res block size - if (p < totpart) + // loop through every low res cell + for(x = 0; x < sds->res[0]; x++) + for(y = 0; y < sds->res[1]; y++) + for(z = 0; z < sds->res[2]; z++) { - 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)) - continue; - } + // neighbor cell emission densities (for high resolution smoke smooth interpolation) + float c000, c001, c010, c011, c100, c101, c110, c111; - state.time = smd->time; - if (psys_get_particle_state(&sim, p, &state, 0) == 0) - continue; - - // copy_v3_v3(pos, pa->state.co); - // mul_m4_v3(ob->imat, pos); - // 1. get corresponding cell - get_cell(smd->domain->p0, smd->domain->res, smd->domain->dx, state.co, cell, 0); - // check if cell is valid (in the domain boundary) - for (i = 0; i < 3; i++) - { - if ((cell[i] > sds->res[i] - 1) || (cell[i] < 0)) - { - badcell = 1; - break; - } - } - if (badcell) - continue; - // 2. set cell values (heat, density and velocity) - index = smoke_get_index(cell[0], sds->res[0], cell[1], sds->res[1], cell[2]); - if (!(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) && !(obstacle[index])) // this is inflow - { - // heat[index] += sfs->temp * 0.1; - // density[index] += sfs->density * 0.1; - heat[index] = sfs->temp; - - // Add emitter density to temp emission map - temp_emission_map[index] = sfs->density; - - // Uses particle velocity as initial velocity for smoke - if (sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY && (psys->part->phystype != PART_PHYS_NO)) - { - velocity_x[index] = state.vel[0]*sfs->vel_multi; - velocity_y[index] = state.vel[1]*sfs->vel_multi; - velocity_z[index] = state.vel[2]*sfs->vel_multi; - } - } - else if (sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) // outflow - { - heat[index] = 0.f; - density[index] = 0.f; - velocity_x[index] = 0.f; - velocity_y[index] = 0.f; - velocity_z[index] = 0.f; - // we need different handling for the high-res feature - if (bigdensity) + c000 = (x>0 && y>0 && z>0) ? temp_emission_map[smoke_get_index(x-1, sds->res[0], y-1, sds->res[1], z-1)] : 0; + c001 = (x>0 && y>0) ? temp_emission_map[smoke_get_index(x-1, sds->res[0], y-1, sds->res[1], z)] : 0; + c010 = (x>0 && z>0) ? temp_emission_map[smoke_get_index(x-1, sds->res[0], y, sds->res[1], z-1)] : 0; + c011 = (x>0) ? temp_emission_map[smoke_get_index(x-1, sds->res[0], y, sds->res[1], z)] : 0; + + c100 = (y>0 && z>0) ? temp_emission_map[smoke_get_index(x, sds->res[0], y-1, sds->res[1], z-1)] : 0; + c101 = (y>0) ? temp_emission_map[smoke_get_index(x, sds->res[0], y-1, sds->res[1], z)] : 0; + c110 = (z>0) ? temp_emission_map[smoke_get_index(x, sds->res[0], y, sds->res[1], z-1)] : 0; + c111 = temp_emission_map[smoke_get_index(x, sds->res[0], y, sds->res[1], z)]; // this cell + + // get cell index + index = smoke_get_index(x, sds->res[0], y, sds->res[1], z); + + // add emission to low resolution density + if (absolute_flow) { - // init all surrounding cells according to amplification, too - int i, j, k; - smoke_turbulence_get_res(smd->domain->wt, bigres); - - for (i = 0; i < smd->domain->amplify + 1; i++) - for (j = 0; j < smd->domain->amplify + 1; j++) - for (k = 0; k < smd->domain->amplify + 1; k++) - { - index = smoke_get_index((smd->domain->amplify + 1)* cell[0] + i, bigres[0], (smd->domain->amplify + 1)* cell[1] + j, bigres[1], (smd->domain->amplify + 1)* cell[2] + k); - bigdensity[index] = 0.f; - } + if (temp_emission_map[index]>0) + density[index] = temp_emission_map[index]; } - } - } // particles loop + else + { + density[index] += temp_emission_map[index]; + if (density[index]>1) + density[index]=1.0f; + } - // apply emission values - if (!(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW)) { + smoke_turbulence_get_res(sds->wt, bigres); - // initialize variables - int ii, jj, kk, x, y, z, block_size; - size_t index, index_big; + /* loop through high res blocks if high res enabled */ + if (bigdensity) + for(ii = 0; ii < block_size; ii++) + for(jj = 0; jj < block_size; jj++) + for(kk = 0; kk < block_size; kk++) + { - smoke_turbulence_get_res(smd->domain->wt, bigres); - block_size = smd->domain->amplify + 1; // high res block size + float fx,fy,fz, interpolated_value; + int shift_x, shift_y, shift_z; - // loop through every low res cell - for (x = 0; x < sds->res[0]; x++) - for (y = 0; y < sds->res[1]; y++) - for (z = 0; z < sds->res[2]; z++) - { + /* + * Do volume interpolation if emitter smoothing + * is enabled + */ + if (high_emission_smoothing) + { + // convert block position to relative + // 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; + + // 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; + + + // add some contrast / sharpness + // depending on hi-res block size + + interpolated_value = (interpolated_value-0.4f*sfs->density)*(block_size/2) + 0.4f*sfs->density; + if (interpolated_value<0.0f) interpolated_value = 0.0f; + if (interpolated_value>1.0f) interpolated_value = 1.0f; + + // shift smoke block index + // (because pixel center is actually + // in halfway of the low res block) + shift_x = (x < 1) ? 0 : block_size/2; + shift_y = (y < 1) ? 0 : block_size/2; + shift_z = (z < 1) ? 0 : block_size/2; + } + else + { + // without interpolation use same low resolution + // block value for all hi-res blocks + interpolated_value = c111; + shift_x = 0; + shift_y = 0; + shift_z = 0; + } - // neighbor cell emission densities (for high resolution smoke smooth interpolation) - float c000, c001, c010, c011, c100, c101, c110, c111; + // get shifted index for current high resolution block + index_big = smoke_get_index(block_size * x + ii - shift_x, bigres[0], block_size * y + jj - shift_y, bigres[1], block_size * z + kk - shift_z); - c000 = (x>0 && y>0 && z>0) ? temp_emission_map[smoke_get_index(x-1, sds->res[0], y-1, sds->res[1], z-1)] : 0; - c001 = (x>0 && y>0) ? temp_emission_map[smoke_get_index(x-1, sds->res[0], y-1, sds->res[1], z)] : 0; - c010 = (x>0 && z>0) ? temp_emission_map[smoke_get_index(x-1, sds->res[0], y, sds->res[1], z-1)] : 0; - c011 = (x>0) ? temp_emission_map[smoke_get_index(x-1, sds->res[0], y, sds->res[1], z)] : 0; + // add emission data to high resolution density + if (absolute_flow) + { + if (interpolated_value > 0) + bigdensity[index_big] = interpolated_value; + } + else + { + bigdensity[index_big] += interpolated_value; - c100 = (y>0 && z>0) ? temp_emission_map[smoke_get_index(x, sds->res[0], y-1, sds->res[1], z-1)] : 0; - c101 = (y>0) ? temp_emission_map[smoke_get_index(x, sds->res[0], y-1, sds->res[1], z)] : 0; - c110 = (z>0) ? temp_emission_map[smoke_get_index(x, sds->res[0], y, sds->res[1], z-1)] : 0; - c111 = temp_emission_map[smoke_get_index(x, sds->res[0], y, sds->res[1], z)]; // this cell + if (bigdensity[index_big]>1) + bigdensity[index_big]=1.0f; + } + } // end of hires loop + } // end of low res loop + // free temporary emission map + if (temp_emission_map) + MEM_freeN(temp_emission_map); - // get cell index - index = smoke_get_index(x, sds->res[0], y, sds->res[1], z); + } // end emission + } + } + } - // add emission to low resolution density - if (absolute_flow) {if (temp_emission_map[index]>0) density[index] = temp_emission_map[index];} - else { - density[index] += temp_emission_map[index]; - if (density[index]>1) density[index]=1.0f; - } + if(flowobjs) + MEM_freeN(flowobjs); +} - smoke_turbulence_get_res(smd->domain->wt, bigres); +static void update_effectors(Scene *scene, Object *ob, SmokeDomainSettings *sds, float dt) +{ + ListBase *effectors = pdInitEffectors(scene, ob, NULL, sds->effector_weights); + if(effectors) + { + float *density = smoke_get_density(sds->fluid); + float *force_x = smoke_get_force_x(sds->fluid); + float *force_y = smoke_get_force_y(sds->fluid); + float *force_z = smoke_get_force_z(sds->fluid); + 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); + int x, y, z; + + // precalculate wind forces + for(x = 0; x < sds->res[0]; x++) + for(y = 0; y < sds->res[1]; y++) + for(z = 0; z < sds->res[2]; z++) + { + EffectedPoint epoint; + 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]; + + voxelCenter[0] = sds->p0[0] + sds->dx * x + sds->dx * 0.5; + voxelCenter[1] = sds->p0[1] + sds->dx * y + sds->dx * 0.5; + voxelCenter[2] = sds->p0[2] + sds->dx * z + sds->dx * 0.5; + + pd_point_from_loc(scene, voxelCenter, vel, index, &epoint); + pdDoEffectors(effectors, NULL, sds->effector_weights, &epoint, retvel, NULL); + + // 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); + } + } + pdEndEffectors(&effectors); +} - /* - loop through high res blocks if high res enabled - */ - if (bigdensity) - 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; - int shift_x, shift_y, shift_z; - - - /* - * Do volume interpolation if emitter smoothing - * is enabled - */ - if (high_emission_smoothing) { - // convert block position to relative - // 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; - - // 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; - - - // add some contrast / sharpness - // depending on hi-res block size - - interpolated_value = (interpolated_value-0.4f*sfs->density)*(block_size/2) + 0.4f*sfs->density; - if (interpolated_value<0.0f) interpolated_value = 0.0f; - if (interpolated_value>1.0f) interpolated_value = 1.0f; - - // shift smoke block index - // (because pixel center is actually - // in halfway of the low res block) - shift_x = (x < 1) ? 0 : block_size/2; - shift_y = (y < 1) ? 0 : block_size/2; - shift_z = (z < 1) ? 0 : block_size/2; - } - else { - // without interpolation use same low resolution - // block value for all hi-res blocks - interpolated_value = c111; - shift_x = 0; - shift_y = 0; - shift_z = 0; - } - - // get shifted index for current high resolution block - index_big = smoke_get_index(block_size * x + ii - shift_x, bigres[0], block_size * y + jj - shift_y, bigres[1], block_size * z + kk - shift_z); - - // add emission data to high resolution density - if (absolute_flow) {if (interpolated_value > 0) bigdensity[index_big] = interpolated_value;} - else { - bigdensity[index_big] += interpolated_value; - if (bigdensity[index_big]>1) bigdensity[index_big]=1.0f; - } +static void step(Scene *scene, Object *ob, SmokeModifierData *smd, float fps) +{ + /* stability values copied from wturbulence.cpp */ + const int maxSubSteps = 25; + float maxVel; + // maxVel should be 1.5 (1.5 cell max movement) * dx (cell size) - } // end of hires loop + float dt = DT_DEFAULT; + float maxVelMag = 0.0f; + int totalSubsteps; + int substep = 0; + float dtSubdiv; - } // end of low res loop + SmokeDomainSettings *sds = smd->domain; - // free temporary emission map - if (temp_emission_map) MEM_freeN(temp_emission_map); + /* 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]; - } // end emission + float *velX = smoke_get_velocity_x(sds->fluid); + float *velY = smoke_get_velocity_y(sds->fluid); + float *velZ = smoke_get_velocity_z(sds->fluid); + size_t i; + /* adapt timestep for different framerates, dt = 0.1 is at 25fps */ + dt *= (25.0f / fps); - - } - else { - /* - for () - { - // no psys - BVHTreeNearest nearest; - nearest.index = -1; - nearest.dist = FLT_MAX; + // printf("test maxVel: %f\n", (sds->dx * 1.5) / dt); // gives 0.9 + maxVel = (sds->dx * 1.5); - BLI_bvhtree_find_nearest(sfs->bvh->tree, pco, &nearest, sfs->bvh->nearest_callback, sfs->bvh); - }*/ - } - } - } - if (sds->fluid_group) - go = go->next; - else - base= base->next; - } + for(i = 0; i < size; i++) + { + float vtemp = (velX[i]*velX[i]+velY[i]*velY[i]+velZ[i]*velZ[i]); + if(vtemp > maxVelMag) + maxVelMag = vtemp; } - // do effectors + maxVelMag = sqrt(maxVelMag) * dt * sds->time_scale; + totalSubsteps = (int)((maxVelMag / maxVel) + 1.0f); /* always round up */ + totalSubsteps = (totalSubsteps < 1) ? 1 : totalSubsteps; + totalSubsteps = (totalSubsteps > maxSubSteps) ? maxSubSteps : totalSubsteps; + + // totalSubsteps = 2.0f; // DEBUG + + dtSubdiv = (float)dt / (float)totalSubsteps; + + // printf("totalSubsteps: %d, maxVelMag: %f, dt: %f\n", totalSubsteps, maxVelMag, dt); + + for(substep = 0; substep < totalSubsteps; substep++) { - ListBase *effectors = pdInitEffectors(scene, ob, NULL, sds->effector_weights); + // calc animated obstacle velocities + update_obstacles(scene, ob, sds, dtSubdiv, substep, totalSubsteps); + update_flowsfluids(scene, ob, sds, smd->time); + update_effectors(scene, ob, sds, dtSubdiv); // DG TODO? problem --> uses forces instead of velocity, need to check how they need to be changed with variable dt - if (effectors) - { - float *density = smoke_get_density(sds->fluid); - float *force_x = smoke_get_force_x(sds->fluid); - float *force_y = smoke_get_force_y(sds->fluid); - float *force_z = smoke_get_force_z(sds->fluid); - 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); - int x, y, z; - - // precalculate wind forces - for (x = 0; x < sds->res[0]; x++) - for (y = 0; y < sds->res[1]; y++) - for (z = 0; z < sds->res[2]; z++) - { - EffectedPoint epoint; - 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) - continue; - - vel[0] = velocity_x[index]; - vel[1] = velocity_y[index]; - vel[2] = velocity_z[index]; - - voxelCenter[0] = sds->p0[0] + sds->dx * x + sds->dx * 0.5; - voxelCenter[1] = sds->p0[1] + sds->dx * y + sds->dx * 0.5; - voxelCenter[2] = sds->p0[2] + sds->dx * z + sds->dx * 0.5; - - pd_point_from_loc(scene, voxelCenter, vel, index, &epoint); - pdDoEffectors(effectors, NULL, sds->effector_weights, &epoint, retvel, NULL); - - // 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); - } - } + smoke_step(sds->fluid, dtSubdiv); - pdEndEffectors(&effectors); - } + // move animated obstacle: Done in update_obstacles() */ + // where to delete old obstacles from array? Done in update_obstacles() */ + } } + void smokeModifier_do(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 (scene->r.cfra > smd->time) + if(scene->r.cfra > smd->time) { // XXX TODO smd->time = scene->r.cfra; @@ -1366,40 +1675,102 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM copy_m4_m4(smd->flow->mat, ob->obmat); */ } - 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) + /* Check if domain resolution changed */ + /* DG TODO: can this be solved more elegant using dependancy graph? */ + { + SmokeCollSettings *scs = smd->coll; + Base *base = scene->base.first; + int changed = 0; + float dx = FLT_MAX; + int haveDomain = 0; + + for ( ; base; base = base->next) + { + SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(base->object, eModifierType_Smoke); + + if (smd2 && (smd2->type & MOD_SMOKE_TYPE_DOMAIN) && smd2->domain) + { + SmokeDomainSettings *sds = smd2->domain; + + if(sds->dx < dx) + { + dx = sds->dx; + changed = 1; + } + + haveDomain = 1; + } + } + + if(!haveDomain) + return; + + if(changed) + { + if(dx != scs->dx) + { + scs->dx = dx; + smokeModifier_reset(smd); + } + } + } + + if(scene->r.cfra >= smd->time) smokeModifier_init(smd, ob, scene, dm); - if (scene->r.cfra > smd->time) + if(scene->r.cfra > smd->time) { - // XXX TODO + unsigned int i; + SmokeCollSettings *scs = smd->coll; + float *points_old = scs->points_old; + float *points = scs->points; + unsigned int numpoints = scs->numpoints; + + // XXX TODO <-- DG: what is TODO here? smd->time = scene->r.cfra; -#ifdef USE_SMOKE_COLLISION_DM - if (smd->coll->dm) - smd->coll->dm->release(smd->coll->dm); + // rigid movement support + copy_m4_m4(scs->mat_old, scs->mat); + copy_m4_m4(scs->mat, ob->obmat); - smd->coll->dm = CDDM_copy_from_tessface(dm); -#endif + if(scs->type != SM_COLL_ANIMATED) // if(not_animated) + { + // nothing to do, "mat" is already up to date + } + else + { + // XXX TODO: need to update positions + divs - // rigid movement support - copy_m4_m4(smd->coll->mat_old, smd->coll->mat); - copy_m4_m4(smd->coll->mat, ob->obmat); + if(scs->numverts != dm->getNumVerts(dm)) + { + // DG TODO: reset modifier? + return; + } + + for(i = 0; i < numpoints * 3; i++) + { + points_old[i] = points[i]; + } + + DM_ensure_tessface(dm); + fill_scs_points_anim(ob, dm, scs); + } } - 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_DOMAIN) + else if(smd->type & MOD_SMOKE_TYPE_DOMAIN) { SmokeDomainSettings *sds = smd->domain; float light[3]; @@ -1416,14 +1787,14 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM 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); BKE_ptcache_validate(cache, framenr); 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; @@ -1436,21 +1807,21 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM // printf("startframe: %d, framenr: %d\n", startframe, framenr); - 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 */ @@ -1462,14 +1833,14 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM smoke_calc_domain(scene, ob, smd); /* 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 - if (get_lamp(scene, light)) + if(get_lamp(scene, light)) smoke_calc_transparency(sds->shadow, smoke_get_density(sds->fluid), sds->p0, sds->p1, sds->res, sds->dx, light, calc_voxel_transp, -7.0*sds->dx); - 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); } @@ -1486,30 +1857,31 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM // 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); - smoke_step(sds->fluid, smd->time, scene->r.frs_sec / scene->r.frs_sec_base); + + step(scene, ob, smd, scene->r.frs_sec / scene->r.frs_sec_base); } // create shadows before writing cache so they get stored - if (get_lamp(scene, light)) + if(get_lamp(scene, light)) smoke_calc_transparency(sds->shadow, smoke_get_density(sds->fluid), sds->p0, sds->p1, sds->res, sds->dx, light, calc_voxel_transp, -7.0*sds->dx); - 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(); - //printf ( "Frame: %d, Time: %f\n", (int)smd->time, ( float ) tval() ); + // printf ( "Frame: %d, Time: %f\n\n", (int)smd->time, ( float ) tval() ); } } @@ -1520,7 +1892,7 @@ static float calc_voxel_transp(float *result, float *input, int res[3], int *pix // T_ray *= T_vox *tRay *= exp(input[index]*correct); - if (result[index] < 0.0f) + if(result[index] < 0.0f) { #pragma omp critical result[index] = *tRay; @@ -1574,7 +1946,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; @@ -1588,12 +1960,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; @@ -1607,12 +1979,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; @@ -1654,7 +2026,7 @@ static void smoke_calc_transparency(float *result, float *input, float *p0, floa float bv[6]; int a, z, slabsize=res[0]*res[1], size= res[0]*res[1]*res[2]; - for (a=0; a<size; a++) + for(a=0; a<size; a++) result[a]= -1.0f; bv[0] = p0[0]; @@ -1667,27 +2039,27 @@ static void smoke_calc_transparency(float *result, float *input, float *p0, floa bv[5] = p1[2]; #pragma omp parallel for schedule(static,1) - for (z = 0; z < res[2]; z++) + for(z = 0; z < res[2]; z++) { size_t index = z*slabsize; int x,y; - for (y = 0; y < res[1]; y++) - for (x = 0; x < res[0]; x++, index++) + for(y = 0; y < res[1]; y++) + for(x = 0; x < res[0]; x++, index++) { float voxelCenter[3]; float pos[3]; int cell[3]; float tRay = 1.0; - if (result[index] >= 0.0f) + if(result[index] >= 0.0f) continue; voxelCenter[0] = p0[0] + dx * x + dx * 0.5; voxelCenter[1] = p0[1] + dx * y + dx * 0.5; voxelCenter[2] = p0[2] + dx * z + dx * 0.5; // get starting position (in voxel coords) - 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 get_cell(p0, res, dx, pos, cell, 1); diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 01930cc28da..5d8a4955e58 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -78,6 +78,7 @@ variables on the UI for now #include "BKE_DerivedMesh.h" #include "BKE_pointcache.h" #include "BKE_deform.h" +#include "BKE_mesh.h" //XXX #include "BIF_editdeform.h" //XXX #include "BIF_graphics.h" #include "PIL_time.h" @@ -401,7 +402,10 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M) if (!cmd->numverts || !cmd->numfaces) return; if ((pccd_M->totvert != cmd->numverts) || - (pccd_M->totface != cmd->numfaces)) return; + (pccd_M->totface != cmd->numfaces)) + { + return; + } pccd_M->bbmin[0]=pccd_M->bbmin[1]=pccd_M->bbmin[2]=1e30f; pccd_M->bbmax[0]=pccd_M->bbmax[1]=pccd_M->bbmax[2]=-1e30f; @@ -1387,8 +1391,7 @@ static void scan_for_ext_face_forces(Object *ob,float timenow) } bf = sb->scratch->bodyface; for (a=0; a<sb->scratch->totface; a++, bf++) { - if (( bf->flag & BFF_INTERSECT) || ( bf->flag & BFF_CLOSEVERT)) - { + if (( bf->flag & BFF_INTERSECT) || ( bf->flag & BFF_CLOSEVERT)) { sb->bpoint[bf->v1].choke2=MAX2(sb->bpoint[bf->v1].choke2,choke); sb->bpoint[bf->v2].choke2=MAX2(sb->bpoint[bf->v2].choke2,choke); sb->bpoint[bf->v3].choke2=MAX2(sb->bpoint[bf->v3].choke2,choke); @@ -1934,8 +1937,8 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], } } - if ((deflected < 2)&& (G.rt != 444)) // we did not hit a face until now - { // see if 'outer' hits an edge + if ((deflected < 2)&& (G.rt != 444)) { /* we did not hit a face until now */ + /* see if 'outer' hits an edge */ float dist; closest_to_line_segment_v3(ve, opco, nv1, nv2); @@ -2830,8 +2833,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa nlEnd(NL_MATRIX); nlEnd(NL_SYSTEM); - if ((G.rt == 32) && (nl_flags & NLF_BUILD)) - { + if ((G.rt == 32) && (nl_flags & NLF_BUILD)) { printf("####MEE#####\n"); nlPrintMatrix(); } @@ -3229,8 +3231,7 @@ static void springs_from_mesh(Object *ob) float scale =1.0f; sb= ob->soft; - if (me && sb) - { + if (me && sb) { /* using bp->origS as a container for spring calcualtions here ** will be overwritten sbObjectStep() to receive ** actual modifier stack positions @@ -3267,6 +3268,7 @@ static void mesh_to_softbody(Scene *scene, Object *ob) BodyPoint *bp; BodySpring *bs; int a, totedge; + BKE_mesh_tessface_ensure(me); if (ob->softflag & OB_SB_EDGES) totedge= me->totedge; else totedge= 0; @@ -3305,8 +3307,7 @@ static void mesh_to_softbody(Scene *scene, Object *ob) this enables per vertex *mass painting* */ - if (sb->namedVG_Mass[0]) - { + if (sb->namedVG_Mass[0]) { int grp= defgroup_name_index (ob,sb->namedVG_Mass); /* printf("VGN %s %d\n",sb->namedVG_Mass,grp); */ if (grp > -1) { @@ -3319,8 +3320,7 @@ static void mesh_to_softbody(Scene *scene, Object *ob) /* first set the default */ bp->springweight = 1.0f; - if (sb->namedVG_Spring_K[0]) - { + if (sb->namedVG_Spring_K[0]) { int grp= defgroup_name_index (ob,sb->namedVG_Spring_K); //printf("VGN %s %d\n",sb->namedVG_Spring_K,grp); if (grp > -1) { @@ -3559,7 +3559,7 @@ static void curve_surf_to_softbody(Scene *scene, Object *ob) int a, curindex=0; int totvert, totspring = 0, setgoal=0; - totvert= count_curveverts(&cu->nurb); + totvert= BKE_nurbList_verts_count(&cu->nurb); if (ob->softflag & OB_SB_EDGES) { if (ob->type==OB_CURVE) { @@ -3637,8 +3637,7 @@ static void curve_surf_to_softbody(Scene *scene, Object *ob) } } - if (totspring) - { + if (totspring) { build_bps_springlist(ob); /* link bps to springs */ if (ob->softflag & OB_SB_SELF) {calculate_collision_balls(ob);} } @@ -3894,7 +3893,7 @@ static void softbody_reset(Object *ob, SoftBody *sb, float (*vertexCos)[3], int SB_estimate_transform(ob,NULL,NULL,NULL); SB_estimate_transform(ob,NULL,NULL,NULL); } - switch(ob->type) { + switch (ob->type) { case OB_MESH: if (ob->softflag & OB_SB_FACECOLL) mesh_faces_to_scratch(ob); break; @@ -3950,8 +3949,7 @@ static void softbody_step(Scene *scene, Object *ob, SoftBody *sb, float dtime) if (sb->solver_ID>0) mid_flags |= MID_PRESERVE; forcetime = forcetimemax; /* hope for integrating in one step */ - while ( (ABS(timedone) < ABS(dtime)) && (loops < 2000) ) - { + while ( (ABS(timedone) < ABS(dtime)) && (loops < 2000) ) { /* set goals in time */ interpolate_exciter(ob,200,(int)(200.0f*(timedone/dtime))); @@ -4019,12 +4017,11 @@ static void softbody_step(Scene *scene, Object *ob, SoftBody *sb, float dtime) } } - else if (sb->solver_ID == 2) - {/* do semi "fake" implicit euler */ + else if (sb->solver_ID == 2) { + /* do semi "fake" implicit euler */ //removed }/*SOLVER SELECT*/ - else if (sb->solver_ID == 4) - { + else if (sb->solver_ID == 4) { /* do semi "fake" implicit euler */ }/*SOLVER SELECT*/ else if (sb->solver_ID == 3) { @@ -4081,7 +4078,7 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i if (sb->bpoint == NULL || ((ob->softflag & OB_SB_EDGES) && !ob->soft->bspring && object_has_edges(ob))) { - switch(ob->type) { + switch (ob->type) { case OB_MESH: mesh_to_softbody(scene, ob); break; diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index c2dbb518837..28ce95ea8d1 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -95,8 +95,7 @@ struct bSound* sound_new_file(struct Main *bmain, const char *filename) sound_load(bmain, sound); - if (!sound->playback_handle) - { + if (!sound->playback_handle) { free_libblock(&bmain->sound, sound); sound = NULL; } @@ -106,22 +105,19 @@ struct bSound* sound_new_file(struct Main *bmain, const char *filename) void sound_free(struct bSound* sound) { - if (sound->packedfile) - { + if (sound->packedfile) { freePackedFile(sound->packedfile); sound->packedfile = NULL; } #ifdef WITH_AUDASPACE - if (sound->handle) - { + if (sound->handle) { AUD_unload(sound->handle); sound->handle = NULL; sound->playback_handle = NULL; } - if (sound->cache) - { + if (sound->cache) { AUD_unload(sound->cache); sound->cache = NULL; } @@ -141,10 +137,8 @@ static void sound_sync_callback(void* data, int mode, float time) struct Scene* scene; scene = bmain->scene.first; - while (scene) - { - if (scene->audio.flag & AUDIO_SYNC) - { + while (scene) { + if (scene->audio.flag & AUDIO_SYNC) { if (mode) sound_play_scene(scene); else @@ -282,8 +276,7 @@ struct bSound* sound_new_limiter(struct Main *bmain, struct bSound *source, floa void sound_delete(struct Main *bmain, struct bSound* sound) { - if (sound) - { + if (sound) { sound_free(sound); free_libblock(&bmain->sound, sound); @@ -312,8 +305,7 @@ void sound_cache_notifying(struct Main* main, struct bSound* sound) void sound_delete_cache(struct bSound* sound) { sound->flags &= ~SOUND_FLAGS_CACHING; - if (sound->cache) - { + if (sound->cache) { AUD_unload(sound->cache); sound->cache = NULL; sound->playback_handle = sound->handle; @@ -322,16 +314,13 @@ void sound_delete_cache(struct bSound* sound) void sound_load(struct Main *bmain, struct bSound* sound) { - if (sound) - { - if (sound->cache) - { + if (sound) { + if (sound->cache) { AUD_unload(sound->cache); sound->cache = NULL; } - if (sound->handle) - { + if (sound->handle) { AUD_unload(sound->handle); sound->handle = NULL; sound->playback_handle = NULL; @@ -341,7 +330,7 @@ void sound_load(struct Main *bmain, struct bSound* sound) // XXX unused currently #if 0 - switch(sound->type) + switch (sound->type) { case SOUND_TYPE_FILE: #endif @@ -376,15 +365,13 @@ void sound_load(struct Main *bmain, struct bSound* sound) break; } #endif - if (sound->flags & SOUND_FLAGS_MONO) - { + if (sound->flags & SOUND_FLAGS_MONO) { void* handle = AUD_monoSound(sound->handle); AUD_unload(sound->handle); sound->handle = handle; } - if (sound->flags & SOUND_FLAGS_CACHING) - { + if (sound->flags & SOUND_FLAGS_CACHING) { sound->cache = AUD_bufferSound(sound->handle); } @@ -557,14 +544,12 @@ void sound_play_scene(struct Scene *scene) if (status == AUD_STATUS_INVALID) sound_start_play_scene(scene); - if (!scene->sound_scene_handle) - { + if (!scene->sound_scene_handle) { AUD_unlock(); return; } - if (status != AUD_STATUS_PLAYING) - { + if (status != AUD_STATUS_PLAYING) { AUD_seek(scene->sound_scene_handle, CFRA / FPS); AUD_resume(scene->sound_scene_handle); } @@ -577,8 +562,7 @@ void sound_play_scene(struct Scene *scene) void sound_stop_scene(struct Scene *scene) { - if (scene->sound_scene_handle) - { + if (scene->sound_scene_handle) { AUD_pause(scene->sound_scene_handle); if (scene->audio.flag & AUDIO_SYNC) @@ -596,12 +580,10 @@ void sound_seek_scene(struct Main *bmain, struct Scene *scene) status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID; - if (status == AUD_STATUS_INVALID) - { + if (status == AUD_STATUS_INVALID) { sound_start_play_scene(scene); - if (!scene->sound_scene_handle) - { + if (!scene->sound_scene_handle) { AUD_unlock(); return; } @@ -616,10 +598,8 @@ void sound_seek_scene(struct Main *bmain, struct Scene *scene) } } - if (scene->audio.flag & AUDIO_SCRUB && !animation_playing) - { - if (scene->audio.flag & AUDIO_SYNC) - { + if (scene->audio.flag & AUDIO_SCRUB && !animation_playing) { + if (scene->audio.flag & AUDIO_SYNC) { AUD_seek(scene->sound_scene_handle, CFRA / FPS); AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS); } @@ -648,8 +628,7 @@ void sound_seek_scene(struct Main *bmain, struct Scene *scene) float sound_sync_scene(struct Scene *scene) { - if (scene->sound_scene_handle) - { + if (scene->sound_scene_handle) { if (scene->audio.flag & AUDIO_SYNC) return AUD_getSequencerPosition(scene->sound_scene_handle); else @@ -668,8 +647,7 @@ int sound_scene_playing(struct Scene *scene) void sound_free_waveform(struct bSound* sound) { - if (sound->waveform) - { + if (sound->waveform) { MEM_freeN(((SoundWaveform*)sound->waveform)->data); MEM_freeN(sound->waveform); } @@ -683,8 +661,7 @@ void sound_read_waveform(struct bSound* sound) info = AUD_getInfo(sound->playback_handle); - if (info.length > 0) - { + if (info.length > 0) { SoundWaveform* waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND; @@ -709,23 +686,16 @@ void sound_update_scene(struct Scene* scene) void* handle; float quat[4]; - for (SETLOOPER(scene, sce_it, base)) - { + for (SETLOOPER(scene, sce_it, base)) { ob = base->object; - if (ob->type == OB_SPEAKER) - { - if (ob->adt) - { - for (track = ob->adt->nla_tracks.first; track; track = track->next) - { - for (strip = track->strips.first; strip; strip = strip->next) - { - if (strip->type == NLASTRIP_TYPE_SOUND) - { + if (ob->type == OB_SPEAKER) { + if (ob->adt) { + for (track = ob->adt->nla_tracks.first; track; track = track->next) { + for (strip = track->strips.first; strip; strip = strip->next) { + if (strip->type == NLASTRIP_TYPE_SOUND) { speaker = (Speaker*)ob->data; - if (AUD_removeSet(scene->speaker_handles, strip->speaker_handle)) - { + if (AUD_removeSet(scene->speaker_handles, strip->speaker_handle)) { if (speaker->sound) AUD_moveSequence(strip->speaker_handle, strip->start / FPS, -1, 0); else { @@ -734,15 +704,13 @@ void sound_update_scene(struct Scene* scene) } } else { - if (speaker->sound) - { + if (speaker->sound) { strip->speaker_handle = AUD_addSequence(scene->sound_scene, speaker->sound->playback_handle, strip->start / FPS, -1, 0); AUD_setRelativeSequence(strip->speaker_handle, 0); } } - if (strip->speaker_handle) - { + if (strip->speaker_handle) { AUD_addSet(new_set, strip->speaker_handle); AUD_updateSequenceData(strip->speaker_handle, speaker->volume_max, speaker->volume_min, speaker->distance_max, @@ -765,13 +733,11 @@ void sound_update_scene(struct Scene* scene) } } - while ((handle = AUD_getSet(scene->speaker_handles))) - { + while ((handle = AUD_getSet(scene->speaker_handles))) { AUD_removeSequence(scene->sound_scene, handle); } - if (scene->camera) - { + if (scene->camera) { mat4_to_quat(quat, scene->camera->obmat); AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_LOCATION, CFRA, scene->camera->obmat[3], 1); AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_ORIENTATION, CFRA, quat, 1); diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 83a24f6afdc..129d3a3f698 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -314,7 +314,7 @@ static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm, MLoop *ml = mloop + mp->loopstart; BLI_array_empty(fverts); - BLI_array_growitems(fverts, nverts); + BLI_array_grow_items(fverts, nverts); get_face_uv_map_vert(vmap, mpoly, ml, i, fverts); @@ -350,7 +350,7 @@ static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm, CCGFace *f; BLI_array_empty(fverts); - BLI_array_growitems(fverts, nverts); + BLI_array_grow_items(fverts, nverts); get_face_uv_map_vert(vmap, mpoly, ml, i, fverts); ccgSubSurf_syncFace(ss, SET_INT_IN_POINTER(i), nverts, fverts, &f); @@ -583,7 +583,7 @@ static void ss_sync_from_derivedmesh(CCGSubSurf *ss, DerivedMesh *dm, CCGFace *f; BLI_array_empty(fVerts); - BLI_array_growitems(fVerts, mp->totloop); + BLI_array_grow_items(fVerts, mp->totloop); ml = mloop + mp->loopstart; for (j = 0; j < mp->totloop; j++, ml++) { @@ -2423,7 +2423,9 @@ static void ccgDM_release(DerivedMesh *dm) /* Check that mmd still exists */ if (!ccgdm->multires.local_mmd && BLI_findindex(&ccgdm->multires.ob->modifiers, ccgdm->multires.mmd) < 0) + { ccgdm->multires.mmd = NULL; + } if (ccgdm->multires.mmd) { if (ccgdm->multires.modified_flags & MULTIRES_COORDS_MODIFIED) @@ -3148,13 +3150,13 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, *((int *)ccgSubSurf_getFaceUserData(ss, f)) = vertNum; BLI_array_empty(loopidx); - BLI_array_growitems(loopidx, numVerts); + BLI_array_grow_items(loopidx, numVerts); for (s = 0; s < numVerts; s++) { loopidx[s] = loopindex++; } BLI_array_empty(vertidx); - BLI_array_growitems(vertidx, numVerts); + BLI_array_grow_items(vertidx, numVerts); for (s = 0; s < numVerts; s++) { CCGVert *v = ccgSubSurf_getFaceVert(f, s); vertidx[s] = GET_INT_FROM_POINTER(ccgSubSurf_getVertVertHandle(v)); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 1197ec23907..cb7369476c0 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -1193,9 +1193,11 @@ void txt_order_cursors(Text *text) if (!text->sell) return; /* Flip so text->curl is before text->sell */ - if (txt_get_span(text->curl, text->sell)<0 || - (text->curl==text->sell && text->curc>text->selc)) + if ((txt_get_span(text->curl, text->sell) < 0) || + (text->curl == text->sell && text->curc > text->selc)) + { txt_curs_swap(text); + } } int txt_has_sel(Text *text) @@ -2018,7 +2020,7 @@ void txt_do_undo(Text *text) undoing= 1; - switch(op) { + switch (op) { case UNDO_CLEFT: txt_move_right(text, 0); break; @@ -2245,7 +2247,7 @@ void txt_do_redo(Text *text) undoing= 1; - switch(op) { + switch (op) { case UNDO_CLEFT: txt_move_left(text, 0); break; @@ -2832,8 +2834,7 @@ void txt_indent(Text *text) } num = 0; - while (TRUE) - { + while (TRUE) { tmp= MEM_mallocN(text->curl->len+indentlen+1, "textline_string"); text->curc = 0; @@ -2851,8 +2852,7 @@ void txt_indent(Text *text) txt_make_dirty(text); txt_clean_text(text); - if (text->curl == text->sell) - { + if (text->curl == text->sell) { text->selc = text->sell->len; break; } @@ -2862,14 +2862,12 @@ void txt_indent(Text *text) } } text->curc = 0; - while ( num > 0 ) - { + while ( num > 0 ) { text->curl = text->curl->prev; num--; } - if (!undoing) - { + if (!undoing) { txt_undo_add_toop(text, UNDO_INDENT, txt_get_span(text->lines.first, text->curl), text->curc, txt_get_span(text->lines.first, text->sell), text->selc); } } @@ -2893,12 +2891,10 @@ void txt_unindent(Text *text) indent = spaceslen; } - while (TRUE) - { + while (TRUE) { int i = 0; - if (BLI_strncasecmp(text->curl->line, remove, indent) == 0) - { + if (BLI_strncasecmp(text->curl->line, remove, indent) == 0) { while (i< text->curl->len) { text->curl->line[i]= text->curl->line[i+indent]; i++; @@ -2909,8 +2905,7 @@ void txt_unindent(Text *text) txt_make_dirty(text); txt_clean_text(text); - if (text->curl == text->sell) - { + if (text->curl == text->sell) { text->selc = text->sell->len; break; } @@ -2921,14 +2916,12 @@ void txt_unindent(Text *text) } text->curc = 0; - while ( num > 0 ) - { + while ( num > 0 ) { text->curl = text->curl->prev; num--; } - if (!undoing) - { + if (!undoing) { txt_undo_add_toop(text, UNDO_UNINDENT, txt_get_span(text->lines.first, text->curl), text->curc, txt_get_span(text->lines.first, text->sell), text->selc); } } @@ -2944,8 +2937,7 @@ void txt_comment(Text *text) if (!text->sell) return;// Need to change this need to check if only one line is selected to more then one num = 0; - while (TRUE) - { + while (TRUE) { tmp= MEM_mallocN(text->curl->len+2, "textline_string"); text->curc = 0; @@ -2963,8 +2955,7 @@ void txt_comment(Text *text) txt_make_dirty(text); txt_clean_text(text); - if (text->curl == text->sell) - { + if (text->curl == text->sell) { text->selc = text->sell->len; break; } @@ -2974,14 +2965,12 @@ void txt_comment(Text *text) } } text->curc = 0; - while ( num > 0 ) - { + while ( num > 0 ) { text->curl = text->curl->prev; num--; } - if (!undoing) - { + if (!undoing) { txt_undo_add_toop(text, UNDO_COMMENT, txt_get_span(text->lines.first, text->curl), text->curc, txt_get_span(text->lines.first, text->sell), text->selc); } } @@ -2995,12 +2984,10 @@ void txt_uncomment(Text *text) if (!text->curl) return; if (!text->sell) return; - while (TRUE) - { + while (TRUE) { int i = 0; - if (text->curl->line[i] == remove) - { + if (text->curl->line[i] == remove) { while (i< text->curl->len) { text->curl->line[i]= text->curl->line[i+1]; i++; @@ -3012,8 +2999,7 @@ void txt_uncomment(Text *text) txt_make_dirty(text); txt_clean_text(text); - if (text->curl == text->sell) - { + if (text->curl == text->sell) { text->selc = text->sell->len; break; } @@ -3024,14 +3010,12 @@ void txt_uncomment(Text *text) } text->curc = 0; - while ( num > 0 ) - { + while ( num > 0 ) { text->curl = text->curl->prev; num--; } - if (!undoing) - { + if (!undoing) { txt_undo_add_toop(text, UNDO_UNCOMMENT, txt_get_span(text->lines.first, text->curl), text->curc, txt_get_span(text->lines.first, text->sell), text->selc); } } @@ -3047,27 +3031,23 @@ int setcurr_tab_spaces (Text *text, int space) if (!text) return 0; if (!text->curl) return 0; - while (text->curl->line[i] == indent) - { + while (text->curl->line[i] == indent) { //we only count those tabs/spaces that are before any text or before the curs; - if (i == text->curc) - { + if (i == text->curc) { return i; } else { i++; } } - if (strstr(text->curl->line, word)) - { + if (strstr(text->curl->line, word)) { /* if we find a ':' on this line, then add a tab but not if it is: * 1) in a comment * 2) within an identifier * 3) after the cursor (text->curc), i.e. when creating space before a function def [#25414] */ int a, is_indent = 0; - for (a=0; (a < text->curc) && (text->curl->line[a] != '\0'); a++) - { + for (a=0; (a < text->curc) && (text->curl->line[a] != '\0'); a++) { char ch= text->curl->line[a]; if (ch=='#') { break; @@ -3084,13 +3064,10 @@ int setcurr_tab_spaces (Text *text, int space) } } - for (test=0; back_words[test]; test++) - { + for (test=0; back_words[test]; test++) { /* if there are these key words then remove a tab because we are done with the block */ - if (strstr(text->curl->line, back_words[test]) && i > 0) - { - if (strcspn(text->curl->line, back_words[test]) < strcspn(text->curl->line, comm)) - { + if (strstr(text->curl->line, back_words[test]) && i > 0) { + if (strcspn(text->curl->line, back_words[test]) < strcspn(text->curl->line, comm)) { i -= space; } } @@ -3139,14 +3116,16 @@ TextMarker *txt_find_marker_region(Text *text, TextLine *line, int start, int en for (marker=text->markers.first; marker; marker=next) { next= marker->next; - if (group && marker->group != group) continue; + if (group && marker->group != group) continue; else if ((marker->flags & flags) != flags) continue; - else if (marker->lineno < lineno) continue; + else if (marker->lineno < lineno) continue; else if (marker->lineno > lineno) break; if ((marker->start==marker->end && start<=marker->start && marker->start<=end) || - (marker->start<end && marker->end>start)) + (marker->start<end && marker->end>start)) + { return marker; + } } return NULL; } diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 23d818369a2..29b9505f449 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -663,7 +663,7 @@ void default_tex(Tex *tex) void tex_set_type(Tex *tex, int type) { - switch(type) { + switch (type) { case TEX_VOXELDATA: if (tex->vd == NULL) @@ -1180,7 +1180,7 @@ Tex *give_current_material_texture(Material *ma) int give_active_mtex(ID *id, MTex ***mtex_ar, short *act) { - switch(GS(id->name)) { + switch (GS(id->name)) { case ID_MA: *mtex_ar= ((Material *)id)->mtex; if (act) *act= (((Material *)id)->texact); @@ -1211,7 +1211,7 @@ void set_active_mtex(ID *id, short act) if (act<0) act= 0; else if (act>=MAX_MTEX) act= MAX_MTEX-1; - switch(GS(id->name)) { + switch (GS(id->name)) { case ID_MA: ((Material *)id)->texact= act; break; diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 7654c361d14..e511cd362de 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -1523,6 +1523,7 @@ typedef struct MovieReconstructContext { #endif char object_name[MAX_NAME]; int is_camera; + short motion_flag; float focal_length; float principal_point[2]; @@ -1752,7 +1753,11 @@ int BKE_tracking_can_reconstruct(MovieTracking *tracking, MovieTrackingObject *o #if WITH_LIBMV ListBase *tracksbase = BKE_tracking_object_tracks(tracking, object); - if (count_tracks_on_both_keyframes(tracking, tracksbase)<8) { + if (tracking->settings.motion_flag & TRACKING_MOTION_MODAL) { + /* TODO: check for number of tracks? */ + return TRUE; + } + else if (count_tracks_on_both_keyframes(tracking, tracksbase) < 8) { BLI_strncpy(error_msg, "At least 8 common tracks on both of keyframes are needed for reconstruction", error_size); return FALSE; @@ -1781,7 +1786,8 @@ MovieReconstructContext* BKE_tracking_reconstruction_context_new(MovieTracking * MovieTrackingTrack *track; BLI_strncpy(context->object_name, object->name, sizeof(context->object_name)); - context->is_camera = object->flag&TRACKING_OBJECT_CAMERA; + context->is_camera = object->flag & TRACKING_OBJECT_CAMERA; + context->motion_flag = tracking->settings.motion_flag; context->tracks_map = tracks_map_new(context->object_name, context->is_camera, num_tracks, 0); @@ -1894,13 +1900,22 @@ void BKE_tracking_solve_reconstruction(MovieReconstructContext *context, short * progressdata.stats_message = stats_message; progressdata.message_size = message_size; - context->reconstruction = libmv_solveReconstruction(context->tracks, - context->keyframe1, context->keyframe2, - context->refine_flags, - context->focal_length, - context->principal_point[0], context->principal_point[1], - context->k1, context->k2, context->k3, - solve_reconstruction_update_cb, &progressdata); + if (context->motion_flag & TRACKING_MOTION_MODAL) { + context->reconstruction = libmv_solveModal(context->tracks, + context->focal_length, + context->principal_point[0], context->principal_point[1], + context->k1, context->k2, context->k3, + solve_reconstruction_update_cb, &progressdata); + } + else { + context->reconstruction = libmv_solveReconstruction(context->tracks, + context->keyframe1, context->keyframe2, + context->refine_flags, + context->focal_length, + context->principal_point[0], context->principal_point[1], + context->k1, context->k2, context->k3, + solve_reconstruction_update_cb, &progressdata); + } error = libmv_reprojectionError(context->reconstruction); diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index 59c38117858..079bde0afec 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -120,19 +120,17 @@ static int write_audio_frame(void) audio_time += (double) audio_input_samples / (double) c->sample_rate; pkt.size = avcodec_encode_audio(c, audio_output_buffer, - audio_outbuf_size, - (short*) audio_input_buffer); + audio_outbuf_size, + (short *)audio_input_buffer); - if (pkt.size < 0) - { + if (pkt.size < 0) { // XXX error("Error writing audio packet"); return -1; } pkt.data = audio_output_buffer; - if (c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE) - { + if (c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE) { pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base, audio_stream->time_base); fprintf(stderr, "Audio Frame PTS: %d\n", (int)pkt.pts); @@ -175,7 +173,7 @@ static AVFrame* alloc_picture(int pix_fmt, int width, int height) * first is always desired guess_format parameter */ static const char** get_file_extensions(int format) { - switch(format) { + switch (format) { case FFMPEG_DV: { static const char * rv[] = { ".dv", NULL }; return rv; @@ -372,7 +370,7 @@ static void set_ffmpeg_property_option(AVCodecContext* c, IDProperty * prop) *param++ = 0; } - switch(prop->type) { + switch (prop->type) { case IDP_STRING: fprintf(stderr, "%s.\n", IDP_String(prop)); av_set_string3(c, prop->name, IDP_String(prop), 1, &rv); @@ -717,7 +715,7 @@ static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, Report BLI_snprintf(of->filename, sizeof(of->filename), "%s", name); /* set the codec to the user's selection */ - switch(ffmpeg_type) { + switch (ffmpeg_type) { case FFMPEG_AVI: case FFMPEG_MOV: case FFMPEG_MKV: @@ -929,8 +927,7 @@ int start_ffmpeg(struct Scene *scene, RenderData *rd, int rectx, int recty, Repo success = start_ffmpeg_impl(rd, rectx, recty, reports); #ifdef WITH_AUDASPACE - if (audio_stream) - { + if (audio_stream) { AVCodecContext* c = audio_stream->codec; AUD_DeviceSpecs specs; specs.channels = c->channels; @@ -974,8 +971,7 @@ int append_ffmpeg(RenderData *rd, int start_frame, int frame, int *pixels, int r // why is this done before writing the video frame and again at end_ffmpeg? // write_audio_frames(frame / (((double)rd->frs_sec) / rd->frs_sec_base)); - if (video_stream) - { + if (video_stream) { avframe= generate_video_frame((unsigned char*) pixels, reports); success= (avframe && write_video_frame(rd, frame - start_frame, avframe, reports)); @@ -1172,10 +1168,12 @@ static const AVOption *my_av_find_opt(void *v, const char *name, const AVOption *o= c->option; for (;o && o->name; o++) { - if (!strcmp(o->name, name) && - (!unit || (o->unit && !strcmp(o->unit, unit))) && - (o->flags & mask) == flags ) + if (!strcmp(o->name, name) && + (!unit || (o->unit && !strcmp(o->unit, unit))) && + (o->flags & mask) == flags) + { return o; + } } return NULL; } |