* 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,8 +29,68 @@
|
||||
* ***** 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"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* 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 */
|
||||
@@ -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 */
|
||||
/* 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 */
|
||||
/* 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 */
|
||||
/* 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 */
|
||||
/* 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);
|
||||
}
|
||||
|
@@ -33,136 +33,27 @@
|
||||
#define EXPP_IMAGE_H
|
||||
|
||||
#include <Python.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <BKE_main.h>
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_library.h>
|
||||
#include <BKE_image.h>
|
||||
#include <BLI_blenlib.h>
|
||||
#include <DNA_image_types.h>
|
||||
|
||||
#include "gen_utils.h"
|
||||
#include "modules.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Image defaults: */
|
||||
/*****************************************************************************/
|
||||
#define EXPP_IMAGE_REP 1
|
||||
#define EXPP_IMAGE_REP_MIN 1
|
||||
#define EXPP_IMAGE_REP_MAX 16
|
||||
|
||||
/*****************************************************************************/
|
||||
/* 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__ */
|
||||
/*****************************************************************************/
|
||||
char M_Image_doc[] =
|
||||
"The Blender Image module\n\n";
|
||||
|
||||
char M_Image_New_doc[] =
|
||||
"() - return a new Image object -- unimplemented";
|
||||
|
||||
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.";
|
||||
|
||||
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}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Image structure definition: */
|
||||
/* Python C_Image structure definition */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Image *image;
|
||||
|
||||
} C_Image;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* 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);
|
||||
PyTypeObject Image_Type; /* The Image PyType Object */
|
||||
|
||||
#define C_Image_Check(v) ((v)->ob_type == &Image_Type) /* for type checking */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Image methods table: */
|
||||
/* Module Blender.Image - public functions */
|
||||
/*****************************************************************************/
|
||||
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 ImageDeAlloc (C_Image *self);
|
||||
static int ImagePrint (C_Image *self, FILE *fp, int flags);
|
||||
static int ImageSetAttr (C_Image *self, char *name, PyObject *v);
|
||||
static PyObject *ImageGetAttr (C_Image *self, char *name);
|
||||
static int ImageCompare (C_Image *a, C_Image *b);
|
||||
static PyObject *ImageRepr (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)ImageDeAlloc, /* tp_dealloc */
|
||||
(printfunc)ImagePrint, /* tp_print */
|
||||
(getattrfunc)ImageGetAttr, /* tp_getattr */
|
||||
(setattrfunc)ImageSetAttr, /* tp_setattr */
|
||||
(cmpfunc)ImageCompare, /* tp_compare */
|
||||
(reprfunc)ImageRepr, /* 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 */
|
||||
};
|
||||
PyObject *M_Image_Init (void);
|
||||
PyObject *Image_CreatePyObject (Image *image);
|
||||
int Image_CheckPyObject (PyObject *pyobj);
|
||||
|
||||
#endif /* EXPP_IMAGE_H */
|
||||
|
@@ -29,8 +29,118 @@
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <BKE_main.h>
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_library.h>
|
||||
#include <MEM_guardedalloc.h>
|
||||
#include <DNA_ID.h>
|
||||
#include <BLI_blenlib.h>
|
||||
|
||||
#include "constant.h"
|
||||
#include "gen_utils.h"
|
||||
|
||||
#include "Material.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Material defaults: */
|
||||
/*****************************************************************************/
|
||||
#define EXPP_MAT_MODE_TRACEABLE MA_TRACEBLE
|
||||
#define EXPP_MAT_MODE_SHADOW MA_SHADOW
|
||||
#define EXPP_MAT_MODE_SHADELESS MA_SHLESS
|
||||
#define EXPP_MAT_MODE_WIRE MA_WIRE
|
||||
#define EXPP_MAT_MODE_VCOLLIGHT MA_VERTEXCOL
|
||||
#define EXPP_MAT_MODE_HALO MA_HALO
|
||||
#define EXPP_MAT_MODE_ZTRANSP MA_ZTRA
|
||||
#define EXPP_MAT_MODE_VCOLPAINT MA_VERTEXCOLP
|
||||
#define EXPP_MAT_MODE_ZINVERT MA_ZINV
|
||||
#define EXPP_MAT_MODE_HALORINGS MA_HALO_RINGS
|
||||
#define EXPP_MAT_MODE_ENV MA_ENV
|
||||
#define EXPP_MAT_MODE_HALOLINES MA_HALO_LINES
|
||||
#define EXPP_MAT_MODE_ONLYSHADOW MA_ONLYSHADOW
|
||||
#define EXPP_MAT_MODE_XALPHA MA_HALO_XALPHA
|
||||
#define EXPP_MAT_MODE_STAR MA_STAR
|
||||
#define EXPP_MAT_MODE_FACETEX MA_FACETEXTURE
|
||||
#define EXPP_MAT_MODE_HALOTEX MA_HALOTEX
|
||||
#define EXPP_MAT_MODE_HALOPUNO MA_HALOPUNO
|
||||
#define EXPP_MAT_MODE_NOMIST MA_NOMIST
|
||||
#define EXPP_MAT_MODE_HALOSHADE MA_HALO_SHADE
|
||||
#define EXPP_MAT_MODE_HALOFLARE MA_HALO_FLARE
|
||||
|
||||
/* Material MIN, MAX values */
|
||||
#define EXPP_MAT_ADD_MIN 0.0
|
||||
#define EXPP_MAT_ADD_MAX 1.0
|
||||
#define EXPP_MAT_ALPHA_MIN 0.0
|
||||
#define EXPP_MAT_ALPHA_MAX 1.0
|
||||
#define EXPP_MAT_AMB_MIN 0.0
|
||||
#define EXPP_MAT_AMB_MAX 1.0
|
||||
#define EXPP_MAT_ANG_MIN 0.0 /* XXX Confirm these two */
|
||||
#define EXPP_MAT_ANG_MAX 1.0
|
||||
#define EXPP_MAT_COL_MIN 0.0 /* min/max for all ... */
|
||||
#define EXPP_MAT_COL_MAX 1.0 /* ... color triplets */
|
||||
#define EXPP_MAT_EMIT_MIN 0.0
|
||||
#define EXPP_MAT_EMIT_MAX 1.0
|
||||
#define EXPP_MAT_REF_MIN 0.0
|
||||
#define EXPP_MAT_REF_MAX 1.0
|
||||
#define EXPP_MAT_SPEC_MIN 0.0
|
||||
#define EXPP_MAT_SPEC_MAX 2.0
|
||||
#define EXPP_MAT_SPECTRA_MIN 0.0
|
||||
#define EXPP_MAT_SPECTRA_MAX 1.0
|
||||
#define EXPP_MAT_ZOFFS_MIN 0.0
|
||||
#define EXPP_MAT_ZOFFS_MAX 10.0
|
||||
#define EXPP_MAT_HALOSIZE_MIN 0.0
|
||||
#define EXPP_MAT_HALOSIZE_MAX 100.0
|
||||
#define EXPP_MAT_FLARESIZE_MIN 0.1
|
||||
#define EXPP_MAT_FLARESIZE_MAX 25.0
|
||||
#define EXPP_MAT_FLAREBOOST_MIN 0.1
|
||||
#define EXPP_MAT_FLAREBOOST_MAX 10.0
|
||||
#define EXPP_MAT_SUBSIZE_MIN 0.1
|
||||
#define EXPP_MAT_SUBSIZE_MAX 25.0
|
||||
|
||||
#define EXPP_MAT_HARD_MIN 1
|
||||
#define EXPP_MAT_HARD_MAX 255 /* 127 with MODE HALO ON */
|
||||
#define EXPP_MAT_NFLARES_MIN 1
|
||||
#define EXPP_MAT_NFLARES_MAX 32
|
||||
#define EXPP_MAT_NSTARS_MIN 3
|
||||
#define EXPP_MAT_NSTARS_MAX 50
|
||||
#define EXPP_MAT_NLINES_MIN 0
|
||||
#define EXPP_MAT_NLINES_MAX 250
|
||||
#define EXPP_MAT_NRINGS_MIN 0
|
||||
#define EXPP_MAT_NRINGS_MAX 24
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Material module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Material_New (PyObject *self, PyObject *args,
|
||||
PyObject *keywords);
|
||||
static PyObject *M_Material_Get (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.Material.__doc__ */
|
||||
/*****************************************************************************/
|
||||
static char M_Material_doc[] =
|
||||
"The Blender Material module";
|
||||
|
||||
static char M_Material_New_doc[] =
|
||||
"(name) - return a new material called 'name'\n\
|
||||
() - return a new material called 'Mat'";
|
||||
|
||||
static char M_Material_Get_doc[] =
|
||||
"(name) - return the material called 'name', None if not found.\n\
|
||||
() - return a list of all materials in the current scene.";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Material module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_Material_methods[] = {
|
||||
{"New",(PyCFunction)M_Material_New, METH_VARARGS|METH_KEYWORDS,
|
||||
M_Material_New_doc},
|
||||
{"Get", M_Material_Get, METH_VARARGS, M_Material_Get_doc},
|
||||
{"get", M_Material_Get, METH_VARARGS, M_Material_Get_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Material_New */
|
||||
/* Python equivalent: Blender.Material.New */
|
||||
@@ -53,7 +163,7 @@ static PyObject *M_Material_New(PyObject *self, PyObject *args, PyObject *keywor
|
||||
blmat = add_material(name); /* first create the Material Data in Blender */
|
||||
|
||||
if (blmat) /* now create the wrapper obj in Python */
|
||||
pymat = (C_Material *)Material_createPyObject (blmat);
|
||||
pymat = (C_Material *)Material_CreatePyObject (blmat);
|
||||
else
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't create Material Data in Blender"));
|
||||
@@ -91,7 +201,7 @@ static PyObject *M_Material_Get(PyObject *self, PyObject *args)
|
||||
while ((mat_iter) && (wanted_mat == NULL)) {
|
||||
|
||||
if (strcmp (name, mat_iter->id.name+2) == 0)
|
||||
wanted_mat = (C_Material *)Material_createPyObject (mat_iter);
|
||||
wanted_mat = (C_Material *)Material_CreatePyObject (mat_iter);
|
||||
|
||||
mat_iter = mat_iter->id.next;
|
||||
}
|
||||
@@ -146,6 +256,275 @@ PyObject *M_Material_Init (void)
|
||||
return (submodule);
|
||||
}
|
||||
|
||||
/***************************/
|
||||
/*** The Material PyType ***/
|
||||
/***************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Material methods declarations: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Material_getName(C_Material *self);
|
||||
static PyObject *Material_getMode(C_Material *self);
|
||||
static PyObject *Material_getRGBCol(C_Material *self);
|
||||
static PyObject *Material_getAmbCol(C_Material *self);
|
||||
static PyObject *Material_getSpecCol(C_Material *self);
|
||||
static PyObject *Material_getMirCol(C_Material *self);
|
||||
static PyObject *Material_getAmb(C_Material *self);
|
||||
static PyObject *Material_getAng(C_Material *self);
|
||||
static PyObject *Material_getEmit(C_Material *self);
|
||||
static PyObject *Material_getAlpha(C_Material *self);
|
||||
static PyObject *Material_getRef(C_Material *self);
|
||||
static PyObject *Material_getSpec(C_Material *self);
|
||||
static PyObject *Material_getSpecTransp(C_Material *self);
|
||||
static PyObject *Material_getAdd(C_Material *self);
|
||||
static PyObject *Material_getZOffset(C_Material *self);
|
||||
static PyObject *Material_getHaloSize(C_Material *self);
|
||||
static PyObject *Material_getFlareSize(C_Material *self);
|
||||
static PyObject *Material_getFlareBoost(C_Material *self);
|
||||
static PyObject *Material_getSubSize(C_Material *self);
|
||||
static PyObject *Material_getHardness(C_Material *self);
|
||||
static PyObject *Material_getNFlares(C_Material *self);
|
||||
static PyObject *Material_getNStars(C_Material *self);
|
||||
static PyObject *Material_getNLines(C_Material *self);
|
||||
static PyObject *Material_getNRings(C_Material *self);
|
||||
static PyObject *Material_setName(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setMode(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setIntMode(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setRGBCol(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setAmbCol(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setSpecCol(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setMirCol(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setAmb(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setEmit(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setAng(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setAlpha(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setRef(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setSpec(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setSpecTransp(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setAdd(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setZOffset(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setHaloSize(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setFlareSize(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setFlareBoost(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setSubSize(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setHardness(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setNFlares(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setNStars(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setNLines(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setNRings(C_Material *self, PyObject *args);
|
||||
|
||||
static PyObject *Material_setColorComponent(C_Material *self, char *key,
|
||||
PyObject *args);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Material methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef C_Material_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"getName", (PyCFunction)Material_getName, METH_NOARGS,
|
||||
"() - Return Material Data name"},
|
||||
{"getMode", (PyCFunction)Material_getMode, METH_NOARGS,
|
||||
"() - Return Material mode flags"},
|
||||
{"getRGBCol", (PyCFunction)Material_getRGBCol, METH_NOARGS,
|
||||
"() - Return Material's rgb color triplet"},
|
||||
{"getAmbCol", (PyCFunction)Material_getAmbCol, METH_NOARGS,
|
||||
"() - Return Material's ambient color"},
|
||||
{"getSpecCol", (PyCFunction)Material_getSpecCol, METH_NOARGS,
|
||||
"() - Return Material's specular color"},
|
||||
{"getMirCol", (PyCFunction)Material_getMirCol, METH_NOARGS,
|
||||
"() - Return Material's mirror color"},
|
||||
{"getAmb", (PyCFunction)Material_getAmb, METH_NOARGS,
|
||||
"() - Return Material's ambient color blend factor"},
|
||||
{"getAng", (PyCFunction)Material_getAng, METH_NOARGS,
|
||||
"() - Return Material's ????"},
|
||||
{"getEmit", (PyCFunction)Material_getEmit, METH_NOARGS,
|
||||
"() - Return Material's emitting light intensity"},
|
||||
{"getAlpha", (PyCFunction)Material_getAlpha, METH_NOARGS,
|
||||
"() - Return Material's alpha (transparency) value"},
|
||||
{"getRef", (PyCFunction)Material_getRef, METH_NOARGS,
|
||||
"() - Return Material's reflectivity"},
|
||||
{"getSpec", (PyCFunction)Material_getSpec, METH_NOARGS,
|
||||
"() - Return Material's specularity"},
|
||||
{"getSpecTransp", (PyCFunction)Material_getSpecTransp, METH_NOARGS,
|
||||
"() - Return Material's specular transparency"},
|
||||
{"getAdd", (PyCFunction)Material_getAdd, METH_NOARGS,
|
||||
"() - Return Material's glow factor"},
|
||||
{"getZOffset", (PyCFunction)Material_getZOffset, METH_NOARGS,
|
||||
"() - Return Material's artificial offset "},
|
||||
{"getHaloSize", (PyCFunction)Material_getHaloSize, METH_NOARGS,
|
||||
"() - Return Material's halo size"},
|
||||
{"getFlareSize", (PyCFunction)Material_getFlareSize, METH_NOARGS,
|
||||
"() - Return Material's (flare size)/(halo size) factor"},
|
||||
{"getFlareBoost", (PyCFunction)Material_getFlareBoost, METH_NOARGS,
|
||||
"() - Return Material's flare boost"},
|
||||
{"getSubSize", (PyCFunction)Material_getSubSize, METH_NOARGS,
|
||||
"() - Return Material's dimension of subflare, dots and circles"},
|
||||
{"getHardness", (PyCFunction)Material_getHardness, METH_NOARGS,
|
||||
"() - Return Material's hardness"},
|
||||
{"getNFlares", (PyCFunction)Material_getNFlares, METH_NOARGS,
|
||||
"() - Return Material's number of flares in halo"},
|
||||
{"getNStars", (PyCFunction)Material_getNStars, METH_NOARGS,
|
||||
"() - Return Material's number of stars in halo"},
|
||||
{"getNLines", (PyCFunction)Material_getNLines, METH_NOARGS,
|
||||
"() - Return Material's number of lines in halo"},
|
||||
{"getNRings", (PyCFunction)Material_getNRings, METH_NOARGS,
|
||||
"() - Return Material's number of rings in halo"},
|
||||
{"setName", (PyCFunction)Material_setName, METH_VARARGS,
|
||||
"(s) - Change Material Data name"},
|
||||
{"setMode", (PyCFunction)Material_setMode, METH_VARARGS,
|
||||
"([s[,s]]) - Set Material mode flag(s)"},
|
||||
{"setRGBCol", (PyCFunction)Material_setMode, METH_VARARGS,
|
||||
"([s[,s]]) - Set Material's rgb color triplet"},
|
||||
{"setAmbCol", (PyCFunction)Material_setMode, METH_VARARGS,
|
||||
"([s[,s]]) - Set Material's ambient color"},
|
||||
{"setSpecCol", (PyCFunction)Material_setMode, METH_VARARGS,
|
||||
"([s[,s]]) - Set Material's specular color"},
|
||||
{"setMirCol", (PyCFunction)Material_setMode, METH_VARARGS,
|
||||
"([s[,s]]) - Set Material's mirror color"},
|
||||
{"setAmb", (PyCFunction)Material_setAmb, METH_VARARGS,
|
||||
"(f) - Set how much the Material's color is affected"
|
||||
" by \nthe global ambient colors - [0.0, 1.0]"},
|
||||
{"setAng", (PyCFunction)Material_setAng, METH_VARARGS,
|
||||
"(f) - Set Material's ?????"},
|
||||
{"setEmit", (PyCFunction)Material_setEmit, METH_VARARGS,
|
||||
"(f) - Set Material's emitting light intensity - [0.0, 1.0]"},
|
||||
{"setAlpha", (PyCFunction)Material_setAlpha, METH_VARARGS,
|
||||
"(f) - Set Material's alpha (transparency) - [0.0, 1.0]"},
|
||||
{"setRef", (PyCFunction)Material_setRef, METH_VARARGS,
|
||||
"(f) - Set Material's reflectivity - [0.0, 1.0]"},
|
||||
{"setSpec", (PyCFunction)Material_setSpec, METH_VARARGS,
|
||||
"(f) - Set Material's specularity - [0.0, 2.0]"},
|
||||
{"setSpecTransp", (PyCFunction)Material_setSpecTransp, METH_VARARGS,
|
||||
"(f) - Set Material's specular transparency - [0.0, 1.0]"},
|
||||
{"setAdd", (PyCFunction)Material_setAdd, METH_VARARGS,
|
||||
"(f) - Set Material's glow factor - [0.0, 1.0]"},
|
||||
{"setZOffset", (PyCFunction)Material_setZOffset, METH_VARARGS,
|
||||
"(f) - Set Material's artificial offset - [0.0, 10.0]"},
|
||||
{"setHaloSize", (PyCFunction)Material_setHaloSize, METH_VARARGS,
|
||||
"(f) - Set Material's halo size - [0.0, 100.0]"},
|
||||
{"setFlareSize", (PyCFunction)Material_setFlareSize, METH_VARARGS,
|
||||
"(f) - Set Material's factor: (flare size)/(halo size) - [0.1, 25.0]"},
|
||||
{"setFlareBoost", (PyCFunction)Material_setFlareBoost, METH_VARARGS,
|
||||
"(f) - Set Material's flare boost - [0.1, 10.0]"},
|
||||
{"setSubSize", (PyCFunction)Material_setSubSize, METH_VARARGS,
|
||||
"(f) - Set Material's dimension of subflare,"
|
||||
" dots and circles - [0.1, 25.0]"},
|
||||
{"setHardness", (PyCFunction)Material_setFlareBoost, METH_VARARGS,
|
||||
"(f) - Set Material's hardness - [1, 255 (127 if halo mode is ON)]"},
|
||||
{"setNFlares", (PyCFunction)Material_setFlareBoost, METH_VARARGS,
|
||||
"(f) - Set Material's number of flares in halo - [1, 32]"},
|
||||
{"setNStars", (PyCFunction)Material_setFlareBoost, METH_VARARGS,
|
||||
"(f) - Set Material's number of stars in halo - [3, 50]"},
|
||||
{"setNLines", (PyCFunction)Material_setFlareBoost, METH_VARARGS,
|
||||
"(f) - Set Material's number of lines in halo - [0, 250]"},
|
||||
{"setNRings", (PyCFunction)Material_setNRings, METH_VARARGS,
|
||||
"(f) - Set Material's number of rings in halo - [0, 24]"},
|
||||
{0}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Material_Type callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static void Material_Dealloc (C_Material *self);
|
||||
static int Material_Print (C_Material *self, FILE *fp, int flags);
|
||||
static int Material_SetAttr (C_Material *self, char *name, PyObject *v);
|
||||
static PyObject *Material_GetAttr (C_Material *self, char *name);
|
||||
static PyObject *Material_Repr (C_Material *self);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Material_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Material_Type =
|
||||
{
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /* ob_size */
|
||||
"Material", /* tp_name */
|
||||
sizeof (C_Material), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor)Material_Dealloc, /* tp_dealloc */
|
||||
(printfunc)Material_Print, /* tp_print */
|
||||
(getattrfunc)Material_GetAttr, /* tp_getattr */
|
||||
(setattrfunc)Material_SetAttr, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
(reprfunc)Material_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_Material_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Material_Dealloc */
|
||||
/* Description: This is a callback function for the C_Material type. It is */
|
||||
/* the destructor function. */
|
||||
/*****************************************************************************/
|
||||
static void Material_Dealloc (C_Material *self)
|
||||
{
|
||||
Py_DECREF (self->rgb);
|
||||
Py_DECREF (self->amb);
|
||||
Py_DECREF (self->spec);
|
||||
Py_DECREF (self->mir);
|
||||
PyObject_DEL (self);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Material_CreatePyObject */
|
||||
/* Description: This function will create a new C_Material from an existing */
|
||||
/* Blender material structure. */
|
||||
/*****************************************************************************/
|
||||
PyObject *Material_CreatePyObject (Material *mat)
|
||||
{
|
||||
C_Material *pymat;
|
||||
float *rgb[3], *amb[3], *spec[3], *mir[3];
|
||||
|
||||
pymat = (C_Material *)PyObject_NEW (C_Material, &Material_Type);
|
||||
|
||||
if (!pymat)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create C_Material object");
|
||||
|
||||
pymat->material = mat;
|
||||
|
||||
rgb[0] = &mat->r;
|
||||
rgb[1] = &mat->g;
|
||||
rgb[2] = &mat->b;
|
||||
|
||||
amb[0] = &mat->ambr;
|
||||
amb[1] = &mat->ambg;
|
||||
amb[2] = &mat->ambb;
|
||||
|
||||
spec[0] = &mat->specr;
|
||||
spec[1] = &mat->specg;
|
||||
spec[2] = &mat->specb;
|
||||
|
||||
mir[0] = &mat->mirr;
|
||||
mir[1] = &mat->mirg;
|
||||
mir[2] = &mat->mirb;
|
||||
|
||||
pymat->rgb = (C_rgbTuple *)rgbTuple_New(rgb);
|
||||
pymat->amb = (C_rgbTuple *)rgbTuple_New(amb);
|
||||
pymat->spec = (C_rgbTuple *)rgbTuple_New(spec);
|
||||
pymat->mir = (C_rgbTuple *)rgbTuple_New(mir);
|
||||
|
||||
return (PyObject *)pymat;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Material_CheckPyObject */
|
||||
/* Description: This function returns true when the given PyObject is of the */
|
||||
/* type Material. Otherwise it will return false. */
|
||||
/*****************************************************************************/
|
||||
int Material_CheckPyObject (PyObject *pyobj)
|
||||
{
|
||||
return (pyobj->ob_type == &Material_Type);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Material methods: */
|
||||
/*****************************************************************************/
|
||||
@@ -772,64 +1151,12 @@ static PyObject *Material_setNRings(C_Material *self, PyObject *args)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Material_createPyObject */
|
||||
/* Description: This function will create a new C_Material from an existing */
|
||||
/* Blender material structure. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Material_createPyObject (Material *mat)
|
||||
{
|
||||
C_Material *pymat;
|
||||
float *rgb[3], *amb[3], *spec[3], *mir[3];
|
||||
|
||||
pymat = (C_Material *)PyObject_NEW (C_Material, &Material_Type);
|
||||
|
||||
if (!pymat)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create C_Material object");
|
||||
|
||||
pymat->material = mat;
|
||||
|
||||
rgb[0] = &mat->r;
|
||||
rgb[1] = &mat->g;
|
||||
rgb[2] = &mat->b;
|
||||
|
||||
amb[0] = &mat->ambr;
|
||||
amb[1] = &mat->ambg;
|
||||
amb[2] = &mat->ambb;
|
||||
|
||||
spec[0] = &mat->specr;
|
||||
spec[1] = &mat->specg;
|
||||
spec[2] = &mat->specb;
|
||||
|
||||
mir[0] = &mat->mirr;
|
||||
mir[1] = &mat->mirg;
|
||||
mir[2] = &mat->mirb;
|
||||
|
||||
pymat->rgb = (C_rgbTuple *)rgbTuple_New(rgb);
|
||||
pymat->amb = (C_rgbTuple *)rgbTuple_New(amb);
|
||||
pymat->spec = (C_rgbTuple *)rgbTuple_New(spec);
|
||||
pymat->mir = (C_rgbTuple *)rgbTuple_New(mir);
|
||||
|
||||
return (PyObject *)pymat;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: MaterialDeAlloc */
|
||||
/* Description: This is a callback function for the C_Material type. It is */
|
||||
/* the destructor function. */
|
||||
/*****************************************************************************/
|
||||
static void MaterialDeAlloc (C_Material *self)
|
||||
{
|
||||
PyObject_DEL (self);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: MaterialGetAttr */
|
||||
/* Function: Material_GetAttr */
|
||||
/* Description: This is a callback function for the C_Material type. It is */
|
||||
/* the function that accesses C_Material "member variables" and */
|
||||
/* methods. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *MaterialGetAttr (C_Material *self, char *name)
|
||||
static PyObject *Material_GetAttr (C_Material *self, char *name)
|
||||
{
|
||||
PyObject *attr = Py_None;
|
||||
|
||||
@@ -909,12 +1236,12 @@ static PyObject *MaterialGetAttr (C_Material *self, char *name)
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/* Function: MaterialSetAttr */
|
||||
/* Function: Material_SetAttr */
|
||||
/* Description: This is a callback function for the C_Material type. */
|
||||
/* It is the function that sets Material attributes (member */
|
||||
/* variables). */
|
||||
/****************************************************************************/
|
||||
static int MaterialSetAttr (C_Material *self, char *name, PyObject *value)
|
||||
static int Material_SetAttr (C_Material *self, char *name, PyObject *value)
|
||||
{
|
||||
PyObject *valtuple;
|
||||
PyObject *error = NULL;
|
||||
@@ -1006,22 +1333,22 @@ static int MaterialSetAttr (C_Material *self, char *name, PyObject *value)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: MaterialPrint */
|
||||
/* Function: Material_Print */
|
||||
/* Description: This is a callback function for the C_Material type. It */
|
||||
/* builds a meaninful string to 'print' material objects. */
|
||||
/*****************************************************************************/
|
||||
static int MaterialPrint(C_Material *self, FILE *fp, int flags)
|
||||
static int Material_Print(C_Material *self, FILE *fp, int flags)
|
||||
{
|
||||
fprintf(fp, "[Material \"%s\"]", self->material->id.name+2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: MaterialRepr */
|
||||
/* Function: Material_Repr */
|
||||
/* Description: This is a callback function for the C_Material type. It */
|
||||
/* builds a meaninful string to represent material objects. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *MaterialRepr (C_Material *self)
|
||||
static PyObject *Material_Repr (C_Material *self)
|
||||
{
|
||||
char buf[40];
|
||||
|
||||
@@ -1030,3 +1357,70 @@ static PyObject *MaterialRepr (C_Material *self)
|
||||
|
||||
return PyString_FromString(buf);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* These three functions are used in NMesh.c */
|
||||
/*****************************************************************************/
|
||||
PyObject *EXPP_PyList_fromMaterialList (Material **matlist, int len)
|
||||
{
|
||||
PyObject *list;
|
||||
int i;
|
||||
|
||||
list = PyList_New(0);
|
||||
if (!matlist) return list;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
Material *mat = matlist[i];
|
||||
PyObject *ob;
|
||||
|
||||
if (mat) {
|
||||
ob = Material_CreatePyObject (mat);
|
||||
PyList_Append (list, ob);
|
||||
Py_DECREF (ob); /* because Append increfs */
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
Material **EXPP_newMaterialList_fromPyList (PyObject *list)
|
||||
{
|
||||
int i, len;
|
||||
C_Material *pymat = 0;
|
||||
Material *mat;
|
||||
Material **matlist;
|
||||
|
||||
len = PySequence_Length (list);
|
||||
if (len > 16) len = 16;
|
||||
|
||||
matlist = EXPP_newMaterialList (len);
|
||||
|
||||
for (i= 0; i < len; i++) {
|
||||
|
||||
pymat = (C_Material *)PySequence_GetItem (list, i);
|
||||
|
||||
if (Material_CheckPyObject ((PyObject *)pymat)) {
|
||||
mat = pymat->material;
|
||||
matlist[i] = mat;
|
||||
}
|
||||
|
||||
else { /* error; illegal type in material list */
|
||||
Py_DECREF(pymat);
|
||||
MEM_freeN(matlist);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_DECREF(pymat);
|
||||
}
|
||||
|
||||
return matlist;
|
||||
}
|
||||
|
||||
Material **EXPP_newMaterialList(int len)
|
||||
{
|
||||
Material **matlist =
|
||||
(Material **)MEM_mallocN(len * sizeof(Material *), "MaterialList");
|
||||
|
||||
return matlist;
|
||||
}
|
||||
|
@@ -33,119 +33,10 @@
|
||||
#define EXPP_MATERIAL_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <BKE_main.h>
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_library.h>
|
||||
#include <DNA_ID.h>
|
||||
#include <BKE_material.h>
|
||||
#include <BLI_blenlib.h>
|
||||
#include <DNA_material_types.h>
|
||||
|
||||
#include "constant.h"
|
||||
#include "rgbTuple.h"
|
||||
#include "gen_utils.h"
|
||||
#include "modules.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Material defaults: */
|
||||
/*****************************************************************************/
|
||||
#define EXPP_MAT_MODE_TRACEABLE MA_TRACEBLE
|
||||
#define EXPP_MAT_MODE_SHADOW MA_SHADOW
|
||||
#define EXPP_MAT_MODE_SHADELESS MA_SHLESS
|
||||
#define EXPP_MAT_MODE_WIRE MA_WIRE
|
||||
#define EXPP_MAT_MODE_VCOLLIGHT MA_VERTEXCOL
|
||||
#define EXPP_MAT_MODE_HALO MA_HALO
|
||||
#define EXPP_MAT_MODE_ZTRANSP MA_ZTRA
|
||||
#define EXPP_MAT_MODE_VCOLPAINT MA_VERTEXCOLP
|
||||
#define EXPP_MAT_MODE_ZINVERT MA_ZINV
|
||||
#define EXPP_MAT_MODE_HALORINGS MA_HALO_RINGS
|
||||
#define EXPP_MAT_MODE_ENV MA_ENV
|
||||
#define EXPP_MAT_MODE_HALOLINES MA_HALO_LINES
|
||||
#define EXPP_MAT_MODE_ONLYSHADOW MA_ONLYSHADOW
|
||||
#define EXPP_MAT_MODE_XALPHA MA_HALO_XALPHA
|
||||
#define EXPP_MAT_MODE_STAR MA_STAR
|
||||
#define EXPP_MAT_MODE_FACETEX MA_FACETEXTURE
|
||||
#define EXPP_MAT_MODE_HALOTEX MA_HALOTEX
|
||||
#define EXPP_MAT_MODE_HALOPUNO MA_HALOPUNO
|
||||
#define EXPP_MAT_MODE_NOMIST MA_NOMIST
|
||||
#define EXPP_MAT_MODE_HALOSHADE MA_HALO_SHADE
|
||||
#define EXPP_MAT_MODE_HALOFLARE MA_HALO_FLARE
|
||||
|
||||
/* Material MIN, MAX values */
|
||||
#define EXPP_MAT_ADD_MIN 0.0
|
||||
#define EXPP_MAT_ADD_MAX 1.0
|
||||
#define EXPP_MAT_ALPHA_MIN 0.0
|
||||
#define EXPP_MAT_ALPHA_MAX 1.0
|
||||
#define EXPP_MAT_AMB_MIN 0.0
|
||||
#define EXPP_MAT_AMB_MAX 1.0
|
||||
#define EXPP_MAT_ANG_MIN 0.0 /* XXX Confirm these two */
|
||||
#define EXPP_MAT_ANG_MAX 1.0
|
||||
#define EXPP_MAT_COL_MIN 0.0 /* min/max for all ... */
|
||||
#define EXPP_MAT_COL_MAX 1.0 /* ... color triplets */
|
||||
#define EXPP_MAT_EMIT_MIN 0.0
|
||||
#define EXPP_MAT_EMIT_MAX 1.0
|
||||
#define EXPP_MAT_REF_MIN 0.0
|
||||
#define EXPP_MAT_REF_MAX 1.0
|
||||
#define EXPP_MAT_SPEC_MIN 0.0
|
||||
#define EXPP_MAT_SPEC_MAX 2.0
|
||||
#define EXPP_MAT_SPECTRA_MIN 0.0
|
||||
#define EXPP_MAT_SPECTRA_MAX 1.0
|
||||
#define EXPP_MAT_ZOFFS_MIN 0.0
|
||||
#define EXPP_MAT_ZOFFS_MAX 10.0
|
||||
#define EXPP_MAT_HALOSIZE_MIN 0.0
|
||||
#define EXPP_MAT_HALOSIZE_MAX 100.0
|
||||
#define EXPP_MAT_FLARESIZE_MIN 0.1
|
||||
#define EXPP_MAT_FLARESIZE_MAX 25.0
|
||||
#define EXPP_MAT_FLAREBOOST_MIN 0.1
|
||||
#define EXPP_MAT_FLAREBOOST_MAX 10.0
|
||||
#define EXPP_MAT_SUBSIZE_MIN 0.1
|
||||
#define EXPP_MAT_SUBSIZE_MAX 25.0
|
||||
|
||||
#define EXPP_MAT_HARD_MIN 1
|
||||
#define EXPP_MAT_HARD_MAX 255 /* 127 with MODE HALO ON */
|
||||
#define EXPP_MAT_NFLARES_MIN 1
|
||||
#define EXPP_MAT_NFLARES_MAX 32
|
||||
#define EXPP_MAT_NSTARS_MIN 3
|
||||
#define EXPP_MAT_NSTARS_MAX 50
|
||||
#define EXPP_MAT_NLINES_MIN 0
|
||||
#define EXPP_MAT_NLINES_MAX 250
|
||||
#define EXPP_MAT_NRINGS_MIN 0
|
||||
#define EXPP_MAT_NRINGS_MAX 24
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Material module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Material_New (PyObject *self, PyObject *args,
|
||||
PyObject *keywords);
|
||||
static PyObject *M_Material_Get (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.Material.__doc__ */
|
||||
/*****************************************************************************/
|
||||
char M_Material_doc[] =
|
||||
"The Blender Material module";
|
||||
|
||||
char M_Material_New_doc[] =
|
||||
"(name) - return a new material called 'name'\n\
|
||||
() - return a new material called 'Mat'";
|
||||
|
||||
char M_Material_Get_doc[] =
|
||||
"(name) - return the material called 'name', None if not found.\n\
|
||||
() - return a list of all materials in the current scene.";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Material module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_Material_methods[] = {
|
||||
{"New",(PyCFunction)M_Material_New, METH_VARARGS|METH_KEYWORDS,
|
||||
M_Material_New_doc},
|
||||
{"Get", M_Material_Get, METH_VARARGS, M_Material_Get_doc},
|
||||
{"get", M_Material_Get, METH_VARARGS, M_Material_Get_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Material structure definition: */
|
||||
@@ -157,204 +48,22 @@ typedef struct {
|
||||
|
||||
} C_Material;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Material methods declarations: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Material_getName(C_Material *self);
|
||||
static PyObject *Material_getMode(C_Material *self);
|
||||
static PyObject *Material_getRGBCol(C_Material *self);
|
||||
static PyObject *Material_getAmbCol(C_Material *self);
|
||||
static PyObject *Material_getSpecCol(C_Material *self);
|
||||
static PyObject *Material_getMirCol(C_Material *self);
|
||||
static PyObject *Material_getAmb(C_Material *self);
|
||||
static PyObject *Material_getAng(C_Material *self);
|
||||
static PyObject *Material_getEmit(C_Material *self);
|
||||
static PyObject *Material_getAlpha(C_Material *self);
|
||||
static PyObject *Material_getRef(C_Material *self);
|
||||
static PyObject *Material_getSpec(C_Material *self);
|
||||
static PyObject *Material_getSpecTransp(C_Material *self);
|
||||
static PyObject *Material_getAdd(C_Material *self);
|
||||
static PyObject *Material_getZOffset(C_Material *self);
|
||||
static PyObject *Material_getHaloSize(C_Material *self);
|
||||
static PyObject *Material_getFlareSize(C_Material *self);
|
||||
static PyObject *Material_getFlareBoost(C_Material *self);
|
||||
static PyObject *Material_getSubSize(C_Material *self);
|
||||
static PyObject *Material_getHardness(C_Material *self);
|
||||
static PyObject *Material_getNFlares(C_Material *self);
|
||||
static PyObject *Material_getNStars(C_Material *self);
|
||||
static PyObject *Material_getNLines(C_Material *self);
|
||||
static PyObject *Material_getNRings(C_Material *self);
|
||||
static PyObject *Material_setName(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setMode(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setIntMode(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setRGBCol(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setAmbCol(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setSpecCol(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setMirCol(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setAmb(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setEmit(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setAng(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setAlpha(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setRef(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setSpec(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setSpecTransp(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setAdd(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setZOffset(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setHaloSize(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setFlareSize(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setFlareBoost(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setSubSize(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setHardness(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setNFlares(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setNStars(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setNLines(C_Material *self, PyObject *args);
|
||||
static PyObject *Material_setNRings(C_Material *self, PyObject *args);
|
||||
PyTypeObject Material_Type; /* The Image PyType Object */
|
||||
|
||||
static PyObject *Material_setColorComponent(C_Material *self, char *key,
|
||||
PyObject *args);
|
||||
#define C_Material_Check(v) \
|
||||
((v)->ob_type == &Image_Type) /* for type checking */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_Material methods table: */
|
||||
/* Module Blender.Material - public functions */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef C_Material_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"getName", (PyCFunction)Material_getName, METH_NOARGS,
|
||||
"() - Return Material Data name"},
|
||||
{"getMode", (PyCFunction)Material_getMode, METH_NOARGS,
|
||||
"() - Return Material mode flags"},
|
||||
{"getRGBCol", (PyCFunction)Material_getRGBCol, METH_NOARGS,
|
||||
"() - Return Material's rgb color triplet"},
|
||||
{"getAmbCol", (PyCFunction)Material_getAmbCol, METH_NOARGS,
|
||||
"() - Return Material's ambient color"},
|
||||
{"getSpecCol", (PyCFunction)Material_getSpecCol, METH_NOARGS,
|
||||
"() - Return Material's specular color"},
|
||||
{"getMirCol", (PyCFunction)Material_getMirCol, METH_NOARGS,
|
||||
"() - Return Material's mirror color"},
|
||||
{"getAmb", (PyCFunction)Material_getAmb, METH_NOARGS,
|
||||
"() - Return Material's ambient color blend factor"},
|
||||
{"getAng", (PyCFunction)Material_getAng, METH_NOARGS,
|
||||
"() - Return Material's ????"},
|
||||
{"getEmit", (PyCFunction)Material_getEmit, METH_NOARGS,
|
||||
"() - Return Material's emitting light intensity"},
|
||||
{"getAlpha", (PyCFunction)Material_getAlpha, METH_NOARGS,
|
||||
"() - Return Material's alpha (transparency) value"},
|
||||
{"getRef", (PyCFunction)Material_getRef, METH_NOARGS,
|
||||
"() - Return Material's reflectivity"},
|
||||
{"getSpec", (PyCFunction)Material_getSpec, METH_NOARGS,
|
||||
"() - Return Material's specularity"},
|
||||
{"getSpecTransp", (PyCFunction)Material_getSpecTransp, METH_NOARGS,
|
||||
"() - Return Material's specular transparency"},
|
||||
{"getAdd", (PyCFunction)Material_getAdd, METH_NOARGS,
|
||||
"() - Return Material's glow factor"},
|
||||
{"getZOffset", (PyCFunction)Material_getZOffset, METH_NOARGS,
|
||||
"() - Return Material's artificial offset "},
|
||||
{"getHaloSize", (PyCFunction)Material_getHaloSize, METH_NOARGS,
|
||||
"() - Return Material's halo size"},
|
||||
{"getFlareSize", (PyCFunction)Material_getFlareSize, METH_NOARGS,
|
||||
"() - Return Material's (flare size)/(halo size) factor"},
|
||||
{"getFlareBoost", (PyCFunction)Material_getFlareBoost, METH_NOARGS,
|
||||
"() - Return Material's flare boost"},
|
||||
{"getSubSize", (PyCFunction)Material_getSubSize, METH_NOARGS,
|
||||
"() - Return Material's dimension of subflare, dots and circles"},
|
||||
{"getHardness", (PyCFunction)Material_getHardness, METH_NOARGS,
|
||||
"() - Return Material's hardness"},
|
||||
{"getNFlares", (PyCFunction)Material_getNFlares, METH_NOARGS,
|
||||
"() - Return Material's number of flares in halo"},
|
||||
{"getNStars", (PyCFunction)Material_getNStars, METH_NOARGS,
|
||||
"() - Return Material's number of stars in halo"},
|
||||
{"getNLines", (PyCFunction)Material_getNLines, METH_NOARGS,
|
||||
"() - Return Material's number of lines in halo"},
|
||||
{"getNRings", (PyCFunction)Material_getNRings, METH_NOARGS,
|
||||
"() - Return Material's number of rings in halo"},
|
||||
{"setName", (PyCFunction)Material_setName, METH_VARARGS,
|
||||
"(s) - Change Material Data name"},
|
||||
{"setMode", (PyCFunction)Material_setMode, METH_VARARGS,
|
||||
"([s[,s]]) - Set Material mode flag(s)"},
|
||||
{"setRGBCol", (PyCFunction)Material_setMode, METH_VARARGS,
|
||||
"([s[,s]]) - Set Material's rgb color triplet"},
|
||||
{"setAmbCol", (PyCFunction)Material_setMode, METH_VARARGS,
|
||||
"([s[,s]]) - Set Material's ambient color"},
|
||||
{"setSpecCol", (PyCFunction)Material_setMode, METH_VARARGS,
|
||||
"([s[,s]]) - Set Material's specular color"},
|
||||
{"setMirCol", (PyCFunction)Material_setMode, METH_VARARGS,
|
||||
"([s[,s]]) - Set Material's mirror color"},
|
||||
{"setAmb", (PyCFunction)Material_setAmb, METH_VARARGS,
|
||||
"(f) - Set how much the Material's color is affected"
|
||||
" by \nthe global ambient colors - [0.0, 1.0]"},
|
||||
{"setAng", (PyCFunction)Material_setAng, METH_VARARGS,
|
||||
"(f) - Set Material's ?????"},
|
||||
{"setEmit", (PyCFunction)Material_setEmit, METH_VARARGS,
|
||||
"(f) - Set Material's emitting light intensity - [0.0, 1.0]"},
|
||||
{"setAlpha", (PyCFunction)Material_setAlpha, METH_VARARGS,
|
||||
"(f) - Set Material's alpha (transparency) - [0.0, 1.0]"},
|
||||
{"setRef", (PyCFunction)Material_setRef, METH_VARARGS,
|
||||
"(f) - Set Material's reflectivity - [0.0, 1.0]"},
|
||||
{"setSpec", (PyCFunction)Material_setSpec, METH_VARARGS,
|
||||
"(f) - Set Material's specularity - [0.0, 2.0]"},
|
||||
{"setSpecTransp", (PyCFunction)Material_setSpecTransp, METH_VARARGS,
|
||||
"(f) - Set Material's specular transparency - [0.0, 1.0]"},
|
||||
{"setAdd", (PyCFunction)Material_setAdd, METH_VARARGS,
|
||||
"(f) - Set Material's glow factor - [0.0, 1.0]"},
|
||||
{"setZOffset", (PyCFunction)Material_setZOffset, METH_VARARGS,
|
||||
"(f) - Set Material's artificial offset - [0.0, 10.0]"},
|
||||
{"setHaloSize", (PyCFunction)Material_setHaloSize, METH_VARARGS,
|
||||
"(f) - Set Material's halo size - [0.0, 100.0]"},
|
||||
{"setFlareSize", (PyCFunction)Material_setFlareSize, METH_VARARGS,
|
||||
"(f) - Set Material's factor: (flare size)/(halo size) - [0.1, 25.0]"},
|
||||
{"setFlareBoost", (PyCFunction)Material_setFlareBoost, METH_VARARGS,
|
||||
"(f) - Set Material's flare boost - [0.1, 10.0]"},
|
||||
{"setSubSize", (PyCFunction)Material_setSubSize, METH_VARARGS,
|
||||
"(f) - Set Material's dimension of subflare,"
|
||||
" dots and circles - [0.1, 25.0]"},
|
||||
{"setHardness", (PyCFunction)Material_setFlareBoost, METH_VARARGS,
|
||||
"(f) - Set Material's hardness - [1, 255 (127 if halo mode is ON)]"},
|
||||
{"setNFlares", (PyCFunction)Material_setFlareBoost, METH_VARARGS,
|
||||
"(f) - Set Material's number of flares in halo - [1, 32]"},
|
||||
{"setNStars", (PyCFunction)Material_setFlareBoost, METH_VARARGS,
|
||||
"(f) - Set Material's number of stars in halo - [3, 50]"},
|
||||
{"setNLines", (PyCFunction)Material_setFlareBoost, METH_VARARGS,
|
||||
"(f) - Set Material's number of lines in halo - [0, 250]"},
|
||||
{"setNRings", (PyCFunction)Material_setNRings, METH_VARARGS,
|
||||
"(f) - Set Material's number of rings in halo - [0, 24]"},
|
||||
{0}
|
||||
};
|
||||
PyObject *M_Material_Init (void);
|
||||
PyObject *Material_CreatePyObject (Material *mat);
|
||||
int Material_CheckPyObject (PyObject *pyobj);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Material_Type callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static void MaterialDeAlloc (C_Material *self);
|
||||
static int MaterialPrint (C_Material *self, FILE *fp, int flags);
|
||||
static int MaterialSetAttr (C_Material *self, char *name, PyObject *v);
|
||||
static PyObject *MaterialGetAttr (C_Material *self, char *name);
|
||||
static PyObject *MaterialRepr (C_Material *self);
|
||||
static PyObject *Material_createPyObject (Material *mat);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Material_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Material_Type =
|
||||
{
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /* ob_size */
|
||||
"Material", /* tp_name */
|
||||
sizeof (C_Material), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor)MaterialDeAlloc, /* tp_dealloc */
|
||||
(printfunc)MaterialPrint, /* tp_print */
|
||||
(getattrfunc)MaterialGetAttr, /* tp_getattr */
|
||||
(setattrfunc)MaterialSetAttr, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
(reprfunc)MaterialRepr, /* 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_Material_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
};
|
||||
/* Some functions needed by NMesh.c */
|
||||
PyObject *EXPP_PyList_fromMaterialList (Material **matlist, int len);
|
||||
Material **EXPP_newMaterialList_fromPyList (PyObject *list);
|
||||
Material **EXPP_newMaterialList(int len);
|
||||
|
||||
#endif /* EXPP_MATERIAL_H */
|
||||
|
@@ -142,6 +142,7 @@ static void NMFace_dealloc (PyObject *self)
|
||||
Py_DECREF(mf->v);
|
||||
Py_DECREF(mf->uv);
|
||||
Py_DECREF(mf->col);
|
||||
Py_XDECREF(mf->image);
|
||||
|
||||
PyMem_DEL(self);
|
||||
}
|
||||
@@ -298,7 +299,9 @@ static int NMFace_setattr(PyObject *self, char *name, PyObject *v)
|
||||
}
|
||||
else if (strcmp(name, "image") == 0) {
|
||||
PyObject *img;
|
||||
PyArg_Parse(v, "O", &img);
|
||||
if (!PyArg_Parse(v, "O!", &Image_Type, &img))
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"expected image object");
|
||||
|
||||
if (img == Py_None) {
|
||||
mf->image = NULL;
|
||||
@@ -306,9 +309,7 @@ static int NMFace_setattr(PyObject *self, char *name, PyObject *v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// XXX if PyType ... XXXXXXX
|
||||
|
||||
mf->image = img;
|
||||
mf->image = (C_Image *)img;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -686,7 +687,8 @@ static PyObject *NMesh_update(PyObject *self, PyObject *args)
|
||||
|
||||
|
||||
/** Implementation of the python method getVertexInfluence for an NMesh object.
|
||||
* This method returns a list of pairs (string,float) with bone nemaes and influences that this vertex receives.
|
||||
* This method returns a list of pairs (string,float) with bone nemaes and
|
||||
* influences that this vertex receives.
|
||||
* @author Jordi Rovira i Bonet
|
||||
*/
|
||||
static PyObject *NMesh_getVertexInfluences(PyObject *self, PyObject *args)
|
||||
@@ -694,61 +696,60 @@ static PyObject *NMesh_getVertexInfluences(PyObject *self, PyObject *args)
|
||||
int index;
|
||||
PyObject* influence_list = NULL;
|
||||
|
||||
// Get a reference to the mesh object wrapped in here.
|
||||
Mesh *me= ((C_NMesh*)self)->mesh;
|
||||
/* Get a reference to the mesh object wrapped in here. */
|
||||
Mesh *me = ((C_NMesh*)self)->mesh;
|
||||
|
||||
// Parse the parameters: only on integer (vertex index)
|
||||
/* Parse the parameters: only on integer (vertex index) */
|
||||
if (!PyArg_ParseTuple(args, "i", &index))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected int argument (index of the vertex)");
|
||||
|
||||
// Proceed only if we have vertex deformation information and index is valid
|
||||
if (me->dvert)
|
||||
if ((index>=0) && (index<me->totvert))
|
||||
{
|
||||
/* Proceed only if we have vertex deformation information and index is valid*/
|
||||
if (me->dvert) {
|
||||
if ((index >= 0) && (index < me->totvert)) {
|
||||
|
||||
int i;
|
||||
MDeformWeight *sweight = NULL;
|
||||
|
||||
// Number of bones influencig the vertex
|
||||
/* Number of bones influencig the vertex */
|
||||
int totinfluences=me->dvert[index].totweight;
|
||||
|
||||
// Build the list only with weights and names of the influent bones
|
||||
/* Build the list only with weights and names of the influent bones */
|
||||
influence_list = PyList_New(totinfluences);
|
||||
|
||||
//Get the reference of the first wwight structure
|
||||
/* Get the reference of the first wwight structure */
|
||||
sweight = me->dvert[index].dw;
|
||||
|
||||
for (i=0; i<totinfluences; i++) {
|
||||
|
||||
// Some check that should always be true
|
||||
assert(sweight->data);
|
||||
/* Some check that should always be true */
|
||||
/* assert(sweight->data);*/
|
||||
|
||||
//Add the weight and the name of the bone, which is used to identify it
|
||||
PyList_SetItem(influence_list, i, Py_BuildValue("[sf]", sweight->data->name, sweight->weight));
|
||||
/*Add the weight and the name of the bone, which is used to identify it*/
|
||||
PyList_SetItem(influence_list, i,
|
||||
Py_BuildValue("[sf]", sweight->data->name, sweight->weight));
|
||||
|
||||
//Next weight
|
||||
/* Next weight */
|
||||
sweight++;
|
||||
}
|
||||
}
|
||||
else influence_list = PyList_New(0);
|
||||
}
|
||||
else influence_list = PyList_New(0);
|
||||
|
||||
// Return the list. !QUESTION! Should i reincrement the number of references like i'm doing?
|
||||
return EXPP_incr_ret(influence_list);
|
||||
|
||||
/* Return the list. !QUESTION! Should i reincrement the number of
|
||||
* references like i'm doing? */
|
||||
return influence_list; /* No need to incref it */
|
||||
}
|
||||
|
||||
|
||||
|
||||
Mesh *Mesh_fromNMesh(C_NMesh *nmesh)
|
||||
{
|
||||
Mesh *mesh = NULL;
|
||||
mesh = add_mesh(); /* us == 1, should we zero it for all added objs ? */
|
||||
|
||||
if (!mesh) {
|
||||
if (!mesh)
|
||||
EXPP_ReturnPyObjError(PyExc_RuntimeError,
|
||||
"FATAL: could not create mesh object");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
convert_NMeshToMesh(mesh, nmesh);
|
||||
mesh_update(mesh);
|
||||
@@ -757,8 +758,15 @@ Mesh *Mesh_fromNMesh(C_NMesh *nmesh)
|
||||
}
|
||||
|
||||
PyObject *NMesh_link(PyObject *self, PyObject *args)
|
||||
{
|
||||
// XXX return DataBlock_link(self, args);
|
||||
{/*
|
||||
C_Object *bl_obj;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!", &Object_Type, bl_obj))
|
||||
return EXPP_ReturnPyErrorObj (PyExc_TypeError,
|
||||
"NMesh can only be linked to Objects");
|
||||
|
||||
bl_obj->data = (PyObject *)self; do this function later */
|
||||
|
||||
return EXPP_incr_ret(Py_None);
|
||||
}
|
||||
|
||||
@@ -880,7 +888,7 @@ static C_NMFace *nmface_from_data(C_NMesh *mesh, int vidxs[4],
|
||||
}
|
||||
|
||||
if (tface->tpage) /* pointer to image per face: */
|
||||
newf->image = NULL;// XXX Image_Get(tface->tpage);
|
||||
newf->image = (C_Image *)Image_CreatePyObject (tface->tpage);
|
||||
else
|
||||
newf->image = NULL;
|
||||
|
||||
@@ -1055,7 +1063,7 @@ static PyObject *new_NMesh_internal(Mesh *oldmesh,
|
||||
(PyObject *)nmface_from_shortdata(me, oldmf, oldtf, oldmc));
|
||||
}
|
||||
}
|
||||
me->materials = NULL;// XXX PyList_fromMaterialList(oldmesh->mat, oldmesh->totcol);
|
||||
me->materials = EXPP_PyList_fromMaterialList(oldmesh->mat, oldmesh->totcol);
|
||||
}
|
||||
|
||||
return (PyObject *)me;
|
||||
@@ -1188,7 +1196,7 @@ static int assignFaceUV(TFace *tf, C_NMFace *nmface)
|
||||
}
|
||||
if (nmface->image) /* image assigned ? */
|
||||
{
|
||||
tf->tpage = nmface->image;
|
||||
tf->tpage = nmface->image->image;
|
||||
}
|
||||
else
|
||||
tf->tpage = 0;
|
||||
@@ -1319,7 +1327,7 @@ Material **nmesh_updateMaterials(C_NMesh *nmesh)
|
||||
}
|
||||
|
||||
if (len > 0) {
|
||||
matlist = newMaterialList_fromPyList(nmesh->materials);
|
||||
matlist = EXPP_newMaterialList_fromPyList(nmesh->materials);
|
||||
if (mesh->mat)
|
||||
MEM_freeN(mesh->mat);
|
||||
mesh->mat = matlist;
|
||||
@@ -1332,36 +1340,38 @@ Material **nmesh_updateMaterials(C_NMesh *nmesh)
|
||||
|
||||
PyObject *NMesh_assignMaterials_toObject(C_NMesh *nmesh, Object *ob)
|
||||
{
|
||||
// DataBlock *block;
|
||||
// Material *ma;
|
||||
// int i;
|
||||
// short old_matmask;
|
||||
C_Material *pymat;
|
||||
Material *ma;
|
||||
int i;
|
||||
short old_matmask;
|
||||
|
||||
//old_matmask = ob->colbits; // HACK: save previous colbits
|
||||
//ob->colbits = 0; // make assign_material work on mesh linked material
|
||||
old_matmask = ob->colbits; /*@ HACK: save previous colbits */
|
||||
ob->colbits = 0; /* make assign_material work on mesh linked material */
|
||||
|
||||
// for (i = 0; i < PySequence_Length(nmesh->materials); i++) {
|
||||
// block= (DataBlock *) PySequence_GetItem(nmesh->materials, i);
|
||||
for (i = 0; i < PySequence_Length(nmesh->materials); i++) {
|
||||
pymat = (C_Material *)PySequence_GetItem(nmesh->materials, i);
|
||||
|
||||
// if (DataBlock_isType(block, ID_MA)) {
|
||||
// ma = (Material *) block->data;
|
||||
// assign_material(ob, ma, i+1); // XXX don't use this function anymore
|
||||
// } else {
|
||||
// PyErr_SetString(PyExc_TypeError,
|
||||
// "Material type in attribute list 'materials' expected!");
|
||||
//Py_DECREF(block);
|
||||
// return NULL;
|
||||
// }
|
||||
if (Material_CheckPyObject ((PyObject *)pymat)) {
|
||||
ma = pymat->material;
|
||||
assign_material(ob, ma, i+1);/*@ XXX don't use this function anymore*/
|
||||
}
|
||||
|
||||
//Py_DECREF(block);
|
||||
//}
|
||||
//ob->colbits = old_matmask; // HACK
|
||||
else {
|
||||
Py_DECREF (pymat);
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"Material type in attribute list 'materials' expected!");
|
||||
}
|
||||
|
||||
// ob->actcol = 1;
|
||||
return EXPP_incr_ret(Py_None);
|
||||
Py_DECREF (pymat);
|
||||
}
|
||||
|
||||
ob->colbits = old_matmask; /*@ HACK */
|
||||
|
||||
ob->actcol = 1;
|
||||
return EXPP_incr_ret (Py_None);
|
||||
}
|
||||
|
||||
static int convert_NMeshToMesh(Mesh *mesh, C_NMesh *nmesh)
|
||||
static int convert_NMeshToMesh (Mesh *mesh, C_NMesh *nmesh)
|
||||
{
|
||||
MFace *newmf;
|
||||
TFace *newtf;
|
||||
@@ -1378,7 +1388,7 @@ static int convert_NMeshToMesh(Mesh *mesh, C_NMesh *nmesh)
|
||||
mesh->tface = NULL;
|
||||
mesh->mat = NULL;
|
||||
|
||||
// material assignment moved to PutRaw
|
||||
/*@ material assignment moved to PutRaw */
|
||||
mesh->totvert = PySequence_Length(nmesh->verts);
|
||||
if (mesh->totvert) {
|
||||
if (nmesh->flags&NMESH_HASVERTUV)
|
||||
@@ -1572,11 +1582,12 @@ static PyObject *M_NMesh_PutRaw(PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
#undef MethodDef
|
||||
#define MethodDef(func) {#func, M_NMesh_##func, METH_VARARGS, M_NMesh_##func##_doc}
|
||||
#define MethodDef(func) \
|
||||
{#func, M_NMesh_##func, METH_VARARGS, M_NMesh_##func##_doc}
|
||||
|
||||
static struct PyMethodDef M_NMesh_methods[] = {
|
||||
// These should be: Mesh.Col, Mesh.Vert, Mesh.Face in fure
|
||||
// -- for ownership reasons
|
||||
/*@ These should be: Mesh.Col, Mesh.Vert, Mesh.Face in fure */
|
||||
/* -- for ownership reasons */
|
||||
MethodDef(Col),
|
||||
MethodDef(Vert),
|
||||
MethodDef(Face),
|
||||
@@ -1590,11 +1601,15 @@ static struct PyMethodDef M_NMesh_methods[] = {
|
||||
#undef EXPP_ADDCONST
|
||||
#define EXPP_ADDCONST(dict, name) \
|
||||
constant_insert(dict, #name, PyInt_FromLong(TF_##name))
|
||||
/* Set constants for face drawing mode -- see drawmesh.c */
|
||||
|
||||
/*@ set constants for face drawing mode -- see drawmesh.c */
|
||||
|
||||
static void init_NMeshConst(C_constant *d)
|
||||
static PyObject *M_NMesh_FaceModesDict (void)
|
||||
{
|
||||
PyObject *FM = M_constant_New();
|
||||
|
||||
if (FM) {
|
||||
C_constant *d = (C_constant *)FM;
|
||||
|
||||
constant_insert(d, "BILLBOARD", PyInt_FromLong(TF_BILLBOARD2));
|
||||
constant_insert(d, "ALL", PyInt_FromLong(0xffff));
|
||||
constant_insert(d, "HALO", PyInt_FromLong(TF_BILLBOARD));
|
||||
@@ -1608,30 +1623,57 @@ static void init_NMeshConst(C_constant *d)
|
||||
EXPP_ADDCONST(d, TEX);
|
||||
EXPP_ADDCONST(d, TILES);
|
||||
EXPP_ADDCONST(d, TWOSIDE);
|
||||
/* transparent modes */
|
||||
}
|
||||
|
||||
return FM;
|
||||
}
|
||||
|
||||
static PyObject *M_NMesh_FaceFlagsDict (void)
|
||||
{
|
||||
PyObject *FF = M_constant_New();
|
||||
|
||||
if (FF) {
|
||||
C_constant *d = (C_constant *)FF;
|
||||
|
||||
EXPP_ADDCONST(d, SELECT);
|
||||
EXPP_ADDCONST(d, HIDE);
|
||||
EXPP_ADDCONST(d, ACTIVE);
|
||||
}
|
||||
|
||||
return FF;
|
||||
}
|
||||
|
||||
static PyObject *M_NMesh_FaceTranspModesDict (void)
|
||||
{
|
||||
PyObject *FTM = M_constant_New();
|
||||
|
||||
if (FTM) {
|
||||
C_constant *d = (C_constant *)FTM;
|
||||
|
||||
EXPP_ADDCONST(d, SOLID);
|
||||
EXPP_ADDCONST(d, ADD);
|
||||
EXPP_ADDCONST(d, ALPHA);
|
||||
EXPP_ADDCONST(d, SUB);
|
||||
/* TFACE flags */
|
||||
EXPP_ADDCONST(d, SELECT);
|
||||
EXPP_ADDCONST(d, HIDE);
|
||||
EXPP_ADDCONST(d, ACTIVE);
|
||||
}
|
||||
|
||||
return FTM;
|
||||
}
|
||||
|
||||
PyObject *M_NMesh_Init (void)
|
||||
{
|
||||
PyObject *mod = Py_InitModule("Blender.NMesh", M_NMesh_methods);
|
||||
PyObject *dict = PyModule_GetDict(mod);
|
||||
PyObject *d = M_constant_New();
|
||||
PyObject *submodule;
|
||||
|
||||
PyDict_SetItemString(dict, "Const" , d);
|
||||
init_NMeshConst((C_constant *)d);
|
||||
PyObject *FaceFlags = M_NMesh_FaceFlagsDict ();
|
||||
PyObject *FaceModes = M_NMesh_FaceModesDict ();
|
||||
PyObject *FaceTranspModes = M_NMesh_FaceTranspModesDict ();
|
||||
|
||||
g_nmeshmodule = mod;
|
||||
return mod;
|
||||
submodule = Py_InitModule3("Blender.NMesh", M_NMesh_methods, M_NMesh_doc);
|
||||
|
||||
if (FaceFlags) PyModule_AddObject (submodule, "FaceFlags" , FaceFlags);
|
||||
if (FaceModes) PyModule_AddObject (submodule, "FaceModes" , FaceModes);
|
||||
if (FaceTranspModes)
|
||||
PyModule_AddObject (submodule, "FaceTranspModes" , FaceTranspModes);
|
||||
|
||||
g_nmeshmodule = submodule;
|
||||
return submodule;
|
||||
}
|
||||
|
||||
/* Unimplemented stuff: */
|
||||
|
||||
Material **newMaterialList_fromPyList (PyObject *list) { return NULL; }
|
||||
|
@@ -59,9 +59,12 @@
|
||||
#include "DNA_armature_types.h"
|
||||
#include "mydevice.h"
|
||||
|
||||
#include "gen_utils.h"
|
||||
#include "Material.h"
|
||||
#include "Image.h"
|
||||
#include "vector.h"
|
||||
#include "constant.h"
|
||||
#include "gen_utils.h"
|
||||
|
||||
|
||||
/* EXPP PyType Objects */
|
||||
|
||||
@@ -70,6 +73,8 @@ PyTypeObject NMFace_Type;
|
||||
PyTypeObject NMVert_Type;
|
||||
PyTypeObject NMCol_Type;
|
||||
|
||||
PyTypeObject Image_Type;
|
||||
|
||||
/* Globals */
|
||||
|
||||
static PyObject *g_nmeshmodule = NULL;
|
||||
@@ -81,6 +86,9 @@ static PyObject *g_nmeshmodule = NULL;
|
||||
#define C_NMVert_Check(v) ((v)->ob_type == &NMVert_Type)
|
||||
#define C_NMCol_Check(v) ((v)->ob_type == &NMCol_Type)
|
||||
|
||||
static char M_NMesh_doc[] =
|
||||
"The Blender.NMesh module";
|
||||
|
||||
static char M_NMesh_Col_doc[]=
|
||||
"([r, g, b, a]) - Get a new mesh color\n\n\
|
||||
[r=255, g=255, b=255, a=255] Specify the color components";
|
||||
@@ -179,7 +187,7 @@ typedef struct {
|
||||
short mode;
|
||||
short flag;
|
||||
unsigned char transp;
|
||||
PyObject *image; /* Image; was DataBlock *tpage -- PyObj is wrong, change it*/
|
||||
C_Image *image;
|
||||
char mat_nr, smooth;
|
||||
|
||||
} C_NMFace; /* an NMesh face */
|
||||
|
@@ -188,4 +188,3 @@ int EXPP_check_sequence_consistency(PyObject *seq, PyTypeObject *against)
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@@ -32,14 +32,15 @@
|
||||
#ifndef EXPP_gen_utils_h
|
||||
#define EXPP_gen_utils_h
|
||||
|
||||
#include <Python.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <Python.h>
|
||||
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_main.h>
|
||||
#include <DNA_ID.h>
|
||||
#include <DNA_object_types.h>
|
||||
#include <DNA_material_types.h>
|
||||
#include <DNA_scriptlink_types.h>
|
||||
#include <DNA_listBase.h>
|
||||
|
||||
|
@@ -40,6 +40,7 @@
|
||||
#include <DNA_curve_types.h>
|
||||
#include <DNA_effect_types.h>
|
||||
#include <DNA_armature_types.h>
|
||||
#include <DNA_image_types.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Global variables */
|
||||
@@ -99,9 +100,13 @@ struct Effect * EffectFromPyObject (PyObject *py_obj);
|
||||
int EffectCheckPyObject (PyObject *py_obj);
|
||||
*/
|
||||
|
||||
/* Image */
|
||||
PyObject * M_Image_Init (void);
|
||||
PyObject * ImageCreatePyObject (Image *image);
|
||||
int Image_checkPyObject (PyObject *pyobj);
|
||||
|
||||
/* Init functions for other modules */
|
||||
PyObject * M_Window_Init (void);
|
||||
PyObject * M_Image_Init (void);
|
||||
PyObject * M_Draw_Init (void);
|
||||
PyObject * M_BGL_Init (void);
|
||||
PyObject * M_Text_Init (void);
|
||||
|
Reference in New Issue
Block a user