/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
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <!-- Created by texi2html 1.64 -->
- <!--
- 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: Olaf Bachmann <obachman@mathematik.uni-kl.de>
- Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
-
- -->
- <HTML>
- <HEAD>
- <TITLE>Crystal Space: HOWTO Create Genmesh</TITLE>
- <META NAME="description" CONTENT="Crystal Space: HOWTO Create Genmesh">
- <META NAME="keywords" CONTENT="Crystal Space: HOWTO Create Genmesh">
- <META NAME="resource-type" CONTENT="document">
- <META NAME="distribution" CONTENT="global">
- <META NAME="Generator" CONTENT="texi2html 1.64">
- </HEAD>
- <BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
- <A NAME="SEC259"></A>
- <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
- <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_115.html#SEC254"> < </A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_117.html#SEC264"> > </A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_102.html#SEC210"> << </A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_110.html#SEC226"> Up </A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_135.html#SEC355"> >> </A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC942">Index</A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
- </TR></TABLE>
- <HR SIZE=1>
- <H3> 5.8.6 Creating a Genmesh Mesh </H3>
- <!--docid::SEC259::-->
- <P>
- This section describes how to create a Genmesh mesh.
- </P><P>
- <A NAME="SEC260"></A>
- <H4> What is Genmesh? </H4>
- <!--docid::SEC260::-->
- <P>
- A `<SAMP>Genmesh</SAMP>' mesh object (see section <A HREF="cs_214.html#SEC581">7.7.7 Genmesh Mesh Object</A>) is a generic
- triangle mesh object that (currently) supports one material for the entire
- mesh. In contrast with 3D sprites (see section <A HREF="cs_212.html#SEC571">7.7.5 Sprite3D Mesh Object</A>), genmeshes do not
- support animation (except that you can modify the vertices manually at
- runtime).
- </P><P>
- Genmeshes are very useful for static or semi-static geometry (chests,
- doors, candles, swords, etc.) which do not need internal animation but which
- can sometimes require a lot of detail.
- </P><P>
- Genmeshes use vertex lighting (or stencil if you use a stencil lighting
- shader).
- </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><P>
- <A NAME="SEC261"></A>
- <H4> Creating a Genmesh in a Map </H4>
- <!--docid::SEC261::-->
- <P>
- Here is an example of how to create a cube genmesh in a map file:
- </P><P>
- <TABLE><tr><td> </td><td class=example><pre><meshfact name="cubeFact">
- <plugin>crystalspace.mesh.loader.factory.genmesh</plugin>
- <params>
- <numvt>8</numvt>
- <numtri>12</numtri>
- <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><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><P>
- <TABLE><tr><td> </td><td class=example><pre><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 />
- </params>
- </meshfact>
- </pre></td></tr></table></P><P>
- This is a quick way to make boxes in a map file.
- </P><P>
- <A NAME="SEC262"></A>
- <H4> Creating a Genmesh Programmatically </H4>
- <!--docid::SEC262::-->
- <P>
- Here we create the same genmesh programmatically:
- </P><P>
- <TABLE><tr><td> </td><td class=example><pre> // First create the factory:
- csRef<iMeshFactoryWrapper> fact = engine->CreateMeshFactory (
- "crystalspace.mesh.object.genmesh", "cubeFact");
- csRef<iGeneralFactoryState> factstate = SCF_QUERY_INTERFACE (
- fact->GetMeshObjectFactory (), iGeneralFactoryState);
- 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);
- <small>...</small>
- factstate->SetTriangleCount (12);
- factstate->GetTriangles ()[0].Set (0, 3, 1);
- factstate->GetTriangles ()[1].Set (3, 2, 1);
- <small>...</small>
- factstate->CalculateNormals ();
- // Now create an instance:
- csRef<iMeshWrapper> mesh =
- engine->CreateMeshWrapper (fact, "cube");
- csRef<iGeneralMeshState> meshstate = SCF_QUERY_INTERFACE (
- mesh->GetMeshObject (), iGeneralMeshState);
- meshstate->SetMaterialWrapper (myMaterial);
- <small>...</small>
- </pre></td></tr></table></P><P>
- This will basically create the same cube as in the map file example.
- </P><P>
- <A NAME="SEC263"></A>
- <H4> Include Files </H4>
- <!--docid::SEC263::-->
- <P>
- The include files useful for this section are:
- </P><P>
- <TABLE><tr><td> </td><td class=example><pre>#include "imesh/genmesh.h"
- </pre></td></tr></table><A NAME="HOWTO Camera Movement"></A>
- <HR SIZE=1>
- <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
- <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_115.html#SEC254"> < </A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_117.html#SEC264"> > </A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_102.html#SEC210"> << </A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_110.html#SEC226"> Up </A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_135.html#SEC355"> >> </A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC942">Index</A>]</TD>
- <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
- </TR></TABLE>
- <BR>
- <FONT SIZE="-1">
- This document was generated using
- <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
- "><I>texi2html</I></A>
- </BODY>
- </HTML>