-- New module: Blender.Texture, by new developer Alex Mole.
Most of it is done: guess only Ipo, envmap, colorband and plugin were not implemented yet.
This commit is contained in:
2003-11-23 17:46:06 +00:00
parent 511b098c81
commit 5e7f9dfa08
14 changed files with 2109 additions and 7 deletions

View File

@@ -229,4 +229,5 @@ void M_Blender_Init (void)
PyDict_SetItemString (dict, "Effect", Effect_Init()); PyDict_SetItemString (dict, "Effect", Effect_Init());
PyDict_SetItemString (dict, "Text", Text_Init()); PyDict_SetItemString (dict, "Text", Text_Init());
PyDict_SetItemString (dict, "World", World_Init()); PyDict_SetItemString (dict, "World", World_Init());
PyDict_SetItemString (dict, "Texture", Texture_Init());
} }

View File

@@ -337,6 +337,15 @@ int Image_CheckPyObject (PyObject *pyobj)
return (pyobj->ob_type == &Image_Type); return (pyobj->ob_type == &Image_Type);
} }
/*****************************************************************************/
/* Function: Image_FromPyObject */
/* Description: Returns the Blender Image associated with this object */
/*****************************************************************************/
Image *Image_FromPyObject (PyObject *pyobj)
{
return ((BPy_Image *)pyobj)->image;
}
/*****************************************************************************/ /*****************************************************************************/
/* Python BPy_Image methods: */ /* Python BPy_Image methods: */
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -24,7 +24,7 @@
* *
* This is a new part of Blender. * This is a new part of Blender.
* *
* Contributor(s): Willian P. Germano * Contributor(s): Willian P. Germano, Alex Mole
* *
* ***** END GPL/BL DUAL LICENSE BLOCK ***** * ***** END GPL/BL DUAL LICENSE BLOCK *****
*/ */
@@ -55,5 +55,6 @@ extern PyTypeObject Image_Type; /* The Image PyType Object */
PyObject *Image_Init (void); PyObject *Image_Init (void);
PyObject *Image_CreatePyObject (Image *image); PyObject *Image_CreatePyObject (Image *image);
int Image_CheckPyObject (PyObject *pyobj); int Image_CheckPyObject (PyObject *pyobj);
Image *Image_FromPyObject (PyObject *pyobj);
#endif /* EXPP_IMAGE_H */ #endif /* EXPP_IMAGE_H */

View File

