vrshoot

annotate 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
rev   line source
nuclear@0 1 /*
nuclear@0 2 Open Asset Import Library (assimp)
nuclear@0 3 ----------------------------------------------------------------------
nuclear@0 4
nuclear@0 5 Copyright (c) 2006-2012, assimp team
nuclear@0 6 All rights reserved.
nuclear@0 7
nuclear@0 8 Redistribution and use of this software in source and binary forms,
nuclear@0 9 with or without modification, are permitted provided that the
nuclear@0 10 following conditions are met:
nuclear@0 11
nuclear@0 12 * Redistributions of source code must retain the above
nuclear@0 13 copyright notice, this list of conditions and the
nuclear@0 14 following disclaimer.
nuclear@0 15
nuclear@0 16 * Redistributions in binary form must reproduce the above
nuclear@0 17 copyright notice, this list of conditions and the
nuclear@0 18 following disclaimer in the documentation and/or other
nuclear@0 19 materials provided with the distribution.
nuclear@0 20
nuclear@0 21 * Neither the name of the assimp team, nor the names of its
nuclear@0 22 contributors may be used to endorse or promote products
nuclear@0 23 derived from this software without specific prior
nuclear@0 24 written permission of the assimp team.
nuclear@0 25
nuclear@0 26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
nuclear@0 27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
nuclear@0 28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
nuclear@0 29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
nuclear@0 30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
nuclear@0 31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
nuclear@0 32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
nuclear@0 33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nuclear@0 34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
nuclear@0 35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nuclear@0 36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nuclear@0 37
nuclear@0 38 ----------------------------------------------------------------------
nuclear@0 39 */
nuclear@0 40
nuclear@0 41 /** @file Definition of a helper step that processes texture transformations */
nuclear@0 42 #ifndef AI_TEXTURE_TRANSFORM_H_INCLUDED
nuclear@0 43 #define AI_TEXTURE_TRANSFORM_H_INCLUDED
nuclear@0 44
nuclear@0 45 #include "BaseImporter.h"
nuclear@0 46 #include "BaseProcess.h"
nuclear@0 47
nuclear@0 48 struct aiNode;
nuclear@0 49
nuclear@0 50 namespace Assimp {
nuclear@0 51
nuclear@0 52 #define AI_TT_UV_IDX_LOCK_TBD 0xffffffff
nuclear@0 53 #define AI_TT_UV_IDX_LOCK_NONE 0xeeeeeeee
nuclear@0 54
nuclear@0 55
nuclear@0 56 #define AI_TT_ROTATION_EPSILON ((float)AI_DEG_TO_RAD(0.5))
nuclear@0 57
nuclear@0 58 // ---------------------------------------------------------------------------
nuclear@0 59 /** Small helper structure representing a shortcut into the material list
nuclear@0 60 * to be able to update some values quickly.
nuclear@0 61 */
nuclear@0 62 struct TTUpdateInfo
nuclear@0 63 {
nuclear@0 64 TTUpdateInfo() :
nuclear@0 65 directShortcut (NULL)
nuclear@0 66 , mat (NULL)
nuclear@0 67 , semantic (0)
nuclear@0 68 , index (0)
nuclear@0 69 {}
nuclear@0 70
nuclear@0 71 //! Direct shortcut, if available
nuclear@0 72 unsigned int* directShortcut;
nuclear@0 73
nuclear@0 74 //! Material
nuclear@0 75 aiMaterial *mat;
nuclear@0 76
nuclear@0 77 //! Texture type and index
nuclear@0 78 unsigned int semantic, index;
nuclear@0 79 };
nuclear@0 80
nuclear@0 81
nuclear@0 82 // ---------------------------------------------------------------------------
nuclear@0 83 /** Helper class representing texture coordinate transformations
nuclear@0 84 */
nuclear@0 85 struct STransformVecInfo : public aiUVTransform
nuclear@0 86 {
nuclear@0 87
nuclear@0 88 STransformVecInfo()
nuclear@0 89 : uvIndex (0)
nuclear@0 90 , mapU (aiTextureMapMode_Wrap)
nuclear@0 91 , mapV (aiTextureMapMode_Wrap)
nuclear@0 92 , lockedPos (AI_TT_UV_IDX_LOCK_NONE)
nuclear@0 93 {}
nuclear@0 94
nuclear@0 95 //! Source texture coordinate index
nuclear@0 96 unsigned int uvIndex;
nuclear@0 97
nuclear@0 98 //! Texture mapping mode in the u, v direction
nuclear@0 99 aiTextureMapMode mapU,mapV;
nuclear@0 100
nuclear@0 101 //! Locked destination UV index
nuclear@0 102 //! AI_TT_UV_IDX_LOCK_TBD - to be determined
nuclear@0 103 //! AI_TT_UV_IDX_LOCK_NONE - none (default)
nuclear@0 104 unsigned int lockedPos;
nuclear@0 105
nuclear@0 106 //! Update info - shortcuts into all materials
nuclear@0 107 //! that are referencing this transform setup
nuclear@0 108 std::list<TTUpdateInfo> updateList;
nuclear@0 109
nuclear@0 110
nuclear@0 111 // -------------------------------------------------------------------
nuclear@0 112 /** Compare two transform setups
nuclear@0 113 */
nuclear@0 114 inline bool operator== (const STransformVecInfo& other) const
nuclear@0 115 {
nuclear@0 116 // We use a small epsilon here
nuclear@0 117 const static float epsilon = 0.05f;
nuclear@0 118
nuclear@0 119 if (fabs( mTranslation.x - other.mTranslation.x ) > epsilon ||
nuclear@0 120 fabs( mTranslation.y - other.mTranslation.y ) > epsilon)
nuclear@0 121 {
nuclear@0 122 return false;
nuclear@0 123 }
nuclear@0 124
nuclear@0 125 if (fabs( mScaling.x - other.mScaling.x ) > epsilon ||
nuclear@0 126 fabs( mScaling.y - other.mScaling.y ) > epsilon)
nuclear@0 127 {
nuclear@0 128 return false;
nuclear@0 129 }
nuclear@0 130
nuclear@0 131 if (fabs( mRotation - other.mRotation) > epsilon)
nuclear@0 132 {
nuclear@0 133 return false;
nuclear@0 134 }
nuclear@0 135 return true;
nuclear@0 136 }
nuclear@0 137
nuclear@0 138 inline bool operator!= (const STransformVecInfo& other) const
nuclear@0 139 {
nuclear@0 140 return !(*this == other);
nuclear@0 141 }
nuclear@0 142
nuclear@0 143
nuclear@0 144 // -------------------------------------------------------------------
nuclear@0 145 /** Returns whether this is an untransformed texture coordinate set
nuclear@0 146 */
nuclear@0 147 inline bool IsUntransformed() const
nuclear@0 148 {
nuclear@0 149 return (1.0f == mScaling.x && 1.f == mScaling.y &&
nuclear@0 150 !mTranslation.x && !mTranslation.y &&
nuclear@0 151 mRotation < AI_TT_ROTATION_EPSILON);
nuclear@0 152 }
nuclear@0 153
nuclear@0 154 // -------------------------------------------------------------------
nuclear@0 155 /** Build a 3x3 matrix from the transformations
nuclear@0 156 */
nuclear@0 157 inline void GetMatrix(aiMatrix3x3& mOut)
nuclear@0 158 {
nuclear@0 159 mOut = aiMatrix3x3();
nuclear@0 160
nuclear@0 161 if (1.0f != mScaling.x || 1.0f != mScaling.y)
nuclear@0 162 {
nuclear@0 163 aiMatrix3x3 mScale;
nuclear@0 164 mScale.a1 = mScaling.x;
nuclear@0 165 mScale.b2 = mScaling.y;
nuclear@0 166 mOut = mScale;
nuclear@0 167 }
nuclear@0 168 if (mRotation)
nuclear@0 169 {
nuclear@0 170 aiMatrix3x3 mRot;
nuclear@0 171 mRot.a1 = mRot.b2 = cos(mRotation);
nuclear@0 172 mRot.a2 = mRot.b1 = sin(mRotation);
nuclear@0 173 mRot.a2 = -mRot.a2;
nuclear@0 174 mOut *= mRot;
nuclear@0 175 }
nuclear@0 176 if (mTranslation.x || mTranslation.y)
nuclear@0 177 {
nuclear@0 178 aiMatrix3x3 mTrans;
nuclear@0 179 mTrans.a3 = mTranslation.x;
nuclear@0 180 mTrans.b3 = mTranslation.y;
nuclear@0 181 mOut *= mTrans;
nuclear@0 182 }
nuclear@0 183 }
nuclear@0 184 };
nuclear@0 185
nuclear@0 186
nuclear@0 187 // ---------------------------------------------------------------------------
nuclear@0 188 /** Helper step to compute final UV coordinate sets if there are scalings
nuclear@0 189 * or rotations in the original data read from the file.
nuclear@0 190 */
nuclear@0 191 class TextureTransformStep : public BaseProcess
nuclear@0 192 {
nuclear@0 193 public:
nuclear@0 194
nuclear@0 195 TextureTransformStep();
nuclear@0 196 ~TextureTransformStep();
nuclear@0 197
nuclear@0 198 public:
nuclear@0 199
nuclear@0 200 // -------------------------------------------------------------------
nuclear@0 201 bool IsActive( unsigned int pFlags) const;
nuclear@0 202
nuclear@0 203 // -------------------------------------------------------------------
nuclear@0 204 void Execute( aiScene* pScene);
nuclear@0 205
nuclear@0 206 // -------------------------------------------------------------------
nuclear@0 207 void SetupProperties(const Importer* pImp);
nuclear@0 208
nuclear@0 209
nuclear@0 210 protected:
nuclear@0 211
nuclear@0 212
nuclear@0 213 // -------------------------------------------------------------------
nuclear@0 214 /** Preprocess a specific UV transformation setup
nuclear@0 215 *
nuclear@0 216 * @param info Transformation setup to be preprocessed.
nuclear@0 217 */
nuclear@0 218 void PreProcessUVTransform(STransformVecInfo& info);
nuclear@0 219
nuclear@0 220 private:
nuclear@0 221
nuclear@0 222 unsigned int configFlags;
nuclear@0 223 };
nuclear@0 224
nuclear@0 225 }
nuclear@0 226
nuclear@0 227 #endif //! AI_TEXTURE_TRANSFORM_H_INCLUDED