code cleanup: some edits for unused vars in recent smooth addition and some style edits.

This commit is contained in:
Campbell Barton 2012-10-24 11:31:57 +00:00
parent e4fcc07a10
commit c93978d445
8 changed files with 106 additions and 91 deletions

@ -46,7 +46,7 @@ extern "C" FLUID_3D *smoke_init(int *res, float dx, float dtdef, int use_heat, i
extern "C" WTURBULENCE *smoke_turbulence_init(int *res, int amplify, int noisetype, int use_fire, int use_colors) extern "C" WTURBULENCE *smoke_turbulence_init(int *res, int amplify, int noisetype, int use_fire, int use_colors)
{ {
if(amplify) if (amplify)
return new WTURBULENCE(res[0],res[1],res[2], amplify, noisetype, use_fire, use_colors); return new WTURBULENCE(res[0],res[1],res[2], amplify, noisetype, use_fire, use_colors);
else else
return NULL; return NULL;
@ -105,8 +105,7 @@ extern "C" void smoke_initWaveletBlenderRNA(WTURBULENCE *wt, float *strength)
static void data_dissolve(float *density, float *heat, float *r, float *g, float *b, int total_cells, int speed, int log) static void data_dissolve(float *density, float *heat, float *r, float *g, float *b, int total_cells, int speed, int log)
{ {
if(log) if (log) {
{
/* max density/speed = dydx */ /* max density/speed = dydx */
float fac = 1.0f - (1.0f / (float)speed); float fac = 1.0f - (1.0f / (float)speed);
@ -138,14 +137,14 @@ static void data_dissolve(float *density, float *heat, float *r, float *g, float
float d = density[i]; float d = density[i];
/* density */ /* density */
density[i] -= dydx; density[i] -= dydx;
if(density[i] < 0.0f) if (density[i] < 0.0f)
density[i] = 0.0f; density[i] = 0.0f;
/* heat */ /* heat */
if (heat) { if (heat) {
if(abs(heat[i]) < dydx) heat[i] = 0.0f; if (abs(heat[i]) < dydx) heat[i] = 0.0f;
else if (heat[i]>0.0f) heat[i] -= dydx; else if (heat[i] > 0.0f) heat[i] -= dydx;
else if (heat[i]<0.0f) heat[i] += dydx; else if (heat[i] < 0.0f) heat[i] += dydx;
} }
/* color */ /* color */
@ -190,9 +189,9 @@ extern "C" void smoke_export(FLUID_3D *fluid, float *dt, float *dx, float **dens
} }
extern "C" void smoke_turbulence_export(WTURBULENCE *wt, float **dens, float **react, float **flame, float **fuel, extern "C" void smoke_turbulence_export(WTURBULENCE *wt, float **dens, float **react, float **flame, float **fuel,
float **r, float **g, float **b , float **tcu, float **tcv, float **tcw) float **r, float **g, float **b , float **tcu, float **tcv, float **tcw)
{ {
if(!wt) if (!wt)
return; return;
*dens = wt->_densityBig; *dens = wt->_densityBig;

@ -1832,9 +1832,11 @@ int BKE_imbuf_write(ImBuf *ibuf, const char *name, ImageFormatData *imf)
} }
if (imf->depth == R_IMF_CHAN_DEPTH_16) { if (imf->depth == R_IMF_CHAN_DEPTH_16) {
ibuf->ftype |= CINEON_16BIT; ibuf->ftype |= CINEON_16BIT;
} else if (imf->depth == R_IMF_CHAN_DEPTH_12) { }
else if (imf->depth == R_IMF_CHAN_DEPTH_12) {
ibuf->ftype |= CINEON_12BIT; ibuf->ftype |= CINEON_12BIT;
} else if (imf->depth == R_IMF_CHAN_DEPTH_10) { }
else if (imf->depth == R_IMF_CHAN_DEPTH_10) {
ibuf->ftype |= CINEON_10BIT; ibuf->ftype |= CINEON_10BIT;
} }
} }
@ -1845,9 +1847,11 @@ int BKE_imbuf_write(ImBuf *ibuf, const char *name, ImageFormatData *imf)
} }
if (imf->depth == R_IMF_CHAN_DEPTH_16) { if (imf->depth == R_IMF_CHAN_DEPTH_16) {
ibuf->ftype |= CINEON_16BIT; ibuf->ftype |= CINEON_16BIT;
} else if (imf->depth == R_IMF_CHAN_DEPTH_12) { }
else if (imf->depth == R_IMF_CHAN_DEPTH_12) {
ibuf->ftype |= CINEON_12BIT; ibuf->ftype |= CINEON_12BIT;
} else if (imf->depth == R_IMF_CHAN_DEPTH_10) { }
else if (imf->depth == R_IMF_CHAN_DEPTH_10) {
ibuf->ftype |= CINEON_10BIT; ibuf->ftype |= CINEON_10BIT;
} }
} }

@ -69,7 +69,7 @@ struct BLaplacianSystem {
}; };
typedef struct BLaplacianSystem LaplacianSystem; typedef struct BLaplacianSystem LaplacianSystem;
static float compute_volume(BMesh *bm, BMOperator *op); static float compute_volume(BMesh *bm);
static float cotan_weight(float *v1, float *v2, float *v3); static float cotan_weight(float *v1, float *v2, float *v3);
static int vert_is_boundary(BMVert *v); static int vert_is_boundary(BMVert *v);
static LaplacianSystem * init_laplacian_system( int a_numEdges, int a_numFaces, int a_numVerts); static LaplacianSystem * init_laplacian_system( int a_numEdges, int a_numFaces, int a_numVerts);
@ -78,7 +78,7 @@ static void delete_laplacian_system(LaplacianSystem * sys);
static void delete_void_pointer(void * data); static void delete_void_pointer(void * data);
static void fill_laplacian_matrix(LaplacianSystem * sys); static void fill_laplacian_matrix(LaplacianSystem * sys);
static void memset_laplacian_system(LaplacianSystem *sys, int val); static void memset_laplacian_system(LaplacianSystem *sys, int val);
static void validate_solution(LaplacianSystem * sys, int usex, int usey, int usez, float lambda, float lambda_border, int volumepreservation); static void validate_solution(LaplacianSystem * sys, int usex, int usey, int usez, int volumepreservation);
static void volume_preservation(BMesh *bm, BMOperator *op, float vini, float vend, int usex, int usey, int usez); static void volume_preservation(BMesh *bm, BMOperator *op, float vini, float vend, int usex, int usey, int usez);
static void delete_void_pointer(void * data) static void delete_void_pointer(void * data)
@ -230,7 +230,8 @@ static void init_laplacian_matrix(LaplacianSystem * sys)
if (has_4_vert) { if (has_4_vert) {
areaf = area_quad_v3(v1, v2, v3, v4); areaf = area_quad_v3(v1, v2, v3, v4);
} else { }
else {
areaf = area_tri_v3(v1, v2, v3); areaf = area_tri_v3(v1, v2, v3);
} }
@ -270,7 +271,8 @@ static void init_laplacian_matrix(LaplacianSystem * sys)
sys->vweights[idv1] += (w2 + w3 + w4) / 4.0f; sys->vweights[idv1] += (w2 + w3 + w4) / 4.0f;
} }
} else { }
else {
i = BM_elem_index_get(f); i = BM_elem_index_get(f);
w1 = cotan_weight(v1, v2, v3); w1 = cotan_weight(v1, v2, v3);
@ -341,7 +343,8 @@ static void fill_laplacian_matrix(LaplacianSystem * sys)
nlMatrixAdd(idv1, idv4, w4 * sys->vweights[idv1]); nlMatrixAdd(idv1, idv4, w4 * sys->vweights[idv1]);
} }
} }
} else { }
else {
idv1 = BM_elem_index_get(vf[0]); idv1 = BM_elem_index_get(vf[0]);
idv2 = BM_elem_index_get(vf[1]); idv2 = BM_elem_index_get(vf[1]);
idv3 = BM_elem_index_get(vf[2]); idv3 = BM_elem_index_get(vf[2]);
@ -412,7 +415,7 @@ static int vert_is_boundary(BMVert *v)
return 0; return 0;
} }
static float compute_volume(BMesh *bm, BMOperator *op) static float compute_volume(BMesh *bm)
{ {
float vol = 0.0f; float vol = 0.0f;
float x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4; float x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4;
@ -474,7 +477,7 @@ static void volume_preservation(BMesh *bm, BMOperator *op, float vini, float ven
} }
} }
static void validate_solution(LaplacianSystem * sys, int usex, int usey, int usez, float lambda, float lambda_border, int volumepreservation) static void validate_solution(LaplacianSystem * sys, int usex, int usey, int usez, int volumepreservation)
{ {
int m_vertex_id; int m_vertex_id;
float leni, lene; float leni, lene;
@ -506,7 +509,7 @@ static void validate_solution(LaplacianSystem * sys, int usex, int usey, int use
} }
if (volumepreservation) { if (volumepreservation) {
vini = compute_volume(sys->bm, sys->op); vini = compute_volume(sys->bm);
} }
BMO_ITER (v, &siter, sys->bm, sys->op, "verts", BM_VERT) { BMO_ITER (v, &siter, sys->bm, sys->op, "verts", BM_VERT) {
m_vertex_id = BM_elem_index_get(v); m_vertex_id = BM_elem_index_get(v);
@ -523,7 +526,7 @@ static void validate_solution(LaplacianSystem * sys, int usex, int usey, int use
} }
} }
if (volumepreservation) { if (volumepreservation) {
vend = compute_volume(sys->bm, sys->op); vend = compute_volume(sys->bm);
volume_preservation(sys->bm, sys->op, vini, vend, usex, usey, usez); volume_preservation(sys->bm, sys->op, vini, vend, usex, usey, usez);
} }
@ -587,16 +590,18 @@ void bmo_smooth_laplacian_vert_exec(BMesh *bm, BMOperator *op)
i = m_vertex_id; i = m_vertex_id;
if (sys->zerola[i] == 0) { if (sys->zerola[i] == 0) {
w = sys->vweights[i] * sys->ring_areas[i]; w = sys->vweights[i] * sys->ring_areas[i];
sys->vweights[i] = (w == 0.0f) ? 0.0f : - lambda / (4.0f * w); sys->vweights[i] = (w == 0.0f) ? 0.0f : -lambda / (4.0f * w);
w = sys->vlengths[i]; w = sys->vlengths[i];
sys->vlengths[i] = (w == 0.0f) ? 0.0f : - lambda_border * 2.0f / w; sys->vlengths[i] = (w == 0.0f) ? 0.0f : -lambda_border * 2.0f / w;
if (!vert_is_boundary(v)) { if (!vert_is_boundary(v)) {
nlMatrixAdd(i, i, 1.0f + lambda / (4.0f * sys->ring_areas[i])); nlMatrixAdd(i, i, 1.0f + lambda / (4.0f * sys->ring_areas[i]));
} else { }
else {
nlMatrixAdd(i, i, 1.0f + lambda_border * 2.0f); nlMatrixAdd(i, i, 1.0f + lambda_border * 2.0f);
} }
} else { }
else {
nlMatrixAdd(i, i, 1.0f); nlMatrixAdd(i, i, 1.0f);
} }
} }
@ -606,7 +611,7 @@ void bmo_smooth_laplacian_vert_exec(BMesh *bm, BMOperator *op)
nlEnd(NL_SYSTEM); nlEnd(NL_SYSTEM);
if (nlSolveAdvanced(NULL, NL_TRUE) ) { if (nlSolveAdvanced(NULL, NL_TRUE) ) {
validate_solution(sys, usex, usey, usez, lambda, lambda_border, volumepreservation); validate_solution(sys, usex, usey, usez, volumepreservation);
} }
delete_laplacian_system(sys); delete_laplacian_system(sys);

