Coverage Report

Created: 2025-11-11 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/PostProcessing/DeboneProcess.h
Line
Count
Source
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2025, assimp team
6
7
All rights reserved.
8
9
Redistribution and use of this software in source and binary forms,
10
with or without modification, are permitted provided that the
11
following conditions are met:
12
13
* Redistributions of source code must retain the above
14
  copyright notice, this list of conditions and the
15
  following disclaimer.
16
17
* Redistributions in binary form must reproduce the above
18
  copyright notice, this list of conditions and the
19
  following disclaimer in the documentation and/or other
20
  materials provided with the distribution.
21
22
* Neither the name of the assimp team, nor the names of its
23
  contributors may be used to endorse or promote products
24
  derived from this software without specific prior
25
  written permission of the assimp team.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39
----------------------------------------------------------------------
40
*/
41
42
/** Defines a post processing step to limit the number of bones affecting a single vertex. */
43
#ifndef AI_DEBONEPROCESS_H_INC
44
#define AI_DEBONEPROCESS_H_INC
45
46
#include "Common/BaseProcess.h"
47
48
#include <assimp/mesh.h>
49
#include <assimp/scene.h>
50
51
#include <vector>
52
#include <utility>
53
54
#// Forward declarations
55
class DeboneTest;
56
57
namespace Assimp {
58
59
#if (!defined AI_DEBONE_THRESHOLD)
60
#   define AI_DEBONE_THRESHOLD  1.0f
61
#endif // !! AI_DEBONE_THRESHOLD
62
63
// ---------------------------------------------------------------------------
64
/** This post processing step removes bones nearly losslessly or according to
65
* a configured threshold. In order to remove the bone, the primitives affected by
66
* the bone are split from the mesh. The split off (new) mesh is boneless. At any
67
* point in time, bones without affect upon a given mesh are to be removed.
68
*/
69
class DeboneProcess final : public BaseProcess {
70
public:
71
    DeboneProcess();
72
1.12k
    ~DeboneProcess() override = default;
73
74
    // -------------------------------------------------------------------
75
    /** Returns whether the processing step is present in the given flag.
76
    * @param pFlags The processing flags the importer was called with.
77
    *   A bitwise combination of #aiPostProcessSteps.
78
    * @return true if the process is present in this flag fields,
79
    *   false if not.
80
    */
81
    bool IsActive( unsigned int pFlags) const override;
82
83
    // -------------------------------------------------------------------
84
    /** Called prior to ExecuteOnScene().
85
    * The function is a request to the process to update its configuration
86
    * basing on the Importer's configuration property list.
87
    */
88
    void SetupProperties(const Importer* pImp) override;
89
90
protected:
91
    // -------------------------------------------------------------------
92
    /** Executes the post processing step on the given imported data.
93
    * At the moment a process is not supposed to fail.
94
    * @param pScene The imported data to work at.
95
    */
96
    void Execute( aiScene* pScene) override;
97
98
    // -------------------------------------------------------------------
99
    /** Counts bones total/removable in a given mesh.
100
    * @param pMesh The mesh to process.
101
    */
102
    bool ConsiderMesh( const aiMesh* pMesh);
103
104
    /// Splits the given mesh by bone count.
105
    /// @param pMesh the Mesh to split. Is not changed at all, but might be superfluous in case it was split.
106
    /// @param poNewMeshes Array of submeshes created in the process. Empty if splitting was not necessary.
107
    void SplitMesh(const aiMesh* pMesh, std::vector< std::pair< aiMesh*,const aiBone* > >& poNewMeshes) const;
108
109
    /// Recursively updates the node's mesh list to account for the changed mesh list
110
    void UpdateNode(aiNode* pNode) const;
111
112
    // -------------------------------------------------------------------
113
    // Apply transformation to a mesh
114
    void ApplyTransform(aiMesh* mesh, const aiMatrix4x4& mat)const;
115
116
public:
117
    /** Number of bones present in the scene. */
118
    unsigned int mNumBones;
119
    unsigned int mNumBonesCanDoWithout;
120
121
    float mThreshold;
122
    bool mAllOrNone;
123
124
    /// Per mesh index: Array of indices of the new submeshes.
125
    std::vector< std::vector< std::pair< unsigned int,aiNode* > > > mSubMeshIndices;
126
};
127
128
} // end of namespace Assimp
129
130
#endif // AI_DEBONEPROCESS_H_INC