* Updated NMesh port to exppython:
Added material and image handling/hooks and the constant dictionaries. Changed Image.h and Material.h to only have public declarations, so NMesh could include them.
This commit is contained in:
@@ -29,11 +29,71 @@
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <BKE_main.h>
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_library.h>
|
||||
#include <BKE_image.h>
|
||||
#include <BLI_blenlib.h>
|
||||
|
||||
#include "gen_utils.h"
|
||||
|
||||
#include "Image.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Image_New */
|
||||
/* Python equivalent: Blender.Image.New */
|
||||
/* Python C_Image defaults: */
|
||||
/*****************************************************************************/
|
||||
#define EXPP_IMAGE_REP 1
|
||||
#define EXPP_IMAGE_REP_MIN 1
|
||||
#define EXPP_IMAGE_REP_MAX 16
|
||||
|
||||
|
||||
/************************/
|
||||
/*** The Image Module ***/
|
||||
/************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Image module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Image_New (PyObject *self, PyObject *args,
|
||||
PyObject *keywords);
|
||||
static PyObject *M_Image_Get (PyObject *self, PyObject *args);
|
||||
static PyObject *M_Image_Load (PyObject *self, PyObject *args);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* The following string definitions are used for documentation strings. */
|
||||
/* In Python these will be written to the console when doing a */
|
||||
/* Blender.Image.__doc__ */
|
||||
/*****************************************************************************/
|
||||
static char M_Image_doc[] =
|
||||
"The Blender Image module\n\n";
|
||||
|
||||
static char M_Image_New_doc[] =
|
||||
"() - return a new Image object -- unimplemented";
|
||||
|
||||
static char M_Image_Get_doc[] =
|
||||
"(name) - return the image with the name 'name', \
|
||||
returns None if not found.\n If 'name' is not specified, \
|
||||
it returns a list of all images in the\ncurrent scene.";
|
||||
|
||||
static char M_Image_Load_doc[] =
|
||||
"(filename) - return image from file filename as Image Object, \
|
||||
returns None if not found.\n";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Image module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_Image_methods[] = {
|
||||
{"New",(PyCFunction)M_Image_New, METH_VARARGS|METH_KEYWORDS,
|
||||
M_Image_New_doc},
|
||||
{"Get", M_Image_Get, METH_VARARGS, M_Image_Get_doc},
|
||||
{"get", M_Image_Get, METH_VARARGS, M_Image_Get_doc},
|
||||
{"Load", M_Image_Load, METH_VARARGS, M_Image_Load_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Image_New */
|
||||
/* Python equivalent: Blender.Image.New */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Image_New(PyObject *self, PyObject *args, PyObject *keywords)
|
||||
{
|
||||
@@ -155,6 +215,115 @@ PyObject *M_Image_Init (void)
|
||||
return (submodule);
|
||||
}
|
||||
|
||||
/************************/
|
||||
/*** The Image PyType ***/
|
||||
/************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Image methods declarations: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Image_getName(C_Image *self);
|
||||
static PyObject *Image_getFilename(C_Image *self);
|
||||
static PyObject *Image_setName(C_Image *self, PyObject *args);
|
||||
static PyObject *Image_setXRep(C_Image *self, PyObject *args);
|
||||
static PyObject *Image_setYRep(C_Image *self, PyObject *args);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Image methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef C_Image_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"getName", (PyCFunction)Image_getName, METH_NOARGS,
|
||||
"() - Return Image Data name"},
|
||||
{"getFilename", (PyCFunction)Image_getFilename, METH_VARARGS,
|
||||
"() - Return Image Data filename"},
|
||||
{"setName", (PyCFunction)Image_setName, METH_VARARGS,
|
||||
"(str) - Change Image Data name"},
|
||||
{"setXRep", (PyCFunction)Image_setXRep, METH_VARARGS,
|
||||
"(int) - Change Image Data x repetition value"},
|
||||
{"setYRep", (PyCFunction)Image_setYRep, METH_VARARGS,
|
||||
"(int) - Change Image Data y repetition value"},
|
||||
{0}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Image_Type callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static void Image_Dealloc (C_Image *self);
|
||||
static int Image_SetAttr (C_Image *self, char *name, PyObject *v);
|
||||
static int Image_Compare (C_Image *a, C_Image *b);
|
||||
static int Image_Print (C_Image *self, FILE *fp, int flags);
|
||||
static PyObject *Image_GetAttr (C_Image *self, char *name);
|
||||
static PyObject *Image_Repr (C_Image *self);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Image_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Image_Type =
|
||||
{
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /* ob_size */
|
||||
"Image", /* tp_name */
|
||||
sizeof (C_Image), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor)Image_Dealloc, /* tp_dealloc */
|
||||
(printfunc)Image_Print, /* tp_print */
|
||||
(getattrfunc)Image_GetAttr, /* tp_getattr */
|
||||
(setattrfunc)Image_SetAttr, /* tp_setattr */
|
||||
(cmpfunc)Image_Compare, /* tp_compare */
|
||||
(reprfunc)Image_Repr, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_as_hash */
|
||||
0,0,0,0,0,0,
|
||||
0, /* tp_doc */
|
||||
0,0,0,0,0,0,
|
||||
C_Image_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: ImageDealloc */
|
||||
/* Description: This is a callback function for the C_Image type. It is */
|
||||
/* the destructor function. */
|
||||
/*****************************************************************************/
|
||||
static void Image_Dealloc (C_Image *self)
|
||||
{
|
||||
PyObject_DEL (self);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Image_CreatePyObject */
|
||||
/* Description: This function will create a new C_Image from an existing */
|
||||
/* Blender image structure. */
|
||||
/*****************************************************************************/
|
||||
PyObject *Image_CreatePyObject (Image *image)
|
||||
{
|
||||
C_Image *py_img;
|
||||
|
||||
py_img = (C_Image *)PyObject_NEW (C_Image, &Image_Type);
|
||||
|
||||
if (!py_img)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create C_Image object");
|
||||
|
||||
py_img->image = image;
|
||||
|
||||
return (PyObject *)py_img;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Image_CheckPyObject */
|
||||
/* Description: This function returns true when the given PyObject is of the */
|
||||
/* type Image. Otherwise it will return false. */
|
||||
/*****************************************************************************/
|
||||
int Image_CheckPyObject (PyObject *pyobj)
|
||||
{
|
||||
return (pyobj->ob_type == &Image_Type);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Image methods: */
|
||||
/*****************************************************************************/
|
||||
@@ -232,22 +401,12 @@ static PyObject *Image_setYRep(C_Image *self, PyObject *args)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: ImageDeAlloc */
|
||||
/* Description: This is a callback function for the C_Image type. It is */
|
||||
/* the destructor function. */
|
||||
/*****************************************************************************/
|
||||
static void ImageDeAlloc (C_Image *self)
|
||||
{
|
||||
PyObject_DEL (self);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: ImageGetAttr */
|
||||
/* Description: This is a callback function for the C_Image type. It is */
|
||||
/* the function that accesses C_Image member variables and */
|
||||
/* Function: Image_GetAttr */
|
||||
/* Description: This is a callback function for the C_Image type. It is */
|
||||
/* the function that accesses C_Image member variables and */
|
||||
/* methods. */
|
||||
/*****************************************************************************/
|
||||
static PyObject* ImageGetAttr (C_Image *self, char *name)
|
||||
static PyObject *Image_GetAttr (C_Image *self, char *name)
|
||||
{
|
||||
PyObject *attr = Py_None;
|
||||
|
||||
@@ -275,12 +434,12 @@ static PyObject* ImageGetAttr (C_Image *self, char *name)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: ImageSetAttr */
|
||||
/* Description: This is a callback function for the C_Image type. It is the */
|
||||
/* function that changes Image Data members values. If this */
|
||||
/* data is linked to a Blender Image, it also gets updated. */
|
||||
/* Function: Image_SetAttr */
|
||||
/* Description: This is a callback function for the C_Image type. It is the */
|
||||
/* function that changes Image Data members values. If this */
|
||||
/* data is linked to a Blender Image, it also gets updated. */
|
||||
/*****************************************************************************/
|
||||
static int ImageSetAttr (C_Image *self, char *name, PyObject *value)
|
||||
static int Image_SetAttr (C_Image *self, char *name, PyObject *value)
|
||||
{
|
||||
PyObject *valtuple;
|
||||
PyObject *error = NULL;
|
||||
@@ -290,7 +449,7 @@ static int ImageSetAttr (C_Image *self, char *name, PyObject *value)
|
||||
* function anyway, since it already has error checking, clamps to the right
|
||||
* interval and updates the Blender Image structure when necessary. */
|
||||
|
||||
valtuple = Py_BuildValue("(N)", value); /* the set* functions expect a tuple */
|
||||
valtuple = Py_BuildValue("(N)", value); /*the set* functions expect a tuple*/
|
||||
|
||||
if (!valtuple)
|
||||
return EXPP_ReturnIntError(PyExc_MemoryError,
|
||||
@@ -318,36 +477,36 @@ static int ImageSetAttr (C_Image *self, char *name, PyObject *value)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: ImageCompare */
|
||||
/* Function: Image_Compare */
|
||||
/* Description: This is a callback function for the C_Image type. It */
|
||||
/* compares two Image_Type objects. Only the "==" and "!=" */
|
||||
/* comparisons are meaninful. Returns 0 for equality and -1 if */
|
||||
/* they don't point to the same Blender Image struct. */
|
||||
/* In Python it becomes 1 if they are equal, 0 otherwise. */
|
||||
/*****************************************************************************/
|
||||
static int ImageCompare (C_Image *a, C_Image *b)
|
||||
static int Image_Compare (C_Image *a, C_Image *b)
|
||||
{
|
||||
Image *pa = a->image, *pb = b->image;
|
||||
return (pa == pb) ? 0:-1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: ImagePrint */
|
||||
/* Description: This is a callback function for the C_Image type. It */
|
||||
/* builds a meaninful string to 'print' image objects. */
|
||||
/* Function: Image_Print */
|
||||
/* Description: This is a callback function for the C_Image type. It */
|
||||
/* builds a meaninful string to 'print' image objects. */
|
||||
/*****************************************************************************/
|
||||
static int ImagePrint(C_Image *self, FILE *fp, int flags)
|
||||
static int Image_Print(C_Image *self, FILE *fp, int flags)
|
||||
{
|
||||
fprintf(fp, "[Image \"%s\"]", self->image->id.name+2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: ImageRepr */
|
||||
/* Description: This is a callback function for the C_Image type. It */
|
||||
/* builds a meaninful string to represent image objects. */
|
||||
/* Function: Image_Repr */
|
||||
/* Description: This is a callback function for the C_Image type. It */
|
||||
/* builds a meaninful string to represent image objects. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *ImageRepr (C_Image *self)
|
||||
static PyObject *Image_Repr (C_Image *self)
|
||||
{
|
||||
return PyString_FromString(self->image->id.name+2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user