; CreateMesh Example ; ------------------ ; CreateMesh creates an empty mesh with no geometry at all. ; We then add a surface, add vertices, and connect them with ; triangles to build a ramp entirely by hand. Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,1,-6 light=CreateLight() RotateEntity light,45,30,0 ; Create the blank mesh - the documented command ramp=CreateMesh() ; Surfaces hold the actual triangles (a surface must belong to a mesh) surf=CreateSurface(ramp) ; Six vertices, one per corner of a wedge shape v0=AddVertex(surf,-2,0,-1) ; bottom front left v1=AddVertex(surf,-2,0,1) ; bottom back left v2=AddVertex(surf,2,0,1) ; bottom back right v3=AddVertex(surf,2,0,-1) ; bottom front right v4=AddVertex(surf,-2,2,-1) ; top front left v5=AddVertex(surf,-2,2,1) ; top back left ; Triangles are one-sided: list each triangle's vertices in clockwise ; order as seen from OUTSIDE the ramp, or that face will be invisible AddTriangle surf,v0,v3,v2 ; bottom half 1 AddTriangle surf,v0,v2,v1 ; bottom half 2 AddTriangle surf,v0,v4,v3 ; front face AddTriangle surf,v1,v2,v5 ; back face AddTriangle surf,v0,v1,v5 ; left side half 1 AddTriangle surf,v0,v5,v4 ; left side half 2 AddTriangle surf,v2,v4,v5 ; slope half 1 AddTriangle surf,v2,v3,v4 ; slope half 2 ; Point the normals outwards so the light shades the ramp correctly UpdateNormals ramp EntityColor ramp,90,180,255 wire=0 While Not KeyDown(1) ; Space toggles wireframe so you can see the triangle structure If KeyHit(57) Then wire=1-wire : WireFrame wire ; Keep the ramp slowly turning TurnEntity ramp,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: toggle wireframe Arrow keys: move camera Esc: exit" Text 0,20,"CreateMesh ramp: 6 vertices, 8 triangles built by hand" Flip Wend End