svn merge ^/trunk/blender -r48321:48333
This commit is contained in:
@@ -64,7 +64,7 @@ const GHOST_TUns8 *GHOST_SystemPathsX11::getSystemDir(int, const char *versionst
|
||||
if (static_path) {
|
||||
static char system_path[PATH_MAX];
|
||||
snprintf(system_path, sizeof(system_path), "%s/blender/%s", static_path, versionstr);
|
||||
return (GHOST_TUns8*)system_path;
|
||||
return (GHOST_TUns8 *)system_path;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -81,22 +81,22 @@ const GHOST_TUns8 *GHOST_SystemPathsX11::getUserDir(int version, const char *ver
|
||||
|
||||
if (home) {
|
||||
snprintf(user_path, sizeof(user_path), "%s/.blender/%s", home, versionstr);
|
||||
return (GHOST_TUns8*)user_path;
|
||||
return (GHOST_TUns8 *)user_path;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
const char *home= getenv("XDG_CONFIG_HOME");
|
||||
const char *home = getenv("XDG_CONFIG_HOME");
|
||||
|
||||
if (home) {
|
||||
snprintf(user_path, sizeof(user_path), "%s/blender/%s", home, versionstr);
|
||||
}
|
||||
else {
|
||||
home= getenv("HOME");
|
||||
home = getenv("HOME");
|
||||
|
||||
if (home == NULL)
|
||||
home= getpwuid(getuid())->pw_dir;
|
||||
home = getpwuid(getuid())->pw_dir;
|
||||
|
||||
snprintf(user_path, sizeof(user_path), "%s/.config/blender/%s", home, versionstr);
|
||||
}
|
||||
|
||||
@@ -245,12 +245,12 @@ static BMOpDefine bmo_finddoubles_def = {
|
||||
* Finds groups of vertices closer then dist and merges them together,
|
||||
* using the weld verts bmop.
|
||||
*/
|
||||
static BMOpDefine bmo_removedoubles_def = {
|
||||
"removedoubles",
|
||||
static BMOpDefine bmo_remove_doubles_def = {
|
||||
"remove_doubles",
|
||||
{{BMO_OP_SLOT_ELEMENT_BUF, "verts"}, //input verts
|
||||
{BMO_OP_SLOT_FLT, "dist"}, //minimum distance
|
||||
{0, /* null-terminating sentinel */}},
|
||||
bmo_removedoubles_exec,
|
||||
bmo_remove_doubles_exec,
|
||||
BMO_OP_FLAG_UNTAN_MULTIRES,
|
||||
};
|
||||
|
||||
@@ -1199,7 +1199,7 @@ BMOpDefine *opdefines[] = {
|
||||
&bmo_contextual_create_def,
|
||||
&bmo_makevert_def,
|
||||
&bmo_weldverts_def,
|
||||
&bmo_removedoubles_def,
|
||||
&bmo_remove_doubles_def,
|
||||
&bmo_finddoubles_def,
|
||||
&bmo_mirror_def,
|
||||
&bmo_edgebisect_def,
|
||||
|
||||
@@ -57,7 +57,7 @@ void bmo_makevert_exec(BMesh *bm, BMOperator *op);
|
||||
void bmo_dissolve_edges_exec(BMesh *bm, BMOperator *op);
|
||||
void bmo_dissolve_edgeloop_exec(BMesh *bm, BMOperator *op);
|
||||
void bmo_weldverts_exec(BMesh *bm, BMOperator *op);
|
||||
void bmo_removedoubles_exec(BMesh *bm, BMOperator *op);
|
||||
void bmo_remove_doubles_exec(BMesh *bm, BMOperator *op);
|
||||
void bmo_finddoubles_exec(BMesh *bm, BMOperator *op);
|
||||
void bmo_mirror_exec(BMesh *bm, BMOperator *op);
|
||||
void bmo_edgebisect_exec(BMesh *bm, BMOperator *op);
|
||||
|
||||
@@ -365,7 +365,7 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op)
|
||||
len2 = len_v3v3(vec, vec2);
|
||||
|
||||
/* use shortest segment length divided by 3 as merge threshold */
|
||||
BMO_op_callf(bm, "removedoubles verts=%fv dist=%f", VERT_MARK, MIN2(len, len2) / 3.0f);
|
||||
BMO_op_callf(bm, "remove_doubles verts=%fv dist=%f", VERT_MARK, MIN2(len, len2) / 3.0f);
|
||||
}
|
||||
|
||||
/* and now do imat */
|
||||
@@ -661,7 +661,7 @@ void bmo_create_cone_exec(BMesh *bm, BMOperator *op)
|
||||
|
||||
BM_face_create_quad_tri(bm, v1, v2, firstv2, firstv1, NULL, FALSE);
|
||||
|
||||
BMO_op_callf(bm, "removedoubles verts=%fv dist=%f", VERT_MARK, 0.000001);
|
||||
BMO_op_callf(bm, "remove_doubles verts=%fv dist=%f", VERT_MARK, 0.000001);
|
||||
BMO_slot_buffer_from_enabled_flag(bm, op, "vertout", BM_VERT, VERT_MARK);
|
||||
}
|
||||
|
||||
|
||||
@@ -557,7 +557,7 @@ void bmesh_finddoubles_common(BMesh *bm, BMOperator *op, BMOperator *optarget, c
|
||||
BLI_array_free(verts);
|
||||
}
|
||||
|
||||
void bmo_removedoubles_exec(BMesh *bm, BMOperator *op)
|
||||
void bmo_remove_doubles_exec(BMesh *bm, BMOperator *op)
|
||||
{
|
||||
BMOperator weldop;
|
||||
|
||||
|
||||
@@ -898,7 +898,7 @@ int mesh_mirrtopo_table(Object *ob, char mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mesh_get_x_mirror_vert_spacial(Object *ob, int index)
|
||||
static int mesh_get_x_mirror_vert_spatial(Object *ob, int index)
|
||||
{
|
||||
Mesh *me = ob->data;
|
||||
MVert *mvert;
|
||||
@@ -926,12 +926,12 @@ int mesh_get_x_mirror_vert(Object *ob, int index)
|
||||
return mesh_get_x_mirror_vert_topo(ob, index);
|
||||
}
|
||||
else {
|
||||
return mesh_get_x_mirror_vert_spacial(ob, index);
|
||||
return mesh_get_x_mirror_vert_spatial(ob, index);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static BMVert *editbmesh_get_x_mirror_vert_spacial(Object *ob, BMEditMesh *em, const float co[3])
|
||||
static BMVert *editbmesh_get_x_mirror_vert_spatial(Object *ob, BMEditMesh *em, const float co[3])
|
||||
{
|
||||
float vec[3];
|
||||
intptr_t poinval;
|
||||
@@ -989,7 +989,7 @@ BMVert *editbmesh_get_x_mirror_vert(Object *ob, struct BMEditMesh *em, BMVert *e
|
||||
return editbmesh_get_x_mirror_vert_topo(ob, em, eve, index);
|
||||
}
|
||||
else {
|
||||
return editbmesh_get_x_mirror_vert_spacial(ob, em, co);
|
||||
return editbmesh_get_x_mirror_vert_spatial(ob, em, co);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4935,7 +4935,7 @@ static int texture_paint_init(bContext *C, wmOperator *op)
|
||||
if (BKE_brush_size_get(scene, brush) < 2)
|
||||
BKE_brush_size_set(scene, brush, 2);
|
||||
|
||||
/* allocate and initialize spacial data structures */
|
||||
/* allocate and initialize spatial data structures */
|
||||
project_paint_begin(&pop->ps);
|
||||
|
||||
if (pop->ps.dm == NULL)
|
||||
@@ -5728,7 +5728,7 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op)
|
||||
undo_paint_push_begin(UNDO_PAINT_IMAGE, op->type->name,
|
||||
image_undo_restore, image_undo_free);
|
||||
|
||||
/* allocate and initialize spacial data structures */
|
||||
/* allocate and initialize spatial data structures */
|
||||
project_paint_begin(&ps);
|
||||
|
||||
if (ps.dm == NULL) {
|
||||
|
||||
@@ -306,7 +306,7 @@ static void planeProjection(TransInfo *t, float in[3], float out[3])
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic callback for constant spacial constraints applied to linear motion
|
||||
* Generic callback for constant spatial constraints applied to linear motion
|
||||
*
|
||||
* The IN vector in projected into the constrained space and then further
|
||||
* projected along the view vector.
|
||||
@@ -404,9 +404,7 @@ static void applyObjectConstraintVec(TransInfo *t, TransData *td, float in[3], f
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic callback for constant spacial constraints applied to resize motion
|
||||
*
|
||||
*
|
||||
* Generic callback for constant spatial constraints applied to resize motion
|
||||
*/
|
||||
|
||||
static void applyAxisConstraintSize(TransInfo *t, TransData *td, float smat[3][3])
|
||||
@@ -430,9 +428,7 @@ static void applyAxisConstraintSize(TransInfo *t, TransData *td, float smat[3][3
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback for object based spacial constraints applied to resize motion
|
||||
*
|
||||
*
|
||||
* Callback for object based spatial constraints applied to resize motion
|
||||
*/
|
||||
|
||||
static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3][3])
|
||||
@@ -459,7 +455,7 @@ static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3]
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic callback for constant spacial constraints applied to rotations
|
||||
* Generic callback for constant spatial constraints applied to rotations
|
||||
*
|
||||
* The rotation axis is copied into VEC.
|
||||
*
|
||||
@@ -501,7 +497,7 @@ static void applyAxisConstraintRot(TransInfo *t, TransData *td, float vec[3], fl
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback for object based spacial constraints applied to rotations
|
||||
* Callback for object based spatial constraints applied to rotations
|
||||
*
|
||||
* The rotation axis is copied into VEC.
|
||||
*
|
||||
|
||||
@@ -33,6 +33,7 @@ set(INC_SYS
|
||||
|
||||
set(SRC
|
||||
bmesh_py_api.c
|
||||
bmesh_py_ops.c
|
||||
bmesh_py_types.c
|
||||
bmesh_py_types_customdata.c
|
||||
bmesh_py_types_meshdata.c
|
||||
@@ -40,6 +41,7 @@ set(SRC
|
||||
bmesh_py_utils.c
|
||||
|
||||
bmesh_py_api.h
|
||||
bmesh_py_ops.h
|
||||
bmesh_py_types.h
|
||||
bmesh_py_types_customdata.h
|
||||
bmesh_py_types_meshdata.h
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "bmesh_py_types_customdata.h"
|
||||
#include "bmesh_py_types_meshdata.h"
|
||||
|
||||
#include "bmesh_py_ops.h"
|
||||
#include "bmesh_py_utils.h"
|
||||
|
||||
#include "BKE_tessmesh.h"
|
||||
@@ -143,6 +144,10 @@ PyObject *BPyInit_bmesh(void)
|
||||
PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
|
||||
Py_INCREF(submodule);
|
||||
|
||||
PyModule_AddObject(mod, "ops", (submodule = BPyInit_bmesh_ops()));
|
||||
PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
|
||||
Py_INCREF(submodule);
|
||||
|
||||
PyModule_AddObject(mod, "utils", (submodule = BPyInit_bmesh_utils()));
|
||||
PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
|
||||
Py_INCREF(submodule);
|
||||
|
||||
273
source/blender/python/bmesh/bmesh_py_ops.c
Normal file
273
source/blender/python/bmesh/bmesh_py_ops.c
Normal file
@@ -0,0 +1,273 @@
|
||||
/*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2012 Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/** \file blender/python/bmesh/bmesh_py_ops.c
|
||||
* \ingroup pybmesh
|
||||
*
|
||||
* This file defines the 'bmesh.ops' module.
|
||||
* Operators from 'opdefines' are wrapped.
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "../generic/py_capi_utils.h"
|
||||
|
||||
#include "../mathutils/mathutils.h"
|
||||
|
||||
#include "bmesh.h"
|
||||
|
||||
#include "bmesh_py_types.h"
|
||||
|
||||
#include "bmesh_py_utils.h" /* own include */
|
||||
|
||||
static int bpy_bm_op_as_py_error(BMesh *bm)
|
||||
{
|
||||
if (BMO_error_occurred(bm)) {
|
||||
const char *errmsg;
|
||||
if (BMO_error_get(bm, &errmsg, NULL)) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"bmesh operator: %.200s",
|
||||
errmsg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(bpy_bm_ops_convex_hull_doc,
|
||||
".. method:: convex_hull(bmesh, filter)\n"
|
||||
"\n"
|
||||
" Face split with optional intermediate points.\n"
|
||||
"\n"
|
||||
" :arg bmesh: The face to cut.\n"
|
||||
" :type bmesh: :class:`bmesh.types.BMFace`\n"
|
||||
" :arg filter: Set containing vertex flags to apply the operator.\n"
|
||||
" :type filter: set\n"
|
||||
);
|
||||
static PyObject *bpy_bm_ops_convex_hull(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
||||
{
|
||||
static const char *kwlist[] = {"bmesh", "filter", NULL};
|
||||
|
||||
BPy_BMesh *py_bm;
|
||||
BMesh *bm;
|
||||
|
||||
PyObject *filter;
|
||||
int filter_flags;
|
||||
BMOperator bmop;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!:convex_hull", (char **)kwlist,
|
||||
&BPy_BMesh_Type, &py_bm,
|
||||
&PySet_Type, &filter))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BPY_BM_CHECK_OBJ(py_bm);
|
||||
bm = py_bm->bm;
|
||||
|
||||
if (filter != NULL && PyC_FlagSet_ToBitfield(bpy_bm_hflag_all_flags, filter,
|
||||
&filter_flags, "convex_hull") == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BMO_op_initf(bm, &bmop,
|
||||
"convex_hull input=%hv",
|
||||
filter_flags);
|
||||
BMO_op_exec(bm, &bmop);
|
||||
BMO_op_finish(bm, &bmop);
|
||||
|
||||
if (bpy_bm_op_as_py_error(bm) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* TODO, return values */
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PyDoc_STRVAR(bpy_bm_ops_dissolve_limit_doc,
|
||||
".. method:: dissolve_limit(bmesh, filter, dist)\n"
|
||||
"\n"
|
||||
" Face split with optional intermediate points.\n"
|
||||
"\n"
|
||||
" :arg bmesh: The face to cut.\n"
|
||||
" :type bmesh: :class:`bmesh.types.BMFace`\n"
|
||||
" :arg filter: Set containing vertex flags to apply the operator.\n"
|
||||
" :type filter: set\n"
|
||||
" :arg dist: Distance limit.\n"
|
||||
" :type dist: float\n"
|
||||
);
|
||||
static PyObject *bpy_bm_ops_dissolve_limit(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
||||
{
|
||||
static const char *kwlist[] = {"bmesh", "filter_verts", "filter_edges", "angle_limit", NULL};
|
||||
|
||||
BPy_BMesh *py_bm;
|
||||
BMesh *bm;
|
||||
|
||||
PyObject *filter_verts;
|
||||
int filter_verts_flags;
|
||||
PyObject *filter_edges;
|
||||
int filter_edges_flags;
|
||||
|
||||
float angle_limit = 0.0f;
|
||||
|
||||
BMOperator bmop;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!O!|f:dissolve_limit", (char **)kwlist,
|
||||
&BPy_BMesh_Type, &py_bm,
|
||||
&PySet_Type, &filter_verts,
|
||||
&PySet_Type, &filter_edges,
|
||||
&angle_limit))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BPY_BM_CHECK_OBJ(py_bm);
|
||||
bm = py_bm->bm;
|
||||
|
||||
if (filter_verts != NULL && PyC_FlagSet_ToBitfield(bpy_bm_hflag_all_flags, filter_verts,
|
||||
&filter_verts_flags, "dissolve_limit") == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (filter_edges != NULL && PyC_FlagSet_ToBitfield(bpy_bm_hflag_all_flags, filter_edges,
|
||||
&filter_edges_flags, "dissolve_limit") == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BMO_op_initf(bm, &bmop,
|
||||
"dissolve_limit verts=%hv edges=%he angle_limit=%f",
|
||||
filter_verts_flags, filter_edges_flags, angle_limit);
|
||||
BMO_op_exec(bm, &bmop);
|
||||
BMO_op_finish(bm, &bmop);
|
||||
|
||||
if (bpy_bm_op_as_py_error(bm) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* TODO, return values */
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PyDoc_STRVAR(bpy_bm_ops_remove_doubles_doc,
|
||||
".. method:: remove_doubles(bmesh, filter, dist)\n"
|
||||
"\n"
|
||||
" Face split with optional intermediate points.\n"
|
||||
"\n"
|
||||
" :arg bmesh: The face to cut.\n"
|
||||
" :type bmesh: :class:`bmesh.types.BMFace`\n"
|
||||
" :arg filter: Set containing vertex flags to apply the operator.\n"
|
||||
" :type filter: set\n"
|
||||
" :arg dist: Distance limit.\n"
|
||||
" :type dist: float\n"
|
||||
);
|
||||
static PyObject *bpy_bm_ops_remove_doubles(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
||||
{
|
||||
static const char *kwlist[] = {"bmesh", "filter", "dist", NULL};
|
||||
|
||||
BPy_BMesh *py_bm;
|
||||
BMesh *bm;
|
||||
|
||||
PyObject *filter;
|
||||
int filter_flags;
|
||||
float dist = 0.0f;
|
||||
|
||||
BMOperator bmop;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!|f:remove_doubles", (char **)kwlist,
|
||||
&BPy_BMesh_Type, &py_bm,
|
||||
&PySet_Type, &filter,
|
||||
&dist))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BPY_BM_CHECK_OBJ(py_bm);
|
||||
bm = py_bm->bm;
|
||||
|
||||
if (filter != NULL && PyC_FlagSet_ToBitfield(bpy_bm_hflag_all_flags, filter,
|
||||
&filter_flags, "remove_doubles") == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BMO_op_initf(bm, &bmop,
|
||||
"remove_doubles verts=%hv dist=%f",
|
||||
filter_flags, dist);
|
||||
BMO_op_exec(bm, &bmop);
|
||||
BMO_op_finish(bm, &bmop);
|
||||
|
||||
if (bpy_bm_op_as_py_error(bm) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* TODO, return values */
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static struct PyMethodDef BPy_BM_ops_methods[] = {
|
||||
{"convex_hull", (PyCFunction)bpy_bm_ops_convex_hull, METH_VARARGS | METH_KEYWORDS, bpy_bm_ops_convex_hull_doc},
|
||||
{"dissolve_limit", (PyCFunction)bpy_bm_ops_dissolve_limit, METH_VARARGS | METH_KEYWORDS, bpy_bm_ops_dissolve_limit_doc},
|
||||
{"remove_doubles", (PyCFunction)bpy_bm_ops_remove_doubles, METH_VARARGS | METH_KEYWORDS, bpy_bm_ops_remove_doubles_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
PyDoc_STRVAR(BPy_BM_ops_doc,
|
||||
"This module provides access to bmesh operators (EXPEREMENTAL)."
|
||||
);
|
||||
static struct PyModuleDef BPy_BM_ops_module_def = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"bmesh.ops", /* m_name */
|
||||
BPy_BM_ops_doc, /* m_doc */
|
||||
0, /* m_size */
|
||||
BPy_BM_ops_methods, /* m_methods */
|
||||
NULL, /* m_reload */
|
||||
NULL, /* m_traverse */
|
||||
NULL, /* m_clear */
|
||||
NULL, /* m_free */
|
||||
};
|
||||
|
||||
|
||||
PyObject *BPyInit_bmesh_ops(void)
|
||||
{
|
||||
PyObject *submodule;
|
||||
|
||||
submodule = PyModule_Create(&BPy_BM_ops_module_def);
|
||||
|
||||
return submodule;
|
||||
}
|
||||
35
source/blender/python/bmesh/bmesh_py_ops.h
Normal file
35
source/blender/python/bmesh/bmesh_py_ops.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2012 Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/** \file blender/python/bmesh/bmesh_py_ops.h
|
||||
* \ingroup pybmesh
|
||||
*/
|
||||
|
||||
#ifndef __BMESH_PY_OPS_H__
|
||||
#define __BMESH_PY_OPS_H__
|
||||
|
||||
PyObject *BPyInit_bmesh_ops(void);
|
||||
|
||||
#endif /* __BMESH_PY_OPS_H__ */
|
||||
@@ -186,4 +186,13 @@ char *BPy_BMElem_StringFromHType(const char htype);
|
||||
ele; \
|
||||
ele = BM_iter_step(iter))
|
||||
|
||||
|
||||
#ifdef __PY_CAPI_UTILS_H__
|
||||
struct PyC_FlagSet;
|
||||
extern struct PyC_FlagSet bpy_bm_scene_vert_edge_face_flags[];
|
||||
extern struct PyC_FlagSet bpy_bm_htype_vert_edge_face_flags[];
|
||||
extern struct PyC_FlagSet bpy_bm_htype_all_flags[];
|
||||
extern struct PyC_FlagSet bpy_bm_hflag_all_flags[];
|
||||
#endif
|
||||
|
||||
#endif /* __BMESH_TYPES_H__ */
|
||||
|
||||
@@ -668,13 +668,13 @@ static struct PyMethodDef BPy_BM_utils_methods[] = {
|
||||
};
|
||||
|
||||
|
||||
PyDoc_STRVAR(BPy_BM_doc,
|
||||
PyDoc_STRVAR(BPy_BM_utils_doc,
|
||||
"This module provides access to blenders bmesh data structures."
|
||||
);
|
||||
static struct PyModuleDef BPy_BM_types_module_def = {
|
||||
static struct PyModuleDef BPy_BM_utils_module_def = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"bmesh.utils", /* m_name */
|
||||
BPy_BM_doc, /* m_doc */
|
||||
BPy_BM_utils_doc, /* m_doc */
|
||||
0, /* m_size */
|
||||
BPy_BM_utils_methods, /* m_methods */
|
||||
NULL, /* m_reload */
|
||||
@@ -688,7 +688,7 @@ PyObject *BPyInit_bmesh_utils(void)
|
||||
{
|
||||
PyObject *submodule;
|
||||
|
||||
submodule = PyModule_Create(&BPy_BM_types_module_def);
|
||||
submodule = PyModule_Create(&BPy_BM_utils_module_def);
|
||||
|
||||
return submodule;
|
||||
}
|
||||
|
||||
@@ -944,6 +944,109 @@ static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObje
|
||||
return Vector_CreatePyObject(vec, 3, Py_NEW, NULL);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(M_Geometry_points_in_planes_doc,
|
||||
".. function:: points_in_planes(planes)\n"
|
||||
"\n"
|
||||
" Returns a list of points inside all planes given and a list of index values for the planes used.\n"
|
||||
"\n"
|
||||
" :arg planes: List of planes (4D vectors).\n"
|
||||
" :type planes: list of :class:`mathutils.Vector`\n"
|
||||
" :return: two lists, once containing the vertices inside the planes, another containing the plane indicies used\n"
|
||||
" :rtype: pair of lists\n"
|
||||
);
|
||||
/* note: this function could be optimized by some spatial structure */
|
||||
static PyObject *M_Geometry_points_in_planes(PyObject *UNUSED(self), PyObject *args)
|
||||
{
|
||||
PyObject *py_planes;
|
||||
float (*planes)[4];
|
||||
unsigned int planes_len;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O:points_in_planes",
|
||||
&py_planes))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((planes_len = mathutils_array_parse_alloc_v((float **)&planes, 4, py_planes, "points_in_planes")) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
/* note, this could be refactored into plain C easy - py bits are noted */
|
||||
const float eps = 0.0001f;
|
||||
const unsigned int len = (unsigned int)planes_len;
|
||||
unsigned int i, j, k, l;
|
||||
|
||||
float n1n2[3], n2n3[3], n3n1[3];
|
||||
float potentialVertex[3];
|
||||
char *planes_used = MEM_callocN(sizeof(char) * len, __func__);
|
||||
|
||||
/* python */
|
||||
PyObject *py_verts = PyList_New(0);
|
||||
PyObject *py_plene_index = PyList_New(0);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
const float *N1 = planes[i];
|
||||
for (j = i + 1; j < len; j++) {
|
||||
const float *N2 = planes[j];
|
||||
cross_v3_v3v3(n1n2, N1, N2);
|
||||
if (len_squared_v3(n1n2) > eps) {
|
||||
for (k = j + 1; k < len; k++) {
|
||||
const float *N3 = planes[k];
|
||||
cross_v3_v3v3(n2n3, N2, N3);
|
||||
if (len_squared_v3(n2n3) > eps) {
|
||||
cross_v3_v3v3(n3n1, N3, N1);
|
||||
if (len_squared_v3(n3n1) > eps) {
|
||||
const float quotient = dot_v3v3(N1, n2n3);
|
||||
if (fabsf(quotient) > eps) {
|
||||
/* potentialVertex = (n2n3 * N1[3] + n3n1 * N2[3] + n1n2 * N3[3]) * (-1.0 / quotient); */
|
||||
const float quotient_ninv = -1.0f / quotient;
|
||||
potentialVertex[0] = ((n2n3[0] * N1[3]) + (n3n1[0] * N2[3]) + (n1n2[0] * N3[3])) * quotient_ninv;
|
||||
potentialVertex[1] = ((n2n3[1] * N1[3]) + (n3n1[1] * N2[3]) + (n1n2[1] * N3[3])) * quotient_ninv;
|
||||
potentialVertex[2] = ((n2n3[2] * N1[3]) + (n3n1[2] * N2[3]) + (n1n2[2] * N3[3])) * quotient_ninv;
|
||||
for (l = 0; l < len; l++) {
|
||||
const float *NP = planes[l];
|
||||
if ((dot_v3v3(NP, potentialVertex) + NP[3]) > 0.000001f) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (l == len) { /* ok */
|
||||
/* python */
|
||||
PyObject *item = Vector_CreatePyObject(potentialVertex, 3, Py_NEW, NULL);
|
||||
PyList_Append(py_verts, item);
|
||||
Py_DECREF(item);
|
||||
|
||||
planes_used[i] = planes_used[j] = planes_used[k] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PyMem_Free(planes);
|
||||
|
||||
/* now make a list of used planes */
|
||||
for (i = 0; i < len; i++) {
|
||||
if (planes_used[i]) {
|
||||
PyObject *item = PyLong_FromLong(i);
|
||||
PyList_Append(py_plene_index, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
}
|
||||
MEM_freeN(planes_used);
|
||||
|
||||
{
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(ret, 0, py_verts);
|
||||
PyTuple_SET_ITEM(ret, 1, py_plene_index);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef MATH_STANDALONE
|
||||
|
||||
PyDoc_STRVAR(M_Geometry_interpolate_bezier_doc,
|
||||
@@ -1279,6 +1382,7 @@ static PyMethodDef M_Geometry_methods[] = {
|
||||
{"area_tri", (PyCFunction) M_Geometry_area_tri, METH_VARARGS, M_Geometry_area_tri_doc},
|
||||
{"normal", (PyCFunction) M_Geometry_normal, METH_VARARGS, M_Geometry_normal_doc},
|
||||
{"barycentric_transform", (PyCFunction) M_Geometry_barycentric_transform, METH_VARARGS, M_Geometry_barycentric_transform_doc},
|
||||
{"points_in_planes", (PyCFunction) M_Geometry_points_in_planes, METH_VARARGS, M_Geometry_points_in_planes_doc},
|
||||
#ifndef MATH_STANDALONE
|
||||
{"interpolate_bezier", (PyCFunction) M_Geometry_interpolate_bezier, METH_VARARGS, M_Geometry_interpolate_bezier_doc},
|
||||
{"tessellate_polygon", (PyCFunction) M_Geometry_tessellate_polygon, METH_O, M_Geometry_tessellate_polygon_doc},
|
||||
|
||||
@@ -1130,8 +1130,8 @@ static int getGLSLSettingFlag(const char *setting)
|
||||
}
|
||||
|
||||
static PyObject* gPySetGLSLMaterialSetting(PyObject*,
|
||||
PyObject* args,
|
||||
PyObject*)
|
||||
PyObject* args,
|
||||
PyObject*)
|
||||
{
|
||||
GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
|
||||
char *setting;
|
||||
@@ -1142,7 +1142,7 @@ static PyObject* gPySetGLSLMaterialSetting(PyObject*,
|
||||
|
||||
flag = getGLSLSettingFlag(setting);
|
||||
|
||||
if (flag==-1) {
|
||||
if (flag == -1) {
|
||||
PyErr_SetString(PyExc_ValueError, "Rasterizer.setGLSLMaterialSetting(string): glsl setting is not known");
|
||||
return NULL;
|
||||
}
|
||||
@@ -1173,8 +1173,8 @@ static PyObject* gPySetGLSLMaterialSetting(PyObject*,
|
||||
}
|
||||
|
||||
static PyObject* gPyGetGLSLMaterialSetting(PyObject*,
|
||||
PyObject* args,
|
||||
PyObject*)
|
||||
PyObject* args,
|
||||
PyObject*)
|
||||
{
|
||||
GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
|
||||
char *setting;
|
||||
@@ -1185,7 +1185,7 @@ static PyObject* gPyGetGLSLMaterialSetting(PyObject*,
|
||||
|
||||
flag = getGLSLSettingFlag(setting);
|
||||
|
||||
if (flag==-1) {
|
||||
if (flag == -1) {
|
||||
PyErr_SetString(PyExc_ValueError, "Rasterizer.getGLSLMaterialSetting(string): glsl setting is not known");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user