1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2017, assimp team
6
7All rights reserved.
8
9Redistribution and use of this software in source and binary forms,
10with or without modification, are permitted provided that the
11following 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
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37OF 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 "BaseProcess.h"
49#include "ProcessHelper.h"
50
51class FindInstancesProcessTest;
52namespace Assimp {
53
54// -------------------------------------------------------------------------------
55/** @brief Get a pseudo(!)-hash representing a mesh.
56 *
57 * The hash is built from number of vertices, faces, primitive types,
58 * .... but *not* from the real mesh data. The funcction is not a perfect hash.
59 * @param in Input mesh
60 * @return Hash.
61 */
62inline uint64_t GetMeshHash(aiMesh* in)
63{
64 ai_assert(NULL != in);
65
66 // ... get an unique value representing the vertex format of the mesh
67 const unsigned int fhash = GetMeshVFormatUnique(in);
68
69 // and bake it with number of vertices/faces/bones/matidx/ptypes
70 return ((uint64_t)fhash << 32u) | ((
71 (in->mNumBones << 16u) ^ (in->mNumVertices) ^
72 (in->mNumFaces<<4u) ^ (in->mMaterialIndex<<15) ^
73 (in->mPrimitiveTypes<<28)) & 0xffffffff );
74}
75
76// -------------------------------------------------------------------------------
77/** @brief Perform a component-wise comparison of two arrays
78 *
79 * @param first First array
80 * @param second Second aray
81 * @param size Size of both arrays
82 * @param e Epsilon
83 * @return true if the arrays are identical
84 */
85inline bool CompareArrays(const aiVector3D* first, const aiVector3D* second,
86 unsigned int size, float e)
87{
88 for (const aiVector3D* end = first+size; first != end; ++first,++second) {
89 if ( (*first - *second).SquareLength() >= e)
90 return false;
91 }
92 return true;
93}
94
95// and the same for colors ...
96inline bool CompareArrays(const aiColor4D* first, const aiColor4D* second,
97 unsigned int size, float e)
98{
99 for (const aiColor4D* end = first+size; first != end; ++first,++second) {
100 if ( GetColorDifference(*first,*second) >= e)
101 return false;
102 }
103 return true;
104}
105
106// ---------------------------------------------------------------------------
107/** @brief A post-processing steps to search for instanced meshes
108*/
109class FindInstancesProcess : public BaseProcess
110{
111public:
112
113 FindInstancesProcess();
114 ~FindInstancesProcess();
115
116public:
117 // -------------------------------------------------------------------
118 // Check whether step is active in given flags combination
119 bool IsActive( unsigned int pFlags) const;
120
121 // -------------------------------------------------------------------
122 // Execute step on a given scene
123 void Execute( aiScene* pScene);
124
125 // -------------------------------------------------------------------
126 // Setup properties prior to executing the process
127 void SetupProperties(const Importer* pImp);
128
129private:
130
131 bool configSpeedFlag;
132
133}; // ! end class FindInstancesProcess
134} // ! end namespace Assimp
135
136#endif // !! AI_FINDINSTANCES_H_INC
137