/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp 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 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 Defines a helper class to represent an interleaved vertex along with arithmetic operations to support vertex operations such as subdivision, smoothing etc. While the code is kept as general as possible, arithmetic operations that are not currently well-defined (and would cause compile errors due to missing operators in the math library), are commented. */ #pragma once #ifndef AI_VERTEX_H_INC #define AI_VERTEX_H_INC #ifdef __GNUC__ # pragma GCC system_header #endif #include #include #include #include namespace Assimp { /////////////////////////////////////////////////////////////////////////// // std::plus-family operates on operands with identical types - we need to // support all the (vectype op float) combinations in vector maths. // Providing T(float) would open the way to endless implicit conversions. /////////////////////////////////////////////////////////////////////////// namespace Intern { template struct plus { TRES operator() (const T0& t0, const T1& t1) const { return t0+t1; } }; template struct minus { TRES operator() (const T0& t0, const T1& t1) const { return t0-t1; } }; template struct multiplies { TRES operator() (const T0& t0, const T1& t1) const { return t0*t1; } }; template struct divides { TRES operator() (const T0& t0, const T1& t1) const { return t0/t1; } }; } // ------------------------------------------------------------------------------------------------ /** Intermediate description a vertex with all possible components. Defines a full set of * operators, so you may use such a 'Vertex' in basic arithmetic. All operators are applied * to *all* vertex components equally. This is useful for stuff like interpolation * or subdivision, but won't work if special handling is required for some vertex components. */ // ------------------------------------------------------------------------------------------------ class Vertex { friend Vertex operator + (const Vertex&,const Vertex&); friend Vertex operator - (const Vertex&,const Vertex&); friend Vertex operator * (const Vertex&,ai_real); friend Vertex operator / (const Vertex&,ai_real); friend Vertex operator * (ai_real, const Vertex&); public: Vertex() {} // ---------------------------------------------------------------------------- /** Extract a particular vertex from a mesh and interleave all components */ explicit Vertex(const aiMesh* msh, unsigned int idx) { ai_assert(idx < msh->mNumVertices); position = msh->mVertices[idx]; if (msh->HasNormals()) { normal = msh->mNormals[idx]; } if (msh->HasTangentsAndBitangents()) { tangent = msh->mTangents[idx]; bitangent = msh->mBitangents[idx]; } for (unsigned int i = 0; msh->HasTextureCoords(i); ++i) { texcoords[i] = msh->mTextureCoords[i][idx]; } for (unsigned int i = 0; msh->HasVertexColors(i); ++i) { colors[i] = msh->mColors[i][idx]; } } // ---------------------------------------------------------------------------- /** Extract a particular vertex from a anim mesh and interleave all components */ explicit Vertex(const aiAnimMesh* msh, unsigned int idx) { ai_assert(idx < msh->mNumVertices); if (msh->HasPositions()) { position = msh->mVertices[idx]; } if (msh->HasNormals()) { normal = msh->mNormals[idx]; } if (msh->HasTangentsAndBitangents()) { tangent = msh->mTangents[idx]; bitangent = msh->mBitangents[idx]; } for (unsigned int i = 0; msh->HasTextureCoords(i); ++i) { texcoords[i] = msh->mTextureCoords[i][idx]; } for (unsigned int i = 0; msh->HasVertexColors(i); ++i) { colors[i] = msh->mColors[i][idx]; } } Vertex& operator += (const Vertex& v) { *this = *this+v; return *this; } Vertex& operator -= (const Vertex& v) { *this = *this-v; return *this; } Vertex& operator *= (ai_real v) { *this = *this*v; return *this; } Vertex& operator /= (ai_real v) { *this = *this/v; return *this; } // ---------------------------------------------------------------------------- /** Convert back to non-interleaved storage */ void SortBack(aiMesh* out, unsigned int idx) const { ai_assert(idxmNumVertices); out->mVertices[idx] = position; if (out->HasNormals()) { out->mNormals[idx] = normal; } if (out->HasTangentsAndBitangents()) { out->mTangents[idx] = tangent; out->mBitangents[idx] = bitangent; } for(unsigned int i = 0; out->HasTextureCoords(i); ++i) { out->mTextureCoords[i][idx] = texcoords[i]; } for(unsigned int i = 0; out->HasVertexColors(i); ++i) { out->mColors[i][idx] = colors[i]; } } private: // ---------------------------------------------------------------------------- /** Construct from two operands and a binary operation to combine them */ template