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 | |||||
| MEM_SAFE_FREE(kb->data); | MEM_SAFE_FREE(kb->data); | ||||
| kb->data = MEM_malloc_arrayN((size_t)len, (size_t)key->elemsize, __func__); | kb->data = MEM_malloc_arrayN((size_t)len, (size_t)key->elemsize, __func__); | ||||
| kb->totelem = len; | kb->totelem = len; | ||||
| BKE_keyblock_update_from_mesh(me, kb); | BKE_keyblock_update_from_mesh(me, kb); | ||||
| } | } | ||||
| void BKE_keyblock_convert_to_mesh(KeyBlock *kb, Mesh *me) | void BKE_keyblock_convert_to_mesh(KeyBlock *kb, struct MVert *mvert, int totvert) | ||||
| { | { | ||||
| MVert *mvert; | |||||
| const float(*fp)[3]; | const float(*fp)[3]; | ||||
| int a, tot; | int a, tot; | ||||
| mvert = me->mvert; | |||||
| fp = kb->data; | fp = kb->data; | ||||
| tot = min_ii(kb->totelem, me->totvert); | tot = min_ii(kb->totelem, totvert); | ||||
| for (a = 0; a < tot; a++, fp++, mvert++) { | for (a = 0; a < tot; a++, fp++, mvert++) { | ||||
| copy_v3_v3(mvert->co, *fp); | copy_v3_v3(mvert->co, *fp); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_keyblock_mesh_calc_normals(struct KeyBlock *kb, | void BKE_keyblock_mesh_calc_normals_vertex(const KeyBlock *kb, | ||||
| struct Mesh *mesh, | const Mesh *mesh, | ||||
| float (*r_vertnors)[3], | float (*r_vert_normals)[3]) | ||||
| float (*r_polynors)[3], | { | ||||
| float (*r_loopnors)[3]) | MVert *mvert = MEM_dupallocN(mesh->mvert); | ||||
| { | BKE_keyblock_convert_to_mesh(kb, mesh->mvert, mesh->totvert); | ||||
| /* We use a temp, shallow copy of mesh to work. */ | float(*poly_normals)[3] = MEM_mallocN(sizeof(float[3]) * mesh->totpoly, __func__); | ||||
| Mesh me; | |||||
| bool free_polynors = false; | BKE_mesh_calc_normals_poly_and_vertex(mvert, | ||||
| mesh->totvert, | |||||
| if (r_vertnors == NULL && r_polynors == NULL && r_loopnors == NULL) { | mesh->mloop, | ||||
| return; | mesh->totloop, | ||||
| } | mesh->mpoly, | ||||
| mesh->totpoly, | |||||
| me = *mesh; | poly_normals, | ||||
| me.mvert = MEM_dupallocN(mesh->mvert); | r_vert_normals); | ||||
| CustomData_reset(&me.vdata); | |||||
| CustomData_reset(&me.edata); | MEM_freeN(poly_normals); | ||||
| CustomData_reset(&me.pdata); | MEM_freeN(mvert); | ||||
| CustomData_reset(&me.ldata); | } | ||||
| CustomData_reset(&me.fdata); | |||||
| void BKE_keyblock_mesh_calc_normals_poly(const KeyBlock *kb, | |||||
| BKE_keyblock_convert_to_mesh(kb, &me); | const Mesh *mesh, | ||||
| float (*r_poly_normals)[3]) | |||||
| if (r_polynors == NULL && r_loopnors != NULL) { | { | ||||
| r_polynors = MEM_mallocN(sizeof(float[3]) * me.totpoly, __func__); | MVert *mvert = MEM_dupallocN(mesh->mvert); | ||||
| free_polynors = true; | BKE_keyblock_convert_to_mesh(kb, mesh->mvert, mesh->totvert); | ||||
| } | |||||
| BKE_mesh_calc_normals_poly(mvert, | |||||
| const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh); | mesh->totvert, | ||||
| if (r_vertnors) { | mesh->mloop, | ||||
| memcpy(r_vertnors, vert_normals, sizeof(float[3]) * me.totvert); | mesh->totloop, | ||||
| } | mesh->mpoly, | ||||
| mesh->totpoly, | |||||
| const float(*face_normals)[3] = BKE_mesh_poly_normals_ensure(mesh); | r_poly_normals); | ||||
| memcpy(r_polynors, face_normals, sizeof(float[3]) * me.totpoly); | |||||
| MEM_freeN(mvert); | |||||
| if (r_loopnors) { | } | ||||
| short(*clnors)[2] = CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); /* May be NULL. */ | |||||
| void BKE_keyblock_mesh_calc_normals_split(const KeyBlock *kb, | |||||
| BKE_mesh_normals_loop_split(me.mvert, | const Mesh *mesh, | ||||
| vert_normals, | float (*r_split_normals)[3]) | ||||
| me.totvert, | { | ||||
| me.medge, | MVert *mvert = MEM_dupallocN(mesh->mvert); | ||||
| me.totedge, | BKE_keyblock_convert_to_mesh(kb, mesh->mvert, mesh->totvert); | ||||
| me.mloop, | float(*vert_normals)[3] = MEM_mallocN(sizeof(float[3]) * mesh->totvert, __func__); | ||||
| r_loopnors, | float(*poly_normals)[3] = MEM_mallocN(sizeof(float[3]) * mesh->totpoly, __func__); | ||||
| me.totloop, | |||||
| me.mpoly, | BKE_mesh_calc_normals_poly_and_vertex(mvert, | ||||
| face_normals, | mesh->totvert, | ||||
| me.totpoly, | mesh->mloop, | ||||
| (me.flag & ME_AUTOSMOOTH) != 0, | mesh->totloop, | ||||
| me.smoothresh, | mesh->mpoly, | ||||
| NULL, | mesh->totpoly, | ||||
| clnors, | poly_normals, | ||||
| NULL); | vert_normals); | ||||
| } | BKE_mesh_normals_loop_split(mesh->mvert, | ||||
| vert_normals, | |||||
| CustomData_free(&me.vdata, me.totvert); | mesh->totvert, | ||||
| CustomData_free(&me.edata, me.totedge); | mesh->medge, | ||||
| CustomData_free(&me.pdata, me.totpoly); | mesh->totedge, | ||||
| CustomData_free(&me.ldata, me.totloop); | mesh->mloop, | ||||
| CustomData_free(&me.fdata, me.totface); | r_split_normals, | ||||
| MEM_freeN(me.mvert); | mesh->totloop, | ||||
| mesh->mpoly, | |||||
| if (free_polynors) { | poly_normals, | ||||
| MEM_freeN(r_polynors); | mesh->totpoly, | ||||
| } | (mesh->flag & ME_AUTOSMOOTH) != 0, | ||||
| mesh->smoothresh, | |||||
| NULL, | |||||
| CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL), | |||||
| NULL); | |||||
| MEM_freeN(mvert); | |||||
| MEM_freeN(vert_normals); | |||||
| MEM_freeN(poly_normals); | |||||
| } | } | ||||
| /************************* 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 | |||||