PyTex: which face?

I was wondering: is there any way to find out for which face of a mesh the PyTex script is being called?
Or in other words: On which face is the pixel that is currently being rendered?

I saw someone mention a SSS Pytex script some time ago. Surly that would have requred to know some information about faces and world coordinates of the rended pixel.

Is raytracing the solution?

Thanks for any help!

To make things like this :



Well, what i actually want to write is a PyTex that just gets the Vertex colours. That way we could use grayscale vertex colours as a stencil map for example. That way we could paint stencil maps directly onto the mesh!

JMS, I worked though your code, but you don’t actually find out the face-number, but only use a very tricky method to find the edges. Am i right?

Anyway, to extract the vertexcolor i need to know the ID of the face that is being rendered, and the coordinates, so that i can get the vertex colour and interpolate them.

The coordinates could be get by setting the mapping of the texture to “global” and calculating these coords into local object space.
Or the mapping option “orco” could be used, but only if texture coordiates = local space coordinates.

But then i still have to find out the number of the face (vertex colours are stored in the face, AFAIK)
I think raytracing is the only option at the moment, though it would be great to have a Pxtex function to get the face-number.
Raytracing would take rather long i guess.

If anyone knows a better method, or has any idea please tell me. :slight_smile:
Or if anyone is willing to develop the script, go ahead!

I think this would be a very nice feature to have in Blender. At the moment it sounds like doing quite a lot of workarounds in python.

hum, …
I can write something but for non coplanar faces only …