File indexing completed on 2025-02-21 09:30:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 #pragma once
0050 #ifndef AI_VERTEX_H_INC
0051 #define AI_VERTEX_H_INC
0052
0053 #ifdef __GNUC__
0054 # pragma GCC system_header
0055 #endif
0056
0057 #include <assimp/vector3.h>
0058 #include <assimp/mesh.h>
0059 #include <assimp/ai_assert.h>
0060
0061 #include <functional>
0062
0063 namespace Assimp {
0064
0065
0066
0067
0068
0069
0070 namespace Intern {
0071 template <typename T0, typename T1, typename TRES = T0> struct plus {
0072 TRES operator() (const T0& t0, const T1& t1) const {
0073 return t0+t1;
0074 }
0075 };
0076 template <typename T0, typename T1, typename TRES = T0> struct minus {
0077 TRES operator() (const T0& t0, const T1& t1) const {
0078 return t0-t1;
0079 }
0080 };
0081 template <typename T0, typename T1, typename TRES = T0> struct multiplies {
0082 TRES operator() (const T0& t0, const T1& t1) const {
0083 return t0*t1;
0084 }
0085 };
0086 template <typename T0, typename T1, typename TRES = T0> struct divides {
0087 TRES operator() (const T0& t0, const T1& t1) const {
0088 return t0/t1;
0089 }
0090 };
0091 }
0092
0093
0094
0095
0096
0097
0098
0099 struct Vertex {
0100 friend Vertex operator + (const Vertex&,const Vertex&);
0101 friend Vertex operator - (const Vertex&,const Vertex&);
0102 friend Vertex operator * (const Vertex&,ai_real);
0103 friend Vertex operator / (const Vertex&,ai_real);
0104 friend Vertex operator * (ai_real, const Vertex&);
0105
0106 aiVector3D position;
0107 aiVector3D normal;
0108 aiVector3D tangent, bitangent;
0109
0110 aiVector3D texcoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
0111 aiColor4D colors[AI_MAX_NUMBER_OF_COLOR_SETS];
0112
0113 Vertex() = default;
0114
0115
0116
0117 explicit Vertex(const aiMesh* msh, unsigned int idx) {
0118 ai_assert(idx < msh->mNumVertices);
0119 position = msh->mVertices[idx];
0120
0121 if (msh->HasNormals()) {
0122 normal = msh->mNormals[idx];
0123 }
0124
0125 if (msh->HasTangentsAndBitangents()) {
0126 tangent = msh->mTangents[idx];
0127 bitangent = msh->mBitangents[idx];
0128 }
0129
0130 for (unsigned int i = 0; msh->HasTextureCoords(i); ++i) {
0131 texcoords[i] = msh->mTextureCoords[i][idx];
0132 }
0133
0134 for (unsigned int i = 0; msh->HasVertexColors(i); ++i) {
0135 colors[i] = msh->mColors[i][idx];
0136 }
0137 }
0138
0139
0140
0141 explicit Vertex(const aiAnimMesh* msh, unsigned int idx) {
0142 ai_assert(idx < msh->mNumVertices);
0143 if (msh->HasPositions()) {
0144 position = msh->mVertices[idx];
0145 }
0146
0147 if (msh->HasNormals()) {
0148 normal = msh->mNormals[idx];
0149 }
0150
0151 if (msh->HasTangentsAndBitangents()) {
0152 tangent = msh->mTangents[idx];
0153 bitangent = msh->mBitangents[idx];
0154 }
0155
0156 for (unsigned int i = 0; msh->HasTextureCoords(i); ++i) {
0157 texcoords[i] = msh->mTextureCoords[i][idx];
0158 }
0159
0160 for (unsigned int i = 0; msh->HasVertexColors(i); ++i) {
0161 colors[i] = msh->mColors[i][idx];
0162 }
0163 }
0164
0165 Vertex& operator += (const Vertex& v) {
0166 *this = *this+v;
0167 return *this;
0168 }
0169
0170 Vertex& operator -= (const Vertex& v) {
0171 *this = *this-v;
0172 return *this;
0173 }
0174
0175 Vertex& operator *= (ai_real v) {
0176 *this = *this*v;
0177 return *this;
0178 }
0179
0180 Vertex& operator /= (ai_real v) {
0181 *this = *this/v;
0182 return *this;
0183 }
0184
0185
0186
0187 void SortBack(aiMesh* out, unsigned int idx) const {
0188 ai_assert(idx<out->mNumVertices);
0189 out->mVertices[idx] = position;
0190
0191 if (out->HasNormals()) {
0192 out->mNormals[idx] = normal;
0193 }
0194
0195 if (out->HasTangentsAndBitangents()) {
0196 out->mTangents[idx] = tangent;
0197 out->mBitangents[idx] = bitangent;
0198 }
0199
0200 for(unsigned int i = 0; out->HasTextureCoords(i); ++i) {
0201 out->mTextureCoords[i][idx] = texcoords[i];
0202 }
0203
0204 for(unsigned int i = 0; out->HasVertexColors(i); ++i) {
0205 out->mColors[i][idx] = colors[i];
0206 }
0207 }
0208
0209 private:
0210
0211
0212
0213 template <template <typename t> class op> static Vertex BinaryOp(const Vertex& v0, const Vertex& v1) {
0214
0215
0216 Vertex res;
0217 res.position = op<aiVector3D>()(v0.position,v1.position);
0218 res.normal = op<aiVector3D>()(v0.normal,v1.normal);
0219 res.tangent = op<aiVector3D>()(v0.tangent,v1.tangent);
0220 res.bitangent = op<aiVector3D>()(v0.bitangent,v1.bitangent);
0221
0222 for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
0223 res.texcoords[i] = op<aiVector3D>()(v0.texcoords[i],v1.texcoords[i]);
0224 }
0225 for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i) {
0226 res.colors[i] = op<aiColor4D>()(v0.colors[i],v1.colors[i]);
0227 }
0228 return res;
0229 }
0230
0231
0232
0233 template <template <typename, typename, typename> class op>
0234 static Vertex BinaryOp(const Vertex& v0, ai_real f) {
0235
0236
0237 Vertex res;
0238 res.position = op<aiVector3D,ai_real,aiVector3D>()(v0.position,f);
0239 res.normal = op<aiVector3D,ai_real,aiVector3D>()(v0.normal,f);
0240 res.tangent = op<aiVector3D,ai_real,aiVector3D>()(v0.tangent,f);
0241 res.bitangent = op<aiVector3D,ai_real,aiVector3D>()(v0.bitangent,f);
0242
0243 for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
0244 res.texcoords[i] = op<aiVector3D,ai_real,aiVector3D>()(v0.texcoords[i],f);
0245 }
0246 for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i) {
0247 res.colors[i] = op<aiColor4D,float, aiColor4D>()(v0.colors[i],f);
0248 }
0249 return res;
0250 }
0251
0252
0253
0254 template <template <typename, typename, typename> class op>
0255 static Vertex BinaryOp(ai_real f, const Vertex& v0) {
0256
0257
0258 Vertex res;
0259 res.position = op<ai_real,aiVector3D,aiVector3D>()(f,v0.position);
0260 res.normal = op<ai_real,aiVector3D,aiVector3D>()(f,v0.normal);
0261 res.tangent = op<ai_real,aiVector3D,aiVector3D>()(f,v0.tangent);
0262 res.bitangent = op<ai_real,aiVector3D,aiVector3D>()(f,v0.bitangent);
0263
0264 for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
0265 res.texcoords[i] = op<ai_real,aiVector3D,aiVector3D>()(f,v0.texcoords[i]);
0266 }
0267 for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i) {
0268 res.colors[i] = op<float, aiColor4D,aiColor4D>()(f,v0.colors[i]);
0269 }
0270 return res;
0271 }
0272 };
0273
0274
0275 AI_FORCE_INLINE Vertex operator + (const Vertex& v0,const Vertex& v1) {
0276 return Vertex::BinaryOp<std::plus>(v0,v1);
0277 }
0278
0279 AI_FORCE_INLINE Vertex operator - (const Vertex& v0,const Vertex& v1) {
0280 return Vertex::BinaryOp<std::minus>(v0,v1);
0281 }
0282
0283 AI_FORCE_INLINE Vertex operator * (const Vertex& v0,ai_real f) {
0284 return Vertex::BinaryOp<Intern::multiplies>(v0,f);
0285 }
0286
0287 AI_FORCE_INLINE Vertex operator / (const Vertex& v0,ai_real f) {
0288 return Vertex::BinaryOp<Intern::multiplies>(v0,1.f/f);
0289 }
0290
0291 AI_FORCE_INLINE Vertex operator * (ai_real f,const Vertex& v0) {
0292 return Vertex::BinaryOp<Intern::multiplies>(f,v0);
0293 }
0294
0295 }
0296
0297 #endif