![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
Direct3DRMMeshBuilder: The Meshbuilder InterfaceThe Direct3DRMMeshBuilder interface is a high-level, convenient mesh manipulation tool that offers 38 member functions for creating and modifying meshes. Meshbuilders, as their name implies, build meshes and are not meshes themselves. They can, however, be used as convenient substitutes for meshes. Meshbuilders can be added to scenes as visual elements. When meshbuilders are added to a scene, they create and use an internal mesh. Meshbuilders are created using the Direct3DRM CreateMeshBuilder() function as shown below: LPDIRECT3DRMMESHBUILDER meshbuilder; d3drm->CreateMeshBuilder( &meshbuilder ); Loading and SavingThe Load() member function lets meshbuilder objects load meshes from disk, program resources, or memory. The Load() function will also load any textures applied to a mesh as long as the textures location is supplied in Direct3Ds search path. Load() allows for the use of a callback function whenever an attempt is made to load a texture. This allows programs to override the default attempt to load a texture, making it possible to load textures from specific directories or from a programs resources. The meshbuilder Save() member function allows you to save meshes as text, binary, or compressed files. Rendering OptionsMeshbuilders allow for the manipulation of mesh qualities such as color, texture, and rendering options. Some meshbuilder member functions used for rendering mesh options include:
The SetColor() and SetColorRGB() functions can be used to assign colors to the faces in a mesh. No GetColor() function is supplied because there is no guarantee that all of the faces in the mesh will be the same color. The GetQuality() and SetQuality() member functions can be used to set the rendering mode of the mesh (wireframe, flat, Gouraud, etc.). There is a limitation, however. Direct3D will demote the render quality of a meshbuilder if the device on which it is to be rendered is configured to use a more primitive rendering mode. For example, if a device is configured to use the wireframe mode, then any meshbuilders that use flat or Gouraud mode will appear in wireframe. The meshbuilder SetTexture() member function assigns specific textures to the meshbuilder. The GetTextureCoordinates(), SetTextureCoordinates(), and SetTextureTopology() member functions allow texture attributes to be assigned. It is usually preferable to use a texture wrap instead of these functions. Well talk about texture wraps later in this chapter. The GetPerspective() and SetPerspective() member functions can be used to turn texture perspective correction on or off. Texture perspective correction insures that textures appear correctly given their location and orientation from the viewer, but it brings extra computational overhead as well. In general, perspective correction is desirable when a texture appears on large faces, close to the viewer. Correction can be safely turned off if a mesh doesnt get close to the viewer. Youll know its time to turn on perspective correction if it appears that textures are drifting and sliding across mesh faces during animation. Face AccessThe Meshbuilder interface also allows face modifications and additions. For example, a list of the faces that make up a meshbuilder can be retrieved with the GetFaces() member function. The number of faces in a mesh can be retrieved with the GetFaceCount() member function. Faces can be created and added to a meshbuilder with the CreateFace(), AddFace() and AddFaces() member functions. Vertex AccessMeshbuilders allow the vertices used by the mesh to be accessed. The number of vertices in a mesh can be retrieved with the GetVertexCount() member function. All of the vertices in a mesh can be retrieved, modified, and assigned using the GetVertices() and SetVertices() member functions. The vertex access functionality is powerful since the shape of the mesh can be modified using the vertex functions. Translating And ScalingObjects rely on frames for their locations, but meshes can specify how they are situated in relation to attached frames. The meshbuilder Translate() member function allows you to specify offsets for a meshs location. This allows you to attach multiple meshes to a single frame without having the meshes occupy the exact same space. The Scale() member function applies a set of scale factors to a mesh. The scaling takes place on the meshs local axis, so the mesh is scaled as if it were centered on the origin. Different scale factors can be used for each axis, so meshes can be stretched and reduced. PerformanceBecause of the power and ease of use that the Direct3DRMMeshBuilder interface provides, meshbuilders are the obvious choice for many tasks. In terms of performance, however, the Meshbuilder interface is lacking in some situations. If you use a meshbuilder to load and configure a mesh, and then use the resulting mesh in a scene without frequently modifying its qualities, then using the Meshbuilder interface is fine. However, if the qualities of a mesh (color, texture, vertex positions, etc.) change often during the course of execution, meshbuilders perform poorly. Well talk about the alternative to meshbuilders next.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |