vrshoot

view libs/assimp/TextureTransform.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 Definition of a helper step that processes texture transformations */
42 #ifndef AI_TEXTURE_TRANSFORM_H_INCLUDED
43 #define AI_TEXTURE_TRANSFORM_H_INCLUDED
45 #include "BaseImporter.h"
46 #include "BaseProcess.h"
48 struct aiNode;
50 namespace Assimp {
52 #define AI_TT_UV_IDX_LOCK_TBD 0xffffffff
53 #define AI_TT_UV_IDX_LOCK_NONE 0xeeeeeeee
56 #define AI_TT_ROTATION_EPSILON ((float)AI_DEG_TO_RAD(0.5))
58 // ---------------------------------------------------------------------------
59 /** Small helper structure representing a shortcut into the material list
60 * to be able to update some values quickly.
61 */
62 struct TTUpdateInfo
63 {
64 TTUpdateInfo() :
65 directShortcut (NULL)
66 , mat (NULL)
67 , semantic (0)
68 , index (0)
69 {}
71 //! Direct shortcut, if available
72 unsigned int* directShortcut;
74 //! Material
75 aiMaterial *mat;
77 //! Texture type and index
78 unsigned int semantic, index;
79 };
82 // ---------------------------------------------------------------------------
83 /** Helper class representing texture coordinate transformations
84 */
85 struct STransformVecInfo : public aiUVTransform
86 {
88 STransformVecInfo()
89 : uvIndex (0)
90 , mapU (aiTextureMapMode_Wrap)
91 , mapV (aiTextureMapMode_Wrap)
92 , lockedPos (AI_TT_UV_IDX_LOCK_NONE)
93 {}
95 //! Source texture coordinate index
96 unsigned int uvIndex;
98 //! Texture mapping mode in the u, v direction
99 aiTextureMapMode mapU,mapV;
101 //! Locked destination UV index
102 //! AI_TT_UV_IDX_LOCK_TBD - to be determined
103 //! AI_TT_UV_IDX_LOCK_NONE - none (default)
104 unsigned int lockedPos;
106 //! Update info - shortcuts into all materials
107 //! that are referencing this transform setup
108 std::list<TTUpdateInfo> updateList;
111 // -------------------------------------------------------------------
112 /** Compare two transform setups
113 */
114 inline bool operator== (const STransformVecInfo& other) const
115 {
116 // We use a small epsilon here
117 const static float epsilon = 0.05f;
119 if (fabs( mTranslation.x - other.mTranslation.x ) > epsilon ||
120 fabs( mTranslation.y - other.mTranslation.y ) > epsilon)
121 {
122 return false;
123 }
125 if (fabs( mScaling.x - other.mScaling.x ) > epsilon ||
126 fabs( mScaling.y - other.mScaling.y ) > epsilon)
127 {
128 return false;
129 }
131 if (fabs( mRotation - other.mRotation) > epsilon)
132 {
133 return false;
134 }
135 return true;
136 }
138 inline bool operator!= (const STransformVecInfo& other) const
139 {
140 return !(*this == other);
141 }
144 // -------------------------------------------------------------------
145 /** Returns whether this is an untransformed texture coordinate set
146 */
147 inline bool IsUntransformed() const
148 {
149 return (1.0f == mScaling.x && 1.f == mScaling.y &&
150 !mTranslation.x && !mTranslation.y &&
151 mRotation < AI_TT_ROTATION_EPSILON);
152 }
154 // -------------------------------------------------------------------
155 /** Build a 3x3 matrix from the transformations
156 */
157 inline void GetMatrix(aiMatrix3x3& mOut)
158 {
159 mOut = aiMatrix3x3();
161 if (1.0f != mScaling.x || 1.0f != mScaling.y)
162 {
163 aiMatrix3x3 mScale;
164 mScale.a1 = mScaling.x;
165 mScale.b2 = mScaling.y;
166 mOut = mScale;
167 }
168 if (mRotation)
169 {
170 aiMatrix3x3 mRot;
171 mRot.a1 = mRot.b2 = cos(mRotation);
172 mRot.a2 = mRot.b1 = sin(mRotation);
173 mRot.a2 = -mRot.a2;
174 mOut *= mRot;
175 }
176 if (mTranslation.x || mTranslation.y)
177 {
178 aiMatrix3x3 mTrans;
179 mTrans.a3 = mTranslation.x;
180 mTrans.b3 = mTranslation.y;
181 mOut *= mTrans;
182 }
183 }
184 };
187 // ---------------------------------------------------------------------------
188 /** Helper step to compute final UV coordinate sets if there are scalings
189 * or rotations in the original data read from the file.
190 */
191 class TextureTransformStep : public BaseProcess
192 {
193 public:
195 TextureTransformStep();
196 ~TextureTransformStep();
198 public:
200 // -------------------------------------------------------------------
201 bool IsActive( unsigned int pFlags) const;
203 // -------------------------------------------------------------------
204 void Execute( aiScene* pScene);
206 // -------------------------------------------------------------------
207 void SetupProperties(const Importer* pImp);
210 protected:
213 // -------------------------------------------------------------------
214 /** Preprocess a specific UV transformation setup
215 *
216 * @param info Transformation setup to be preprocessed.
217 */
218 void PreProcessUVTransform(STransformVecInfo& info);
220 private:
222 unsigned int configFlags;
223 };
225 }
227 #endif //! AI_TEXTURE_TRANSFORM_H_INCLUDED