Meshes.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>Planes</title>
  5. </head>
  6. <body>
  7. <center><h1><font face="Verdana">Introduction to Meshes</font></h1></center>
  8. <p><font face="Verdana">Meshes are the entities you will most frequently be
  9. working with - unless you're writing something weird (please do...)!</font>
  10. </p>
  11. <p><font face="Verdana">Meshes are made up of vertices and triangles, and can be
  12. either loaded from files (perhaps the result of a 3d modeler program), or built
  13. 'by hand'. (assembled from within a B3d program in realtime)</font>
  14. </p>
  15. <h2><font face="Verdana"><span style="background-color: #6097C9">&nbsp;Loading
  16. Meshes&nbsp;</span></font></h2>
  17. <p><font face="Verdana">There are 2 commands provided for loading meshes from
  18. files - 'LoadMesh' and 'LoadAnimMesh', both of which load a '.X' or '.3DS' file
  19. and return an entity. So what's the difference ?</font>
  20. </p>
  21. <p><font face="Verdana">Models stored in files are usually made up of several
  22. 'parts'. In the case of a character model, these parts may represent arms, legs
  23. etc.</font>
  24. </p>
  25. <p><font face="Verdana">In addition, files also contain animation information
  26. with the 'LoadAnimMesh' command. The entity returned will actually be the parent
  27. entity of the whole bunch of child 'parts'.</font>
  28. </p>
  29. <p><font face="Verdana">Therefore, 'LoadAnimMesh' really loads in several meshes
  30. !</font>
  31. </p>
  32. <p><font face="Verdana">If you don't need to animate a model, you can use 'LoadMesh'
  33. instead. This will 'collapse' all the parts in a mesh and return a single,
  34. combined mesh. The collapsed mesh will look the same as a mesh loaded with
  35. LoadAnimMesh, only you wont be able to animate it, and it wont have any child
  36. meshes.</font>
  37. </p>
  38. <p><font face="Verdana">Why bother with LoadMesh at all ? SPEED! - It's faster
  39. for B3D to deal with a single mesh than with multiple meshes, so if you're not
  40. planning to animate or doing anything tricky with a mesh, use LoadMesh.</font>
  41. </p>
  42. <h2><font face="Verdana"><span style="background-color: #6097C9">&nbsp;Creating
  43. Meshes&nbsp;</span></font></h2>
  44. <p><font face="Verdana">Before looking closely at creating meshes, you'll need
  45. to know about 'Brushes' in Blitz3D. A brush is a collection of properties used
  46. when rendering triangles. These properties are:</font>
  47. </p>
  48. <ul>
  49. <li><font face="Verdana"><b>Colour</b> - The colour a triangle is rendered in.
  50. (see BrushColor)<br>
  51. </font></li>
  52. <li><font face="Verdana"><b>Texture</b> - From 0 to 8 texture maps that are
  53. used to render a triangle. (see BrushTexture)<br>
  54. </font></li>
  55. <li><font face="Verdana"><b>Alpha</b> - How transparent a triangle is. Alpha
  56. can range from 0 (completely transparent) to 1 (completely opaque). (see
  57. BrushAlpha)<br>
  58. </font></li>
  59. <li><font face="Verdana"><b>Shininess</b> - How 'shiny' a triangle is. This
  60. value can range from 0 (not shiny) to 1 (really shiny!). (see BrushShininess)<br>
  61. </font></li>
  62. <li><font face="Verdana"><b>Blend</b> - The blend mode used to render a
  63. triangle. Blend mode describes how a triangle is combined with what's
  64. already on the screen. (see BrushBlend)<br>
  65. </font></li>
  66. <li><font face="Verdana"><b>FX</b> - Optional special effects for rendering.
  67. (see BrushFX)<br>
  68. </font></li>
  69. </ul>
  70. <p><font face="Verdana">To create a brush, you use the CreateBrush command:</font></p>
  71. <table border="1" width="100%" bordercolor="#FFFFFF">
  72. <tr>
  73. <td width="14%">&nbsp;</td>
  74. <td width="72%" bordercolor="#000000" bgcolor="#C0C0C0">&nbsp;<br>
  75. &nbsp;&nbsp;&nbsp;&nbsp;<font face="Arial">;create a brush.<br>
  76. &nbsp;&nbsp;&nbsp;&nbsp;<b>brush=CreateBrush()</b><br></font><br>
  77. </td>
  78. <td width="14%">&nbsp;</td>
  79. </tr>
  80. </table>
  81. <p><font face="Verdana">Once we have a brush, we can set its properties:</font>
  82. </p>
  83. <table border="1" width="100%" bordercolor="#FFFFFF">
  84. <tr>
  85. <td width="14%">&nbsp;</td>
  86. <td width="72%" bordercolor="#000000" bgcolor="#C0C0C0">&nbsp;<br>
  87. &nbsp;&nbsp;&nbsp;&nbsp;<font face="Arial">;a red brush.<br>
  88. &nbsp;&nbsp;&nbsp;&nbsp;<b>BrushColor brush,255,255,0</b></font>
  89. <p><font face="Arial">&nbsp;&nbsp;a shiny red brush.&nbsp;<br>
  90. </font>&nbsp;&nbsp; <font face="Arial"><b>BrushShininess brush,1</b></font><br><br>
  91. </p>
  92. </td>
  93. <td width="14%">&nbsp;</td>
  94. </tr>
  95. </table>
  96. <p><font face="Verdana">So what has all this got to do with meshes ?</font>
  97. </p>
  98. <p><font face="Verdana">Well, when I said meshes are made up of vertices and
  99. triangles, I sort of lied !. Meshes are actually made of 'surfaces', and
  100. surfaces are made up of vertices and triangles !.</font>
  101. </p>
  102. <p><font face="Verdana">When a surface is created, you provide it with a brush
  103. that controls how all the triangles in the surface are rendered.</font>
  104. </p>
  105. <p><font face="Verdana">So, a quick overview:</font>
  106. </p>
  107. <ul>
  108. <li><font face="Verdana">A mesh is made up of any number of surfaces.<br>
  109. </font></li>
  110. <li><font face="Verdana">Each surface in a mesh contains any number of
  111. vertices and triangles.<br>
  112. </font></li>
  113. <li><font face="Verdana">All triangles in a surface are rendered using a
  114. common brush.</font></li>
  115. </ul>
  116. <p><font face="Verdana">Lets dive on in and create a simple mesh:</font></p>
  117. <table border="1" width="100%" bordercolor="#FFFFFF">
  118. <tr>
  119. <td width="14%">&nbsp;</td>
  120. <td width="72%" bordercolor="#000000" bgcolor="#C0C0C0">&nbsp;<font face="Arial"><br>
  121. &nbsp;&nbsp;&nbsp;&nbsp;<b>brush=CreateBrush()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>
  122. ; create a brush<br>
  123. &nbsp;&nbsp;&nbsp; <b>BrushColor
  124. brush,255,0,0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  125. </b>; a red brush</font>
  126. <p><font face="Arial">&nbsp;&nbsp;&nbsp; <b>mesh=CreateMesh()&nbsp;&nbsp;</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  127. ; create a mesh<br>
  128. </font>&nbsp;&nbsp;&nbsp; &nbsp;<font face="Arial"><b> surf=CreateSurface(
  129. mesh,brush)&nbsp;&nbsp;&nbsp;</b> ; create a (red) surface</font></p>
  130. <p><font face="Arial">&nbsp;&nbsp;&nbsp; <b>AddVertex surf,-1,1,0</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  131. ; Now, we add 4 vertices...<br>
  132. &nbsp;&nbsp;&nbsp; <b>AddVertex surf,1,1,0&nbsp;<br>
  133. &nbsp;&nbsp;&nbsp; AddVertex surf,1-,1,0&nbsp;<br>
  134. &nbsp;&nbsp;&nbsp; AddVertex surf,-1,-1,0</b></font></p>
  135. <p><font face="Arial"><b>&nbsp;&nbsp;&nbsp; AddTriangle
  136. surf,0,1,2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  137. </b>; and 2 triangles...<b><br>
  138. &nbsp;&nbsp;&nbsp; AddTriangle surf,0,2,3</b></font></p>
  139. <p><font face="Arial"><b>&nbsp;&nbsp;&nbsp; UpdateNormals mesh</b>&nbsp;</font><br><br>
  140. </p>
  141. </td>
  142. <td width="14%">&nbsp;</td>
  143. </tr>
  144. </table>
  145. <p><font face="Verdana">This code will create a simple red square mesh entity.</font>
  146. </p>
  147. <p><font face="Verdana">So what's with the weird 'UpdateNormals' command at the
  148. end ?. Well, in order for a mesh to be correctly lit, its 'vertex normals' must
  149. be calculated. Without going into the gory details, the UpdateNormals command
  150. will do this for you. If you are aware of how normals work, you can actually set
  151. your own vertex normals using the VertexNormal command. If not, just remember to
  152. stick an 'UpdateNormals' command at the end of any mesh modifications you do, or
  153. else your meshes will not be correctly lit.</font>
  154. </p>
  155. <p><font face="Verdana">Note that you can create any number of surfaces you
  156. want. So, the same mesh can contain many differently coloured/textured/whatever
  157. triangles !.</font>
  158. </p>
  159. <p><font face="Verdana">Why bother with surfaces at all ?, Why not just create a
  160. bunch of separate meshes, each with its own rendering properties and skip all
  161. this surface nonsense ?. Well, again it comes down to SPEED !. It's faster for
  162. Blitz3D to handle multiple surfaces - which can NOT be moved or rotated as
  163. entities can - than it would be to handle multiple meshes.</font>
  164. </p>
  165. <h2><font face="Verdana"><span style="background-color: #6097C9">&nbsp;Modifying
  166. Meshes&nbsp;</span></font></h2>
  167. <p>
  168. <font face="Verdana">
  169. Once you've created a mesh, there are various commands available for modifying
  170. the mesh in realtime. This can be used to create a range of impressive special
  171. effects such as waving flags, rippling water and so on.</font></p>
  172. <p><font face="Verdana">These commands are:</font></p>
  173. <ul>
  174. <li><font face="Verdana"><b>VertexCoords</b> - Changes the coordinates of a
  175. vertex.<br>
  176. </font></li>
  177. <li><font face="Verdana"><b>VertexColor</b> - Changes the colour of a vertex.<br>
  178. </font></li>
  179. <li><font face="Verdana"><b>VertexTexCoords</b> - Changes the texture mapping
  180. coordinates of a vertex.<br>
  181. </font></li>
  182. <li><font face="Verdana"><b>VertexNormal</b> - Changes the normal of a vertex.</font></li>
  183. </ul>
  184. <p><font face="Verdana">For more info on how to use these commands, take a look
  185. at the Vertex tutorial further on down the line.</font></p>
  186. <p><center><font color="#666666" face="Verdana">By Paul Gerfen (GamecodingUK)<br>Copyright 2001 Mark Sibly/Guildhall Leisure Ltd</font>
  187. </center></p>
  188. </body>
  189. </html>