From cffaa42d3a34c6b310c3c87c98e1f8313881e473 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 12 May 2012 19:18:02 +0000 Subject: style cleanup: blenkernel --- source/blender/blenkernel/intern/DerivedMesh.c | 639 ++++++++++----------- source/blender/blenkernel/intern/armature.c | 14 +- source/blender/blenkernel/intern/deform.c | 14 +- source/blender/blenkernel/intern/depsgraph.c | 2 +- source/blender/blenkernel/intern/editderivedmesh.c | 324 +++++------ source/blender/blenkernel/intern/ocean.c | 499 ++++++++-------- 6 files changed, 734 insertions(+), 758 deletions(-) diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 50c10ea3c3d..18560d3dbc0 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -95,7 +95,7 @@ static MVert *dm_getVertArray(DerivedMesh *dm) if (!mvert) { mvert = CustomData_add_layer(&dm->vertData, CD_MVERT, CD_CALLOC, NULL, - dm->getNumVerts(dm)); + dm->getNumVerts(dm)); CustomData_set_layer_flag(&dm->vertData, CD_MVERT, CD_FLAG_TEMPORARY); dm->copyVertArray(dm, mvert); } @@ -109,7 +109,7 @@ static MEdge *dm_getEdgeArray(DerivedMesh *dm) if (!medge) { medge = CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_CALLOC, NULL, - dm->getNumEdges(dm)); + dm->getNumEdges(dm)); CustomData_set_layer_flag(&dm->edgeData, CD_MEDGE, CD_FLAG_TEMPORARY); dm->copyEdgeArray(dm, medge); } @@ -146,7 +146,7 @@ static MLoop *dm_getLoopArray(DerivedMesh *dm) if (!mloop) { mloop = CustomData_add_layer(&dm->loopData, CD_MLOOP, CD_CALLOC, NULL, - dm->getNumLoops(dm)); + dm->getNumLoops(dm)); CustomData_set_layer_flag(&dm->loopData, CD_MLOOP, CD_FLAG_TEMPORARY); dm->copyLoopArray(dm, mloop); } @@ -160,7 +160,7 @@ static MPoly *dm_getPolyArray(DerivedMesh *dm) if (!mpoly) { mpoly = CustomData_add_layer(&dm->polyData, CD_MPOLY, CD_CALLOC, NULL, - dm->getNumPolys(dm)); + dm->getNumPolys(dm)); CustomData_set_layer_flag(&dm->polyData, CD_MPOLY, CD_FLAG_TEMPORARY); dm->copyPolyArray(dm, mpoly); } @@ -171,7 +171,7 @@ static MPoly *dm_getPolyArray(DerivedMesh *dm) static MVert *dm_dupVertArray(DerivedMesh *dm) { MVert *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumVerts(dm), - "dm_dupVertArray tmp"); + "dm_dupVertArray tmp"); if (tmp) dm->copyVertArray(dm, tmp); @@ -181,7 +181,7 @@ static MVert *dm_dupVertArray(DerivedMesh *dm) static MEdge *dm_dupEdgeArray(DerivedMesh *dm) { MEdge *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumEdges(dm), - "dm_dupEdgeArray tmp"); + "dm_dupEdgeArray tmp"); if (tmp) dm->copyEdgeArray(dm, tmp); @@ -191,7 +191,7 @@ static MEdge *dm_dupEdgeArray(DerivedMesh *dm) static MFace *dm_dupFaceArray(DerivedMesh *dm) { MFace *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumTessFaces(dm), - "dm_dupFaceArray tmp"); + "dm_dupFaceArray tmp"); if (tmp) dm->copyTessFaceArray(dm, tmp); @@ -201,7 +201,7 @@ static MFace *dm_dupFaceArray(DerivedMesh *dm) static MLoop *dm_dupLoopArray(DerivedMesh *dm) { MLoop *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumLoops(dm), - "dm_dupLoopArray tmp"); + "dm_dupLoopArray tmp"); if (tmp) dm->copyLoopArray(dm, tmp); @@ -211,7 +211,7 @@ static MLoop *dm_dupLoopArray(DerivedMesh *dm) static MPoly *dm_dupPolyArray(DerivedMesh *dm) { MPoly *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumPolys(dm), - "dm_dupPolyArray tmp"); + "dm_dupPolyArray tmp"); if (tmp) dm->copyPolyArray(dm, tmp); @@ -295,11 +295,11 @@ void DM_from_template(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type int numLoops, int numPolys) { CustomData_copy(&source->vertData, &dm->vertData, CD_MASK_DERIVEDMESH, - CD_CALLOC, numVerts); + CD_CALLOC, numVerts); CustomData_copy(&source->edgeData, &dm->edgeData, CD_MASK_DERIVEDMESH, - CD_CALLOC, numEdges); + CD_CALLOC, numEdges); CustomData_copy(&source->faceData, &dm->faceData, CD_MASK_DERIVEDMESH, - CD_CALLOC, numTessFaces); + CD_CALLOC, numTessFaces); CustomData_copy(&source->loopData, &dm->loopData, CD_MASK_DERIVEDMESH, CD_CALLOC, numLoops); CustomData_copy(&source->polyData, &dm->polyData, CD_MASK_DERIVEDMESH, @@ -463,7 +463,7 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob) /* dm might depend on me, so we need to do everything with a local copy */ Mesh tmp = *me; int totvert, totedge /*, totface */ /* UNUSED */, totloop, totpoly; - int did_shapekeys=0; + int did_shapekeys = 0; memset(&tmp.vdata, 0, sizeof(tmp.vdata)); memset(&tmp.edata, 0, sizeof(tmp.edata)); @@ -486,13 +486,13 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob) int uid; if (ob) { - kb = BLI_findlink(&me->key->block, ob->shapenr-1); + kb = BLI_findlink(&me->key->block, ob->shapenr - 1); if (kb) { uid = kb->uid; } else { printf("%s: error - could not find active shapekey %d!\n", - __func__, ob->shapenr-1); + __func__, ob->shapenr - 1); uid = INT_MAX; } @@ -558,16 +558,16 @@ void DM_to_meshkey(DerivedMesh *dm, Mesh *me, KeyBlock *kb) float *fp; MVert *mvert; - if (totvert==0 || me->totvert==0 || me->totvert!=totvert) return; + if (totvert == 0 || me->totvert == 0 || me->totvert != totvert) return; if (kb->data) MEM_freeN(kb->data); - kb->data= MEM_callocN(me->key->elemsize*me->totvert, "kb->data"); - kb->totelem= totvert; + kb->data = MEM_callocN(me->key->elemsize * me->totvert, "kb->data"); + kb->totelem = totvert; - fp= kb->data; - mvert=dm->getVertDataArray(dm, CD_MVERT); + fp = kb->data; + mvert = dm->getVertDataArray(dm, CD_MVERT); - for (a=0; atotelem; a++, fp+=3, mvert++) { + for (a = 0; a < kb->totelem; a++, fp += 3, mvert++) { copy_v3_v3(fp, mvert->co); } } @@ -669,24 +669,24 @@ void DM_set_tessface_data(DerivedMesh *dm, int index, int type, void *data) } void DM_copy_vert_data(DerivedMesh *source, DerivedMesh *dest, - int source_index, int dest_index, int count) + int source_index, int dest_index, int count) { CustomData_copy_data(&source->vertData, &dest->vertData, - source_index, dest_index, count); + source_index, dest_index, count); } void DM_copy_edge_data(DerivedMesh *source, DerivedMesh *dest, - int source_index, int dest_index, int count) + int source_index, int dest_index, int count) { CustomData_copy_data(&source->edgeData, &dest->edgeData, - source_index, dest_index, count); + source_index, dest_index, count); } void DM_copy_tessface_data(DerivedMesh *source, DerivedMesh *dest, - int source_index, int dest_index, int count) + int source_index, int dest_index, int count) { CustomData_copy_data(&source->faceData, &dest->faceData, - source_index, dest_index, count); + source_index, dest_index, count); } void DM_copy_loop_data(DerivedMesh *source, DerivedMesh *dest, @@ -729,29 +729,29 @@ void DM_free_poly_data(struct DerivedMesh *dm, int index, int count) } void DM_interp_vert_data(DerivedMesh *source, DerivedMesh *dest, - int *src_indices, float *weights, - int count, int dest_index) + int *src_indices, float *weights, + int count, int dest_index) { CustomData_interp(&source->vertData, &dest->vertData, src_indices, - weights, NULL, count, dest_index); + weights, NULL, count, dest_index); } void DM_interp_edge_data(DerivedMesh *source, DerivedMesh *dest, - int *src_indices, - float *weights, EdgeVertWeight *vert_weights, - int count, int dest_index) + int *src_indices, + float *weights, EdgeVertWeight *vert_weights, + int count, int dest_index) { CustomData_interp(&source->edgeData, &dest->edgeData, src_indices, - weights, (float*)vert_weights, count, dest_index); + weights, (float *)vert_weights, count, dest_index); } void DM_interp_tessface_data(DerivedMesh *source, DerivedMesh *dest, - int *src_indices, - float *weights, FaceVertWeight *vert_weights, - int count, int dest_index) + int *src_indices, + float *weights, FaceVertWeight *vert_weights, + int count, int dest_index) { CustomData_interp(&source->faceData, &dest->faceData, src_indices, - weights, (float*)vert_weights, count, dest_index); + weights, (float *)vert_weights, count, dest_index); } void DM_swap_tessface_data(DerivedMesh *dm, int index, const int *corner_indices) @@ -801,16 +801,16 @@ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, DerivedMesh *dm; KeyBlock *kb; - md->scene= scene; + md->scene = scene; - if (!(md->mode&eModifierMode_Realtime)) return NULL; + if (!(md->mode & eModifierMode_Realtime)) return NULL; if (mti->isDisabled && mti->isDisabled(md, 0)) return NULL; - if (build_shapekey_layers && me->key && (kb = BLI_findlink(&me->key->block, ob->shapenr-1))) { + if (build_shapekey_layers && me->key && (kb = BLI_findlink(&me->key->block, ob->shapenr - 1))) { key_to_mesh(kb, me); } - if (mti->type==eModifierTypeType_OnlyDeform) { + if (mti->type == eModifierTypeType_OnlyDeform) { int numVerts; float (*deformedVerts)[3] = mesh_getVertexCos(me, &numVerts); @@ -846,13 +846,13 @@ static float *get_editbmesh_orco_verts(BMEditMesh *em) /* these may not really be the orco's, but it's only for preview. * could be solver better once, but isn't simple */ - totvert= em->bm->totvert; + totvert = em->bm->totvert; - orco = MEM_mallocN(sizeof(float)*3*totvert, "BMEditMesh Orco"); + orco = MEM_mallocN(sizeof(float) * 3 * totvert, "BMEditMesh Orco"); eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); - for (a=0; eve; eve=BM_iter_step(&iter), a+=3) { - copy_v3_v3(orco+a, eve->co); + for (a = 0; eve; eve = BM_iter_step(&iter), a += 3) { + copy_v3_v3(orco + a, eve->co); } return orco; @@ -861,11 +861,11 @@ static float *get_editbmesh_orco_verts(BMEditMesh *em) /* orco custom data layer */ static void *get_orco_coords_dm(Object *ob, BMEditMesh *em, int layer, int *free) { - *free= 0; + *free = 0; if (layer == CD_ORCO) { /* get original coordinates */ - *free= 1; + *free = 1; if (em) return (float(*)[3])get_editbmesh_orco_verts(em); @@ -877,7 +877,7 @@ static void *get_orco_coords_dm(Object *ob, BMEditMesh *em, int layer, int *free * by a more flexible customdata system, but not simple */ if (!em) { ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth); - KeyBlock *kb= key_get_keyblock(ob_get_key(ob), clmd->sim_parms->shapekey_rest); + KeyBlock *kb = key_get_keyblock(ob_get_key(ob), clmd->sim_parms->shapekey_rest); if (kb->data) return kb->data; @@ -895,10 +895,10 @@ static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, BMEditMesh *em, int lay float (*orco)[3]; int free; - if (em) dm= CDDM_from_BMEditMesh(em, me, FALSE, FALSE); - else dm= CDDM_from_mesh(me, ob); + if (em) dm = CDDM_from_BMEditMesh(em, me, FALSE, FALSE); + else dm = CDDM_from_mesh(me, ob); - orco= get_orco_coords_dm(ob, em, layer, &free); + orco = get_orco_coords_dm(ob, em, layer, &free); if (orco) { CDDM_apply_vert_coords(dm, orco); @@ -911,16 +911,16 @@ static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, BMEditMesh *em, int lay } static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm, - DerivedMesh *orcodm, int layer) + DerivedMesh *orcodm, int layer) { float (*orco)[3], (*layerorco)[3]; int totvert, free; - totvert= dm->getNumVerts(dm); + totvert = dm->getNumVerts(dm); if (orcodm) { - orco= MEM_callocN(sizeof(float)*3*totvert, "dm orco"); - free= 1; + orco = MEM_callocN(sizeof(float) * 3 * totvert, "dm orco"); + free = 1; if (orcodm->getNumVerts(orcodm) == totvert) orcodm->getVertCos(orcodm, orco); @@ -928,7 +928,7 @@ static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm, dm->getVertCos(dm, orco); } else - orco= get_orco_coords_dm(ob, em, layer, &free); + orco = get_orco_coords_dm(ob, em, layer, &free); if (orco) { if (layer == CD_ORCO) @@ -939,7 +939,7 @@ static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm, layerorco = DM_get_vert_data_layer(dm, layer); } - memcpy(layerorco, orco, sizeof(float)*3*totvert); + memcpy(layerorco, orco, sizeof(float) * 3 * totvert); if (free) MEM_freeN(orco); } } @@ -954,41 +954,41 @@ static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm, void weight_to_rgb(float r_rgb[3], const float weight) { - const float blend= ((weight/2.0f)+0.5f); + const float blend = ((weight / 2.0f) + 0.5f); - if (weight<=0.25f) { // blue->cyan - r_rgb[0]= 0.0f; - r_rgb[1]= blend*weight*4.0f; - r_rgb[2]= blend; + if (weight <= 0.25f) { // blue->cyan + r_rgb[0] = 0.0f; + r_rgb[1] = blend * weight * 4.0f; + r_rgb[2] = blend; } - else if (weight<=0.50f) { // cyan->green - r_rgb[0]= 0.0f; - r_rgb[1]= blend; - r_rgb[2]= blend*(1.0f-((weight-0.25f)*4.0f)); + else if (weight <= 0.50f) { // cyan->green + r_rgb[0] = 0.0f; + r_rgb[1] = blend; + r_rgb[2] = blend * (1.0f - ((weight - 0.25f) * 4.0f)); } - else if (weight <= 0.75f) { // green->yellow - r_rgb[0]= blend * ((weight-0.50f)*4.0f); - r_rgb[1]= blend; - r_rgb[2]= 0.0f; + else if (weight <= 0.75f) { // green->yellow + r_rgb[0] = blend * ((weight - 0.50f) * 4.0f); + r_rgb[1] = blend; + r_rgb[2] = 0.0f; } else if (weight <= 1.0f) { // yellow->red - r_rgb[0]= blend; - r_rgb[1]= blend * (1.0f-((weight-0.75f)*4.0f)); - r_rgb[2]= 0.0f; + r_rgb[0] = blend; + r_rgb[1] = blend * (1.0f - ((weight - 0.75f) * 4.0f)); + r_rgb[2] = 0.0f; } else { /* exceptional value, unclamped or nan, * avoid uninitialized memory use */ - r_rgb[0]= 1.0f; - r_rgb[1]= 0.0f; - r_rgb[2]= 1.0f; + r_rgb[0] = 1.0f; + r_rgb[1] = 0.0f; + r_rgb[2] = 1.0f; } } /* draw_flag's for calc_weightpaint_vert_color */ enum { - CALC_WP_MULTIPAINT= (1<<0), - CALC_WP_AUTO_NORMALIZE= (1<<1) + CALC_WP_MULTIPAINT = (1 << 0), + CALC_WP_AUTO_NORMALIZE = (1 << 1) }; static void weightpaint_color(unsigned char r_col[4], ColorBand *coba, const float input) @@ -1020,13 +1020,13 @@ static void calc_weightpaint_vert_color( { float input = 0.0f; - int make_black= FALSE; + int make_black = FALSE; if ((selected > 1) && (draw_flag & CALC_WP_MULTIPAINT)) { - int was_a_nonzero= FALSE; + int was_a_nonzero = FALSE; unsigned int i; - MDeformWeight *dw= dv->dw; + MDeformWeight *dw = dv->dw; for (i = dv->totweight; i != 0; i--, dw++) { /* in multipaint, get the average if auto normalize is inactive * get the sum if it is active */ @@ -1034,7 +1034,7 @@ static void calc_weightpaint_vert_color( if (dg_flags[dw->def_nr]) { if (dw->weight) { input += dw->weight; - was_a_nonzero= TRUE; + was_a_nonzero = TRUE; } } } @@ -1050,7 +1050,7 @@ static void calc_weightpaint_vert_color( } else { /* default, non tricky behavior */ - input= defvert_find_weight(dv, defbase_act); + input = defvert_find_weight(dv, defbase_act); } if (make_black) { /* TODO, theme color */ @@ -1065,11 +1065,11 @@ static void calc_weightpaint_vert_color( } } -static ColorBand *stored_cb= NULL; +static ColorBand *stored_cb = NULL; void vDM_ColorBand_store(ColorBand *coba) { - stored_cb= coba; + stored_cb = coba; } /* return an array of vertex weight colors, caller must free. @@ -1081,7 +1081,7 @@ static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, i { MDeformVert *dv = DM_get_vert_data_layer(dm, CD_MDEFORMVERT); int numVerts = dm->getNumVerts(dm); - unsigned char *wtcol_v = MEM_mallocN (sizeof(unsigned char) * numVerts * 4, "weightmap_v"); + unsigned char *wtcol_v = MEM_mallocN(sizeof(unsigned char) * numVerts * 4, "weightmap_v"); if (dv) { unsigned char *wc = wtcol_v; @@ -1089,7 +1089,7 @@ static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, i /* variables for multipaint */ const int defbase_tot = BLI_countlist(&ob->defbase); - const int defbase_act = ob->actdef-1; + const int defbase_act = ob->actdef - 1; char *dg_flags = MEM_mallocN(defbase_tot * sizeof(char), __func__); const int selected = get_selected_defgroups(ob, dg_flags, defbase_tot); @@ -1128,7 +1128,7 @@ static unsigned char *calc_colors_from_weights_array(const int num, float *weigh void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, float *weights, int num, const int *indices) { - ColorBand *coba= stored_cb; /* warning, not a local var */ + ColorBand *coba = stored_cb; /* warning, not a local var */ unsigned char *wtcol_v; #if 0 /* See coment below. */ @@ -1148,7 +1148,7 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, int i, j; #if 0 /* See comment below */ - /* If no CD_PREVIEW_MCOL existed yet, add a new one! */ + /* If no CD_PREVIEW_MCOL existed yet, add a new one! */ if (!wtcol_f) wtcol_f = CustomData_add_layer(&dm->faceData, CD_PREVIEW_MCOL, CD_CALLOC, NULL, numFaces); @@ -1170,7 +1170,7 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, /* If indices is not NULL, it means we do not have weights for all vertices, * so we must create them (and set them to zero)... */ if (indices) { - w = MEM_callocN(sizeof(float)*numVerts, "Temp weight array DM_update_weight_mcol"); + w = MEM_callocN(sizeof(float) * numVerts, "Temp weight array DM_update_weight_mcol"); i = num; while (i--) w[indices[i]] = weights[i]; @@ -1196,9 +1196,9 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, for (i = 0; i < numFaces; i++, mf++, wtcol_f_step += (4 * 4)) { /*origindex being NULL means we're operating on original mesh data*/ #if 0 - unsigned int fidx= mf->v4 ? 3:2; + unsigned int fidx = mf->v4 ? 3 : 2; -#else /* better zero out triangles 4th component. else valgrind complains when the buffer's copied */ +#else /* better zero out triangles 4th component. else valgrind complains when the buffer's copied */ unsigned int fidx; if (mf->v4) { fidx = 3; @@ -1220,7 +1220,7 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, if (!wtcol_l) { BLI_array_declare(wtcol_l); totloop = 0; - for (i=0; inumPolyData; i++, mp++) { + for (i = 0; i < dm->numPolyData; i++, mp++) { ml = mloop + mp->loopstart; BLI_array_grow_items(wtcol_l, mp->totloop); @@ -1233,10 +1233,10 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag, } else { totloop = 0; - for (i=0; i < dm->numPolyData; i++, mp++) { + for (i = 0; i < dm->numPolyData; i++, mp++) { ml = mloop + mp->loopstart; - for (j=0; j < mp->totloop; j++, ml++, totloop++) { + for (j = 0; j < mp->totloop; j++, ml++, totloop++) { copy_v4_v4_char((char *)&wtcol_l[totloop], (char *)&wtcol_v[4 * ml->v]); } @@ -1258,11 +1258,11 @@ static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape return; tot = CustomData_number_of_layers(&dm->vertData, CD_SHAPEKEY); - for (i=0; ivertData.layers[CustomData_get_layer_index_n(&dm->vertData, CD_SHAPEKEY, i)]; float (*cos)[3], (*kbcos)[3]; - for (kb=me->key->block.first; kb; kb=kb->next) { + for (kb = me->key->block.first; kb; kb = kb->next) { if (kb->uid == layer->uid) break; } @@ -1278,28 +1278,28 @@ static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape cos = CustomData_get_layer_n(&dm->vertData, CD_SHAPEKEY, i); kb->totelem = dm->numVertData; - kb->data = kbcos = MEM_mallocN(sizeof(float)*3*kb->totelem, "kbcos DerivedMesh.c"); + kb->data = kbcos = MEM_mallocN(sizeof(float) * 3 * kb->totelem, "kbcos DerivedMesh.c"); if (kb->uid == actshape_uid) { MVert *mvert = dm->getVertArray(dm); - for (j=0; jnumVertData; j++, kbcos++, mvert++) { + for (j = 0; j < dm->numVertData; j++, kbcos++, mvert++) { copy_v3_v3(*kbcos, mvert->co); } } else { - for (j=0; jtotelem; j++, cos++, kbcos++) { + for (j = 0; j < kb->totelem; j++, cos++, kbcos++) { copy_v3_v3(*kbcos, *cos); } } } - for (kb=me->key->block.first; kb; kb=kb->next) { + for (kb = me->key->block.first; kb; kb = kb->next) { if (kb->totelem != dm->numVertData) { if (kb->data) MEM_freeN(kb->data); kb->totelem = dm->numVertData; - kb->data = MEM_callocN(sizeof(float)*3*kb->totelem, "kb->data derivedmesh.c"); + kb->data = MEM_callocN(sizeof(float) * 3 * kb->totelem, "kb->data derivedmesh.c"); fprintf(stderr, "%s: lost a shapekey layer: '%s'! (bmesh internal error)\n", __func__, kb->name); } } @@ -1319,11 +1319,11 @@ static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *UNUSED(ob)) if (me->totvert != dm->getNumVerts(dm)) { fprintf(stderr, "%s: vertex size mismatch (mesh/dm) '%s' (%d != %d)\n", - __func__, me->id.name+2, me->totvert, dm->getNumVerts(dm)); + __func__, me->id.name + 2, me->totvert, dm->getNumVerts(dm)); return; } - for (i=0, kb=key->block.first; kb; kb=kb->next, i++) { + for (i = 0, kb = key->block.first; kb; kb = kb->next, i++) { int ci; float *array; @@ -1351,10 +1351,10 @@ static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *UNUSED(ob)) * - apply deform modifiers and input vertexco */ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos)[3], - DerivedMesh **deform_r, DerivedMesh **final_r, - int useRenderParams, int useDeform, - int needMapping, CustomDataMask dataMask, - int index, int useCache, int build_shapekey_layers) + DerivedMesh **deform_r, DerivedMesh **final_r, + int useRenderParams, int useDeform, + int needMapping, CustomDataMask dataMask, + int index, int useCache, int build_shapekey_layers) { Mesh *me = ob->data; ModifierData *firstmd, *md, *previewmd = NULL; @@ -1362,17 +1362,17 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* XXX Always copying POLYINDEX, else tessellated data are no more valid! */ CustomDataMask mask, nextmask, append_mask = CD_MASK_POLYINDEX; float (*deformedVerts)[3] = NULL; - DerivedMesh *dm=NULL, *orcodm, *clothorcodm, *finaldm; + DerivedMesh *dm = NULL, *orcodm, *clothorcodm, *finaldm; int numVerts = me->totvert; int required_mode; - int isPrevDeform= FALSE; + int isPrevDeform = FALSE; int skipVirtualArmature = (useDeform < 0); - MultiresModifierData *mmd= get_multires_modifier(scene, ob, 0); + MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0); int has_multires = mmd != NULL, multires_applied = 0; int sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt; - const int draw_flag= ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 0) | - (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0)); + const int draw_flag = ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 0) | + (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0)); /* Generic preview only in object mode! */ const int do_mod_mcol = (ob->mode == OB_MODE_OBJECT); #if 0 /* XXX Will re-enable this when we have global mod stack options. */ @@ -1385,9 +1385,9 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos ModifierApplyFlag app_flags = useRenderParams ? MOD_APPLY_RENDER : 0; ModifierApplyFlag deform_app_flags = app_flags; - if (useCache) + if (useCache) app_flags |= MOD_APPLY_USECACHE; - if (useDeform) + if (useDeform) deform_app_flags |= MOD_APPLY_USECACHE; if (mmd && !mmd->sculptlvl) @@ -1429,10 +1429,10 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos deformedVerts = inputVertexCos; /* Apply all leading deforming modifiers */ - for (;md; md = md->next, curr = curr->next) { + for (; md; md = md->next, curr = curr->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; + md->scene = scene; if (!modifier_isEnabled(scene, md, required_mode)) continue; if (useDeform < 0 && mti->dependsOnTime && mti->dependsOnTime(md)) continue; @@ -1484,10 +1484,10 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos orcodm = NULL; clothorcodm = NULL; - for (;md; md = md->next, curr = curr->next) { + for (; md; md = md->next, curr = curr->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; + md->scene = scene; if (!modifier_isEnabled(scene, md, required_mode)) continue; if (mti->type == eModifierTypeType_OnlyDeform && !useDeform) continue; @@ -1496,13 +1496,13 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos continue; } if (sculpt_mode && (!has_multires || multires_applied)) { - int unsupported= 0; + int unsupported = 0; if (scene->toolsettings->sculpt->flags & SCULPT_ONLY_DEFORM) - unsupported|= mti->type != eModifierTypeType_OnlyDeform; + unsupported |= mti->type != eModifierTypeType_OnlyDeform; - unsupported|= md->type == eModifierType_Multires && ((MultiresModifierData*)md)->sculptlvl==0; - unsupported|= multires_applied; + unsupported |= md->type == eModifierType_Multires && ((MultiresModifierData *)md)->sculptlvl == 0; + unsupported |= multires_applied; if (unsupported) { modifier_setError(md, "%s", TIP_("Not supported in sculpt mode.")); @@ -1536,7 +1536,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos */ numVerts = dm->getNumVerts(dm); deformedVerts = - MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv"); + MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv"); dm->getVertCos(dm, deformedVerts); } else { @@ -1561,9 +1561,9 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* determine which data layers are needed by following modifiers */ if (curr->next) - nextmask= curr->next->mask; + nextmask = curr->next->mask; else - nextmask= dataMask; + nextmask = dataMask; /* apply vertex coordinates or build a DerivedMesh as necessary */ if (dm) { @@ -1611,7 +1611,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* set the DerivedMesh to only copy needed data */ - mask= curr->mask; + mask = curr->mask; /* needMapping check here fixes bug [#28112], otherwise its * possible that it wont be copied */ mask |= append_mask; @@ -1648,7 +1648,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* create an orco derivedmesh in parallel */ if (nextmask & CD_MASK_ORCO) { if (!orcodm) - orcodm= create_orco_dm(ob, me, NULL, CD_ORCO); + orcodm = create_orco_dm(ob, me, NULL, CD_ORCO); nextmask &= ~CD_MASK_ORCO; DM_set_only_copy(orcodm, nextmask | CD_MASK_ORIGINDEX); @@ -1664,7 +1664,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* create cloth orco derivedmesh in parallel */ if (nextmask & CD_MASK_CLOTH_ORCO) { if (!clothorcodm) - clothorcodm= create_orco_dm(ob, me, NULL, CD_CLOTH_ORCO); + clothorcodm = create_orco_dm(ob, me, NULL, CD_CLOTH_ORCO); nextmask &= ~CD_MASK_CLOTH_ORCO; DM_set_only_copy(clothorcodm, nextmask | CD_MASK_ORIGINDEX); @@ -1688,7 +1688,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } } - isPrevDeform= (mti->type == eModifierTypeType_OnlyDeform); + isPrevDeform = (mti->type == eModifierTypeType_OnlyDeform); /* grab modifiers until index i */ if ((index >= 0) && (modifiers_indexInObject(ob, md) >= index)) @@ -1698,7 +1698,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos multires_applied = 1; } - for (md=firstmd; md; md=md->next) + for (md = firstmd; md; md = md->next) modifier_freeTemporaryData(md); /* Yay, we are done. If we have a DerivedMesh and deformed vertices @@ -1729,18 +1729,18 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos #endif } else { - int recalc_normals= 0; + int recalc_normals = 0; finaldm = CDDM_from_mesh(me, ob); if (build_shapekey_layers) { add_shapekey_layers(finaldm, me, ob); - recalc_normals= 1; + recalc_normals = 1; } if (deformedVerts) { CDDM_apply_vert_coords(finaldm, deformedVerts); - recalc_normals= 1; + recalc_normals = 1; } if (recalc_normals) { @@ -1819,10 +1819,10 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* NavMesh - this is a hack but saves having a NavMesh modifier */ if ((ob->gameflag & OB_NAVMESH) && (finaldm->type == DM_TYPE_CDDM)) { DerivedMesh *tdm; - tdm= navmesh_dm_createNavMeshForVisualization(finaldm); + tdm = navmesh_dm_createNavMeshForVisualization(finaldm); if (finaldm != tdm) { finaldm->release(finaldm); - finaldm= tdm; + finaldm = tdm; } } #endif /* WITH_GAMEENGINE */ @@ -1837,20 +1837,20 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos if (deformedVerts && deformedVerts != inputVertexCos) MEM_freeN(deformedVerts); - BLI_linklist_free((LinkNode*)datamasks, NULL); + BLI_linklist_free((LinkNode *)datamasks, NULL); } -float (*editbmesh_get_vertex_cos(BMEditMesh *em, int *numVerts_r))[3] +float (*editbmesh_get_vertex_cos(BMEditMesh * em, int *numVerts_r))[3] { int i, numVerts = *numVerts_r = em->bm->totvert; float (*cos)[3]; BMIter iter; BMVert *eve; - cos = MEM_mallocN(sizeof(float)*3*numVerts, "vertexcos"); + cos = MEM_mallocN(sizeof(float) * 3 * numVerts, "vertexcos"); eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); - for (i=0; eve; eve=BM_iter_step(&iter), i++) { + for (i = 0; eve; eve = BM_iter_step(&iter), i++) { copy_v3_v3(cos[i], eve->co); } @@ -1872,8 +1872,8 @@ int editbmesh_modifier_is_enabled(Scene *scene, ModifierData *md, DerivedMesh *d } static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, DerivedMesh **cage_r, - DerivedMesh **final_r, - CustomDataMask dataMask) + DerivedMesh **final_r, + CustomDataMask dataMask) { ModifierData *md; float (*deformedVerts)[3] = NULL; @@ -1898,7 +1898,7 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D for (i = 0; md; i++, md = md->next, curr = curr->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; + md->scene = scene; if (!editbmesh_modifier_is_enabled(scene, md, dm)) continue; @@ -1925,7 +1925,7 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D */ numVerts = dm->getNumVerts(dm); deformedVerts = - MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv"); + MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv"); dm->getVertCos(dm, deformedVerts); } else { @@ -1968,10 +1968,10 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D } /* create an orco derivedmesh in parallel */ - mask= curr->mask; + mask = curr->mask; if (mask & CD_MASK_ORCO) { if (!orcodm) - orcodm= create_orco_dm(ob, ob->data, em, CD_ORCO); + orcodm = create_orco_dm(ob, ob->data, em, CD_ORCO); mask &= ~CD_MASK_ORCO; DM_set_only_copy(orcodm, mask | CD_MASK_ORIGINDEX); @@ -1989,7 +1989,7 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D } /* set the DerivedMesh to only copy needed data */ - mask= curr->mask; /* CD_MASK_ORCO may have been cleared above */ + mask = curr->mask; /* CD_MASK_ORCO may have been cleared above */ DM_set_only_copy(dm, mask | CD_MASK_ORIGINDEX); @@ -2028,13 +2028,13 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D } else { *cage_r = - getEditDerivedBMesh(em, ob, - deformedVerts ? MEM_dupallocN(deformedVerts) : NULL); + getEditDerivedBMesh(em, ob, + deformedVerts ? MEM_dupallocN(deformedVerts) : NULL); } } } - BLI_linklist_free((LinkNode*)datamasks, NULL); + BLI_linklist_free((LinkNode *)datamasks, NULL); /* Yay, we are done. If we have a DerivedMesh and deformed vertices need * to apply these back onto the DerivedMesh. If we have no DerivedMesh @@ -2093,9 +2093,9 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D static void clear_mesh_caches(Object *ob) { - Mesh *me= ob->data; + Mesh *me = ob->data; - /* also serves as signal to remake texspace */ + /* also serves as signal to remake texspace */ if (ob->bb) { MEM_freeN(ob->bb); ob->bb = NULL; @@ -2110,12 +2110,12 @@ static void clear_mesh_caches(Object *ob) if (ob->derivedFinal) { ob->derivedFinal->needsFree = 1; ob->derivedFinal->release(ob->derivedFinal); - ob->derivedFinal= NULL; + ob->derivedFinal = NULL; } if (ob->derivedDeform) { ob->derivedDeform->needsFree = 1; ob->derivedDeform->release(ob->derivedDeform); - ob->derivedDeform= NULL; + ob->derivedDeform = NULL; } if (ob->sculpt) { @@ -2126,18 +2126,18 @@ static void clear_mesh_caches(Object *ob) static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask, int build_shapekey_layers) { - Object *obact = scene->basact?scene->basact->object:NULL; + Object *obact = scene->basact ? scene->basact->object : NULL; int editing = paint_facesel_test(ob); /* weight paint and face select need original indices because of selection buffer drawing */ - int needMapping = (ob==obact) && (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT|OB_MODE_VERTEX_PAINT|OB_MODE_TEXTURE_PAINT))); + int needMapping = (ob == obact) && (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT | OB_MODE_VERTEX_PAINT | OB_MODE_TEXTURE_PAINT))); clear_mesh_caches(ob); mesh_calc_modifiers(scene, ob, NULL, &ob->derivedDeform, - &ob->derivedFinal, 0, 1, - needMapping, dataMask, -1, 1, build_shapekey_layers); + &ob->derivedFinal, 0, 1, + needMapping, dataMask, -1, 1, build_shapekey_layers); - DM_set_object_boundbox (ob, ob->derivedFinal); + DM_set_object_boundbox(ob, ob->derivedFinal); ob->derivedFinal->needsFree = 0; ob->derivedDeform->needsFree = 0; @@ -2146,7 +2146,7 @@ static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask, if ((ob->mode & OB_MODE_SCULPT) && ob->sculpt) { /* create PBVH immediately (would be created on the fly too, * but this avoids waiting on first stroke) */ - ob->sculpt->pbvh= ob->derivedFinal->getPBVH(ob, ob->derivedFinal); + ob->sculpt->pbvh = ob->derivedFinal->getPBVH(ob, ob->derivedFinal); } } @@ -2155,7 +2155,7 @@ static void editbmesh_build_data(Scene *scene, Object *obedit, BMEditMesh *em, C clear_mesh_caches(obedit); if (em->derivedFinal) { - if (em->derivedFinal!=em->derivedCage) { + if (em->derivedFinal != em->derivedCage) { em->derivedFinal->needsFree = 1; em->derivedFinal->release(em->derivedFinal); } @@ -2168,7 +2168,7 @@ static void editbmesh_build_data(Scene *scene, Object *obedit, BMEditMesh *em, C } editbmesh_calc_modifiers(scene, obedit, em, &em->derivedCage, &em->derivedFinal, dataMask); - DM_set_object_boundbox (obedit, em->derivedFinal); + DM_set_object_boundbox(obedit, em->derivedFinal); em->lastDataMask = dataMask; em->derivedFinal->needsFree = 0; @@ -2238,7 +2238,7 @@ DerivedMesh *mesh_create_derived_view(Scene *scene, Object *ob, CustomDataMask d } DerivedMesh *mesh_create_derived_no_deform(Scene *scene, Object *ob, float (*vertCos)[3], - CustomDataMask dataMask) + CustomDataMask dataMask) { DerivedMesh *final; @@ -2248,7 +2248,7 @@ DerivedMesh *mesh_create_derived_no_deform(Scene *scene, Object *ob, float (*ver } DerivedMesh *mesh_create_derived_no_virtual(Scene *scene, Object *ob, float (*vertCos)[3], - CustomDataMask dataMask) + CustomDataMask dataMask) { DerivedMesh *final; @@ -2258,7 +2258,7 @@ DerivedMesh *mesh_create_derived_no_virtual(Scene *scene, Object *ob, float (*ve } DerivedMesh *mesh_create_derived_physics(Scene *scene, Object *ob, float (*vertCos)[3], - CustomDataMask dataMask) + CustomDataMask dataMask) { DerivedMesh *final; @@ -2268,8 +2268,8 @@ DerivedMesh *mesh_create_derived_physics(Scene *scene, Object *ob, float (*vertC } DerivedMesh *mesh_create_derived_no_deform_render(Scene *scene, Object *ob, - float (*vertCos)[3], - CustomDataMask dataMask) + float (*vertCos)[3], + CustomDataMask dataMask) { DerivedMesh *final; @@ -2281,7 +2281,7 @@ DerivedMesh *mesh_create_derived_no_deform_render(Scene *scene, Object *ob, /***/ DerivedMesh *editbmesh_get_derived_cage_and_final(Scene *scene, Object *obedit, BMEditMesh *em, DerivedMesh **final_r, - CustomDataMask dataMask) + CustomDataMask dataMask) { /* if there's no derived mesh or the last data mask used doesn't include * the data we need, rebuild the derived mesh @@ -2323,13 +2323,13 @@ static void make_vertexcosnos__mapFunc(void *userData, int index, const float co { float *vec = userData; - vec+= 6*index; + vec += 6 * index; /* check if we've been here before (normal should not be 0) */ if (vec[3] || vec[4] || vec[5]) return; copy_v3_v3(vec, co); - vec+= 3; + vec += 3; if (no_f) { copy_v3_v3(vec, no_f); } @@ -2345,27 +2345,27 @@ static void make_vertexcosnos__mapFunc(void *userData, int index, const float co float *mesh_get_mapped_verts_nors(Scene *scene, Object *ob) { - Mesh *me= ob->data; + Mesh *me = ob->data; DerivedMesh *dm; float *vertexcosnos; /* lets prevent crashing... */ - if (ob->type!=OB_MESH || me->totvert==0) + if (ob->type != OB_MESH || me->totvert == 0) return NULL; - dm= mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH|CD_MASK_ORIGINDEX); - vertexcosnos= MEM_callocN(6*sizeof(float)*me->totvert, "vertexcosnos map"); + dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); + vertexcosnos = MEM_callocN(6 * sizeof(float) * me->totvert, "vertexcosnos map"); if (dm->foreachMappedVert) { dm->foreachMappedVert(dm, make_vertexcosnos__mapFunc, vertexcosnos); } else { - float *fp= vertexcosnos; + float *fp = vertexcosnos; int a; - for (a=0; a< me->totvert; a++, fp+=6) { + for (a = 0; a < me->totvert; a++, fp += 6) { dm->getVertCo(dm, a, fp); - dm->getVertNo(dm, a, fp+3); + dm->getVertNo(dm, a, fp + 3); } } @@ -2375,14 +2375,13 @@ float *mesh_get_mapped_verts_nors(Scene *scene, Object *ob) /* ******************* GLSL ******************** */ -typedef struct -{ - float * precomputedFaceNormals; - MTFace * mtface; // texture coordinates - MFace * mface; // indices - MVert * mvert; // vertices & normals +typedef struct { + float *precomputedFaceNormals; + MTFace *mtface; // texture coordinates + MFace *mface; // indices + MVert *mvert; // vertices & normals float (*orco)[3]; - float (*tangent)[4]; // destination + float (*tangent)[4]; // destination int numTessFaces; } SGLSLMeshToTangent; @@ -2390,56 +2389,56 @@ typedef struct // interface #include "mikktspace.h" -static int GetNumFaces(const SMikkTSpaceContext * pContext) +static int GetNumFaces(const SMikkTSpaceContext *pContext) { - SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; + SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; return pMesh->numTessFaces; } -static int GetNumVertsOfFace(const SMikkTSpaceContext * pContext, const int face_num) +static int GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int face_num) { - SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; - return pMesh->mface[face_num].v4!=0 ? 4 : 3; + SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; + return pMesh->mface[face_num].v4 != 0 ? 4 : 3; } -static void GetPosition(const SMikkTSpaceContext * pContext, float fPos[], const int face_num, const int vert_index) +static void GetPosition(const SMikkTSpaceContext *pContext, float fPos[], const int face_num, const int vert_index) { //assert(vert_index>=0 && vert_index<4); - SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; - const float *co= pMesh->mvert[(&pMesh->mface[face_num].v1)[vert_index]].co; + SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; + const float *co = pMesh->mvert[(&pMesh->mface[face_num].v1)[vert_index]].co; copy_v3_v3(fPos, co); } -static void GetTextureCoordinate(const SMikkTSpaceContext * pContext, float fUV[], const int face_num, const int vert_index) +static void GetTextureCoordinate(const SMikkTSpaceContext *pContext, float fUV[], const int face_num, const int vert_index) { //assert(vert_index>=0 && vert_index<4); - SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; + SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; - if (pMesh->mtface!=NULL) { - float * uv = pMesh->mtface[face_num].uv[vert_index]; - fUV[0]=uv[0]; fUV[1]=uv[1]; + if (pMesh->mtface != NULL) { + float *uv = pMesh->mtface[face_num].uv[vert_index]; + fUV[0] = uv[0]; fUV[1] = uv[1]; } else { - const float *orco= pMesh->orco[(&pMesh->mface[face_num].v1)[vert_index]]; + const float *orco = pMesh->orco[(&pMesh->mface[face_num].v1)[vert_index]]; map_to_sphere(&fUV[0], &fUV[1], orco[0], orco[1], orco[2]); } } -static void GetNormal(const SMikkTSpaceContext * pContext, float fNorm[], const int face_num, const int vert_index) +static void GetNormal(const SMikkTSpaceContext *pContext, float fNorm[], const int face_num, const int vert_index) { //assert(vert_index>=0 && vert_index<4); - SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; + SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; const int smoothnormal = (pMesh->mface[face_num].flag & ME_SMOOTH); - if (!smoothnormal) { // flat + if (!smoothnormal) { // flat if (pMesh->precomputedFaceNormals) { - copy_v3_v3(fNorm, &pMesh->precomputedFaceNormals[3*face_num]); + copy_v3_v3(fNorm, &pMesh->precomputedFaceNormals[3 * face_num]); } else { - MFace *mf= &pMesh->mface[face_num]; - float *p0= pMesh->mvert[mf->v1].co; - float *p1= pMesh->mvert[mf->v2].co; - float *p2= pMesh->mvert[mf->v3].co; + MFace *mf = &pMesh->mface[face_num]; + float *p0 = pMesh->mvert[mf->v1].co; + float *p1 = pMesh->mvert[mf->v2].co; + float *p2 = pMesh->mvert[mf->v3].co; if (mf->v4) { float *p3 = pMesh->mvert[mf->v4].co; @@ -2451,17 +2450,17 @@ static void GetNormal(const SMikkTSpaceContext * pContext, float fNorm[], const } } else { - const short *no= pMesh->mvert[(&pMesh->mface[face_num].v1)[vert_index]].no; + const short *no = pMesh->mvert[(&pMesh->mface[face_num].v1)[vert_index]].no; normal_short_to_float_v3(fNorm, no); } } -static void SetTSpace(const SMikkTSpaceContext * pContext, const float fvTangent[], const float fSign, const int face_num, const int iVert) +static void SetTSpace(const SMikkTSpaceContext *pContext, const float fvTangent[], const float fSign, const int face_num, const int iVert) { //assert(vert_index>=0 && vert_index<4); - SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; - float * pRes = pMesh->tangent[4*face_num+iVert]; + SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; + float *pRes = pMesh->tangent[4 * face_num + iVert]; copy_v3_v3(pRes, fvTangent); - pRes[3]=fSign; + pRes[3] = fSign; } @@ -2471,9 +2470,9 @@ void DM_add_tangent_layer(DerivedMesh *dm) MTFace *mtface, *tf; MFace *mface, *mf; MVert *mvert, *v1, *v2, *v3, *v4; - MemArena *arena= NULL; - VertexTangent **vtangents= NULL; - float (*orco)[3]= NULL, (*tangent)[4]; + MemArena *arena = NULL; + VertexTangent **vtangents = NULL; + float (*orco)[3] = NULL, (*tangent)[4]; float *uv1, *uv2, *uv3, *uv4, *vtang; float fno[3], tang[3], uv[4][2]; int i, j, len, mf_vi[4], totvert, totface, iCalcNewMethod; @@ -2485,34 +2484,34 @@ void DM_add_tangent_layer(DerivedMesh *dm) nors = dm->getTessFaceDataArray(dm, CD_NORMAL); /* check we have all the needed layers */ - totvert= dm->getNumVerts(dm); - totface= dm->getNumTessFaces(dm); + totvert = dm->getNumVerts(dm); + totface = dm->getNumTessFaces(dm); - mvert= dm->getVertArray(dm); - mface= dm->getTessFaceArray(dm); - mtface= dm->getTessFaceDataArray(dm, CD_MTFACE); + mvert = dm->getVertArray(dm); + mface = dm->getTessFaceArray(dm); + mtface = dm->getTessFaceDataArray(dm, CD_MTFACE); if (!mtface) { - orco= dm->getVertDataArray(dm, CD_ORCO); + orco = dm->getVertDataArray(dm, CD_ORCO); if (!orco) return; } /* create tangent layer */ DM_add_tessface_layer(dm, CD_TANGENT, CD_CALLOC, NULL); - tangent= DM_get_tessface_data_layer(dm, CD_TANGENT); + tangent = DM_get_tessface_data_layer(dm, CD_TANGENT); /* allocate some space */ - arena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "tangent layer arena"); + arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "tangent layer arena"); BLI_memarena_use_calloc(arena); - vtangents= MEM_callocN(sizeof(VertexTangent*)*totvert, "VertexTangent"); + vtangents = MEM_callocN(sizeof(VertexTangent *) * totvert, "VertexTangent"); // new computation method iCalcNewMethod = 1; if (iCalcNewMethod != 0) { - SGLSLMeshToTangent mesh2tangent= {0}; - SMikkTSpaceContext sContext= {0}; - SMikkTSpaceInterface sInterface= {0}; + SGLSLMeshToTangent mesh2tangent = {0}; + SMikkTSpaceContext sContext = {0}; + SMikkTSpaceInterface sInterface = {0}; mesh2tangent.precomputedFaceNormals = nors; mesh2tangent.mtface = mtface; @@ -2537,28 +2536,28 @@ void DM_add_tangent_layer(DerivedMesh *dm) if (!iCalcNewMethod) { /* sum tangents at connected vertices */ - for (i=0, tf=mtface, mf=mface; i < totface; mf++, tf++, i++) { - v1= &mvert[mf->v1]; - v2= &mvert[mf->v2]; - v3= &mvert[mf->v3]; + for (i = 0, tf = mtface, mf = mface; i < totface; mf++, tf++, i++) { + v1 = &mvert[mf->v1]; + v2 = &mvert[mf->v2]; + v3 = &mvert[mf->v3]; if (mf->v4) { - v4= &mvert[mf->v4]; + v4 = &mvert[mf->v4]; normal_quad_v3(fno, v4->co, v3->co, v2->co, v1->co); } else { - v4= NULL; + v4 = NULL; normal_tri_v3(fno, v3->co, v2->co, v1->co); } if (mtface) { - uv1= tf->uv[0]; - uv2= tf->uv[1]; - uv3= tf->uv[2]; - uv4= tf->uv[3]; + uv1 = tf->uv[0]; + uv2 = tf->uv[1]; + uv3 = tf->uv[2]; + uv4 = tf->uv[3]; } else { - uv1= uv[0]; uv2= uv[1]; uv3= uv[2]; uv4= uv[3]; + uv1 = uv[0]; uv2 = uv[1]; uv3 = uv[2]; uv4 = uv[3]; map_to_sphere(&uv[0][0], &uv[0][1], orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2]); map_to_sphere(&uv[1][0], &uv[1][1], orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2]); map_to_sphere(&uv[2][0], &uv[2][1], orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2]); @@ -2572,7 +2571,7 @@ void DM_add_tangent_layer(DerivedMesh *dm) sum_or_add_vertex_tangent(arena, &vtangents[mf->v3], tang, uv3); if (mf->v4) { - v4= &mvert[mf->v4]; + v4 = &mvert[mf->v4]; tangent_from_uv(uv1, uv3, uv4, v1->co, v3->co, v4->co, fno, tang); sum_or_add_vertex_tangent(arena, &vtangents[mf->v1], tang, uv1); @@ -2582,26 +2581,26 @@ void DM_add_tangent_layer(DerivedMesh *dm) } /* write tangent to layer */ - for (i=0, tf=mtface, mf=mface; i < totface; mf++, tf++, i++, tangent+=4) { - len= (mf->v4)? 4 : 3; + for (i = 0, tf = mtface, mf = mface; i < totface; mf++, tf++, i++, tangent += 4) { + len = (mf->v4) ? 4 : 3; if (mtface == NULL) { map_to_sphere(&uv[0][0], &uv[0][1], orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2]); map_to_sphere(&uv[1][0], &uv[1][1], orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2]); map_to_sphere(&uv[2][0], &uv[2][1], orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2]); - if (len==4) + if (len == 4) map_to_sphere(&uv[3][0], &uv[3][1], orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2]); } - mf_vi[0]= mf->v1; - mf_vi[1]= mf->v2; - mf_vi[2]= mf->v3; - mf_vi[3]= mf->v4; + mf_vi[0] = mf->v1; + mf_vi[1] = mf->v2; + mf_vi[2] = mf->v3; + mf_vi[3] = mf->v4; - for (j=0; juv[j] : uv[j]); + for (j = 0; j < len; j++) { + vtang = find_vertex_tangent(vtangents[mf_vi[j]], mtface ? tf->uv[j] : uv[j]); normalize_v3_v3(tangent[j], vtang); - ((float *) tangent[j])[3]=1.0f; + ((float *) tangent[j])[3] = 1.0f; } } } @@ -2613,34 +2612,34 @@ void DM_add_tangent_layer(DerivedMesh *dm) void DM_calc_auto_bump_scale(DerivedMesh *dm) { /* int totvert= dm->getNumVerts(dm); */ /* UNUSED */ - int totface= dm->getNumTessFaces(dm); + int totface = dm->getNumTessFaces(dm); - MVert * mvert = dm->getVertArray(dm); - MFace * mface = dm->getTessFaceArray(dm); - MTFace * mtface = dm->getTessFaceDataArray(dm, CD_MTFACE); + MVert *mvert = dm->getVertArray(dm); + MFace *mface = dm->getTessFaceArray(dm); + MTFace *mtface = dm->getTessFaceDataArray(dm, CD_MTFACE); if (mtface) { double dsum = 0.0; int nr_accumulated = 0; int f; - for (f=0; f < totface; f++ ) { + for (f = 0; f < totface; f++) { { - float * verts[4], * tex_coords[4]; - const int nr_verts = mface[f].v4!=0 ? 4 : 3; + float *verts[4], *tex_coords[4]; + const int nr_verts = mface[f].v4 != 0 ? 4 : 3; int i, is_degenerate; - verts[0]=mvert[mface[f].v1].co; verts[1]=mvert[mface[f].v2].co; verts[2]=mvert[mface[f].v3].co; - tex_coords[0]=mtface[f].uv[0]; tex_coords[1]=mtface[f].uv[1]; tex_coords[2]=mtface[f].uv[2]; - if (nr_verts==4) { - verts[3]=mvert[mface[f].v4].co; - tex_coords[3]=mtface[f].uv[3]; + verts[0] = mvert[mface[f].v1].co; verts[1] = mvert[mface[f].v2].co; verts[2] = mvert[mface[f].v3].co; + tex_coords[0] = mtface[f].uv[0]; tex_coords[1] = mtface[f].uv[1]; tex_coords[2] = mtface[f].uv[2]; + if (nr_verts == 4) { + verts[3] = mvert[mface[f].v4].co; + tex_coords[3] = mtface[f].uv[3]; } // discard degenerate faces is_degenerate = 0; - if ( equals_v3v3(verts[0], verts[1]) || equals_v3v3(verts[0], verts[2]) || equals_v3v3(verts[1], verts[2]) || - equals_v2v2(tex_coords[0], tex_coords[1]) || equals_v2v2(tex_coords[0], tex_coords[2]) || equals_v2v2(tex_coords[1], tex_coords[2])) + if (equals_v3v3(verts[0], verts[1]) || equals_v3v3(verts[0], verts[2]) || equals_v3v3(verts[1], verts[2]) || + equals_v2v2(tex_coords[0], tex_coords[1]) || equals_v2v2(tex_coords[0], tex_coords[2]) || equals_v2v2(tex_coords[1], tex_coords[2])) { is_degenerate = 1; } @@ -2662,10 +2661,10 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm) i = 0; while (is_degenerate == 0 && i < 4) { float cur_edge[2], signed_area; - sub_v2_v2v2(cur_edge, tex_coords[(i+1)&0x3], tex_coords[i]); - signed_area = prev_edge[0]*cur_edge[1] - prev_edge[1]*cur_edge[0]; + sub_v2_v2v2(cur_edge, tex_coords[(i + 1) & 0x3], tex_coords[i]); + signed_area = prev_edge[0] * cur_edge[1] - prev_edge[1] * cur_edge[0]; - if (i == 0 ) { + if (i == 0) { is_signed = (signed_area < 0.0f) ? 1 : 0; } else if ((is_signed != 0) != (signed_area < 0.0f)) { @@ -2682,9 +2681,9 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm) // proceed if not a degenerate face if (is_degenerate == 0) { - int nr_tris_to_pile=0; + int nr_tris_to_pile = 0; // quads split at shortest diagonal - int offs = 0; // initial triangulation is 0,1,2 and 0, 2, 3 + int offs = 0; // initial triangulation is 0,1,2 and 0, 2, 3 if (nr_verts == 4) { float pos_len_diag0, pos_len_diag1; float vtmp[3]; @@ -2693,10 +2692,10 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm) sub_v3_v3v3(vtmp, verts[3], verts[1]); pos_len_diag1 = dot_v3v3(vtmp, vtmp); - if (pos_len_diag1FLT_EPSILON) { + f2x_area_uv = fabsf(edge_t0[0] * edge_t1[1] - edge_t0[1] * edge_t1[0]); + if (f2x_area_uv > FLT_EPSILON) { float norm[3], v0[3], v1[3], f2x_surf_area, fsurf_ratio; sub_v3_v3v3(v0, p1, p0); sub_v3_v3v3(v1, p2, p0); cross_v3_v3v3(norm, v0, v1); f2x_surf_area = len_v3(norm); - fsurf_ratio = f2x_surf_area/f2x_area_uv; // tri area divided by texture area + fsurf_ratio = f2x_surf_area / f2x_area_uv; // tri area divided by texture area nr_accumulated++; dsum += (double)(fsurf_ratio); @@ -2744,8 +2743,8 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm) // finalize { - const float avg_area_ratio = (nr_accumulated>0) ? ((float)(dsum / nr_accumulated)) : 1.0f; - const float use_as_render_bump_scale = sqrtf(avg_area_ratio); // use width of average surface ratio as your bump scale + const float avg_area_ratio = (nr_accumulated > 0) ? ((float)(dsum / nr_accumulated)) : 1.0f; + const float use_as_render_bump_scale = sqrtf(avg_area_ratio); // use width of average surface ratio as your bump scale dm->auto_bump_scale = use_as_render_bump_scale; } } @@ -2786,7 +2785,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, if (gattribs->layer[b].name[0]) layer = CustomData_get_named_layer_index(ldata, CD_MLOOPUV, - gattribs->layer[b].name); + gattribs->layer[b].name); else layer = CustomData_get_active_layer_index(ldata, CD_MLOOPUV); @@ -2802,7 +2801,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, else { if (gattribs->layer[b].name[0]) layer = CustomData_get_named_layer_index(tfdata, CD_MTFACE, - gattribs->layer[b].name); + gattribs->layer[b].name); else layer = CustomData_get_active_layer_index(tfdata, CD_MTFACE); @@ -2823,7 +2822,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, if (gattribs->layer[b].name[0]) layer = CustomData_get_named_layer_index(ldata, CD_MLOOPCOL, - gattribs->layer[b].name); + gattribs->layer[b].name); else layer = CustomData_get_active_layer_index(ldata, CD_MLOOPCOL); @@ -2839,7 +2838,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, /* vertex colors */ if (gattribs->layer[b].name[0]) layer = CustomData_get_named_layer_index(tfdata, CD_MCOL, - gattribs->layer[b].name); + gattribs->layer[b].name); else layer = CustomData_get_active_layer_index(tfdata, CD_MCOL); @@ -2890,7 +2889,7 @@ void DM_set_object_boundbox(Object *ob, DerivedMesh *dm) dm->getMinMax(dm, min, max); if (!ob->bb) - ob->bb= MEM_callocN(sizeof(BoundBox), "DM-BoundBox"); + ob->bb = MEM_callocN(sizeof(BoundBox), "DM-BoundBox"); BKE_boundbox_init_from_minmax(ob->bb, min, max); } @@ -2914,12 +2913,12 @@ BLI_INLINE int navmesh_bit(int a, int b) BLI_INLINE void navmesh_intToCol(int i, float col[3]) { - int r = navmesh_bit(i, 0) + navmesh_bit(i, 3) * 2 + 1; - int g = navmesh_bit(i, 1) + navmesh_bit(i, 4) * 2 + 1; - int b = navmesh_bit(i, 2) + navmesh_bit(i, 5) * 2 + 1; - col[0] = 1 - r*63.0f/255.0f; - col[1] = 1 - g*63.0f/255.0f; - col[2] = 1 - b*63.0f/255.0f; + int r = navmesh_bit(i, 0) + navmesh_bit(i, 3) * 2 + 1; + int g = navmesh_bit(i, 1) + navmesh_bit(i, 4) * 2 + 1; + int b = navmesh_bit(i, 2) + navmesh_bit(i, 5) * 2 + 1; + col[0] = 1 - r * 63.0f / 255.0f; + col[1] = 1 - g * 63.0f / 255.0f; + col[2] = 1 - b * 63.0f / 255.0f; } static void navmesh_drawColored(DerivedMesh *dm) @@ -2948,7 +2947,7 @@ static void navmesh_drawColored(DerivedMesh *dm) //glShadeModel(GL_SMOOTH); glBegin(glmode = GL_QUADS); for (a = 0; a < dm->numTessFaceData; a++, mface++) { - int new_glmode = mface->v4?GL_QUADS:GL_TRIANGLES; + int new_glmode = mface->v4 ? GL_QUADS : GL_TRIANGLES; int pi = polygonIdx[a]; if (pi <= 0) { zero_v3(col); @@ -2975,9 +2974,9 @@ static void navmesh_drawColored(DerivedMesh *dm) } static void navmesh_DM_drawFacesTex(DerivedMesh *dm, - DMSetDrawOptionsTex setDrawOptions, - DMCompareDrawOptions compareDrawOptions, - void *userData) + DMSetDrawOptionsTex setDrawOptions, + DMCompareDrawOptions compareDrawOptions, + void *userData) { (void) setDrawOptions; (void) compareDrawOptions; @@ -3002,21 +3001,21 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm) DerivedMesh *result; int maxFaces = dm->getNumPolys(dm); int *recastData; - int vertsPerPoly=0, nverts=0, ndtris=0, npolys=0; - float* verts=NULL; - unsigned short *dtris=NULL, *dmeshes=NULL, *polys=NULL; - int *dtrisToPolysMap=NULL, *dtrisToTrisMap=NULL, *trisToFacesMap=NULL; + int vertsPerPoly = 0, nverts = 0, ndtris = 0, npolys = 0; + float *verts = NULL; + unsigned short *dtris = NULL, *dmeshes = NULL, *polys = NULL; + int *dtrisToPolysMap = NULL, *dtrisToTrisMap = NULL, *trisToFacesMap = NULL; int res; result = CDDM_copy(dm); if (!CustomData_has_layer(&result->polyData, CD_RECAST)) { - int *sourceRecastData = (int*)CustomData_get_layer(&dm->polyData, CD_RECAST); + int *sourceRecastData = (int *)CustomData_get_layer(&dm->polyData, CD_RECAST); if (sourceRecastData) { CustomData_add_layer_named(&result->polyData, CD_RECAST, CD_DUPLICATE, sourceRecastData, maxFaces, "recastData"); } } - recastData = (int*)CustomData_get_layer(&result->polyData, CD_RECAST); + recastData = (int *)CustomData_get_layer(&result->polyData, CD_RECAST); /* note: This is not good design! - really should not be doing this */ result->drawFacesTex = navmesh_DM_drawFacesTex; @@ -3031,17 +3030,17 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm) size_t polyIdx; /* invalidate concave polygon */ - for (polyIdx=0; polyIdx<(size_t)npolys; polyIdx++) { - unsigned short* poly = &polys[polyIdx*2*vertsPerPoly]; + for (polyIdx = 0; polyIdx < (size_t)npolys; polyIdx++) { + unsigned short *poly = &polys[polyIdx * 2 * vertsPerPoly]; if (!polyIsConvex(poly, vertsPerPoly, verts)) { /* set negative polygon idx to all faces */ - unsigned short *dmesh = &dmeshes[4*polyIdx]; + unsigned short *dmesh = &dmeshes[4 * polyIdx]; unsigned short tbase = dmesh[2]; unsigned short tnum = dmesh[3]; unsigned short ti; - for (ti=0; ti 0) { recastData[faceidx] = -recastData[faceidx]; @@ -3055,19 +3054,19 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm) } /* clean up */ - if (verts!=NULL) + if (verts != NULL) MEM_freeN(verts); - if (dtris!=NULL) + if (dtris != NULL) MEM_freeN(dtris); - if (dmeshes!=NULL) + if (dmeshes != NULL) MEM_freeN(dmeshes); - if (polys!=NULL) + if (polys != NULL) MEM_freeN(polys); - if (dtrisToPolysMap!=NULL) + if (dtrisToPolysMap != NULL) MEM_freeN(dtrisToPolysMap); - if (dtrisToTrisMap!=NULL) + if (dtrisToTrisMap != NULL) MEM_freeN(dtrisToTrisMap); - if (trisToFacesMap!=NULL) + if (trisToFacesMap != NULL) MEM_freeN(trisToFacesMap); return result; @@ -3132,7 +3131,7 @@ static void dm_debug_info_layers(DynStr *dynstr, DerivedMesh *dm, void *(*getEle char *DM_debug_info(DerivedMesh *dm) { - DynStr *dynstr= BLI_dynstr_new(); + DynStr *dynstr = BLI_dynstr_new(); char *ret; const char *tstr; diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 09b295aabf1..599587cb15b 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -459,7 +459,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) } } - hlength1 = bone->ease1 * length * 0.390464f; /* 0.5*sqrt(2)*kappa, the handle length for near-perfect circles */ + hlength1 = bone->ease1 * length * 0.390464f; /* 0.5f * sqrt(2) * kappa, the handle length for near-perfect circles */ hlength2 = bone->ease2 * length * 0.390464f; /* evaluate next and prev bones */ @@ -566,14 +566,10 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) if (bone->segments > MAX_BBONE_SUBDIV) bone->segments = MAX_BBONE_SUBDIV; - BKE_curve_forward_diff_bezier(0.0, h1[0], h2[0], 0.0, data[0], - MAX_BBONE_SUBDIV, 4*sizeof(float)); - BKE_curve_forward_diff_bezier(0.0, h1[1], length + h2[1], length, data[0]+1, - MAX_BBONE_SUBDIV, 4*sizeof(float)); - BKE_curve_forward_diff_bezier(0.0, h1[2], h2[2], 0.0, data[0]+2, - MAX_BBONE_SUBDIV, 4*sizeof(float)); - 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)); + BKE_curve_forward_diff_bezier(0.0f, h1[0], h2[0], 0.0f, data[0], MAX_BBONE_SUBDIV, 4 * sizeof(float)); + BKE_curve_forward_diff_bezier(0.0f, h1[1], length + h2[1], length, data[0] + 1, MAX_BBONE_SUBDIV, 4 * sizeof(float)); + BKE_curve_forward_diff_bezier(0.0f, h1[2], h2[2], 0.0f, data[0] + 2, MAX_BBONE_SUBDIV, 4 * sizeof(float)); + 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! */ diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index ebf5735c1cd..19e7eb9dce1 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -251,7 +251,7 @@ void defvert_flip(MDeformVert *dvert, const int *flip_map, const int flip_map_le MDeformWeight *dw; int i; - for (dw = dvert->dw, i = 0; itotweight; dw++, i++) { + for (dw = dvert->dw, i = 0; i < dvert->totweight; dw++, i++) { if (dw->def_nr < flip_map_len) { if (flip_map[dw->def_nr] >= 0) { dw->def_nr = flip_map[dw->def_nr]; @@ -275,8 +275,8 @@ void defvert_flip_merged(MDeformVert *dvert, const int *flip_map, const int flip dw = &dvert->dw[i]; /* in case array got realloced */ /* distribute weights: if only one of the vertex groups was - * assigned this will halve the weights, otherwise it gets - * evened out. this keeps it proportional to other groups */ + * assigned this will halve the weights, otherwise it gets + * evened out. this keeps it proportional to other groups */ weight = 0.5f * (dw_cpy->weight + dw->weight); dw_cpy->weight = weight; dw->weight = weight; @@ -424,13 +424,13 @@ static int defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *o static int defgroup_unique_check(void *arg, const char *name) { - struct {Object *ob; void *dg;} *data = arg; + struct {Object *ob; void *dg; } *data = arg; return defgroup_find_name_dupe(name, data->dg, data->ob); } void defgroup_unique_name(bDeformGroup *dg, Object *ob) { - struct {Object *ob; void *dg;} data; + struct {Object *ob; void *dg; } data; data.ob = ob; data.dg = dg; @@ -595,7 +595,7 @@ void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_ } } - BLI_snprintf (name, MAX_VGROUP_NAME, "%s%s%s%s", prefix, replace, suffix, number); + BLI_snprintf(name, MAX_VGROUP_NAME, "%s%s%s%s", prefix, replace, suffix, number); } float defvert_find_weight(const struct MDeformVert *dvert, const int defgroup) @@ -710,7 +710,7 @@ void defvert_remove_group(MDeformVert *dvert, MDeformWeight *dw) if (dvert->totweight) { dw_new = MEM_mallocN(sizeof(MDeformWeight) * (dvert->totweight), __func__); if (dvert->dw) { -#if 1 /* since we don't care about order, swap this with the last, save a memcpy */ +#if 1 /* since we don't care about order, swap this with the last, save a memcpy */ if (i != dvert->totweight) { dvert->dw[i] = dvert->dw[dvert->totweight]; } diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index fc54ea6eed5..c6f46a7309b 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -2385,7 +2385,7 @@ static void dag_current_scene_layers(Main *bmain, Scene **sce, unsigned int *lay /* if we have a windowmanager, look into windows */ for (win = wm->windows.first; win; win = win->next) { if (win->screen) { - if (!*sce) *sce = win->screen->scene; + if (*sce == NULL) *sce = win->screen->scene; *lay |= BKE_screen_visible_layers(win->screen, win->screen->scene); } } diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 428dc176e1d..f480f881a8d 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -113,7 +113,7 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) #define USE_TESSFACE_SPEEDUP BMesh *bm = tm->bm; - BMLoop *(*looptris)[3]= NULL; + BMLoop *(*looptris)[3] = NULL; BLI_array_declare(looptris); BMIter iter, liter; BMFace *f; @@ -163,7 +163,7 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) else if (f->len == 3) { 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++) { + for (j = 0; l; l = BM_iter_step(&liter), j++) { looptris[i][j] = l; } i += 1; @@ -173,7 +173,7 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) 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++) { + for (j = 0; l; l = BM_iter_step(&liter), j++) { ltmp[j] = l; } @@ -191,7 +191,7 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) #endif /* USE_TESSFACE_SPEEDUP */ else { - ScanFillVert *v, *lastv=NULL, *firstv=NULL; + ScanFillVert *v, *lastv = NULL, *firstv = NULL; /* ScanFillEdge *e; */ /* UNUSED */ ScanFillFace *efa; int totfilltri; @@ -199,7 +199,7 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) BLI_scanfill_begin(&sf_ctx); /*scanfill time*/ l = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, f); - for (j=0; l; l=BM_iter_step(&liter), j++) { + for (j = 0; l; l = BM_iter_step(&liter), j++) { /*mark order*/ BM_elem_index_set(l, j); /* set_loop */ @@ -211,7 +211,7 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) } lastv = v; - if (firstv==NULL) firstv = v; + if (firstv == NULL) firstv = v; } /*complete the loop*/ @@ -220,14 +220,14 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm) totfilltri = BLI_scanfill_calc_ex(&sf_ctx, FALSE, f->no); BLI_array_grow_items(looptris, totfilltri); - for (efa = sf_ctx.fillfacebase.first; efa; efa=efa->next) { - BMLoop *l1= efa->v1->tmp.p; - BMLoop *l2= efa->v2->tmp.p; - BMLoop *l3= efa->v3->tmp.p; + for (efa = sf_ctx.fillfacebase.first; efa; efa = efa->next) { + BMLoop *l1 = efa->v1->tmp.p; + BMLoop *l2 = efa->v2->tmp.p; + BMLoop *l3 = efa->v3->tmp.p; - if (BM_elem_index_get(l1) > BM_elem_index_get(l2)) { SWAP(BMLoop*, l1, l2); } - if (BM_elem_index_get(l2) > BM_elem_index_get(l3)) { SWAP(BMLoop*, l2, l3); } - if (BM_elem_index_get(l1) > BM_elem_index_get(l2)) { SWAP(BMLoop*, l1, l2); } + if (BM_elem_index_get(l1) > BM_elem_index_get(l2)) { SWAP(BMLoop *, l1, l2); } + if (BM_elem_index_get(l2) > BM_elem_index_get(l3)) { SWAP(BMLoop *, l2, l3); } + if (BM_elem_index_get(l1) > BM_elem_index_get(l2)) { SWAP(BMLoop *, l1, l2); } looptris[i][0] = l1; looptris[i][1] = l2; @@ -289,16 +289,16 @@ void BMEdit_UpdateLinkedCustomData(BMEditMesh *em) void BMEdit_Free(BMEditMesh *em) { if (em->derivedFinal) { - if (em->derivedFinal!=em->derivedCage) { - em->derivedFinal->needsFree= 1; + if (em->derivedFinal != em->derivedCage) { + em->derivedFinal->needsFree = 1; em->derivedFinal->release(em->derivedFinal); } - em->derivedFinal= NULL; + em->derivedFinal = NULL; } if (em->derivedCage) { - em->derivedCage->needsFree= 1; + em->derivedCage->needsFree = 1; em->derivedCage->release(em->derivedCage); - em->derivedCage= NULL; + em->derivedCage = NULL; } if (em->looptris) MEM_freeN(em->looptris); @@ -351,12 +351,11 @@ static void emDM_recalcTessellation(DerivedMesh *UNUSED(dm)) /* do nothing */ } -static void emDM_foreachMappedVert( - DerivedMesh *dm, - void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]), - void *userData) +static void emDM_foreachMappedVert(DerivedMesh *dm, + void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]), + void *userData) { - EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMVert *eve; BMIter iter; int i; @@ -372,12 +371,11 @@ static void emDM_foreachMappedVert( } } } -static void emDM_foreachMappedEdge( - DerivedMesh *dm, - void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]), - void *userData) +static void emDM_foreachMappedEdge(DerivedMesh *dm, + void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]), + void *userData) { - EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMEdge *eed; BMIter iter; int i; @@ -387,24 +385,23 @@ static void emDM_foreachMappedEdge( BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_VERT); eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); - for (i=0; eed; i++, eed=BM_iter_step(&iter)) + for (i = 0; eed; i++, eed = BM_iter_step(&iter)) func(userData, i, - bmdm->vertexCos[BM_elem_index_get(eed->v1)], - bmdm->vertexCos[BM_elem_index_get(eed->v2)]); + bmdm->vertexCos[BM_elem_index_get(eed->v1)], + bmdm->vertexCos[BM_elem_index_get(eed->v2)]); } else { eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); - for (i=0; eed; i++, eed=BM_iter_step(&iter)) + for (i = 0; eed; i++, eed = BM_iter_step(&iter)) func(userData, i, eed->v1->co, eed->v2->co); } } -static void emDM_drawMappedEdges( - DerivedMesh *dm, - DMSetDrawOptions setDrawOptions, - void *userData) +static void emDM_drawMappedEdges(DerivedMesh *dm, + DMSetDrawOptions setDrawOptions, + void *userData) { - EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMEdge *eed; BMIter iter; int i; @@ -415,7 +412,7 @@ static void emDM_drawMappedEdges( glBegin(GL_LINES); eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); - for (i=0; eed; i++, eed=BM_iter_step(&iter)) { + for (i = 0; eed; i++, eed = BM_iter_step(&iter)) { if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]); glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]); @@ -426,7 +423,7 @@ static void emDM_drawMappedEdges( else { glBegin(GL_LINES); eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); - for (i=0; eed; i++, eed=BM_iter_step(&iter)) { + for (i = 0; eed; i++, eed = BM_iter_step(&iter)) { if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { glVertex3fv(eed->v1->co); glVertex3fv(eed->v2->co); @@ -435,21 +432,19 @@ static void emDM_drawMappedEdges( glEnd(); } } -static void emDM_drawEdges( - DerivedMesh *dm, - int UNUSED(drawLooseEdges), - int UNUSED(drawAllEdges)) +static void emDM_drawEdges(DerivedMesh *dm, + int UNUSED(drawLooseEdges), + int UNUSED(drawAllEdges)) { emDM_drawMappedEdges(dm, NULL, NULL); } -static void emDM_drawMappedEdgesInterp( - DerivedMesh *dm, - DMSetDrawOptions setDrawOptions, - DMSetDrawInterpOptions setDrawInterpOptions, - void *userData) +static void emDM_drawMappedEdgesInterp(DerivedMesh *dm, + DMSetDrawOptions setDrawOptions, + DMSetDrawInterpOptions setDrawInterpOptions, + void *userData) { - EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMEdge *eed; BMIter iter; int i; @@ -460,7 +455,7 @@ static void emDM_drawMappedEdgesInterp( glBegin(GL_LINES); eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); - for (i=0; eed; i++, eed=BM_iter_step(&iter)) { + for (i = 0; eed; i++, eed = BM_iter_step(&iter)) { if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { setDrawInterpOptions(userData, i, 0.0); glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]); @@ -473,7 +468,7 @@ static void emDM_drawMappedEdgesInterp( else { glBegin(GL_LINES); eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); - for (i=0; eed; i++, eed=BM_iter_step(&iter)) { + for (i = 0; eed; i++, eed = BM_iter_step(&iter)) { if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { setDrawInterpOptions(userData, i, 0.0); glVertex3fv(eed->v1->co); @@ -487,7 +482,7 @@ static void emDM_drawMappedEdgesInterp( static void emDM_drawUVEdges(DerivedMesh *dm) { - EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMEditMesh *em = bmdm->tc; BMFace *efa; BMIter iter; @@ -535,29 +530,28 @@ static void emDM__calcFaceCent(BMesh *bm, BMFace *efa, float cent[3], float (*ve if (vertexCos) { l = BM_iter_new(&iter, bm, BM_LOOPS_OF_FACE, efa); - for (; l; l=BM_iter_step(&iter)) { + for (; l; l = BM_iter_step(&iter)) { add_v3_v3(cent, vertexCos[BM_elem_index_get(l->v)]); tot++; } } else { l = BM_iter_new(&iter, bm, BM_LOOPS_OF_FACE, efa); - for (; l; l=BM_iter_step(&iter)) { + for (; l; l = BM_iter_step(&iter)) { add_v3_v3(cent, l->v->co); tot++; } } - if (tot==0) return; - mul_v3_fl(cent, 1.0f/(float)tot); + if (tot == 0) return; + mul_v3_fl(cent, 1.0f / (float)tot); } -static void emDM_foreachMappedFaceCenter( - DerivedMesh *dm, - void (*func)(void *userData, int index, const float co[3], const float no[3]), - void *userData) +static void emDM_foreachMappedFaceCenter(DerivedMesh *dm, + void (*func)(void *userData, int index, const float co[3], const float no[3]), + void *userData) { - EditDerivedBMesh *bmdm= (EditDerivedBMesh *)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; float (*polyNos)[3] = NULL; BMFace *efa; BMIter iter; @@ -578,13 +572,12 @@ static void emDM_foreachMappedFaceCenter( } } -static void emDM_drawMappedFaces( - DerivedMesh *dm, - DMSetDrawOptions setDrawOptions, - DMSetMaterial setMaterial, - DMCompareDrawOptions compareDrawOptions, - void *userData, - DMDrawFlag flag) +static void emDM_drawMappedFaces(DerivedMesh *dm, + DMSetDrawOptions setDrawOptions, + DMSetMaterial setMaterial, + DMCompareDrawOptions compareDrawOptions, + void *userData, + DMDrawFlag flag) { EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMFace *efa; @@ -621,8 +614,8 @@ static void emDM_drawMappedFaces( drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH); draw_option = (!setDrawOptions ? - DM_DRAW_OPTION_NORMAL : - setDrawOptions(userData, BM_elem_index_get(efa))); + DM_DRAW_OPTION_NORMAL : + setDrawOptions(userData, BM_elem_index_get(efa))); if (draw_option != DM_DRAW_OPTION_SKIP) { const GLenum poly_type = GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */ if (draw_option == DM_DRAW_OPTION_STIPPLE) { /* enabled with stipple */ @@ -673,7 +666,7 @@ static void emDM_drawMappedFaces( flush = (draw_option == DM_DRAW_OPTION_STIPPLE); if (!skip_normals && !flush && (i != lasttri)) - flush |= efa->mat_nr != looptris[i + 1][0]->f->mat_nr; /* TODO, make this neater */ + flush |= efa->mat_nr != looptris[i + 1][0]->f->mat_nr; /* TODO, make this neater */ if (flush) { glEnd(); @@ -687,16 +680,16 @@ static void emDM_drawMappedFaces( else { BM_mesh_elem_index_ensure(bmdm->tc->bm, BM_FACE); - for (i=0; i < tottri; i++) { + for (i = 0; i < tottri; i++) { BMLoop **l = looptris[i]; int drawSmooth; efa = l[0]->f; - drawSmooth= (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH); + drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH); draw_option = (!setDrawOptions ? - DM_DRAW_OPTION_NORMAL : - setDrawOptions(userData, BM_elem_index_get(efa))); + DM_DRAW_OPTION_NORMAL : + setDrawOptions(userData, BM_elem_index_get(efa))); if (draw_option != DM_DRAW_OPTION_SKIP) { const GLenum poly_type = GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */ if (draw_option == DM_DRAW_OPTION_STIPPLE) { /* enabled with stipple */ @@ -752,7 +745,7 @@ static void emDM_drawMappedFaces( if (flush) { glEnd(); - poly_prev= GL_ZERO; /* force glBegin */ + poly_prev = GL_ZERO; /* force glBegin */ glDisable(GL_POLYGON_STIPPLE); } @@ -782,12 +775,11 @@ static void bmdm_get_tri_tex(BMesh *bm, BMLoop **ls, MLoopUV *luv[3], MLoopCol * } -static void emDM_drawFacesTex_common( - DerivedMesh *dm, - DMSetDrawOptionsTex drawParams, - DMSetDrawOptions drawParamsMapped, - DMCompareDrawOptions compareDrawOptions, - void *userData) +static void emDM_drawFacesTex_common(DerivedMesh *dm, + DMSetDrawOptionsTex drawParams, + DMSetDrawOptions drawParamsMapped, + DMCompareDrawOptions compareDrawOptions, + void *userData) { EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMEditMesh *em = bmdm->tc; @@ -965,29 +957,26 @@ static void emDM_drawFacesTex_common( glShadeModel(GL_FLAT); } -static void emDM_drawFacesTex( - DerivedMesh *dm, - DMSetDrawOptionsTex setDrawOptions, - DMCompareDrawOptions compareDrawOptions, - void *userData) +static void emDM_drawFacesTex(DerivedMesh *dm, + DMSetDrawOptionsTex setDrawOptions, + DMCompareDrawOptions compareDrawOptions, + void *userData) { emDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData); } -static void emDM_drawMappedFacesTex( - DerivedMesh *dm, - DMSetDrawOptions setDrawOptions, - DMCompareDrawOptions compareDrawOptions, - void *userData) +static void emDM_drawMappedFacesTex(DerivedMesh *dm, + DMSetDrawOptions setDrawOptions, + DMCompareDrawOptions compareDrawOptions, + void *userData) { emDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData); } -static void emDM_drawMappedFacesGLSL( - DerivedMesh *dm, - DMSetMaterial setMaterial, - DMSetDrawOptions setDrawOptions, - void *userData) +static void emDM_drawMappedFacesGLSL(DerivedMesh *dm, + DMSetMaterial setMaterial, + DMSetDrawOptions setDrawOptions, + void *userData) { EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMesh *bm = bmdm->tc->bm; @@ -1010,26 +999,26 @@ static void emDM_drawMappedFacesGLSL( glShadeModel(GL_SMOOTH); BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE); -#define PASSATTRIB(loop, eve, vert) { \ - if (attribs.totorco) { \ - float *orco = attribs.orco.array[BM_elem_index_get(eve)]; \ - glVertexAttrib3fvARB(attribs.orco.gl_index, orco); \ - } \ - for (b = 0; b < attribs.tottface; b++) { \ - MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPUV, b);\ - glVertexAttrib2fvARB(attribs.tface[b].gl_index, _luv->uv); \ - } \ - for (b = 0; b < attribs.totmcol; b++) { \ - MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPCOL, b);\ - GLubyte _col[4]; \ - _col[0]= _cp->b; _col[1]= _cp->g; _col[2]= _cp->r; _col[3]= _cp->a; \ - glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, _col); \ - } \ - if (attribs.tottang) { \ - float *tang = attribs.tang.array[i*4 + vert]; \ - glVertexAttrib3fvARB(attribs.tang.gl_index, tang); \ - } \ - } +#define PASSATTRIB(loop, eve, vert) { \ + if (attribs.totorco) { \ + float *orco = attribs.orco.array[BM_elem_index_get(eve)]; \ + glVertexAttrib3fvARB(attribs.orco.gl_index, orco); \ + } \ + for (b = 0; b < attribs.tottface; b++) { \ + MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPUV, b); \ + glVertexAttrib2fvARB(attribs.tface[b].gl_index, _luv->uv); \ + } \ + for (b = 0; b < attribs.totmcol; b++) { \ + MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPCOL, b); \ + GLubyte _col[4]; \ + _col[0] = _cp->b; _col[1] = _cp->g; _col[2] = _cp->r; _col[3] = _cp->a; \ + glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, _col); \ + } \ + if (attribs.tottang) { \ + float *tang = attribs.tang.array[i * 4 + vert]; \ + glVertexAttrib3fvARB(attribs.tang.gl_index, tang); \ + } \ +} for (i = 0, ltri = em->looptris[0]; i < em->tottri; i++, ltri += 3) { @@ -1103,17 +1092,15 @@ static void emDM_drawMappedFacesGLSL( #undef PASSATTRIB } -static void emDM_drawFacesGLSL( - DerivedMesh *dm, - int (*setMaterial)(int, void *attribs)) +static void emDM_drawFacesGLSL(DerivedMesh *dm, + int (*setMaterial)(int, void *attribs)) { dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL); } -static void emDM_drawMappedFacesMat( - DerivedMesh *dm, - void (*setMaterial)(void *userData, int, void *attribs), - int (*setFace)(void *userData, int index), void *userData) +static void emDM_drawMappedFacesMat(DerivedMesh *dm, + void (*setMaterial)(void *userData, int, void *attribs), + int (*setFace)(void *userData, int index), void *userData) { EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; BMesh *bm = bmdm->tc->bm; @@ -1133,31 +1120,31 @@ static void emDM_drawMappedFacesMat( BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE); -#define PASSATTRIB(loop, eve, vert) { \ - if (attribs.totorco) { \ - float *orco = attribs.orco.array[BM_elem_index_get(eve)]; \ - if (attribs.orco.gl_texco) \ - glTexCoord3fv(orco); \ - else \ - glVertexAttrib3fvARB(attribs.orco.gl_index, orco); \ - } \ - for (b = 0; b < attribs.tottface; b++) { \ - MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPUV, b);\ - if (attribs.tface[b].gl_texco) \ - glTexCoord2fv(_luv->uv); \ - else \ - glVertexAttrib2fvARB(attribs.tface[b].gl_index, _luv->uv); \ - } \ - for (b = 0; b < attribs.totmcol; b++) { \ - MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPCOL, b);\ - GLubyte _col[4]; \ - _col[0]= _cp->b; _col[1]= _cp->g; _col[2]= _cp->r; _col[3]= _cp->a; \ - glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, _col); \ - } \ - if (attribs.tottang) { \ - float *tang = attribs.tang.array[i*4 + vert]; \ - glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \ - } \ +#define PASSATTRIB(loop, eve, vert) { \ + if (attribs.totorco) { \ + float *orco = attribs.orco.array[BM_elem_index_get(eve)]; \ + if (attribs.orco.gl_texco) \ + glTexCoord3fv(orco); \ + else \ + glVertexAttrib3fvARB(attribs.orco.gl_index, orco); \ + } \ + for (b = 0; b < attribs.tottface; b++) { \ + MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPUV, b); \ + if (attribs.tface[b].gl_texco) \ + glTexCoord2fv(_luv->uv); \ + else \ + glVertexAttrib2fvARB(attribs.tface[b].gl_index, _luv->uv); \ + } \ + for (b = 0; b < attribs.totmcol; b++) { \ + MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPCOL, b); \ + GLubyte _col[4]; \ + _col[0] = _cp->b; _col[1] = _cp->g; _col[2] = _cp->r; _col[3] = _cp->a; \ + glVertexAttrib4ubvARB(attribs.mcol[b].gl_index, _col); \ + } \ + if (attribs.tottang) { \ + float *tang = attribs.tang.array[i * 4 + vert]; \ + glVertexAttrib4fvARB(attribs.tang.gl_index, tang); \ + } \ } for (i = 0, ltri = em->looptris[0]; i < em->tottri; i++, ltri += 3) { @@ -1300,7 +1287,7 @@ static int bmvert_to_mvert(BMesh *bm, BMVert *ev, MVert *vert_r) vert_r->flag = BM_vert_flag_to_mflag(ev); if (CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) { - vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, ev, CD_BWEIGHT)*255.0f); + vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, ev, CD_BWEIGHT) * 255.0f); } return 1; @@ -1339,11 +1326,11 @@ static void emDM_getEdge(DerivedMesh *dm, int index, MEdge *edge_r) e = BM_edge_at_index(bmdm->tc->bm, index); /* warning, does list loop, _not_ ideal */ if (CustomData_has_layer(&bm->edata, CD_BWEIGHT)) { - edge_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->edata, e, CD_BWEIGHT)*255.0f); + edge_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->edata, e, CD_BWEIGHT) * 255.0f); } if (CustomData_has_layer(&bm->edata, CD_CREASE)) { - edge_r->crease = (unsigned char) (BM_elem_float_data_get(&bm->edata, e, CD_CREASE)*255.0f); + edge_r->crease = (unsigned char) (BM_elem_float_data_get(&bm->edata, e, CD_CREASE) * 255.0f); } edge_r->flag = BM_edge_flag_to_mflag(e); @@ -1387,7 +1374,7 @@ static void emDM_copyVertArray(DerivedMesh *dm, MVert *vert_r) int i; ev = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL); - for (i = 0 ; ev; ev = BM_iter_step(&iter), ++vert_r, ++i) { + for (i = 0; ev; ev = BM_iter_step(&iter), ++vert_r, ++i) { if (bmdm->vertexCos) copy_v3_v3(vert_r->co, bmdm->vertexCos[i]); else @@ -1398,7 +1385,7 @@ static void emDM_copyVertArray(DerivedMesh *dm, MVert *vert_r) vert_r->flag = BM_vert_flag_to_mflag(ev); if (CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) { - vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, ev, CD_BWEIGHT)*255.0f); + vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, ev, CD_BWEIGHT) * 255.0f); } } } @@ -1415,11 +1402,11 @@ static void emDM_copyEdgeArray(DerivedMesh *dm, MEdge *edge_r) for (ee = BM_iter_new(&iter, bm, BM_EDGES_OF_MESH, NULL); ee; ee = BM_iter_step(&iter), edge_r++) { if (has_bweight) { - edge_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->edata, ee, CD_BWEIGHT)*255.0f); + edge_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->edata, ee, CD_BWEIGHT) * 255.0f); } if (has_crease) { - edge_r->crease = (unsigned char) (BM_elem_float_data_get(&bm->edata, ee, CD_CREASE)*255.0f); + edge_r->crease = (unsigned char) (BM_elem_float_data_get(&bm->edata, ee, CD_CREASE) * 255.0f); } edge_r->flag = BM_edge_flag_to_mflag(ee); @@ -1586,52 +1573,51 @@ static void emDM_release(DerivedMesh *dm) static CustomData *bmDm_getVertDataLayout(DerivedMesh *dm) { - EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; return &bmdm->tc->bm->vdata; } static CustomData *bmDm_getEdgeDataLayout(DerivedMesh *dm) { - EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; return &bmdm->tc->bm->edata; } static CustomData *bmDm_getTessFaceDataLayout(DerivedMesh *dm) { - EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; return &bmdm->dm.faceData; } static CustomData *bmDm_getLoopDataLayout(DerivedMesh *dm) { - EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; return &bmdm->tc->bm->ldata; } static CustomData *bmDm_getPolyDataLayout(DerivedMesh *dm) { - EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; return &bmdm->tc->bm->pdata; } -DerivedMesh *getEditDerivedBMesh( - BMEditMesh *em, - Object *UNUSED(ob), - float (*vertexCos)[3]) +DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, + Object *UNUSED(ob), + float (*vertexCos)[3]) { EditDerivedBMesh *bmdm = MEM_callocN(sizeof(*bmdm), __func__); BMesh *bm = em->bm; bmdm->tc = em; - DM_init((DerivedMesh*)bmdm, DM_TYPE_EDITBMESH, em->bm->totvert, - em->bm->totedge, em->tottri, em->bm->totloop, em->bm->totface); + DM_init((DerivedMesh *)bmdm, DM_TYPE_EDITBMESH, em->bm->totvert, + em->bm->totedge, em->tottri, em->bm->totloop, em->bm->totface); bmdm->dm.getVertCos = emDM_getVertCos; bmdm->dm.getMinMax = emDM_getMinMax; @@ -1690,7 +1676,7 @@ DerivedMesh *getEditDerivedBMesh( BM_ITER_MESH_INDEX (eve, &iter, bmdm->tc->bm, BM_VERTS_OF_MESH, i) { DM_set_vert_data(&bmdm->dm, i, CD_MDEFORMVERT, - CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MDEFORMVERT)); + CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MDEFORMVERT)); } } @@ -1704,7 +1690,7 @@ DerivedMesh *getEditDerivedBMesh( BM_mesh_elem_index_ensure(bm, BM_VERT); bmdm->vertexNos = MEM_callocN(sizeof(*bmdm->vertexNos) * bm->totvert, "bmdm_vno"); - bmdm->polyNos = MEM_mallocN(sizeof(*bmdm->polyNos)*bm->totface, "bmdm_pno"); + bmdm->polyNos = MEM_mallocN(sizeof(*bmdm->polyNos) * bm->totface, "bmdm_pno"); BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) { BM_elem_index_set(efa, i); /* set_inline */ diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index 6242976d323..b2096ca97d4 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -39,7 +39,7 @@ #include "BKE_ocean.h" #include "BKE_utildefines.h" -#include "BKE_global.h" // XXX TESTING +#include "BKE_global.h" // XXX TESTING #include "BLI_math_base.h" #include "BLI_math_inline.h" @@ -84,7 +84,7 @@ typedef struct Ocean { float _Lx; float _Lz; - float normalize_factor; // init w + float normalize_factor; // init w float time; short _do_disp_y; @@ -98,73 +98,71 @@ typedef struct Ocean { /* ********* sim data arrays ********* */ /* two dimensional arrays of complex */ - fftw_complex *_fft_in; // init w sim w - fftw_complex *_fft_in_x; // init w sim w - fftw_complex *_fft_in_z; // init w sim w - fftw_complex *_fft_in_jxx; // init w sim w - fftw_complex *_fft_in_jzz; // init w sim w - fftw_complex *_fft_in_jxz; // init w sim w - fftw_complex *_fft_in_nx; // init w sim w - fftw_complex *_fft_in_nz; // init w sim w - fftw_complex *_htilda; // init w sim w (only once) + fftw_complex *_fft_in; // init w sim w + fftw_complex *_fft_in_x; // init w sim w + fftw_complex *_fft_in_z; // init w sim w + fftw_complex *_fft_in_jxx; // init w sim w + fftw_complex *_fft_in_jzz; // init w sim w + fftw_complex *_fft_in_jxz; // init w sim w + fftw_complex *_fft_in_nx; // init w sim w + fftw_complex *_fft_in_nz; // init w sim w + fftw_complex *_htilda; // init w sim w (only once) /* fftw "plans" */ - fftw_plan _disp_y_plan; // init w sim r - fftw_plan _disp_x_plan; // init w sim r - fftw_plan _disp_z_plan; // init w sim r - fftw_plan _N_x_plan; // init w sim r - fftw_plan _N_z_plan; // init w sim r - fftw_plan _Jxx_plan; // init w sim r - fftw_plan _Jxz_plan; // init w sim r - fftw_plan _Jzz_plan; // init w sim r + fftw_plan _disp_y_plan; // init w sim r + fftw_plan _disp_x_plan; // init w sim r + fftw_plan _disp_z_plan; // init w sim r + fftw_plan _N_x_plan; // init w sim r + fftw_plan _N_z_plan; // init w sim r + fftw_plan _Jxx_plan; // init w sim r + fftw_plan _Jxz_plan; // init w sim r + fftw_plan _Jzz_plan; // init w sim r /* two dimensional arrays of float */ - double * _disp_y; // init w sim w via plan? - double * _N_x; // init w sim w via plan? + double *_disp_y; // init w sim w via plan? + double *_N_x; // init w sim w via plan? /*float * _N_y; all member of this array has same values, so convert this array to a float to reduce memory usage (MEM01)*/ - double _N_y; // sim w ********* can be rearranged? - double * _N_z; // init w sim w via plan? - double * _disp_x; // init w sim w via plan? - double * _disp_z; // init w sim w via plan? + double _N_y; // sim w ********* can be rearranged? + double *_N_z; // init w sim w via plan? + double *_disp_x; // init w sim w via plan? + double *_disp_z; // init w sim w via plan? /* two dimensional arrays of float */ /* Jacobian and minimum eigenvalue */ - double * _Jxx; // init w sim w - double * _Jzz; // init w sim w - double * _Jxz; // init w sim w + double *_Jxx; // init w sim w + double *_Jzz; // init w sim w + double *_Jxz; // init w sim w /* one dimensional float array */ - float * _kx; // init w sim r - float * _kz; // init w sim r + float *_kx; // init w sim r + float *_kz; // init w sim r /* two dimensional complex array */ - fftw_complex * _h0; // init w sim r - fftw_complex * _h0_minus; // init w sim r + fftw_complex *_h0; // init w sim r + fftw_complex *_h0_minus; // init w sim r /* two dimensional float array */ - float * _k; // init w sim r + float *_k; // init w sim r } Ocean; static float nextfr(float min, float max) { - return BLI_frand()*(min-max)+max; + return BLI_frand() * (min - max) + max; } -static float gaussRand (void) +static float gaussRand(void) { - float x; // Note: to avoid numerical problems with very small - float y; // numbers, we make these variables singe-precision - float length2; // floats, but later we call the double-precision log() + float x; // Note: to avoid numerical problems with very small + float y; // numbers, we make these variables singe-precision + float length2; // floats, but later we call the double-precision log() // and sqrt() functions instead of logf() and sqrtf(). - do - { - x = (float) (nextfr (-1, 1)); - y = (float)(nextfr (-1, 1)); + do { + x = (float) (nextfr(-1, 1)); + y = (float)(nextfr(-1, 1)); length2 = x * x + y * y; - } - while (length2 >= 1 || length2 == 0); + } while (length2 >= 1 || length2 == 0); return x * sqrtf(-2.0f * logf(length2) / length2); } @@ -174,63 +172,63 @@ static float gaussRand (void) * */ MINLINE float lerp(float a, float b, float f) { - return a + (b-a)*f; + return a + (b - a) * f; } MINLINE float catrom(float p0, float p1, float p2, float p3, float f) { - return 0.5f *((2.0f * p1) + - (-p0 + p2) * f + - (2.0f*p0 - 5.0f*p1 + 4.0f*p2 - p3) * f*f + - (-p0 + 3.0f*p1- 3.0f*p2 + p3) * f*f*f); + return 0.5f * ((2.0f * p1) + + (-p0 + p2) * f + + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * f * f + + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * f * f * f); } MINLINE float omega(float k, float depth) { - return sqrt(GRAVITY*k * tanh(k*depth)); + return sqrt(GRAVITY * k * tanh(k * depth)); } // modified Phillips spectrum -static float Ph(struct Ocean* o, float kx, float kz ) +static float Ph(struct Ocean *o, float kx, float kz) { float tmp; - float k2 = kx*kx + kz*kz; + float k2 = kx * kx + kz * kz; 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); + tmp = (o->_wx * kx + o->_wz * kz) / sqrtf(k2); if (tmp < 0) { tmp *= o->_damp_reflections; } - return o->_A * expf( -1.0f / (k2*(o->_L*o->_L))) * expf(-k2 * (o->_l*o->_l)) * powf(fabsf(tmp), o->_wind_alignment) / (k2*k2); + return o->_A * expf(-1.0f / (k2 * (o->_L * o->_L))) * expf(-k2 * (o->_l * o->_l)) * powf(fabsf(tmp), o->_wind_alignment) / (k2 * k2); } static void compute_eigenstuff(struct OceanResult *ocr, float jxx, float jzz, float jxz) { float a, b, qplus, qminus; a = jxx + jzz; - b = sqrt((jxx - jzz)*(jxx - jzz) + 4 * jxz * jxz); + b = sqrt((jxx - jzz) * (jxx - jzz) + 4 * jxz * jxz); - ocr->Jminus = 0.5f*(a-b); - ocr->Jplus = 0.5f*(a+b); + ocr->Jminus = 0.5f * (a - b); + ocr->Jplus = 0.5f * (a + b); - qplus = (ocr->Jplus - jxx)/jxz; - qminus = (ocr->Jminus - jxx)/jxz; + qplus = (ocr->Jplus - jxx) / jxz; + qminus = (ocr->Jminus - jxx) / jxz; - a = sqrt(1 + qplus*qplus); - b = sqrt(1 + qminus*qminus); + a = sqrt(1 + qplus * qplus); + b = sqrt(1 + qminus * qminus); - ocr->Eplus[0] = 1.0f/ a; + ocr->Eplus[0] = 1.0f / a; ocr->Eplus[1] = 0.0f; - ocr->Eplus[2] = qplus/a; + ocr->Eplus[2] = qplus / a; - ocr->Eminus[0] = 1.0f/b; + ocr->Eminus[0] = 1.0f / b; ocr->Eminus[1] = 0.0f; - ocr->Eminus[2] = qminus/b; + ocr->Eminus[2] = qminus / b; } /* @@ -244,7 +242,7 @@ static void init_complex(fftw_complex cmpl, float real, float image) cmpl[1] = image; } -#if 0 // unused +#if 0 // unused static void add_complex_f(fftw_complex res, fftw_complex cmpl, float f) { res[0] = cmpl[0] + f; @@ -260,15 +258,15 @@ static void add_comlex_c(fftw_complex res, fftw_complex cmpl1, fftw_complex cmpl static void mul_complex_f(fftw_complex res, fftw_complex cmpl, float f) { - res[0] = cmpl[0]*f; - res[1] = cmpl[1]*f; + res[0] = cmpl[0] * f; + res[1] = cmpl[1] * f; } static void mul_complex_c(fftw_complex res, fftw_complex cmpl1, fftw_complex cmpl2) { fftwf_complex temp; - temp[0] = cmpl1[0]*cmpl2[0]-cmpl1[1]*cmpl2[1]; - temp[1] = cmpl1[0]*cmpl2[1]+cmpl1[1]*cmpl2[0]; + temp[0] = cmpl1[0] * cmpl2[0] - cmpl1[1] * cmpl2[1]; + temp[1] = cmpl1[0] * cmpl2[1] + cmpl1[1] * cmpl2[0]; res[0] = temp[0]; res[1] = temp[1]; } @@ -293,15 +291,15 @@ static void exp_complex(fftw_complex res, fftw_complex cmpl) { float r = expf(cmpl[0]); - res[0] = cos(cmpl[1])*r; - res[1] = sin(cmpl[1])*r; + res[0] = cos(cmpl[1]) * r; + res[1] = sin(cmpl[1]) * r; } float BKE_ocean_jminus_to_foam(float jminus, float coverage) { float foam = jminus * -0.005f + coverage; CLAMP(foam, 0.0f, 1.0f); - return foam*foam; + return foam * foam; } void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u, float v) @@ -338,7 +336,7 @@ void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u, float j1 = j1 % oc->_N; -#define BILERP(m) (lerp(lerp(m[i0*oc->_N+j0], m[i1*oc->_N+j0], frac_x), lerp(m[i0*oc->_N+j1], m[i1*oc->_N+j1], frac_x), frac_z)) +#define BILERP(m) (lerp(lerp(m[i0 * oc->_N + j0], m[i1 * oc->_N + j0], frac_x), lerp(m[i0 * oc->_N + j1], m[i1 * oc->_N + j1], frac_x), frac_z)) { if (oc->_do_disp_y) { ocr->disp[1] = BILERP(oc->_disp_y); @@ -346,7 +344,7 @@ void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u, float if (oc->_do_normals) { ocr->normal[0] = BILERP(oc->_N_x); - ocr->normal[1] = oc->_N_y/*BILERP(oc->_N_y) (MEM01)*/; + ocr->normal[1] = oc->_N_y /*BILERP(oc->_N_y) (MEM01)*/; ocr->normal[2] = BILERP(oc->_N_z); } @@ -402,21 +400,21 @@ void BKE_ocean_eval_uv_catrom(struct Ocean *oc, struct OceanResult *ocr, float u i2 = i2 % oc->_M; j2 = j2 % oc->_N; - i0 = (i1-1); - i3 = (i2+1); + i0 = (i1 - 1); + i3 = (i2 + 1); i0 = i0 < 0 ? i0 + oc->_M : i0; i3 = i3 >= oc->_M ? i3 - oc->_M : i3; - j0 = (j1-1); - j3 = (j2+1); + j0 = (j1 - 1); + j3 = (j2 + 1); j0 = j0 < 0 ? j0 + oc->_N : j0; j3 = j3 >= oc->_N ? j3 - oc->_N : j3; -#define INTERP(m) catrom(catrom(m[i0*oc->_N+j0], m[i1*oc->_N+j0], m[i2*oc->_N+j0], m[i3*oc->_N+j0], frac_x), \ - catrom(m[i0*oc->_N+j1], m[i1*oc->_N+j1], m[i2*oc->_N+j1], m[i3*oc->_N+j1], frac_x), \ - catrom(m[i0*oc->_N+j2], m[i1*oc->_N+j2], m[i2*oc->_N+j2], m[i3*oc->_N+j2], frac_x), \ - catrom(m[i0*oc->_N+j3], m[i1*oc->_N+j3], m[i2*oc->_N+j3], m[i3*oc->_N+j3], frac_x), \ - frac_z) +#define INTERP(m) catrom(catrom(m[i0 * oc->_N + j0], m[i1 * oc->_N + j0], m[i2 * oc->_N + j0], m[i3 * oc->_N + j0], frac_x), \ + catrom(m[i0 * oc->_N + j1], m[i1 * oc->_N + j1], m[i2 * oc->_N + j1], m[i3 * oc->_N + j1], frac_x), \ + catrom(m[i0 * oc->_N + j2], m[i1 * oc->_N + j2], m[i2 * oc->_N + j2], m[i3 * oc->_N + j2], frac_x), \ + catrom(m[i0 * oc->_N + j3], m[i1 * oc->_N + j3], m[i2 * oc->_N + j3], m[i3 * oc->_N + j3], frac_x), \ + frac_z) { if (oc->_do_disp_y) { @@ -424,7 +422,7 @@ void BKE_ocean_eval_uv_catrom(struct Ocean *oc, struct OceanResult *ocr, float u } if (oc->_do_normals) { ocr->normal[0] = INTERP(oc->_N_x); - ocr->normal[1] = oc->_N_y/*INTERP(oc->_N_y) (MEM01)*/; + ocr->normal[1] = oc->_N_y /*INTERP(oc->_N_y) (MEM01)*/; ocr->normal[2] = INTERP(oc->_N_z); } if (oc->_do_chop) { @@ -448,12 +446,12 @@ void BKE_ocean_eval_uv_catrom(struct Ocean *oc, struct OceanResult *ocr, float u void BKE_ocean_eval_xz(struct Ocean *oc, struct OceanResult *ocr, float x, float z) { - BKE_ocean_eval_uv(oc, ocr, x/oc->_Lx, z/oc->_Lz); + BKE_ocean_eval_uv(oc, ocr, x / oc->_Lx, z / oc->_Lz); } void BKE_ocean_eval_xz_catrom(struct Ocean *oc, struct OceanResult *ocr, float x, float z) { - BKE_ocean_eval_uv_catrom(oc, ocr, x/oc->_Lx, z/oc->_Lz); + BKE_ocean_eval_uv_catrom(oc, ocr, x / oc->_Lx, z / oc->_Lz); } // note that this doesn't wrap properly for i, j < 0, but its @@ -466,11 +464,11 @@ void BKE_ocean_eval_ij(struct Ocean *oc, struct OceanResult *ocr, int i, int j) i = abs(i) % oc->_M; j = abs(j) % oc->_N; - ocr->disp[1] = oc->_do_disp_y ? oc->_disp_y[i*oc->_N+j] : 0.0f; + ocr->disp[1] = oc->_do_disp_y ? oc->_disp_y[i * oc->_N + j] : 0.0f; if (oc->_do_chop) { - ocr->disp[0] = oc->_disp_x[i*oc->_N+j]; - ocr->disp[2] = oc->_disp_z[i*oc->_N+j]; + ocr->disp[0] = oc->_disp_x[i * oc->_N + j]; + ocr->disp[2] = oc->_disp_z[i * oc->_N + j]; } else { ocr->disp[0] = 0.0f; @@ -478,15 +476,15 @@ void BKE_ocean_eval_ij(struct Ocean *oc, struct OceanResult *ocr, int i, int j) } 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]; + 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]; normalize_v3(ocr->normal); } 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]); + compute_eigenstuff(ocr, oc->_Jxx[i * oc->_N + j], oc->_Jzz[i * oc->_N + j], oc->_Jxz[i * oc->_N + j]); } BLI_rw_mutex_unlock(&oc->oceanmutex); @@ -502,26 +500,26 @@ 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; - init_complex(exp_param1, 0.0, omega(o->_k[i*(1+o->_N/2)+j], o->_depth)*t); - init_complex(exp_param2, 0.0, -omega(o->_k[i*(1+o->_N/2)+j], o->_depth)*t); + init_complex(exp_param1, 0.0, omega(o->_k[i * (1 + o->_N / 2) + j], o->_depth) * t); + init_complex(exp_param2, 0.0, -omega(o->_k[i * (1 + o->_N / 2) + j], o->_depth) * t); exp_complex(exp_param1, exp_param1); exp_complex(exp_param2, exp_param2); - conj_complex(conj_param, o->_h0_minus[i*o->_N+j]); + conj_complex(conj_param, o->_h0_minus[i * o->_N + j]); - mul_complex_c(exp_param1, o->_h0[i*o->_N+j], exp_param1); + mul_complex_c(exp_param1, o->_h0[i * o->_N + j], exp_param1); mul_complex_c(exp_param2, conj_param, exp_param2); - add_comlex_c(o->_htilda[i*(1+o->_N/2)+j], exp_param1, exp_param2); - mul_complex_f(o->_fft_in[i*(1+o->_N/2)+j], o->_htilda[i*(1+o->_N/2)+j], scale); + add_comlex_c(o->_htilda[i * (1 + o->_N / 2) + j], exp_param1, exp_param2); + mul_complex_f(o->_fft_in[i * (1 + o->_N / 2) + j], o->_htilda[i * (1 + o->_N / 2) + j], scale); } } @@ -540,8 +538,8 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount { 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; @@ -549,9 +547,9 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount init_complex(mul_param, -scale, 0); mul_complex_f(mul_param, mul_param, chop_amount); mul_complex_c(mul_param, mul_param, minus_i); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); - mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kx[i] / o->_k[i*(1+o->_N/2)+j])); - init_complex(o->_fft_in_x[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); + mul_complex_f(mul_param, mul_param, (o->_k[i * (1 + o->_N / 2) + j] == 0.0 ? 0.0 : o->_kx[i] / o->_k[i * (1 + o->_N / 2) + j])); + init_complex(o->_fft_in_x[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_disp_x_plan); @@ -562,8 +560,8 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount { 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; @@ -571,9 +569,9 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount init_complex(mul_param, -scale, 0); mul_complex_f(mul_param, mul_param, chop_amount); mul_complex_c(mul_param, mul_param, minus_i); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); - mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kz[j] / o->_k[i*(1+o->_N/2)+j])); - init_complex(o->_fft_in_z[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); + mul_complex_f(mul_param, mul_param, (o->_k[i * (1 + o->_N / 2) + j] == 0.0 ? 0.0 : o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j])); + init_complex(o->_fft_in_z[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_disp_z_plan); @@ -584,24 +582,24 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount { 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); init_complex(mul_param, -1, 0); mul_complex_f(mul_param, mul_param, chop_amount); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); - mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kx[i]*o->_kx[i] / o->_k[i*(1+o->_N/2)+j])); - init_complex(o->_fft_in_jxx[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); + mul_complex_f(mul_param, mul_param, (o->_k[i * (1 + o->_N / 2) + j] == 0.0 ? 0.0 : o->_kx[i] * o->_kx[i] / o->_k[i * (1 + o->_N / 2) + j])); + init_complex(o->_fft_in_jxx[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_Jxx_plan); - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j < o->_N ; ++j) { - o->_Jxx[i*o->_N+j] += 1.0; + for (i = 0; i < o->_M; ++i) { + for (j = 0; j < o->_N; ++j) { + o->_Jxx[i * o->_N + j] += 1.0; } } } @@ -611,23 +609,23 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount { 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); init_complex(mul_param, -1, 0); mul_complex_f(mul_param, mul_param, chop_amount); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); - mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kz[j]*o->_kz[j] / o->_k[i*(1+o->_N/2)+j])); - init_complex(o->_fft_in_jzz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); + mul_complex_f(mul_param, mul_param, (o->_k[i * (1 + o->_N / 2) + j] == 0.0 ? 0.0 : o->_kz[j] * o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j])); + init_complex(o->_fft_in_jzz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_Jzz_plan); - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j < o->_N ; ++j) { - o->_Jzz[i*o->_N+j] += 1.0; + for (i = 0; i < o->_M; ++i) { + for (j = 0; j < o->_N; ++j) { + o->_Jzz[i * o->_N + j] += 1.0; } } } @@ -637,17 +635,17 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount { 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); init_complex(mul_param, -1, 0); mul_complex_f(mul_param, mul_param, chop_amount); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); - mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0f ? 0.0f : o->_kx[i]*o->_kz[j] / o->_k[i*(1+o->_N/2)+j])); - init_complex(o->_fft_in_jxz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); + mul_complex_f(mul_param, mul_param, (o->_k[i * (1 + o->_N / 2) + j] == 0.0f ? 0.0f : o->_kx[i] * o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j])); + init_complex(o->_fft_in_jxz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_Jxz_plan); @@ -658,14 +656,14 @@ void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount { // fft normals if (o->_do_normals) { - 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, 0.0, -1.0); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); mul_complex_f(mul_param, mul_param, o->_kx[i]); - init_complex(o->_fft_in_nx[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + init_complex(o->_fft_in_nx[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_N_x_plan); @@ -676,27 +674,27 @@ 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) { + 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); - mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]); + mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); mul_complex_f(mul_param, mul_param, o->_kz[i]); - init_complex(o->_fft_in_nz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param)); + init_complex(o->_fft_in_nz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); } } fftw_execute(o->_N_z_plan); #if 0 - for ( i = 0 ; i < o->_M ; ++i) { - for ( j = 0 ; j < o->_N ; ++j) { - o->_N_y[i*o->_N+j] = 1.0f/scale; + for (i = 0; i < o->_M; ++i) { + for (j = 0; j < o->_N; ++j) { + o->_N_y[i * o->_N + j] = 1.0f / scale; } } (MEM01) #endif - o->_N_y = 1.0f/scale; + o->_N_y = 1.0f / scale; } } // section 8 @@ -722,23 +720,22 @@ static void set_height_normalize_factor(struct Ocean *oc) 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]); + if (max_h < fabsf(oc->_disp_y[i * oc->_N + j])) { + max_h = fabsf(oc->_disp_y[i * oc->_N + j]); } } } BLI_rw_mutex_unlock(&oc->oceanmutex); - if (max_h == 0.0f) max_h = 0.00001f; // just in case ... + if (max_h == 0.0f) max_h = 0.00001f; // just in case ... res = 1.0f / (max_h); oc->normalize_factor = res; } -struct Ocean *BKE_add_ocean(void) -{ +struct Ocean *BKE_add_ocean(void){ Ocean *oc = MEM_callocN(sizeof(Ocean), "ocean sim data"); BLI_rw_mutex_init(&oc->oceanmutex); @@ -746,8 +743,8 @@ struct Ocean *BKE_add_ocean(void) return oc; } -void BKE_init_ocean(struct Ocean* o, int M, int N, float Lx, float Lz, float V, float l, float A, float w, float damp, - float alignment, float depth, float time, short do_height_field, short do_chop, short do_normals, short do_jacobian, int seed) +void BKE_init_ocean(struct Ocean *o, int M, int N, float Lx, float Lz, float V, float l, float A, float w, float damp, + float alignment, float depth, float time, short do_height_field, short do_chop, short do_normals, short do_jacobian, int seed) { int i, j, ii; @@ -766,7 +763,7 @@ void BKE_init_ocean(struct Ocean* o, int M, int N, float Lx, float Lz, float V, o->_Lz = Lz; o->_wx = cos(w); o->_wz = -sin(w); // wave direction - o->_L = V*V / GRAVITY; // largest wave for a given velocity V + o->_L = V * V / GRAVITY; // largest wave for a given velocity V o->time = time; o->_do_disp_y = do_height_field; @@ -774,11 +771,11 @@ void BKE_init_ocean(struct Ocean* o, int M, int N, float Lx, float Lz, float V, o->_do_chop = do_chop; o->_do_jacobian = do_jacobian; - o->_k = (float*) MEM_mallocN(M * (1+N/2) * sizeof(float), "ocean_k"); - o->_h0 = (fftw_complex*) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0"); - o->_h0_minus = (fftw_complex*) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0_minus"); - o->_kx = (float*) MEM_mallocN(o->_M * sizeof(float), "ocean_kx"); - o->_kz = (float*) MEM_mallocN(o->_N * sizeof(float), "ocean_kz"); + o->_k = (float *) MEM_mallocN(M * (1 + N / 2) * sizeof(float), "ocean_k"); + o->_h0 = (fftw_complex *) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0"); + o->_h0_minus = (fftw_complex *) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0_minus"); + o->_kx = (float *) MEM_mallocN(o->_M * sizeof(float), "ocean_kx"); + o->_kz = (float *) MEM_mallocN(o->_N * sizeof(float), "ocean_kz"); // make this robust in the face of erroneous usage if (o->_Lx == 0.0f) @@ -788,79 +785,79 @@ void BKE_init_ocean(struct Ocean* o, int M, int N, float Lx, float Lz, float V, o->_Lz = 0.001f; // the +ve components and DC - for (i = 0 ; i <= o->_M/2 ; ++i) + for (i = 0; i <= o->_M / 2; ++i) o->_kx[i] = 2.0f * (float)M_PI * i / o->_Lx; // the -ve components - for (i = o->_M-1, ii=0 ; i > o->_M/2 ; --i, ++ii) + for (i = o->_M - 1, ii = 0; i > o->_M / 2; --i, ++ii) o->_kx[i] = -2.0f * (float)M_PI * ii / o->_Lx; // the +ve components and DC - for (i = 0 ; i <= o->_N/2 ; ++i) + for (i = 0; i <= o->_N / 2; ++i) o->_kz[i] = 2.0f * (float)M_PI * i / o->_Lz; // the -ve components - for (i = o->_N-1, ii=0 ; i > o->_N/2 ; --i, ++ii) + for (i = o->_N - 1, ii = 0; i > o->_N / 2; --i, ++ii) o->_kz[i] = -2.0f * (float)M_PI * ii / o->_Lz; // pre-calculate the k matrix - for (i = 0 ; i < o->_M ; ++i) - for (j = 0 ; j <= o->_N / 2 ; ++j) - o->_k[i*(1+o->_N/2)+j] = sqrt(o->_kx[i]*o->_kx[i] + o->_kz[j]*o->_kz[j] ); + for (i = 0; i < o->_M; ++i) + for (j = 0; j <= o->_N / 2; ++j) + o->_k[i * (1 + o->_N / 2) + j] = sqrt(o->_kx[i] * o->_kx[i] + o->_kz[j] * o->_kz[j]); /*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(); fftw_complex r1r2; init_complex(r1r2, r1, r2); - mul_complex_f(o->_h0[i*o->_N+j], r1r2, (float)(sqrt(Ph(o, o->_kx[i], o->_kz[j]) / 2.0f))); - mul_complex_f(o->_h0_minus[i*o->_N+j], r1r2, (float)(sqrt(Ph(o, -o->_kx[i], -o->_kz[j]) / 2.0f))); + mul_complex_f(o->_h0[i * o->_N + j], r1r2, (float)(sqrt(Ph(o, o->_kx[i], o->_kz[j]) / 2.0f))); + mul_complex_f(o->_h0_minus[i * o->_N + j], r1r2, (float)(sqrt(Ph(o, -o->_kx[i], -o->_kz[j]) / 2.0f))); } } - o->_fft_in = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in"); - o->_htilda = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_htilda"); + o->_fft_in = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in"); + o->_htilda = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_htilda"); if (o->_do_disp_y) { - o->_disp_y = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_y"); + o->_disp_y = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_y"); o->_disp_y_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in, o->_disp_y, FFTW_ESTIMATE); } if (o->_do_normals) { - o->_fft_in_nx = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_nx"); - o->_fft_in_nz = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_nz"); + o->_fft_in_nx = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_nx"); + o->_fft_in_nz = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_nz"); - o->_N_x = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_x"); + o->_N_x = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_x"); /*o->_N_y = (float*) fftwf_malloc(o->_M * o->_N * sizeof(float)); (MEM01)*/ - o->_N_z = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_z"); + o->_N_z = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_z"); o->_N_x_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_nx, o->_N_x, FFTW_ESTIMATE); o->_N_z_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_nz, o->_N_z, FFTW_ESTIMATE); } if (o->_do_chop) { - o->_fft_in_x = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_x"); - o->_fft_in_z = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_z"); + o->_fft_in_x = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_x"); + o->_fft_in_z = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_z"); - o->_disp_x = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_x"); - o->_disp_z = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_z"); + o->_disp_x = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_x"); + o->_disp_z = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_z"); o->_disp_x_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_x, o->_disp_x, FFTW_ESTIMATE); o->_disp_z_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_z, o->_disp_z, FFTW_ESTIMATE); } if (o->_do_jacobian) { - o->_fft_in_jxx = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_jxx"); - o->_fft_in_jzz = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_jzz"); - o->_fft_in_jxz = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_jxz"); + o->_fft_in_jxx = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_jxx"); + o->_fft_in_jzz = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_jzz"); + o->_fft_in_jxz = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_jxz"); - o->_Jxx = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxx"); - o->_Jzz = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jzz"); - o->_Jxz = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxz"); + o->_Jxx = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxx"); + o->_Jzz = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jzz"); + o->_Jxz = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxz"); o->_Jxx_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_jxx, o->_Jxx, FFTW_ESTIMATE); o->_Jzz_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_jzz, o->_Jzz, FFTW_ESTIMATE); @@ -947,9 +944,9 @@ void BKE_free_ocean(struct Ocean *oc) /* ********* Baking/Caching ********* */ -#define CACHE_TYPE_DISPLACE 1 -#define CACHE_TYPE_FOAM 2 -#define CACHE_TYPE_NORMAL 3 +#define CACHE_TYPE_DISPLACE 1 +#define CACHE_TYPE_FOAM 2 +#define CACHE_TYPE_NORMAL 3 static void cache_filename(char *string, const char *path, const char *relbase, int frame, int type) { @@ -957,16 +954,16 @@ static void cache_filename(char *string, const char *path, const char *relbase, const char *fname; switch (type) { - case CACHE_TYPE_FOAM: - fname= "foam_"; - break; - case CACHE_TYPE_NORMAL: - fname= "normal_"; - break; - case CACHE_TYPE_DISPLACE: - default: - fname= "disp_"; - break; + case CACHE_TYPE_FOAM: + fname = "foam_"; + break; + case CACHE_TYPE_NORMAL: + fname = "normal_"; + break; + case CACHE_TYPE_DISPLACE: + default: + fname = "disp_"; + break; } BLI_join_dirfile(cachepath, sizeof(cachepath), path, fname); @@ -977,27 +974,27 @@ static void cache_filename(char *string, const char *path, const char *relbase, /* silly functions but useful to inline when the args do a lot of indirections */ MINLINE void rgb_to_rgba_unit_alpha(float r_rgba[4], const float rgb[3]) { - r_rgba[0]= rgb[0]; - r_rgba[1]= rgb[1]; - r_rgba[2]= rgb[2]; - r_rgba[3]= 1.0f; + r_rgba[0] = rgb[0]; + r_rgba[1] = rgb[1]; + r_rgba[2] = rgb[2]; + r_rgba[3] = 1.0f; } MINLINE void value_to_rgba_unit_alpha(float r_rgba[4], const float value) { - r_rgba[0]= value; - r_rgba[1]= value; - r_rgba[2]= value; - r_rgba[3]= 1.0f; + r_rgba[0] = value; + r_rgba[1] = value; + r_rgba[2] = value; + r_rgba[3] = 1.0f; } void BKE_free_ocean_cache(struct OceanCache *och) { - int i, f=0; + int i, f = 0; 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]); } @@ -1006,7 +1003,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]); } @@ -1015,7 +1012,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]); } @@ -1041,17 +1038,17 @@ void BKE_ocean_cache_eval_uv(struct OceanCache *och, struct OceanResult *ocr, in if (v < 0) v += 1.0f; if (och->ibufs_disp[f]) { - ibuf_sample(och->ibufs_disp[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result); + ibuf_sample(och->ibufs_disp[f], u, v, (1.0f / (float)res_x), (1.0f / (float)res_y), result); copy_v3_v3(ocr->disp, result); } if (och->ibufs_foam[f]) { - ibuf_sample(och->ibufs_foam[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result); + ibuf_sample(och->ibufs_foam[f], u, v, (1.0f / (float)res_x), (1.0f / (float)res_y), result); ocr->foam = result[0]; } if (och->ibufs_norm[f]) { - ibuf_sample(och->ibufs_norm[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result); + ibuf_sample(och->ibufs_norm[f], u, v, (1.0f / (float)res_x), (1.0f / (float)res_y), result); copy_v3_v3(ocr->normal, result); } } @@ -1061,29 +1058,28 @@ void BKE_ocean_cache_eval_ij(struct OceanCache *och, struct OceanResult *ocr, in const int res_x = och->resolution_x; const int res_y = och->resolution_y; - if (i < 0) i= -i; - if (j < 0) j= -j; + if (i < 0) i = -i; + if (j < 0) j = -j; i = i % res_x; j = j % res_y; if (och->ibufs_disp[f]) { - copy_v3_v3(ocr->disp, &och->ibufs_disp[f]->rect_float[4*(res_x*j + i)]); + copy_v3_v3(ocr->disp, &och->ibufs_disp[f]->rect_float[4 * (res_x * j + i)]); } if (och->ibufs_foam[f]) { - ocr->foam = och->ibufs_foam[f]->rect_float[4*(res_x*j + i)]; + ocr->foam = och->ibufs_foam[f]->rect_float[4 * (res_x * j + i)]; } if (och->ibufs_norm[f]) { - copy_v3_v3(ocr->normal, &och->ibufs_norm[f]->rect_float[4*(res_x*j + i)]); + copy_v3_v3(ocr->normal, &och->ibufs_norm[f]->rect_float[4 * (res_x * j + i)]); } } struct OceanCache *BKE_init_ocean_cache(const char *bakepath, const char *relbase, int start, int end, float wave_scale, - float chop_amount, float foam_coverage, float foam_fade, int resolution) -{ + float chop_amount, float foam_coverage, float foam_fade, int resolution){ OceanCache *och = MEM_callocN(sizeof(OceanCache), "ocean cache data"); och->bakepath = bakepath; @@ -1096,12 +1092,12 @@ struct OceanCache *BKE_init_ocean_cache(const char *bakepath, const char *relbas och->chop_amount = chop_amount; och->foam_coverage = foam_coverage; och->foam_fade = foam_fade; - och->resolution_x = resolution*resolution; - och->resolution_y = resolution*resolution; + och->resolution_x = resolution * resolution; + och->resolution_y = resolution * resolution; - och->ibufs_disp = MEM_callocN(sizeof(ImBuf *)*och->duration, "displacement imbuf pointer array"); - och->ibufs_foam = MEM_callocN(sizeof(ImBuf *)*och->duration, "foam imbuf pointer array"); - och->ibufs_norm = MEM_callocN(sizeof(ImBuf *)*och->duration, "normal imbuf pointer array"); + och->ibufs_disp = MEM_callocN(sizeof(ImBuf *) * och->duration, "displacement imbuf pointer array"); + och->ibufs_foam = MEM_callocN(sizeof(ImBuf *) * och->duration, "foam imbuf pointer array"); + och->ibufs_norm = MEM_callocN(sizeof(ImBuf *) * och->duration, "normal imbuf pointer array"); och->time = NULL; @@ -1116,10 +1112,10 @@ void BKE_simulate_ocean_cache(struct OceanCache *och, int frame) /* ibufs array is zero based, but filenames are based on frame numbers */ /* still need to clamp frame numbers to valid range of images on disk though */ CLAMP(frame, och->start, och->end); - f = frame - och->start; // shift to 0 based + f = frame - och->start; // shift to 0 based /* if image is already loaded in mem, return */ - if (och->ibufs_disp[f] != NULL ) return; + if (och->ibufs_disp[f] != NULL) return; cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_DISPLACE); @@ -1146,9 +1142,9 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v * before use - campbell */ OceanResult ocr; - ImageFormatData imf= {0}; + ImageFormatData imf = {0}; - int f, i=0, x, y, cancel=0; + int f, i = 0, x, y, cancel = 0; float progress; ImBuf *ibuf_foam, *ibuf_disp, *ibuf_normal; @@ -1159,17 +1155,17 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v if (!o) return; - if (o->_do_jacobian) prev_foam = MEM_callocN(res_x*res_y*sizeof(float), "previous frame foam bake data"); - else prev_foam = NULL; + if (o->_do_jacobian) prev_foam = MEM_callocN(res_x * res_y * sizeof(float), "previous frame foam bake data"); + else prev_foam = NULL; BLI_srand(0); /* setup image format */ - imf.imtype= R_IMF_IMTYPE_OPENEXR; - imf.depth= R_IMF_CHAN_DEPTH_16; - imf.exr_codec= R_IMF_EXR_CODEC_ZIP; + imf.imtype = R_IMF_IMTYPE_OPENEXR; + imf.depth = R_IMF_CHAN_DEPTH_16; + imf.exr_codec = R_IMF_EXR_CODEC_ZIP; - for (f=och->start, i=0; f<=och->end; f++, i++) { + for (f = och->start, i = 0; f <= och->end; f++, i++) { /* create a new imbuf to store image for this frame */ ibuf_foam = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat); @@ -1181,25 +1177,25 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v BKE_simulate_ocean(o, och->time[i], och->wave_scale, och->chop_amount); /* add new foam */ - for (y=0; y < res_y; y++) { - for (x=0; x < res_x; x++) { + for (y = 0; y < res_y; y++) { + for (x = 0; x < res_x; x++) { BKE_ocean_eval_ij(o, &ocr, x, y); /* add to the image */ - rgb_to_rgba_unit_alpha(&ibuf_disp->rect_float[4*(res_x*y + x)], ocr.disp); + rgb_to_rgba_unit_alpha(&ibuf_disp->rect_float[4 * (res_x * y + x)], ocr.disp); if (o->_do_jacobian) { /* TODO, cleanup unused code - campbell */ - float /*r, */ /* UNUSED */ pr=0.0f, foam_result; + float /*r, */ /* UNUSED */ pr = 0.0f, foam_result; float neg_disp, neg_eplus; ocr.foam = BKE_ocean_jminus_to_foam(ocr.Jminus, och->foam_coverage); /* accumulate previous value for this cell */ if (i > 0) { - pr = prev_foam[res_x*y + x]; + pr = prev_foam[res_x * y + x]; } /* r = BLI_frand(); */ /* UNUSED */ // randomly reduce foam @@ -1217,12 +1213,12 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v CLAMP(hor_stretch, 0.0, 1.0); #endif - neg_disp = ocr.disp[1] < 0.0f ? 1.0f+ocr.disp[1] : 1.0f; + neg_disp = ocr.disp[1] < 0.0f ? 1.0f + ocr.disp[1] : 1.0f; neg_disp = neg_disp < 0.0f ? 0.0f : neg_disp; /* foam, 'ocr.Eplus' only initialized with do_jacobian */ - neg_eplus = ocr.Eplus[2] < 0.0f ? 1.0f + ocr.Eplus[2]:1.0f; - neg_eplus = neg_eplus<0.0f ? 0.0f : neg_eplus; + neg_eplus = ocr.Eplus[2] < 0.0f ? 1.0f + ocr.Eplus[2] : 1.0f; + neg_eplus = neg_eplus < 0.0f ? 0.0f : neg_eplus; //if (ocr.disp[1] < 0.0 || r > och->foam_fade) // pr *= och->foam_fade; @@ -1231,20 +1227,20 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v //pr = pr * (1.0 - hor_stretch) * ocr.disp[1]; //pr = pr * neg_disp * neg_eplus; - if (pr < 1.0f) pr *=pr; + if (pr < 1.0f) pr *= pr; pr *= och->foam_fade * (0.75f + neg_eplus * 0.25f); foam_result = pr + ocr.foam; - prev_foam[res_x*y + x] = foam_result; + prev_foam[res_x * y + x] = foam_result; - value_to_rgba_unit_alpha(&ibuf_foam->rect_float[4*(res_x*y + x)], foam_result); + value_to_rgba_unit_alpha(&ibuf_foam->rect_float[4 * (res_x * y + x)], foam_result); } if (o->_do_normals) { - rgb_to_rgba_unit_alpha(&ibuf_normal->rect_float[4*(res_x*y + x)], ocr.normal); + rgb_to_rgba_unit_alpha(&ibuf_normal->rect_float[4 * (res_x * y + x)], ocr.normal); } } } @@ -1330,8 +1326,8 @@ struct Ocean *BKE_add_ocean(void) return oc; } -void BKE_init_ocean(struct Ocean* UNUSED(o), int UNUSED(M), int UNUSED(N), float UNUSED(Lx), float UNUSED(Lz), float UNUSED(V), float UNUSED(l), float UNUSED(A), float UNUSED(w), float UNUSED(damp), - float UNUSED(alignment), float UNUSED(depth), float UNUSED(time), short UNUSED(do_height_field), short UNUSED(do_chop), short UNUSED(do_normals), short UNUSED(do_jacobian), int UNUSED(seed)) +void BKE_init_ocean(struct Ocean *UNUSED(o), int UNUSED(M), int UNUSED(N), float UNUSED(Lx), float UNUSED(Lz), float UNUSED(V), float UNUSED(l), float UNUSED(A), float UNUSED(w), float UNUSED(damp), + float UNUSED(alignment), float UNUSED(depth), float UNUSED(time), short UNUSED(do_height_field), short UNUSED(do_chop), short UNUSED(do_normals), short UNUSED(do_jacobian), int UNUSED(seed)) { } @@ -1366,8 +1362,7 @@ void BKE_ocean_cache_eval_ij(struct OceanCache *UNUSED(och), struct OceanResult struct OceanCache *BKE_init_ocean_cache(const char *UNUSED(bakepath), const char *UNUSED(relbase), int UNUSED(start), int UNUSED(end), float UNUSED(wave_scale), - float UNUSED(chop_amount), float UNUSED(foam_coverage), float UNUSED(foam_fade), int UNUSED(resolution)) -{ + float UNUSED(chop_amount), float UNUSED(foam_coverage), float UNUSED(foam_fade), int UNUSED(resolution)){ OceanCache *och = MEM_callocN(sizeof(OceanCache), "ocean cache data"); return och; -- cgit v1.2.3