Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh_convert.c
| Show All 16 Lines | |||||
| * | * | ||||
| * ***** END GPL LICENSE BLOCK ***** | * ***** END GPL LICENSE BLOCK ***** | ||||
| */ | */ | ||||
| /** \file blender/blenkernel/intern/mesh_convert.c | /** \file blender/blenkernel/intern/mesh_convert.c | ||||
| * \ingroup bke | * \ingroup bke | ||||
| */ | */ | ||||
| #include "CLG_log.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_key_types.h" | #include "DNA_key_types.h" | ||||
| #include "DNA_material_types.h" | #include "DNA_material_types.h" | ||||
| #include "DNA_meta_types.h" | #include "DNA_meta_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| Show All 29 Lines | |||||
| // #undef VALIDATE_MESH | // #undef VALIDATE_MESH | ||||
| #ifdef VALIDATE_MESH | #ifdef VALIDATE_MESH | ||||
| # define ASSERT_IS_VALID_MESH(mesh) (BLI_assert((mesh == NULL) || (BKE_mesh_is_valid(mesh) == true))) | # define ASSERT_IS_VALID_MESH(mesh) (BLI_assert((mesh == NULL) || (BKE_mesh_is_valid(mesh) == true))) | ||||
| #else | #else | ||||
| # define ASSERT_IS_VALID_MESH(mesh) | # define ASSERT_IS_VALID_MESH(mesh) | ||||
| #endif | #endif | ||||
| static CLG_LogRef LOG = {"bke.mesh_convert"}; | |||||
| void BKE_mesh_from_metaball(ListBase *lb, Mesh *me) | void BKE_mesh_from_metaball(ListBase *lb, Mesh *me) | ||||
| { | { | ||||
| DispList *dl; | DispList *dl; | ||||
| MVert *mvert; | MVert *mvert; | ||||
| MLoop *mloop, *allloop; | MLoop *mloop, *allloop; | ||||
| MPoly *mpoly; | MPoly *mpoly; | ||||
| const float *nors, *verts; | const float *nors, *verts; | ||||
| int a, *index; | int a, *index; | ||||
| ▲ Show 20 Lines • Show All 1,005 Lines • ▼ Show 20 Lines | static void add_shapekey_layers(Mesh *mesh_dest, Mesh *mesh_src) | ||||
| Key *key = mesh_src->key; | Key *key = mesh_src->key; | ||||
| int i; | int i; | ||||
| if (!mesh_src->key) | if (!mesh_src->key) | ||||
| return; | return; | ||||
| /* ensure we can use mesh vertex count for derived mesh custom data */ | /* ensure we can use mesh vertex count for derived mesh custom data */ | ||||
| if (mesh_src->totvert != mesh_dest->totvert) { | if (mesh_src->totvert != mesh_dest->totvert) { | ||||
| fprintf(stderr, | CLOG_ERROR(&LOG, "vertex size mismatch (mesh/dm) '%s' (%d != %d)", | ||||
| "%s: vertex size mismatch (mesh/dm) '%s' (%d != %d)\n", | mesh_src->id.name + 2, mesh_src->totvert, mesh_dest->totvert); | ||||
| __func__, mesh_src->id.name + 2, mesh_src->totvert, mesh_dest->totvert); | |||||
| return; | return; | ||||
| } | } | ||||
| for (i = 0, kb = key->block.first; kb; kb = kb->next, i++) { | for (i = 0, kb = key->block.first; kb; kb = kb->next, i++) { | ||||
| int ci; | int ci; | ||||
| float *array; | float *array; | ||||
| if (mesh_src->totvert != kb->totelem) { | if (mesh_src->totvert != kb->totelem) { | ||||
| fprintf(stderr, | CLOG_ERROR(&LOG, "vertex size mismatch (Mesh '%s':%d != KeyBlock '%s':%d)", | ||||
| "%s: vertex size mismatch (Mesh '%s':%d != KeyBlock '%s':%d)\n", | mesh_src->id.name + 2, mesh_src->totvert, kb->name, kb->totelem); | ||||
| __func__, mesh_src->id.name + 2, mesh_src->totvert, kb->name, kb->totelem); | |||||
| array = MEM_calloc_arrayN((size_t)mesh_src->totvert, 3 * sizeof(float), __func__); | array = MEM_calloc_arrayN((size_t)mesh_src->totvert, 3 * sizeof(float), __func__); | ||||
| } | } | ||||
| else { | else { | ||||
| array = MEM_malloc_arrayN((size_t)mesh_src->totvert, 3 * sizeof(float), __func__); | array = MEM_malloc_arrayN((size_t)mesh_src->totvert, 3 * sizeof(float), __func__); | ||||
| memcpy(array, kb->data, (size_t)mesh_src->totvert * 3 * sizeof(float)); | memcpy(array, kb->data, (size_t)mesh_src->totvert * 3 * sizeof(float)); | ||||
| } | } | ||||
| CustomData_add_layer_named(&mesh_dest->vdata, CD_SHAPEKEY, CD_ASSIGN, array, mesh_dest->totvert, kb->name); | CustomData_add_layer_named(&mesh_dest->vdata, CD_SHAPEKEY, CD_ASSIGN, array, mesh_dest->totvert, kb->name); | ||||
| ▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | static void shapekey_layers_to_keyblocks(Mesh *mesh_src, Mesh *mesh_dst, int actshape_uid) | ||||
| for (kb = mesh_dst->key->block.first; kb; kb = kb->next) { | for (kb = mesh_dst->key->block.first; kb; kb = kb->next) { | ||||
| if (kb->totelem != mesh_src->totvert) { | if (kb->totelem != mesh_src->totvert) { | ||||
| if (kb->data) | if (kb->data) | ||||
| MEM_freeN(kb->data); | MEM_freeN(kb->data); | ||||
| kb->totelem = mesh_src->totvert; | kb->totelem = mesh_src->totvert; | ||||
| kb->data = MEM_calloc_arrayN(kb->totelem, 3 * sizeof(float), __func__); | kb->data = MEM_calloc_arrayN(kb->totelem, 3 * sizeof(float), __func__); | ||||
| fprintf(stderr, "%s: lost a shapekey layer: '%s'! (bmesh internal error)\n", __func__, kb->name); | CLOG_ERROR(&LOG, "lost a shapekey layer: '%s'! (bmesh internal error)", kb->name); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* This is a Mesh-based copy of DM_to_mesh() */ | /* This is a Mesh-based copy of DM_to_mesh() */ | ||||
| void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, CustomDataMask mask, bool take_ownership) | void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, CustomDataMask mask, bool take_ownership) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (CustomData_has_layer(&mesh_src->vdata, CD_SHAPEKEY)) { | ||||
| int uid; | int uid; | ||||
| if (ob) { | if (ob) { | ||||
| kb = BLI_findlink(&mesh_dst->key->block, ob->shapenr - 1); | kb = BLI_findlink(&mesh_dst->key->block, ob->shapenr - 1); | ||||
| if (kb) { | if (kb) { | ||||
| uid = kb->uid; | uid = kb->uid; | ||||
| } | } | ||||
| else { | else { | ||||
| printf("%s: error - could not find active shapekey %d!\n", | CLOG_ERROR(&LOG, "could not find active shapekey %d!", ob->shapenr - 1); | ||||
| __func__, ob->shapenr - 1); | |||||
| uid = INT_MAX; | uid = INT_MAX; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* if no object, set to INT_MAX so we don't mess up any shapekey layers */ | /* if no object, set to INT_MAX so we don't mess up any shapekey layers */ | ||||
| uid = INT_MAX; | uid = INT_MAX; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, CustomDataMask mask, bool take_ownership) | ||||
| CustomData_free(&mesh_dst->fdata, mesh_dst->totface); | CustomData_free(&mesh_dst->fdata, mesh_dst->totface); | ||||
| CustomData_free(&mesh_dst->ldata, mesh_dst->totloop); | CustomData_free(&mesh_dst->ldata, mesh_dst->totloop); | ||||
| CustomData_free(&mesh_dst->pdata, mesh_dst->totpoly); | CustomData_free(&mesh_dst->pdata, mesh_dst->totpoly); | ||||
| /* ok, this should now use new CD shapekey data, | /* ok, this should now use new CD shapekey data, | ||||
| * which should be fed through the modifier | * which should be fed through the modifier | ||||
| * stack */ | * stack */ | ||||
| if (tmp.totvert != mesh_dst->totvert && !did_shapekeys && mesh_dst->key) { | if (tmp.totvert != mesh_dst->totvert && !did_shapekeys && mesh_dst->key) { | ||||
| printf("%s: YEEK! this should be recoded! Shape key loss!: ID '%s'\n", __func__, tmp.id.name); | CLOG_ERROR(&LOG, "YEEK! this should be recoded! Shape key loss!: ID '%s'", tmp.id.name); | ||||
| if (tmp.key && !(tmp.id.tag & LIB_TAG_NO_MAIN)) { | if (tmp.key && !(tmp.id.tag & LIB_TAG_NO_MAIN)) { | ||||
| id_us_min(&tmp.key->id); | id_us_min(&tmp.key->id); | ||||
| } | } | ||||
| tmp.key = NULL; | tmp.key = NULL; | ||||
| } | } | ||||
| /* Clear selection history */ | /* Clear selection history */ | ||||
| MEM_SAFE_FREE(tmp.mselect); | MEM_SAFE_FREE(tmp.mselect); | ||||
| ▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines | |||||