using the uv "project to view" function in game

Hi all,

I want to call the “Project from view” function in a script, which is accessed when pressing U in edit mode, so that the texture of an object can face the camera at every frame.

Does anyone know how this can be done?

Many thanks

1/1 credit(s)

I see two options:
1 - write a GLSL shader - need a GLSL compatible Gfx
2 - set the UV for each vertex of the object - this is very very slow!

Is there a reason you can’t use billboarding/halos?

@ Monster - I was thinking of making a GLSL shader, but at the moment I only have very basic skills. Surely the source for the UV function uses openGL, so it could be used in a script? Do you know how to do the slow vertex method or the GLSL method? It would help a lot…

@ Moguri - I can’t do billboarding/halos because I’m trying to make the texture of a large, complex object, like a house, have its texture permenantly face the camera. Although, it would be awesome if there is a button in blender to do just that!

Thank you both for your help so far.

1/1 credit(s)

I can’t help with GLSL. Mainly I do not have a GLSL compatible laptop. This is the reason because I never looked at this in detail.

For the other option check the KX_MeshProxy. This enables you to set the UV of each vertex. As I said, this is slow especially when used on objects with a lot of vertices.

I see what you mean when you say use KX_MeshProxy. Obviously, the vertices should be given UV coordinates based on the position of the camera, in order to make the texture face the camera.

I suppose that a vector from the camera could be used to calculate the right UV coordinates??? :eek: hm… Basically I have no idea how to calculate the right coordinates - I am way out of my depth now! Your help is very much appreciated BTW!!

Many thanks,

1/1 credit(s)

3rd option - Material Node editor - using View Coodrinates as UV input for texture

The nodes method seems to work great! Thanks much!!

Feel free to check out the simple example - could you tell me if I’m connecting anything incorrectly; I feel the material needs to be connected to something… or not.

ANYWAY, thank you very much!!


brickTest.blend (458 KB)

Alternately, instead of using nodes, you could just map the texture to camera or normal in the mapping pane for the texture in the materials buttons.