| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <html>
- <head>
- <title>Blitz3D Docs</title>
- <link rel=stylesheet href=../css/commands.css type=text/css>
- </head>
- <body>
- <h1>CreateMesh([parent])</h1>
- <h1>Parameters</h1>
- <table>
- <tr>
- <td>
- parent (optional) - This optional parameter allows you to specify another entity which will act as the parent to this mesh.
- </td>
- </tr>
- </table>
- <h1>Description</h1>
- <table>
- <tr>
- <td>
- Create a 'blank' mesh entity and returns its handle.
<br />
-
<br />
- When a mesh is first created it has no surfaces, vertices or triangles associated with it.
<br />
-
<br />
- To add geometry to this mesh, you will need to:
<br />
-
<br />
- CreateSurface() ; To make a surface
<br />
- AddVertex ; You will need to add at least 3 to make a Triangle
<br />
- AddTriangle ; This will add a triangle by connecting the Vertices (points) you added to the mesh.
- </td>
- </tr>
- </table>
- <h1><a href=../3d_examples/CreateMesh.bb>Example</a></h1>
- <table>
- <tr>
- <td>
- ; CreateMesh Example
<br />
- ; ------------------
<br />
-
<br />
- ; In this example, we will create a custom mesh. This custom mesh will be in the shape of a ramp.
<br />
-
<br />
- Graphics3D 640,480
<br />
- SetBuffer BackBuffer()
<br />
-
<br />
- camera=CreateCamera()
<br />
-
<br />
- light=CreateLight()
<br />
- RotateEntity light,45,0,0
<br />
-
<br />
- ; Create blank mesh
<br />
- ramp=CreateMesh()
<br />
-
<br />
- ; Create blank surface which is attached to mesh (surfaces must always be attached to a mesh)
<br />
- surf=CreateSurface(ramp)
<br />
-
<br />
- ; Now we have our blank mesh and surface, we can start adding vertices to it, to form the shape of our
<br />
- ; ramp.
<br />
- ; Vertices are invisible 'points' in a 3D object that we can attach triangles too later.
<br />
- ; To create a single triangle, you need three vertices, one for each corner.
<br />
- ; However, you can share vertices between triangles, so you do not always need 3 new vertices per
<br />
- ; triangle.
<br />
- ; In the case of our ramp mesh, we will require 6 vertices, one for each corner
<br />
-
<br />
- v0=AddVertex(surf,0,0,0) ; bottom corner 1
<br />
- v1=AddVertex(surf,0,0,1) ; bottom corner 2
<br />
- v2=AddVertex(surf,4,0,1) ; bottom corner 3
<br />
- v3=AddVertex(surf,4,0,0) ; bottom corner 4
<br />
- v4=AddVertex(surf,0,2,0) ; top corner 1
<br />
- v5=AddVertex(surf,0,2,1) ; top corner 2
<br />
-
<br />
- ; Having created our blank mesh and surface, and added our vertices to form the shape of the mesh, we
<br />
- ; now need to add triangles to it in order to make it solid and visible to the user. We create
<br />
- ; triangles simply by connecting vertices up, very much like a 3D dot-to-dot.
<br />
-
<br />
- ; When adding triangles, we need to remember that they are only one sided, and the side they are
<br />
- ; visible from is determined by the order in which we specify the vertices when using AddTriangle.
<br />
- ; If the vertices, in the order that they are specified, are aligned in a clockwise fashion relative
<br />
- ; to the camera then they will appear visible, otherwise they won't.
<br />
- ; So, to make our ramp visible from the outside, we will be connecting all vertices in a clockwise
<br />
- ; fashion, relative to the camera.
<br />
-
<br />
- t0=AddTriangle(surf,v0,v3,v2) ; bottom triangle 1
<br />
- t1=AddTriangle(surf,v0,v2,v1) ; bottom triangle 2
<br />
- t2=AddTriangle(surf,v0,v4,v3) ; front triangle
<br />
- t3=AddTriangle(surf,v1,v2,v5) ; back triangle
<br />
- t4=AddTriangle(surf,v0,v1,v5) ; side triangle 1
<br />
- t5=AddTriangle(surf,v0,v5,v4) ; side triangle 2
<br />
- t6=AddTriangle(surf,v2,v4,v5) ; top triangle 1
<br />
- t7=AddTriangle(surf,v2,v3,v4) ; top triangle 2
<br />
-
<br />
- ; Now we will position our ramp in front of the camera so we can see it!
<br />
- PositionEntity ramp,0,-4,10
<br />
-
<br />
- ; Enable wireframe mode so we can see structure of model more clearly
<br />
- WireFrame True
<br />
-
<br />
- ; And a quick loop that renders the scene and displays the contents on the screen until we press esc
<br />
- While Not KeyDown(1)
<br />
-
<br />
- ; Constantly turn our ramp entity to show it off a bit
<br />
- TurnEntity ramp,0,1,0
<br />
-
<br />
- RenderWorld
<br />
- Flip
<br />
-
<br />
- Wend
<br />
-
<br />
- ; The end!
<br />
- End
- </td>
- </tr>
- </table>
- <br>
- <a target=_top href=../index.htm>Index</a><br>
- <br>
- Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=CreateMesh&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
- </html>
|