Move duplicate code to glFT common header.
parent
18531e3677
commit
0fef0e1101
File diff suppressed because it is too large
Load Diff
|
@ -56,130 +56,11 @@ using namespace glTFCommon;
|
|||
|
||||
namespace glTF {
|
||||
|
||||
namespace {
|
||||
|
||||
#if _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4706)
|
||||
#endif // _MSC_VER
|
||||
|
||||
//
|
||||
// JSON Value reading helpers
|
||||
//
|
||||
|
||||
template <class T>
|
||||
struct ReadHelper {
|
||||
static bool Read(Value &val, T &out) {
|
||||
return val.IsInt() ? out = static_cast<T>(val.GetInt()), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<bool> {
|
||||
static bool Read(Value &val, bool &out) {
|
||||
return val.IsBool() ? out = val.GetBool(), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<float> {
|
||||
static bool Read(Value &val, float &out) {
|
||||
return val.IsNumber() ? out = static_cast<float>(val.GetDouble()), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <unsigned int N>
|
||||
struct ReadHelper<float[N]> {
|
||||
static bool Read(Value &val, float (&out)[N]) {
|
||||
if (!val.IsArray() || val.Size() != N) return false;
|
||||
for (unsigned int i = 0; i < N; ++i) {
|
||||
if (val[i].IsNumber())
|
||||
out[i] = static_cast<float>(val[i].GetDouble());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<const char *> {
|
||||
static bool Read(Value &val, const char *&out) {
|
||||
return val.IsString() ? (out = val.GetString(), true) : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<std::string> {
|
||||
static bool Read(Value &val, std::string &out) {
|
||||
return val.IsString() ? (out = std::string(val.GetString(), val.GetStringLength()), true) : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct ReadHelper<Nullable<T>> {
|
||||
static bool Read(Value &val, Nullable<T> &out) {
|
||||
return out.isPresent = ReadHelper<T>::Read(val, out.value);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<uint64_t> {
|
||||
static bool Read(Value &val, uint64_t &out) {
|
||||
return val.IsUint64() ? out = val.GetUint64(), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<int64_t> {
|
||||
static bool Read(Value &val, int64_t &out) {
|
||||
return val.IsInt64() ? out = val.GetInt64(), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline static bool ReadValue(Value &val, T &out) {
|
||||
return ReadHelper<T>::Read(val, out);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline static bool ReadMember(Value &obj, const char *id, T &out) {
|
||||
Value::MemberIterator it = obj.FindMember(id);
|
||||
if (it != obj.MemberEnd()) {
|
||||
return ReadHelper<T>::Read(it->value, out);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline static T MemberOrDefault(Value &obj, const char *id, T defaultValue) {
|
||||
T out;
|
||||
return ReadMember(obj, id, out) ? out : defaultValue;
|
||||
}
|
||||
|
||||
inline Value *FindMember(Value &val, const char *id) {
|
||||
Value::MemberIterator it = val.FindMember(id);
|
||||
return (it != val.MemberEnd()) ? &it->value : 0;
|
||||
}
|
||||
|
||||
inline Value *FindString(Value &val, const char *id) {
|
||||
Value::MemberIterator it = val.FindMember(id);
|
||||
return (it != val.MemberEnd() && it->value.IsString()) ? &it->value : 0;
|
||||
}
|
||||
|
||||
inline Value *FindNumber(Value &val, const char *id) {
|
||||
Value::MemberIterator it = val.FindMember(id);
|
||||
return (it != val.MemberEnd() && it->value.IsNumber()) ? &it->value : 0;
|
||||
}
|
||||
|
||||
inline Value *FindArray(Value &val, const char *id) {
|
||||
Value::MemberIterator it = val.FindMember(id);
|
||||
return (it != val.MemberEnd() && it->value.IsArray()) ? &it->value : 0;
|
||||
}
|
||||
|
||||
inline Value *FindObject(Value &val, const char *id) {
|
||||
Value::MemberIterator it = val.FindMember(id);
|
||||
return (it != val.MemberEnd() && it->value.IsObject()) ? &it->value : 0;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
//
|
||||
// LazyDict methods
|
||||
|
|
|
@ -56,33 +56,40 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <rapidjson/error/en.h>
|
||||
#include <rapidjson/rapidjson.h>
|
||||
|
||||
// clang-format off
|
||||
|
||||
#ifdef ASSIMP_API
|
||||
#include <assimp/ByteSwapper.h>
|
||||
#include <assimp/DefaultIOSystem.h>
|
||||
#include <memory>
|
||||
# include <assimp/ByteSwapper.h>
|
||||
# include <assimp/DefaultIOSystem.h>
|
||||
# include <memory>
|
||||
#else
|
||||
#include <memory>
|
||||
#define AI_SWAP4(p)
|
||||
#define ai_assert
|
||||
# include <memory>
|
||||
# define AI_SWAP4(p)
|
||||
# define ai_assert
|
||||
#endif
|
||||
|
||||
#if _MSC_VER > 1500 || (defined __GNUC___)
|
||||
#define ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
|
||||
# define ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
|
||||
#else
|
||||
#define gltf_unordered_map map
|
||||
# define gltf_unordered_map map
|
||||
#endif
|
||||
|
||||
#ifdef ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
|
||||
#include <unordered_map>
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1600
|
||||
#define gltf_unordered_map tr1::unordered_map
|
||||
#else
|
||||
#define gltf_unordered_map unordered_map
|
||||
#endif
|
||||
# include <unordered_map>
|
||||
# if defined(_MSC_VER) && _MSC_VER <= 1600
|
||||
# define gltf_unordered_map tr1::unordered_map
|
||||
# else
|
||||
# define gltf_unordered_map unordered_map
|
||||
# endif
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
|
||||
namespace glTFCommon {
|
||||
|
||||
using rapidjson::Document;
|
||||
using rapidjson::Value;
|
||||
|
||||
#ifdef ASSIMP_API
|
||||
using Assimp::IOStream;
|
||||
using Assimp::IOSystem;
|
||||
|
@ -193,7 +200,6 @@ inline void CopyValue(const glTFCommon::mat4 &v, aiMatrix4x4 &o) {
|
|||
#endif // _MSC_VER
|
||||
|
||||
inline std::string getCurrentAssetDir(const std::string &pFile) {
|
||||
std::string path = pFile;
|
||||
int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
|
||||
if (pos == int(std::string::npos)) {
|
||||
return std::string();
|
||||
|
@ -262,6 +268,284 @@ void EncodeBase64(const uint8_t *in, size_t inLength, std::string &out);
|
|||
#define CHECK_EXT(EXT) \
|
||||
if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true;
|
||||
|
||||
|
||||
|
||||
//! Helper struct to represent values that might not be present
|
||||
template <class T>
|
||||
struct Nullable {
|
||||
T value;
|
||||
bool isPresent;
|
||||
|
||||
Nullable() :
|
||||
isPresent(false) {}
|
||||
Nullable(T &val) :
|
||||
value(val),
|
||||
isPresent(true) {}
|
||||
};
|
||||
|
||||
//! A reference to one top-level object, which is valid
|
||||
//! until the Asset instance is destroyed
|
||||
template <class T>
|
||||
class Ref {
|
||||
std::vector<T *> *vector;
|
||||
unsigned int index;
|
||||
|
||||
public:
|
||||
Ref() :
|
||||
vector(0),
|
||||
index(0) {}
|
||||
Ref(std::vector<T *> &vec, unsigned int idx) :
|
||||
vector(&vec),
|
||||
index(idx) {}
|
||||
|
||||
inline unsigned int GetIndex() const { return index; }
|
||||
|
||||
operator bool() const { return vector != 0; }
|
||||
|
||||
T *operator->() { return (*vector)[index]; }
|
||||
|
||||
T &operator*() { return *((*vector)[index]); }
|
||||
};
|
||||
|
||||
//
|
||||
// JSON Value reading helpers
|
||||
//
|
||||
|
||||
template <class T>
|
||||
struct ReadHelper {
|
||||
static bool Read(Value &val, T &out) {
|
||||
return val.IsInt() ? out = static_cast<T>(val.GetInt()), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<bool> {
|
||||
static bool Read(Value &val, bool &out) {
|
||||
return val.IsBool() ? out = val.GetBool(), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<float> {
|
||||
static bool Read(Value &val, float &out) {
|
||||
return val.IsNumber() ? out = static_cast<float>(val.GetDouble()), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <unsigned int N>
|
||||
struct ReadHelper<float[N]> {
|
||||
static bool Read(Value &val, float (&out)[N]) {
|
||||
if (!val.IsArray() || val.Size() != N) return false;
|
||||
for (unsigned int i = 0; i < N; ++i) {
|
||||
if (val[i].IsNumber())
|
||||
out[i] = static_cast<float>(val[i].GetDouble());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<const char *> {
|
||||
static bool Read(Value &val, const char *&out) {
|
||||
return val.IsString() ? (out = val.GetString(), true) : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<std::string> {
|
||||
static bool Read(Value &val, std::string &out) {
|
||||
return val.IsString() ? (out = std::string(val.GetString(), val.GetStringLength()), true) : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct ReadHelper<Nullable<T>> {
|
||||
static bool Read(Value &val, Nullable<T> &out) {
|
||||
return out.isPresent = ReadHelper<T>::Read(val, out.value);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<uint64_t> {
|
||||
static bool Read(Value &val, uint64_t &out) {
|
||||
return val.IsUint64() ? out = val.GetUint64(), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<int64_t> {
|
||||
static bool Read(Value &val, int64_t &out) {
|
||||
return val.IsInt64() ? out = val.GetInt64(), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline static bool ReadValue(Value &val, T &out) {
|
||||
return ReadHelper<T>::Read(val, out);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline static bool ReadMember(Value &obj, const char *id, T &out) {
|
||||
if (!obj.IsObject()) {
|
||||
return false;
|
||||
}
|
||||
Value::MemberIterator it = obj.FindMember(id);
|
||||
if (it != obj.MemberEnd()) {
|
||||
return ReadHelper<T>::Read(it->value, out);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline static T MemberOrDefault(Value &obj, const char *id, T defaultValue) {
|
||||
T out;
|
||||
return ReadMember(obj, id, out) ? out : defaultValue;
|
||||
}
|
||||
|
||||
inline Value *FindMember(Value &val, const char *id) {
|
||||
if (!val.IsObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
Value::MemberIterator it = val.FindMember(id);
|
||||
return (it != val.MemberEnd()) ? &it->value : nullptr;
|
||||
}
|
||||
|
||||
template <int N>
|
||||
inline void throwUnexpectedTypeError(const char (&expectedTypeName)[N], const char *memberId, const char *context, const char *extraContext) {
|
||||
std::string fullContext = context;
|
||||
if (extraContext && (strlen(extraContext) > 0)) {
|
||||
fullContext = fullContext + " (" + extraContext + ")";
|
||||
}
|
||||
throw DeadlyImportError("Member \"", memberId, "\" was not of type \"", expectedTypeName, "\" when reading ", fullContext);
|
||||
}
|
||||
|
||||
// Look-up functions with type checks. Context and extra context help the user identify the problem if there's an error.
|
||||
|
||||
inline Value *FindStringInContext(Value &val, const char *memberId, const char *context, const char *extraContext = nullptr) {
|
||||
if (!val.IsObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
Value::MemberIterator it = val.FindMember(memberId);
|
||||
if (it == val.MemberEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!it->value.IsString()) {
|
||||
throwUnexpectedTypeError("string", memberId, context, extraContext);
|
||||
}
|
||||
return &it->value;
|
||||
}
|
||||
|
||||
inline Value *FindNumberInContext(Value &val, const char *memberId, const char *context, const char *extraContext = nullptr) {
|
||||
if (!val.IsObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
Value::MemberIterator it = val.FindMember(memberId);
|
||||
if (it == val.MemberEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!it->value.IsNumber()) {
|
||||
throwUnexpectedTypeError("number", memberId, context, extraContext);
|
||||
}
|
||||
return &it->value;
|
||||
}
|
||||
|
||||
inline Value *FindUIntInContext(Value &val, const char *memberId, const char *context, const char *extraContext = nullptr) {
|
||||
if (!val.IsObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
Value::MemberIterator it = val.FindMember(memberId);
|
||||
if (it == val.MemberEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!it->value.IsUint()) {
|
||||
throwUnexpectedTypeError("uint", memberId, context, extraContext);
|
||||
}
|
||||
return &it->value;
|
||||
}
|
||||
|
||||
inline Value *FindArrayInContext(Value &val, const char *memberId, const char *context, const char *extraContext = nullptr) {
|
||||
if (!val.IsObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
Value::MemberIterator it = val.FindMember(memberId);
|
||||
if (it == val.MemberEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!it->value.IsArray()) {
|
||||
throwUnexpectedTypeError("array", memberId, context, extraContext);
|
||||
}
|
||||
return &it->value;
|
||||
}
|
||||
|
||||
inline Value *FindObjectInContext(Value &val, const char *memberId, const char *context, const char *extraContext = nullptr) {
|
||||
if (!val.IsObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
Value::MemberIterator it = val.FindMember(memberId);
|
||||
if (it == val.MemberEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!it->value.IsObject()) {
|
||||
throwUnexpectedTypeError("object", memberId, context, extraContext);
|
||||
}
|
||||
return &it->value;
|
||||
}
|
||||
|
||||
inline Value *FindExtensionInContext(Value &val, const char *extensionId, const char *context, const char *extraContext = nullptr) {
|
||||
if (Value *extensionList = FindObjectInContext(val, "extensions", context, extraContext)) {
|
||||
if (Value *extension = FindObjectInContext(*extensionList, extensionId, context, extraContext)) {
|
||||
return extension;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Overloads when the value is the document.
|
||||
|
||||
inline Value *FindString(Document &doc, const char *memberId) {
|
||||
return FindStringInContext(doc, memberId, "the document");
|
||||
}
|
||||
|
||||
inline Value *FindNumber(Document &doc, const char *memberId) {
|
||||
return FindNumberInContext(doc, memberId, "the document");
|
||||
}
|
||||
|
||||
inline Value *FindUInt(Document &doc, const char *memberId) {
|
||||
return FindUIntInContext(doc, memberId, "the document");
|
||||
}
|
||||
|
||||
inline Value *FindArray(Document &val, const char *memberId) {
|
||||
return FindArrayInContext(val, memberId, "the document");
|
||||
}
|
||||
|
||||
inline Value *FindObject(Document &doc, const char *memberId) {
|
||||
return FindObjectInContext(doc, memberId, "the document");
|
||||
}
|
||||
|
||||
inline Value *FindExtension(Value &val, const char *extensionId) {
|
||||
return FindExtensionInContext(val, extensionId, "the document");
|
||||
}
|
||||
|
||||
inline Value *FindString(Value &val, const char *id) {
|
||||
Value::MemberIterator it = val.FindMember(id);
|
||||
return (it != val.MemberEnd() && it->value.IsString()) ? &it->value : 0;
|
||||
}
|
||||
|
||||
inline Value *FindObject(Value &val, const char *id) {
|
||||
Value::MemberIterator it = val.FindMember(id);
|
||||
return (it != val.MemberEnd() && it->value.IsObject()) ? &it->value : 0;
|
||||
}
|
||||
|
||||
inline Value *FindArray(Value &val, const char *id) {
|
||||
Value::MemberIterator it = val.FindMember(id);
|
||||
return (it != val.MemberEnd() && it->value.IsArray()) ? &it->value : 0;
|
||||
}
|
||||
|
||||
inline Value *FindNumber(Value &val, const char *id) {
|
||||
Value::MemberIterator it = val.FindMember(id);
|
||||
return (it != val.MemberEnd() && it->value.IsNumber()) ? &it->value : 0;
|
||||
}
|
||||
|
||||
} // namespace glTFCommon
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER
|
||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2021, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
@ -41,79 +40,79 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
*/
|
||||
|
||||
/** @file GltfExporter.h
|
||||
* Declares the exporter class to write a scene to a gltf/glb file
|
||||
*/
|
||||
* Declares the exporter class to write a scene to a gltf/glb file
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef AI_GLTFEXPORTER_H_INC
|
||||
#define AI_GLTFEXPORTER_H_INC
|
||||
|
||||
#if !defined(ASSIMP_BUILD_NO_GLTF_EXPORTER) && !defined(ASSIMP_BUILD_NO_GLTF1_EXPORTER)
|
||||
|
||||
#include <assimp/types.h>
|
||||
#include <assimp/material.h>
|
||||
#include <assimp/types.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
struct aiScene;
|
||||
struct aiNode;
|
||||
struct aiMaterial;
|
||||
|
||||
namespace glTF
|
||||
{
|
||||
template<class T>
|
||||
class Ref;
|
||||
|
||||
class Asset;
|
||||
struct TexProperty;
|
||||
struct Node;
|
||||
}
|
||||
|
||||
namespace Assimp
|
||||
{
|
||||
class IOSystem;
|
||||
class IOStream;
|
||||
class ExportProperties;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/** Helper class to export a given scene to an glTF file. */
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class glTFExporter
|
||||
{
|
||||
public:
|
||||
/// Constructor for a specific scene to export
|
||||
glTFExporter(const char* filename, IOSystem* pIOSystem, const aiScene* pScene,
|
||||
const ExportProperties* pProperties, bool binary);
|
||||
|
||||
private:
|
||||
|
||||
const char* mFilename;
|
||||
IOSystem* mIOSystem;
|
||||
std::shared_ptr<const aiScene> mScene;
|
||||
const ExportProperties* mProperties;
|
||||
|
||||
std::map<std::string, unsigned int> mTexturesByPath;
|
||||
|
||||
std::shared_ptr<glTF::Asset> mAsset;
|
||||
|
||||
std::vector<unsigned char> mBodyData;
|
||||
|
||||
void WriteBinaryData(IOStream* outfile, std::size_t sceneLength);
|
||||
|
||||
void GetTexSampler(const aiMaterial* mat, glTF::TexProperty& prop);
|
||||
void GetMatColorOrTex(const aiMaterial* mat, glTF::TexProperty& prop, const char* propName, int type, int idx, aiTextureType tt);
|
||||
void ExportMetadata();
|
||||
void ExportMaterials();
|
||||
void ExportMeshes();
|
||||
unsigned int ExportNodeHierarchy(const aiNode* n);
|
||||
unsigned int ExportNode(const aiNode* node, glTF::Ref<glTF::Node>& parent);
|
||||
void ExportScene();
|
||||
void ExportAnimations();
|
||||
};
|
||||
namespace glTFCommon {
|
||||
template <class T>
|
||||
class Ref;
|
||||
|
||||
}
|
||||
|
||||
namespace glTF {
|
||||
class Asset;
|
||||
struct TexProperty;
|
||||
struct Node;
|
||||
|
||||
} // namespace glTF
|
||||
|
||||
namespace Assimp {
|
||||
class IOSystem;
|
||||
class IOStream;
|
||||
class ExportProperties;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/** Helper class to export a given scene to an glTF file. */
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class glTFExporter {
|
||||
public:
|
||||
/// Constructor for a specific scene to export
|
||||
glTFExporter(const char *filename, IOSystem *pIOSystem, const aiScene *pScene,
|
||||
const ExportProperties *pProperties, bool binary);
|
||||
|
||||
private:
|
||||
const char *mFilename;
|
||||
IOSystem *mIOSystem;
|
||||
std::shared_ptr<const aiScene> mScene;
|
||||
const ExportProperties *mProperties;
|
||||
|
||||
std::map<std::string, unsigned int> mTexturesByPath;
|
||||
|
||||
std::shared_ptr<glTF::Asset> mAsset;
|
||||
|
||||
std::vector<unsigned char> mBodyData;
|
||||
|
||||
void WriteBinaryData(IOStream *outfile, std::size_t sceneLength);
|
||||
|
||||
void GetTexSampler(const aiMaterial *mat, glTF::TexProperty &prop);
|
||||
void GetMatColorOrTex(const aiMaterial *mat, glTF::TexProperty &prop, const char *propName, int type, int idx, aiTextureType tt);
|
||||
void ExportMetadata();
|
||||
void ExportMaterials();
|
||||
void ExportMeshes();
|
||||
unsigned int ExportNodeHierarchy(const aiNode *n);
|
||||
unsigned int ExportNode(const aiNode *node, glTFCommon::Ref<glTF::Node> & parent);
|
||||
void ExportScene();
|
||||
void ExportAnimations();
|
||||
};
|
||||
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_GLTF_EXPORTER
|
||||
|
||||
#endif // AI_GLTFEXPORTER_H_INC
|
||||
|
|
|
@ -49,7 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
struct aiNode;
|
||||
|
||||
namespace glTF {
|
||||
class Asset;
|
||||
class Asset;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// clang-format off
|
||||
#if (__GNUC__ == 8 && __GNUC_MINOR__ >= 0)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wclass-memaccess"
|
||||
|
@ -75,37 +76,38 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <rapidjson/rapidjson.h>
|
||||
|
||||
#if (__GNUC__ == 8 && __GNUC_MINOR__ >= 0)
|
||||
#pragma GCC diagnostic pop
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#ifdef ASSIMP_API
|
||||
#include <assimp/ByteSwapper.h>
|
||||
#include <assimp/DefaultIOSystem.h>
|
||||
#include <memory>
|
||||
# include <assimp/ByteSwapper.h>
|
||||
# include <assimp/DefaultIOSystem.h>
|
||||
# include <memory>
|
||||
#else
|
||||
#include <memory>
|
||||
#define AI_SWAP4(p)
|
||||
#define ai_assert
|
||||
# include <memory>
|
||||
# define AI_SWAP4(p)
|
||||
# define ai_assert
|
||||
#endif
|
||||
|
||||
#if _MSC_VER > 1500 || (defined __GNUC___)
|
||||
#define ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
|
||||
# define ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
|
||||
#else
|
||||
#define gltf_unordered_map map
|
||||
#define gltf_unordered_set set
|
||||
# define gltf_unordered_map map
|
||||
# define gltf_unordered_set set
|
||||
#endif
|
||||
|
||||
#ifdef ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1600
|
||||
#define gltf_unordered_map tr1::unordered_map
|
||||
#define gltf_unordered_set tr1::unordered_set
|
||||
#else
|
||||
#define gltf_unordered_map unordered_map
|
||||
#define gltf_unordered_set unordered_set
|
||||
#endif
|
||||
# include <unordered_map>
|
||||
# include <unordered_set>
|
||||
# if defined(_MSC_VER) && _MSC_VER <= 1600
|
||||
# define gltf_unordered_map tr1::unordered_map
|
||||
# define gltf_unordered_set tr1::unordered_set
|
||||
# else
|
||||
# define gltf_unordered_map unordered_map
|
||||
# define gltf_unordered_set unordered_set
|
||||
# endif
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
#include <assimp/StringUtils.h>
|
||||
|
||||
|
@ -113,6 +115,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
namespace glTF2 {
|
||||
|
||||
using glTFCommon::Nullable;
|
||||
using glTFCommon::Ref;
|
||||
using glTFCommon::IOStream;
|
||||
using glTFCommon::IOSystem;
|
||||
using glTFCommon::shared_ptr;
|
||||
|
@ -319,44 +323,9 @@ const AttribType::Info
|
|||
{ "SCALAR", 1 }, { "VEC2", 2 }, { "VEC3", 3 }, { "VEC4", 4 }, { "MAT2", 4 }, { "MAT3", 9 }, { "MAT4", 16 }
|
||||
};
|
||||
|
||||
//! A reference to one top-level object, which is valid
|
||||
//! until the Asset instance is destroyed
|
||||
template <class T>
|
||||
class Ref {
|
||||
std::vector<T *> *vector;
|
||||
unsigned int index;
|
||||
|
||||
public:
|
||||
Ref() :
|
||||
vector(0),
|
||||
index(0) {}
|
||||
Ref(std::vector<T *> &vec, unsigned int idx) :
|
||||
vector(&vec),
|
||||
index(idx) {}
|
||||
|
||||
inline unsigned int GetIndex() const { return index; }
|
||||
|
||||
operator bool() const { return vector != 0; }
|
||||
|
||||
T *operator->() { return (*vector)[index]; }
|
||||
|
||||
T &operator*() { return *((*vector)[index]); }
|
||||
};
|
||||
|
||||
//! Helper struct to represent values that might not be present
|
||||
template <class T>
|
||||
struct Nullable {
|
||||
T value;
|
||||
bool isPresent;
|
||||
|
||||
Nullable() :
|
||||
isPresent(false) {}
|
||||
Nullable(T &val) :
|
||||
value(val),
|
||||
isPresent(true) {}
|
||||
};
|
||||
|
||||
struct CustomExtension {
|
||||
|
||||
//
|
||||
// A struct containing custom extension data added to a glTF2 file
|
||||
// Has to contain Object, Array, String, Double, Uint64, and Int64 at a minimum
|
||||
|
@ -553,7 +522,7 @@ public:
|
|||
|
||||
void MarkAsSpecial() { mIsSpecial = true; }
|
||||
|
||||
bool IsSpecial() const { return mIsSpecial; }
|
||||
bool IsSpecial() const override { return mIsSpecial; }
|
||||
|
||||
std::string GetURI() { return std::string(this->id) + ".bin"; }
|
||||
|
||||
|
@ -849,7 +818,7 @@ struct Material : public Object {
|
|||
|
||||
//! A set of primitives to be rendered. A node can contain one or more meshes. A node's transform places the mesh in the scene.
|
||||
struct Mesh : public Object {
|
||||
typedef std::vector<Ref<Accessor>> AccessorList;
|
||||
using AccessorList = std::vector<Ref<Accessor>>;
|
||||
|
||||
struct Primitive {
|
||||
PrimitiveMode mode;
|
||||
|
@ -880,7 +849,6 @@ struct Mesh : public Object {
|
|||
|
||||
Mesh() {}
|
||||
|
||||
/// \fn void Read(Value& pJSON_Object, Asset& pAsset_Root)
|
||||
/// Get mesh data from JSON-object and place them to root asset.
|
||||
/// \param [in] pJSON_Object - reference to pJSON-object from which data are read.
|
||||
/// \param [out] pAsset_Root - reference to root asset where data will be stored.
|
||||
|
@ -1023,8 +991,8 @@ class LazyDict : public LazyDictBase {
|
|||
friend class Asset;
|
||||
friend class AssetWriter;
|
||||
|
||||
typedef typename std::gltf_unordered_map<unsigned int, unsigned int> Dict;
|
||||
typedef typename std::gltf_unordered_map<std::string, unsigned int> IdDict;
|
||||
using Dict = typename std::gltf_unordered_map<unsigned int, unsigned int>;
|
||||
using IdDict = typename std::gltf_unordered_map<std::string, unsigned int>;
|
||||
|
||||
std::vector<T *> mObjs; //! The read objects
|
||||
Dict mObjsByOIndex; //! The read objects accessible by original index
|
||||
|
@ -1087,7 +1055,7 @@ struct AssetMetadata {
|
|||
|
||||
//! Root object for a glTF asset
|
||||
class Asset {
|
||||
typedef std::gltf_unordered_map<std::string, int> IdMap;
|
||||
using IdMap = std::gltf_unordered_map<std::string, int>;
|
||||
|
||||
template <class T>
|
||||
friend class LazyDict;
|
||||
|
|
|
@ -45,40 +45,43 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/StringUtils.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
|
||||
// clang-format off
|
||||
#ifdef ASSIMP_ENABLE_DRACO
|
||||
|
||||
// Google draco library headers spew many warnings. Bad Google, no cookie
|
||||
#if _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4018) // Signed/unsigned mismatch
|
||||
#pragma warning(disable : 4804) // Unsafe use of type 'bool'
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wsign-compare"
|
||||
#elif defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#if (__GNUC__ > 4)
|
||||
#pragma GCC diagnostic ignored "-Wbool-compare"
|
||||
#endif
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
# if _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4018) // Signed/unsigned mismatch
|
||||
# pragma warning(disable : 4804) // Unsafe use of type 'bool'
|
||||
# elif defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wsign-compare"
|
||||
# elif defined(__GNUC__)
|
||||
# pragma GCC diagnostic push
|
||||
# if (__GNUC__ > 4)
|
||||
# pragma GCC diagnostic ignored "-Wbool-compare"
|
||||
# endif
|
||||
# pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#endif
|
||||
|
||||
#include "draco/compression/decode.h"
|
||||
#include "draco/core/decoder_buffer.h"
|
||||
|
||||
#if _MSC_VER
|
||||
#pragma warning(pop)
|
||||
# pragma warning(pop)
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
# pragma clang diagnostic pop
|
||||
#elif defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifndef DRACO_MESH_COMPRESSION_SUPPORTED
|
||||
#error glTF: KHR_draco_mesh_compression: draco library must have DRACO_MESH_COMPRESSION_SUPPORTED
|
||||
# error glTF: KHR_draco_mesh_compression: draco library must have DRACO_MESH_COMPRESSION_SUPPORTED
|
||||
#endif
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
using namespace Assimp;
|
||||
using namespace glTFCommon;
|
||||
|
||||
namespace glTF2 {
|
||||
|
||||
|
@ -88,222 +91,6 @@ namespace {
|
|||
// JSON Value reading helpers
|
||||
//
|
||||
|
||||
template <class T>
|
||||
struct ReadHelper {
|
||||
static bool Read(Value &val, T &out) {
|
||||
return val.IsInt() ? out = static_cast<T>(val.GetInt()), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<bool> {
|
||||
static bool Read(Value &val, bool &out) {
|
||||
return val.IsBool() ? out = val.GetBool(), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<float> {
|
||||
static bool Read(Value &val, float &out) {
|
||||
return val.IsNumber() ? out = static_cast<float>(val.GetDouble()), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <unsigned int N>
|
||||
struct ReadHelper<float[N]> {
|
||||
static bool Read(Value &val, float (&out)[N]) {
|
||||
if (!val.IsArray() || val.Size() != N) return false;
|
||||
for (unsigned int i = 0; i < N; ++i) {
|
||||
if (val[i].IsNumber())
|
||||
out[i] = static_cast<float>(val[i].GetDouble());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<const char *> {
|
||||
static bool Read(Value &val, const char *&out) {
|
||||
return val.IsString() ? (out = val.GetString(), true) : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<std::string> {
|
||||
static bool Read(Value &val, std::string &out) {
|
||||
return val.IsString() ? (out = std::string(val.GetString(), val.GetStringLength()), true) : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<uint64_t> {
|
||||
static bool Read(Value &val, uint64_t &out) {
|
||||
return val.IsUint64() ? out = val.GetUint64(), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ReadHelper<int64_t> {
|
||||
static bool Read(Value &val, int64_t &out) {
|
||||
return val.IsInt64() ? out = val.GetInt64(), true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct ReadHelper<Nullable<T>> {
|
||||
static bool Read(Value &val, Nullable<T> &out) {
|
||||
return out.isPresent = ReadHelper<T>::Read(val, out.value);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline static bool ReadValue(Value &val, T &out) {
|
||||
return ReadHelper<T>::Read(val, out);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline static bool ReadMember(Value &obj, const char *id, T &out) {
|
||||
if (!obj.IsObject()) {
|
||||
return false;
|
||||
}
|
||||
Value::MemberIterator it = obj.FindMember(id);
|
||||
if (it != obj.MemberEnd()) {
|
||||
return ReadHelper<T>::Read(it->value, out);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline static T MemberOrDefault(Value &obj, const char *id, T defaultValue) {
|
||||
T out;
|
||||
return ReadMember(obj, id, out) ? out : defaultValue;
|
||||
}
|
||||
|
||||
inline Value *FindMember(Value &val, const char *id) {
|
||||
if (!val.IsObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
Value::MemberIterator it = val.FindMember(id);
|
||||
return (it != val.MemberEnd()) ? &it->value : nullptr;
|
||||
}
|
||||
|
||||
template<int N>
|
||||
inline void throwUnexpectedTypeError(const char (&expectedTypeName)[N], const char* memberId, const char* context, const char* extraContext) {
|
||||
std::string fullContext = context;
|
||||
if (extraContext && (strlen(extraContext) > 0))
|
||||
{
|
||||
fullContext = fullContext + " (" + extraContext + ")";
|
||||
}
|
||||
throw DeadlyImportError("Member \"", memberId, "\" was not of type \"", expectedTypeName, "\" when reading ", fullContext);
|
||||
}
|
||||
|
||||
// Look-up functions with type checks. Context and extra context help the user identify the problem if there's an error.
|
||||
|
||||
inline Value *FindStringInContext(Value &val, const char *memberId, const char* context, const char* extraContext = nullptr) {
|
||||
if (!val.IsObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
Value::MemberIterator it = val.FindMember(memberId);
|
||||
if (it == val.MemberEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!it->value.IsString()) {
|
||||
throwUnexpectedTypeError("string", memberId, context, extraContext);
|
||||
}
|
||||
return &it->value;
|
||||
}
|
||||
|
||||
inline Value *FindNumberInContext(Value &val, const char *memberId, const char* context, const char* extraContext = nullptr) {
|
||||
if (!val.IsObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
Value::MemberIterator it = val.FindMember(memberId);
|
||||
if (it == val.MemberEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!it->value.IsNumber()) {
|
||||
throwUnexpectedTypeError("number", memberId, context, extraContext);
|
||||
}
|
||||
return &it->value;
|
||||
}
|
||||
|
||||
inline Value *FindUIntInContext(Value &val, const char *memberId, const char* context, const char* extraContext = nullptr) {
|
||||
if (!val.IsObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
Value::MemberIterator it = val.FindMember(memberId);
|
||||
if (it == val.MemberEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!it->value.IsUint()) {
|
||||
throwUnexpectedTypeError("uint", memberId, context, extraContext);
|
||||
}
|
||||
return &it->value;
|
||||
}
|
||||
|
||||
inline Value *FindArrayInContext(Value &val, const char *memberId, const char* context, const char* extraContext = nullptr) {
|
||||
if (!val.IsObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
Value::MemberIterator it = val.FindMember(memberId);
|
||||
if (it == val.MemberEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!it->value.IsArray()) {
|
||||
throwUnexpectedTypeError("array", memberId, context, extraContext);
|
||||
}
|
||||
return &it->value;
|
||||
}
|
||||
|
||||
inline Value *FindObjectInContext(Value &val, const char *memberId, const char* context, const char* extraContext = nullptr) {
|
||||
if (!val.IsObject()) {
|
||||
return nullptr;
|
||||
}
|
||||
Value::MemberIterator it = val.FindMember(memberId);
|
||||
if (it == val.MemberEnd()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!it->value.IsObject()) {
|
||||
throwUnexpectedTypeError("object", memberId, context, extraContext);
|
||||
}
|
||||
return &it->value;
|
||||
}
|
||||
|
||||
inline Value *FindExtensionInContext(Value &val, const char *extensionId, const char* context, const char* extraContext = nullptr) {
|
||||
if (Value *extensionList = FindObjectInContext(val, "extensions", context, extraContext)) {
|
||||
if (Value *extension = FindObjectInContext(*extensionList, extensionId, context, extraContext)) {
|
||||
return extension;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Overloads when the value is the document.
|
||||
|
||||
inline Value *FindString(Document &doc, const char *memberId) {
|
||||
return FindStringInContext(doc, memberId, "the document");
|
||||
}
|
||||
|
||||
inline Value *FindNumber(Document &doc, const char *memberId) {
|
||||
return FindNumberInContext(doc, memberId, "the document");
|
||||
}
|
||||
|
||||
inline Value *FindUInt(Document &doc, const char *memberId) {
|
||||
return FindUIntInContext(doc, memberId, "the document");
|
||||
}
|
||||
|
||||
inline Value *FindArray(Document &val, const char *memberId) {
|
||||
return FindArrayInContext(val, memberId, "the document");
|
||||
}
|
||||
|
||||
inline Value *FindObject(Document &doc, const char *memberId) {
|
||||
return FindObjectInContext(doc, memberId, "the document");
|
||||
}
|
||||
|
||||
inline Value *FindExtension(Value &val, const char *extensionId) {
|
||||
return FindExtensionInContext(val, extensionId, "the document");
|
||||
}
|
||||
|
||||
inline CustomExtension ReadExtensions(const char *name, Value &obj) {
|
||||
CustomExtension ret;
|
||||
ret.name = name;
|
||||
|
|
|
@ -57,7 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/IOSystem.hpp>
|
||||
|
||||
// Header files, standard library.
|
||||
#include <inttypes.h>
|
||||
#include <cinttypes>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2021, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
@ -48,93 +47,94 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#if !defined(ASSIMP_BUILD_NO_GLTF_IMPORTER) && !defined(ASSIMP_BUILD_NO_GLTF2_IMPORTER)
|
||||
|
||||
#include <assimp/types.h>
|
||||
#include <assimp/material.h>
|
||||
#include <assimp/types.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
struct aiScene;
|
||||
struct aiNode;
|
||||
struct aiMaterial;
|
||||
|
||||
namespace glTF2
|
||||
{
|
||||
template<class T>
|
||||
class Ref;
|
||||
|
||||
class Asset;
|
||||
struct TexProperty;
|
||||
struct TextureInfo;
|
||||
struct NormalTextureInfo;
|
||||
struct OcclusionTextureInfo;
|
||||
struct Node;
|
||||
struct Texture;
|
||||
struct PbrSpecularGlossiness;
|
||||
struct MaterialSheen;
|
||||
struct MaterialClearcoat;
|
||||
struct MaterialTransmission;
|
||||
|
||||
// Vec/matrix types, as raw float arrays
|
||||
typedef float (vec2)[2];
|
||||
typedef float (vec3)[3];
|
||||
typedef float (vec4)[4];
|
||||
}
|
||||
|
||||
namespace Assimp
|
||||
{
|
||||
class IOSystem;
|
||||
class IOStream;
|
||||
class ExportProperties;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/** Helper class to export a given scene to an glTF file. */
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class glTF2Exporter {
|
||||
public:
|
||||
/// Constructor for a specific scene to export
|
||||
glTF2Exporter(const char* filename, IOSystem* pIOSystem, const aiScene* pScene,
|
||||
const ExportProperties* pProperties, bool binary);
|
||||
~glTF2Exporter();
|
||||
|
||||
protected:
|
||||
void WriteBinaryData(IOStream* outfile, std::size_t sceneLength);
|
||||
void GetTexSampler(const aiMaterial& mat, glTF2::Ref<glTF2::Texture> texture, aiTextureType tt, unsigned int slot);
|
||||
void GetMatTexProp(const aiMaterial& mat, unsigned int& prop, const char* propName, aiTextureType tt, unsigned int idx);
|
||||
void GetMatTexProp(const aiMaterial& mat, float& prop, const char* propName, aiTextureType tt, unsigned int idx);
|
||||
void GetMatTex(const aiMaterial& mat, glTF2::Ref<glTF2::Texture>& texture, unsigned int &texCoord, aiTextureType tt, unsigned int slot);
|
||||
void GetMatTex(const aiMaterial& mat, glTF2::TextureInfo& prop, aiTextureType tt, unsigned int slot);
|
||||
void GetMatTex(const aiMaterial& mat, glTF2::NormalTextureInfo& prop, aiTextureType tt, unsigned int slot);
|
||||
void GetMatTex(const aiMaterial& mat, glTF2::OcclusionTextureInfo& prop, aiTextureType tt, unsigned int slot);
|
||||
aiReturn GetMatColor(const aiMaterial& mat, glTF2::vec4& prop, const char* propName, int type, int idx) const;
|
||||
aiReturn GetMatColor(const aiMaterial& mat, glTF2::vec3& prop, const char* propName, int type, int idx) const;
|
||||
bool GetMatSpecGloss(const aiMaterial& mat, glTF2::PbrSpecularGlossiness& pbrSG);
|
||||
bool GetMatSheen(const aiMaterial& mat, glTF2::MaterialSheen& sheen);
|
||||
bool GetMatClearcoat(const aiMaterial& mat, glTF2::MaterialClearcoat& clearcoat);
|
||||
bool GetMatTransmission(const aiMaterial& mat, glTF2::MaterialTransmission& transmission);
|
||||
void ExportMetadata();
|
||||
void ExportMaterials();
|
||||
void ExportMeshes();
|
||||
void MergeMeshes();
|
||||
unsigned int ExportNodeHierarchy(const aiNode* n);
|
||||
unsigned int ExportNode(const aiNode* node, glTF2::Ref<glTF2::Node>& parent);
|
||||
void ExportScene();
|
||||
void ExportAnimations();
|
||||
|
||||
private:
|
||||
const char* mFilename;
|
||||
IOSystem* mIOSystem;
|
||||
const aiScene* mScene;
|
||||
const ExportProperties* mProperties;
|
||||
std::map<std::string, unsigned int> mTexturesByPath;
|
||||
std::shared_ptr<glTF2::Asset> mAsset;
|
||||
std::vector<unsigned char> mBodyData;
|
||||
};
|
||||
namespace glTFCommon {
|
||||
template <class T>
|
||||
class Ref;
|
||||
|
||||
}
|
||||
|
||||
namespace glTF2 {
|
||||
class Asset;
|
||||
struct TexProperty;
|
||||
struct TextureInfo;
|
||||
struct NormalTextureInfo;
|
||||
struct OcclusionTextureInfo;
|
||||
struct Node;
|
||||
struct Texture;
|
||||
struct PbrSpecularGlossiness;
|
||||
struct MaterialSheen;
|
||||
struct MaterialClearcoat;
|
||||
struct MaterialTransmission;
|
||||
|
||||
// Vec/matrix types, as raw float arrays
|
||||
typedef float(vec2)[2];
|
||||
typedef float(vec3)[3];
|
||||
typedef float(vec4)[4];
|
||||
} // namespace glTF2
|
||||
|
||||
namespace Assimp {
|
||||
class IOSystem;
|
||||
class IOStream;
|
||||
class ExportProperties;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/** Helper class to export a given scene to an glTF file. */
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class glTF2Exporter {
|
||||
public:
|
||||
/// Constructor for a specific scene to export
|
||||
glTF2Exporter(const char *filename, IOSystem *pIOSystem, const aiScene *pScene,
|
||||
const ExportProperties *pProperties, bool binary);
|
||||
~glTF2Exporter();
|
||||
|
||||
protected:
|
||||
void WriteBinaryData(IOStream *outfile, std::size_t sceneLength);
|
||||
void GetTexSampler(const aiMaterial &mat, glTFCommon::Ref<glTF2::Texture> texture, aiTextureType tt, unsigned int slot);
|
||||
void GetMatTexProp(const aiMaterial &mat, unsigned int &prop, const char *propName, aiTextureType tt, unsigned int idx);
|
||||
void GetMatTexProp(const aiMaterial &mat, float &prop, const char *propName, aiTextureType tt, unsigned int idx);
|
||||
void GetMatTex(const aiMaterial &mat, glTFCommon::Ref<glTF2::Texture> &texture, unsigned int &texCoord, aiTextureType tt, unsigned int slot);
|
||||
void GetMatTex(const aiMaterial &mat, glTF2::TextureInfo &prop, aiTextureType tt, unsigned int slot);
|
||||
void GetMatTex(const aiMaterial &mat, glTF2::NormalTextureInfo &prop, aiTextureType tt, unsigned int slot);
|
||||
void GetMatTex(const aiMaterial &mat, glTF2::OcclusionTextureInfo &prop, aiTextureType tt, unsigned int slot);
|
||||
aiReturn GetMatColor(const aiMaterial &mat, glTF2::vec4 &prop, const char *propName, int type, int idx) const;
|
||||
aiReturn GetMatColor(const aiMaterial &mat, glTF2::vec3 &prop, const char *propName, int type, int idx) const;
|
||||
bool GetMatSpecGloss(const aiMaterial &mat, glTF2::PbrSpecularGlossiness &pbrSG);
|
||||
bool GetMatSheen(const aiMaterial &mat, glTF2::MaterialSheen &sheen);
|
||||
bool GetMatClearcoat(const aiMaterial &mat, glTF2::MaterialClearcoat &clearcoat);
|
||||
bool GetMatTransmission(const aiMaterial &mat, glTF2::MaterialTransmission &transmission);
|
||||
void ExportMetadata();
|
||||
void ExportMaterials();
|
||||
void ExportMeshes();
|
||||
void MergeMeshes();
|
||||
unsigned int ExportNodeHierarchy(const aiNode *n);
|
||||
unsigned int ExportNode(const aiNode *node, glTFCommon::Ref<glTF2::Node> &parent);
|
||||
void ExportScene();
|
||||
void ExportAnimations();
|
||||
|
||||
private:
|
||||
const char *mFilename;
|
||||
IOSystem *mIOSystem;
|
||||
const aiScene *mScene;
|
||||
const ExportProperties *mProperties;
|
||||
std::map<std::string, unsigned int> mTexturesByPath;
|
||||
std::shared_ptr<glTF2::Asset> mAsset;
|
||||
std::vector<unsigned char> mBodyData;
|
||||
};
|
||||
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER
|
||||
|
||||
#endif // AI_GLTF2EXPORTER_H_INC
|
||||
|
|
|
@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "AssetLib/glTF2/glTF2Importer.h"
|
||||
#include "PostProcessing/MakeVerboseFormat.h"
|
||||
#include "AssetLib/glTF2/glTF2Asset.h"
|
||||
|
||||
#if !defined(ASSIMP_BUILD_NO_EXPORT)
|
||||
#include "AssetLib/glTF2/glTF2AssetWriter.h"
|
||||
#endif
|
||||
|
@ -57,6 +58,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/commonMetaData.h>
|
||||
#include <assimp/DefaultIOSystem.h>
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
@ -1536,11 +1538,9 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) {
|
|||
if (ext) {
|
||||
if (strcmp(ext, "jpeg") == 0) {
|
||||
ext = "jpg";
|
||||
}
|
||||
else if(strcmp(ext, "ktx2") == 0) { //basisu: ktx remains
|
||||
} else if(strcmp(ext, "ktx2") == 0) { //basisu: ktx remains
|
||||
ext = "kx2";
|
||||
}
|
||||
else if(strcmp(ext, "basis") == 0) { //basisu
|
||||
} else if(strcmp(ext, "basis") == 0) { //basisu
|
||||
ext = "bu";
|
||||
}
|
||||
|
||||
|
|
|
@ -43,12 +43,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#define AI_GLTF2IMPORTER_H_INC
|
||||
|
||||
#include <assimp/BaseImporter.h>
|
||||
#include <assimp/DefaultIOSystem.h>
|
||||
|
||||
struct aiNode;
|
||||
|
||||
namespace glTF2 {
|
||||
class Asset;
|
||||
class Asset;
|
||||
}
|
||||
|
||||
namespace Assimp {
|
||||
|
|
Loading…
Reference in New Issue