nuclear@0: /* nuclear@0: Open Asset Import Library (assimp) nuclear@0: ---------------------------------------------------------------------- nuclear@0: nuclear@0: Copyright (c) 2006-2012, assimp team nuclear@0: All rights reserved. nuclear@0: nuclear@0: Redistribution and use of this software in source and binary forms, nuclear@0: with or without modification, are permitted provided that the nuclear@0: following conditions are met: nuclear@0: nuclear@0: * Redistributions of source code must retain the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer. nuclear@0: nuclear@0: * Redistributions in binary form must reproduce the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer in the documentation and/or other nuclear@0: materials provided with the distribution. nuclear@0: nuclear@0: * Neither the name of the assimp team, nor the names of its nuclear@0: contributors may be used to endorse or promote products nuclear@0: derived from this software without specific prior nuclear@0: written permission of the assimp team. nuclear@0: nuclear@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nuclear@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT nuclear@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR nuclear@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT nuclear@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, nuclear@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT nuclear@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, nuclear@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY nuclear@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT nuclear@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE nuclear@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nuclear@0: nuclear@0: ---------------------------------------------------------------------- nuclear@0: */ nuclear@0: nuclear@0: /** @file Definition of a helper step that processes texture transformations */ nuclear@0: #ifndef AI_TEXTURE_TRANSFORM_H_INCLUDED nuclear@0: #define AI_TEXTURE_TRANSFORM_H_INCLUDED nuclear@0: nuclear@0: #include "BaseImporter.h" nuclear@0: #include "BaseProcess.h" nuclear@0: nuclear@0: struct aiNode; nuclear@0: nuclear@0: namespace Assimp { nuclear@0: nuclear@0: #define AI_TT_UV_IDX_LOCK_TBD 0xffffffff nuclear@0: #define AI_TT_UV_IDX_LOCK_NONE 0xeeeeeeee nuclear@0: nuclear@0: nuclear@0: #define AI_TT_ROTATION_EPSILON ((float)AI_DEG_TO_RAD(0.5)) nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** Small helper structure representing a shortcut into the material list nuclear@0: * to be able to update some values quickly. nuclear@0: */ nuclear@0: struct TTUpdateInfo nuclear@0: { nuclear@0: TTUpdateInfo() : nuclear@0: directShortcut (NULL) nuclear@0: , mat (NULL) nuclear@0: , semantic (0) nuclear@0: , index (0) nuclear@0: {} nuclear@0: nuclear@0: //! Direct shortcut, if available nuclear@0: unsigned int* directShortcut; nuclear@0: nuclear@0: //! Material nuclear@0: aiMaterial *mat; nuclear@0: nuclear@0: //! Texture type and index nuclear@0: unsigned int semantic, index; nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** Helper class representing texture coordinate transformations nuclear@0: */ nuclear@0: struct STransformVecInfo : public aiUVTransform nuclear@0: { nuclear@0: nuclear@0: STransformVecInfo() nuclear@0: : uvIndex (0) nuclear@0: , mapU (aiTextureMapMode_Wrap) nuclear@0: , mapV (aiTextureMapMode_Wrap) nuclear@0: , lockedPos (AI_TT_UV_IDX_LOCK_NONE) nuclear@0: {} nuclear@0: nuclear@0: //! Source texture coordinate index nuclear@0: unsigned int uvIndex; nuclear@0: nuclear@0: //! Texture mapping mode in the u, v direction nuclear@0: aiTextureMapMode mapU,mapV; nuclear@0: nuclear@0: //! Locked destination UV index nuclear@0: //! AI_TT_UV_IDX_LOCK_TBD - to be determined nuclear@0: //! AI_TT_UV_IDX_LOCK_NONE - none (default) nuclear@0: unsigned int lockedPos; nuclear@0: nuclear@0: //! Update info - shortcuts into all materials nuclear@0: //! that are referencing this transform setup nuclear@0: std::list updateList; nuclear@0: nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Compare two transform setups nuclear@0: */ nuclear@0: inline bool operator== (const STransformVecInfo& other) const nuclear@0: { nuclear@0: // We use a small epsilon here nuclear@0: const static float epsilon = 0.05f; nuclear@0: nuclear@0: if (fabs( mTranslation.x - other.mTranslation.x ) > epsilon || nuclear@0: fabs( mTranslation.y - other.mTranslation.y ) > epsilon) nuclear@0: { nuclear@0: return false; nuclear@0: } nuclear@0: nuclear@0: if (fabs( mScaling.x - other.mScaling.x ) > epsilon || nuclear@0: fabs( mScaling.y - other.mScaling.y ) > epsilon) nuclear@0: { nuclear@0: return false; nuclear@0: } nuclear@0: nuclear@0: if (fabs( mRotation - other.mRotation) > epsilon) nuclear@0: { nuclear@0: return false; nuclear@0: } nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: inline bool operator!= (const STransformVecInfo& other) const nuclear@0: { nuclear@0: return !(*this == other); nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Returns whether this is an untransformed texture coordinate set nuclear@0: */ nuclear@0: inline bool IsUntransformed() const nuclear@0: { nuclear@0: return (1.0f == mScaling.x && 1.f == mScaling.y && nuclear@0: !mTranslation.x && !mTranslation.y && nuclear@0: mRotation < AI_TT_ROTATION_EPSILON); nuclear@0: } nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Build a 3x3 matrix from the transformations nuclear@0: */ nuclear@0: inline void GetMatrix(aiMatrix3x3& mOut) nuclear@0: { nuclear@0: mOut = aiMatrix3x3(); nuclear@0: nuclear@0: if (1.0f != mScaling.x || 1.0f != mScaling.y) nuclear@0: { nuclear@0: aiMatrix3x3 mScale; nuclear@0: mScale.a1 = mScaling.x; nuclear@0: mScale.b2 = mScaling.y; nuclear@0: mOut = mScale; nuclear@0: } nuclear@0: if (mRotation) nuclear@0: { nuclear@0: aiMatrix3x3 mRot; nuclear@0: mRot.a1 = mRot.b2 = cos(mRotation); nuclear@0: mRot.a2 = mRot.b1 = sin(mRotation); nuclear@0: mRot.a2 = -mRot.a2; nuclear@0: mOut *= mRot; nuclear@0: } nuclear@0: if (mTranslation.x || mTranslation.y) nuclear@0: { nuclear@0: aiMatrix3x3 mTrans; nuclear@0: mTrans.a3 = mTranslation.x; nuclear@0: mTrans.b3 = mTranslation.y; nuclear@0: mOut *= mTrans; nuclear@0: } nuclear@0: } nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** Helper step to compute final UV coordinate sets if there are scalings nuclear@0: * or rotations in the original data read from the file. nuclear@0: */ nuclear@0: class TextureTransformStep : public BaseProcess nuclear@0: { nuclear@0: public: nuclear@0: nuclear@0: TextureTransformStep(); nuclear@0: ~TextureTransformStep(); nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: bool IsActive( unsigned int pFlags) const; nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: void Execute( aiScene* pScene); nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: void SetupProperties(const Importer* pImp); nuclear@0: nuclear@0: nuclear@0: protected: nuclear@0: nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Preprocess a specific UV transformation setup nuclear@0: * nuclear@0: * @param info Transformation setup to be preprocessed. nuclear@0: */ nuclear@0: void PreProcessUVTransform(STransformVecInfo& info); nuclear@0: nuclear@0: private: nuclear@0: nuclear@0: unsigned int configFlags; nuclear@0: }; nuclear@0: nuclear@0: } nuclear@0: nuclear@0: #endif //! AI_TEXTURE_TRANSFORM_H_INCLUDED