Exemplo n.º 1
0
static void curve_to_filledpoly(Curve *cu, ListBase *UNUSED(nurb), ListBase *dispbase)
{
	if (!CU_DO_2DFILL(cu))
		return;

	if (dispbase->first && ((DispList *) dispbase->first)->type == DL_SURF) {
		bevels_to_filledpoly(cu, dispbase);
	}
	else {
		const float z_up[3] = {0.0f, 0.0f, 1.0f};
		BKE_displist_fill(dispbase, dispbase, z_up, false);
	}
}
Exemplo n.º 2
0
static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase)
{
	const float z_up[3] = {0.0f, 0.0f, 1.0f};
	ListBase front, back;
	DispList *dl, *dlnew;
	float *fp, *fp1;
	int a, dpoly;

	BLI_listbase_clear(&front);
	BLI_listbase_clear(&back);

	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->flag = DL_BACK_CURVE;
					dlnew->col = dl->col;
					dlnew->charidx = dl->charidx;

					fp = dl->verts;
					dpoly = 3 * dl->nr;

					a = dl->parts;
					while (a--) {
						copy_v3_v3(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->flag = DL_FRONT_CURVE;
					dlnew->col = dl->col;
					dlnew->charidx = dl->charidx;

					fp = dl->verts + 3 * (dl->nr - 1);
					dpoly = 3 * dl->nr;

					a = dl->parts;
					while (a--) {
						copy_v3_v3(fp1, fp);
						fp1 += 3;
						fp += dpoly;
					}
				}
			}
		}
		dl = dl->next;
	}

	BKE_displist_fill(&front, dispbase, z_up, true);
	BKE_displist_fill(&back, dispbase, z_up, false);

	BKE_displist_free(&front);
	BKE_displist_free(&back);

	BKE_displist_fill(dispbase, dispbase, z_up, false);
}
Exemplo n.º 3
0
/* PolyFill function, uses Blenders scanfill to fill multiple poly lines */
static PyObject *M_Geometry_tessellate_polygon(PyObject *UNUSED(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;

	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)) {
			BKE_displist_free(&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) { /* don't 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) == -1)
						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) {
		BKE_displist_free(&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 */
		BKE_displist_fill(&dispbase, &dispbase, 0);

		/* 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) {
			BKE_displist_free(&dispbase);
			PyErr_SetString(PyExc_RuntimeError,
			                "failed to make a new list");
			return NULL;
		}

		index = 0;
		dl_face = dl->index;
		while (index < dl->parts) {
			PyList_SET_ITEM(tri_list, index, Py_BuildValue("iii", dl_face[0], dl_face[1], dl_face[2]));
			dl_face += 3;
			index++;
		}
		BKE_displist_free(&dispbase);
	}
	else {
		/* no points, do this so scripts don't barf */
		BKE_displist_free(&dispbase); /* possible some dl was allocated */
		tri_list = PyList_New(0);
	}

	return tri_list;
}