Blitz3D+ Command Reference

CountTriangles ( surface )

Parameters

surface - surface handle

Description

Returns the number of triangles in a surface.

Triangle index numbers run from 0 to CountTriangles(surface)-1, so this sets the loop bounds when you walk a surface's triangles with TriangleVertex - for mesh analysis, custom tools or exporters.

It is also handy for keeping an eye on your polygon budget when generating geometry at runtime.

See also: CountVertices, CountSurfaces, TriangleVertex, AddTriangle.

Example

; CountTriangles Example
; ----------------------

; CountTriangles returns how many triangles one surface holds.
; Summing it over every surface of a loaded model gives the model's
; full triangle count - a handy performance statistic.

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

; Total the triangles surface by surface - the documented command
tris=0
For i=1 To CountSurfaces(drum)
    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,"CountTriangles totalled over "+CountSurfaces(drum)+" surfaces = "+tris

    Flip

Wend

End

Index