Yeah, seeing as the texture will always be the same for these 'cubes', minimising the surface count with AddMesh should be better.
Yeah, Optimising the cubes with regaards to non-visible faces is also an important consideration. Especially the top and bottom of the 'cubes' these I think will never be seen.
puki, the idea of pairing the verts is something I wouldn't know where to start, especially considering the random nature of the deformations. Not affecting the tris along the edge did cross my mind, but then the meshes would lose a lot of their 'caverny' feeling.
Here's my code so far, with step-by-step movement and torchlighting (the code needs two texture files in the root folder t.bmp and floor.bmp)
Graphics3D 800,600
SetBuffer BackBuffer()
;*****************************INITIALISE******************************
AmbientLight 150,150,150
cam=CreateCamera()
CameraViewport cam,0,0,800,600
CameraRange cam,0.01,100
CameraFogMode cam,1
CameraFogColor cam,1,1,1
CameraFogRange cam,-20,20
camlight=CreateLight(2)
EntityParent camlight,cam,1
LightRange camlight,1
;****************************BUILD ARRAYS *****************************
Dim vpos#(1,1)
Dim Map(200)
;***************************CREATE QUICK RANDOM MAP**********************
Fl=CreatePlane()
MoveEntity fl,0,-1,0
ft=LoadTexture("floor.bmp",1)
EntityTexture Fl,ft
For f= 1 To 200
Map(f)=CreateWall()
If f>1
AddMesh Map(f),Map(f-1)
EndIf
tt=LoadTexture("t.bmp",9)
EntityTexture Map(f),tt
Morph(Map(f))
PositionEntity Map(f),Rand(-15,15),0,Rand(-15,15)
Next
;*************************** MAIN LOOP ****************************
timer=MilliSecs()
While Not KeyDown(1)
If KeyDown(200) Then walkforward(cam)
If KeyDown(208) Then walkbackward(cam)
If KeyDown(203) Then turnleft(cam)
If KeyDown(205) Then turnright(cam)
;*************************TORCHLIGHT*******************************
LightColor camlight,Rand(150,200),Rand(170,220),100
;*************************COUNT FRAMES*****************************
fpscount=fpscount+1
If (MilliSecs()-timer)>=1000
timer=MilliSecs()
fps=fpscount
fpscount=0
EndIf
render()
Wend
End
;*******************************************FUNCTIONS************************
Function walkforward(entity)
For f= 1 To 10
MoveEntity entity,0,0,0.1
render()
Next
End Function
Function walkbackward(entity)
For f=1 To 10
MoveEntity entity,0,0,-.1
render()
Next
End Function
Function turnleft(entity)
For f=1 To 20
TurnEntity entity,0,4.5,0
render()
Next
End Function
Function turnright(entity)
For f=1 To 20
TurnEntity entity,0,-4.5,0
render()
Next
End Function
Function CreateWall()
;*****************************CREATE SEGMENTED CUBE FROM 6 SIDES **************
mesh=CreateMesh()
segs=3
For scnt=0 To 3
surf=CreateSurface( mesh )
stx#=-.5
sty#=stx
stp#=Float(1)/Float(segs)
y#=sty
For a=0 To segs
x#=stx
v#=a/Float(segs)
For b=0 To segs
u#=b/Float(segs)
AddVertex(surf,x,y,0.5,u,v)
x=x+stp
Next
y=y+stp
Next
For a=0 To segs-1
For b=0 To segs-1
v0=a*(segs+1)+b:v1=v0+1
v2=(a+1)*(segs+1)+b+1:v3=v2-1
AddTriangle( surf,v0,v1,v2 )
AddTriangle( surf,v0,v2,v3 )
Next
Next
RotateMesh mesh,0,90,0
Next
;top and bottom
RotateMesh mesh,90,0,0
For scnt=0 To 1
surf=CreateSurface( mesh )
stx#=-.5
sty#=stx
stp#=Float(1)/Float(segs)
y#=sty
For a=0 To segs
x#=stx
v#=a/Float(segs)
For b=0 To segs
u#=b/Float(segs)
AddVertex(surf,x,y,0.5,u,v)
x=x+stp
Next
y=y+stp
Next
For a=0 To segs-1
For b=0 To segs-1
v0=a*(segs+1)+b:v1=v0+1
v2=(a+1)*(segs+1)+b+1:v3=v2-1
AddTriangle( surf,v0,v1,v2 )
AddTriangle( surf,v0,v2,v3 )
Next
Next
RotateMesh mesh,180,0,0
Next
UpdateNormals mesh
Return mesh
End Function
;**************************MORPH VERTS*****************************
Function Morph(mesh)
surftotal=CountSurfaces(mesh)
For xx= 1 To surftotal
as1=GetSurface(mesh,xx)
; record the locations of the verts
Dim vpos#(CountVertices(as1)-1,3)
For n=0 To CountVertices(as1)-1
vpos(n,0)=VertexX(as1,n)
vpos(n,1)=VertexY(as1,n)
vpos(n,2)=VertexZ(as1,n)
vpos(n,3)=0
Next
For n=0 To CountVertices(as1)-1
; change these to make it more or less messy
xm#=Rnd(-.2,.2)
ym#=Rnd(-.0,.0)
zm#=Rnd(-.2,.2)
For nn=0 To CountVertices(as1)-1
; if the vert has not been monkeyed with monkey away
If vpos(nn,3)=0
If vpos(n,0)=vpos(nn,0) And vpos(n,1)=vpos(nn,1) And vpos(n,2)=vpos(nn,2)
VertexCoords as1,nn,vpos(nn,0)+xm,vpos(nn,1)+ym,vpos(nn,2)+zm
vpos(nn,3)=1
EndIf
EndIf
Next
Next
Next
Return mesh
End Function
Function render()
UpdateWorld
RenderWorld
Text 0,100,"POLYS: "+TrisRendered(),0,1
Text 0,200,"FPS: "+fps,0,1
Flip
End Function
----------------Now I seem to have a problem that the 'timer' variable doesn't = millisecs at the start(?) it maintains a 'null' value, so my framecounter doesn't work here.