CreateMesh.htm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>CreateMesh([parent])</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. parent (optional) - This optional parameter allows you to specify another entity which will act as the parent to this mesh.
  13. </td>
  14. </tr>
  15. </table>
  16. <h1>Description</h1>
  17. <table>
  18. <tr>
  19. <td>
  20. Create a 'blank' mesh entity and returns its handle. <br />
  21. <br />
  22. When a mesh is first created it has no surfaces, vertices or triangles associated with it. <br />
  23. <br />
  24. To add geometry to this mesh, you will need to: <br />
  25. <br />
  26. CreateSurface() ; To make a surface <br />
  27. AddVertex ; You will need to add at least 3 to make a Triangle <br />
  28. AddTriangle ; This will add a triangle by connecting the Vertices (points) you added to the mesh.
  29. </td>
  30. </tr>
  31. </table>
  32. <h1><a href=../3d_examples/CreateMesh.bb>Example</a></h1>
  33. <table>
  34. <tr>
  35. <td>
  36. ; CreateMesh Example <br />
  37. ; ------------------ <br />
  38. <br />
  39. ; In this example, we will create a custom mesh. This custom mesh will be in the shape of a ramp. <br />
  40. <br />
  41. Graphics3D 640,480 <br />
  42. SetBuffer BackBuffer() <br />
  43. <br />
  44. camera=CreateCamera() <br />
  45. <br />
  46. light=CreateLight() <br />
  47. RotateEntity light,45,0,0 <br />
  48. <br />
  49. ; Create blank mesh <br />
  50. ramp=CreateMesh() <br />
  51. <br />
  52. ; Create blank surface which is attached to mesh (surfaces must always be attached to a mesh) <br />
  53. surf=CreateSurface(ramp) <br />
  54. <br />
  55. ; Now we have our blank mesh and surface, we can start adding vertices to it, to form the shape of our <br />
  56. ; ramp. <br />
  57. ; Vertices are invisible 'points' in a 3D object that we can attach triangles too later. <br />
  58. ; To create a single triangle, you need three vertices, one for each corner. <br />
  59. ; However, you can share vertices between triangles, so you do not always need 3 new vertices per <br />
  60. ; triangle. <br />
  61. ; In the case of our ramp mesh, we will require 6 vertices, one for each corner <br />
  62. <br />
  63. v0=AddVertex(surf,0,0,0) ; bottom corner 1 <br />
  64. v1=AddVertex(surf,0,0,1) ; bottom corner 2 <br />
  65. v2=AddVertex(surf,4,0,1) ; bottom corner 3 <br />
  66. v3=AddVertex(surf,4,0,0) ; bottom corner 4 <br />
  67. v4=AddVertex(surf,0,2,0) ; top corner 1 <br />
  68. v5=AddVertex(surf,0,2,1) ; top corner 2 <br />
  69. <br />
  70. ; Having created our blank mesh and surface, and added our vertices to form the shape of the mesh, we <br />
  71. ; now need to add triangles to it in order to make it solid and visible to the user. We create <br />
  72. ; triangles simply by connecting vertices up, very much like a 3D dot-to-dot. <br />
  73. <br />
  74. ; When adding triangles, we need to remember that they are only one sided, and the side they are <br />
  75. ; visible from is determined by the order in which we specify the vertices when using AddTriangle. <br />
  76. ; If the vertices, in the order that they are specified, are aligned in a clockwise fashion relative <br />
  77. ; to the camera then they will appear visible, otherwise they won't. <br />
  78. ; So, to make our ramp visible from the outside, we will be connecting all vertices in a clockwise <br />
  79. ; fashion, relative to the camera. <br />
  80. <br />
  81. t0=AddTriangle(surf,v0,v3,v2) ; bottom triangle 1 <br />
  82. t1=AddTriangle(surf,v0,v2,v1) ; bottom triangle 2 <br />
  83. t2=AddTriangle(surf,v0,v4,v3) ; front triangle <br />
  84. t3=AddTriangle(surf,v1,v2,v5) ; back triangle <br />
  85. t4=AddTriangle(surf,v0,v1,v5) ; side triangle 1 <br />
  86. t5=AddTriangle(surf,v0,v5,v4) ; side triangle 2 <br />
  87. t6=AddTriangle(surf,v2,v4,v5) ; top triangle 1 <br />
  88. t7=AddTriangle(surf,v2,v3,v4) ; top triangle 2 <br />
  89. <br />
  90. ; Now we will position our ramp in front of the camera so we can see it! <br />
  91. PositionEntity ramp,0,-4,10 <br />
  92. <br />
  93. ; Enable wireframe mode so we can see structure of model more clearly <br />
  94. WireFrame True <br />
  95. <br />
  96. ; And a quick loop that renders the scene and displays the contents on the screen until we press esc <br />
  97. While Not KeyDown(1) <br />
  98. <br />
  99. ; Constantly turn our ramp entity to show it off a bit <br />
  100. TurnEntity ramp,0,1,0 <br />
  101. <br />
  102. RenderWorld <br />
  103. Flip <br />
  104. <br />
  105. Wend <br />
  106. <br />
  107. ; The end! <br />
  108. End
  109. </td>
  110. </tr>
  111. </table>
  112. <br>
  113. <a target=_top href=../index.htm>Index</a><br>
  114. <br>
  115. 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>
  116. </html>