vrshoot

view libs/assimp/FindInstancesProcess.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 /** @file FindInstancesProcess.h
42 * @brief Declares the aiProcess_FindInstances post-process step
43 */
44 #ifndef AI_FINDINSTANCES_H_INC
45 #define AI_FINDINSTANCES_H_INC
47 #include "BaseProcess.h"
48 #include "ProcessHelper.h"
50 class FindInstancesProcessTest;
51 namespace Assimp {
53 // -------------------------------------------------------------------------------
54 /** @brief Get a pseudo(!)-hash representing a mesh.
55 *
56 * The hash is built from number of vertices, faces, primitive types,
57 * .... but *not* from the real mesh data. The funcction is not a perfect hash.
58 * @param in Input mesh
59 * @return Hash.
60 */
61 inline uint64_t GetMeshHash(aiMesh* in)
62 {
63 ai_assert(NULL != in);
65 // ... get an unique value representing the vertex format of the mesh
66 const unsigned int fhash = GetMeshVFormatUnique(in);
68 // and bake it with number of vertices/faces/bones/matidx/ptypes
69 return ((uint64_t)fhash << 32u) | ((
70 (in->mNumBones << 16u) ^ (in->mNumVertices) ^
71 (in->mNumFaces<<4u) ^ (in->mMaterialIndex<<15) ^
72 (in->mPrimitiveTypes<<28)) & 0xffffffff );
73 }
75 // -------------------------------------------------------------------------------
76 /** @brief Perform a component-wise comparison of two arrays
77 *
78 * @param first First array
79 * @param second Second aray
80 * @param size Size of both arrays
81 * @param e Epsilon
82 * @return true if the arrays are identical
83 */
84 inline bool CompareArrays(const aiVector3D* first, const aiVector3D* second,
85 unsigned int size, float e)
86 {
87 for (const aiVector3D* end = first+size; first != end; ++first,++second) {
88 if ( (*first - *second).SquareLength() >= e)
89 return false;
90 }
91 return true;
92 }
94 // and the same for colors ...
95 inline bool CompareArrays(const aiColor4D* first, const aiColor4D* second,
96 unsigned int size, float e)
97 {
98 for (const aiColor4D* end = first+size; first != end; ++first,++second) {
99 if ( GetColorDifference(*first,*second) >= e)
100 return false;
101 }
102 return true;
103 }
105 // ---------------------------------------------------------------------------
106 /** @brief A post-processing steps to search for instanced meshes
107 */
108 class FindInstancesProcess : public BaseProcess
109 {
110 public:
112 FindInstancesProcess();
113 ~FindInstancesProcess();
115 public:
116 // -------------------------------------------------------------------
117 // Check whether step is active in given flags combination
118 bool IsActive( unsigned int pFlags) const;
120 // -------------------------------------------------------------------
121 // Execute step on a given scene
122 void Execute( aiScene* pScene);
124 // -------------------------------------------------------------------
125 // Setup properties prior to executing the process
126 void SetupProperties(const Importer* pImp);
128 private:
130 bool configSpeedFlag;
132 }; // ! end class FindInstancesProcess
133 } // ! end namespace Assimp
135 #endif // !! AI_FINDINSTANCES_H_INC