vrshoot

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/assimp/TextureTransform.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,227 @@
     1.4 +/*
     1.5 +Open Asset Import Library (assimp)
     1.6 +----------------------------------------------------------------------
     1.7 +
     1.8 +Copyright (c) 2006-2012, assimp team
     1.9 +All rights reserved.
    1.10 +
    1.11 +Redistribution and use of this software in source and binary forms, 
    1.12 +with or without modification, are permitted provided that the 
    1.13 +following conditions are met:
    1.14 +
    1.15 +* Redistributions of source code must retain the above
    1.16 +  copyright notice, this list of conditions and the
    1.17 +  following disclaimer.
    1.18 +
    1.19 +* Redistributions in binary form must reproduce the above
    1.20 +  copyright notice, this list of conditions and the
    1.21 +  following disclaimer in the documentation and/or other
    1.22 +  materials provided with the distribution.
    1.23 +
    1.24 +* Neither the name of the assimp team, nor the names of its
    1.25 +  contributors may be used to endorse or promote products
    1.26 +  derived from this software without specific prior
    1.27 +  written permission of the assimp team.
    1.28 +
    1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
    1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.40 +
    1.41 +----------------------------------------------------------------------
    1.42 +*/
    1.43 +
    1.44 +/** @file Definition of a helper step that processes texture transformations */
    1.45 +#ifndef AI_TEXTURE_TRANSFORM_H_INCLUDED
    1.46 +#define AI_TEXTURE_TRANSFORM_H_INCLUDED
    1.47 +
    1.48 +#include "BaseImporter.h"
    1.49 +#include "BaseProcess.h"
    1.50 +
    1.51 +struct aiNode;
    1.52 +
    1.53 +namespace Assimp	{
    1.54 +
    1.55 +#define AI_TT_UV_IDX_LOCK_TBD	0xffffffff
    1.56 +#define AI_TT_UV_IDX_LOCK_NONE	0xeeeeeeee
    1.57 +
    1.58 +
    1.59 +#define AI_TT_ROTATION_EPSILON	((float)AI_DEG_TO_RAD(0.5))
    1.60 +
    1.61 +// ---------------------------------------------------------------------------
    1.62 +/** Small helper structure representing a shortcut into the material list
    1.63 + *  to be able to update some values quickly.
    1.64 +*/
    1.65 +struct TTUpdateInfo
    1.66 +{
    1.67 +	TTUpdateInfo() :
    1.68 +			directShortcut	(NULL)
    1.69 +		,	mat				(NULL)
    1.70 +		,	semantic		(0)
    1.71 +		,	index			(0)
    1.72 +	{}
    1.73 +
    1.74 +	//! Direct shortcut, if available
    1.75 +	unsigned int* directShortcut;
    1.76 +
    1.77 +	//! Material 
    1.78 +	aiMaterial *mat;
    1.79 +
    1.80 +	//! Texture type and index
    1.81 +	unsigned int semantic, index;
    1.82 +};
    1.83 +
    1.84 +
    1.85 +// ---------------------------------------------------------------------------
    1.86 +/** Helper class representing texture coordinate transformations
    1.87 +*/
    1.88 +struct STransformVecInfo : public aiUVTransform
    1.89 +{
    1.90 +
    1.91 +	STransformVecInfo()
    1.92 +		:	uvIndex		(0)
    1.93 +		,	mapU		(aiTextureMapMode_Wrap)
    1.94 +		,	mapV		(aiTextureMapMode_Wrap)
    1.95 +		,	lockedPos	(AI_TT_UV_IDX_LOCK_NONE)
    1.96 +	{}
    1.97 +
    1.98 +	//! Source texture coordinate index
    1.99 +	unsigned int uvIndex;
   1.100 +
   1.101 +	//! Texture mapping mode in the u, v direction
   1.102 +	aiTextureMapMode mapU,mapV;
   1.103 +
   1.104 +	//! Locked destination UV index
   1.105 +	//! AI_TT_UV_IDX_LOCK_TBD - to be determined
   1.106 +	//! AI_TT_UV_IDX_LOCK_NONE - none (default)
   1.107 +	unsigned int lockedPos;
   1.108 +
   1.109 +	//! Update info - shortcuts into all materials
   1.110 +	//! that are referencing this transform setup
   1.111 +	std::list<TTUpdateInfo> updateList;
   1.112 +
   1.113 +
   1.114 +	// -------------------------------------------------------------------
   1.115 +	/** Compare two transform setups
   1.116 +	*/
   1.117 +	inline bool operator== (const STransformVecInfo& other) const
   1.118 +	{
   1.119 +		// We use a small epsilon here
   1.120 +		const static float epsilon = 0.05f;
   1.121 +
   1.122 +		if (fabs( mTranslation.x - other.mTranslation.x ) > epsilon ||
   1.123 +			fabs( mTranslation.y - other.mTranslation.y ) > epsilon)
   1.124 +		{
   1.125 +			return false;
   1.126 +		}
   1.127 +
   1.128 +		if (fabs( mScaling.x - other.mScaling.x ) > epsilon ||
   1.129 +			fabs( mScaling.y - other.mScaling.y ) > epsilon)
   1.130 +		{
   1.131 +			return false;
   1.132 +		}
   1.133 +
   1.134 +		if (fabs( mRotation - other.mRotation) > epsilon)
   1.135 +		{
   1.136 +			return false;
   1.137 +		}
   1.138 +		return true;
   1.139 +	}
   1.140 +
   1.141 +	inline bool operator!= (const STransformVecInfo& other) const
   1.142 +	{
   1.143 +			return !(*this == other);
   1.144 +	}
   1.145 +
   1.146 +
   1.147 +	// -------------------------------------------------------------------
   1.148 +	/** Returns whether this is an untransformed texture coordinate set
   1.149 +	*/
   1.150 +	inline bool IsUntransformed() const
   1.151 +	{
   1.152 +		return (1.0f == mScaling.x && 1.f == mScaling.y &&
   1.153 +			!mTranslation.x && !mTranslation.y && 
   1.154 +			mRotation < AI_TT_ROTATION_EPSILON);
   1.155 +	}
   1.156 +
   1.157 +	// -------------------------------------------------------------------
   1.158 +	/** Build a 3x3 matrix from the transformations
   1.159 +	*/
   1.160 +	inline void GetMatrix(aiMatrix3x3& mOut)
   1.161 +	{
   1.162 +		mOut = aiMatrix3x3();
   1.163 +
   1.164 +		if (1.0f != mScaling.x || 1.0f != mScaling.y)
   1.165 +		{
   1.166 +			aiMatrix3x3 mScale;
   1.167 +			mScale.a1 = mScaling.x;
   1.168 +			mScale.b2 = mScaling.y;
   1.169 +			mOut = mScale;
   1.170 +		}
   1.171 +		if (mRotation)
   1.172 +		{
   1.173 +			aiMatrix3x3 mRot; 
   1.174 +			mRot.a1 = mRot.b2 = cos(mRotation);
   1.175 +			mRot.a2 = mRot.b1 = sin(mRotation);
   1.176 +			mRot.a2 = -mRot.a2;
   1.177 +			mOut *= mRot;
   1.178 +		}
   1.179 +		if (mTranslation.x || mTranslation.y)
   1.180 +		{
   1.181 +			aiMatrix3x3 mTrans; 
   1.182 +			mTrans.a3 = mTranslation.x;
   1.183 +			mTrans.b3 = mTranslation.y;
   1.184 +			mOut *= mTrans;
   1.185 +		}
   1.186 +	}
   1.187 +};
   1.188 +
   1.189 +
   1.190 +// ---------------------------------------------------------------------------
   1.191 +/** Helper step to compute final UV coordinate sets if there are scalings
   1.192 + *  or rotations in the original data read from the file.
   1.193 +*/
   1.194 +class TextureTransformStep : public BaseProcess
   1.195 +{
   1.196 +public:
   1.197 +
   1.198 +	TextureTransformStep();
   1.199 +	~TextureTransformStep();
   1.200 +
   1.201 +public:
   1.202 +
   1.203 +	// -------------------------------------------------------------------
   1.204 +	bool IsActive( unsigned int pFlags) const;
   1.205 +
   1.206 +	// -------------------------------------------------------------------
   1.207 +	void Execute( aiScene* pScene);
   1.208 +
   1.209 +	// -------------------------------------------------------------------
   1.210 +	void SetupProperties(const Importer* pImp);
   1.211 +
   1.212 +
   1.213 +protected:
   1.214 +
   1.215 +
   1.216 +	// -------------------------------------------------------------------
   1.217 +	/** Preprocess a specific UV transformation setup
   1.218 +	 *
   1.219 +	 *  @param info Transformation setup to be preprocessed.
   1.220 +	*/
   1.221 +	void PreProcessUVTransform(STransformVecInfo& info);
   1.222 +
   1.223 +private:
   1.224 +
   1.225 +	unsigned int configFlags;
   1.226 +};
   1.227 +
   1.228 +}
   1.229 +
   1.230 +#endif //! AI_TEXTURE_TRANSFORM_H_INCLUDED