Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh_convert.c
| Show First 20 Lines • Show All 586 Lines • ▼ Show 20 Lines | if (alluv) { | ||||
| me->mloopuv = CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_ASSIGN, alluv, me->totloop, uvname); | me->mloopuv = CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_ASSIGN, alluv, me->totloop, uvname); | ||||
| } | } | ||||
| BKE_mesh_calc_normals(me); | BKE_mesh_calc_normals(me); | ||||
| } | } | ||||
| else { | else { | ||||
| me = BKE_mesh_add(bmain, obdata_name); | me = BKE_mesh_add(bmain, obdata_name); | ||||
| ob->runtime.mesh_eval = NULL; | ob->runtime.mesh_eval = NULL; | ||||
| BKE_mesh_nomain_to_mesh(me_eval, me, ob, CD_MASK_MESH, false); | BKE_mesh_nomain_to_mesh(me_eval, me, ob, &CD_MASK_MESH, false); | ||||
| } | } | ||||
| me->totcol = cu->totcol; | me->totcol = cu->totcol; | ||||
| me->mat = cu->mat; | me->mat = cu->mat; | ||||
| /* Copy evaluated texture space from curve to mesh. | /* Copy evaluated texture space from curve to mesh. | ||||
| * | * | ||||
| * Note that we disable auto texture space feature since that will cause | * Note that we disable auto texture space feature since that will cause | ||||
| ▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | void BKE_mesh_to_curve_nurblist(const Mesh *me, ListBase *nurblist, const int edge_users_test) | ||||
| } | } | ||||
| } | } | ||||
| void BKE_mesh_to_curve(Main *bmain, Depsgraph *depsgraph, Scene *UNUSED(scene), Object *ob) | void BKE_mesh_to_curve(Main *bmain, Depsgraph *depsgraph, Scene *UNUSED(scene), Object *ob) | ||||
| { | { | ||||
| /* make new mesh data from the original copy */ | /* make new mesh data from the original copy */ | ||||
| Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); | Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); | ||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | ||||
| Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, CD_MASK_MESH); | Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_MESH); | ||||
| ListBase nurblist = {NULL, NULL}; | ListBase nurblist = {NULL, NULL}; | ||||
| BKE_mesh_to_curve_nurblist(me_eval, &nurblist, 0); | BKE_mesh_to_curve_nurblist(me_eval, &nurblist, 0); | ||||
| BKE_mesh_to_curve_nurblist(me_eval, &nurblist, 1); | BKE_mesh_to_curve_nurblist(me_eval, &nurblist, 1); | ||||
| if (nurblist.first) { | if (nurblist.first) { | ||||
| Curve *cu = BKE_curve_add(bmain, ob->id.name + 2, OB_CURVE); | Curve *cu = BKE_curve_add(bmain, ob->id.name + 2, OB_CURVE); | ||||
| cu->flag |= CU_3D; | cu->flag |= CU_3D; | ||||
| ▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | case OB_MESH: | ||||
| BKE_id_copy_ex(bmain, &mesh->id, (ID **)&tmpmesh, 0); | BKE_id_copy_ex(bmain, &mesh->id, (ID **)&tmpmesh, 0); | ||||
| /* XXX BKE_mesh_copy() already handles materials usercount. */ | /* XXX BKE_mesh_copy() already handles materials usercount. */ | ||||
| do_mat_id_data_us = false; | do_mat_id_data_us = false; | ||||
| } | } | ||||
| /* if not getting the original caged mesh, get final derived mesh */ | /* if not getting the original caged mesh, get final derived mesh */ | ||||
| else { | else { | ||||
| /* Make a dummy mesh, saves copying */ | /* Make a dummy mesh, saves copying */ | ||||
| Mesh *me_eval; | Mesh *me_eval; | ||||
| /* CustomDataMask mask = CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL; */ | CustomData_Masks mask = CD_MASK_MESH; /* this seems more suitable, exporter, | ||||
| CustomDataMask mask = CD_MASK_MESH; /* this seems more suitable, exporter, | |||||
| * for example, needs CD_MASK_MDEFORMVERT */ | * for example, needs CD_MASK_MDEFORMVERT */ | ||||
| if (calc_undeformed) | if (calc_undeformed) { | ||||
| mask |= CD_MASK_ORCO; | mask.vmask |= CD_MASK_ORCO; | ||||
| } | |||||
| if (render) { | if (render) { | ||||
| me_eval = mesh_create_eval_final_render(depsgraph, sce, ob, mask); | me_eval = mesh_create_eval_final_render(depsgraph, sce, ob, &mask); | ||||
| } | } | ||||
| else { | else { | ||||
| me_eval = mesh_create_eval_final_view(depsgraph, sce, ob, mask); | me_eval = mesh_create_eval_final_view(depsgraph, sce, ob, &mask); | ||||
| } | } | ||||
| tmpmesh = BKE_mesh_add(bmain, ((ID *)ob->data)->name + 2); | tmpmesh = BKE_mesh_add(bmain, ((ID *)ob->data)->name + 2); | ||||
| BKE_mesh_nomain_to_mesh(me_eval, tmpmesh, ob, mask, true); | BKE_mesh_nomain_to_mesh(me_eval, tmpmesh, ob, &mask, true); | ||||
| /* Copy autosmooth settings from original mesh. */ | /* Copy autosmooth settings from original mesh. */ | ||||
| Mesh *me = (Mesh *)ob->data; | Mesh *me = (Mesh *)ob->data; | ||||
| tmpmesh->flag |= (me->flag & ME_AUTOSMOOTH); | tmpmesh->flag |= (me->flag & ME_AUTOSMOOTH); | ||||
| tmpmesh->smoothresh = me->smoothresh; | tmpmesh->smoothresh = me->smoothresh; | ||||
| } | } | ||||
| /* BKE_mesh_add/copy gives us a user count we don't need */ | /* BKE_mesh_add/copy gives us a user count we don't need */ | ||||
| ▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | if (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__); | ||||
| CLOG_ERROR(&LOG, "lost a shapekey layer: '%s'! (bmesh internal error)", 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, const CustomData_Masks *mask, bool take_ownership) | |||||
| { | { | ||||
| /* mesh_src might depend on mesh_dst, so we need to do everything with a local copy */ | /* mesh_src might depend on mesh_dst, so we need to do everything with a local copy */ | ||||
| /* TODO(Sybren): the above claim came from DM_to_mesh(); check whether it is still true with Mesh */ | /* TODO(Sybren): the above claim came from DM_to_mesh(); check whether it is still true with Mesh */ | ||||
| Mesh tmp = *mesh_dst; | Mesh tmp = *mesh_dst; | ||||
| int totvert, totedge /*, totface */ /* UNUSED */, totloop, totpoly; | int totvert, totedge /*, totface */ /* UNUSED */, totloop, totpoly; | ||||
| int did_shapekeys = 0; | int did_shapekeys = 0; | ||||
| eCDAllocType alloctype = CD_DUPLICATE; | eCDAllocType alloctype = CD_DUPLICATE; | ||||
| Show All 17 Lines | void BKE_mesh_nomain_to_mesh( | ||||
| BKE_mesh_ensure_normals(mesh_src); | BKE_mesh_ensure_normals(mesh_src); | ||||
| totvert = tmp.totvert = mesh_src->totvert; | totvert = tmp.totvert = mesh_src->totvert; | ||||
| totedge = tmp.totedge = mesh_src->totedge; | totedge = tmp.totedge = mesh_src->totedge; | ||||
| totloop = tmp.totloop = mesh_src->totloop; | totloop = tmp.totloop = mesh_src->totloop; | ||||
| totpoly = tmp.totpoly = mesh_src->totpoly; | totpoly = tmp.totpoly = mesh_src->totpoly; | ||||
| tmp.totface = 0; | tmp.totface = 0; | ||||
| CustomData_copy(&mesh_src->vdata, &tmp.vdata, mask, alloctype, totvert); | CustomData_copy(&mesh_src->vdata, &tmp.vdata, mask->vmask, alloctype, totvert); | ||||
| CustomData_copy(&mesh_src->edata, &tmp.edata, mask, alloctype, totedge); | CustomData_copy(&mesh_src->edata, &tmp.edata, mask->emask, alloctype, totedge); | ||||
| CustomData_copy(&mesh_src->ldata, &tmp.ldata, mask, alloctype, totloop); | CustomData_copy(&mesh_src->ldata, &tmp.ldata, mask->lmask, alloctype, totloop); | ||||
| CustomData_copy(&mesh_src->pdata, &tmp.pdata, mask, alloctype, totpoly); | CustomData_copy(&mesh_src->pdata, &tmp.pdata, mask->pmask, alloctype, totpoly); | ||||
| tmp.cd_flag = mesh_src->cd_flag; | tmp.cd_flag = mesh_src->cd_flag; | ||||
| tmp.runtime.deformed_only = mesh_src->runtime.deformed_only; | tmp.runtime.deformed_only = mesh_src->runtime.deformed_only; | ||||
| if (CustomData_has_layer(&mesh_src->vdata, CD_SHAPEKEY)) { | if (CustomData_has_layer(&mesh_src->vdata, CD_SHAPEKEY)) { | ||||
| KeyBlock *kb; | KeyBlock *kb; | ||||
| int uid; | int uid; | ||||
| if (ob) { | if (ob) { | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | if (mesh_dst->bb) { | ||||
| tmp.bb = NULL; | tmp.bb = NULL; | ||||
| } | } | ||||
| /* skip the listbase */ | /* skip the listbase */ | ||||
| MEMCPY_STRUCT_OFS(mesh_dst, &tmp, id.prev); | MEMCPY_STRUCT_OFS(mesh_dst, &tmp, id.prev); | ||||
| if (take_ownership) { | if (take_ownership) { | ||||
| if (alloctype == CD_ASSIGN) { | if (alloctype == CD_ASSIGN) { | ||||
| CustomData_free_typemask(&mesh_src->vdata, mesh_src->totvert, ~mask); | CustomData_free_typemask(&mesh_src->vdata, mesh_src->totvert, ~mask->vmask); | ||||
| CustomData_free_typemask(&mesh_src->edata, mesh_src->totedge, ~mask); | CustomData_free_typemask(&mesh_src->edata, mesh_src->totedge, ~mask->emask); | ||||
| CustomData_free_typemask(&mesh_src->ldata, mesh_src->totloop, ~mask); | CustomData_free_typemask(&mesh_src->ldata, mesh_src->totloop, ~mask->lmask); | ||||
| CustomData_free_typemask(&mesh_src->pdata, mesh_src->totpoly, ~mask); | CustomData_free_typemask(&mesh_src->pdata, mesh_src->totpoly, ~mask->pmask); | ||||
| } | } | ||||
| BKE_id_free(NULL, mesh_src); | BKE_id_free(NULL, mesh_src); | ||||
| } | } | ||||
| } | } | ||||
| /* This is a Mesh-based copy of DM_to_meshkey() */ | /* This is a Mesh-based copy of DM_to_meshkey() */ | ||||
| void BKE_mesh_nomain_to_meshkey(Mesh *mesh_src, Mesh *mesh_dst, KeyBlock *kb) | void BKE_mesh_nomain_to_meshkey(Mesh *mesh_src, Mesh *mesh_dst, KeyBlock *kb) | ||||
| { | { | ||||
| Show All 19 Lines | |||||