Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreSubMesh.h @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 11.4 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#ifndef __SubMesh_H_
30#define __SubMesh_H_
31
32#include "OgrePrerequisites.h"
33
34#include "OgreVertexIndexData.h"
35#include "OgreMaterial.h"
36#include "OgreRenderOperation.h"
37#include "OgreVertexBoneAssignment.h"
38#include "OgreProgressiveMesh.h"
39#include "OgreAnimationTrack.h"
40
41namespace Ogre {
42
43    /** Defines a part of a complete mesh.
44        @remarks
45            Meshes which make up the definition of a discrete 3D object
46            are made up of potentially multiple parts. This is because
47            different parts of the mesh may use different materials or
48            use different vertex formats, such that a rendering state
49            change is required between them.
50        @par
51            Like the Mesh class, instatiations of 3D objects in the scene
52            share the SubMesh instances, and have the option of overriding
53            their material differences on a per-object basis if required.
54            See the SubEntity class for more information.
55    */
56    class _OgreExport SubMesh
57    {
58        friend class Mesh;
59        friend class MeshSerializerImpl;
60        friend class MeshSerializerImpl_v1_2;
61        friend class MeshSerializerImpl_v1_1;
62    public:
63        SubMesh();
64        ~SubMesh();
65
66
67        /// Indicates if this submesh shares vertex data with other meshes or whether it has it's own vertices.
68        bool useSharedVertices;
69
70        /// The render operation type used to render this submesh
71        RenderOperation::OperationType operationType;
72
73        /** Dedicated vertex data (only valid if useSharedVertices = false).
74            @remarks
75                This data is completely owned by this submesh.
76            @par
77                The use of shared or non-shared buffers is determined when
78                model data is converted to the OGRE .mesh format.
79        */
80        VertexData *vertexData;
81
82        /// Face index data
83        IndexData *indexData;
84
85        /** Dedicated index map for translate blend index to bone index (only valid if useSharedVertices = false).
86            @remarks
87                This data is completely owned by this submesh.
88            @par
89                We collect actually used bones of all bone assignments, and build the
90                blend index in 'packed' form, then the range of the blend index in vertex
91                data VES_BLEND_INDICES element is continuous, with no gaps. Thus, by
92                minimising the world matrix array constants passing to GPU, we can support
93                more bones for a mesh when hardware skinning is used. The hardware skinning
94                support limit is applied to each set of vertex data in the mesh, in other words, the
95                hardware skinning support limit is applied only to the actually used bones of each
96                SubMeshes, not all bones across the entire Mesh.
97            @par
98                Because the blend index is different to the bone index, therefore, we use
99                the index map to translate the blend index to bone index.
100            @par
101                The use of shared or non-shared index map is determined when
102                model data is converted to the OGRE .mesh format.
103        */
104        typedef std::vector<unsigned short> IndexMap;
105        IndexMap blendIndexToBoneIndexMap;
106
107        ProgressiveMesh::LODFaceList mLodFaceList;
108
109        /** A list of extreme points on the submesh (optional).
110            @remarks
111                These points are some arbitrary points on the mesh that are used
112                by engine to better sort submeshes by depth. This doesn't matter
113                much for non-transparent submeshes, as Z-buffer takes care of invisible
114                surface culling anyway, but is pretty useful for semi-transparent
115                submeshes because the order in which transparent submeshes must be
116                rendered cannot be always correctly deduced from entity position.
117            @par
118                These points are intelligently chosen from the points that make up
119                the submesh, the criteria for choosing them should be that these points
120                somewhat characterize the submesh outline, e.g. they should not be
121                close to each other, and they should be on the outer hull of the submesh.
122                They can be stored in the .mesh file, or generated at runtime
123                (see generateExtremes ()).
124            @par
125                If this array is empty, submesh sorting is done like in older versions -
126                by comparing the positions of the owning entity.
127         */
128        std::vector<Vector3> extremityPoints;
129
130        /// Reference to parent Mesh (not a smart pointer so child does not keep parent alive).
131        Mesh* parent;
132
133        /// Sets the name of the Material which this SubMesh will use
134        void setMaterialName(const String& matName);
135        const String& getMaterialName(void) const;
136
137        /** Returns true if a material has been assigned to the submesh, otherwise returns false.
138        */
139        bool isMatInitialised(void) const;
140
141        /** Returns a RenderOperation structure required to render this mesh.
142            @param
143                rend Reference to a RenderOperation structure to populate.
144            @param
145                lodIndex The index of the LOD to use.
146        */
147        void _getRenderOperation(RenderOperation& rend, ushort lodIndex = 0);
148
149        /** Assigns a vertex to a bone with a given weight, for skeletal animation.
150        @remarks   
151            This method is only valid after calling setSkeletonName.
152            Since this is a one-off process there exists only 'addBoneAssignment' and
153            'clearBoneAssignments' methods, no 'editBoneAssignment'. You should not need
154            to modify bone assignments during rendering (only the positions of bones) and OGRE
155            reserves the right to do some internal data reformatting of this information, depending
156            on render system requirements.
157        @par
158            This method is for assigning weights to the dedicated geometry of the SubMesh. To assign
159            weights to the shared Mesh geometry, see the equivalent methods on Mesh.
160        */
161        void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign);
162
163        /** Removes all bone assignments for this mesh.
164        @par
165            This method is for assigning weights to the dedicated geometry of the SubMesh. To assign
166            weights to the shared Mesh geometry, see the equivalent methods on Mesh.
167        */
168        void clearBoneAssignments(void);
169
170        /// Multimap of verex bone assignments (orders by vertex index)
171        typedef std::multimap<size_t, VertexBoneAssignment> VertexBoneAssignmentList;
172        typedef MapIterator<VertexBoneAssignmentList> BoneAssignmentIterator;
173
174        /** Gets an iterator for access all bone assignments.
175        @remarks
176            Only valid if this SubMesh has dedicated geometry.
177        */
178        BoneAssignmentIterator getBoneAssignmentIterator(void);
179
180        /** Must be called once to compile bone assignments into geometry buffer. */
181        void _compileBoneAssignments(void);
182
183        typedef ConstMapIterator<AliasTextureNamePairList> AliasTextureIterator;
184        /** Gets an constant iterator to access all texture alias names assigned to this submesh.
185
186        */
187        AliasTextureIterator getAliasTextureIterator(void) const;
188        /** Adds the alias or replaces an existing one and associates the texture name to it.
189        @remarks
190          The submesh uses the texture alias to replace textures used in the material applied
191          to the submesh.
192        @param
193            aliasName is the name of the alias.
194        @param
195            textureName is the name of the texture to be associated with the alias
196
197        */
198        void addTextureAlias(const String& aliasName, const String& textureName);
199        /** Remove a specific texture alias name from the sub mesh
200        @param
201            aliasName is the name of the alias to be removed.  If it is not found
202            then it is ignored.
203        */
204        void removeTextureAlias(const String& aliasName);
205        /** removes all texture aliases from the sub mesh
206        */
207        void removeAllTextureAliases(void);
208        /** returns true if the sub mesh has texture aliases
209        */
210        bool hasTextureAliases(void) const { return !mTextureAliases.empty(); }
211        /** Gets the number of texture aliases assigned to the sub mesh.
212        */
213        size_t getTextureAliasCount(void) const { return mTextureAliases.size(); }
214
215        /**  The current material used by the submesh is copied into a new material
216            and the submesh's texture aliases are applied if the current texture alias
217            names match those found in the original material.
218        @remarks
219            The submesh's texture aliases must be setup prior to calling this method.
220            If a new material has to be created, the subMesh autogenerates the new name.
221            The new name is the old name + "_" + number.
222        @return
223            True if texture aliases were applied and a new material was created.
224        */
225        bool updateMaterialUsingTextureAliases(void);
226
227                /** Get the type of any vertex animation used by dedicated geometry.
228                */
229                VertexAnimationType getVertexAnimationType(void) const;
230
231        /** Generate the submesh extremes (@see extremityPoints).
232        @param count
233            Number of extreme points to compute for the submesh.
234        */
235        void generateExtremes(size_t count);
236
237    protected:
238
239        /// Name of the material this SubMesh uses.
240        String mMaterialName;
241
242        /// Is there a material yet?
243        bool mMatInitialised;
244
245        /// paired list of texture aliases and texture names
246        AliasTextureNamePairList mTextureAliases;
247
248        VertexBoneAssignmentList mBoneAssignments;
249
250        /// Flag indicating that bone assignments need to be recompiled
251        bool mBoneAssignmentsOutOfDate;
252
253                /// Type of vertex animation for dedicated vertex data (populated by Mesh)
254                mutable VertexAnimationType mVertexAnimationType;
255
256
257        /// Internal method for removing LOD data
258        void removeLodLevels(void);
259
260
261
262    };
263
264} // namespace
265
266#endif
267
Note: See TracBrowser for help on using the repository browser.