@@ -0,0 +1,255 @@
/*
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Alex Mole
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <BKE_main.h>
#include <BKE_global.h>
#include <BKE_object.h>
#include <BKE_library.h>
#include <BLI_blenlib.h>
#include <BKE_texture.h>
#include <BKE_utildefines.h>
#include "MTex.h"
#include "Texture.h"
#include "constant.h"
#include "gen_utils.h"
#include "modules.h"
/*****************************************************************************/
/* Python BPy_MTex methods declarations: */
/*****************************************************************************/
static PyObject *MTex_setTex(BPy_MTex *self, PyObject *args);
/*****************************************************************************/
/* Python method structure definition for Blender.Texture.MTex module: */
/*****************************************************************************/
struct PyMethodDef M_MTex_methods[] = {
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python BPy_MTex methods table: */
/*****************************************************************************/
static PyMethodDef BPy_MTex_methods[] = {
/* name, method, flags, doc */
{"setTex", (PyCFunction)MTex_setTex, METH_VARARGS,
"(i) - Set MTex Texture"},
{0}
};
/*****************************************************************************/
/* Python MTex_Type callback function prototypes: */
/*****************************************************************************/
static void MTex_dealloc (BPy_MTex *self);
static int MTex_setAttr (BPy_MTex *self, char *name, PyObject *v);
static int MTex_compare (BPy_MTex *a, BPy_MTex *b);
static PyObject *MTex_getAttr (BPy_MTex *self, char *name);
static PyObject *MTex_repr (BPy_MTex *self);
/*****************************************************************************/
/* Python MTex_Type structure definition: */
/*****************************************************************************/
PyTypeObject MTex_Type =
{
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"Blender MTex", /* tp_name */
sizeof (BPy_MTex), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)MTex_dealloc, /* tp_dealloc */
0, /* tp_print */
(getattrfunc)MTex_getAttr, /* tp_getattr */
(setattrfunc)MTex_setAttr, /* tp_setattr */
(cmpfunc)MTex_compare, /* tp_compare */
(reprfunc)MTex_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,
0, /* tp_methods */
0, /* tp_members */
};
PyObject *MTex_Init (void)
{
PyObject *submodule;
MTex_Type.ob_type = &PyType_Type;
submodule = Py_InitModule("Blender.Texture.MTex", M_MTex_methods);
return submodule;
}
PyObject *MTex_CreatePyObject (MTex *mtex)
{
BPy_MTex *pymtex;
pymtex = (BPy_MTex *) PyObject_NEW (BPy_MTex, &MTex_Type);
if (!pymtex)
return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create BPy_MTex PyObject");
pymtex->mtex = mtex;
return (PyObject *) pymtex;
}
MTex *MTex_FromPyObject (PyObject *pyobj)
{
return ((BPy_MTex *)pyobj)->mtex;
}
int MTex_CheckPyObject (PyObject *pyobj)
{
return (pyobj->ob_type == &MTex_Type);
}
/*****************************************************************************/
/* Python BPy_MTex methods: */
/*****************************************************************************/
static PyObject *MTex_setTex(BPy_MTex *self, PyObject *args)
{
BPy_Texture *pytex = NULL;
if (!PyArg_ParseTuple(args, "O!", &Texture_Type, &pytex))
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected Texture argument");
if (self->mtex->tex)
self->mtex->tex->id.us--;
self->mtex->tex = Texture_FromPyObject((PyObject*)pytex);
Py_INCREF(Py_None);
return Py_None;
}
static void MTex_dealloc (BPy_MTex *self)
{
PyObject_DEL (self);
}
static PyObject *MTex_getAttr (BPy_MTex *self, char *name)
{
if (STREQ(name, "tex"))
{
if (self->mtex->tex)
return Texture_CreatePyObject (self->mtex->tex);
else
{
Py_INCREF (Py_None);
return Py_None;
}
}
else if (STREQ(name, "texco"))
return PyInt_FromLong(self->mtex->texco);
else if (STREQ(name, "mapto"))
return PyInt_FromLong(self->mtex->mapto);
else if (STREQ(name, "__members__"))
return Py_BuildValue("[s,s,s]", "tex", "texco", "mapto");
/* not an attribute, search the methods table */
return Py_FindMethod(BPy_MTex_methods, (PyObject *)self, name);
}
static int MTex_setAttr (BPy_MTex *self, char *name, PyObject *value)
{
PyObject *valtuple;
PyObject *error = NULL;
/* Put "value" in a tuple, because we want to pass it to functions *
* that only accept PyTuples. */
valtuple = Py_BuildValue("(O)", value);
if (!valtuple)
return EXPP_ReturnIntError(PyExc_MemoryError,
"MTex_setAttr: couldn't create PyTuple");
if (STREQ(name, "tex"))
error = MTex_setTex(self, valtuple);
else if (STREQ(name, "texco"))
{
if (PyInt_Check(value))
{
int texco = PyInt_AsLong(value);
/* TODO: sanity-check this input! */
self->mtex->texco = texco;
Py_INCREF (Py_None); /* because we decref it below */
error = Py_None;
}
}
else if (STREQ(name, "mapto"))
{
if (PyInt_Check(value))
{
int mapto = PyInt_AsLong(value);
/* TODO: sanity-check this input! */
self->mtex->mapto = mapto;
Py_INCREF (Py_None); /* because we decref it below */
error = Py_None;
}
}
else {
/* Error */
Py_DECREF(valtuple);
return EXPP_ReturnIntError (PyExc_KeyError, "attribute not found");
}
Py_DECREF (valtuple);
if (error != Py_None) return -1;
/* Py_None was INCREF'd by the set*() function, so we need to DECREF it */
Py_DECREF (Py_None);
return 0;
}
static int MTex_compare (BPy_MTex *a, BPy_MTex *b)
{
return (a->mtex == b->mtex) ? 0 : -1;
}
static PyObject *MTex_repr (BPy_MTex *self)
{
return PyString_FromFormat("[MTex]");
}

