Blitz3D+ Command Reference

VertexCoords surface,index,x#,y#,z#

Parameters

surface - surface handle
index - index of the vertex, from 0 to CountVertices( surface )-1
x# - new x position of the vertex
y# - new y position of the vertex
z# - new z position of the vertex

Description

Moves an existing vertex to a new position.

This is the command behind dynamic mesh deformation: every triangle edge connected to the vertex follows it, so sweeping over a surface's vertices each frame produces waves on water, flapping flags, breathing creatures or melting props. The position is relative to the entity's pivot, like everything else in the mesh.

Moving vertices does not update their normals, so lighting keeps the old directions - call UpdateNormals (or set them yourself with VertexNormal) after reshaping, or deformed areas will shade wrongly.

See also: VertexX, VertexY, VertexZ, AddVertex, UpdateNormals, CountVertices.

Example

; VertexCoords Example
; --------------------

; VertexCoords moves an existing vertex to a new position. Moving
; vertices every frame animates the mesh itself - here it turns a
; flat textured grid into a waving flag.

Graphics3D 640,480
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,0,-5

flag=CreateMesh()
surf=CreateSurface(flag)

; Build a 16 x 10 grid of vertices with uv coords spread 0..1
For j=0 To 9
    For i=0 To 15
        AddVertex surf,i*0.25-2,1.2-j*0.25,0,i/15.0,j/9.0
    Next
Next

; Connect each grid cell with two clockwise triangles
For j=0 To 8
    For i=0 To 14
        v00=j*16+i
        AddTriangle surf,v00,v00+1,v00+17
        AddTriangle surf,v00,v00+17,v00+16
    Next
Next

; Texture the flag so the ripple is easy to see
tex=LoadTexture("media/b3dlogo.jpg")
EntityTexture flag,tex

; Fullbright (1) + two-sided (16) so both sides of the cloth show
EntityFX flag,17

While Not KeyDown(1)

    ; Ripple the cloth: reposition every vertex each frame.
    ; The wave grows towards the free (right) end of the flag.
    t#=MilliSecs()*0.25
    For j=0 To 9
        For i=0 To 15
            z#=Sin(t+i*40)*0.03*i
            VertexCoords surf,j*16+i,i*0.25-2,1.2-j*0.25,z
        Next
    Next

    ; 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,"Arrow keys: move camera   Esc: exit"
    Text 0,20,"VertexCoords repositions all 160 vertices every frame"

    Flip

Wend

End

Index