exposed CustomData_get_active_layer_index in BKE_customdata.h (needed by python to get the active layer)
added python api stuff to deal with Color and UV/Image layers. me.activeUvLayer - int me.activeColorLayer - int me.totUvLayers - int me.totColorLayers - int me.addUvLayer() me.addColorLayer() me.removeUvLayer() me.removeColorLayer() Variable names may need changing.
This commit is contained in:
@@ -166,6 +166,8 @@ void *CustomData_em_get(const struct CustomData *data, void *block, int type);
|
||||
void *CustomData_get_layer(const struct CustomData *data, int type);
|
||||
void *CustomData_get_layer_n(const struct CustomData *data, int type, int n);
|
||||
|
||||
int CustomData_get_active_layer_index(const struct CustomData *data, int type);
|
||||
|
||||
/* copies the data from source to the data element at index in the first
|
||||
* layer of type
|
||||
* no effect if there is no layer of type
|
||||
|
@@ -504,7 +504,7 @@ static int CustomData_get_layer_index(const struct CustomData *data, int type)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int CustomData_get_active_layer_index(const CustomData *data, int type)
|
||||
int CustomData_get_active_layer_index(const CustomData *data, int type)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@@ -6223,6 +6223,55 @@ static PyObject *Mesh_insertKey( BPy_Mesh * self, PyObject * args )
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
void Mesh_addCustomLayer_internal(Mesh *me, int type)
|
||||
{
|
||||
int layernum = CustomData_number_of_layers(&me->fdata, type);
|
||||
|
||||
CustomData_add_layer(&me->fdata, type, CD_DEFAULT,
|
||||
NULL, me->totface);
|
||||
|
||||
CustomData_set_layer_active(&me->fdata, type, layernum);
|
||||
mesh_update_customdata_pointers(me);
|
||||
}
|
||||
|
||||
/* custom data layers */
|
||||
static PyObject *Mesh_addUvLayer( BPy_Mesh * self )
|
||||
{
|
||||
Mesh_addCustomLayer_internal(self->mesh, CD_MTFACE);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Mesh_addColorLayer( BPy_Mesh * self, PyObject * args )
|
||||
{
|
||||
Mesh_addCustomLayer_internal(self->mesh, CD_MCOL);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Mesh_removeUvLayer( BPy_Mesh * self )
|
||||
{
|
||||
Mesh *me = self->mesh;
|
||||
if (me->mtface != NULL) {
|
||||
CustomData_free_layer(&me->fdata, CD_MTFACE, me->totface);
|
||||
me->mtface= CustomData_get_layer(&me->fdata, CD_MTFACE);
|
||||
}
|
||||
mesh_update_customdata_pointers(me);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Mesh_removeColorLayer( BPy_Mesh * self )
|
||||
{
|
||||
Mesh *me = self->mesh;
|
||||
if (me->mcol != NULL) {
|
||||
CustomData_free_layer(&me->fdata, CD_MCOL, me->totface);
|
||||
me->mcol= CustomData_get_layer(&me->fdata, CD_MCOL);
|
||||
}
|
||||
mesh_update_customdata_pointers(me);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PyObject *Mesh_Tools( BPy_Mesh * self, int type, void **args )
|
||||
{
|
||||
Base *base;
|
||||
@@ -6508,6 +6557,16 @@ static struct PyMethodDef BPy_Mesh_methods[] = {
|
||||
{"recalcNormals", (PyCFunction)Mesh_recalcNormals, METH_VARARGS,
|
||||
"Recalculates inside or outside normals (experimental)"},
|
||||
|
||||
/* mesh custom data layers */
|
||||
{"addUvLayer", (PyCFunction)Mesh_addUvLayer, METH_NOARGS,
|
||||
"adds a UV layer to this mesh"},
|
||||
{"addColorLayer", (PyCFunction)Mesh_addColorLayer, METH_NOARGS,
|
||||
"adds a color layer to this mesh"},
|
||||
{"removeUvLayer", (PyCFunction)Mesh_removeUvLayer, METH_NOARGS,
|
||||
"removes a UV layer to this mesh"},
|
||||
{"removeColorLayer", (PyCFunction)Mesh_removeColorLayer, METH_NOARGS,
|
||||
"removes a color layer to this mesh"},
|
||||
|
||||
/* python standard class functions */
|
||||
{"__copy__", (PyCFunction)Mesh_copy, METH_NOARGS,
|
||||
"Return a copy of the mesh"},
|
||||
@@ -7029,6 +7088,43 @@ static int Mesh_setActiveGroup( BPy_Mesh * self, PyObject * arg )
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Mesh_getActiveLayer( BPy_Mesh * self, void *type )
|
||||
{
|
||||
int i = CustomData_get_active_layer_index(&self->mesh->fdata, (int)type);
|
||||
if (i != -1) i--; /* so -1 is for no active layer 0+ for an active layer */
|
||||
return PyInt_FromLong( i );
|
||||
}
|
||||
|
||||
static int Mesh_setActiveLayer( BPy_Mesh * self, PyObject * arg, void *type )
|
||||
{
|
||||
int i, totlayers;
|
||||
|
||||
if( !PyInt_Check( arg ) )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"expected an int argument" );
|
||||
|
||||
totlayers = CustomData_number_of_layers(&self->mesh->fdata, (int)type );
|
||||
|
||||
i = PyInt_AsLong( arg );
|
||||
|
||||
if (i >= totlayers)
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"index out of range" );
|
||||
|
||||
if (i<0)
|
||||
i = totlayers+i;
|
||||
|
||||
CustomData_set_layer_active(&self->mesh->fdata, (int)type, i);
|
||||
mesh_update_customdata_pointers(self->mesh);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *Mesh_getTotLayers( BPy_Mesh * self, void *type )
|
||||
{
|
||||
return PyInt_FromLong( CustomData_number_of_layers(&self->mesh->fdata, (int)type ) );
|
||||
}
|
||||
|
||||
static PyObject *Mesh_getTexMesh( BPy_Mesh * self )
|
||||
{
|
||||
Mesh *texme= self->mesh->texcomesh;
|
||||
@@ -7226,6 +7322,26 @@ static PyGetSetDef BPy_Mesh_getseters[] = {
|
||||
(getter)Mesh_getActiveGroup, (setter)Mesh_setActiveGroup,
|
||||
"Active group for the mesh",
|
||||
NULL},
|
||||
|
||||
{"activeColorLayer",
|
||||
(getter)Mesh_getActiveLayer, (setter)Mesh_setActiveLayer,
|
||||
"Index of the active UV layer",
|
||||
CD_MCOL},
|
||||
{"activeUvLayer",
|
||||
(getter)Mesh_getActiveLayer, (setter)Mesh_setActiveLayer,
|
||||
"Index of the active vertex color layer",
|
||||
CD_MTFACE},
|
||||
|
||||
{"totColorLayers",
|
||||
(getter)Mesh_getTotLayers, (setter)NULL,
|
||||
"Index of the active vertex color layer",
|
||||
CD_MCOL},
|
||||
|
||||
{"totUvLayers",
|
||||
(getter)Mesh_getTotLayers, (setter)NULL,
|
||||
"Index of the active vertex color layer",
|
||||
CD_MTFACE},
|
||||
|
||||
{"texMesh",
|
||||
(getter)Mesh_getTexMesh, (setter)Mesh_setTexMesh,
|
||||
"The meshes tex mesh proxy texture coord mesh",
|
||||
|
@@ -720,7 +720,7 @@ class Mesh:
|
||||
@type name: str
|
||||
@ivar subDivLevels: The [display, rendering] subdivision levels in [1, 6].
|
||||
@type subDivLevels: list of 2 ints
|
||||
@ivar users: The number of Objects using (linked to) this mesh.
|
||||
@ivar users: The number of Objects using (linked to) this mesh. (read only)
|
||||
@type users: int
|
||||
|
||||
@ivar faceUV: The mesh contains UV-mapped textured faces. Enabling faceUV
|
||||
@@ -750,6 +750,17 @@ class Mesh:
|
||||
@ivar texMesh: The mesh's texMesh setting, used so coordinates from another
|
||||
mesh can be used for rendering textures.
|
||||
@type texMesh: Mesh or None
|
||||
|
||||
@ivar activeUvLayer: The mesh's active UV/Image layer index. -1 if there is no UV/Image layers.
|
||||
@type activeUvLayer: int
|
||||
@ivar activeColorLayer: The mesh's active Vertex Color layer index. -1 if there is no UV/Image layers.
|
||||
@type activeColorLayer: int
|
||||
|
||||
@ivar totUvLayers: The mesh's total number of UV/Image layers.
|
||||
@type totUvLayers: int
|
||||
@ivar totColorLayers: The mesh's total number of Vertex Color layers.
|
||||
@type totColorLayers: int
|
||||
|
||||
"""
|
||||
|
||||
def getFromObject(object, cage=0, render=0):
|
||||
@@ -991,6 +1002,25 @@ class Mesh:
|
||||
Blender itself later).
|
||||
"""
|
||||
|
||||
def addUvLayer():
|
||||
"""
|
||||
Adds a new UV/Image layer to this mesh, it will always be the last layer and made active.
|
||||
"""
|
||||
|
||||
def addColorLayer():
|
||||
"""
|
||||
Adds a new Vertex Color layer to this mesh, it will always be the last layer and made active.
|
||||
"""
|
||||
|
||||
def removeUvLayer():
|
||||
"""
|
||||
Removes the active UV/Image layer.
|
||||
"""
|
||||
|
||||
def removeColorLayer():
|
||||
"""
|
||||
Removes the active Vertex Color layer.
|
||||
"""
|
||||
|
||||
def smooth():
|
||||
"""
|
||||
|
Reference in New Issue
Block a user