texture evaluation function (like we had in 2.4x api), requested by Lee.

eg:
 red, green, blue, intensity = texture.evaluate(vec)
This commit is contained in:
Campbell Barton 2011-09-06 10:49:55 +00:00
parent 32287bebe8
commit 7062788017
3 changed files with 45 additions and 12 deletions

@ -261,6 +261,7 @@ void RNA_api_wm(struct StructRNA *srna);
void RNA_api_sensor(struct StructRNA *srna); void RNA_api_sensor(struct StructRNA *srna);
void RNA_api_controller(struct StructRNA *srna); void RNA_api_controller(struct StructRNA *srna);
void RNA_api_actuator(struct StructRNA *srna); void RNA_api_actuator(struct StructRNA *srna);
void RNA_api_texture(struct StructRNA *srna);
void RNA_api_environment_map(struct StructRNA *srna); void RNA_api_environment_map(struct StructRNA *srna);
/* main collection functions */ /* main collection functions */

@ -1820,6 +1820,8 @@ static void rna_def_texture(BlenderRNA *brna)
rna_def_texture_pointdensity(brna); rna_def_texture_pointdensity(brna);
rna_def_texture_voxeldata(brna); rna_def_texture_voxeldata(brna);
/* XXX add more types here .. */ /* XXX add more types here .. */
RNA_api_texture(srna);
} }
void RNA_def_texture(BlenderRNA *brna) void RNA_def_texture(BlenderRNA *brna)

@ -43,6 +43,7 @@
#include "BKE_context.h" #include "BKE_context.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "RE_pipeline.h" #include "RE_pipeline.h"
#include "RE_shader_ext.h"
void save_envmap(struct EnvMap *env, bContext *C, ReportList *reports, const char* filepath, struct Scene *scene, float layout[12]) void save_envmap(struct EnvMap *env, bContext *C, ReportList *reports, const char* filepath, struct Scene *scene, float layout[12])
{ {
@ -67,30 +68,59 @@ void clear_envmap(struct EnvMap *env, bContext *C)
} }
} }
void texture_evaluate(struct Tex *tex, float value[3], float color_r[3])
{
TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
multitex_ext(tex, value, NULL, NULL, 1, &texres);
color_r[0] = texres.tr;
color_r[1] = texres.tg;
color_r[2] = texres.tb;
color_r[3] = texres.tin;
}
#else #else
void RNA_api_texture(StructRNA *srna)
{
FunctionRNA *func;
PropertyRNA *parm;
func= RNA_def_function(srna, "evaluate", "texture_evaluate");
RNA_def_function_ui_description(func, "Evaluate the texture at the coordinates given");
parm= RNA_def_float_vector(func, "value", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
RNA_def_property_flag(parm, PROP_REQUIRED);
/* return location and normal */
parm= RNA_def_float_vector(func, "result", 4, NULL, -FLT_MAX, FLT_MAX, "Result", NULL, -1e4, 1e4);
RNA_def_property_flag(parm, PROP_THICK_WRAP);
RNA_def_function_output(func, parm);
}
void RNA_api_environment_map(StructRNA *srna) void RNA_api_environment_map(StructRNA *srna)
{ {
FunctionRNA *func; FunctionRNA *func;
PropertyRNA *parm; PropertyRNA *parm;
static const float default_layout[] = { 0,0, 1,0, 2,0, 0,1, 1,1, 2,1 }; static const float default_layout[] = { 0,0, 1,0, 2,0, 0,1, 1,1, 2,1 };
func= RNA_def_function(srna, "clear", "clear_envmap"); func= RNA_def_function(srna, "clear", "clear_envmap");
RNA_def_function_ui_description(func, "Discard the environment map and free it from memory."); RNA_def_function_ui_description(func, "Discard the environment map and free it from memory.");
RNA_def_function_flag(func, FUNC_USE_CONTEXT); RNA_def_function_flag(func, FUNC_USE_CONTEXT);
func= RNA_def_function(srna,"save", "save_envmap"); func= RNA_def_function(srna,"save", "save_envmap");
RNA_def_function_ui_description(func, "Save the environment map to disc using the scene render settings."); RNA_def_function_ui_description(func, "Save the environment map to disc using the scene render settings.");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS); RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
parm= RNA_def_string_file_name(func,"filepath","",FILE_MAX,"File path","Location of the output file");
RNA_def_property_flag(parm, PROP_REQUIRED);
RNA_def_pointer(func, "scene", "Scene", "", "Overrides the scene from which image parameters are taken.");
parm = RNA_def_float_array(func, "layout", 12, default_layout, 0.0f, 0.0f, "File layout", "Flat array describing the X,Y position of each cube face in the output image, where 1 is the size of a face. Order is [+Z -Z +Y -X -Y +X]. Use -1 to skip a face.", 0.0f, 0.0f); parm= RNA_def_string_file_name(func,"filepath","",FILE_MAX,"File path","Location of the output file");
RNA_def_property_flag(parm, PROP_REQUIRED);
RNA_def_pointer(func, "scene", "Scene", "", "Overrides the scene from which image parameters are taken.");
parm = RNA_def_float_array(func, "layout", 12, default_layout, 0.0f, 0.0f, "File layout", "Flat array describing the X,Y position of each cube face in the output image, where 1 is the size of a face. Order is [+Z -Z +Y -X -Y +X]. Use -1 to skip a face.", 0.0f, 0.0f);
} }
#endif #endif