Object info - material node: is it possible to map the object worldPosition with an UVmap?

You can get the UV of a face with rayCast, use the UV to set maybe the color of the object and use a Object Data node to get the color and connect it to the UV Vector socket of the Texture node.

from bge import logic, render
from mathutils import Vector
from math import floor

cont = logic.getCurrentController()
own = cont.owner

prop = ""
xray = 0
range = 10.0

rayDir = own.worldPosition + Vector((0.0, 0.0, -1.0))
Ray = own.rayCast(rayDir, own, range, prop, 0, xray, 2)

if Ray[3]:
    u = Ray[4][0]
    v = Ray[4][1]
    # keep in range [0.0, 1.0]
    u -= floor(u)
    v -= floor(v)
    # the texture node uses uvs in the range [-1.0, 1.0]
    own.color = [u*2.0-1.0, v*2.0-1.0, 0.0, 1.0]
    
    own['u'] = u
    own['v'] = v
    
    render.drawLine(own.worldPosition, Ray[1], [0.0, 1.0, 0.0])

If it hits an object wihout uv, the uv will be (0.0, 0.0), so you may want to use a prop and xray.

rayCastUV.blend (92.0 KB)

1 Like