; FindSurface Example ; ------------------- ; FindSurface retrieves the surface of a mesh that was created with a ; given brush - handy for picking one material group out of a mesh. ; It returns the surface handle, or 0 if no surface matches. Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,0,-5 ; Two brushes: grey stone and glowing lava stone=CreateBrush() BrushColor stone,130,130,140 lava=CreateBrush() BrushColor lava,255,120,0 ; One mesh with two surfaces, one per brush mesh=CreateMesh() ; Left quad: created with the stone brush s1=CreateSurface(mesh,stone) v0=AddVertex(s1,-2.1,1,0) v1=AddVertex(s1,-0.1,1,0) v2=AddVertex(s1,-0.1,-1,0) v3=AddVertex(s1,-2.1,-1,0) AddTriangle s1,v0,v1,v2 AddTriangle s1,v0,v2,v3 ; Right quad: created with the lava brush s2=CreateSurface(mesh,lava) v0=AddVertex(s2,0.1,1,0) v1=AddVertex(s2,2.1,1,0) v2=AddVertex(s2,2.1,-1,0) v3=AddVertex(s2,0.1,-1,0) AddTriangle s2,v0,v1,v2 AddTriangle s2,v0,v2,v3 ; Fullbright so the brush colours show without lighting setup EntityFX mesh,1 ; The documented command: fetch whichever surface used the lava brush found=FindSurface(mesh,lava) While Not KeyDown(1) ; Bob the FOUND surface's vertices up and down to prove we ; grabbed the right one - the stone quad is untouched wob#=Sin(MilliSecs()*0.3)*0.2 VertexCoords found,0,0.1,1+wob,0 VertexCoords found,1,2.1,1+wob,0 VertexCoords found,2,2.1,-1+wob,0 VertexCoords found,3,0.1,-1+wob,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,"Arrow keys: move camera Esc: exit" Text 0,20,"FindSurface(mesh,lava) = "+found+" (0 would mean not found)" Text 0,40,"Only the found (orange) surface is animated" Flip Wend End