Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh.c
| Show First 20 Lines • Show All 383 Lines • ▼ Show 20 Lines | enum { | ||||
| MESHCMP_LOOPCOLMISMATCH, | MESHCMP_LOOPCOLMISMATCH, | ||||
| MESHCMP_LOOPUVMISMATCH, | MESHCMP_LOOPUVMISMATCH, | ||||
| MESHCMP_LOOPMISMATCH, | MESHCMP_LOOPMISMATCH, | ||||
| MESHCMP_POLYVERTMISMATCH, | MESHCMP_POLYVERTMISMATCH, | ||||
| MESHCMP_POLYMISMATCH, | MESHCMP_POLYMISMATCH, | ||||
| MESHCMP_EDGEUNKNOWN, | MESHCMP_EDGEUNKNOWN, | ||||
| MESHCMP_VERTCOMISMATCH, | MESHCMP_VERTCOMISMATCH, | ||||
| MESHCMP_CDLAYERS_MISMATCH, | MESHCMP_CDLAYERS_MISMATCH, | ||||
| MESHCMP_ATTRIBUTE_VALUE_MISMATCH, | |||||
JacquesLucke: There is no need to abbreviate the words here. | |||||
| }; | }; | ||||
| static const char *cmpcode_to_str(int code) | static const char *cmpcode_to_str(int code) | ||||
| { | { | ||||
| switch (code) { | switch (code) { | ||||
| case MESHCMP_DVERT_WEIGHTMISMATCH: | case MESHCMP_DVERT_WEIGHTMISMATCH: | ||||
| return "Vertex Weight Mismatch"; | return "Vertex Weight Mismatch"; | ||||
| case MESHCMP_DVERT_GROUPMISMATCH: | case MESHCMP_DVERT_GROUPMISMATCH: | ||||
| Show All 11 Lines | switch (code) { | ||||
| case MESHCMP_POLYMISMATCH: | case MESHCMP_POLYMISMATCH: | ||||
| return "Loop Vert Mismatch"; | return "Loop Vert Mismatch"; | ||||
| case MESHCMP_EDGEUNKNOWN: | case MESHCMP_EDGEUNKNOWN: | ||||
| return "Edge Mismatch"; | return "Edge Mismatch"; | ||||
| case MESHCMP_VERTCOMISMATCH: | case MESHCMP_VERTCOMISMATCH: | ||||
| return "Vertex Coordinate Mismatch"; | return "Vertex Coordinate Mismatch"; | ||||
| case MESHCMP_CDLAYERS_MISMATCH: | case MESHCMP_CDLAYERS_MISMATCH: | ||||
| return "CustomData Layer Count Mismatch"; | return "CustomData Layer Count Mismatch"; | ||||
| case MESHCMP_ATTRIBUTE_VALUE_MISMATCH: | |||||
| return "Attribute Value Mismatch"; | |||||
| default: | default: | ||||
| return "Mesh Comparison Code Unknown"; | return "Mesh Comparison Code Unknown"; | ||||
| } | } | ||||
| } | } | ||||
| /** Thresh is threshold for comparing vertices, UV's, vertex colors, weights, etc. */ | /** Thresh is threshold for comparing vertices, UV's, vertex colors, weights, etc. */ | ||||
| static int customdata_compare( | static int customdata_compare( | ||||
| CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2, const float thresh) | CustomData *c1, CustomData *c2, const int total_length, Mesh *m1, Mesh *m2, const float thresh) | ||||
| { | { | ||||
| const float thresh_sq = thresh * thresh; | const float thresh_sq = thresh * thresh; | ||||
| CustomDataLayer *l1, *l2; | CustomDataLayer *l1, *l2; | ||||
| int i, i1 = 0, i2 = 0, tot, j; | int i1 = 0, i2 = 0, tot, j; | ||||
| for (i = 0; i < c1->totlayer; i++) { | for (int i = 0; i < c1->totlayer; i++) { | ||||
| if (ELEM(c1->layers[i].type, | if (ELEM(c1->layers[i].type, | ||||
| CD_MVERT, | CD_MVERT, | ||||
| CD_MEDGE, | CD_MEDGE, | ||||
| CD_MPOLY, | CD_MPOLY, | ||||
| CD_MLOOPUV, | CD_MLOOPUV, | ||||
| CD_MLOOPCOL, | CD_MLOOPCOL, | ||||
| CD_MDEFORMVERT)) { | CD_MDEFORMVERT)) { | ||||
| i1++; | i1++; | ||||
| } | } | ||||
| } | } | ||||
| for (i = 0; i < c2->totlayer; i++) { | for (int i = 0; i < c2->totlayer; i++) { | ||||
| if (ELEM(c2->layers[i].type, | if (ELEM(c2->layers[i].type, | ||||
| CD_MVERT, | CD_MVERT, | ||||
| CD_MEDGE, | CD_MEDGE, | ||||
| CD_MPOLY, | CD_MPOLY, | ||||
| CD_MLOOPUV, | CD_MLOOPUV, | ||||
| CD_MLOOPCOL, | CD_MLOOPCOL, | ||||
| CD_MDEFORMVERT)) { | CD_MDEFORMVERT)) { | ||||
| i2++; | i2++; | ||||
| } | } | ||||
| } | } | ||||
| if (i1 != i2) { | if (i1 != i2) { | ||||
| return MESHCMP_CDLAYERS_MISMATCH; | return MESHCMP_CDLAYERS_MISMATCH; | ||||
| } | } | ||||
| l1 = c1->layers; | l1 = c1->layers; | ||||
| l2 = c2->layers; | l2 = c2->layers; | ||||
| for (i1 = 0; i1 < c1->totlayer; i1++) { | |||||
| l1 = c1->layers + i1; | |||||
| if ((CD_TYPE_AS_MASK(l1->type) & CD_MASK_PROP_ALL) == 0) { | |||||
| /* Skip non generic attribute layers. */ | |||||
| continue; | |||||
| } | |||||
| bool found_corresponding_layer = false; | |||||
| for (i2 = 0; i2 < c2->totlayer; i2++) { | |||||
| l2 = c2->layers + i2; | |||||
| if (l1->type != l2->type || !STREQ(l1->name, l2->name)) { | |||||
| continue; | |||||
| } | |||||
| found_corresponding_layer = true; | |||||
| /* At this point `l1` and `l2` have the same name and type, so they should be compared. */ | |||||
| switch (l1->type) { | |||||
| case CD_PROP_FLOAT: { | |||||
Done Inline ActionsMissing break, some in the cases below. JacquesLucke: Missing `break`, some in the cases below. | |||||
| const float *l1_data = l1->data; | |||||
| const float *l2_data = l2->data; | |||||
Done Inline ActionsThis i shadows a previous declaration. You can remove the function-wide declaration of i and declare it in the for loops where it is used. JacquesLucke: This `i` shadows a previous declaration. You can remove the function-wide declaration of `i`… | |||||
| for (int i = 0; i < total_length; i++) { | |||||
| if (fabsf(l1_data[i] - l2_data[i]) > thresh) { | |||||
| return MESHCMP_ATTRIBUTE_VALUE_MISMATCH; | |||||
| } | |||||
| } | |||||
| break; | |||||
| } | |||||
| case CD_PROP_FLOAT2: { | |||||
| const float(*l1_data)[2] = l1->data; | |||||
| const float(*l2_data)[2] = l2->data; | |||||
| for (int i = 0; i < total_length; i++) { | |||||
Done Inline ActionsRemove unnecessary newlines. JacquesLucke: Remove unnecessary newlines. | |||||
| if (len_squared_v2v2(l1_data[i], l2_data[i]) > thresh_sq) { | |||||
Done Inline ActionsThis is missing [i], same below. JacquesLucke: This is missing `[i]`, same below. | |||||
| return MESHCMP_ATTRIBUTE_VALUE_MISMATCH; | |||||
| } | |||||
| } | |||||
| break; | |||||
| } | |||||
| case CD_PROP_FLOAT3: { | |||||
| const float(*l1_data)[3] = l1->data; | |||||
| const float(*l2_data)[3] = l2->data; | |||||
Done Inline ActionsRemove unnecessary newlines between individual cases. JacquesLucke: Remove unnecessary newlines between individual cases. | |||||
| for (int i = 0; i < total_length; i++) { | |||||
Done Inline ActionsUse clang format. JacquesLucke: Use clang format. | |||||
| if (len_squared_v3v3(l1_data[i], l2_data[i]) > thresh_sq) { | |||||
| return MESHCMP_ATTRIBUTE_VALUE_MISMATCH; | |||||
| } | |||||
| } | |||||
| break; | |||||
| } | |||||
| default: { | |||||
| int element_size = CustomData_sizeof(l1->type); | |||||
| for (int i = 0; i < total_length; i++) { | |||||
| int offset = element_size * i; | |||||
| if (!CustomData_data_equals(l1->type, | |||||
| POINTER_OFFSET(l1->data, offset), | |||||
| POINTER_OFFSET(l2->data, offset))) { | |||||
| return MESHCMP_ATTRIBUTE_VALUE_MISMATCH; | |||||
| } | |||||
| } | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| if (!found_corresponding_layer) { | |||||
| return MESHCMP_CDLAYERS_MISMATCH; | |||||
| } | |||||
| } | |||||
| l1 = c1->layers; | |||||
| l2 = c2->layers; | |||||
| tot = i1; | tot = i1; | ||||
| i1 = 0; | i1 = 0; | ||||
| i2 = 0; | i2 = 0; | ||||
| for (i = 0; i < tot; i++) { | for (int i = 0; i < tot; i++) { | ||||
| while ( | while ( | ||||
| i1 < c1->totlayer && | i1 < c1->totlayer && | ||||
| !ELEM(l1->type, CD_MVERT, CD_MEDGE, CD_MPOLY, CD_MLOOPUV, CD_MLOOPCOL, CD_MDEFORMVERT)) { | !ELEM(l1->type, CD_MVERT, CD_MEDGE, CD_MPOLY, CD_MLOOPUV, CD_MLOOPCOL, CD_MDEFORMVERT)) { | ||||
| i1++; | i1++; | ||||
| l1++; | l1++; | ||||
| } | } | ||||
| while ( | while ( | ||||
| ▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | const char *BKE_mesh_cmp(Mesh *me1, Mesh *me2, float thresh) | ||||
| if (me1->totpoly != me2->totpoly) { | if (me1->totpoly != me2->totpoly) { | ||||
| return "Number of faces don't match"; | return "Number of faces don't match"; | ||||
| } | } | ||||
| if (me1->totloop != me2->totloop) { | if (me1->totloop != me2->totloop) { | ||||
| return "Number of loops don't match"; | return "Number of loops don't match"; | ||||
| } | } | ||||
| if ((c = customdata_compare(&me1->vdata, &me2->vdata, me1, me2, thresh))) { | if ((c = customdata_compare(&me1->vdata, &me2->vdata, me1->totvert, me1, me2, thresh))) { | ||||
| return cmpcode_to_str(c); | return cmpcode_to_str(c); | ||||
| } | } | ||||
| if ((c = customdata_compare(&me1->edata, &me2->edata, me1, me2, thresh))) { | if ((c = customdata_compare(&me1->edata, &me2->edata, me1->totedge, me1, me2, thresh))) { | ||||
| return cmpcode_to_str(c); | return cmpcode_to_str(c); | ||||
| } | } | ||||
| if ((c = customdata_compare(&me1->ldata, &me2->ldata, me1, me2, thresh))) { | if ((c = customdata_compare(&me1->ldata, &me2->ldata, me1->totloop, me1, me2, thresh))) { | ||||
| return cmpcode_to_str(c); | return cmpcode_to_str(c); | ||||
| } | } | ||||
| if ((c = customdata_compare(&me1->pdata, &me2->pdata, me1, me2, thresh))) { | if ((c = customdata_compare(&me1->pdata, &me2->pdata, me1->totpoly, me1, me2, thresh))) { | ||||
| return cmpcode_to_str(c); | return cmpcode_to_str(c); | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| static void mesh_ensure_tessellation_customdata(Mesh *me) | static void mesh_ensure_tessellation_customdata(Mesh *me) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 1,533 Lines • Show Last 20 Lines | |||||
There is no need to abbreviate the words here.