Coverage Report

Created: 2025-07-18 07:08

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