GetSurface ( mesh,surface_index )
Parameters
|
mesh - mesh handle surface_index - index of the surface, in the range 1 to CountSurfaces( mesh ) inclusive |
Description
|
Returns the handle of a mesh's surface by index number. Most surface-level commands - PaintSurface, AddVertex, VertexCoords and friends - want a surface handle, and GetSurface is how you get one from a loaded model. Loop from 1 to CountSurfaces(mesh) to visit them all. Watch the numbering: surfaces count from 1, while the vertices and triangles inside a surface count from 0. GetSurface(mesh,0) is an error. See also: CountSurfaces, FindSurface, CreateSurface, PaintSurface. |
Example
; GetSurface Example ; ------------------ ; GetSurface fetches a surface handle from a mesh by index (from 1 to ; CountSurfaces inclusive). You need the handle to use any of the ; surface commands. Here we walk a loaded model's surfaces and print ; live statistics for each one. Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,0,-4 light=CreateLight() RotateEntity light,30,40,0 ; Load a real model to inspect drum=LoadMesh("media/oil-drum/oildrum.3ds") ; Shrink the drum into a 2-unit box so it fits our view FitMesh drum,-1,-1,-1,2,2,2,1 While Not KeyDown(1) TurnEntity drum,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,"Arrow keys: move camera Esc: exit" ; Fetch each surface in turn - the documented command For i=1 To CountSurfaces(drum) surf=GetSurface(drum,i) Text 0,20+i*20,"GetSurface(drum,"+i+"): "+CountTriangles(surf)+" triangles, "+CountVertices(surf)+" vertices" Next Flip Wend End
Index