sswift.. here's an example demonstrating it. Most of the code you can ignore - the key parts are MoveVertsFast() and MoveVertsSlow(), the two last functions.
The program starts in fast mode, 1 toggles fast, and 2 toggles slow.
The difference is, in fast mode, it stores all vertex change info in an array, then applies it all at the end before the updateworld.
In slow mode, it applies the changes "while working".. in fact, the only command difference here is the CameraPick in each loop, then likewise updateworld's. In both examples it's doing at least 20 CameraPick's a frame - that's not slowing it down. It's just in slow mode - it does it between updating verts.
I get 60fps in fast mode, and 20fps in slow.
size=15
mode=1
SeedRnd MilliSecs()
Dim vertexinfo(20,3,4) ;remember 20 vertices, and their new positions
Graphics3D 800,600,0,2
WireFrame 1
Global FrameTime,Period,timer,fpscount,fpstemp,fps,fx,fy
Global camera=CreateCamera()
SetBuffer BackBuffer()
light=CreateLight(1)
Global map=CreateMesh()
surface=CreateSurface(map)
For x = 0 To size
For y = 0 To size
v0=AddVertex(surface,x,y,0)
v1=AddVertex(surface,x,y+1,0)
v2=AddVertex(surface,x+1,y,0)
v3=AddVertex(surface,x+1,y+1,0)
tri=AddTriangle(surface,v0,v1,v2)
tri=AddTriangle(surface,v2,v1,v3)
Next
Next
UpdateNormals map
EntityPickMode map,2
PositionEntity camera,8,10,2
RotateEntity camera,70,0,0
PositionEntity light,0,0,0
RotateEntity light,25,-45,45
PositionEntity map,0,0,0
RotateEntity map,90,0,0
brush=CreateBrush(200,200,200)
PaintEntity map,brush
;mainloop
While Not KeyHit(1)
If KeyHit(2) Then mode=1
If KeyHit(3) Then mode=2
If mode=1 Then movevertsfast()
If mode=2 Then movevertsslow()
UpdateWorld
RenderWorld
Text 0,5,"Vertices in mesh:" +((size*size)*4)
fps 0,20
Flip
Wend
WaitKey()
End
Function fps(fx,fy)
fpscount=fpscount+1
If MilliSecs()<timer+1000
Else
fps=fpscount-fpstemp
fpstemp=fpscount
timer=MilliSecs()
EndIf
Text fx,fy,"FPS "+fps
End Function
Function movevertsslow()
For i = 1 To 20
x=Rand(0,799)
y=Rand(0,599)
surface=GetSurface(map,1)
If CameraPick(camera,x,y) Then
tri=PickedTriangle()
move#=Rand(1,2)
If move#=1 Then move#=0.1 Else move#=-0.1
v0=TriangleVertex(surface,tri,0)
v1=TriangleVertex(surface,tri,1)
v2=TriangleVertex(surface,tri,2)
x0=VertexX(surface,v0)
x1=VertexX(surface,v1)
x2=VertexX(surface,v2)
y0=VertexY(surface,v0)
y1=VertexY(surface,v1)
y2=VertexY(surface,v2)
z0=VertexZ(surface,v0)
z1=VertexZ(surface,v1)
z2=VertexZ(surface,v2)
;apply changes between each camerapick
VertexCoords (surface,v0,x0,y0+move#,z0)
Else
i=i-1 ;if it doesn't find one, knock the count back and try again
End If
Next
End Function
Function movevertsfast()
For i = 1 To 20
x=Rand(0,799)
y=Rand(0,599)
surface=GetSurface(map,1)
If CameraPick(camera,x,y) Then
tri=PickedTriangle()
move#=Rand(1,2)
If move#=1 Then move#=0.1 Else move#=-0.1
vertexinfo(i,1,1)=TriangleVertex(surface,tri,0)
vertexinfo(i,2,1)=TriangleVertex(surface,tri,1)
vertexinfo(i,3,1)=TriangleVertex(surface,tri,2)
vertexinfo(i,1,2)=VertexX(surface,vertexinfo(i,1,1))
vertexinfo(i,2,2)=VertexX(surface,vertexinfo(i,2,1))
vertexinfo(i,3,2)=VertexX(surface,vertexinfo(i,3,1))
vertexinfo(i,1,3)=VertexY(surface,vertexinfo(i,1,1))
vertexinfo(i,2,3)=VertexY(surface,vertexinfo(i,2,1))
vertexinfo(i,3,3)=VertexY(surface,vertexinfo(i,3,1))
vertexinfo(i,1,4)=VertexZ(surface,vertexinfo(i,1,1))
vertexinfo(i,2,4)=VertexZ(surface,vertexinfo(i,2,1))
vertexinfo(i,3,4)=VertexZ(surface,vertexinfo(i,3,1))
Else
i=i-1 ;if it doesn't find one, knock the count back and try again
End If
Next
;apply changes at once
For i = 1 To 20
VertexCoords(surface,vertexinfo(i,1,1),vertexinfo(i,1,2),vertexinfo(i,1,3)+move#,vertexinfo(i,1,4))
VertexCoords(surface,vertexinfo(i,2,1),vertexinfo(i,2,2),vertexinfo(i,2,3)+move#,vertexinfo(i,2,4))
VertexCoords(surface,vertexinfo(i,3,1),vertexinfo(i,3,2),vertexinfo(i,3,3)+move#,vertexinfo(i,3,4))
Next
End Function
If your computer is particularly l33t and you get no speed difference, then try changing SIZE to 30, or 60.
The thing is - in this example, it's moving 3 verts for 20 tri's at random. That's ONLY updating 60verts in each frame, and you get that large a performance impact if you don't stack the updates all together in one lump. Now imagine trying to write an animation system in Blitz3D as this fellow is, where in animated models - several thousand verts are going to be updated each frame. Personally, I don't think it's possible.
I think if animating meshes in Blitz like this, it'd actually be faster to re-create the entire mesh each time rather than dynamically deform it.
+BlackD