diff --git a/code/AssetLib/Assjson/json_exporter.cpp b/code/AssetLib/Assjson/json_exporter.cpp index 7b2c8ec81..7a8403831 100644 --- a/code/AssetLib/Assjson/json_exporter.cpp +++ b/code/AssetLib/Assjson/json_exporter.cpp @@ -10,6 +10,7 @@ Licensed under a 3-clause BSD license. See the LICENSE file for more information #ifndef ASSIMP_BUILD_NO_ASSJSON_EXPORTER #include +#include #include #include #include @@ -23,16 +24,15 @@ Licensed under a 3-clause BSD license. See the LICENSE file for more information #define CURRENT_FORMAT_VERSION 100 -// grab scoped_ptr from assimp to avoid a dependency on boost. -//#include - #include "mesh_splitter.h" extern "C" { -#include "cencode.h" +# include "cencode.h" } + namespace Assimp { +// Forward declarations void ExportAssimp2Json(const char *, Assimp::IOSystem *, const aiScene *, const Assimp::ExportProperties *); // small utility class to simplify serializing the aiScene to Json @@ -179,7 +179,6 @@ private: // escape backslashes and single quotes, both would render the JSON invalid if left as is t.reserve(s.length); for (size_t i = 0; i < s.length; ++i) { - if (s.data[i] == '\\' || s.data[i] == '\'' || s.data[i] == '\"') { t.push_back('\\'); } @@ -241,7 +240,7 @@ private: unsigned int flags; }; -void Write(JSONWriter &out, const aiVector3D &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiVector3D &ai, bool is_elem = true) { out.StartArray(is_elem); out.Element(ai.x); out.Element(ai.y); @@ -249,7 +248,7 @@ void Write(JSONWriter &out, const aiVector3D &ai, bool is_elem = true) { out.EndArray(); } -void Write(JSONWriter &out, const aiQuaternion &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiQuaternion &ai, bool is_elem = true) { out.StartArray(is_elem); out.Element(ai.w); out.Element(ai.x); @@ -258,7 +257,7 @@ void Write(JSONWriter &out, const aiQuaternion &ai, bool is_elem = true) { out.EndArray(); } -void Write(JSONWriter &out, const aiColor3D &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiColor3D &ai, bool is_elem = true) { out.StartArray(is_elem); out.Element(ai.r); out.Element(ai.g); @@ -266,7 +265,7 @@ void Write(JSONWriter &out, const aiColor3D &ai, bool is_elem = true) { out.EndArray(); } -void Write(JSONWriter &out, const aiMatrix4x4 &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiMatrix4x4 &ai, bool is_elem = true) { out.StartArray(is_elem); for (unsigned int x = 0; x < 4; ++x) { for (unsigned int y = 0; y < 4; ++y) { @@ -276,7 +275,7 @@ void Write(JSONWriter &out, const aiMatrix4x4 &ai, bool is_elem = true) { out.EndArray(); } -void Write(JSONWriter &out, const aiBone &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiBone &ai, bool is_elem = true) { out.StartObj(is_elem); out.Key("name"); @@ -297,7 +296,7 @@ void Write(JSONWriter &out, const aiBone &ai, bool is_elem = true) { out.EndObj(); } -void Write(JSONWriter &out, const aiFace &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiFace &ai, bool is_elem = true) { out.StartArray(is_elem); for (unsigned int i = 0; i < ai.mNumIndices; ++i) { out.Element(ai.mIndices[i]); @@ -305,7 +304,7 @@ void Write(JSONWriter &out, const aiFace &ai, bool is_elem = true) { out.EndArray(); } -void Write(JSONWriter &out, const aiMesh &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiMesh &ai, bool is_elem = true) { out.StartObj(is_elem); out.Key("name"); @@ -416,7 +415,7 @@ void Write(JSONWriter &out, const aiMesh &ai, bool is_elem = true) { out.EndObj(); } -void Write(JSONWriter &out, const aiNode &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiNode &ai, bool is_elem = true) { out.StartObj(is_elem); out.Key("name"); @@ -446,7 +445,7 @@ void Write(JSONWriter &out, const aiNode &ai, bool is_elem = true) { out.EndObj(); } -void Write(JSONWriter &out, const aiMaterial &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiMaterial &ai, bool is_elem = true) { out.StartObj(is_elem); out.Key("properties"); @@ -466,41 +465,55 @@ void Write(JSONWriter &out, const aiMaterial &ai, bool is_elem = true) { out.Key("value"); switch (prop->mType) { - case aiPTI_Float: - if (prop->mDataLength / sizeof(float) > 1) { - out.StartArray(); - for (unsigned int ii = 0; ii < prop->mDataLength / sizeof(float); ++ii) { - out.Element(reinterpret_cast(prop->mData)[ii]); + case aiPTI_Float: + if (prop->mDataLength / sizeof(float) > 1) { + out.StartArray(); + for (unsigned int ii = 0; ii < prop->mDataLength / sizeof(float); ++ii) { + out.Element(reinterpret_cast(prop->mData)[ii]); + } + out.EndArray(); + } else { + out.SimpleValue(*reinterpret_cast(prop->mData)); } - out.EndArray(); - } else { - out.SimpleValue(*reinterpret_cast(prop->mData)); - } - break; - - case aiPTI_Integer: - if (prop->mDataLength / sizeof(int) > 1) { - out.StartArray(); - for (unsigned int ii = 0; ii < prop->mDataLength / sizeof(int); ++ii) { - out.Element(reinterpret_cast(prop->mData)[ii]); + break; + case aiPTI_Double: + if (prop->mDataLength / sizeof(double) > 1) { + out.StartArray(); + for (unsigned int ii = 0; ii < prop->mDataLength / sizeof(double); ++ii) { + out.Element(reinterpret_cast(prop->mData)[ii]); + } + out.EndArray(); + } else { + out.SimpleValue(*reinterpret_cast(prop->mData)); } - out.EndArray(); - } else { - out.SimpleValue(*reinterpret_cast(prop->mData)); - } - break; + break; + case aiPTI_Integer: + if (prop->mDataLength / sizeof(int) > 1) { + out.StartArray(); + for (unsigned int ii = 0; ii < prop->mDataLength / sizeof(int); ++ii) { + out.Element(reinterpret_cast(prop->mData)[ii]); + } + out.EndArray(); + } else { + out.SimpleValue(*reinterpret_cast(prop->mData)); + } + break; - case aiPTI_String: { - aiString s; - aiGetMaterialString(&ai, prop->mKey.data, prop->mSemantic, prop->mIndex, &s); - out.SimpleValue(s); - } break; - case aiPTI_Buffer: { - // binary data is written as series of hex-encoded octets - out.SimpleValue(prop->mData, prop->mDataLength); - } break; - default: - assert(false); + case aiPTI_String: + { + aiString s; + aiGetMaterialString(&ai, prop->mKey.data, prop->mSemantic, prop->mIndex, &s); + out.SimpleValue(s); + } + break; + case aiPTI_Buffer: + { + // binary data is written as series of hex-encoded octets + out.SimpleValue(prop->mData, prop->mDataLength); + } + break; + default: + ai_assert(false); } out.EndObj(); @@ -510,7 +523,7 @@ void Write(JSONWriter &out, const aiMaterial &ai, bool is_elem = true) { out.EndObj(); } -void Write(JSONWriter &out, const aiTexture &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiTexture &ai, bool is_elem = true) { out.StartObj(is_elem); out.Key("width"); @@ -546,7 +559,7 @@ void Write(JSONWriter &out, const aiTexture &ai, bool is_elem = true) { out.EndObj(); } -void Write(JSONWriter &out, const aiLight &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiLight &ai, bool is_elem = true) { out.StartObj(is_elem); out.Key("name"); @@ -594,7 +607,7 @@ void Write(JSONWriter &out, const aiLight &ai, bool is_elem = true) { out.EndObj(); } -void Write(JSONWriter &out, const aiNodeAnim &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiNodeAnim &ai, bool is_elem = true) { out.StartObj(is_elem); out.Key("name"); @@ -647,7 +660,7 @@ void Write(JSONWriter &out, const aiNodeAnim &ai, bool is_elem = true) { out.EndObj(); } -void Write(JSONWriter &out, const aiAnimation &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiAnimation &ai, bool is_elem = true) { out.StartObj(is_elem); out.Key("name"); @@ -668,7 +681,7 @@ void Write(JSONWriter &out, const aiAnimation &ai, bool is_elem = true) { out.EndObj(); } -void Write(JSONWriter &out, const aiCamera &ai, bool is_elem = true) { +static void Write(JSONWriter &out, const aiCamera &ai, bool is_elem = true) { out.StartObj(is_elem); out.Key("name"); @@ -695,7 +708,7 @@ void Write(JSONWriter &out, const aiCamera &ai, bool is_elem = true) { out.EndObj(); } -void WriteFormatInfo(JSONWriter &out) { +static void WriteFormatInfo(JSONWriter &out) { out.StartObj(); out.Key("format"); out.SimpleValue("\"assimp2json\""); @@ -704,7 +717,7 @@ void WriteFormatInfo(JSONWriter &out) { out.EndObj(); } -void Write(JSONWriter &out, const aiScene &ai) { +static void Write(JSONWriter &out, const aiScene &ai) { out.StartObj(); out.Key("__metadata__"); diff --git a/include/assimp/quaternion.h b/include/assimp/quaternion.h index b6d0a5681..7ab3ad6f8 100644 --- a/include/assimp/quaternion.h +++ b/include/assimp/quaternion.h @@ -4,7 +4,6 @@ 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, @@ -36,7 +35,6 @@ 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. - ---------------------------------------------------------------------- */ @@ -55,21 +53,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +// Forward declarations template class aiVector3t; template class aiMatrix3x3t; template class aiMatrix4x4t; // --------------------------------------------------------------------------- -/** Represents a quaternion in a 4D vector. */ +/** + * @brief This class represents a quaternion as a 4D vector. + */ template -class aiQuaterniont -{ +class aiQuaterniont { public: aiQuaterniont() AI_NO_EXCEPT : w(1.0), x(), y(), z() {} aiQuaterniont(TReal pw, TReal px, TReal py, TReal pz) : w(pw), x(px), y(py), z(pz) {} - /** Construct from rotation matrix. Result is undefined if the matrix is not orthonormal. */ + /** + * @brief Construct from rotation matrix. Result is undefined if the matrix is not orthonormal. + */ explicit aiQuaterniont( const aiMatrix3x3t& pRotMatrix); /** Construct from euler angles */ @@ -84,8 +86,6 @@ public: /** Returns a matrix representation of the quaternion */ aiMatrix3x3t GetMatrix() const; -public: - bool operator== (const aiQuaterniont& o) const; bool operator!= (const aiQuaterniont& o) const; @@ -94,23 +94,30 @@ public: bool Equal(const aiQuaterniont &o, TReal epsilon = ai_epsilon) const; -public: - - /** Normalize the quaternion */ + /** + * @brief Will normalize the quaternion representation. + */ aiQuaterniont& Normalize(); - /** Compute quaternion conjugate */ - aiQuaterniont& Conjugate (); + /** + * @brief Will compute the quaternion conjugate. The result will be stored in the instance. + */ + aiQuaterniont& Conjugate(); - /** Rotate a point by this quaternion */ - aiVector3t Rotate (const aiVector3t& in) const; + /** + * @brief Rotate a point by this quaternion + */ + aiVector3t Rotate(const aiVector3t& in) const; - /** Multiply two quaternions */ - aiQuaterniont operator* (const aiQuaterniont& two) const; + /** + * @brief Multiply two quaternions + * @param two The other quaternion. + * @return The result of the multiplication. + */ + aiQuaterniont operator * (const aiQuaterniont& two) const; -public: - - /** Performs a spherical interpolation between two quaternions and writes the result into the third. + /** + * @brief Performs a spherical interpolation between two quaternions and writes the result into the third. * @param pOut Target object to received the interpolated rotation. * @param pStart Start rotation of the interpolation at factor == 0. * @param pEnd End rotation, factor == 1. @@ -119,13 +126,11 @@ public: static void Interpolate( aiQuaterniont& pOut, const aiQuaterniont& pStart, const aiQuaterniont& pEnd, TReal pFactor); -public: - //! w,x,y,z components of the quaternion TReal w, x, y, z; } ; -typedef aiQuaterniont aiQuaternion; +using aiQuaternion = aiQuaterniont; #else