|
surface - surface handle index - index of the vertex, from 0 to CountVertices( surface )-1 |
|
Returns the red component of a vertex's colour, in the range 0 to 255. Vertex colours are set with VertexColor (new vertices start white, 255,255,255) and blend smoothly across each triangle. Reading them back is handy when you tint geometry gradually - fading a trail, darkening damaged areas, baking your own lighting - because you can read, adjust and rewrite the value each frame. Remember that vertex colours only show up on entities using EntityFX or BrushFX flag 2. See also: VertexGreen, VertexBlue, VertexAlpha, VertexColor, EntityFX. |
; VertexRed Example
; -----------------
; Every vertex stores a position, a normal, a colour and a set of
; uv texture coordinates. VertexRed reads back the red component (0-255) 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)
; One colour per vertex (EntityFX 2 displays vertex colours)
VertexColor surf,v0,255,0,0
VertexColor surf,v1,0,255,0
VertexColor surf,v2,0,0,255
VertexColor surf,v3,255,255,0
VertexColor surf,v4,255,255,255
EntityFX mesh,2
; 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#=VertexRed(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,"VertexRed(surf,"+index+") = "+value
Text 0,40,"Corner colours: red, green, blue, yellow; apex white"
Flip
Wend
End