PageRenderTime 80ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/CS/migrated/branches/R0_98/docs/html/manual/cs_116.html

#
HTML | 216 lines | 175 code | 26 blank | 15 comment | 0 complexity | 0eec7f37171e110930c58dfbfaca5845 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <!-- Created by texi2html 1.64 -->
  3. <!--
  4. Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
  5. Karl Berry <karl@freefriends.org>
  6. Olaf Bachmann <obachman@mathematik.uni-kl.de>
  7. and many others.
  8. Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
  9. Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
  10. -->
  11. <HTML>
  12. <HEAD>
  13. <TITLE>Crystal Space: HOWTO Create Genmesh</TITLE>
  14. <META NAME="description" CONTENT="Crystal Space: HOWTO Create Genmesh">
  15. <META NAME="keywords" CONTENT="Crystal Space: HOWTO Create Genmesh">
  16. <META NAME="resource-type" CONTENT="document">
  17. <META NAME="distribution" CONTENT="global">
  18. <META NAME="Generator" CONTENT="texi2html 1.64">
  19. </HEAD>
  20. <BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
  21. <A NAME="SEC259"></A>
  22. <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
  23. <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_115.html#SEC254"> &lt; </A>]</TD>
  24. <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_117.html#SEC264"> &gt; </A>]</TD>
  25. <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_102.html#SEC210"> &lt;&lt; </A>]</TD>
  26. <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_110.html#SEC226"> Up </A>]</TD>
  27. <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_135.html#SEC355"> &gt;&gt; </A>]</TD>
  28. <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
  29. <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
  30. <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC942">Index</A>]</TD>
  31. <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
  32. </TR></TABLE>
  33. <HR SIZE=1>
  34. <H3> 5.8.6 Creating a Genmesh Mesh </H3>
  35. <!--docid::SEC259::-->
  36. <P>
  37. This section describes how to create a Genmesh mesh.
  38. </P><P>
  39. <A NAME="SEC260"></A>
  40. <H4> What is Genmesh? </H4>
  41. <!--docid::SEC260::-->
  42. <P>
  43. A `<SAMP>Genmesh</SAMP>' mesh object (see section <A HREF="cs_214.html#SEC581">7.7.7 Genmesh Mesh Object</A>) is a generic
  44. triangle mesh object that (currently) supports one material for the entire
  45. mesh. In contrast with 3D sprites (see section <A HREF="cs_212.html#SEC571">7.7.5 Sprite3D Mesh Object</A>), genmeshes do not
  46. support animation (except that you can modify the vertices manually at
  47. runtime).
  48. </P><P>
  49. Genmeshes are very useful for static or semi-static geometry (chests,
  50. doors, candles, swords, etc.) which do not need internal animation but which
  51. can sometimes require a lot of detail.
  52. </P><P>
  53. Genmeshes use vertex lighting (or stencil if you use a stencil lighting
  54. shader).
  55. </P><P>
  56. Genmesh objects always have to be created through a factory. So, first
  57. you create the actual geometry in a genmesh factory and then you create one
  58. or more instances from that factory. This is a great way to save memory.
  59. This does mean that it is not possible to HardTransform genmeshes. It is
  60. only possible to HardTransform Genmesh factories.
  61. </P><P>
  62. <A NAME="SEC261"></A>
  63. <H4> Creating a Genmesh in a Map </H4>
  64. <!--docid::SEC261::-->
  65. <P>
  66. Here is an example of how to create a cube genmesh in a map file:
  67. </P><P>
  68. <TABLE><tr><td>&nbsp;</td><td class=example><pre>&#60;meshfact name="cubeFact"&#62;
  69. &#60;plugin&#62;crystalspace.mesh.loader.factory.genmesh&#60;/plugin&#62;
  70. &#60;params&#62;
  71. &#60;numvt&#62;8&#60;/numvt&#62;
  72. &#60;numtri&#62;12&#60;/numtri&#62;
  73. &#60;v x="-0.1" y="0.1" z="0.1" u="0" v="0" /&#62;
  74. &#60;v x="-0.1" y="0.1" z="-0.1" u="1" v="0" /&#62;
  75. &#60;v x="0.1" y="0.1" z="-0.1" u="0" v="1" /&#62;
  76. &#60;v x="0.1" y="0.1" z="0.1" u="1" v="1" /&#62;
  77. &#60;v x="-0.1" y="-0.1" z="0.1" u="1" v="0" /&#62;
  78. &#60;v x="-0.1" y="-0.1" z="-0.1" u="0" v="1" /&#62;
  79. &#60;v x="0.1" y="-0.1" z="-0.1" u="1" v="1" /&#62;
  80. &#60;v x="0.1" y="-0.1" z="0.1" u="0" v="0" /&#62;
  81. &#60;t v1="0" v2="3" v3="1" /&#62;
  82. &#60;t v1="3" v2="2" v3="1" /&#62;
  83. &#60;t v1="4" v2="5" v3="7" /&#62;
  84. &#60;t v1="5" v2="6" v3="7" /&#62;
  85. &#60;t v1="0" v2="4" v3="3" /&#62;
  86. &#60;t v1="4" v2="7" v3="3" /&#62;
  87. &#60;t v1="1" v2="6" v3="5" /&#62;
  88. &#60;t v1="1" v2="2" v3="6" /&#62;
  89. &#60;t v1="0" v2="1" v3="5" /&#62;
  90. &#60;t v1="0" v2="5" v3="4" /&#62;
  91. &#60;t v1="2" v2="3" v3="7" /&#62;
  92. &#60;t v1="2" v2="7" v3="6" /&#62;
  93. &#60;autonormals /&#62;
  94. &#60;/params&#62;
  95. &#60;/meshfact&#62;
  96. &#60;sector name="bla"&#62;
  97. &#60;meshobj name="cube"&#62;
  98. &#60;plugin&#62;crystalspace.mesh.loader.genmesh&#60;/plugin&#62;
  99. &#60;params&#62;
  100. &#60;factory&#62;cubeFact&#60;/factory&#62;
  101. &#60;material&#62;mosaic&#60;/material&#62;
  102. &#60;/params&#62;
  103. &#60;move&#62;
  104. &#60;v x="1" y="0" z="3" /&#62;
  105. &#60;/move&#62;
  106. &#60;/meshobj&#62;
  107. &#60;/sector&#62;
  108. </pre></td></tr></table></P><P>
  109. In this example we define a box by specifying the eight corner vertices
  110. and the twelve triangles. The <CODE>&#60;autonormals&#62;</CODE> tag specifies that normals
  111. will be created automatically (to give the box a smooth appearance). The
  112. normals are used for lighthing. It is also possible to specify normals
  113. manually. Note that with every vertex we also specify a texture coordinate
  114. (uv coordinate).
  115. </P><P>
  116. To create a genmesh box you can actually use a short-hand notation:
  117. </P><P>
  118. <TABLE><tr><td>&nbsp;</td><td class=example><pre>&#60;meshfact name="cubeFact"&#62;
  119. &#60;plugin&#62;crystalspace.mesh.loader.factory.genmesh&#60;/plugin&#62;
  120. &#60;params&#62;
  121. &#60;box&#62;
  122. &#60;min x="-0.1" y="-0.1" z="-0.1" /&#62;
  123. &#60;max x="0.1" y="0.1" z="0.1" /&#62;
  124. &#60;/box&#62;
  125. &#60;autonormals /&#62;
  126. &#60;/params&#62;
  127. &#60;/meshfact&#62;
  128. </pre></td></tr></table></P><P>
  129. This is a quick way to make boxes in a map file.
  130. </P><P>
  131. <A NAME="SEC262"></A>
  132. <H4> Creating a Genmesh Programmatically </H4>
  133. <!--docid::SEC262::-->
  134. <P>
  135. Here we create the same genmesh programmatically:
  136. </P><P>
  137. <TABLE><tr><td>&nbsp;</td><td class=example><pre> // First create the factory:
  138. csRef&#60;iMeshFactoryWrapper&#62; fact = engine-&#62;CreateMeshFactory (
  139. "crystalspace.mesh.object.genmesh", "cubeFact");
  140. csRef&#60;iGeneralFactoryState&#62; factstate = SCF_QUERY_INTERFACE (
  141. fact-&#62;GetMeshObjectFactory (), iGeneralFactoryState);
  142. factstate-&#62;SetVertexCount (8);
  143. factstate-&#62;GetVertices ()[0].Set (-0.1, 0.1, 0.1);
  144. factstate-&#62;GetTexels ()[0].Set (0, 0);
  145. factstate-&#62;GetVertices ()[1].Set (-0.1, 0.1, -0.1);
  146. factstate-&#62;GetTexels ()[1].Set (1, 0);
  147. <small>...</small>
  148. factstate-&#62;SetTriangleCount (12);
  149. factstate-&#62;GetTriangles ()[0].Set (0, 3, 1);
  150. factstate-&#62;GetTriangles ()[1].Set (3, 2, 1);
  151. <small>...</small>
  152. factstate-&#62;CalculateNormals ();
  153. // Now create an instance:
  154. csRef&#60;iMeshWrapper&#62; mesh =
  155. engine-&#62;CreateMeshWrapper (fact, "cube");
  156. csRef&#60;iGeneralMeshState&#62; meshstate = SCF_QUERY_INTERFACE (
  157. mesh-&#62;GetMeshObject (), iGeneralMeshState);
  158. meshstate-&#62;SetMaterialWrapper (myMaterial);
  159. <small>...</small>
  160. </pre></td></tr></table></P><P>
  161. This will basically create the same cube as in the map file example.
  162. </P><P>
  163. <A NAME="SEC263"></A>
  164. <H4> Include Files </H4>
  165. <!--docid::SEC263::-->
  166. <P>
  167. The include files useful for this section are:
  168. </P><P>
  169. <TABLE><tr><td>&nbsp;</td><td class=example><pre>#include "imesh/genmesh.h"
  170. </pre></td></tr></table><A NAME="HOWTO Camera Movement"></A>
  171. <HR SIZE=1>
  172. <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
  173. <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_115.html#SEC254"> &lt; </A>]</TD>
  174. <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_117.html#SEC264"> &gt; </A>]</TD>
  175. <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_102.html#SEC210"> &lt;&lt; </A>]</TD>
  176. <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_110.html#SEC226"> Up </A>]</TD>
  177. <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_135.html#SEC355"> &gt;&gt; </A>]</TD>
  178. <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
  179. <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
  180. <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC942">Index</A>]</TD>
  181. <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
  182. </TR></TABLE>
  183. <BR>
  184. <FONT SIZE="-1">
  185. This document was generated using
  186. <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
  187. "><I>texi2html</I></A>
  188. </BODY>
  189. </HTML>