Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh_convert.c
| Show First 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | for (i = 0, mp = mpoly; i < totpoly; i++, mp++) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| BLI_edgehash_free(eh, NULL); | BLI_edgehash_free(eh, NULL); | ||||
| } | } | ||||
| /* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */ | /* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */ | ||||
| /* return non-zero on error */ | |||||
| int BKE_mesh_nurbs_to_mdata(Object *ob, | |||||
| MVert **r_allvert, | |||||
| int *r_totvert, | |||||
| MEdge **r_alledge, | |||||
| int *r_totedge, | |||||
| MLoop **r_allloop, | |||||
| MPoly **r_allpoly, | |||||
| int *r_totloop, | |||||
| int *r_totpoly) | |||||
| { | |||||
| ListBase disp = {NULL, NULL}; | |||||
| if (ob->runtime.curve_cache) { | |||||
| disp = ob->runtime.curve_cache->disp; | |||||
| } | |||||
| return BKE_mesh_nurbs_displist_to_mdata(ob, | |||||
| &disp, | |||||
| r_allvert, | |||||
| r_totvert, | |||||
| r_alledge, | |||||
| r_totedge, | |||||
| r_allloop, | |||||
| r_allpoly, | |||||
| NULL, | |||||
| r_totloop, | |||||
| r_totpoly); | |||||
| } | |||||
| /* BMESH: this doesn't calculate all edges from polygons, | |||||
| * only free standing edges are calculated */ | |||||
| /* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */ | |||||
| /* use specified dispbase */ | /* use specified dispbase */ | ||||
| int BKE_mesh_nurbs_displist_to_mdata(const Object *ob, | static int mesh_nurbs_displist_to_mdata(const Curve *cu, | ||||
| const ListBase *dispbase, | const ListBase *dispbase, | ||||
| MVert **r_allvert, | MVert **r_allvert, | ||||
| int *r_totvert, | int *r_totvert, | ||||
| MEdge **r_alledge, | MEdge **r_alledge, | ||||
| int *r_totedge, | int *r_totedge, | ||||
| MLoop **r_allloop, | MLoop **r_allloop, | ||||
| MPoly **r_allpoly, | MPoly **r_allpoly, | ||||
| MLoopUV **r_alluv, | MLoopUV **r_alluv, | ||||
| int *r_totloop, | int *r_totloop, | ||||
| int *r_totpoly) | int *r_totpoly) | ||||
| { | { | ||||
| const Curve *cu = ob->data; | |||||
| MVert *mvert; | MVert *mvert; | ||||
| MPoly *mpoly; | MPoly *mpoly; | ||||
| MLoop *mloop; | MLoop *mloop; | ||||
| MLoopUV *mloopuv = NULL; | MLoopUV *mloopuv = NULL; | ||||
| MEdge *medge; | MEdge *medge; | ||||
| const float *data; | const float *data; | ||||
| int a, b, ofs, vertcount, startvert, totvert = 0, totedge = 0, totloop = 0, totpoly = 0; | int a, b, ofs, vertcount, startvert, totvert = 0, totedge = 0, totloop = 0, totpoly = 0; | ||||
| int p1, p2, p3, p4, *index; | int p1, p2, p3, p4, *index; | ||||
| const bool conv_polys = ( | const bool conv_polys = ( | ||||
| /* 2d polys are filled with DL_INDEX3 displists */ | /* 2d polys are filled with DL_INDEX3 displists */ | ||||
| (CU_DO_2DFILL(cu) == false) || | (CU_DO_2DFILL(cu) == false) || | ||||
| /* surf polys are never filled */ | /* surf polys are never filled */ | ||||
| (ob->type == OB_SURF)); | BKE_curve_type_get(cu) == OB_SURF); | ||||
| /* count */ | /* count */ | ||||
| LISTBASE_FOREACH (const DispList *, dl, dispbase) { | LISTBASE_FOREACH (const DispList *, dl, dispbase) { | ||||
| if (dl->type == DL_SEGM) { | if (dl->type == DL_SEGM) { | ||||
| totvert += dl->parts * dl->nr; | totvert += dl->parts * dl->nr; | ||||
| totedge += dl->parts * (dl->nr - 1); | totedge += dl->parts * (dl->nr - 1); | ||||
| } | } | ||||
| else if (dl->type == DL_POLY) { | else if (dl->type == DL_POLY) { | ||||
| ▲ Show 20 Lines • Show All 238 Lines • ▼ Show 20 Lines | Mesh *BKE_mesh_new_nomain_from_curve_displist(const Object *ob, const ListBase *dispbase) | ||||
| Mesh *mesh; | Mesh *mesh; | ||||
| MVert *allvert; | MVert *allvert; | ||||
| MEdge *alledge; | MEdge *alledge; | ||||
| MLoop *allloop; | MLoop *allloop; | ||||
| MPoly *allpoly; | MPoly *allpoly; | ||||
| MLoopUV *alluv = NULL; | MLoopUV *alluv = NULL; | ||||
| int totvert, totedge, totloop, totpoly; | int totvert, totedge, totloop, totpoly; | ||||
| if (BKE_mesh_nurbs_displist_to_mdata(ob, | if (mesh_nurbs_displist_to_mdata(ob->data, | ||||
| dispbase, | dispbase, | ||||
| &allvert, | &allvert, | ||||
| &totvert, | &totvert, | ||||
| &alledge, | &alledge, | ||||
| &totedge, | &totedge, | ||||
| &allloop, | &allloop, | ||||
| &allpoly, | &allpoly, | ||||
| &alluv, | &alluv, | ||||
| &totloop, | &totloop, | ||||
| &totpoly) != 0) { | &totpoly) != 0) { | ||||
| /* Error initializing mdata. This often happens when curve is empty */ | /* Error initializing mdata. This often happens when curve is empty */ | ||||
| return BKE_mesh_new_nomain(0, 0, 0, 0, 0); | return BKE_mesh_new_nomain(0, 0, 0, 0, 0); | ||||
| } | } | ||||
| mesh = BKE_mesh_new_nomain(totvert, totedge, 0, totloop, totpoly); | mesh = BKE_mesh_new_nomain(totvert, totedge, 0, totloop, totpoly); | ||||
| mesh->runtime.cd_dirty_vert |= CD_MASK_NORMAL; | mesh->runtime.cd_dirty_vert |= CD_MASK_NORMAL; | ||||
| if (totvert != 0) { | if (totvert != 0) { | ||||
| Show All 17 Lines | Mesh *BKE_mesh_new_nomain_from_curve_displist(const Object *ob, const ListBase *dispbase) | ||||
| MEM_freeN(allvert); | MEM_freeN(allvert); | ||||
| MEM_freeN(alledge); | MEM_freeN(alledge); | ||||
| MEM_freeN(allloop); | MEM_freeN(allloop); | ||||
| MEM_freeN(allpoly); | MEM_freeN(allpoly); | ||||
| return mesh; | return mesh; | ||||
| } | } | ||||
| Mesh *BKE_mesh_new_nomain_from_curve(Object *ob) | Mesh *BKE_mesh_new_nomain_from_curve(const Object *ob) | ||||
| { | { | ||||
| ListBase disp = {NULL, NULL}; | ListBase disp = {NULL, NULL}; | ||||
| if (ob->runtime.curve_cache) { | if (ob->runtime.curve_cache) { | ||||
| disp = ob->runtime.curve_cache->disp; | disp = ob->runtime.curve_cache->disp; | ||||
| } | } | ||||
| return BKE_mesh_new_nomain_from_curve_displist(ob, &disp); | return BKE_mesh_new_nomain_from_curve_displist(ob, &disp); | ||||
| } | } | ||||
| /* this may fail replacing ob->data, be sure to check ob->type */ | /* this may fail replacing ob->data, be sure to check ob->type */ | ||||
| void BKE_mesh_from_nurbs_displist( | void BKE_mesh_from_nurbs_displist( | ||||
| Main *bmain, Object *ob, ListBase *dispbase, const char *obdata_name, bool temporary) | Main *bmain, Object *ob, ListBase *dispbase, const char *obdata_name, bool temporary) | ||||
| { | { | ||||
| Object *ob1; | Object *ob1; | ||||
| Mesh *me_eval = (Mesh *)ob->runtime.data_eval; | Mesh *me_eval = (Mesh *)ob->runtime.data_eval; | ||||
| Mesh *me; | Mesh *me; | ||||
| Curve *cu; | |||||
| MVert *allvert = NULL; | MVert *allvert = NULL; | ||||
| MEdge *alledge = NULL; | MEdge *alledge = NULL; | ||||
| MLoop *allloop = NULL; | MLoop *allloop = NULL; | ||||
| MLoopUV *alluv = NULL; | MLoopUV *alluv = NULL; | ||||
| MPoly *allpoly = NULL; | MPoly *allpoly = NULL; | ||||
| int totvert, totedge, totloop, totpoly; | int totvert, totedge, totloop, totpoly; | ||||
| cu = ob->data; | Curve *cu = ob->data; | ||||
| if (me_eval == NULL) { | if (me_eval == NULL) { | ||||
| if (BKE_mesh_nurbs_displist_to_mdata(ob, | if (mesh_nurbs_displist_to_mdata(cu, | ||||
| dispbase, | dispbase, | ||||
| &allvert, | &allvert, | ||||
| &totvert, | &totvert, | ||||
| &alledge, | &alledge, | ||||
| &totedge, | &totedge, | ||||
| &allloop, | &allloop, | ||||
| &allpoly, | &allpoly, | ||||
| &alluv, | &alluv, | ||||
| &totloop, | &totloop, | ||||
| &totpoly) != 0) { | &totpoly) != 0) { | ||||
| /* Error initializing */ | /* Error initializing */ | ||||
| return; | return; | ||||
| } | } | ||||
| /* make mesh */ | /* make mesh */ | ||||
| if (bmain != NULL) { | if (bmain != NULL) { | ||||
| me = BKE_mesh_add(bmain, obdata_name); | me = BKE_mesh_add(bmain, obdata_name); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | if (temporary) { | ||||
| * problematic for renderers exporting data. */ | * problematic for renderers exporting data. */ | ||||
| BKE_id_free(NULL, cu); | BKE_id_free(NULL, cu); | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_id_free_us(bmain, cu); | BKE_id_free_us(bmain, cu); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_mesh_from_nurbs(Main *bmain, Object *ob) | |||||
| { | |||||
| Curve *cu = (Curve *)ob->data; | |||||
| ListBase disp = {NULL, NULL}; | |||||
| if (ob->runtime.curve_cache) { | |||||
| disp = ob->runtime.curve_cache->disp; | |||||
| } | |||||
| BKE_mesh_from_nurbs_displist(bmain, ob, &disp, cu->id.name, false); | |||||
| } | |||||
| typedef struct EdgeLink { | typedef struct EdgeLink { | ||||
| struct EdgeLink *next, *prev; | struct EdgeLink *next, *prev; | ||||
| void *edge; | void *edge; | ||||
| } EdgeLink; | } EdgeLink; | ||||
| typedef struct VertLink { | typedef struct VertLink { | ||||
| Link *next, *prev; | Link *next, *prev; | ||||
| uint index; | uint index; | ||||
| ▲ Show 20 Lines • Show All 422 Lines • ▼ Show 20 Lines | static Mesh *mesh_new_from_curve_type_object(Object *object) | ||||
| /* Reset pointers before conversion. */ | /* Reset pointers before conversion. */ | ||||
| temp_curve->editfont = NULL; | temp_curve->editfont = NULL; | ||||
| temp_curve->editnurb = NULL; | temp_curve->editnurb = NULL; | ||||
| /* Convert to mesh. */ | /* Convert to mesh. */ | ||||
| BKE_mesh_from_nurbs_displist( | BKE_mesh_from_nurbs_displist( | ||||
| NULL, temp_object, &temp_object->runtime.curve_cache->disp, curve->id.name + 2, true); | NULL, temp_object, &temp_object->runtime.curve_cache->disp, curve->id.name + 2, true); | ||||
| /* BKE_mesh_from_nurbs changes the type to a mesh, check it worked. If it didn't the curve did | /* BKE_mesh_from_nurbs_displist changes the type to a mesh, check it worked. If it didn't | ||||
| * not have any segments or otherwise would have generated an empty mesh. */ | * the curve did not have any segments or otherwise would have generated an empty mesh. */ | ||||
| if (temp_object->type != OB_MESH) { | if (temp_object->type != OB_MESH) { | ||||
| BKE_id_free(NULL, temp_object->data); | BKE_id_free(NULL, temp_object->data); | ||||
| BKE_id_free(NULL, temp_object); | BKE_id_free(NULL, temp_object); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| Mesh *mesh_result = temp_object->data; | Mesh *mesh_result = temp_object->data; | ||||
| ▲ Show 20 Lines • Show All 587 Lines • Show Last 20 Lines | |||||