static void curve_to_filledpoly(Curve *cu, ListBase *UNUSED(nurb), ListBase *dispbase) { if(cu->flag & CU_3D) return; if(dispbase->first && ((DispList*) dispbase->first)->type==DL_SURF) { bevels_to_filledpoly(cu, dispbase); } else { filldisplist(dispbase, dispbase, 0); } }
static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase) { ListBase front, back; DispList *dl, *dlnew; float *fp, *fp1; int a, dpoly; front.first= front.last= back.first= back.last= NULL; dl= dispbase->first; while(dl) { if(dl->type==DL_SURF) { if( (dl->flag & DL_CYCL_V) && (dl->flag & DL_CYCL_U)==0 ) { if( (cu->flag & CU_BACK) && (dl->flag & DL_BACK_CURVE) ) { dlnew= MEM_callocN(sizeof(DispList), "filldisp"); BLI_addtail(&front, dlnew); dlnew->verts= fp1= MEM_mallocN(sizeof(float)*3*dl->parts, "filldisp1"); dlnew->nr= dl->parts; dlnew->parts= 1; dlnew->type= DL_POLY; dlnew->col= dl->col; dlnew->charidx = dl->charidx; fp= dl->verts; dpoly= 3*dl->nr; a= dl->parts; while(a--) { VECCOPY(fp1, fp); fp1+= 3; fp+= dpoly; } } if( (cu->flag & CU_FRONT) && (dl->flag & DL_FRONT_CURVE) ) { dlnew= MEM_callocN(sizeof(DispList), "filldisp"); BLI_addtail(&back, dlnew); dlnew->verts= fp1= MEM_mallocN(sizeof(float)*3*dl->parts, "filldisp1"); dlnew->nr= dl->parts; dlnew->parts= 1; dlnew->type= DL_POLY; dlnew->col= dl->col; dlnew->charidx= dl->charidx; fp= dl->verts+3*(dl->nr-1); dpoly= 3*dl->nr; a= dl->parts; while(a--) { VECCOPY(fp1, fp); fp1+= 3; fp+= dpoly; } } } } dl= dl->next; } filldisplist(&front, dispbase, 1); filldisplist(&back, dispbase, 0); freedisplist(&front); freedisplist(&back); filldisplist(dispbase, dispbase, 0); }
/* PolyFill function, uses Blenders scanfill to fill multiple poly lines */ static PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * polyLineSeq ) { PyObject *tri_list; /*return this list of tri's */ PyObject *polyLine, *polyVec; int i, len_polylines, len_polypoints, ls_error = 0; /* display listbase */ ListBase dispbase={NULL, NULL}; DispList *dl; float *fp; /*pointer to the array of malloced dl->verts to set the points from the vectors */ int index, *dl_face, totpoints=0; dispbase.first= dispbase.last= NULL; if(!PySequence_Check(polyLineSeq)) { PyErr_SetString( PyExc_TypeError, "expected a sequence of poly lines" ); return NULL; } len_polylines = PySequence_Size( polyLineSeq ); for( i = 0; i < len_polylines; ++i ) { polyLine= PySequence_GetItem( polyLineSeq, i ); if (!PySequence_Check(polyLine)) { freedisplist(&dispbase); Py_XDECREF(polyLine); /* may be null so use Py_XDECREF*/ PyErr_SetString( PyExc_TypeError, "One or more of the polylines is not a sequence of Mathutils.Vector's" ); return NULL; } len_polypoints= PySequence_Size( polyLine ); if (len_polypoints>0) { /* dont bother adding edges as polylines */ #if 0 if (EXPP_check_sequence_consistency( polyLine, &vector_Type ) != 1) { freedisplist(&dispbase); Py_DECREF(polyLine); PyErr_SetString( PyExc_TypeError, "A point in one of the polylines is not a Mathutils.Vector type" ); return NULL; } #endif dl= MEM_callocN(sizeof(DispList), "poly disp"); BLI_addtail(&dispbase, dl); dl->type= DL_INDEX3; dl->nr= len_polypoints; dl->type= DL_POLY; dl->parts= 1; /* no faces, 1 edge loop */ dl->col= 0; /* no material */ dl->verts= fp= MEM_callocN( sizeof(float)*3*len_polypoints, "dl verts"); dl->index= MEM_callocN(sizeof(int)*3*len_polypoints, "dl index"); for( index = 0; index<len_polypoints; ++index, fp+=3) { polyVec= PySequence_GetItem( polyLine, index ); if(VectorObject_Check(polyVec)) { if(!BaseMath_ReadCallback((VectorObject *)polyVec)) ls_error= 1; fp[0] = ((VectorObject *)polyVec)->vec[0]; fp[1] = ((VectorObject *)polyVec)->vec[1]; if( ((VectorObject *)polyVec)->size > 2 ) fp[2] = ((VectorObject *)polyVec)->vec[2]; else fp[2]= 0.0f; /* if its a 2d vector then set the z to be zero */ } else { ls_error= 1; } totpoints++; Py_DECREF(polyVec); } } Py_DECREF(polyLine); } if(ls_error) { freedisplist(&dispbase); /* possible some dl was allocated */ PyErr_SetString( PyExc_TypeError, "A point in one of the polylines is not a Mathutils.Vector type" ); return NULL; } else if (totpoints) { /* now make the list to return */ filldisplist(&dispbase, &dispbase); /* The faces are stored in a new DisplayList thats added to the head of the listbase */ dl= dispbase.first; tri_list= PyList_New(dl->parts); if( !tri_list ) { freedisplist(&dispbase); PyErr_SetString( PyExc_RuntimeError, "Geometry.PolyFill failed to make a new list" ); return NULL; } index= 0; dl_face= dl->index; while(index < dl->parts) { PyList_SetItem(tri_list, index, Py_BuildValue("iii", dl_face[0], dl_face[1], dl_face[2]) ); dl_face+= 3; index++; } freedisplist(&dispbase); } else { /* no points, do this so scripts dont barf */ freedisplist(&dispbase); /* possible some dl was allocated */ tri_list= PyList_New(0); } return tri_list; }