Coverage Report

Created: 2026-10-28 07:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/PostProcessing/RemoveVCProcess.cpp
Line
Count
Source
1
/*
2
---------------------------------------------------------------------------
3
Open Asset Import Library (assimp)
4
---------------------------------------------------------------------------
5
6
Copyright (c) 2006-2026, assimp team
7
8
All rights reserved.
9
10
Redistribution and use of this software in source and binary forms,
11
with or without modification, are permitted provided that the following
12
conditions are met:
13
14
* Redistributions of source code must retain the above
15
  copyright notice, this list of conditions and the
16
  following disclaimer.
17
18
* Redistributions in binary form must reproduce the above
19
  copyright notice, this list of conditions and the
20
  following disclaimer in the documentation and/or other
21
  materials provided with the distribution.
22
23
* Neither the name of the assimp team, nor the names of its
24
  contributors may be used to endorse or promote products
25
  derived from this software without specific prior
26
  written permission of the assimp team.
27
28
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
---------------------------------------------------------------------------
40
*/
41
/** @file Implementation of the post processing step to remove
42
 *        any parts of the mesh structure from the imported data.
43
*/
44
45
#include "RemoveVCProcess.h"
46
#include <assimp/postprocess.h>
47
#include <assimp/scene.h>
48
#include <assimp/DefaultLogger.hpp>
49
50
using namespace Assimp;
51
52
// ------------------------------------------------------------------------------------------------
53
// Constructor to be privately used by Importer
54
RemoveVCProcess::RemoveVCProcess() :
55
132k
        configDeleteFlags(), mScene() {}
