Python textures?


I am wondering if there is any way to define a texture using python. For example, imagine that I have a python function that takes co-ordinates as an input, does some calculation, and returns a colour or a value. Is there a way to use that function as a texture?

The reason I ask is, I was thinking that it would be nice to have a way to use python scripts as nodes in the material nodes editor. Then I realised that all I would have to do is write a texture plugin that does nothing except call a specified python script.

Well, it’s a bit tricky because I don’t remember how to call python functions from C, so I don’t want to write it if there’s another way to do it. But otherwise I’ll write the plugin. The idea is to have the plugin simply as a wrapper for a python script. The user supplies a python script that takes co-ordinates and defines patterns or whatever with them, rather than writing a separate plugin for each pattern. Suppose I have a one-line python function that says return_value =sin(x). Instead of writing a plugin in C just to do that, I take my generic plugin, give it the name of my python file, and I’m done.

Maybe this helps?

Yes, I suppose you could write scripts to generate images, then use the images as textures, but it would be better to cut out the image and do it directly as a texture plugin.

I tried writing this, but it seems I’ve been foiled. Unless I missed something, there is no way in the plugin API to have a string as an input parameter for the plugin, only numbers. That being the case, there is no way to specify the name of the python script for the plugin to use.

Oh well, as I said it wouldn’t have added any functionality anyway. It just would have allowed textures to be defined in python instead of C.