Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/key.c
| Show First 20 Lines • Show All 992 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| void BKE_keyblock_mesh_calc_normals(struct KeyBlock *kb, | void BKE_keyblock_mesh_calc_normals(struct KeyBlock *kb, | ||||
| struct Mesh *mesh, | struct Mesh *mesh, | ||||
| float (*r_vertnors)[3], | float (*r_vertnors)[3], | ||||
| float (*r_polynors)[3], | float (*r_polynors)[3], | ||||
| float (*r_loopnors)[3]) | float (*r_loopnors)[3]) | ||||
| { | { | ||||
| /* We use a temp, shallow copy of mesh to work. */ | |||||
| Mesh me; | |||||
| bool free_polynors = false; | |||||
| if (r_vertnors == NULL && r_polynors == NULL && r_loopnors == NULL) { | if (r_vertnors == NULL && r_polynors == NULL && r_loopnors == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| me = *mesh; | Mesh *local_mesh = BKE_mesh_copy_for_eval(mesh, true); | ||||
| me.mvert = MEM_dupallocN(mesh->mvert); | local_mesh->mvert = CustomData_duplicate_referenced_layer( | ||||
| CustomData_reset(&me.vdata); | &local_mesh->vdata, CD_MVERT, local_mesh->totvert); | ||||
| CustomData_reset(&me.edata); | BKE_keyblock_convert_to_mesh(kb, local_mesh); | ||||
| CustomData_reset(&me.pdata); | |||||
| CustomData_reset(&me.ldata); | |||||
| CustomData_reset(&me.fdata); | |||||
| BKE_keyblock_convert_to_mesh(kb, &me); | |||||
| if (r_polynors == NULL && r_loopnors != NULL) { | |||||
| r_polynors = MEM_mallocN(sizeof(float[3]) * me.totpoly, __func__); | |||||
| free_polynors = true; | |||||
| } | |||||
| const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh); | |||||
| if (r_vertnors) { | if (r_vertnors) { | ||||
| memcpy(r_vertnors, vert_normals, sizeof(float[3]) * me.totvert); | memcpy(r_vertnors, BKE_mesh_vertex_normals_ensure(mesh), sizeof(float[3]) * mesh->totvert); | ||||
| } | } | ||||
| const float(*face_normals)[3] = BKE_mesh_poly_normals_ensure(mesh); | if (r_polynors) { | ||||
| memcpy(r_polynors, face_normals, sizeof(float[3]) * me.totpoly); | memcpy(r_polynors, BKE_mesh_poly_normals_ensure(mesh), sizeof(float[3]) * mesh->totpoly); | ||||
| } | |||||
| if (r_loopnors) { | if (r_loopnors) { | ||||
| short(*clnors)[2] = CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); /* May be NULL. */ | short(*clnors)[2] = CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); /* May be NULL. */ | ||||
| BKE_mesh_normals_loop_split(me.mvert, | BKE_mesh_normals_loop_split(local_mesh->mvert, | ||||
| vert_normals, | BKE_mesh_vertex_normals_ensure(mesh), | ||||
| me.totvert, | local_mesh->totvert, | ||||
| me.medge, | local_mesh->medge, | ||||
| me.totedge, | local_mesh->totedge, | ||||
| me.mloop, | local_mesh->mloop, | ||||
| r_loopnors, | r_loopnors, | ||||
| me.totloop, | local_mesh->totloop, | ||||
| me.mpoly, | local_mesh->mpoly, | ||||
| face_normals, | BKE_mesh_poly_normals_ensure(mesh), | ||||
| me.totpoly, | local_mesh->totpoly, | ||||
| (me.flag & ME_AUTOSMOOTH) != 0, | (local_mesh->flag & ME_AUTOSMOOTH) != 0, | ||||
| me.smoothresh, | local_mesh->smoothresh, | ||||
| NULL, | NULL, | ||||
| clnors, | clnors, | ||||
| NULL); | NULL); | ||||
| } | } | ||||
| CustomData_free(&me.vdata, me.totvert); | BKE_id_free(NULL, local_mesh); | ||||
| CustomData_free(&me.edata, me.totedge); | |||||
| CustomData_free(&me.pdata, me.totpoly); | |||||
| CustomData_free(&me.ldata, me.totloop); | |||||
| CustomData_free(&me.fdata, me.totface); | |||||
| MEM_freeN(me.mvert); | |||||
| if (free_polynors) { | |||||
| MEM_freeN(r_polynors); | |||||
| } | |||||
| } | } | ||||
| /************************* raw coords ************************/ | /************************* raw coords ************************/ | ||||
| void BKE_keyblock_update_from_vertcos(Object *ob, KeyBlock *kb, const float (*vertCos)[3]) | void BKE_keyblock_update_from_vertcos(Object *ob, KeyBlock *kb, const float (*vertCos)[3]) | ||||
| { | { | ||||
| const float(*co)[3] = vertCos; | const float(*co)[3] = vertCos; | ||||
| float *fp = kb->data; | float *fp = kb->data; | ||||
| ▲ Show 20 Lines • Show All 280 Lines • Show Last 20 Lines | |||||