Podstrony
- Strona startowa
- (ebook pdf) Teach Yourself SQL in 21 Days
- Linux. .Mandrake.10.Podręcznik.Użytkownika.[eBook.PL] (3)
- (eBook) James, William The Principles of Psychology Vol. II
- (ebook computers) Visual C .NET DeveloperÂ’s Guide
- (Business Ebook) 101 Ebay Auction Secrets (1)
- LINUXADM (4)
- Ania07 Dolina Teczy
- Janet Evanovich Po czwarte dla grzechu
- Andy Weir Marsjanin (4)
- W dol Tim Johnston
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- slaveofficial.htw.pl
[ Pobierz całość w formacie PDF ]
.// Datachar szXfile1[] = "boxsph1.x" ; // Second formatchar meshName[] = "Box";.retval = lpD3DRM->CreateMeshBuilder(&boxMeshBuilder);if (FAILED(retval))// Meshbuilder creation failure error handler goes here// Use meshbuilder to load a mesh from a DirectX fileretval = boxMeshBuilder->Load(szXfile1, // Source&meshName,D3DRMLOAD_BYNAME, // OptionsNULL, NULL);if (FAILED(retval))// Mesh load error handler goes hereThe program 3DRM Mesh Load Demo in the book's CD-ROM contains menu com-mands to loadindividual meshes.One of these commands loads all four individual meshes that are part of ateapot object.Each individual mesh is colored using the SetColorRGB() function of theIDirect3DRMMeshBuilder3 interface.The result is shown in color plate 9.Although it is not explicitly stated in the documentation, it appears that the X file does not containpositional information regarding meshes.We make this deduction based on our failed attempts toload a mesh by position.Interpreting X File DataWe have stated that the applications programmer is likely to rely on a modeling program for theconstruction of graphical objects.A typical scenario is to model 3D objects using 3D Studio MAX,TrueSpace4, or some other application.The resulting file can be already in X format or in.3dsformat.In the latter case it can be con-verted into X format by means of the Conv3ds utilitydiscussed previously in this chapter.The meshes in the X file are then loaded into program codeeither as frames, or as meshbuilder objects.Considering the power and refinement of the available image editing tools, it is difficult to imaginea circumstance in which the programmer would hard-code a mesh by defining its faces, vertices,and normals.However, there are cases in which, for reasons of convenience or performance, itmay be profitable to store mesh data directly in code.If the programmer is familiar with how meshdata is stored in the file, it is possible to use a 3D modeling program to create the mesh and thencut-and-paste the mesh data from the file into program code.In other words, let the modelingprogram do the hard work of finding the vertices, faces, and normals, and use this information todefine the required data.Decoding an X file cubeThe DirectX file format templates can be of considerable assistance in interpreting the datacontained in a DirectX text format file and in deciphering the encoding.Appendix C contains thetemplates for the DirectX file format.In the following example we use the data in the file boxsph1.x,which was obtained from the 3ds-format file named boxsph.3ds by means of the command:Conv3ds -o"boxsph1.x" -x boxsph.3dsOur purpose is to use the raw mesh data contained in the X file named boxsph1.x in order to hard-code a cube mesh.The data for the mesh object named "Box" appears in the file as follows:Mesh Box {8;-0.440000; -0.000000; -0.440000;,0.440000; -0.000000; -0.440000;,-0.440000; -0.000000; 0.440000;,0.440000; -0.000000; 0.440000;,-0.440000; 0.880000; -0.440000;,0.440000; 0.880000; -0.440000;,-0.440000; 0.880000; 0.440000;,0.440000; 0.880000; 0.440000;;12;3;0,3,2;,3;3,0,1;,3;4,7,5;,3;7,4,6;,3;0,5,1;,3;5,0,4;,3;1,7,3;,3;7,1,5;,3;3,6,2;,3;6,3,7;,3;2,4,0;,3;4,2,6;;MeshNormals {24;-0.000000;-1.000000;-0.000000;,0.000000;0.000000;-1.000000;,-1.000000;0.000000;0.000000;,-0.000000;-1.000000;-0.000000;,0.000000;0.000000;-1.000000;,1.000000;0.000000;0.000000;,-0.000000;-1.000000;-0.000000;,0.000000;0.000000;1.000000;,-1.000000;0.000000;0.000000;,-0.000000;-1.000000;-0.000000;,1.000000;0.000000;0.000000;,0.000000;0.000000;1.000000;,0.000000;1.000000;-0.000000;,0.000000;0.000000;-1.000000;,-1.000000;0.000000;0.000000;,0.000000;1.000000;-0.000000;,0.000000;0.000000;-1.000000;,1.000000;0.000000;0.000000;,0.000000;1.000000;-0.000000;,0.000000;0.000000;1.000000;,-1.000000;0.000000;0.000000;,0.000000;1.000000;-0.000000;,1.000000;0.000000;0.000000;,0.000000;0.000000;1.000000;;12;3;0,9,6;,3;9,0,3;,3;12,21,15;,3;21,12,18;,3;1,16,4;,3;16,1,13;,3;5,22,10;,3;22,5,17;,3;11,19,7;,3;19,11,23;,3;8,14,2;,3;14,8,20;;To decipher this data you can observe how it is formatted in the template for the Mesh component.The template appears in the Microsoft documentation (reproduced with minor editing in AppendixC) as follows:Template: MeshUUIDMember Name Type Optional Array Optional DataSize ObjectsnVertices DWORD (see list)vertices array Vector nVerticesnFaces DWORDfaces array nFacesMeshFaceDescriptionDefines a simple mesh.The first array is a list of vertices.The second array defines the faces ofthe mesh by indexing into the vertex array.Optional data objectsThe following optional data elements are used by Direct3D Retained Mode.MeshFaceWraps If not present, wrapping forboth u and v defaults to false.MeshTextureCoords If not present, there are notexture coordinates.MeshNormals If not present, normals aregenerated using theGenerateNormals API.MeshVertexColors If not present, the colorsdefault to white.MeshMaterialList If not present, the materialdefaults to whiteIf we now observe the X file data in light of the Mesh template we notice that the MeshNormalsoptional data object is the only one included with the mesh.This means that the mesh has nowraps, texture coordinates, vertex colors, or materials list.The first value (8) indicates the numberof vertices and is followed by the coordinate triplets for each vertex, as follows:8;-0.440000; -0.000000; -0.440000;,0.440000; -0.000000; -0.440000;,-0.440000; -0.000000; 0.440000;,0.440000; -0.000000; 0.440000;,-0.440000; 0.880000; -0.440000;,0.440000; 0.880000; -0.440000;,-0.440000; 0.880000; 0.440000;,0.440000; 0.880000; 0.440000;;We can use this data to construct the array that encodes the coordinates for each vertex, asfollows:D3DVECTOR vertices[] = {-0.440000, -0.000000, -0.440000,0.440000, -0.000000, -0.440000,-0.440000, -0.000000, 0.440000,0.440000, -0.000000, 0.440000,-0.440000, 0.880000, -0.440000,0.440000, 0.880000, -0.440000,-0.440000, 0.880000, 0.440000,0.440000, 0.880000, 0.440000 };The mesh file also contains the optional MeshNormals data which you can use to obtain the arrayof normals for our hard-coded cube
[ Pobierz całość w formacie PDF ]