@ -1672,15 +1672,15 @@ static int edbm_do_smooth_laplacian_vertex_exec(bContext *C, wmOperator *op)
BMEditMesh *em = BMEdit_FromObject(obedit); BMEditMesh *em = BMEdit_FromObject(obedit);
int usex = TRUE, usey = TRUE, usez = TRUE, volume_preservation = TRUE; int usex = TRUE, usey = TRUE, usez = TRUE, volume_preservation = TRUE;
int i, repeat; int i, repeat;
float lambda = 0.1f; float lambda;
float lambda_border = 0.1f; float lambda_border;
BMIter fiter; BMIter fiter;
BMFace *f; BMFace *f;
/* Check if select faces are triangles */ /* Check if select faces are triangles */
BM_ITER_MESH (f, &fiter, em->bm, BM_FACES_OF_MESH) { BM_ITER_MESH (f, &fiter, em->bm, BM_FACES_OF_MESH) {
if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
if(f->len > 4) { if (f->len > 4) {
BKE_report(op->reports, RPT_WARNING, "Selected faces must be triangles or quads"); BKE_report(op->reports, RPT_WARNING, "Selected faces must be triangles or quads");
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
} }

@ -2378,11 +2378,12 @@ static void createTransUVs(bContext *C, TransInfo *t)
if (!ED_space_image_show_uvedit(sima, t->obedit)) return; if (!ED_space_image_show_uvedit(sima, t->obedit)) return;
/* count */ /* count */
if(propconnected) { if (propconnected) {
/* create element map with island information */ /* create element map with island information */
if (ts->uv_flag & UV_SYNC_SELECTION) { if (ts->uv_flag & UV_SYNC_SELECTION) {
elementmap = EDBM_uv_element_map_create (em, FALSE, TRUE); elementmap = EDBM_uv_element_map_create (em, FALSE, TRUE);
} else { }
else {
elementmap = EDBM_uv_element_map_create (em, TRUE, TRUE); elementmap = EDBM_uv_element_map_create (em, TRUE, TRUE);
} }
island_enabled = MEM_callocN(sizeof(*island_enabled) * elementmap->totalIslands, "TransIslandData(UV Editing)"); island_enabled = MEM_callocN(sizeof(*island_enabled) * elementmap->totalIslands, "TransIslandData(UV Editing)");
@ -2401,7 +2402,7 @@ static void createTransUVs(bContext *C, TransInfo *t)
if (uvedit_uv_select_test(em, scene, l)) { if (uvedit_uv_select_test(em, scene, l)) {
countsel++; countsel++;
if(propconnected) { if (propconnected) {
UvElement *element = ED_uv_element_get(elementmap, efa, l); UvElement *element = ED_uv_element_get(elementmap, efa, l);
island_enabled[element->island] = TRUE; island_enabled[element->island] = TRUE;
} }

@ -3384,13 +3384,13 @@ static const char *cpp_classes = ""
" DynamicArray(const DynamicArray<T>& other) { copy_from(other); }\n" " DynamicArray(const DynamicArray<T>& other) { copy_from(other); }\n"
" const DynamicArray<T>& operator=(const DynamicArray<T>& other) { copy_from(other); return *this; }\n" " const DynamicArray<T>& operator=(const DynamicArray<T>& other) { copy_from(other); return *this; }\n"
"\n" "\n"
" ~DynamicArray() { if(data) free(data); }\n" " ~DynamicArray() { if (data) free(data); }\n"
"\n" "\n"
" operator T*() { return data; }\n" " operator T*() { return data; }\n"
"\n" "\n"
"protected:\n" "protected:\n"
" void copy_from(const DynamicArray<T>& other) {\n" " void copy_from(const DynamicArray<T>& other) {\n"
" if(data) free(data);\n" " if (data) free(data);\n"
" data = (float*)malloc(sizeof(T) * other.length);\n" " data = (float*)malloc(sizeof(T) * other.length);\n"
" memcpy(data, other.data, sizeof(T) * other.length);\n" " memcpy(data, other.data, sizeof(T) * other.length);\n"
" length = other.length;\n" " length = other.length;\n"

@ -56,17 +56,17 @@
#define MOD_LAPLACIANSMOOTH_MIN_EDGE_PERCENTAGE 0.02 #define MOD_LAPLACIANSMOOTH_MIN_EDGE_PERCENTAGE 0.02
struct BLaplacianSystem { struct BLaplacianSystem {
float *eweights; /* Length weights per Edge */ float *eweights; /* Length weights per Edge */
float (*fweights)[3]; /* Cotangent weights per face */ float (*fweights)[3]; /* Cotangent weights per face */
float *ring_areas; /* Total area per ring*/ float *ring_areas; /* Total area per ring*/
float *vlengths; /* Total sum of lengths(edges) per vertice*/ float *vlengths; /* Total sum of lengths(edges) per vertice*/
float *vweights; /* Total sum of weights per vertice*/ float *vweights; /* Total sum of weights per vertice*/
int numEdges; /* Number of edges*/ int numEdges; /* Number of edges*/
int numFaces; /* Number of faces*/ int numFaces; /* Number of faces*/
int numVerts; /* Number of verts*/ int numVerts; /* Number of verts*/
short *numNeFa; /* Number of neighboors faces around vertice*/ short *numNeFa; /* Number of neighboors faces around vertice*/
short *numNeEd; /* Number of neighboors Edges around vertice*/ short *numNeEd; /* Number of neighboors Edges around vertice*/
short *zerola; /* Is zero area or length*/ short *zerola; /* Is zero area or length*/
/* Pointers to data*/ /* Pointers to data*/
float (*vertexCos)[3]; float (*vertexCos)[3];
@ -86,14 +86,14 @@ static float compute_volume(float (*vertexCos)[3], MFace *mfaces, int numFaces);
static float cotan_weight(float *v1, float *v2, float *v3); static float cotan_weight(float *v1, float *v2, float *v3);
static LaplacianSystem * init_laplacian_system( int a_numEdges, int a_numFaces, int a_numVerts); static LaplacianSystem * init_laplacian_system( int a_numEdges, int a_numFaces, int a_numVerts);
static void copy_data(ModifierData *md, ModifierData *target); static void copy_data(ModifierData *md, ModifierData *target);
static void delete_laplacian_system(LaplacianSystem * sys); static void delete_laplacian_system(LaplacianSystem *sys);
static void delete_void_pointer(void * data); static void delete_void_pointer(void * data);
static void fill_laplacian_matrix(LaplacianSystem * sys); static void fill_laplacian_matrix(LaplacianSystem *sys);
static void init_data(ModifierData *md); static void init_data(ModifierData *md);
static void init_laplacian_matrix(LaplacianSystem * sys); static void init_laplacian_matrix(LaplacianSystem *sys);
static void memset_laplacian_system(LaplacianSystem *sys, int val); static void memset_laplacian_system(LaplacianSystem *sys, int val);
static void volume_preservation(LaplacianSystem *sys, float vini, float vend, short flag); static void volume_preservation(LaplacianSystem *sys, float vini, float vend, short flag);
static void validate_solution(LaplacianSystem * sys, short flag, float lambda, float lambda_border); static void validate_solution(LaplacianSystem *sys, short flag);
static void delete_void_pointer(void * data) static void delete_void_pointer(void * data)
{ {
@ -103,7 +103,7 @@ static void delete_void_pointer(void * data)
} }
} }
static void delete_laplacian_system(LaplacianSystem * sys) static void delete_laplacian_system(LaplacianSystem *sys)
{ {
delete_void_pointer(sys->eweights); delete_void_pointer(sys->eweights);
delete_void_pointer(sys->fweights); delete_void_pointer(sys->fweights);
@ -124,19 +124,19 @@ static void delete_laplacian_system(LaplacianSystem * sys)
static void memset_laplacian_system(LaplacianSystem *sys, int val) static void memset_laplacian_system(LaplacianSystem *sys, int val)
{ {
memset(sys->eweights , val, sizeof(float) * sys->numEdges); memset(sys->eweights, val, sizeof(float) * sys->numEdges);
memset(sys->fweights , val, sizeof(float) * sys->numFaces * 3); memset(sys->fweights, val, sizeof(float) * sys->numFaces * 3);
memset(sys->numNeEd , val, sizeof(short) * sys->numVerts); memset(sys->numNeEd, val, sizeof(short) * sys->numVerts);
memset(sys->numNeFa , val, sizeof(short) * sys->numVerts); memset(sys->numNeFa, val, sizeof(short) * sys->numVerts);
memset(sys->ring_areas , val, sizeof(float) * sys->numVerts); memset(sys->ring_areas, val, sizeof(float) * sys->numVerts);
memset(sys->vlengths , val, sizeof(float) * sys->numVerts); memset(sys->vlengths, val, sizeof(float) * sys->numVerts);
memset(sys->vweights , val, sizeof(float) * sys->numVerts); memset(sys->vweights, val, sizeof(float) * sys->numVerts);
memset(sys->zerola , val, sizeof(short) * sys->numVerts); memset(sys->zerola, val, sizeof(short) * sys->numVerts);
} }
static LaplacianSystem * init_laplacian_system( int a_numEdges, int a_numFaces, int a_numVerts) static LaplacianSystem * init_laplacian_system( int a_numEdges, int a_numFaces, int a_numVerts)
{ {
LaplacianSystem * sys; LaplacianSystem *sys;
sys = MEM_callocN(sizeof(LaplacianSystem), "ModLaplSmoothSystem"); sys = MEM_callocN(sizeof(LaplacianSystem), "ModLaplSmoothSystem");
sys->numEdges = a_numEdges; sys->numEdges = a_numEdges;
sys->numFaces = a_numFaces; sys->numFaces = a_numFaces;
@ -300,20 +300,20 @@ static void volume_preservation(LaplacianSystem *sys, float vini, float vend, sh
beta = pow (vini / vend, 1.0f / 3.0f); beta = pow (vini / vend, 1.0f / 3.0f);
for (i = 0; i < sys->numVerts; i++) { for (i = 0; i < sys->numVerts; i++) {
if (flag & MOD_LAPLACIANSMOOTH_X) { if (flag & MOD_LAPLACIANSMOOTH_X) {
sys->vertexCos[i][0] = (sys->vertexCos[i][0] - sys->vert_centroid[0])* beta + sys->vert_centroid[0]; sys->vertexCos[i][0] = (sys->vertexCos[i][0] - sys->vert_centroid[0]) * beta + sys->vert_centroid[0];
} }
if (flag & MOD_LAPLACIANSMOOTH_Y) { if (flag & MOD_LAPLACIANSMOOTH_Y) {
sys->vertexCos[i][1] = (sys->vertexCos[i][1] - sys->vert_centroid[1])* beta + sys->vert_centroid[1]; sys->vertexCos[i][1] = (sys->vertexCos[i][1] - sys->vert_centroid[1]) * beta + sys->vert_centroid[1];
} }
if (flag & MOD_LAPLACIANSMOOTH_Z) { if (flag & MOD_LAPLACIANSMOOTH_Z) {
sys->vertexCos[i][2] = (sys->vertexCos[i][2] - sys->vert_centroid[2])* beta + sys->vert_centroid[2]; sys->vertexCos[i][2] = (sys->vertexCos[i][2] - sys->vert_centroid[2]) * beta + sys->vert_centroid[2];
} }
} }
} }
} }
static void init_laplacian_matrix(LaplacianSystem * sys) static void init_laplacian_matrix(LaplacianSystem *sys)
{ {
float *v1, *v2, *v3, *v4; float *v1, *v2, *v3, *v4;
float w1, w2, w3, w4; float w1, w2, w3, w4;
@ -334,7 +334,8 @@ static void init_laplacian_matrix(LaplacianSystem * sys)
if (w1 < sys->min_area) { if (w1 < sys->min_area) {
sys->zerola[idv1] = 1; sys->zerola[idv1] = 1;
sys->zerola[idv2] = 1; sys->zerola[idv2] = 1;
} else { }
else {
w1 = 1.0f / w1; w1 = 1.0f / w1;
} }
@ -360,7 +361,8 @@ static void init_laplacian_matrix(LaplacianSystem * sys)
if (has_4_vert) { if (has_4_vert) {
areaf = area_quad_v3(v1, v2, v3, sys->vertexCos[sys->mfaces[i].v4]); areaf = area_quad_v3(v1, v2, v3, sys->vertexCos[sys->mfaces[i].v4]);
} else { }
else {
areaf = area_tri_v3(v1, v2, v3); areaf = area_tri_v3(v1, v2, v3);
} }
if (fabs(areaf) < sys->min_area) { if (fabs(areaf) < sys->min_area) {
@ -399,7 +401,8 @@ static void init_laplacian_matrix(LaplacianSystem * sys)
sys->vweights[idv1] += (w2 + w3 + w4) / 4.0f; sys->vweights[idv1] += (w2 + w3 + w4) / 4.0f;
} }
} else { }
else {
w1 = cotan_weight(v1, v2, v3); w1 = cotan_weight(v1, v2, v3);
w2 = cotan_weight(v2, v3, v1); w2 = cotan_weight(v2, v3, v1);
w3 = cotan_weight(v3, v1, v2); w3 = cotan_weight(v3, v1, v2);
@ -425,7 +428,7 @@ static void init_laplacian_matrix(LaplacianSystem * sys)
} }
static void fill_laplacian_matrix(LaplacianSystem * sys) static void fill_laplacian_matrix(LaplacianSystem *sys)
{ {
float *v1, *v2, *v3, *v4; float *v1, *v2, *v3, *v4;
float w2, w3, w4; float w2, w3, w4;
@ -469,7 +472,8 @@ static void fill_laplacian_matrix(LaplacianSystem * sys)
nlMatrixAdd(idv1, idv4, w4 * sys->vweights[idv1]); nlMatrixAdd(idv1, idv4, w4 * sys->vweights[idv1]);
} }
} }
} else { }
else {
/* Is ring if number of faces == number of edges around vertice*/ /* Is ring if number of faces == number of edges around vertice*/
if (sys->numNeEd[idv1] == sys->numNeFa[idv1] && sys->zerola[idv1] == 0) { if (sys->numNeEd[idv1] == sys->numNeFa[idv1] && sys->zerola[idv1] == 0) {
nlMatrixAdd(idv1, idv2, sys->fweights[i][2] * sys->vweights[idv1]); nlMatrixAdd(idv1, idv2, sys->fweights[i][2] * sys->vweights[idv1]);
@ -501,7 +505,7 @@ static void fill_laplacian_matrix(LaplacianSystem * sys)
} }
} }
static void validate_solution(LaplacianSystem * sys, short flag, float lambda, float lambda_border) static void validate_solution(LaplacianSystem *sys, short flag)
{ {
int i, idv1, idv2; int i, idv1, idv2;
float leni, lene; float leni, lene;
@ -561,7 +565,9 @@ static void laplaciansmoothModifier_do(
DM_ensure_tessface(dm); DM_ensure_tessface(dm);
sys = init_laplacian_system(dm->getNumEdges(dm), dm->getNumTessFaces(dm), numVerts); sys = init_laplacian_system(dm->getNumEdges(dm), dm->getNumTessFaces(dm), numVerts);
if(!sys) return; if (!sys) {
return;
}
sys->mfaces = dm->getTessFaceArray(dm); sys->mfaces = dm->getTessFaceArray(dm);
sys->medges = dm->getEdgeArray(dm); sys->medges = dm->getEdgeArray(dm);
@ -589,15 +595,11 @@ static void laplaciansmoothModifier_do(
nlSetVariable(1, i, vertexCos[i][1]); nlSetVariable(1, i, vertexCos[i][1]);
nlSetVariable(2, i, vertexCos[i][2]); nlSetVariable(2, i, vertexCos[i][2]);
if (iter == 0) { if (iter == 0) {
sys->vert_centroid[0] += vertexCos[i][0]; add_v3_v3(sys->vert_centroid, vertexCos[i]);
sys->vert_centroid[1] += vertexCos[i][1];
sys->vert_centroid[2] += vertexCos[i][2];
} }
} }
if (iter == 0 && numVerts >0) { if (iter == 0 && numVerts > 0) {
sys->vert_centroid[0] = sys->vert_centroid[0] / numVerts; mul_v3_fl(sys->vert_centroid, 1.0f / (float)numVerts);
sys->vert_centroid[1] = sys->vert_centroid[1] / numVerts;
sys->vert_centroid[2] = sys->vert_centroid[2] / numVerts;
} }
nlBegin(NL_MATRIX); nlBegin(NL_MATRIX);
@ -609,21 +611,25 @@ static void laplaciansmoothModifier_do(
if (dv) { if (dv) {
wpaint = defvert_find_weight(dv, defgrp_index); wpaint = defvert_find_weight(dv, defgrp_index);
dv++; dv++;
} else { }
else {
wpaint = 1.0f; wpaint = 1.0f;
} }
if (sys->zerola[i] == 0) { if (sys->zerola[i] == 0) {
w = sys->vweights[i] * sys->ring_areas[i]; w = sys->vweights[i] * sys->ring_areas[i];
sys->vweights[i] = (w == 0.0f) ? 0.0f : - smd->lambda * wpaint / (4.0f * w); sys->vweights[i] = (w == 0.0f) ? 0.0f : -smd->lambda * wpaint / (4.0f * w);
w = sys->vlengths[i]; w = sys->vlengths[i];
sys->vlengths[i] = (w == 0.0f) ? 0.0f : - smd->lambda_border * wpaint * 2.0f / w; sys->vlengths[i] = (w == 0.0f) ? 0.0f : -smd->lambda_border * wpaint * 2.0f / w;
if (sys->numNeEd[i] == sys->numNeFa[i]) { if (sys->numNeEd[i] == sys->numNeFa[i]) {
nlMatrixAdd(i, i, 1.0f + smd->lambda * wpaint / (4.0f * sys->ring_areas[i])); nlMatrixAdd(i, i, 1.0f + smd->lambda * wpaint / (4.0f * sys->ring_areas[i]));
} else { }
else {
nlMatrixAdd(i, i, 1.0f + smd->lambda_border * wpaint * 2.0f); nlMatrixAdd(i, i, 1.0f + smd->lambda_border * wpaint * 2.0f);
} }
} else { }
else {
nlMatrixAdd(i, i, 1.0f); nlMatrixAdd(i, i, 1.0f);
} }
} }
@ -634,7 +640,7 @@ static void laplaciansmoothModifier_do(
nlEnd(NL_SYSTEM); nlEnd(NL_SYSTEM);
if (nlSolveAdvanced(NULL, NL_TRUE)) { if (nlSolveAdvanced(NULL, NL_TRUE)) {
validate_solution(sys, smd->flag, smd->lambda, smd->lambda_border); validate_solution(sys, smd->flag);
} }
nlDeleteContext(sys->context); nlDeleteContext(sys->context);
sys->context = NULL; sys->context = NULL;
@ -684,10 +690,10 @@ ModifierTypeInfo modifierType_LaplacianSmooth = {
/* deformMatricesEM */ NULL, /* deformMatricesEM */ NULL,
/* applyModifier */ NULL, /* applyModifier */ NULL,
/* applyModifierEM */ NULL, /* applyModifierEM */ NULL,
/* init_data */ init_data, /* initData */ init_data,
/* required_data_mask */ required_data_mask, /* requiredDataMask */ required_data_mask,
/* freeData */ NULL, /* freeData */ NULL,
/* is_disabled */ is_disabled, /* isDisabled */ is_disabled,
/* updateDepgraph */ NULL, /* updateDepgraph */ NULL,
/* dependsOnTime */ NULL, /* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL, /* dependsOnNormals */ NULL,

@ -557,8 +557,8 @@ static void GetNormal(const SMikkTSpaceContext * pContext, float fNorm[], const
SRenderMeshToTangent * pMesh = (SRenderMeshToTangent *) pContext->m_pUserData; SRenderMeshToTangent * pMesh = (SRenderMeshToTangent *) pContext->m_pUserData;
VlakRen *vlr= RE_findOrAddVlak(pMesh->obr, face_num); VlakRen *vlr= RE_findOrAddVlak(pMesh->obr, face_num);
if(vlr->flag & ME_SMOOTH) { if (vlr->flag & ME_SMOOTH) {
const float *n= (&vlr->v1)[vert_index]->n; const float *n = (&vlr->v1)[vert_index]->n;
copy_v3_v3(fNorm, n); copy_v3_v3(fNorm, n);
} }
else { else {