Exppython:
- Added "Radio" to Material modes - Fixed bug in bone.getParent (bug report on blender.org py forum) - Added more types to object.shareFrom (method to share obdata) - Added nmesh.get/setMaxSmoothAngle and nmesh.get/setSubDivLevels - Updated NMesh doc
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -31,7 +31,13 @@
|
||||
|
||||
#include "NMesh.h"
|
||||
|
||||
#define NMESH_FRAME_MAX 18000
|
||||
#define NMESH_FRAME_MAX 18000
|
||||
#define NMESH_SMOOTHRESH 30
|
||||
#define NMESH_SMOOTHRESH_MIN 1
|
||||
#define NMESH_SMOOTHRESH_MAX 80
|
||||
#define NMESH_SUBDIV 1
|
||||
#define NMESH_SUBDIV_MIN 1
|
||||
#define NMESH_SUBDIV_MAX 6
|
||||
|
||||
void mesh_update(Mesh *mesh)
|
||||
{
|
||||
@@ -944,6 +950,61 @@ PyObject *NMesh_link(PyObject *self, PyObject *args)
|
||||
return EXPP_incr_ret(Py_None);
|
||||
}
|
||||
|
||||
static PyObject *NMesh_getMaxSmoothAngle (BPy_NMesh *self)
|
||||
{
|
||||
PyObject *attr = PyInt_FromLong (self->smoothresh);
|
||||
|
||||
if (attr) return attr;
|
||||
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get NMesh.maxSmoothAngle attribute");
|
||||
}
|
||||
|
||||
static PyObject *NMesh_setMaxSmoothAngle (PyObject *self, PyObject *args)
|
||||
{
|
||||
short value = 0;
|
||||
BPy_NMesh *nmesh = (BPy_NMesh *)self;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "h", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected an int in [1, 80] as argument");
|
||||
|
||||
nmesh->smoothresh =
|
||||
(short)EXPP_ClampInt (value, NMESH_SMOOTHRESH_MIN, NMESH_SMOOTHRESH_MAX);
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *NMesh_getSubDivLevels (BPy_NMesh *self)
|
||||
{
|
||||
PyObject *attr = Py_BuildValue ("[h,h]", self->subdiv[0], self->subdiv[1]);
|
||||
|
||||
if (attr) return attr;
|
||||
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get NMesh.subDivLevels attribute");
|
||||
}
|
||||
|
||||
static PyObject *NMesh_setSubDivLevels (PyObject *self, PyObject *args)
|
||||
{
|
||||
short display = 0, render = 0;
|
||||
BPy_NMesh *nmesh = (BPy_NMesh *)self;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "(hh)", &display, &render))
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected a sequence [int, int] as argument");
|
||||
|
||||
nmesh->subdiv[0] =
|
||||
(short)EXPP_ClampInt (display, NMESH_SUBDIV_MIN, NMESH_SUBDIV_MAX);
|
||||
|
||||
nmesh->subdiv[1] =
|
||||
(short)EXPP_ClampInt (render, NMESH_SUBDIV_MIN, NMESH_SUBDIV_MAX);
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *NMesh_getMode (BPy_NMesh *self)
|
||||
{
|
||||
PyObject *attr = PyInt_FromLong (self->mode);
|
||||
@@ -1005,8 +1066,14 @@ static struct PyMethodDef NMesh_methods[] =
|
||||
MethodDef(insertKey),
|
||||
MethodDef(removeAllKeys),
|
||||
MethodDef(update),
|
||||
{"getMode", (PyCFunction)NMesh_getMode, METH_NOARGS, NMesh_getMode_doc},
|
||||
MethodDef(setMode),
|
||||
MethodDef(setMaxSmoothAngle),
|
||||
MethodDef(setSubDivLevels),
|
||||
{"getMode", (PyCFunction)NMesh_getMode, METH_NOARGS, NMesh_getMode_doc},
|
||||
{"getMaxSmoothAngle", (PyCFunction)NMesh_getMaxSmoothAngle, METH_NOARGS,
|
||||
NMesh_getMaxSmoothAngle_doc},
|
||||
{"getSubDivLevels", (PyCFunction)NMesh_getSubDivLevels, METH_NOARGS,
|
||||
NMesh_getSubDivLevels_doc},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -1029,6 +1096,12 @@ static PyObject *NMesh_getattr(PyObject *self, char *name)
|
||||
else if (strcmp(name, "verts") == 0)
|
||||
return EXPP_incr_ret(me->verts);
|
||||
|
||||
else if (strcmp(name, "maxSmoothAngle") == 0)
|
||||
return PyInt_FromLong(me->smoothresh);
|
||||
|
||||
else if (strcmp(name, "subDivLevels") == 0)
|
||||
return Py_BuildValue("[h,h]", me->subdiv[0], me->subdiv[1]);
|
||||
|
||||
else if (strcmp(name, "users") == 0) {
|
||||
if (me->mesh) {
|
||||
return PyInt_FromLong(me->mesh->id.us);
|
||||
@@ -1042,8 +1115,9 @@ static PyObject *NMesh_getattr(PyObject *self, char *name)
|
||||
return EXPP_incr_ret(me->faces);
|
||||
|
||||
else if (strcmp(name, "__members__") == 0)
|
||||
return Py_BuildValue("[s,s,s,s,s]",
|
||||
"name", "materials", "verts", "users", "faces");
|
||||
return Py_BuildValue("[s,s,s,s,s,s,s]",
|
||||
"name", "materials", "verts", "users", "faces", "maxSmoothAngle",
|
||||
"subdivLevels");
|
||||
|
||||
return Py_FindMethod(NMesh_methods, (PyObject*)self, name);
|
||||
}
|
||||
@@ -1099,6 +1173,47 @@ static int NMesh_setattr(PyObject *self, char *name, PyObject *v)
|
||||
return EXPP_ReturnIntError (PyExc_TypeError, "expected a sequence");
|
||||
}
|
||||
|
||||
else if (!strcmp(name, "maxSmoothAngle")) {
|
||||
short smoothresh = 0;
|
||||
|
||||
if (!PyInt_Check(v))
|
||||
return EXPP_ReturnIntError (PyExc_TypeError,
|
||||
"expected int argument");
|
||||
|
||||
smoothresh = (short)PyInt_AsLong(v);
|
||||
|
||||
me->smoothresh =
|
||||
EXPP_ClampInt(smoothresh, NMESH_SMOOTHRESH_MIN, NMESH_SMOOTHRESH_MAX);
|
||||
}
|
||||
|
||||
else if (!strcmp(name, "subDivLevels")) {
|
||||
int subdiv[2] = {0,0};
|
||||
int i;
|
||||
PyObject *tmp;
|
||||
|
||||
if (!PySequence_Check(v) || (PySequence_Length(v) != 2))
|
||||
return EXPP_ReturnIntError (PyExc_TypeError,
|
||||
"expected a list [int, int] as argument");
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
tmp = PySequence_GetItem(v, i);
|
||||
if (tmp) {
|
||||
if (!PyInt_Check(tmp)) {
|
||||
Py_DECREF (tmp);
|
||||
return EXPP_ReturnIntError (PyExc_TypeError,
|
||||
"expected a list [int, int] as argument");
|
||||
}
|
||||
|
||||
subdiv[i] = PyInt_AsLong (tmp);
|
||||
me->subdiv[i] =
|
||||
(short)EXPP_ClampInt(subdiv[i], NMESH_SUBDIV_MIN, NMESH_SUBDIV_MAX);
|
||||
Py_DECREF (tmp);
|
||||
}
|
||||
else return EXPP_ReturnIntError (PyExc_RuntimeError,
|
||||
"couldn't retrieve subdiv values from list");
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
return EXPP_ReturnIntError (PyExc_AttributeError, name);
|
||||
|
||||
@@ -1241,6 +1356,10 @@ static PyObject *new_NMesh_internal(Mesh *oldmesh,
|
||||
{
|
||||
BPy_NMesh *me = PyObject_NEW (BPy_NMesh, &NMesh_Type);
|
||||
me->flags = 0;
|
||||
me->subdiv[0] = NMESH_SUBDIV;
|
||||
me->subdiv[1] = NMESH_SUBDIV;
|
||||
me->smoothresh = NMESH_SMOOTHRESH;
|
||||
|
||||
me->object = NULL; /* not linked to any object yet */
|
||||
|
||||
if (!oldmesh) {
|
||||
@@ -1276,7 +1395,10 @@ static PyObject *new_NMesh_internal(Mesh *oldmesh,
|
||||
else {
|
||||
me->name = PyString_FromString(oldmesh->id.name+2);
|
||||
me->mesh = oldmesh;
|
||||
me->mode = oldmesh->flag; /* yes, we save the mesh flags in nmesh->mode */
|
||||
me->mode = oldmesh->flag; /* yes, we save the mesh flags in nmesh->mode*/
|
||||
me->subdiv[0] = oldmesh->subdiv;
|
||||
me->subdiv[1] = oldmesh->subdivr;
|
||||
me->smoothresh = oldmesh->smoothresh;
|
||||
|
||||
mfaceints = NULL;
|
||||
msticky = oldmesh->msticky;
|
||||
@@ -1703,8 +1825,12 @@ static int convert_NMeshToMesh (Mesh *mesh, BPy_NMesh *nmesh)
|
||||
mesh->tface = NULL;
|
||||
mesh->mat = NULL;
|
||||
|
||||
/* Minor note: we used 'mode' because 'flag' was already used internally by nmesh */
|
||||
/* Minor note: we used 'mode' because 'flag' was already used internally
|
||||
* by nmesh */
|
||||
mesh->flag = nmesh->mode;
|
||||
mesh->smoothresh = nmesh->smoothresh;
|
||||
mesh->subdiv = nmesh->subdiv[0];
|
||||
mesh->subdivr = nmesh->subdiv[1];
|
||||
|
||||
/*@ material assignment moved to PutRaw */
|
||||
mesh->totvert = PySequence_Length(nmesh->verts);
|
||||
|
||||
@@ -208,6 +208,20 @@ static char NMesh_setMode_doc[] =
|
||||
"(none to 4 strings) - set the mode flags of this nmesh.\n\
|
||||
() - unset all flags.";
|
||||
|
||||
static char NMesh_getMaxSmoothAngle_doc[] =
|
||||
"() - get the max smooth angle for mesh auto smoothing.";
|
||||
|
||||
static char NMesh_setMaxSmoothAngle_doc[] =
|
||||
"(int) - set the max smooth angle for mesh auto smoothing in the range\n\
|
||||
[1,80] in degrees.";
|
||||
|
||||
static char NMesh_getSubDivLevels_doc[] =
|
||||
"() - get the subdivision levels for display and rendering: [display, render]";
|
||||
|
||||
static char NMesh_setSubDivLevels_doc[] =
|
||||
"([int, int]) - set the subdivision levels for [display, render] -- they are\n\
|
||||
clamped to the range [1,6].";
|
||||
|
||||
static char M_NMesh_New_doc[] =
|
||||
"() - returns a new, empty NMesh mesh object\n";
|
||||
|
||||
@@ -271,6 +285,8 @@ typedef struct {
|
||||
PyObject *verts;
|
||||
PyObject *faces;
|
||||
int sel_face; /*@ XXX remove */
|
||||
short smoothresh; /* max AutoSmooth angle */
|
||||
short subdiv[2]; /* SubDiv Levels: display and rendering */
|
||||
short mode; /* see the EXPP_NMESH_* defines in the beginning of this file */
|
||||
char flags;
|
||||
|
||||
|
||||
@@ -1236,6 +1236,10 @@ static PyObject *Object_shareFrom (BPy_Object *self, PyObject *args)
|
||||
switch (self->object->type)
|
||||
{
|
||||
case OB_MESH:
|
||||
case OB_LAMP:
|
||||
case OB_CAMERA: /* we can probably add the other types, too */
|
||||
case OB_ARMATURE:
|
||||
case OB_CURVE:
|
||||
oldid = (ID*) self->object->data;
|
||||
id = (ID*) object->object->data;
|
||||
self->object->data = object->object->data;
|
||||
|
||||
@@ -232,7 +232,9 @@ class NMesh:
|
||||
@cvar verts: The list of NMesh vertices (NMVerts).
|
||||
@cvar users: The number of Objects using (linked to) this mesh.
|
||||
@cvar faces: The list of NMesh faces (NMFaces).
|
||||
@cvar mode: The mode flags for this mesh. See L{setMode}
|
||||
@cvar mode: The mode flags for this mesh. See L{setMode}.
|
||||
@cvar subDivLevels: The [display, rendering] subdivision levels in [1, 6].
|
||||
@cvar maxSmoothAngle: The max angle for auto smoothing. See L{setMode}.
|
||||
"""
|
||||
|
||||
def addMaterial(material):
|
||||
@@ -483,4 +485,31 @@ class NMesh:
|
||||
@type vertList: list of ints
|
||||
@param vertList: if given, only those vertex points that are both in the
|
||||
list and group passed in are returned.
|
||||
"""
|
||||
"""
|
||||
|
||||
def getMaxSmoothAngle():
|
||||
"""
|
||||
Get the max angle for auto smoothing.
|
||||
@return: The value in degrees.
|
||||
"""
|
||||
|
||||
def setMaxSmoothAngle(angle):
|
||||
"""
|
||||
Set the max angle for auto smoothing.
|
||||
@type angle: int
|
||||
@param angle: The new value in degrees -- it's clamped to [1, 80].
|
||||
"""
|
||||
|
||||
def getSubDivLevels():
|
||||
"""
|
||||
Get the mesh subdivision levels for realtime display and rendering.
|
||||
@return: list of ints: [display, render].
|
||||
"""
|
||||
|
||||
def setSubDivLevels(subdiv):
|
||||
"""
|
||||
Set the mesh subdivision levels for realtime display and rendering.
|
||||
@type subdiv: list of 2 ints
|
||||
@param subdiv: new subdiv levels: [display, render]. Both are clamped to
|
||||
lie in the range [1, 6].
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user