56
57
// ------------------------------------------------------------------------------------------------
58
// Returns whether the processing step is present in the given flag field.
59
82.1k
bool RemoveVCProcess::IsActive(unsigned int pFlags) const {
60
82.1k
    return (pFlags & aiProcess_RemoveComponent) != 0;
61
82.1k
}
62
63
// ------------------------------------------------------------------------------------------------
64
// Small helper function to delete all elements in a T** array using delete
65
template <typename T>
66
1.54k
inline void ArrayDelete(T **&in, unsigned int &num) {
67
4.51k
    for (unsigned int i = 0; i < num; ++i)
68
2.97k
        delete in[i];
69
70
1.54k
    delete[] in;
71
1.54k
    in = nullptr;
72
1.54k
    num = 0;
73
1.54k
}
void ArrayDelete<aiAnimation>(aiAnimation**&, unsigned int&)
Line
Count
Source
66
638
inline void ArrayDelete(T **&in, unsigned int &num) {
67
718
    for (unsigned int i = 0; i < num; ++i)
68
80
        delete in[i];
69
70
638
    delete[] in;
71
638
    in = nullptr;
72
638
    num = 0;
73
638
}
void ArrayDelete<aiTexture>(aiTexture**&, unsigned int&)
Line
Count
Source
66
577
inline void ArrayDelete(T **&in, unsigned int &num) {
67
679
    for (unsigned int i = 0; i < num; ++i)
68
102
        delete in[i];
69
70
577
    delete[] in;
71
577
    in = nullptr;
72
577
    num = 0;
73
577
}
void ArrayDelete<aiLight>(aiLight**&, unsigned int&)
Line
Count
Source
66
125
inline void ArrayDelete(T **&in, unsigned int &num) {
67
282
    for (unsigned int i = 0; i < num; ++i)
68
157
        delete in[i];
69
70
125
    delete[] in;
71
125
    in = nullptr;
72
125
    num = 0;
73
125
}
Unexecuted instantiation: void ArrayDelete<aiCamera>(aiCamera**&, unsigned int&)
Unexecuted instantiation: void ArrayDelete<aiMesh>(aiMesh**&, unsigned int&)
void ArrayDelete<aiBone>(aiBone**&, unsigned int&)
Line
Count
Source
66
200
inline void ArrayDelete(T **&in, unsigned int &num) {
67
2.83k
    for (unsigned int i = 0; i < num; ++i)
68
2.63k
        delete in[i];
69
70
200
    delete[] in;
71
200
    in = nullptr;
72
200
    num = 0;
73
200
}
74
75
// ------------------------------------------------------------------------------------------------
76
// Executes the post processing step on the given imported data.
77
2.06k
void RemoveVCProcess::Execute(aiScene *pScene) {
78
2.06k
    ASSIMP_LOG_DEBUG("RemoveVCProcess begin");
79
2.06k
    bool bHas = false; //,bMasked = false;
80
81
2.06k
    mScene = pScene;
82
83
    // handle animations
84
2.06k
    if (configDeleteFlags & aiComponent_ANIMATIONS) {
85
86
638
        bHas = true;
87
638
        ArrayDelete(pScene->mAnimations, pScene->mNumAnimations);
88
638
    }
89
90
    // handle textures
91
2.06k
    if (configDeleteFlags & aiComponent_TEXTURES) {
92
577
        bHas = true;
93
577
        ArrayDelete(pScene->mTextures, pScene->mNumTextures);
94
577
    }
95
96
    // handle materials
97
2.06k
    if (configDeleteFlags & aiComponent_MATERIALS && pScene->mNumMaterials) {
98
0
        bHas = true;
99
0
        for (unsigned int i = 1; i < pScene->mNumMaterials; ++i)
100
0
            delete pScene->mMaterials[i];
101
102
0
        pScene->mNumMaterials = 1;
103
0
        aiMaterial *helper = (aiMaterial *)pScene->mMaterials[0];
104
0
        ai_assert(nullptr != helper);
105
0
        helper->Clear();
106
107
        // gray
108
0
        aiColor3D clr(0.6f, 0.6f, 0.6f);
109
0
        helper->AddProperty(&clr, 1, AI_MATKEY_COLOR_DIFFUSE);
110
111
        // add a small ambient color value
112
0
        clr = aiColor3D(0.05f, 0.05f, 0.05f);
113
0
        helper->AddProperty(&clr, 1, AI_MATKEY_COLOR_AMBIENT);
114
115
0
        aiString s;
116
0
        s.Set("Dummy_MaterialsRemoved");
117
0
        helper->AddProperty(&s, AI_MATKEY_NAME);
118
0
    }
119
120
    // handle light sources
121
2.06k
    if (configDeleteFlags & aiComponent_LIGHTS) {
122
125
        bHas = true;
123
125
        ArrayDelete(pScene->mLights, pScene->mNumLights);
124
125
    }
125
126
    // handle camneras
127
2.06k
    if (configDeleteFlags & aiComponent_CAMERAS) {
128
0
        bHas = true;
129
0
        ArrayDelete(pScene->mCameras, pScene->mNumCameras);
130
0
    }
131
132
    // handle meshes
133
2.06k
    if (configDeleteFlags & aiComponent_MESHES) {
134
0
        bHas = true;
135
0
        ArrayDelete(pScene->mMeshes, pScene->mNumMeshes);
136
2.06k
    } else {
137
13.9k
        for (unsigned int a = 0; a < pScene->mNumMeshes; a++) {
138
11.9k
            if (ProcessMesh(pScene->mMeshes[a]))
139
3.77k
                bHas = true;
140
11.9k
        }
141
2.06k
    }
142
143
    // now check whether the result is still a full scene
144
2.06k
    if (!pScene->mNumMeshes || !pScene->mNumMaterials) {
145
472
        pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
146
472
        ASSIMP_LOG_DEBUG("Setting AI_SCENE_FLAGS_INCOMPLETE flag");
147
148
        // If we have no meshes anymore we should also clear another flag ...
149
472
        if (!pScene->mNumMeshes)
150
472
            pScene->mFlags &= ~AI_SCENE_FLAGS_NON_VERBOSE_FORMAT;
151
472
    }
152
153
2.06k
    if (bHas) {
154
1.29k
        ASSIMP_LOG_INFO("RemoveVCProcess finished. Data structure cleanup has been done.");
155
1.29k
    } else {
156
775
        ASSIMP_LOG_DEBUG("RemoveVCProcess finished. Nothing to be done ...");
157
775
    }
158
2.06k
}
159
160
// ------------------------------------------------------------------------------------------------
161
// Setup configuration properties for the step
162
2.06k
void RemoveVCProcess::SetupProperties(const Importer *pImp) {
163
2.06k
    configDeleteFlags = pImp->GetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS, 0x0);
