2008-06-01 12:46:17 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (ASSIMP)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
|
|
|
Copyright (c) 2006-2008, ASSIMP Development Team
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the ASSIMP team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the ASSIMP Development Team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file Definition of a helper class that processes texture transformations */
|
|
|
|
#ifndef AI_TEXTURE_TRANSFORM_H_INCLUDED
|
|
|
|
#define AI_TEXTURE_TRANSFORM_H_INCLUDED
|
|
|
|
|
|
|
|
#include "BaseImporter.h"
|
|
|
|
#include "../include/aiTypes.h"
|
|
|
|
#include "../include/aiMaterial.h"
|
|
|
|
#include "../include/aiMesh.h"
|
|
|
|
|
|
|
|
|
|
|
|
struct aiNode;
|
|
|
|
#include "3DSHelper.h"
|
|
|
|
|
|
|
|
namespace Assimp
|
|
|
|
{
|
|
|
|
|
|
|
|
using namespace Assimp::Dot3DS;
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** Helper class representing texture coordinate transformations
|
|
|
|
*/
|
|
|
|
struct STransformVecInfo
|
|
|
|
{
|
2008-06-03 21:50:53 +00:00
|
|
|
//! Construction. The resulting matrix is the identity
|
|
|
|
STransformVecInfo ()
|
|
|
|
:
|
|
|
|
fScaleU(1.0f),fScaleV(1.0f),
|
|
|
|
fOffsetU(0.0f),fOffsetV(0.0f),
|
|
|
|
fRotation(0.0f),
|
|
|
|
iUVIndex(0)
|
|
|
|
{}
|
|
|
|
|
2008-06-01 12:46:17 +00:00
|
|
|
//! Texture coordinate scaling in the x-direction
|
|
|
|
float fScaleU;
|
|
|
|
//! Texture coordinate scaling in the y-direction
|
|
|
|
float fScaleV;
|
|
|
|
//! Texture coordinate offset in the x-direction
|
|
|
|
float fOffsetU;
|
|
|
|
//! Texture coordinate offset in the y-direction
|
|
|
|
float fOffsetV;
|
|
|
|
//! Texture coordinate rotation, clockwise, in radians
|
|
|
|
float fRotation;
|
|
|
|
|
2008-06-03 21:50:53 +00:00
|
|
|
//! Source texture coordinate index
|
|
|
|
unsigned int iUVIndex;
|
|
|
|
|
|
|
|
|
2008-06-01 12:46:17 +00:00
|
|
|
//! List of all textures that use this texture
|
|
|
|
//! coordinate transformations
|
|
|
|
std::vector<Dot3DS::Texture*> pcTextures;
|
|
|
|
|
|
|
|
|
2008-06-03 21:50:53 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Returns whether this is an untransformed texture coordinate set
|
|
|
|
*/
|
|
|
|
inline bool IsUntransformed() const
|
|
|
|
{
|
|
|
|
return 1.0f == fScaleU && 1.0f == fScaleV &&
|
|
|
|
!fOffsetU && !fOffsetV && !fRotation;
|
|
|
|
}
|
|
|
|
|
2008-06-01 12:46:17 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Build a 3x3 matrix from the transformations
|
|
|
|
*/
|
|
|
|
inline void GetMatrix(aiMatrix3x3& mOut)
|
|
|
|
{
|
|
|
|
mOut = aiMatrix3x3();
|
|
|
|
|
|
|
|
if (1.0f != this->fScaleU || 1.0f != this->fScaleV)
|
|
|
|
{
|
|
|
|
aiMatrix3x3 mScale;
|
|
|
|
mScale.a1 = this->fScaleU;
|
|
|
|
mScale.b2 = this->fScaleV;
|
|
|
|
mOut = mScale;
|
|
|
|
}
|
|
|
|
if (this->fRotation)
|
|
|
|
{
|
|
|
|
aiMatrix3x3 mRot;
|
|
|
|
mRot.a1 = mRot.b2 = cosf(this->fRotation);
|
|
|
|
mRot.a2 = mRot.b1 = sinf(this->fRotation);
|
|
|
|
mRot.a2 = -mRot.a2;
|
|
|
|
mOut *= mRot;
|
|
|
|
}
|
|
|
|
if (this->fOffsetU || this->fOffsetV)
|
|
|
|
{
|
|
|
|
aiMatrix3x3 mTrans;
|
|
|
|
mTrans.a3 = this->fOffsetU;
|
|
|
|
mTrans.b3 = this->fOffsetV;
|
|
|
|
mOut *= mTrans;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** Helper class used by the ASE/ASK and 3DS loaders to handle texture
|
|
|
|
* coordinate transformations correctly (such as offsets, scaling)
|
|
|
|
*/
|
2008-07-24 11:19:24 +00:00
|
|
|
class ASSIMP_API TextureTransform
|
2008-06-01 12:46:17 +00:00
|
|
|
{
|
|
|
|
//! Constructor, it is not possible to create instances of this class
|
|
|
|
TextureTransform() {}
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Returns true if a texture requires UV transformations
|
|
|
|
* \param rcIn Input texture
|
|
|
|
*/
|
2008-06-01 14:03:45 +00:00
|
|
|
inline static bool HasUVTransform(
|
2008-06-01 12:46:17 +00:00
|
|
|
const Dot3DS::Texture& rcIn)
|
|
|
|
{
|
|
|
|
return (rcIn.mOffsetU || rcIn.mOffsetV ||
|
|
|
|
1.0f != rcIn.mScaleU || 1.0f != rcIn.mScaleV || rcIn.mRotation);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Must be called before HasUVTransform(rcIn) is called
|
|
|
|
* \param rcIn Input texture
|
|
|
|
*/
|
|
|
|
static void PreProcessUVTransform(
|
|
|
|
Dot3DS::Texture& rcIn);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Check whether the texture coordinate transformation of
|
|
|
|
* a texture is already contained in a given list
|
|
|
|
* \param rasVec List of transformations
|
|
|
|
* \param pcTex Pointer to the texture
|
|
|
|
*/
|
|
|
|
static void AddToList(std::vector<STransformVecInfo>& rasVec,
|
|
|
|
Dot3DS::Texture* pcTex);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Get a full list of all texture coordinate offsets required
|
|
|
|
* for a material
|
|
|
|
* \param materials List of materials to be processed
|
|
|
|
*/
|
2008-06-03 21:50:53 +00:00
|
|
|
static void ApplyScaleNOffset(std::vector<Dot3DS::Material>& materials);
|
2008-06-01 12:46:17 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Get a full list of all texture coordinate offsets required
|
|
|
|
* for a material
|
|
|
|
* \param material Material to be processed
|
|
|
|
*/
|
|
|
|
static void ApplyScaleNOffset(Dot3DS::Material& material);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Precompute as many texture coordinate transformations as possible
|
|
|
|
* \param pcMesh Mesh containing the texture coordinate data
|
|
|
|
* \param pcSrc Input material. Must have been passed to
|
|
|
|
* ApplyScaleNOffset
|
|
|
|
*/
|
|
|
|
static void BakeScaleNOffset(aiMesh* pcMesh, Dot3DS::Material* pcSrc);
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Setup the correct UV source for a material
|
|
|
|
* \param pcMat Final material to be changed
|
|
|
|
* \param pcMatIn Input material, unconverted
|
|
|
|
*/
|
|
|
|
static void SetupMatUVSrc (aiMaterial* pcMat,
|
|
|
|
const Dot3DS::Material* pcMatIn);
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //! AI_TEXTURE_TRANSFORM_H_INCLUDED
|