source: GTP/trunk/Lib/Geom/OgreStuff/include/OgreSubMesh.h @ 1809

Revision 1809, 9.9 KB checked in by gumbau, 18 years ago (diff)
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-2005 The OGRE Team
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-----------------------------------------------------------------------------
24*/
25#ifndef __SubMesh_H_
26#define __SubMesh_H_
27
28#include "OgrePrerequisites.h"
29
30#include "OgreVertexIndexData.h"
31#include "OgreMaterial.h"
32#include "OgreRenderOperation.h"
33#include "OgreVertexBoneAssignment.h"
34#include "OgreProgressiveMesh.h"
35#include "OgreAnimationTrack.h"
36
37namespace Ogre {
38
39    /** Defines a part of a complete mesh.
40        @remarks
41            Meshes which make up the definition of a discrete 3D object
42            are made up of potentially multiple parts. This is because
43            different parts of the mesh may use different materials or
44            use different vertex formats, such that a rendering state
45            change is required between them.
46        @par
47            Like the Mesh class, instatiations of 3D objects in the scene
48            share the SubMesh instances, and have the option of overriding
49            their material differences on a per-object basis if required.
50            See the SubEntity class for more information.
51    */
52    class _OgreExport SubMesh
53    {
54        friend class Mesh;
55        friend class MeshSerializerImpl;
56        friend class MeshSerializerImpl_v1_2;
57        friend class MeshSerializerImpl_v1_1;
58    public:
59        SubMesh();
60        ~SubMesh();
61
62
63        /// Indicates if this submesh shares vertex data with other meshes or whether it has it's own vertices.
64        bool useSharedVertices;
65
66        /// The render operation type used to render this submesh
67        RenderOperation::OperationType operationType;
68
69        /** Dedicated vertex data (only valid if useSharedVertices = false).
70            @remarks
71                This data is completely owned by this submesh.
72            @par
73                The use of shared or non-shared buffers is determined when
74                model data is converted to the OGRE .mesh format.
75        */
76        VertexData *vertexData;
77
78        /// Face index data
79        IndexData *indexData;
80
81        /** Dedicated index map for translate blend index to bone index (only valid if useSharedVertices = false).
82            @remarks
83                This data is completely owned by this submesh.
84            @par
85                We collect actually used bones of all bone assignments, and build the
86                blend index in 'packed' form, then the range of the blend index in vertex
87                data VES_BLEND_INDICES element is continuous, with no gaps. Thus, by
88                minimising the world matrix array constants passing to GPU, we can support
89                more bones for a mesh when hardware skinning is used. The hardware skinning
90                support limit is applied to each set of vertex data in the mesh, in other words, the
91                hardware skinning support limit is applied only to the actually used bones of each
92                SubMeshes, not all bones across the entire Mesh.
93            @par
94                Because the blend index is different to the bone index, therefore, we use
95                the index map to translate the blend index to bone index.
96            @par
97                The use of shared or non-shared index map is determined when
98                model data is converted to the OGRE .mesh format.
99        */
100        typedef std::vector<unsigned short> IndexMap;
101        IndexMap blendIndexToBoneIndexMap;
102
103        ProgressiveMesh::LODFaceList mLodFaceList;
104
105        /// Reference to parent Mesh (not a smart pointer so child does not keep parent alive).
106        Mesh* parent;
107
108        /// Sets the name of the Material which this SubMesh will use
109        void setMaterialName(const String& matName);
110        const String& getMaterialName(void) const;
111
112        /** Returns true if a material has been assigned to the submesh, otherwise returns false.
113        */
114        bool isMatInitialised(void) const;
115
116        /** Returns a RenderOperation structure required to render this mesh.
117            @param
118                rend Reference to a RenderOperation structure to populate.
119            @param
120                lodIndex The index of the LOD to use.
121        */
122        void _getRenderOperation(RenderOperation& rend, ushort lodIndex = 0);
123
124        /** Assigns a vertex to a bone with a given weight, for skeletal animation.
125        @remarks   
126            This method is only valid after calling setSkeletonName.
127            Since this is a one-off process there exists only 'addBoneAssignment' and
128            'clearBoneAssignments' methods, no 'editBoneAssignment'. You should not need
129            to modify bone assignments during rendering (only the positions of bones) and OGRE
130            reserves the right to do some internal data reformatting of this information, depending
131            on render system requirements.
132        @par
133            This method is for assigning weights to the dedicated geometry of the SubMesh. To assign
134            weights to the shared Mesh geometry, see the equivalent methods on Mesh.
135        */
136        void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign);
137
138        /** Removes all bone assignments for this mesh.
139        @par
140            This method is for assigning weights to the dedicated geometry of the SubMesh. To assign
141            weights to the shared Mesh geometry, see the equivalent methods on Mesh.
142        */
143        void clearBoneAssignments(void);
144
145        /// Multimap of verex bone assignments (orders by vertex index)
146        typedef std::multimap<size_t, VertexBoneAssignment> VertexBoneAssignmentList;
147        typedef MapIterator<VertexBoneAssignmentList> BoneAssignmentIterator;
148
149        /** Gets an iterator for access all bone assignments.
150        @remarks
151            Only valid if this SubMesh has dedicated geometry.
152        */
153        BoneAssignmentIterator getBoneAssignmentIterator(void);
154
155        /** Must be called once to compile bone assignments into geometry buffer. */
156        void _compileBoneAssignments(void);
157
158        typedef ConstMapIterator<AliasTextureNamePairList> AliasTextureIterator;
159        /** Gets an constant iterator to access all texture alias names assigned to this submesh.
160
161        */
162        AliasTextureIterator getAliasTextureIterator(void) const;
163        /** Adds the alias or replaces an existing one and associates the texture name to it.
164        @remarks
165          The submesh uses the texture alias to replace textures used in the material applied
166          to the submesh.
167        @param
168            aliasName is the name of the alias.
169        @param
170            textureName is the name of the texture to be associated with the alias
171
172        */
173        void addTextureAlias(const String& aliasName, const String& textureName);
174        /** Remove a specific texture alias name from the sub mesh
175        @param
176            aliasName is the name of the alias to be removed.  If it is not found
177            then it is ignored.
178        */
179        void removeTextureAlias(const String& aliasName);
180        /** removes all texture aliases from the sub mesh
181        */
182        void removeAllTextureAliases(void);
183        /** returns true if the sub mesh has texture aliases
184        */
185        bool hasTextureAliases(void) const { return !mTextureAliases.empty(); }
186        /** Gets the number of texture aliases assigned to the sub mesh.
187        */
188        size_t getTextureAliasCount(void) const { return mTextureAliases.size(); }
189
190        /**  The current material used by the submesh is copied into a new material
191            and the submesh's texture aliases are applied if the current texture alias
192            names match those found in the original material.
193        @remarks
194            The submesh's texture aliases must be setup prior to calling this method.
195            If a new material has to be created, the subMesh autogenerates the new name.
196            The new name is the old name + "_" + number.
197        @return
198            True if texture aliases were applied and a new material was created.
199        */
200        bool updateMaterialUsingTextureAliases(void);
201
202                /** Get the type of any vertex animation used by dedicated geometry.
203                */
204                VertexAnimationType getVertexAnimationType(void) const;
205
206    protected:
207
208        /// Name of the material this SubMesh uses.
209        String mMaterialName;
210
211        /// Is there a material yet?
212        bool mMatInitialised;
213
214        /// paired list of texture aliases and texture names
215        AliasTextureNamePairList mTextureAliases;
216
217        VertexBoneAssignmentList mBoneAssignments;
218
219        /// Flag indicating that bone assignments need to be recompiled
220        bool mBoneAssignmentsOutOfDate;
221
222                /// Type of vertex animation for dedicated vertex data (populated by Mesh)
223                mutable VertexAnimationType mVertexAnimationType;
224
225
226        /// Internal method for removing LOD data
227        void removeLodLevels(void);
228
229
230
231    };
232
233} // namespace
234
235#endif
236
Note: See TracBrowser for help on using the repository browser.