Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreSubMesh.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 12.8 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-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __SubMesh_H_
29#define __SubMesh_H_
30
31#include "OgrePrerequisites.h"
32
33#include "OgreVertexIndexData.h"
34#include "OgreMaterial.h"
35#include "OgreRenderOperation.h"
36#include "OgreVertexBoneAssignment.h"
37#include "OgreAnimationTrack.h"
38#include "OgreResourceGroupManager.h"
39#include "OgreHeaderPrefix.h"
40
41namespace Ogre {
42
43        /** \addtogroup Core
44        *  @{
45        */
46        /** \addtogroup Resources
47        *  @{
48        */
49        /** Defines a part of a complete mesh.
50        @remarks
51            Meshes which make up the definition of a discrete 3D object
52            are made up of potentially multiple parts. This is because
53            different parts of the mesh may use different materials or
54            use different vertex formats, such that a rendering state
55            change is required between them.
56        @par
57            Like the Mesh class, instantiations of 3D objects in the scene
58            share the SubMesh instances, and have the option of overriding
59            their material differences on a per-object basis if required.
60            See the SubEntity class for more information.
61    */
62        class _OgreExport SubMesh : public SubMeshAlloc
63    {
64        friend class Mesh;
65        friend class MeshSerializerImpl;
66        friend class MeshSerializerImpl_v1_2;
67        friend class MeshSerializerImpl_v1_1;
68    public:
69        SubMesh();
70        ~SubMesh();
71
72
73        /// Indicates if this submesh shares vertex data with other meshes or whether it has it's own vertices.
74        bool useSharedVertices;
75
76        /// The render operation type used to render this submesh
77        RenderOperation::OperationType operationType;
78
79        /** Dedicated vertex data (only valid if useSharedVertices = false).
80            @remarks
81                This data is completely owned by this submesh.
82            @par
83                The use of shared or non-shared buffers is determined when
84                model data is converted to the OGRE .mesh format.
85        */
86        VertexData *vertexData;
87
88        /// Face index data
89        IndexData *indexData;
90
91        /** Dedicated index map for translate blend index to bone index (only valid if useSharedVertices = false).
92            @remarks
93                This data is completely owned by this submesh.
94            @par
95                We collect actually used bones of all bone assignments, and build the
96                blend index in 'packed' form, then the range of the blend index in vertex
97                data VES_BLEND_INDICES element is continuous, with no gaps. Thus, by
98                minimising the world matrix array constants passing to GPU, we can support
99                more bones for a mesh when hardware skinning is used. The hardware skinning
100                support limit is applied to each set of vertex data in the mesh, in other words, the
101                hardware skinning support limit is applied only to the actually used bones of each
102                SubMeshes, not all bones across the entire Mesh.
103            @par
104                Because the blend index is different to the bone index, therefore, we use
105                the index map to translate the blend index to bone index.
106            @par
107                The use of shared or non-shared index map is determined when
108                model data is converted to the OGRE .mesh format.
109        */
110        typedef vector<unsigned short>::type IndexMap;
111        IndexMap blendIndexToBoneIndexMap;
112
113                typedef vector<IndexData*>::type LODFaceList;
114                LODFaceList mLodFaceList;
115
116        /** A list of extreme points on the submesh (optional).
117            @remarks
118                These points are some arbitrary points on the mesh that are used
119                by engine to better sort submeshes by depth. This doesn't matter
120                much for non-transparent submeshes, as Z-buffer takes care of invisible
121                surface culling anyway, but is pretty useful for semi-transparent
122                submeshes because the order in which transparent submeshes must be
123                rendered cannot be always correctly deduced from entity position.
124            @par
125                These points are intelligently chosen from the points that make up
126                the submesh, the criteria for choosing them should be that these points
127                somewhat characterize the submesh outline, e.g. they should not be
128                close to each other, and they should be on the outer hull of the submesh.
129                They can be stored in the .mesh file, or generated at runtime
130                (see generateExtremes ()).
131            @par
132                If this array is empty, submesh sorting is done like in older versions -
133                by comparing the positions of the owning entity.
134         */
135        vector<Vector3>::type extremityPoints;
136
137        /// Reference to parent Mesh (not a smart pointer so child does not keep parent alive).
138        Mesh* parent;
139
140        /// Sets the name of the Material which this SubMesh will use
141        void setMaterialName(const String& matName, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
142        const String& getMaterialName(void) const;
143
144        /** Returns true if a material has been assigned to the submesh, otherwise returns false.
145        */
146        bool isMatInitialised(void) const;
147
148        /** Returns a RenderOperation structure required to render this mesh.
149            @param
150                rend Reference to a RenderOperation structure to populate.
151            @param
152                lodIndex The index of the LOD to use.
153        */
154        void _getRenderOperation(RenderOperation& rend, ushort lodIndex = 0);
155
156        /** Assigns a vertex to a bone with a given weight, for skeletal animation.
157        @remarks   
158            This method is only valid after calling setSkeletonName.
159            Since this is a one-off process there exists only 'addBoneAssignment' and
160            'clearBoneAssignments' methods, no 'editBoneAssignment'. You should not need
161            to modify bone assignments during rendering (only the positions of bones) and OGRE
162            reserves the right to do some internal data reformatting of this information, depending
163            on render system requirements.
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 addBoneAssignment(const VertexBoneAssignment& vertBoneAssign);
169
170        /** Removes all bone assignments for this mesh.
171        @par
172            This method is for assigning weights to the dedicated geometry of the SubMesh. To assign
173            weights to the shared Mesh geometry, see the equivalent methods on Mesh.
174        */
175        void clearBoneAssignments(void);
176
177        /// Multimap of verex bone assignments (orders by vertex index)
178        typedef multimap<size_t, VertexBoneAssignment>::type VertexBoneAssignmentList;
179        typedef MapIterator<VertexBoneAssignmentList> BoneAssignmentIterator;
180
181        /** Gets an iterator for access all bone assignments.
182        @remarks
183            Only valid if this SubMesh has dedicated geometry.
184        */
185        BoneAssignmentIterator getBoneAssignmentIterator(void);
186
187                /** Gets a const reference to the list of bone assignments
188                */
189                const VertexBoneAssignmentList& getBoneAssignments() { return mBoneAssignments; }
190
191
192        /** Must be called once to compile bone assignments into geometry buffer. */
193        void _compileBoneAssignments(void);
194
195        typedef ConstMapIterator<AliasTextureNamePairList> AliasTextureIterator;
196        /** Gets an constant iterator to access all texture alias names assigned to this submesh.
197
198        */
199        AliasTextureIterator getAliasTextureIterator(void) const;
200        /** Adds the alias or replaces an existing one and associates the texture name to it.
201        @remarks
202          The submesh uses the texture alias to replace textures used in the material applied
203          to the submesh.
204        @param
205            aliasName is the name of the alias.
206        @param
207            textureName is the name of the texture to be associated with the alias
208
209        */
210        void addTextureAlias(const String& aliasName, const String& textureName);
211        /** Remove a specific texture alias name from the sub mesh
212        @param
213            aliasName is the name of the alias to be removed.  If it is not found
214            then it is ignored.
215        */
216        void removeTextureAlias(const String& aliasName);
217        /** removes all texture aliases from the sub mesh
218        */
219        void removeAllTextureAliases(void);
220        /** returns true if the sub mesh has texture aliases
221        */
222        bool hasTextureAliases(void) const { return !mTextureAliases.empty(); }
223        /** Gets the number of texture aliases assigned to the sub mesh.
224        */
225        size_t getTextureAliasCount(void) const { return mTextureAliases.size(); }
226
227        /**  The current material used by the submesh is copied into a new material
228            and the submesh's texture aliases are applied if the current texture alias
229            names match those found in the original material.
230        @remarks
231            The submesh's texture aliases must be setup prior to calling this method.
232            If a new material has to be created, the subMesh autogenerates the new name.
233            The new name is the old name + "_" + number.
234        @return
235            True if texture aliases were applied and a new material was created.
236        */
237        bool updateMaterialUsingTextureAliases(void);
238
239                /** Get the type of any vertex animation used by dedicated geometry.
240                */
241                VertexAnimationType getVertexAnimationType(void) const;
242               
243                /// Returns whether animation on dedicated vertex data includes normals
244                bool getVertexAnimationIncludesNormals() const { return mVertexAnimationIncludesNormals; }
245
246
247        /** Generate the submesh extremes (@see extremityPoints).
248        @param count
249            Number of extreme points to compute for the submesh.
250        */
251        void generateExtremes(size_t count);
252
253                /** Returns true(by default) if the submesh should be included in the mesh EdgeList, otherwise returns false.
254        */             
255                bool isBuildEdgesEnabled(void) const { return mBuildEdgesEnabled; }
256                void setBuildEdgesEnabled(bool b);
257        /** Makes a copy of this submesh object and gives it a new name.
258         @param newName
259         The name to give the clone.
260         @param parentMesh
261         Optional mesh to make the parent of the newly created clone.
262         If you leave this blank, the clone will be parented to the same Mesh as the original.
263         */
264        SubMesh * clone(const String& newName, Mesh *parentMesh = 0);
265
266    protected:
267
268        /// Name of the material this SubMesh uses.
269        String mMaterialName;
270
271        /// Is there a material yet?
272        bool mMatInitialised;
273
274        /// paired list of texture aliases and texture names
275        AliasTextureNamePairList mTextureAliases;
276
277        VertexBoneAssignmentList mBoneAssignments;
278
279        /// Flag indicating that bone assignments need to be recompiled
280        bool mBoneAssignmentsOutOfDate;
281
282                /// Type of vertex animation for dedicated vertex data (populated by Mesh)
283                mutable VertexAnimationType mVertexAnimationType;
284
285                /// Whether normals are included in vertex animation keyframes
286                mutable bool mVertexAnimationIncludesNormals;
287
288                /// Is Build Edges Enabled
289                bool mBuildEdgesEnabled;
290
291        /// Internal method for removing LOD data
292        void removeLodLevels(void);
293
294
295    };
296        /** @} */
297        /** @} */
298
299} // namespace
300
301#include "OgreHeaderSuffix.h"
302
303#endif
304
305
Note: See TracBrowser for help on using the repository browser.