<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd"> <html> <!-- Created by texi2html 1.76 --> <!-- Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author) Karl Berry <karl@freefriends.org> Olaf Bachmann <obachman@mathematik.uni-kl.de> and many others. Maintained by: Many creative people <dev@texi2html.cvshome.org> Send bugs and suggestions to <users@texi2html.cvshome.org> --> <head> <title>Crystal Space 1.2.1: 4.10.5 Creating a Genmesh Mesh</title> <meta name="description" content="Crystal Space 1.2.1: 4.10.5 Creating a Genmesh Mesh"> <meta name="keywords" content="Crystal Space 1.2.1: 4.10.5 Creating a Genmesh Mesh"> <meta name="resource-type" content="document"> <meta name="distribution" content="global"> <meta name="Generator" content="texi2html 1.76"> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> <style type="text/css"> <!-- a.summary-letter {text-decoration: none} pre.display {font-family: serif} pre.format {font-family: serif} pre.menu-comment {font-family: serif} pre.menu-preformatted {font-family: serif} pre.smalldisplay {font-family: serif; font-size: smaller} pre.smallexample {font-size: smaller} pre.smallformat {font-family: serif; font-size: smaller} pre.smalllisp {font-size: smaller} span.sansserif {font-family:sans-serif; font-weight:normal;} ul.toc {list-style: none} --> </style> </head> <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> <a name="HOWTO-Create-Genmesh"></a> <a name="0"></a> <table cellpadding="1" cellspacing="1" border="0"> <tr><td valign="middle" align="left">[<a href="HOWTO-Create-Thing.html#0" title="Previous section in reading order"> < </a>]</td> <td valign="middle" align="left">[<a href="HOWTO-Mesh-LightAnim.html#0" title="Next section in reading order"> > </a>]</td> <td valign="middle" align="left"> </td> <td valign="middle" align="left">[<a href="Using-Crystal-Space.html#0" title="Beginning of this chapter or previous chapter"> << </a>]</td> <td valign="middle" align="left">[<a href="MeshObject.html#0" title="Up section"> Up </a>]</td> <td valign="middle" align="left">[<a href="Working-with-Engine-Content.html#0" title="Next chapter"> >> </a>]</td> <td valign="middle" align="left"> </td> <td valign="middle" align="left"> </td> <td valign="middle" align="left"> </td> <td valign="middle" align="left"> </td> <td valign="middle" align="left">[<a href="index.html#SEC_Top" title="Cover (top) of document">Top</a>]</td> <td valign="middle" align="left">[<a href="cs_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td> <td valign="middle" align="left">[<a href="cs_Index.html#0" title="Index">Index</a>]</td> <td valign="middle" align="left">[<a href="cs_abt.html#SEC_About" title="About (help)"> ? </a>]</td> </tr></table> <hr size="1"> <h3 class="subsection"> 4.10.5 Creating a Genmesh Mesh </h3> <p>This section describes how to create a Genmesh mesh. </p> <a name="1"></a> <h4 class="subsubheading"> What is Genmesh? </h4> <p>A <samp>‘Genmesh’</samp> mesh object (see section <a href="MeshObject-Genmesh.html#0">Genmesh Mesh Object</a>) is a generic triangle mesh object. Genmeshes also support animation (see section <a href="GenMesh-Animation.html#0">GenMesh Animation</a>). </p> <p>Genmeshes are very useful for static or semi-static geometry (chests, doors, candles, swords, etc.) which can sometimes require a lot of detail. </p> <p>Genmeshes use vertex lighting (or stencil if you use a stencil lighting shader). You can also use lightmaps on genmeshes with the <samp>‘lighter2’</samp> application. See section <a href="Using-lighter2.html#0">Using <code>lighter2</code></a>. </p> <p>Genmesh objects always have to be created through a factory. So, first you create the actual geometry in a genmesh factory and then you create one or more instances from that factory. This is a great way to save memory. This does mean that it is not possible to HardTransform genmeshes. It is only possible to HardTransform Genmesh factories. </p> <a name="2"></a> <h4 class="subsubheading"> Creating a Genmesh in a Map </h4> <p>Here is an example of how to create a cube genmesh in a map file: </p> <table><tr><td> </td><td><pre class="example"><meshfact name="cubeFact"> <plugin>crystalspace.mesh.loader.factory.genmesh</plugin> <params> <v x="-0.1" y="0.1" z="0.1" u="0" v="0" /> <v x="-0.1" y="0.1" z="-0.1" u="1" v="0" /> <v x="0.1" y="0.1" z="-0.1" u="0" v="1" /> <v x="0.1" y="0.1" z="0.1" u="1" v="1" /> <v x="-0.1" y="-0.1" z="0.1" u="1" v="0" /> <v x="-0.1" y="-0.1" z="-0.1" u="0" v="1" /> <v x="0.1" y="-0.1" z="-0.1" u="1" v="1" /> <v x="0.1" y="-0.1" z="0.1" u="0" v="0" /> <t v1="0" v2="3" v3="1" /> <t v1="3" v2="2" v3="1" /> <t v1="4" v2="5" v3="7" /> <t v1="5" v2="6" v3="7" /> <t v1="0" v2="4" v3="3" /> <t v1="4" v2="7" v3="3" /> <t v1="1" v2="6" v3="5" /> <t v1="1" v2="2" v3="6" /> <t v1="0" v2="1" v3="5" /> <t v1="0" v2="5" v3="4" /> <t v1="2" v2="3" v3="7" /> <t v1="2" v2="7" v3="6" /> <autonormals /> </params> </meshfact> <sector name="bla"> <meshobj name="cube"> <plugin>crystalspace.mesh.loader.genmesh</plugin> <params> <factory>cubeFact</factory> <material>mosaic</material> </params> <move> <v x="1" y="0" z="3" /> </move> </meshobj> </sector> </pre></td></tr></table> <p>In this example we define a box by specifying the eight corner vertices and the twelve triangles. The <code><autonormals></code> tag specifies that normals will be created automatically (to give the box a smooth appearance). The normals are used for lighthing. It is also possible to specify normals manually. Note that with every vertex we also specify a texture coordinate (uv coordinate). </p> <p>To create a genmesh box you can actually use a short-hand notation: </p> <table><tr><td> </td><td><pre class="example"><meshfact name="cubeFact"> <plugin>crystalspace.mesh.loader.factory.genmesh</plugin> <params> <box> <min x="-0.1" y="-0.1" z="-0.1" /> <max x="0.1" y="0.1" z="0.1" /> </box> <autonormals /> <lighting>true</lighting> </params> </meshfact> </pre></td></tr></table> <p>This is a quick way to make boxes in a map file. </p> <a name="3"></a> <h4 class="subsubheading"> Creating a Genmesh Programmatically </h4> <p>Here we create the same genmesh programmatically: </p> <table><tr><td> </td><td><pre class="example">// First create the factory: csRef<iMeshFactoryWrapper> fact = engine->CreateMeshFactory ( "crystalspace.mesh.object.genmesh", "cubeFact"); csRef<iGeneralFactoryState> factstate = scfQueryInterface<iGeneralFactoryState> ( fact->GetMeshObjectFactory ()); factstate->SetVertexCount (8); factstate->GetVertices ()[0].Set (-0.1, 0.1, 0.1); factstate->GetTexels ()[0].Set (0, 0); factstate->GetVertices ()[1].Set (-0.1, 0.1, -0.1); factstate->GetTexels ()[1].Set (1, 0); ... factstate->SetTriangleCount (12); factstate->GetTriangles ()[0].Set (0, 3, 1); factstate->GetTriangles ()[1].Set (3, 2, 1); ... factstate->CalculateNormals (); // Now create an instance: csRef<iMeshWrapper> mesh = engine->CreateMeshWrapper (fact, "cube"); mesh->GetMeshObject ()->SetMaterialWrapper (myMaterial); csRef<iGeneralMeshState> meshstate = scfQueryInterface<iGeneralMeshState> ( mesh->GetMeshObject ()); meshstate->SetLighting (true); ... </pre></td></tr></table> <p>This will basically create the same cube as in the map file example. </p> <a name="4"></a> <h4 class="subsubheading"> Include Files </h4> <p>The include files useful for this section are: </p> <table><tr><td> </td><td><pre class="example">#include <imesh/genmesh.h> </pre></td></tr></table> <hr size="1"> <table cellpadding="1" cellspacing="1" border="0"> <tr><td valign="middle" align="left">[<a href="HOWTO-Create-Thing.html#0" title="Previous section in reading order"> < </a>]</td> <td valign="middle" align="left">[<a href="HOWTO-Mesh-LightAnim.html#0" title="Next section in reading order"> > </a>]</td> <td valign="middle" align="left"> </td> <td valign="middle" align="left">[<a href="Using-Crystal-Space.html#0" title="Beginning of this chapter or previous chapter"> << </a>]</td> <td valign="middle" align="left">[<a href="MeshObject.html#0" title="Up section"> Up </a>]</td> <td valign="middle" align="left">[<a href="Working-with-Engine-Content.html#0" title="Next chapter"> >> </a>]</td> <td valign="middle" align="left"> </td> <td valign="middle" align="left"> </td> <td valign="middle" align="left"> </td> <td valign="middle" align="left"> </td> <td valign="middle" align="left">[<a href="index.html#SEC_Top" title="Cover (top) of document">Top</a>]</td> <td valign="middle" align="left">[<a href="cs_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td> <td valign="middle" align="left">[<a href="cs_Index.html#0" title="Index">Index</a>]</td> <td valign="middle" align="left">[<a href="cs_abt.html#SEC_About" title="About (help)"> ? </a>]</td> </tr></table> <p> <font size="-1"> This document was generated using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>. </font> <br> </p> </body> </html>