;3d terrain editor in progress ;duckstab ;left mouse select triangle ;hold q vert up ;hold a vert down ;arrow keys rotate map ;page up and down zoom ;create a texture with a black background and a white circle outline for target (30 by 30) ;create a texture with a green background with a 1 pixle border for vertile (30 by 30) Graphics3D 1024,768,32,1 ClearWorld(1,1,1) Global cam1=CreateCamera() Global lgt1=CreateLight() Global mesh Global picked#,tri,surface Global v1x#,v1y#,v1z#,v1 Global v2x#,v2y#,v2z#,v2 Global v3x#,v3y#,v3z#,v3,uvmap1#,uvmap2# Dim Vert#(21,21) PositionEntity cam1,0,2,-40 tex=LoadTexture("vertile.png") target=LoadImage("target.png") mesh_create EntityTexture mesh,tex ScaleTexture tex,.05,.05 ;EntityColor mesh,255,126,46 RotateEntity mesh,90,0,0 While Not KeyHit(1) If KeyDown(200) Then TurnEntity mesh,.1,0,0 If KeyDown(203) Then TurnEntity mesh,0,-.1,0 If KeyDown(208) Then TurnEntity mesh,-.1,0,0 If KeyDown(205) Then TurnEntity mesh,0,.1,0 If KeyDown(201) Then MoveEntity cam1,0,0,.1 If KeyDown(209) Then MoveEntity cam1,0,0,-.1 If KeyDown(16) And picked>0 Then movevert1 If KeyDown(30) And picked>0 Then movevert2 If MouseDown(1) Then getpicked UpdateWorld RenderWorld Text 100,100,"picked="+picked Text 100,115,"Tri="+tri Text 100,130,"vert1 x="+v1x+" y="+v1y+" z="+v1z Text 100,145,"uv1="+uvmap1 Text 100,160,"uv2="+uvmap2 DrawImage target,MouseX(),MouseY() Flip 0 Wend End Function Mesh_create() mesh=CreateMesh() surf=CreateSurface(mesh) For x=1 To 21 For z=1 To 21 vert(x,z)=AddVertex(surf,x-9,0,z-9,(x*.05)-.05,((z*.05)-.05)) Next Next For x=1 To 20 For z=1 To 20 AddTriangle surf,vert(x,z),vert(x+1,z),vert(x,z+1) AddTriangle surf,vert(x,z+1),vert(x+1,z),vert(x+1,z+1) Next Next UpdateNormals Mesh EntityPickMode mesh,2 End Function Function Getpicked() picked=CameraPick(cam1,MouseX()+15,MouseY()+15) If picked>0 Then getvert End Function Function Getvert() tri=PickedTriangle() surface=GetSurface(mesh,1) v1=TriangleVertex(surface,tri,0) v2=TriangleVertex(surface,tri,1) v3=TriangleVertex(surface,tri,2) v1x=VertexX(surface,v1) v1y=VertexY(surface,v1) V1z=VertexZ(surface,v1) v2x=VertexX(surface,v2) v2y=VertexY(surface,v2) V2z=VertexZ(surface,v2) v3x=VertexX(surface,v3) v3y=VertexY(surface,v3) V3z=VertexZ(surface,v3) uvmap1=VertexV# ( surface,v1,0 ) uvmap2=VertexU# ( surface,v1,1) End Function Function movevert1() v1y=v1y+.003 v2y=v2y+.003 v3y=v3y+.003 VertexCoords (surface,v1,v1x,v1y,v1z) VertexCoords (surface,v2,v2x,v2y,v2z) VertexCoords (surface,v3,v3x,v3y,v3z) UpdateNormals mesh End Function Function movevert2() v1y=v1y-.003 v2y=v2y-.003 v3y=v3y-.003 VertexCoords (surface,v1,v1x,v1y,v1z) VertexCoords (surface,v2,v2x,v2y,v2z) VertexCoords (surface,v3,v3x,v3y,v3z) UpdateNormals mesh End Function
updated code slimline added testing for vertical move of tris