FlipMesh mesh
Parameters
| mesh - mesh handle |
Description
|
Reverses the winding of every triangle in a mesh, turning it inside-out. Triangles are one-sided: which side you can see depends on the order of their corner points. FlipMesh swaps that order for the whole mesh, and also flips the vertex normals so lighting matches the newly visible side. The classic use is a sky sphere: create a sphere, FlipMesh it, and you can now see it from the inside while the outside becomes invisible. It is also the fix when a modelling package exports a mesh whose triangles appear to be missing - they are usually just wound the wrong way. To make a mesh two-sided, copy it with CopyEntity (parenting the copy to the original) and FlipMesh the copy: two meshes occupy the same space facing opposite ways. That doubles the polygon count, though - EntityFX flag 16 (disable backface culling) gets the same look without extra triangles. See also: AddTriangle, CopyMesh, CopyEntity, EntityFX, UpdateNormals. |
Example
; FlipMesh Example ; ---------------- ; Triangles are one-sided. FlipMesh reverses every triangle in a mesh ; so it faces the other way - the classic trick for sky domes: flip a ; giant sphere and view it from the inside. Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() ; A huge sphere surrounding the camera, painted with a sky texture sky=CreateSphere() ScaleEntity sky,100,100,100 sky_tex=LoadTexture("media/sky.bmp") EntityTexture sky,sky_tex EntityFX sky,1 ; The documented command: turn the sphere inside-out so its faces ; point INWARDS, towards our camera FlipMesh sky flipped=1 While Not KeyDown(1) ; Space flips the mesh again - unflipped, the faces point away ; from us and the whole sky disappears If KeyHit(57) Then FlipMesh sky : flipped=1-flipped ; Arrow keys look around If KeyDown(200) Then TurnEntity camera,-1,0,0 If KeyDown(208) Then TurnEntity camera,1,0,0 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Space: FlipMesh again Arrow keys: look around Esc: exit" If flipped Then Text 0,20,"Flipped: faces point inwards - a perfect sky dome" Else Text 0,20,"Not flipped: faces point outwards - invisible from inside!" EndIf Flip Wend End
Index