1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#ifndef __VCG_TRI_UPDATE_TEXTURE
#define __VCG_TRI_UPDATE_TEXTURE
//#include <vcg/space/plane.h>
namespace vcg {
namespace tri {
/// \ingroup trimesh
/// \headerfile texture.h vcg/complex/algorithms/update/texture.h
/// \brief This class is used to update/generate texcoord position according to various critera. .
template <class ComputeMeshType>
class UpdateTexture
{
public:
typedef ComputeMeshType MeshType;
typedef typename MeshType::ScalarType ScalarType;
typedef typename MeshType::VertexType VertexType;
typedef typename MeshType::VertexPointer VertexPointer;
typedef typename MeshType::VertexIterator VertexIterator;
typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::FacePointer FacePointer;
typedef typename MeshType::FaceIterator FaceIterator;
static void WedgeTexFromPlane(ComputeMeshType &m, const Point3<ScalarType> &uVec, const Point3<ScalarType> &vVec, bool aspectRatio)
{
// First just project
FaceIterator fi;
for(fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
{
for(int i=0;i<3;++i)
{
(*fi).WT(i).U()= (*fi).V(i)->cP() * uVec;
(*fi).WT(i).V()= (*fi).V(i)->cP() * vVec;
}
}
// second Loop normalize to
Box2f bb;
for(fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
{
for(int i=0;i<3;++i)
{
bb.Add((*fi).WT(i).P());
}
}
ScalarType wideU = bb.max[0]- bb.min[0];
ScalarType wideV = bb.max[1]- bb.min[1];
if(aspectRatio) {
wideU = std::max(wideU,wideV);
wideV = wideU;
}
for(fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
{
for(int i=0;i<3;++i)
{
(*fi).WT(i).U() = ((*fi).WT(i).U() - bb.min[0]) / wideU;
(*fi).WT(i).V() = ((*fi).WT(i).V() - bb.min[1]) / wideV;
}
}
}
static void WedgeTexFromCamera(ComputeMeshType &m, Plane3<ScalarType> &pl)
{
}
static void WedgeTexFromVertexTex(ComputeMeshType &m)
{
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
{
for(int i=0;i<3;++i)
{
(*fi).WT(i).U() = (*fi).V(i)->T().U();
(*fi).WT(i).V() = (*fi).V(i)->T().V();
}
}
}
/// Currently texture coords are kept for ALL the triangles of a mesh. The texture id is stored with each face.
/// if a given face should not have tex coord it has the default -1 value for texture ID.
/// This function will add an new fake texture, add that to the list of textures and change all the -1 id to that value.
static void WedgeTexRemoveNull(ComputeMeshType &m, const std::string &texturename)
{
bool found=false;
FaceIterator fi;
// first loop lets check that there are -1 indexed textured face
for(fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD()) if((*fi).WT(0).N()==-1) found = true;
if(!found) return;
m.textures.push_back(texturename);
int nullId=m.textures.size()-1;
for(fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD()) if((*fi).WT(0).N()==-1)
{
(*fi).WT(0).N() = nullId;
(*fi).WT(1).N() = nullId;
(*fi).WT(2).N() = nullId;
}
}
}; // end class
} // End namespace
} // End namespace
#endif
|