/src/assimp/code/PostProcessing/FindInstancesProcess.h
Line | Count | Source (jump to first uncovered line) |
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 | | /** @file FindInstancesProcess.h |
43 | | * @brief Declares the aiProcess_FindInstances post-process step |
44 | | */ |
45 | | #ifndef AI_FINDINSTANCES_H_INC |
46 | | #define AI_FINDINSTANCES_H_INC |
47 | | |
48 | | #include "Common/BaseProcess.h" |
49 | | #include "PostProcessing/ProcessHelper.h" |
50 | | |
51 | | class FindInstancesProcessTest; |
52 | | |
53 | | namespace Assimp { |
54 | | |
55 | | // ------------------------------------------------------------------------------- |
56 | | /** @brief Get a pseudo(!)-hash representing a mesh. |
57 | | * |
58 | | * The hash is built from number of vertices, faces, primitive types, |
59 | | * .... but *not* from the real mesh data. The funcction is not a perfect hash. |
60 | | * @param in Input mesh |
61 | | * @return Hash. |
62 | | */ |
63 | 0 | inline uint64_t GetMeshHash(aiMesh* in) { |
64 | 0 | ai_assert(nullptr != in); |
65 | | |
66 | | // ... get an unique value representing the vertex format of the mesh |
67 | 0 | const unsigned int fhash = GetMeshVFormatUnique(in); |
68 | | |
69 | | // and bake it with number of vertices/faces/bones/matidx/ptypes |
70 | 0 | return ((uint64_t)fhash << 32u) | (( |
71 | 0 | (in->mNumBones << 16u) ^ (in->mNumVertices) ^ |
72 | 0 | (in->mNumFaces<<4u) ^ (in->mMaterialIndex<<15) ^ |
73 | 0 | (in->mPrimitiveTypes<<28)) & 0xffffffff ); |
74 | 0 | } |
75 | | |
76 | | // ------------------------------------------------------------------------------- |
77 | | /** @brief Perform a component-wise comparison of two arrays |
78 | | * |
79 | | * @param first First array |
80 | | * @param second Second array |
81 | | * @param size Size of both arrays |
82 | | * @param e Epsilon |
83 | | * @return true if the arrays are identical |
84 | | */ |
85 | | inline bool CompareArrays(const aiVector3D* first, const aiVector3D* second, |
86 | 0 | unsigned int size, float e) { |
87 | 0 | for (const aiVector3D* end = first+size; first != end; ++first,++second) { |
88 | 0 | if ( (*first - *second).SquareLength() >= e) |
89 | 0 | return false; |
90 | 0 | } |
91 | 0 | return true; |
92 | 0 | } |
93 | | |
94 | | // and the same for colors ... |
95 | | inline bool CompareArrays(const aiColor4D* first, const aiColor4D* second, |
96 | | unsigned int size, float e) |
97 | 0 | { |
98 | 0 | for (const aiColor4D* end = first+size; first != end; ++first,++second) { |
99 | 0 | if ( GetColorDifference(*first,*second) >= e) |
100 | 0 | return false; |
101 | 0 | } |
102 | 0 | return true; |
103 | 0 | } |
104 | | |
105 | | // --------------------------------------------------------------------------- |
106 | | /** @brief A post-processing steps to search for instanced meshes |
107 | | */ |
108 | | class FindInstancesProcess : public BaseProcess { |
109 | | public: |
110 | | FindInstancesProcess(); |
111 | | ~FindInstancesProcess() override = default; |
112 | | |
113 | | // ------------------------------------------------------------------- |
114 | | // Check whether step is active in given flags combination |
115 | | bool IsActive( unsigned int pFlags) const override; |
116 | | |
117 | | // ------------------------------------------------------------------- |
118 | | // Execute step on a given scene |
119 | | void Execute( aiScene* pScene) override; |
120 | | |
121 | | // ------------------------------------------------------------------- |
122 | | // Setup properties prior to executing the process |
123 | | void SetupProperties(const Importer* pImp) override; |
124 | | |
125 | | private: |
126 | | bool configSpeedFlag; |
127 | | }; // ! end class FindInstancesProcess |
128 | | |
129 | | } // ! end namespace Assimp |
130 | | |
131 | | #endif // !! AI_FINDINSTANCES_H_INC |