/src/assimp/code/PostProcessing/DropFaceNormalsProcess.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | --------------------------------------------------------------------------- |
3 | | Open Asset Import Library (assimp) |
4 | | --------------------------------------------------------------------------- |
5 | | |
6 | | Copyright (c) 2006-2025, assimp team |
7 | | |
8 | | |
9 | | |
10 | | All rights reserved. |
11 | | |
12 | | Redistribution and use of this software in source and binary forms, |
13 | | with or without modification, are permitted provided that the following |
14 | | conditions are met: |
15 | | |
16 | | * Redistributions of source code must retain the above |
17 | | copyright notice, this list of conditions and the |
18 | | following disclaimer. |
19 | | |
20 | | * Redistributions in binary form must reproduce the above |
21 | | copyright notice, this list of conditions and the |
22 | | following disclaimer in the documentation and/or other |
23 | | materials provided with the distribution. |
24 | | |
25 | | * Neither the name of the assimp team, nor the names of its |
26 | | contributors may be used to endorse or promote products |
27 | | derived from this software without specific prior |
28 | | written permission of the assimp team. |
29 | | |
30 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
31 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
32 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
33 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
34 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
35 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
36 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
37 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
38 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
39 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
40 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
41 | | --------------------------------------------------------------------------- |
42 | | */ |
43 | | |
44 | | /** @file Implementation of the post processing step to drop face |
45 | | * normals for all imported faces. |
46 | | */ |
47 | | |
48 | | #include "DropFaceNormalsProcess.h" |
49 | | #include <assimp/Exceptional.h> |
50 | | #include <assimp/postprocess.h> |
51 | | #include <assimp/scene.h> |
52 | | #include <assimp/DefaultLogger.hpp> |
53 | | |
54 | | using namespace Assimp; |
55 | | |
56 | | // ------------------------------------------------------------------------------------------------ |
57 | | // Returns whether the processing step is present in the given flag field. |
58 | 96 | bool DropFaceNormalsProcess::IsActive(unsigned int pFlags) const { |
59 | 96 | return (pFlags & aiProcess_DropNormals) != 0; |
60 | 96 | } |
61 | | |
62 | | // ------------------------------------------------------------------------------------------------ |
63 | | // Executes the post processing step on the given imported data. |
64 | 0 | void DropFaceNormalsProcess::Execute(aiScene *pScene) { |
65 | 0 | ASSIMP_LOG_DEBUG("DropFaceNormalsProcess begin"); |
66 | |
|
67 | 0 | if (pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) { |
68 | 0 | throw DeadlyImportError("Post-processing order mismatch: expecting pseudo-indexed (\"verbose\") vertices here"); |
69 | 0 | } |
70 | | |
71 | 0 | bool bHas = false; |
72 | 0 | for (unsigned int a = 0; a < pScene->mNumMeshes; a++) { |
73 | 0 | bHas |= this->DropMeshFaceNormals(pScene->mMeshes[a]); |
74 | 0 | } |
75 | 0 | if (bHas) { |
76 | 0 | ASSIMP_LOG_INFO("DropFaceNormalsProcess finished. " |
77 | 0 | "Face normals have been removed"); |
78 | 0 | } else { |
79 | 0 | ASSIMP_LOG_DEBUG("DropFaceNormalsProcess finished. " |
80 | 0 | "No normals were present"); |
81 | 0 | } |
82 | 0 | } |
83 | | |
84 | | // ------------------------------------------------------------------------------------------------ |
85 | | // Executes the post processing step on the given imported data. |
86 | 0 | bool DropFaceNormalsProcess::DropMeshFaceNormals(aiMesh *mesh) { |
87 | 0 | ai_assert(nullptr != mesh); |
88 | |
|
89 | 0 | if (nullptr == mesh->mNormals) { |
90 | 0 | return false; |
91 | 0 | } |
92 | | |
93 | 0 | delete[] mesh->mNormals; |
94 | 0 | mesh->mNormals = nullptr; |
95 | 0 | return true; |
96 | 0 | } |