164
2.06k
    if (!configDeleteFlags) {
165
453
        ASSIMP_LOG_WARN("RemoveVCProcess: AI_CONFIG_PP_RVC_FLAGS is zero.");
166
453
    }
167
2.06k
}
168
169
// ------------------------------------------------------------------------------------------------
170
// Executes the post processing step on the given imported data.
171
11.9k
bool RemoveVCProcess::ProcessMesh(aiMesh *pMesh) {
172
11.9k
    bool ret = false;
173
174
    // if all materials have been deleted let the material
175
    // index of the mesh point to the created default material
176
11.9k
    if (configDeleteFlags & aiComponent_MATERIALS)
177
0
        pMesh->mMaterialIndex = 0;
178
179
    // handle normals
180
11.9k
    if (configDeleteFlags & aiComponent_NORMALS && pMesh->mNormals) {
181
1.23k
        delete[] pMesh->mNormals;
182
1.23k
        pMesh->mNormals = nullptr;
183
1.23k
        ret = true;
184
1.23k
    }
185
186
    // handle tangents and bitangents
187
11.9k
    if (configDeleteFlags & aiComponent_TANGENTS_AND_BITANGENTS && pMesh->mTangents) {
188
2
        delete[] pMesh->mTangents;
189
2
        pMesh->mTangents = nullptr;
190
191
2
        delete[] pMesh->mBitangents;
192
2
        pMesh->mBitangents = nullptr;
193
2
        ret = true;
194
2
    }
195
196
    // handle texture coordinates
197
11.9k
    bool b = (0 != (configDeleteFlags & aiComponent_TEXCOORDS));
198
15.3k
    for (unsigned int i = 0, real = 0; real < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++real) {
199
15.3k
        if (!pMesh->mTextureCoords[i]) break;
200
3.44k
        if (configDeleteFlags & aiComponent_TEXCOORDSn(real) || b) {
201
2.56k
            delete[] pMesh->mTextureCoords[i];
202
2.56k
            pMesh->mTextureCoords[i] = nullptr;
203
2.56k
            ret = true;
204
205
2.56k
            if (!b) {
206
                // collapse the rest of the array
207
0
                for (unsigned int a = i + 1; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a)
208
0
                    pMesh->mTextureCoords[a - 1] = pMesh->mTextureCoords[a];
209
210
0
                pMesh->mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS - 1] = nullptr;
211
0
                continue;
212
0
            }
213
2.56k
        }
214
3.44k
        ++i;
215
3.44k
    }
216
217
    // handle vertex colors
218
11.9k
    b = (0 != (configDeleteFlags & aiComponent_COLORS));
219
14.6k
    for (unsigned int i = 0, real = 0; real < AI_MAX_NUMBER_OF_COLOR_SETS; ++real) {
220
14.6k
        if (!pMesh->mColors[i]) break;
221
2.72k
        if (configDeleteFlags & aiComponent_COLORSn(i) || b) {
222
868
            delete[] pMesh->mColors[i];
223
868
            pMesh->mColors[i] = nullptr;
224
868
            ret = true;
225
226
868
            if (!b) {
227
                // collapse the rest of the array
228
0
                for (unsigned int a = i + 1; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a)
229
0
                    pMesh->mColors[a - 1] = pMesh->mColors[a];
230
231
0
                pMesh->mColors[AI_MAX_NUMBER_OF_COLOR_SETS - 1] = nullptr;
232
0
                continue;
233
0
            }
234
868
        }
235
2.72k
        ++i;
236
2.72k
    }
237
238
    // handle bones
239
11.9k
    if (configDeleteFlags & aiComponent_BONEWEIGHTS && pMesh->mBones) {
240
200
        ArrayDelete(pMesh->mBones, pMesh->mNumBones);
241
200
        ret = true;
242
200
    }
243
11.9k
    return ret;
244
11.9k
}