Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesrna/intern/rna_mesh_api.c
| Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
| static void rna_Mesh_create_normals_split(Mesh *mesh) | static void rna_Mesh_create_normals_split(Mesh *mesh) | ||||
| { | { | ||||
| if (!CustomData_has_layer(&mesh->ldata, CD_NORMAL)) { | if (!CustomData_has_layer(&mesh->ldata, CD_NORMAL)) { | ||||
| CustomData_add_layer(&mesh->ldata, CD_NORMAL, CD_CALLOC, NULL, mesh->totloop); | CustomData_add_layer(&mesh->ldata, CD_NORMAL, CD_CALLOC, NULL, mesh->totloop); | ||||
| CustomData_set_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); | CustomData_set_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); | ||||
| } | } | ||||
| } | } | ||||
| static void rna_Mesh_calc_normals_split(Mesh *mesh) | |||||
| { | |||||
| float (*r_loopnors)[3]; | |||||
| float (*polynors)[3]; | |||||
| short (*clnors)[2] = NULL; | |||||
| bool free_polynors = false; | |||||
| if (CustomData_has_layer(&mesh->ldata, CD_NORMAL)) { | |||||
| r_loopnors = CustomData_get_layer(&mesh->ldata, CD_NORMAL); | |||||
| memset(r_loopnors, 0, sizeof(float[3]) * mesh->totloop); | |||||
| } | |||||
| else { | |||||
| r_loopnors = CustomData_add_layer(&mesh->ldata, CD_NORMAL, CD_CALLOC, NULL, mesh->totloop); | |||||
| CustomData_set_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); | |||||
| } | |||||
| /* may be NULL */ | |||||
| clnors = CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); | |||||
| if (CustomData_has_layer(&mesh->pdata, CD_NORMAL)) { | |||||
| /* This assume that layer is always up to date, not sure this is the case (esp. in Edit mode?)... */ | |||||
| polynors = CustomData_get_layer(&mesh->pdata, CD_NORMAL); | |||||
| free_polynors = false; | |||||
| } | |||||
| else { | |||||
| polynors = MEM_mallocN(sizeof(float[3]) * mesh->totpoly, __func__); | |||||
| BKE_mesh_calc_normals_poly(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, | |||||
| polynors, false); | |||||
| free_polynors = true; | |||||
| } | |||||
| BKE_mesh_normals_loop_split( | |||||
| mesh->mvert, mesh->totvert, mesh->medge, mesh->totedge, | |||||
| mesh->mloop, r_loopnors, mesh->totloop, mesh->mpoly, (const float (*)[3])polynors, mesh->totpoly, | |||||
| (mesh->flag & ME_AUTOSMOOTH) != 0, mesh->smoothresh, NULL, clnors, NULL); | |||||
| if (free_polynors) { | |||||
| MEM_freeN(polynors); | |||||
| } | |||||
| } | |||||
| static void rna_Mesh_free_normals_split(Mesh *mesh) | static void rna_Mesh_free_normals_split(Mesh *mesh) | ||||
| { | { | ||||
| CustomData_free_layers(&mesh->ldata, CD_NORMAL, mesh->totloop); | CustomData_free_layers(&mesh->ldata, CD_NORMAL, mesh->totloop); | ||||
| } | } | ||||
| static void rna_Mesh_calc_tangents(Mesh *mesh, ReportList *reports, const char *uvmap) | static void rna_Mesh_calc_tangents(Mesh *mesh, ReportList *reports, const char *uvmap) | ||||
| { | { | ||||
| float (*r_looptangents)[4]; | float (*r_looptangents)[4]; | ||||
| if (CustomData_has_layer(&mesh->ldata, CD_MLOOPTANGENT)) { | if (CustomData_has_layer(&mesh->ldata, CD_MLOOPTANGENT)) { | ||||
| r_looptangents = CustomData_get_layer(&mesh->ldata, CD_MLOOPTANGENT); | r_looptangents = CustomData_get_layer(&mesh->ldata, CD_MLOOPTANGENT); | ||||
| memset(r_looptangents, 0, sizeof(float[4]) * mesh->totloop); | memset(r_looptangents, 0, sizeof(float[4]) * mesh->totloop); | ||||
| } | } | ||||
| else { | else { | ||||
| r_looptangents = CustomData_add_layer(&mesh->ldata, CD_MLOOPTANGENT, CD_CALLOC, NULL, mesh->totloop); | r_looptangents = CustomData_add_layer(&mesh->ldata, CD_MLOOPTANGENT, CD_CALLOC, NULL, mesh->totloop); | ||||
| CustomData_set_layer_flag(&mesh->ldata, CD_MLOOPTANGENT, CD_FLAG_TEMPORARY); | CustomData_set_layer_flag(&mesh->ldata, CD_MLOOPTANGENT, CD_FLAG_TEMPORARY); | ||||
| } | } | ||||
| /* Compute loop normals if needed. */ | /* Compute loop normals if needed. */ | ||||
| if (!CustomData_has_layer(&mesh->ldata, CD_NORMAL)) { | if (!CustomData_has_layer(&mesh->ldata, CD_NORMAL)) { | ||||
| rna_Mesh_calc_normals_split(mesh); | BKE_mesh_calc_normals_split(mesh); | ||||
| } | } | ||||
| BKE_mesh_loop_tangents(mesh, uvmap, r_looptangents, reports); | BKE_mesh_loop_tangents(mesh, uvmap, r_looptangents, reports); | ||||
| } | } | ||||
| static void rna_Mesh_free_tangents(Mesh *mesh) | static void rna_Mesh_free_tangents(Mesh *mesh) | ||||
| { | { | ||||
| CustomData_free_layers(&mesh->ldata, CD_MLOOPTANGENT, mesh->totloop); | CustomData_free_layers(&mesh->ldata, CD_MLOOPTANGENT, mesh->totloop); | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | void RNA_api_mesh(StructRNA *srna) | ||||
| RNA_def_boolean(func, "shape_keys", 0, "", "Transform Shape Keys"); | RNA_def_boolean(func, "shape_keys", 0, "", "Transform Shape Keys"); | ||||
| func = RNA_def_function(srna, "calc_normals", "BKE_mesh_calc_normals"); | func = RNA_def_function(srna, "calc_normals", "BKE_mesh_calc_normals"); | ||||
| RNA_def_function_ui_description(func, "Calculate vertex normals"); | RNA_def_function_ui_description(func, "Calculate vertex normals"); | ||||
| func = RNA_def_function(srna, "create_normals_split", "rna_Mesh_create_normals_split"); | func = RNA_def_function(srna, "create_normals_split", "rna_Mesh_create_normals_split"); | ||||
| RNA_def_function_ui_description(func, "Empty split vertex normals"); | RNA_def_function_ui_description(func, "Empty split vertex normals"); | ||||
| func = RNA_def_function(srna, "calc_normals_split", "rna_Mesh_calc_normals_split"); | func = RNA_def_function(srna, "calc_normals_split", "BKE_mesh_calc_normals_split"); | ||||
| RNA_def_function_ui_description(func, "Calculate split vertex normals, which preserve sharp edges"); | RNA_def_function_ui_description(func, "Calculate split vertex normals, which preserve sharp edges"); | ||||
| func = RNA_def_function(srna, "free_normals_split", "rna_Mesh_free_normals_split"); | func = RNA_def_function(srna, "free_normals_split", "rna_Mesh_free_normals_split"); | ||||
| RNA_def_function_ui_description(func, "Free split vertex normals"); | RNA_def_function_ui_description(func, "Free split vertex normals"); | ||||
| func = RNA_def_function(srna, "calc_tangents", "rna_Mesh_calc_tangents"); | func = RNA_def_function(srna, "calc_tangents", "rna_Mesh_calc_tangents"); | ||||
| RNA_def_function_flag(func, FUNC_USE_REPORTS); | RNA_def_function_flag(func, FUNC_USE_REPORTS); | ||||
| RNA_def_function_ui_description(func, | RNA_def_function_ui_description(func, | ||||
| ▲ Show 20 Lines • Show All 75 Lines • Show Last 20 Lines | |||||