added CustomData_add_layer_named, same as CustomData_add_layer but accepts a name. saves Mesh.c having to look up the data after adding (just to rename it)
This commit is contained in:
@@ -83,6 +83,9 @@ void CustomData_free_temporary(struct CustomData *data, int totelem);
|
|||||||
*/
|
*/
|
||||||
void *CustomData_add_layer(struct CustomData *data, int type, int alloctype,
|
void *CustomData_add_layer(struct CustomData *data, int type, int alloctype,
|
||||||
void *layer, int totelem);
|
void *layer, int totelem);
|
||||||
|
/*same as above but accepts a name */
|
||||||
|
void *CustomData_add_layer_named(struct CustomData *data, int type, int alloctype,
|
||||||
|
void *layer, int totelem, char *name);
|
||||||
|
|
||||||
/* frees the active or first data layer with the give type.
|
/* frees the active or first data layer with the give type.
|
||||||
* returns 1 on succes, 0 if no layer with the given type is found
|
* returns 1 on succes, 0 if no layer with the given type is found
|
||||||
|
|||||||
@@ -639,6 +639,23 @@ void *CustomData_add_layer(CustomData *data, int type, int alloctype,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*same as above but accepts a name*/
|
||||||
|
void *CustomData_add_layer_named(CustomData *data, int type, int alloctype,
|
||||||
|
void *layerdata, int totelem, char *name)
|
||||||
|
{
|
||||||
|
CustomDataLayer *layer;
|
||||||
|
const LayerTypeInfo *typeInfo= layerType_getInfo(type);
|
||||||
|
|
||||||
|
layer = customData_add_layer__internal(data, type, alloctype, layerdata,
|
||||||
|
totelem, name);
|
||||||
|
|
||||||
|
if(layer)
|
||||||
|
return layer->data;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int CustomData_free_layer(CustomData *data, int type, int totelem, int index)
|
int CustomData_free_layer(CustomData *data, int type, int totelem, int index)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
@@ -6356,30 +6356,22 @@ static PyObject *Mesh_insertKey( BPy_Mesh * self, PyObject * args )
|
|||||||
|
|
||||||
static PyObject * Mesh_addCustomLayer_internal(Mesh *me, PyObject * args, int type)
|
static PyObject * Mesh_addCustomLayer_internal(Mesh *me, PyObject * args, int type)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
void *layer_data;
|
|
||||||
CustomData *data = &me->fdata;
|
CustomData *data = &me->fdata;
|
||||||
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
||||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||||
"expected a string or nothing" );
|
"expected a string or nothing" );
|
||||||
|
|
||||||
layer_data = CustomData_add_layer(data, type, CD_DEFAULT,
|
|
||||||
NULL, me->totface);
|
|
||||||
|
|
||||||
if (name && layer_data) {
|
|
||||||
|
|
||||||
if (strlen(name)>31)
|
if (strlen(name)>31)
|
||||||
return EXPP_ReturnPyObjError( PyExc_ValueError,
|
return EXPP_ReturnPyObjError( PyExc_ValueError,
|
||||||
"error, maximum name length is 31" );
|
"error, maximum name length is 31" );
|
||||||
|
|
||||||
for(i = 0; i < data->totlayer; i++) {
|
if (name)
|
||||||
if (data->layers[i].data == layer_data ) {
|
CustomData_add_layer_named(data, type, CD_DEFAULT,
|
||||||
BLI_strncpy(data->layers[i].name, name, 31);
|
NULL, me->totface, name);
|
||||||
CustomData_set_layer_unique_name(&me->fdata, i);
|
else
|
||||||
}
|
CustomData_add_layer(data, type, CD_DEFAULT,
|
||||||
}
|
NULL, me->totface);
|
||||||
}
|
|
||||||
mesh_update_customdata_pointers(me);
|
mesh_update_customdata_pointers(me);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user