UV Alignment to vertex Position (Cave x16 style)

I’m basically talking about this effect,


How is it done? Getting the two vertexes to go to a certain position, and the seamless UV texture to stretch with it?

It’s done by magic (the node texture). I’ll write up a resource on this later today.


obligatory

http://i.imgur.com/EUlfIPK.gif


import bge
from time import time
from math import sin


def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner
    mesh = own.meshes[0]


    v1, v2 = mesh.getVertex(0, 2),mesh.getVertex(0, 3)
   
    alpha = 1 + abs(sin(time()*2)) * 10
    
    v1.y, v2.y = alpha, alpha
    
    v1.v, v2.v = alpha, alpha


main()

In short, edit the vertex pos and UV properties.
https://www.blender.org/api/blender_python_api_2_73_5/bge.types.KX_VertexProxy.html#bge.types.KX_VertexProxy

Didn’t know you would need magic/nodes for this kind simple thing?
:spin:

EDIT: yeah right, my bad, you need magic when you dont want to use libnew!
(see the post below)

@VegetableJuiceF:
But there are multiple vehicles, which have multiple of those pointers, so manipulating the mesh is not an option (unless I want to use LibNew, which I don’t unless absolutely necessary).

So. How is it done?
It is object-color driven UV manipulation in a node shader. Because object colour is per-instance, this means all those pointers share a mesh but can have different lengths.

*** Create a material:


The first step is to get object colour into a node shader. This is a little cryptic, and takes a few steps.
First, create a shadeless material and enable object colour:


***Add the ability to scale the texture
***Turn the material into a node material and create the following:



What’s going on here?
Well, we grab the UV channel and split it into U and V (and non-used W) components. Then we can scale the U channel by the red channel of the object colour.
Now, by playing with the red channel of the object color, you should be able to scale the texture!

***Add the ability to scroll the texture
***We want to be able to scroll the texture. So we’ll modify the node setup like this:



We’re adding the green channel to the UV position, so by changing the G slider on the object colour, we can move it backwards and forwards.

***Controlling the Colour
***Now let’s say we want to be able to control the color. We can do that by feeding the remaining object color channel into the hue node and using it to set the colour channel:


And there we have it.
Here is the blend:
NodeUVAlter.blend (522 KB)

The scaling and position can now be altered by using obj.color in python, or animations or any other methods.


It is worth mentioning a few things:

  • From blenders interface, the color sliders have the range 0.0 - 1.0, but from python, you can use normal floating point numbers going higher (eg 2.5, 354.3 etc).
  • This is implemented in CaveX16 in the file “Models/UI/Indicators.blend”.
  • You can set the material to ‘add’ type alpha blending to make them layer nicely on top of other objects (as I did in CaveX16)

Thanks a lot guys! :slight_smile: