VertexU# ( surface,index[,coord_set] )
Parameters
|
surface - surface handle index - index of the vertex, from 0 to CountVertices( surface )-1 coord_set (optional) - which texture coordinate set to read: 0: first coordinate set (default) 1: second coordinate set |
Description
|
Returns the u texture coordinate of a vertex. The u axis runs across the texture: 0 is the image's left edge, 1 its right edge, and values beyond that tile it. AddVertex writes its u,v into both coordinate sets; VertexTexCoords can set them separately, and this command reads whichever set you ask for. The usual reason to read u,v back is scrolling or animating a texture mapping vertex by vertex: read, add a little, write back with VertexTexCoords each frame. See also: VertexV, VertexW, VertexTexCoords, TextureCoords. |
Example
; VertexU Example ; --------------- ; Every vertex stores a position, a normal, a colour and a set of ; uv texture coordinates. VertexU reads back the u texture coordinate of one vertex. ; Space steps the magenta marker through the pyramid's five vertices. Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,1,-4 light=CreateLight() RotateEntity light,45,45,0 ; A small pyramid: base corners v0-v3 and apex v4 mesh=CreateMesh() surf=CreateSurface(mesh) v0=AddVertex(surf,-1,0,-1,0,1) v1=AddVertex(surf,1,0,-1,1,1) v2=AddVertex(surf,1,0,1,1,0) v3=AddVertex(surf,-1,0,1,0,0) v4=AddVertex(surf,0,1.5,0,0.5,0.5) ; Texture the pyramid so the uv mapping is visible (fullbright) tex=LoadTexture("media/b3dlogo.jpg") EntityTexture mesh,tex EntityFX mesh,1 ; Sides then base, wound clockwise seen from outside AddTriangle surf,v0,v4,v1 AddTriangle surf,v1,v4,v2 AddTriangle surf,v2,v4,v3 AddTriangle surf,v3,v4,v0 AddTriangle surf,v2,v1,v0 AddTriangle surf,v3,v2,v0 ; A marker sphere parented to the mesh highlights the queried vertex marker=CreateSphere() ScaleEntity marker,0.1,0.1,0.1 EntityColor marker,255,0,255 EntityFX marker,1 EntityParent marker,mesh index=0 While Not KeyDown(1) ; Space cycles through vertices 0-4 If KeyHit(57) Then index=(index+1) Mod 5 ; Query the highlighted vertex - the documented command value#=VertexU(surf,index) ; Park the marker on the queried vertex (local mesh coordinates) PositionEntity marker,VertexX(surf,index),VertexY(surf,index),VertexZ(surf,index) TurnEntity mesh,0,1,0 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Space: next vertex Arrow keys: move camera Esc: exit" Text 0,20,"VertexU(surf,"+index+") = "+value Text 0,40,"uv 0,0 = texture top left; uv 1,1 = bottom right" Flip Wend End
Index