Fix: Add missing ahndling for double export in json
parent
a3c209f2ca
commit
07aef23d24
|
@ -10,6 +10,7 @@ Licensed under a 3-clause BSD license. See the LICENSE file for more information
|
||||||
#ifndef ASSIMP_BUILD_NO_ASSJSON_EXPORTER
|
#ifndef ASSIMP_BUILD_NO_ASSJSON_EXPORTER
|
||||||
|
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
|
#include <assimp/ai_assert.h>
|
||||||
#include <assimp/Exporter.hpp>
|
#include <assimp/Exporter.hpp>
|
||||||
#include <assimp/IOStream.hpp>
|
#include <assimp/IOStream.hpp>
|
||||||
#include <assimp/IOSystem.hpp>
|
#include <assimp/IOSystem.hpp>
|
||||||
|
@ -23,16 +24,15 @@ Licensed under a 3-clause BSD license. See the LICENSE file for more information
|
||||||
|
|
||||||
#define CURRENT_FORMAT_VERSION 100
|
#define CURRENT_FORMAT_VERSION 100
|
||||||
|
|
||||||
// grab scoped_ptr from assimp to avoid a dependency on boost.
|
|
||||||
//#include <assimp/../../code/BoostWorkaround/boost/scoped_ptr.hpp>
|
|
||||||
|
|
||||||
#include "mesh_splitter.h"
|
#include "mesh_splitter.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
# include "cencode.h"
|
# include "cencode.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
void ExportAssimp2Json(const char *, Assimp::IOSystem *, const aiScene *, const Assimp::ExportProperties *);
|
void ExportAssimp2Json(const char *, Assimp::IOSystem *, const aiScene *, const Assimp::ExportProperties *);
|
||||||
|
|
||||||
// small utility class to simplify serializing the aiScene to Json
|
// 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
|
// escape backslashes and single quotes, both would render the JSON invalid if left as is
|
||||||
t.reserve(s.length);
|
t.reserve(s.length);
|
||||||
for (size_t i = 0; i < s.length; ++i) {
|
for (size_t i = 0; i < s.length; ++i) {
|
||||||
|
|
||||||
if (s.data[i] == '\\' || s.data[i] == '\'' || s.data[i] == '\"') {
|
if (s.data[i] == '\\' || s.data[i] == '\'' || s.data[i] == '\"') {
|
||||||
t.push_back('\\');
|
t.push_back('\\');
|
||||||
}
|
}
|
||||||
|
@ -241,7 +240,7 @@ private:
|
||||||
unsigned int flags;
|
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.StartArray(is_elem);
|
||||||
out.Element(ai.x);
|
out.Element(ai.x);
|
||||||
out.Element(ai.y);
|
out.Element(ai.y);
|
||||||
|
@ -249,7 +248,7 @@ void Write(JSONWriter &out, const aiVector3D &ai, bool is_elem = true) {
|
||||||
out.EndArray();
|
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.StartArray(is_elem);
|
||||||
out.Element(ai.w);
|
out.Element(ai.w);
|
||||||
out.Element(ai.x);
|
out.Element(ai.x);
|
||||||
|
@ -258,7 +257,7 @@ void Write(JSONWriter &out, const aiQuaternion &ai, bool is_elem = true) {
|
||||||
out.EndArray();
|
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.StartArray(is_elem);
|
||||||
out.Element(ai.r);
|
out.Element(ai.r);
|
||||||
out.Element(ai.g);
|
out.Element(ai.g);
|
||||||
|
@ -266,7 +265,7 @@ void Write(JSONWriter &out, const aiColor3D &ai, bool is_elem = true) {
|
||||||
out.EndArray();
|
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);
|
out.StartArray(is_elem);
|
||||||
for (unsigned int x = 0; x < 4; ++x) {
|
for (unsigned int x = 0; x < 4; ++x) {
|
||||||
for (unsigned int y = 0; y < 4; ++y) {
|
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();
|
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.StartObj(is_elem);
|
||||||
|
|
||||||
out.Key("name");
|
out.Key("name");
|
||||||
|
@ -297,7 +296,7 @@ void Write(JSONWriter &out, const aiBone &ai, bool is_elem = true) {
|
||||||
out.EndObj();
|
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);
|
out.StartArray(is_elem);
|
||||||
for (unsigned int i = 0; i < ai.mNumIndices; ++i) {
|
for (unsigned int i = 0; i < ai.mNumIndices; ++i) {
|
||||||
out.Element(ai.mIndices[i]);
|
out.Element(ai.mIndices[i]);
|
||||||
|
@ -305,7 +304,7 @@ void Write(JSONWriter &out, const aiFace &ai, bool is_elem = true) {
|
||||||
out.EndArray();
|
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.StartObj(is_elem);
|
||||||
|
|
||||||
out.Key("name");
|
out.Key("name");
|
||||||
|
@ -416,7 +415,7 @@ void Write(JSONWriter &out, const aiMesh &ai, bool is_elem = true) {
|
||||||
out.EndObj();
|
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.StartObj(is_elem);
|
||||||
|
|
||||||
out.Key("name");
|
out.Key("name");
|
||||||
|
@ -446,7 +445,7 @@ void Write(JSONWriter &out, const aiNode &ai, bool is_elem = true) {
|
||||||
out.EndObj();
|
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.StartObj(is_elem);
|
||||||
|
|
||||||
out.Key("properties");
|
out.Key("properties");
|
||||||
|
@ -477,7 +476,17 @@ void Write(JSONWriter &out, const aiMaterial &ai, bool is_elem = true) {
|
||||||
out.SimpleValue(*reinterpret_cast<float *>(prop->mData));
|
out.SimpleValue(*reinterpret_cast<float *>(prop->mData));
|
||||||
}
|
}
|
||||||
break;
|
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<double*>(prop->mData)[ii]);
|
||||||
|
}
|
||||||
|
out.EndArray();
|
||||||
|
} else {
|
||||||
|
out.SimpleValue(*reinterpret_cast<double*>(prop->mData));
|
||||||
|
}
|
||||||
|
break;
|
||||||
case aiPTI_Integer:
|
case aiPTI_Integer:
|
||||||
if (prop->mDataLength / sizeof(int) > 1) {
|
if (prop->mDataLength / sizeof(int) > 1) {
|
||||||
out.StartArray();
|
out.StartArray();
|
||||||
|
@ -490,17 +499,21 @@ void Write(JSONWriter &out, const aiMaterial &ai, bool is_elem = true) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case aiPTI_String: {
|
case aiPTI_String:
|
||||||
|
{
|
||||||
aiString s;
|
aiString s;
|
||||||
aiGetMaterialString(&ai, prop->mKey.data, prop->mSemantic, prop->mIndex, &s);
|
aiGetMaterialString(&ai, prop->mKey.data, prop->mSemantic, prop->mIndex, &s);
|
||||||
out.SimpleValue(s);
|
out.SimpleValue(s);
|
||||||
} break;
|
}
|
||||||
case aiPTI_Buffer: {
|
break;
|
||||||
|
case aiPTI_Buffer:
|
||||||
|
{
|
||||||
// binary data is written as series of hex-encoded octets
|
// binary data is written as series of hex-encoded octets
|
||||||
out.SimpleValue(prop->mData, prop->mDataLength);
|
out.SimpleValue(prop->mData, prop->mDataLength);
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
ai_assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
out.EndObj();
|
out.EndObj();
|
||||||
|
@ -510,7 +523,7 @@ void Write(JSONWriter &out, const aiMaterial &ai, bool is_elem = true) {
|
||||||
out.EndObj();
|
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.StartObj(is_elem);
|
||||||
|
|
||||||
out.Key("width");
|
out.Key("width");
|
||||||
|
@ -546,7 +559,7 @@ void Write(JSONWriter &out, const aiTexture &ai, bool is_elem = true) {
|
||||||
out.EndObj();
|
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.StartObj(is_elem);
|
||||||
|
|
||||||
out.Key("name");
|
out.Key("name");
|
||||||
|
@ -594,7 +607,7 @@ void Write(JSONWriter &out, const aiLight &ai, bool is_elem = true) {
|
||||||
out.EndObj();
|
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.StartObj(is_elem);
|
||||||
|
|
||||||
out.Key("name");
|
out.Key("name");
|
||||||
|
@ -647,7 +660,7 @@ void Write(JSONWriter &out, const aiNodeAnim &ai, bool is_elem = true) {
|
||||||
out.EndObj();
|
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.StartObj(is_elem);
|
||||||
|
|
||||||
out.Key("name");
|
out.Key("name");
|
||||||
|
@ -668,7 +681,7 @@ void Write(JSONWriter &out, const aiAnimation &ai, bool is_elem = true) {
|
||||||
out.EndObj();
|
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.StartObj(is_elem);
|
||||||
|
|
||||||
out.Key("name");
|
out.Key("name");
|
||||||
|
@ -695,7 +708,7 @@ void Write(JSONWriter &out, const aiCamera &ai, bool is_elem = true) {
|
||||||
out.EndObj();
|
out.EndObj();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteFormatInfo(JSONWriter &out) {
|
static void WriteFormatInfo(JSONWriter &out) {
|
||||||
out.StartObj();
|
out.StartObj();
|
||||||
out.Key("format");
|
out.Key("format");
|
||||||
out.SimpleValue("\"assimp2json\"");
|
out.SimpleValue("\"assimp2json\"");
|
||||||
|
@ -704,7 +717,7 @@ void WriteFormatInfo(JSONWriter &out) {
|
||||||
out.EndObj();
|
out.EndObj();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Write(JSONWriter &out, const aiScene &ai) {
|
static void Write(JSONWriter &out, const aiScene &ai) {
|
||||||
out.StartObj();
|
out.StartObj();
|
||||||
|
|
||||||
out.Key("__metadata__");
|
out.Key("__metadata__");
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2022, assimp team
|
Copyright (c) 2006-2022, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
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
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
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 <assimp/defs.h>
|
#include <assimp/defs.h>
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
template <typename TReal> class aiVector3t;
|
template <typename TReal> class aiVector3t;
|
||||||
template <typename TReal> class aiMatrix3x3t;
|
template <typename TReal> class aiMatrix3x3t;
|
||||||
template <typename TReal> class aiMatrix4x4t;
|
template <typename TReal> class aiMatrix4x4t;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
/** Represents a quaternion in a 4D vector. */
|
/**
|
||||||
|
* @brief This class represents a quaternion as a 4D vector.
|
||||||
|
*/
|
||||||
template <typename TReal>
|
template <typename TReal>
|
||||||
class aiQuaterniont
|
class aiQuaterniont {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
aiQuaterniont() AI_NO_EXCEPT : w(1.0), x(), y(), z() {}
|
aiQuaterniont() AI_NO_EXCEPT : w(1.0), x(), y(), z() {}
|
||||||
aiQuaterniont(TReal pw, TReal px, TReal py, TReal pz)
|
aiQuaterniont(TReal pw, TReal px, TReal py, TReal pz)
|
||||||
: w(pw), x(px), y(py), z(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<TReal>& pRotMatrix);
|
explicit aiQuaterniont( const aiMatrix3x3t<TReal>& pRotMatrix);
|
||||||
|
|
||||||
/** Construct from euler angles */
|
/** Construct from euler angles */
|
||||||
|
@ -84,8 +86,6 @@ public:
|
||||||
/** Returns a matrix representation of the quaternion */
|
/** Returns a matrix representation of the quaternion */
|
||||||
aiMatrix3x3t<TReal> GetMatrix() const;
|
aiMatrix3x3t<TReal> GetMatrix() const;
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
bool operator== (const aiQuaterniont& o) const;
|
bool operator== (const aiQuaterniont& o) const;
|
||||||
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;
|
bool Equal(const aiQuaterniont &o, TReal epsilon = ai_epsilon) const;
|
||||||
|
|
||||||
public:
|
/**
|
||||||
|
* @brief Will normalize the quaternion representation.
|
||||||
/** Normalize the quaternion */
|
*/
|
||||||
aiQuaterniont& Normalize();
|
aiQuaterniont& Normalize();
|
||||||
|
|
||||||
/** Compute quaternion conjugate */
|
/**
|
||||||
|
* @brief Will compute the quaternion conjugate. The result will be stored in the instance.
|
||||||
|
*/
|
||||||
aiQuaterniont& Conjugate();
|
aiQuaterniont& Conjugate();
|
||||||
|
|
||||||
/** Rotate a point by this quaternion */
|
/**
|
||||||
|
* @brief Rotate a point by this quaternion
|
||||||
|
*/
|
||||||
aiVector3t<TReal> Rotate(const aiVector3t<TReal>& in) const;
|
aiVector3t<TReal> Rotate(const aiVector3t<TReal>& in) const;
|
||||||
|
|
||||||
/** Multiply two quaternions */
|
/**
|
||||||
|
* @brief Multiply two quaternions
|
||||||
|
* @param two The other quaternion.
|
||||||
|
* @return The result of the multiplication.
|
||||||
|
*/
|
||||||
aiQuaterniont operator * (const aiQuaterniont& two) const;
|
aiQuaterniont operator * (const aiQuaterniont& two) const;
|
||||||
|
|
||||||
public:
|
/**
|
||||||
|
* @brief Performs a spherical interpolation between two quaternions and writes the result into the third.
|
||||||
/** Performs a spherical interpolation between two quaternions and writes the result into the third.
|
|
||||||
* @param pOut Target object to received the interpolated rotation.
|
* @param pOut Target object to received the interpolated rotation.
|
||||||
* @param pStart Start rotation of the interpolation at factor == 0.
|
* @param pStart Start rotation of the interpolation at factor == 0.
|
||||||
* @param pEnd End rotation, factor == 1.
|
* @param pEnd End rotation, factor == 1.
|
||||||
|
@ -119,13 +126,11 @@ public:
|
||||||
static void Interpolate( aiQuaterniont& pOut, const aiQuaterniont& pStart,
|
static void Interpolate( aiQuaterniont& pOut, const aiQuaterniont& pStart,
|
||||||
const aiQuaterniont& pEnd, TReal pFactor);
|
const aiQuaterniont& pEnd, TReal pFactor);
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//! w,x,y,z components of the quaternion
|
//! w,x,y,z components of the quaternion
|
||||||
TReal w, x, y, z;
|
TReal w, x, y, z;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
typedef aiQuaterniont<ai_real> aiQuaternion;
|
using aiQuaternion = aiQuaterniont<ai_real>;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue