Changeset View
Changeset View
Standalone View
Standalone View
source/blender/modifiers/intern/MOD_triangulate.c
| Show All 34 Lines | |||||
| #include "MOD_modifiertypes.h" | #include "MOD_modifiertypes.h" | ||||
| static Mesh *triangulate_mesh(Mesh *mesh, const int quad_method, const int ngon_method, const int flag) | static Mesh *triangulate_mesh(Mesh *mesh, const int quad_method, const int ngon_method, const int flag) | ||||
| { | { | ||||
| Mesh *result; | Mesh *result; | ||||
| BMesh *bm; | BMesh *bm; | ||||
| int total_edges, i; | int total_edges, i; | ||||
| MEdge *me; | MEdge *me; | ||||
| CustomDataMask cddata_masks = CD_MASK_ORIGINDEX; | CustomData_MeshMasks cddata_masks = {.vmask=CD_MASK_ORIGINDEX, .emask=CD_MASK_ORIGINDEX, .pmask=CD_MASK_ORIGINDEX}; | ||||
| bool keep_clnors = (flag & MOD_TRIANGULATE_KEEP_CUSTOMLOOP_NORMALS) != 0; | bool keep_clnors = (flag & MOD_TRIANGULATE_KEEP_CUSTOMLOOP_NORMALS) != 0; | ||||
| if (keep_clnors) { | if (keep_clnors) { | ||||
| BKE_mesh_calc_normals_split(mesh); | BKE_mesh_calc_normals_split(mesh); | ||||
| /* We need that one to 'survive' to/from BMesh conversions. */ | /* We need that one to 'survive' to/from BMesh conversions. */ | ||||
| CustomData_clear_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); | CustomData_clear_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); | ||||
| cddata_masks |= CD_MASK_NORMAL; /* TODO: once D4421 is in, only request CD_NORMAL on loop data... */ | cddata_masks.lmask |= CD_MASK_NORMAL; | ||||
| } | } | ||||
| bm = BKE_mesh_to_bmesh_ex( | bm = BKE_mesh_to_bmesh_ex( | ||||
| mesh, | mesh, | ||||
| &((struct BMeshCreateParams){0}), | &((struct BMeshCreateParams){0}), | ||||
| &((struct BMeshFromMeshParams){ | &((struct BMeshFromMeshParams){ | ||||
| .calc_face_normal = true, | .calc_face_normal = true, | ||||
| .cd_mask_extra = cddata_masks, | .cd_mask_extra = cddata_masks, | ||||
| })); | })); | ||||
| BM_mesh_triangulate(bm, quad_method, ngon_method, false, NULL, NULL, NULL); | BM_mesh_triangulate(bm, quad_method, ngon_method, false, NULL, NULL, NULL); | ||||
| result = BKE_mesh_from_bmesh_for_eval_nomain(bm, cddata_masks); | result = BKE_mesh_from_bmesh_for_eval_nomain(bm, &cddata_masks); | ||||
| BM_mesh_free(bm); | BM_mesh_free(bm); | ||||
| if (keep_clnors) { | if (keep_clnors) { | ||||
| float (*lnors)[3] = CustomData_get_layer(&result->ldata, CD_NORMAL); | float (*lnors)[3] = CustomData_get_layer(&result->ldata, CD_NORMAL); | ||||
| BLI_assert(lnors != NULL); | BLI_assert(lnors != NULL); | ||||
| BKE_mesh_set_custom_normals(result, lnors); | BKE_mesh_set_custom_normals(result, lnors); | ||||
| ▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines | |||||