View File

@@ -0,0 +1,65 @@
/*
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Alex Mole
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef EXPP_MTEX_H
#define EXPP_MTEX_H
#include <Python.h>
#include <DNA_texture_types.h>
/*****************************************************************************/
/* Python BPy_MTex structure definition */
/*****************************************************************************/
typedef struct {
PyObject_HEAD
MTex *mtex;
} BPy_MTex;
extern PyTypeObject MTex_Type;
#define BPy_MTex_Check(v) ((v)->ob_type == &MTex_Type)
/*****************************************************************************/
/* Module Blender.Texture.MTex - public functions */
/*****************************************************************************/
PyObject *MTex_Init (void);
PyObject* MTex_CreatePyObject (struct MTex *obj);
int MTex_CheckPyObject (PyObject *py_obj);
MTex* MTex_FromPyObject (PyObject *py_obj);
#endif /* EXPP_MTEX_H */

View File

@@ -24,7 +24,7 @@
* *
* This is a new part of Blender. * This is a new part of Blender.
* *
* Contributor(s): Willian P. Germano, Michel Selten * Contributor(s): Willian P. Germano, Michel Selten, Alex Mole
* *
* ***** END GPL/BL DUAL LICENSE BLOCK ***** * ***** END GPL/BL DUAL LICENSE BLOCK *****
*/ */
@@ -41,6 +41,9 @@
#include "bpy_types.h" #include "bpy_types.h"
#include "modules.h" #include "modules.h"
#include "MTex.h"
#include "Texture.h"
#include "Material.h" #include "Material.h"
/*****************************************************************************/ /*****************************************************************************/
@@ -345,6 +348,7 @@ static PyObject *Material_getNFlares(BPy_Material *self);
static PyObject *Material_getNStars(BPy_Material *self); static PyObject *Material_getNStars(BPy_Material *self);
static PyObject *Material_getNLines(BPy_Material *self); static PyObject *Material_getNLines(BPy_Material *self);
static PyObject *Material_getNRings(BPy_Material *self); static PyObject *Material_getNRings(BPy_Material *self);
static PyObject *Material_getTextures(BPy_Material *self);
static PyObject *Material_setIpo(BPy_Material *self, PyObject *args); static PyObject *Material_setIpo(BPy_Material *self, PyObject *args);
static PyObject *Material_clearIpo(BPy_Material *self); static PyObject *Material_clearIpo(BPy_Material *self);
static PyObject *Material_setName(BPy_Material *self, PyObject *args); static PyObject *Material_setName(BPy_Material *self, PyObject *args);
@@ -373,6 +377,8 @@ static PyObject *Material_setNFlares(BPy_Material *self, PyObject *args);
static PyObject *Material_setNStars(BPy_Material *self, PyObject *args); static PyObject *Material_setNStars(BPy_Material *self, PyObject *args);
static PyObject *Material_setNLines(BPy_Material *self, PyObject *args); static PyObject *Material_setNLines(BPy_Material *self, PyObject *args);
static PyObject *Material_setNRings(BPy_Material *self, PyObject *args); static PyObject *Material_setNRings(BPy_Material *self, PyObject *args);
static PyObject *Material_setTexture(BPy_Material *self, PyObject *args);
static PyObject *Material_clearTexture(BPy_Material *self, PyObject *args);
static PyObject *Material_setColorComponent(BPy_Material *self, char *key, static PyObject *Material_setColorComponent(BPy_Material *self, char *key,
PyObject *args); PyObject *args);
@@ -435,6 +441,8 @@ static PyMethodDef BPy_Material_methods[] = {
"() - Return Material's number of lines in halo"}, "() - Return Material's number of lines in halo"},
{"getNRings", (PyCFunction)Material_getNRings, METH_NOARGS, {"getNRings", (PyCFunction)Material_getNRings, METH_NOARGS,
"() - Return Material's number of rings in halo"}, "() - Return Material's number of rings in halo"},
{"getTextures", (PyCFunction)Material_getTextures, METH_NOARGS,
"() - Return Material's texture list as a tuple"},
{"setName", (PyCFunction)Material_setName, METH_VARARGS, {"setName", (PyCFunction)Material_setName, METH_VARARGS,
"(s) - Change Material's name"}, "(s) - Change Material's name"},
{"setIpo", (PyCFunction)Material_setIpo, METH_VARARGS, {"setIpo", (PyCFunction)Material_setIpo, METH_VARARGS,
@@ -491,6 +499,10 @@ static PyMethodDef BPy_Material_methods[] = {
"(i) - Set Material's number of lines in halo - [0, 250]"}, "(i) - Set Material's number of lines in halo - [0, 250]"},
{"setNRings", (PyCFunction)Material_setNRings, METH_VARARGS, {"setNRings", (PyCFunction)Material_setNRings, METH_VARARGS,
"(i) - Set Material's number of rings in halo - [0, 24]"}, "(i) - Set Material's number of rings in halo - [0, 24]"},
{"setTexture", (PyCFunction)Material_setTexture, METH_VARARGS,
"(n,tex,texco=0,mapto=0) - Set numbered texture to tex"},
{"clearTexture", (PyCFunction)Material_clearTexture, METH_VARARGS,
"(n) - Remove texture from numbered slot"},
{0} {0}
}; };
@@ -878,6 +890,36 @@ static PyObject *Material_getNRings(BPy_Material *self)
"couldn't get Material.nRings attribute"); "couldn't get Material.nRings attribute");
} }
static PyObject *Material_getTextures(BPy_Material *self)
{
int i;
struct MTex *mtex;
PyObject *t[8];
PyObject *tuple;
/* build a texture list */
for (i=0; i<8; ++i) {
mtex = self->material->mtex[i];
if (mtex) {
t[i] = MTex_CreatePyObject (mtex);
}
else {
Py_INCREF (Py_None);
t[i] = Py_None;
}
}
/* turn the array into a tuple */
tuple = Py_BuildValue ("NNNNNNNN", t[0], t[1], t[2], t[3],
t[4], t[5], t[6], t[7]);
if (!tuple)
return EXPP_ReturnPyObjError(PyExc_MemoryError,
"Material_getTextures: couldn't create PyTuple");
return tuple;
}
static PyObject *Material_setIpo(BPy_Material *self, PyObject *args) static PyObject *Material_setIpo(BPy_Material *self, PyObject *args)
{ {
PyObject *pyipo = 0; PyObject *pyipo = 0;
@@ -1352,6 +1394,65 @@ static PyObject *Material_setNRings(BPy_Material *self, PyObject *args)
return EXPP_incr_ret (Py_None); return EXPP_incr_ret (Py_None);
} }
static PyObject *Material_setTexture(BPy_Material *self, PyObject *args)
{
int texnum;
PyObject *pytex;
Tex *bltex;
int texco=TEXCO_ORCO, mapto=MAP_COL;
if (!PyArg_ParseTuple(args, "iO!|ii", &texnum, &Texture_Type, &pytex,
&texco, &mapto))
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int in [0,7] and Texture");
if ((texnum<0) || (texnum>=8))
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int in [0,7] and Texture");
bltex = Texture_FromPyObject (pytex);
if (!self->material->mtex[texnum]) {
/* there isn't an mtex for this slot so we need to make one */
self->material->mtex[texnum] = add_mtex ();
}
else {
/* we already had a texture here so deal with the old one first */
self->material->mtex[texnum]->tex->id.us--;
}
self->material->mtex[texnum]->tex = bltex;
id_us_plus (&bltex->id);
self->material->mtex[texnum]->texco = texco;
self->material->mtex[texnum]->mapto = mapto;
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *Material_clearTexture(BPy_Material *self, PyObject *args)
{
int texnum;
struct MTex *mtex;
if (!PyArg_ParseTuple(args, "i", &texnum))
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int in [0,7]");
if ((texnum<0) || (texnum>=8))
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int in [0,7]");
mtex = self->material->mtex[texnum];
if (mtex) {
if (mtex->tex)
mtex->tex->id.us--;
MEM_freeN (mtex);
self->material->mtex[texnum] = NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
/*****************************************************************************/ /*****************************************************************************/
/* Function: Material_getAttr */ /* Function: Material_getAttr */
/* Description: This is a callback function for the BPy_Material type. It is */ /* Description: This is a callback function for the BPy_Material type. It is */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,67 @@
/*
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Alex Mole
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/* based on Image.h */
#ifndef EXPP_TEXTURE_H
#define EXPP_TEXTURE_H
#include <Python.h>
#include <DNA_texture_types.h>
#include <BKE_texture.h>
/*****************************************************************************/
/* Python BPy_Texture structure definition */
/*****************************************************************************/
typedef struct {
PyObject_HEAD
Tex *texture;
} BPy_Texture;
extern PyTypeObject Texture_Type;
#define BPy_Texture_Check(v) ((v)->ob_type == &Texture_Type)
/*****************************************************************************/
/* Module Blender.Texture - public functions */
/*****************************************************************************/
PyObject * Texture_Init(void);
PyObject * Texture_CreatePyObject(struct Tex *tex);
int Texture_CheckPyObject(PyObject *pyobj);
Tex * Texture_FromPyObject (PyObject *pyobj);
#endif /* EXPP_TEXTURE_H */

View File

@@ -24,7 +24,7 @@
* *
* This is a new part of Blender. * This is a new part of Blender.
* *
* Contributor(s): Willian P. Germano * Contributor(s): Willian P. Germano, Alex Mole
* *
* ***** END GPL/BL DUAL LICENSE BLOCK ***** * ***** END GPL/BL DUAL LICENSE BLOCK *****
*/ */
@@ -53,6 +53,8 @@ PyObject *Types_Init (void)
/* Another one that needs to be here: */ /* Another one that needs to be here: */
Text_Type.ob_type = &PyType_Type; Text_Type.ob_type = &PyType_Type;
Texture_Type.ob_type = &PyType_Type;
submodule = Py_InitModule3 ("Blender.Types", Null_methods, M_Types_doc); submodule = Py_InitModule3 ("Blender.Types", Null_methods, M_Types_doc);
dict = PyModule_GetDict(submodule); dict = PyModule_GetDict(submodule);

View File

@@ -24,7 +24,7 @@
* *
* This is a new part of Blender. * This is a new part of Blender.
* *
* Contributor(s): Willian P. Germano * Contributor(s): Willian P. Germano, Alex Mole
* *
* ***** END GPL/BL DUAL LICENSE BLOCK ***** * ***** END GPL/BL DUAL LICENSE BLOCK *****
*/ */
@@ -36,6 +36,8 @@
extern PyTypeObject Button_Type, Material_Type; extern PyTypeObject Button_Type, Material_Type;
extern PyTypeObject Texture_Type;
extern PyTypeObject Object_Type; extern PyTypeObject Object_Type;
extern PyTypeObject Scene_Type; extern PyTypeObject Scene_Type;
extern PyTypeObject NMesh_Type, NMFace_Type, NMVert_Type, NMCol_Type; extern PyTypeObject NMesh_Type, NMFace_Type, NMVert_Type, NMCol_Type;

View File

@@ -24,6 +24,7 @@ The Blender Python API Reference
- L{Object} - L{Object}
- L{NMesh} - L{NMesh}
- L{Material} - L{Material}
- L{Texture}
- L{Armature} - L{Armature}
- L{Camera} - L{Camera}
- L{Lamp} - L{Lamp}

View File

@@ -57,7 +57,7 @@ float EXPP_ClampFloat (float value, float min, float max)
/* Description: This function returns true if both given strings are equal, */ /* Description: This function returns true if both given strings are equal, */
/* otherwise it returns false. */ /* otherwise it returns false. */
/*****************************************************************************/ /*****************************************************************************/
int StringEqual (char * string1, char * string2) int StringEqual (const char * string1, const char * string2)
{ {
return (strcmp(string1, string2)==0); return (strcmp(string1, string2)==0);
} }
@@ -188,3 +188,70 @@ PyObject *EXPP_tuple_repr(PyObject *self, int size)
return repr; return repr;
} }
/****************************************************************************/
/* Description: searches through a map for a pair with a given name. If the */
/* pair is present, its ival is stored in *ival and nonzero is */
/* returned. If the pair is absent, zero is returned. */
/****************************************************************************/
int EXPP_map_getIntVal (const EXPP_map_pair *map, const char *sval, int *ival)
{
while (map->sval)
{
if (StringEqual(sval, map->sval))
{
*ival = map->ival;
return 1;
}
++map;
}
return 0;
}
/****************************************************************************/
/* Description: searches through a map for a pair with a given name. If the */
/* pair is present, its ival is stored in *ival and nonzero is */
/* returned. If the pair is absent, zero is returned. */
/* note: this function is identical to EXPP_map_getIntVal except that the */
/* output is stored in a short value. */
/****************************************************************************/
int EXPP_map_getShortVal (const EXPP_map_pair *map,
const char *sval, short *ival)
{
while (map->sval)
{
if (StringEqual(sval, map->sval))
{
*ival = map->ival;
return 1;
}
++map;
}
return 0;
}
/****************************************************************************/
/* Description: searches through a map for a pair with a given ival. If the */
/* pair is present, a pointer to its name is stored in *sval */
/* and nonzero is returned. If the pair is absent, zero is */
/* returned. */
/****************************************************************************/
int EXPP_map_getStrVal (const EXPP_map_pair *map,
int ival, const char **sval)
{
while (map->sval)
{
if (ival == map->ival)
{
*sval = map->sval;
return 1;
}
++map;
}
return 0;
}

View File

@@ -24,7 +24,7 @@
* *
* This is a new part of Blender. * This is a new part of Blender.
* *
* Contributor(s): Michel Selten, Willian P. Germano * Contributor(s): Michel Selten, Willian P. Germano, Alex Mole
* *
* ***** END GPL/BL DUAL LICENSE BLOCK ***** * ***** END GPL/BL DUAL LICENSE BLOCK *****
*/ */
@@ -44,7 +44,7 @@
#include <DNA_scriptlink_types.h> #include <DNA_scriptlink_types.h>
#include <DNA_listBase.h> #include <DNA_listBase.h>
int StringEqual (char * string1, char * string2); int StringEqual (const char * string1, const char * string2);
char * GetIdName (ID *id); char * GetIdName (ID *id);
ID *GetIdFromList(ListBase *list, char *name); ID *GetIdFromList(ListBase *list, char *name);
@@ -63,4 +63,19 @@ int EXPP_ReturnIntError (PyObject *type, char *error_msg);
int EXPP_check_sequence_consistency (PyObject *seq, PyTypeObject *against); int EXPP_check_sequence_consistency (PyObject *seq, PyTypeObject *against);
PyObject *EXPP_tuple_repr(PyObject *self, int size); PyObject *EXPP_tuple_repr(PyObject *self, int size);
/* mapping utilities - see Texture.c for an example of how to use these */
typedef struct {
const char *sval;
int ival;
} EXPP_map_pair;
/* maps must end with a pair that has NULL as sval */
int EXPP_map_getIntVal (const EXPP_map_pair *map,
const char *sval, int *ival);
int EXPP_map_getShortVal (const EXPP_map_pair *map,
const char *sval, short *ival);
int EXPP_map_getStrVal (const EXPP_map_pair *map,
int ival, const char **sval);
#endif /* EXPP_gen_utils_h */ #endif /* EXPP_gen_utils_h */

View File

@@ -102,6 +102,9 @@ void EXPP_incr_mats_us (Material **matlist, int len);
PyObject * EXPP_PyList_fromMaterialList(Material **matlist, int len); PyObject * EXPP_PyList_fromMaterialList(Material **matlist, int len);
Material * GetMaterialByName (char * name); Material * GetMaterialByName (char * name);
/* Texture */
PyObject * Texture_Init (void);
/* Camera Data */ /* Camera Data */
PyObject * Camera_Init (void); PyObject * Camera_Init (void);
PyObject * Camera_CreatePyObject (struct Camera *cam); PyObject * Camera_CreatePyObject (struct Camera *cam);