Hi all!
I have been wondering for a while how one might go about creating static UV coordinates, and whilst i had theoretically sound code (i tried 2 methods) there seemed to be a factor of error.
I recently tried to determine this factor, but couldn’t establish what relationship it had with the object, until i realised i had to divide the (original global coordinates-new global coordinates) / the scale of object in the direction it’s travelling!?
Here’s an extract:
Note you have to re-unwrap the object if you change the scale!
import bge
from mathutils import*
cont = bge.logic.getCurrentController()
own = cont.owner
mesh =own.meshes[0]
array = mesh.getVertexArrayLength(0)
pos = own.worldPosition
npos = Vector([pos[0],pos[1]])
if not "uv" in own:
uv_coords = {v:mesh.getVertex(0,v).getUV() for v in range(array)}
own["uv"] = {a:b+npos for a,b in uv_coords.items()}
for vert_id,gpos in own["uv"].items():
print(own.localScale)
mesh.getVertex(0,vert_id).setUV(gpos-npos/own.localScale[1])