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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -469,6 +469,15 @@ class Texture:
|
||||
and 'DistNoise'
|
||||
@type type: string
|
||||
"""
|
||||
def evaluate(coord):
|
||||
"""
|
||||
Evaluates the texture at this location and returns the result.
|
||||
|
||||
The return value is a 4D vector where (x,y,z,w) are (red, green, blue, intensity)
|
||||
For greyscale textures, often intensity only will be used.
|
||||
@type coord: vector
|
||||
"""
|
||||
|
||||
import id_generics
|
||||
Texture.__doc__ += id_generics.attributes
|
||||
|
||||
|
||||
@@ -959,7 +959,7 @@ static PyObject *Vector_getAxis( VectorObject * self, void *type )
|
||||
return EXPP_ReturnPyObjError(PyExc_AttributeError,
|
||||
"vector.w: error, cannot get this axis for a 3D vector\n");
|
||||
|
||||
return PyFloat_FromDouble(self->vec[4]);
|
||||
return PyFloat_FromDouble(self->vec[3]);
|
||||
default:
|
||||
{
|
||||
char errstr[1024];
|
||||
|
||||
Reference in New Issue
Block a user