From b2acdd69b037b8363dd2c214ccc0a2af691ab017 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 2 Mar 2007 09:48:04 +0000 Subject: vector.c - bugfix, vec.w accessed vec[4] not vec[3]! (probably my fault) Texture.c - added "val = tex.evaluate(vec)" so you can find the color/intensity at a given loaction for a texture. --- source/blender/python/api2_2x/Texture.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source/blender/python/api2_2x/Texture.c') diff --git a/source/blender/python/api2_2x/Texture.c b/source/blender/python/api2_2x/Texture.c index 2a0f4af45aa..12caa55fce5 100644 --- a/source/blender/python/api2_2x/Texture.c +++ b/source/blender/python/api2_2x/Texture.c @@ -53,6 +53,9 @@ #include "blendef.h" #include "gen_utils.h" +#include "vector.h" /* for Texture_evaluate(vec) */ +#include "RE_shader_ext.h" + /*****************************************************************************/ /* Blender.Texture constants */ /*****************************************************************************/ @@ -487,6 +490,8 @@ static int Texture_setImageFlags( BPy_Texture *self, PyObject *args, void *type ); static int Texture_setNoiseBasis2( BPy_Texture *self, PyObject *args, void *type ); + +static PyObject *Texture_evaluate( BPy_Texture *self, PyObject *args ); /*****************************************************************************/ /* Python BPy_Texture methods table: */ @@ -529,6 +534,8 @@ static PyMethodDef BPy_Texture_methods[] = { "(s) - Set Dist Noise"}, {"setDistMetric", ( PyCFunction ) Texture_oldsetDistMetric, METH_VARARGS, "(s) - Set Dist Metric"}, + {"evaluate", ( PyCFunction ) Texture_evaluate, METH_VARARGS, + "(vector) - evaluate the texture at this position"}, {NULL, NULL, 0, NULL} }; @@ -2644,3 +2651,25 @@ static PyObject *Texture_oldsetImageFlags( BPy_Texture * self, PyObject * args ) Py_RETURN_NONE; } +static PyObject *Texture_evaluate( BPy_Texture * self, PyObject * args ) +{ + VectorObject *vec_in = NULL; + TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL}; + float vec[4]; + /* int rgbnor; dont use now */ + + if(!PyArg_ParseTuple(args, "O!", &vector_Type, &vec_in) || vec_in->size < 3) + return EXPP_ReturnPyObjError(PyExc_TypeError, + "expects a 3D vector object\n"); + + /* rgbnor = .. we dont need this now */ + multitex_ext(self->texture, vec_in->vec, 1, 1, 1, &texres); + + vec[0] = texres.tr; + vec[1] = texres.tg; + vec[2] = texres.tb; + vec[3] = texres.tin; + + return newVectorObject(vec, 4, Py_NEW); +} + -- cgit v1.2.3