static PyObject *bpy_bmlayercollection_items(BPy_BMLayerCollection *self)
{
	PyObject *ret;
	PyObject *item;
	int index;
	CustomData *data;
	int tot, i;

	BPY_BM_CHECK_OBJ(self);

	data = bpy_bm_customdata_get(self->bm, self->htype);
	index = CustomData_get_layer_index(data, self->type);
	tot = (index != -1) ? CustomData_number_of_layers(data, self->type) : 0;

	ret = PyList_New(tot);

	for (i = 0; tot-- > 0; index++) {
		item = PyTuple_New(2);
		PyTuple_SET_ITEMS(item,
		        PyUnicode_FromString(data->layers[index].name),
		        BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, i));
		PyList_SET_ITEM(ret, i++, item);
	}

	return ret;
}
示例#2
0
static PyObject *BPy_Group_Iter_Next(BPy_IDGroup_Iter *self)
{

	if (self->cur) {
		PyObject *ret;
		IDProperty *cur;

		cur = self->cur;
		self->cur = self->cur->next;

		if (self->mode == IDPROP_ITER_ITEMS) {
			ret = PyTuple_New(2);
			PyTuple_SET_ITEMS(ret,
			        PyUnicode_FromString(cur->name),
			        BPy_IDGroup_WrapData(self->group->id, cur, self->group->prop));
			return ret;
		}
		else {
			return PyUnicode_FromString(cur->name);
		}
	}
	else {
		PyErr_SetNone(PyExc_StopIteration);
		return NULL;
	}
}
PyObject *BPy_directedViewEdge_from_directedViewEdge(ViewVertex::directedViewEdge& dve)
{
	PyObject *py_dve = PyTuple_New(2);
	PyTuple_SET_ITEMS(py_dve,
	        BPy_ViewEdge_from_ViewEdge(*(dve.first)),
	        PyBool_from_bool(dve.second));
	return py_dve;
}
示例#4
0
static PyObject *bpy_lib_enter(BPy_Library *self)
{
	PyObject *ret;
	BPy_Library *self_from;
	PyObject *from_dict = _PyDict_NewPresized(MAX_LIBARRAY);
	ReportList reports;

	BKE_reports_init(&reports, RPT_STORE);

	self->blo_handle = BLO_blendhandle_from_file(self->abspath, &reports);

	if (self->blo_handle == NULL) {
		if (BPy_reports_to_error(&reports, PyExc_IOError, true) != -1) {
			PyErr_Format(PyExc_IOError,
			             "load: %s failed to open blend file",
			             self->abspath);
		}
		return NULL;
	}
	else {
		int i = 0, code;
		while ((code = BKE_idcode_iter_step(&i))) {
			if (BKE_idcode_is_linkable(code)) {
				const char *name_plural = BKE_idcode_to_name_plural(code);
				PyObject *str = PyUnicode_FromString(name_plural);
				PyObject *item;

				PyDict_SetItem(self->dict, str, item = PyList_New(0));
				Py_DECREF(item);
				PyDict_SetItem(from_dict, str, item = _bpy_names(self, code));
				Py_DECREF(item);

				Py_DECREF(str);
			}
		}
	}

	/* create a dummy */
	self_from = PyObject_New(BPy_Library, &bpy_lib_Type);
	BLI_strncpy(self_from->relpath, self->relpath, sizeof(self_from->relpath));
	BLI_strncpy(self_from->abspath, self->abspath, sizeof(self_from->abspath));

	self_from->blo_handle = NULL;
	self_from->flag = 0;
	self_from->dict = from_dict; /* owns the dict */

	/* return pair */
	ret = PyTuple_New(2);
	PyTuple_SET_ITEMS(ret,
	        (PyObject *)self_from,
	        (PyObject *)self);
	Py_INCREF(self);

	BKE_reports_clear(&reports);

	return ret;
}
static void kdtree_nearest_to_py_tuple(const KDTreeNearest *nearest, PyObject *py_retval)
{
	BLI_assert(nearest->index >= 0);
	BLI_assert(PyTuple_GET_SIZE(py_retval) == 3);

	PyTuple_SET_ITEMS(py_retval,
	        Vector_CreatePyObject((float *)nearest->co, 3, NULL),
	        PyLong_FromLong(nearest->index),
	        PyFloat_FromDouble(nearest->dist));
}
static PyObject *bpy_bm_utils_edge_split(PyObject *UNUSED(self), PyObject *args)
{
	BPy_BMEdge *py_edge;
	BPy_BMVert *py_vert;
	float fac;

	BMesh *bm;
	BMVert *v_new = NULL;
	BMEdge *e_new = NULL;

	if (!PyArg_ParseTuple(args, "O!O!f:edge_split",
	                      &BPy_BMEdge_Type, &py_edge,
	                      &BPy_BMVert_Type, &py_vert,
	                      &fac))
	{
		return NULL;
	}

	BPY_BM_CHECK_OBJ(py_edge);
	BPY_BM_CHECK_OBJ(py_vert);

	/* this doubles for checking that the verts are in the same mesh */
	if (!(py_edge->e->v1 == py_vert->v ||
	      py_edge->e->v2 == py_vert->v))
	{
		PyErr_SetString(PyExc_ValueError,
		                "edge_split(edge, vert): the vertex is not found in the edge");
		return NULL;
	}

	bm = py_edge->bm;

	v_new = BM_edge_split(bm, py_edge->e, py_vert->v, &e_new, CLAMPIS(fac, 0.0f, 1.0f));

	if (v_new && e_new) {
		PyObject *ret = PyTuple_New(2);
		PyTuple_SET_ITEMS(ret,
		        BPy_BMEdge_CreatePyObject(bm, e_new),
		        BPy_BMVert_CreatePyObject(bm, v_new));
		return ret;
	}
	else {
		PyErr_SetString(PyExc_ValueError,
		                "edge_split(edge, vert): couldn't split the edge, internal error");
		return NULL;
	}
}
示例#7
0
static PyObject *py_blf_dimensions(PyObject *UNUSED(self), PyObject *args)
{
  const char *text;
  float r_width, r_height;
  PyObject *ret;
  int fontid;

  if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text)) {
    return NULL;
  }

  BLF_width_and_height(fontid, text, INT_MAX, &r_width, &r_height);

  ret = PyTuple_New(2);
  PyTuple_SET_ITEMS(ret, PyFloat_FromDouble(r_width), PyFloat_FromDouble(r_height));
  return ret;
}
static PyObject *bpy_bmdeformvert_items(BPy_BMDeformVert *self)
{
	PyObject *ret;
	PyObject *item;
	int i;
	MDeformWeight *dw = self->data->dw;

	ret = PyList_New(self->data->totweight);
	for (i = 0; i < self->data->totweight; i++, dw++) {
		item = PyTuple_New(2);
		PyTuple_SET_ITEMS(item,
		        PyLong_FromLong(dw->def_nr),
		        PyFloat_FromDouble(dw->weight));
		PyList_SET_ITEM(ret, i, item);
	}

	return ret;
}
static PyObject *SVertex_curvatures_get(BPy_SVertex *self, void *UNUSED(closure))
{
	const CurvatureInfo *info = self->sv->getCurvatureInfo();
	if (!info)
		Py_RETURN_NONE;
	Vec3r e1(info->e1.x(), info->e1.y(), info->e1.z());
	Vec3r e2(info->e2.x(), info->e2.y(), info->e2.z());
	Vec3r er(info->er.x(), info->er.y(), info->er.z());
	PyObject *retval = PyTuple_New(7);
	PyTuple_SET_ITEMS(retval,
	        PyFloat_FromDouble(info->K1),
	        PyFloat_FromDouble(info->K2),
	        Vector_from_Vec3r(e1),
	        Vector_from_Vec3r(e2),
	        PyFloat_FromDouble(info->Kr),
	        Vector_from_Vec3r(er),
	        PyFloat_FromDouble(info->dKr));
	return retval;
}
示例#10
0
PyObject *BPy_Wrap_GetItems(ID *id, IDProperty *prop)
{
	PyObject *seq = PyList_New(prop->len);
	IDProperty *loop;
	int i;

	for (i = 0, loop = prop->data.group.first; loop; loop = loop->next, i++) {
		PyObject *item = PyTuple_New(2);
		PyTuple_SET_ITEMS(item,
		        PyUnicode_FromString(loop->name),
		        BPy_IDGroup_WrapData(id, loop, prop));
		PyList_SET_ITEM(seq, i, item);
	}

	if (i != prop->len) {
		BPy_IDGroup_CorrectListLen(prop, seq, i, __func__);
		Py_DECREF(seq); /*free the list*/
		/*call self again*/
		return BPy_Wrap_GetItems(id, prop);
	}

	return seq;
}
static PyObject *bpy_bm_utils_face_split(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
	static const char *kwlist[] = {"face", "vert_a", "vert_b",
	                               "coords", "use_exist", "example", NULL};

	BPy_BMFace *py_face;
	BPy_BMVert *py_vert_a;
	BPy_BMVert *py_vert_b;

	/* optional */
	PyObject *py_coords = NULL;
	bool edge_exists = true;
	BPy_BMEdge *py_edge_example = NULL;

	float *coords;
	int ncoords = 0;

	BMesh *bm;
	BMFace *f_new = NULL;
	BMLoop *l_new = NULL;
	BMLoop *l_a, *l_b;

	if (!PyArg_ParseTupleAndKeywords(
	        args, kw,
	        "O!O!O!|OO&O!:face_split", (char **)kwlist,
	        &BPy_BMFace_Type, &py_face,
	        &BPy_BMVert_Type, &py_vert_a,
	        &BPy_BMVert_Type, &py_vert_b,
	        &py_coords,
	        PyC_ParseBool, &edge_exists,
	        &BPy_BMEdge_Type, &py_edge_example))
	{
		return NULL;
	}

	BPY_BM_CHECK_OBJ(py_face);
	BPY_BM_CHECK_OBJ(py_vert_a);
	BPY_BM_CHECK_OBJ(py_vert_b);

	if (py_edge_example) {
		BPY_BM_CHECK_OBJ(py_edge_example);
	}

	/* this doubles for checking that the verts are in the same mesh */
	if ((l_a = BM_face_vert_share_loop(py_face->f, py_vert_a->v)) &&
	    (l_b = BM_face_vert_share_loop(py_face->f, py_vert_b->v)))
	{
		/* pass */
	}
	else {
		PyErr_SetString(PyExc_ValueError,
		                "face_split(...): one of the verts passed is not found in the face");
		return NULL;
	}

	if (py_vert_a->v == py_vert_b->v) {
		PyErr_SetString(PyExc_ValueError,
		                "face_split(...): vert arguments must differ");
		return NULL;
	}

	if (py_coords) {
		ncoords = mathutils_array_parse_alloc_v(&coords, 3, py_coords, "face_split(...): ");
		if (ncoords == -1) {
			return NULL;
		}
	}

	/* --- main function body --- */
	bm = py_face->bm;

	if (ncoords) {
		f_new = BM_face_split_n(bm, py_face->f,
		                        l_a, l_b,
		                        (float (*)[3])coords, ncoords,
		                        &l_new, py_edge_example ? py_edge_example->e : NULL);
		PyMem_Free(coords);
	}
	else {
		f_new = BM_face_split(bm, py_face->f,
		                      l_a, l_b,
		                      &l_new, py_edge_example ? py_edge_example->e : NULL, edge_exists);
	}

	if (f_new && l_new) {
		PyObject *ret = PyTuple_New(2);
		PyTuple_SET_ITEMS(ret,
		        BPy_BMFace_CreatePyObject(bm, f_new),
		        BPy_BMLoop_CreatePyObject(bm, l_new));
		return ret;
	}
	else {
		PyErr_SetString(PyExc_ValueError,
		                "face_split(...): couldn't split the face, internal error");
		return NULL;
	}
}