| mesh - mesh handle |
|
Returns the number of surfaces in a mesh. Surfaces are the sections a mesh is made of - each one is a batch of triangles sharing one appearance. A mesh you built yourself has however many surfaces you created; a loaded model typically has one surface per material. The usual job for this command is driving a loop: For i=1 To CountSurfaces(mesh) with GetSurface(mesh,i) inside visits every surface, ready for repainting or vertex work. Note that surface indices run from 1, not 0. See also: GetSurface, FindSurface, CountVertices, CountTriangles, CreateSurface. |
; CountSurfaces Example
; ---------------------
; CountSurfaces returns how many surfaces a mesh contains. A surface
; is one group of triangles sharing a single material, so loaded
; models often have several - one per material.
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
; The documented command
surfs=CountSurfaces(drum)
; Use GetSurface to total up the triangles inside those surfaces
tris=0
For i=1 To surfs
tris=tris+CountTriangles(GetSurface(drum,i))
Next
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"
Text 0,20,"CountSurfaces(drum) = "+surfs
Text 0,40,"Those surfaces hold "+tris+" triangles in total"
Flip
Wend
End