mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 07:34:45 +00:00
* Adjustment: Update Assimp version to 5.0.1.
This commit is contained in:
parent
14ebeaf3eb
commit
4758f7bdaf
679 changed files with 50502 additions and 19698 deletions
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -198,7 +198,6 @@ namespace glTF2
|
|||
//! Values for the BufferView::target field
|
||||
enum BufferViewTarget
|
||||
{
|
||||
BufferViewTarget_NONE = 0,
|
||||
BufferViewTarget_ARRAY_BUFFER = 34962,
|
||||
BufferViewTarget_ELEMENT_ARRAY_BUFFER = 34963
|
||||
};
|
||||
|
|
@ -388,8 +387,8 @@ namespace glTF2
|
|||
ComponentType componentType; //!< The datatype of components in the attribute. (required)
|
||||
size_t count; //!< The number of attributes referenced by this accessor. (required)
|
||||
AttribType::Value type; //!< Specifies if the attribute is a scalar, vector, or matrix. (required)
|
||||
std::vector<double> max; //!< Maximum value of each component in this attribute.
|
||||
std::vector<double> min; //!< Minimum value of each component in this attribute.
|
||||
std::vector<float> max; //!< Maximum value of each component in this attribute.
|
||||
std::vector<float> min; //!< Minimum value of each component in this attribute.
|
||||
|
||||
unsigned int GetNumComponents();
|
||||
unsigned int GetBytesPerComponent();
|
||||
|
|
@ -686,13 +685,6 @@ namespace glTF2
|
|||
Ref<Texture> texture;
|
||||
unsigned int index;
|
||||
unsigned int texCoord = 0;
|
||||
|
||||
bool textureTransformSupported = false;
|
||||
struct TextureTransformExt {
|
||||
float offset[2];
|
||||
float rotation;
|
||||
float scale[2];
|
||||
} TextureTransformExt_t;
|
||||
};
|
||||
|
||||
struct NormalTextureInfo : TextureInfo
|
||||
|
|
@ -784,7 +776,7 @@ namespace glTF2
|
|||
/// \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.
|
||||
/// \param [out] pAsset_Root - reference to root assed where data will be stored.
|
||||
void Read(Value& pJSON_Object, Asset& pAsset_Root);
|
||||
};
|
||||
|
||||
|
|
@ -1032,14 +1024,8 @@ namespace glTF2
|
|||
bool KHR_materials_pbrSpecularGlossiness;
|
||||
bool KHR_materials_unlit;
|
||||
bool KHR_lights_punctual;
|
||||
bool KHR_texture_transform;
|
||||
} extensionsUsed;
|
||||
|
||||
//! Keeps info about the required extensions
|
||||
struct RequiredExtensions
|
||||
{
|
||||
bool KHR_draco_mesh_compression;
|
||||
} extensionsRequired;
|
||||
} extensionsUsed;
|
||||
|
||||
AssetMetadata asset;
|
||||
|
||||
|
|
@ -1083,7 +1069,6 @@ namespace glTF2
|
|||
, textures (*this, "textures")
|
||||
{
|
||||
memset(&extensionsUsed, 0, sizeof(extensionsUsed));
|
||||
memset(&extensionsRequired, 0, sizeof(extensionsRequired));
|
||||
}
|
||||
|
||||
//! Main function
|
||||
|
|
@ -1102,7 +1087,6 @@ namespace glTF2
|
|||
void ReadBinaryHeader(IOStream& stream, std::vector<char>& sceneData);
|
||||
|
||||
void ReadExtensionsUsed(Document& doc);
|
||||
void ReadExtensionsRequired(Document& doc);
|
||||
|
||||
IOStream* OpenFile(std::string path, const char* mode, bool absolute = false);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -270,14 +270,13 @@ Ref<T> LazyDict<T>::Retrieve(unsigned int i)
|
|||
throw DeadlyImportError("GLTF: Object at index \"" + to_string(i) + "\" is not a JSON object");
|
||||
}
|
||||
|
||||
// Unique ptr prevents memory leak in case of Read throws an exception
|
||||
auto inst = std::unique_ptr<T>(new T());
|
||||
T* inst = new T();
|
||||
inst->id = std::string(mDictId) + "_" + to_string(i);
|
||||
inst->oIndex = i;
|
||||
ReadMember(obj, "name", inst->name);
|
||||
inst->Read(obj, mAsset);
|
||||
|
||||
return Add(inst.release());
|
||||
return Add(inst);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
|
|
@ -384,7 +383,7 @@ inline void Buffer::Read(Value& obj, Asset& r)
|
|||
}
|
||||
else { // Local file
|
||||
if (byteLength > 0) {
|
||||
std::string dir = !r.mCurrentAssetDir.empty() ? (r.mCurrentAssetDir) : "";
|
||||
std::string dir = !r.mCurrentAssetDir.empty() ? (r.mCurrentAssetDir + "/") : "";
|
||||
|
||||
IOStream* file = r.OpenFile(dir + uri, "rb");
|
||||
if (file) {
|
||||
|
|
@ -752,7 +751,6 @@ inline uint8_t* Image::StealData()
|
|||
return mData.release();
|
||||
}
|
||||
|
||||
// Never take over the ownership of data whenever binary or not
|
||||
inline void Image::SetData(uint8_t* data, size_t length, Asset& r)
|
||||
{
|
||||
Ref<Buffer> b = r.GetBodyBuffer();
|
||||
|
|
@ -765,10 +763,8 @@ inline void Image::SetData(uint8_t* data, size_t length, Asset& r)
|
|||
bufferView->byteOffset = b->AppendData(data, length);
|
||||
}
|
||||
else { // text file: will be stored as a data uri
|
||||
uint8_t *temp = new uint8_t[length];
|
||||
memcpy(temp, data, length);
|
||||
this->mData.reset(temp);
|
||||
this->mDataLength = length;
|
||||
this->mData.reset(data);
|
||||
this->mDataLength = length;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -804,34 +800,8 @@ inline void Texture::Read(Value& obj, Asset& r)
|
|||
}
|
||||
|
||||
namespace {
|
||||
inline void SetTextureProperties(Asset& r, Value* prop, TextureInfo& out) {
|
||||
if (r.extensionsUsed.KHR_texture_transform) {
|
||||
if (Value *extensions = FindObject(*prop, "extensions")) {
|
||||
out.textureTransformSupported = true;
|
||||
if (Value *pKHR_texture_transform = FindObject(*extensions, "KHR_texture_transform")) {
|
||||
if (Value *array = FindArray(*pKHR_texture_transform, "offset")) {
|
||||
out.TextureTransformExt_t.offset[0] = (*array)[0].GetFloat();
|
||||
out.TextureTransformExt_t.offset[1] = (*array)[1].GetFloat();
|
||||
} else {
|
||||
out.TextureTransformExt_t.offset[0] = 0;
|
||||
out.TextureTransformExt_t.offset[1] = 0;
|
||||
}
|
||||
|
||||
if (!ReadMember(*pKHR_texture_transform, "rotation", out.TextureTransformExt_t.rotation)) {
|
||||
out.TextureTransformExt_t.rotation = 0;
|
||||
}
|
||||
|
||||
if (Value *array = FindArray(*pKHR_texture_transform, "scale")) {
|
||||
out.TextureTransformExt_t.scale[0] = (*array)[0].GetFloat();
|
||||
out.TextureTransformExt_t.scale[1] = (*array)[1].GetFloat();
|
||||
} else {
|
||||
out.TextureTransformExt_t.scale[0] = 1;
|
||||
out.TextureTransformExt_t.scale[1] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void SetTextureProperties(Asset& r, Value* prop, TextureInfo& out)
|
||||
{
|
||||
if (Value* index = FindUInt(*prop, "index")) {
|
||||
out.texture = r.textures.Retrieve(index->GetUint());
|
||||
}
|
||||
|
|
@ -907,9 +877,6 @@ inline void Material::Read(Value& material, Asset& r)
|
|||
}
|
||||
}
|
||||
|
||||
if (r.extensionsUsed.KHR_texture_transform) {
|
||||
}
|
||||
|
||||
unlit = nullptr != FindObject(*extensions, "KHR_materials_unlit");
|
||||
}
|
||||
}
|
||||
|
|
@ -1436,12 +1403,6 @@ inline void Asset::Load(const std::string& pFile, bool isBinary)
|
|||
// Load the metadata
|
||||
asset.Read(doc);
|
||||
ReadExtensionsUsed(doc);
|
||||
ReadExtensionsRequired(doc);
|
||||
|
||||
// Currently Draco is not supported
|
||||
if (extensionsRequired.KHR_draco_mesh_compression) {
|
||||
throw DeadlyImportError("GLTF: Draco mesh compression not currently supported.");
|
||||
}
|
||||
|
||||
// Prepare the dictionaries
|
||||
for (size_t i = 0; i < mDicts.size(); ++i) {
|
||||
|
|
@ -1488,29 +1449,6 @@ inline void Asset::SetAsBinary()
|
|||
}
|
||||
}
|
||||
|
||||
// As required extensions are only a concept in glTF 2.0, this is here
|
||||
// instead of glTFCommon.h
|
||||
#define CHECK_REQUIRED_EXT(EXT) \
|
||||
if (exts.find(#EXT) != exts.end()) extensionsRequired.EXT = true;
|
||||
|
||||
inline void Asset::ReadExtensionsRequired(Document& doc)
|
||||
{
|
||||
Value* extsRequired = FindArray(doc, "extensionsRequired");
|
||||
if (nullptr == extsRequired) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::gltf_unordered_map<std::string, bool> exts;
|
||||
for (unsigned int i = 0; i < extsRequired->Size(); ++i) {
|
||||
if ((*extsRequired)[i].IsString()) {
|
||||
exts[(*extsRequired)[i].GetString()] = true;
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_REQUIRED_EXT(KHR_draco_mesh_compression);
|
||||
|
||||
#undef CHECK_REQUIRED_EXT
|
||||
}
|
||||
|
||||
inline void Asset::ReadExtensionsUsed(Document& doc)
|
||||
{
|
||||
|
|
@ -1525,10 +1463,12 @@ inline void Asset::ReadExtensionsUsed(Document& doc)
|
|||
}
|
||||
}
|
||||
|
||||
#define CHECK_EXT(EXT) \
|
||||
if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true;
|
||||
|
||||
CHECK_EXT(KHR_materials_pbrSpecularGlossiness);
|
||||
CHECK_EXT(KHR_materials_unlit);
|
||||
CHECK_EXT(KHR_lights_punctual);
|
||||
CHECK_EXT(KHR_texture_transform);
|
||||
|
||||
#undef CHECK_EXT
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -54,8 +54,8 @@ namespace glTF2 {
|
|||
|
||||
namespace {
|
||||
|
||||
template<typename T, size_t N>
|
||||
inline Value& MakeValue(Value& val, T(&r)[N], MemoryPoolAllocator<>& al) {
|
||||
template<size_t N>
|
||||
inline Value& MakeValue(Value& val, float(&r)[N], MemoryPoolAllocator<>& al) {
|
||||
val.SetArray();
|
||||
val.Reserve(N, al);
|
||||
for (decltype(N) i = 0; i < N; ++i) {
|
||||
|
|
@ -64,8 +64,7 @@ namespace glTF2 {
|
|||
return val;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline Value& MakeValue(Value& val, const std::vector<T> & r, MemoryPoolAllocator<>& al) {
|
||||
inline Value& MakeValue(Value& val, const std::vector<float> & r, MemoryPoolAllocator<>& al) {
|
||||
val.SetArray();
|
||||
val.Reserve(static_cast<rapidjson::SizeType>(r.size()), al);
|
||||
for (unsigned int i = 0; i < r.size(); ++i) {
|
||||
|
|
@ -74,19 +73,8 @@ namespace glTF2 {
|
|||
return val;
|
||||
}
|
||||
|
||||
template<typename C, typename T>
|
||||
inline Value& MakeValueCast(Value& val, const std::vector<T> & r, MemoryPoolAllocator<>& al) {
|
||||
val.SetArray();
|
||||
val.Reserve(static_cast<rapidjson::SizeType>(r.size()), al);
|
||||
for (unsigned int i = 0; i < r.size(); ++i) {
|
||||
val.PushBack(static_cast<C>(r[i]), al);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline Value& MakeValue(Value& val, T r, MemoryPoolAllocator<>& /*al*/) {
|
||||
val.Set(r);
|
||||
inline Value& MakeValue(Value& val, float r, MemoryPoolAllocator<>& /*al*/) {
|
||||
val.SetDouble(r);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
|
@ -116,13 +104,8 @@ namespace glTF2 {
|
|||
obj.AddMember("type", StringRef(AttribType::ToString(a.type)), w.mAl);
|
||||
|
||||
Value vTmpMax, vTmpMin;
|
||||
if (a.componentType == ComponentType_FLOAT) {
|
||||
obj.AddMember("max", MakeValue(vTmpMax, a.max, w.mAl), w.mAl);
|
||||
obj.AddMember("min", MakeValue(vTmpMin, a.min, w.mAl), w.mAl);
|
||||
} else {
|
||||
obj.AddMember("max", MakeValueCast<int64_t>(vTmpMax, a.max, w.mAl), w.mAl);
|
||||
obj.AddMember("min", MakeValueCast<int64_t>(vTmpMin, a.min, w.mAl), w.mAl);
|
||||
}
|
||||
obj.AddMember("max", MakeValue(vTmpMax, a.max, w.mAl), w.mAl);
|
||||
obj.AddMember("min", MakeValue(vTmpMin, a.min, w.mAl), w.mAl);
|
||||
}
|
||||
|
||||
inline void Write(Value& obj, Animation& a, AssetWriter& w)
|
||||
|
|
@ -176,13 +159,13 @@ namespace glTF2 {
|
|||
valSampler.AddMember("input", s.input->index, w.mAl);
|
||||
switch (s.interpolation) {
|
||||
case Interpolation_LINEAR:
|
||||
valSampler.AddMember("interpolation", "LINEAR", w.mAl);
|
||||
valSampler.AddMember("path", "LINEAR", w.mAl);
|
||||
break;
|
||||
case Interpolation_STEP:
|
||||
valSampler.AddMember("interpolation", "STEP", w.mAl);
|
||||
valSampler.AddMember("path", "STEP", w.mAl);
|
||||
break;
|
||||
case Interpolation_CUBICSPLINE:
|
||||
valSampler.AddMember("interpolation", "CUBICSPLINE", w.mAl);
|
||||
valSampler.AddMember("path", "CUBICSPLINE", w.mAl);
|
||||
break;
|
||||
}
|
||||
valSampler.AddMember("output", s.output->index, w.mAl);
|
||||
|
|
@ -209,7 +192,7 @@ namespace glTF2 {
|
|||
if (bv.byteStride != 0) {
|
||||
obj.AddMember("byteStride", bv.byteStride, w.mAl);
|
||||
}
|
||||
if (bv.target != BufferViewTarget_NONE) {
|
||||
if (bv.target != 0) {
|
||||
obj.AddMember("target", int(bv.target), w.mAl);
|
||||
}
|
||||
}
|
||||
|
|
@ -375,7 +358,7 @@ namespace glTF2 {
|
|||
WriteVec(pbrSpecularGlossiness, pbrSG.specularFactor, "specularFactor", defaultSpecularFactor, w.mAl);
|
||||
|
||||
if (pbrSG.glossinessFactor != 1) {
|
||||
WriteFloat(pbrSpecularGlossiness, pbrSG.glossinessFactor, "glossinessFactor", w.mAl);
|
||||
WriteFloat(obj, pbrSG.glossinessFactor, "glossinessFactor", w.mAl);
|
||||
}
|
||||
|
||||
WriteTex(pbrSpecularGlossiness, pbrSG.diffuseTexture, "diffuseTexture", w.mAl);
|
||||
|
|
@ -446,24 +429,6 @@ namespace glTF2 {
|
|||
WriteAttrs(w, attrs, p.attributes.weight, "WEIGHTS", true);
|
||||
}
|
||||
prim.AddMember("attributes", attrs, w.mAl);
|
||||
|
||||
// targets for blendshapes
|
||||
if (p.targets.size() > 0) {
|
||||
Value tjs;
|
||||
tjs.SetArray();
|
||||
tjs.Reserve(unsigned(p.targets.size()), w.mAl);
|
||||
for (unsigned int t = 0; t < p.targets.size(); ++t) {
|
||||
Value tj;
|
||||
tj.SetObject();
|
||||
{
|
||||
WriteAttrs(w, tj, p.targets[t].position, "POSITION");
|
||||
WriteAttrs(w, tj, p.targets[t].normal, "NORMAL");
|
||||
WriteAttrs(w, tj, p.targets[t].tangent, "TANGENT");
|
||||
}
|
||||
tjs.PushBack(tj, w.mAl);
|
||||
}
|
||||
prim.AddMember("targets", tjs, w.mAl);
|
||||
}
|
||||
}
|
||||
primitives.PushBack(prim, w.mAl);
|
||||
}
|
||||
|
|
@ -738,8 +703,6 @@ namespace glTF2 {
|
|||
asset.SetObject();
|
||||
asset.AddMember("version", Value(mAsset.asset.version, mAl).Move(), mAl);
|
||||
asset.AddMember("generator", Value(mAsset.asset.generator, mAl).Move(), mAl);
|
||||
if (!mAsset.asset.copyright.empty())
|
||||
asset.AddMember("copyright", Value(mAsset.asset.copyright, mAl).Move(), mAl);
|
||||
mDoc.AddMember("asset", asset, mAl);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -46,7 +46,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "glTF2/glTF2AssetWriter.h"
|
||||
#include "PostProcessing/SplitLargeMeshes.h"
|
||||
|
||||
#include <assimp/commonMetaData.h>
|
||||
#include <assimp/Exceptional.h>
|
||||
#include <assimp/StringComparison.h>
|
||||
#include <assimp/ByteSwapper.h>
|
||||
|
|
@ -59,7 +58,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
// Header files, standard library.
|
||||
#include <memory>
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
|
||||
using namespace rapidjson;
|
||||
|
|
@ -141,7 +139,10 @@ static void CopyValue(const aiMatrix4x4& v, mat4& o) {
|
|||
}
|
||||
|
||||
static void CopyValue(const aiMatrix4x4& v, aiMatrix4x4& o) {
|
||||
memcpy(&o, &v, sizeof(aiMatrix4x4));
|
||||
o.a1 = v.a1; o.a2 = v.a2; o.a3 = v.a3; o.a4 = v.a4;
|
||||
o.b1 = v.b1; o.b2 = v.b2; o.b3 = v.b3; o.b4 = v.b4;
|
||||
o.c1 = v.c1; o.c2 = v.c2; o.c3 = v.c3; o.c4 = v.c4;
|
||||
o.d1 = v.d1; o.d2 = v.d2; o.d3 = v.d3; o.d4 = v.d4;
|
||||
}
|
||||
|
||||
static void IdentityMatrix4(mat4& o) {
|
||||
|
|
@ -151,64 +152,8 @@ static void IdentityMatrix4(mat4& o) {
|
|||
o[12] = 0; o[13] = 0; o[14] = 0; o[15] = 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SetAccessorRange(Ref<Accessor> acc, void* data, size_t count,
|
||||
unsigned int numCompsIn, unsigned int numCompsOut)
|
||||
{
|
||||
ai_assert(numCompsOut <= numCompsIn);
|
||||
|
||||
// Allocate and initialize with large values.
|
||||
for (unsigned int i = 0 ; i < numCompsOut ; i++) {
|
||||
acc->min.push_back( std::numeric_limits<double>::max());
|
||||
acc->max.push_back(-std::numeric_limits<double>::max());
|
||||
}
|
||||
|
||||
size_t totalComps = count * numCompsIn;
|
||||
T* buffer_ptr = static_cast<T*>(data);
|
||||
T* buffer_end = buffer_ptr + totalComps;
|
||||
|
||||
// Search and set extreme values.
|
||||
for (; buffer_ptr < buffer_end ; buffer_ptr += numCompsIn) {
|
||||
for (unsigned int j = 0 ; j < numCompsOut ; j++) {
|
||||
double valueTmp = buffer_ptr[j];
|
||||
|
||||
if (valueTmp < acc->min[j]) {
|
||||
acc->min[j] = valueTmp;
|
||||
}
|
||||
if (valueTmp > acc->max[j]) {
|
||||
acc->max[j] = valueTmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void SetAccessorRange(ComponentType compType, Ref<Accessor> acc, void* data,
|
||||
size_t count, unsigned int numCompsIn, unsigned int numCompsOut)
|
||||
{
|
||||
switch (compType) {
|
||||
case ComponentType_SHORT:
|
||||
SetAccessorRange<short>(acc, data, count, numCompsIn, numCompsOut);
|
||||
return;
|
||||
case ComponentType_UNSIGNED_SHORT:
|
||||
SetAccessorRange<unsigned short>(acc, data, count, numCompsIn, numCompsOut);
|
||||
return;
|
||||
case ComponentType_UNSIGNED_INT:
|
||||
SetAccessorRange<unsigned int>(acc, data, count, numCompsIn, numCompsOut);
|
||||
return;
|
||||
case ComponentType_FLOAT:
|
||||
SetAccessorRange<float>(acc, data, count, numCompsIn, numCompsOut);
|
||||
return;
|
||||
case ComponentType_BYTE:
|
||||
SetAccessorRange<int8_t>(acc, data, count, numCompsIn, numCompsOut);
|
||||
return;
|
||||
case ComponentType_UNSIGNED_BYTE:
|
||||
SetAccessorRange<uint8_t>(acc, data, count, numCompsIn, numCompsOut);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
inline Ref<Accessor> ExportData(Asset& a, std::string& meshName, Ref<Buffer>& buffer,
|
||||
size_t count, void* data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, BufferViewTarget target = BufferViewTarget_NONE)
|
||||
size_t count, void* data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, bool isIndices = false)
|
||||
{
|
||||
if (!count || !data) {
|
||||
return Ref<Accessor>();
|
||||
|
|
@ -231,7 +176,7 @@ inline Ref<Accessor> ExportData(Asset& a, std::string& meshName, Ref<Buffer>& bu
|
|||
bv->byteOffset = offset;
|
||||
bv->byteLength = length; //! The target that the WebGL buffer should be bound to.
|
||||
bv->byteStride = 0;
|
||||
bv->target = target;
|
||||
bv->target = isIndices ? BufferViewTarget_ELEMENT_ARRAY_BUFFER : BufferViewTarget_ARRAY_BUFFER;
|
||||
|
||||
// accessor
|
||||
Ref<Accessor> acc = a.accessors.Create(a.FindUniqueID(meshName, "accessor"));
|
||||
|
|
@ -242,7 +187,33 @@ inline Ref<Accessor> ExportData(Asset& a, std::string& meshName, Ref<Buffer>& bu
|
|||
acc->type = typeOut;
|
||||
|
||||
// calculate min and max values
|
||||
SetAccessorRange(compType, acc, data, count, numCompsIn, numCompsOut);
|
||||
{
|
||||
// Allocate and initialize with large values.
|
||||
float float_MAX = 10000000000000.0f;
|
||||
for (unsigned int i = 0 ; i < numCompsOut ; i++) {
|
||||
acc->min.push_back( float_MAX);
|
||||
acc->max.push_back(-float_MAX);
|
||||
}
|
||||
|
||||
// Search and set extreme values.
|
||||
float valueTmp;
|
||||
for (unsigned int i = 0 ; i < count ; i++) {
|
||||
for (unsigned int j = 0 ; j < numCompsOut ; j++) {
|
||||
if (numCompsOut == 1) {
|
||||
valueTmp = static_cast<unsigned short*>(data)[i];
|
||||
} else {
|
||||
valueTmp = static_cast<aiVector3D*>(data)[i][j];
|
||||
}
|
||||
|
||||
if (valueTmp < acc->min[j]) {
|
||||
acc->min[j] = valueTmp;
|
||||
}
|
||||
if (valueTmp > acc->max[j]) {
|
||||
acc->max[j] = valueTmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copy the data
|
||||
acc->WriteData(count, data, numCompsIn*bytesPerComp);
|
||||
|
|
@ -348,11 +319,9 @@ void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref<Texture>& texture, aiTe
|
|||
|
||||
if (path[0] == '*') { // embedded
|
||||
aiTexture* tex = mScene->mTextures[atoi(&path[1])];
|
||||
|
||||
texture->source->name = tex->mFilename.C_Str();
|
||||
|
||||
// The asset has its own buffer, see Image::SetData
|
||||
texture->source->SetData(reinterpret_cast<uint8_t*> (tex->pcData), tex->mWidth, *mAsset);
|
||||
uint8_t* data = reinterpret_cast<uint8_t*>(tex->pcData);
|
||||
texture->source->SetData(data, tex->mWidth, *mAsset);
|
||||
|
||||
if (tex->achFormatHint[0]) {
|
||||
std::string mimeType = "image/";
|
||||
|
|
@ -744,7 +713,7 @@ void glTF2Exporter::ExportMeshes()
|
|||
p.material = mAsset->materials.Get(aim->mMaterialIndex);
|
||||
|
||||
/******************* Vertices ********************/
|
||||
Ref<Accessor> v = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mVertices, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER);
|
||||
Ref<Accessor> v = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mVertices, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
|
||||
if (v) p.attributes.position.push_back(v);
|
||||
|
||||
/******************** Normals ********************/
|
||||
|
|
@ -755,7 +724,7 @@ void glTF2Exporter::ExportMeshes()
|
|||
}
|
||||
}
|
||||
|
||||
Ref<Accessor> n = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mNormals, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER);
|
||||
Ref<Accessor> n = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mNormals, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
|
||||
if (n) p.attributes.normal.push_back(n);
|
||||
|
||||
/************** Texture coordinates **************/
|
||||
|
|
@ -773,14 +742,14 @@ void glTF2Exporter::ExportMeshes()
|
|||
if (aim->mNumUVComponents[i] > 0) {
|
||||
AttribType::Value type = (aim->mNumUVComponents[i] == 2) ? AttribType::VEC2 : AttribType::VEC3;
|
||||
|
||||
Ref<Accessor> tc = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mTextureCoords[i], AttribType::VEC3, type, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER);
|
||||
Ref<Accessor> tc = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mTextureCoords[i], AttribType::VEC3, type, ComponentType_FLOAT, false);
|
||||
if (tc) p.attributes.texcoord.push_back(tc);
|
||||
}
|
||||
}
|
||||
|
||||
/*************** Vertex colors ****************/
|
||||
for (unsigned int indexColorChannel = 0; indexColorChannel < aim->GetNumColorChannels(); ++indexColorChannel) {
|
||||
Ref<Accessor> c = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mColors[indexColorChannel], AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER);
|
||||
Ref<Accessor> c = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mColors[indexColorChannel], AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT, false);
|
||||
if (c)
|
||||
p.attributes.color.push_back(c);
|
||||
}
|
||||
|
|
@ -796,7 +765,7 @@ void glTF2Exporter::ExportMeshes()
|
|||
}
|
||||
}
|
||||
|
||||
p.indices = ExportData(*mAsset, meshId, b, indices.size(), &indices[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_UNSIGNED_INT, BufferViewTarget_ELEMENT_ARRAY_BUFFER);
|
||||
p.indices = ExportData(*mAsset, meshId, b, indices.size(), &indices[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_UNSIGNED_INT, true);
|
||||
}
|
||||
|
||||
switch (aim->mPrimitiveTypes) {
|
||||
|
|
@ -814,47 +783,6 @@ void glTF2Exporter::ExportMeshes()
|
|||
if(aim->HasBones()) {
|
||||
ExportSkin(*mAsset, aim, m, b, skinRef, inverseBindMatricesData);
|
||||
}
|
||||
|
||||
/*************** Targets for blendshapes ****************/
|
||||
if (aim->mNumAnimMeshes > 0) {
|
||||
p.targets.resize(aim->mNumAnimMeshes);
|
||||
for (unsigned int am = 0; am < aim->mNumAnimMeshes; ++am) {
|
||||
aiAnimMesh *pAnimMesh = aim->mAnimMeshes[am];
|
||||
|
||||
// position
|
||||
if (pAnimMesh->HasPositions()) {
|
||||
// NOTE: in gltf it is the diff stored
|
||||
aiVector3D *pPositionDiff = new aiVector3D[pAnimMesh->mNumVertices];
|
||||
for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) {
|
||||
pPositionDiff[vt] = pAnimMesh->mVertices[vt] - aim->mVertices[vt];
|
||||
}
|
||||
Ref<Accessor> v = ExportData(*mAsset, meshId, b,
|
||||
pAnimMesh->mNumVertices, pPositionDiff,
|
||||
AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
|
||||
if (v) {
|
||||
p.targets[am].position.push_back(v);
|
||||
}
|
||||
delete[] pPositionDiff;
|
||||
}
|
||||
|
||||
// normal
|
||||
if (pAnimMesh->HasNormals()) {
|
||||
aiVector3D *pNormalDiff = new aiVector3D[pAnimMesh->mNumVertices];
|
||||
for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) {
|
||||
pNormalDiff[vt] = pAnimMesh->mNormals[vt] - aim->mNormals[vt];
|
||||
}
|
||||
Ref<Accessor> v = ExportData(*mAsset, meshId, b,
|
||||
pAnimMesh->mNumVertices, pNormalDiff,
|
||||
AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
|
||||
if (v) {
|
||||
p.targets[am].normal.push_back(v);
|
||||
}
|
||||
delete[] pNormalDiff;
|
||||
}
|
||||
|
||||
// tangent?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
|
@ -994,27 +922,8 @@ unsigned int glTF2Exporter::ExportNode(const aiNode* n, Ref<Node>& parent)
|
|||
node->name = name;
|
||||
|
||||
if (!n->mTransformation.IsIdentity()) {
|
||||
if (mScene->mNumAnimations > 0) {
|
||||
aiQuaternion quaternion;
|
||||
n->mTransformation.Decompose(*reinterpret_cast<aiVector3D *>(&node->scale.value), quaternion, *reinterpret_cast<aiVector3D *>(&node->translation.value));
|
||||
|
||||
aiVector3D vector(static_cast<ai_real>(1.0f), static_cast<ai_real>(1.0f), static_cast<ai_real>(1.0f));
|
||||
if (!reinterpret_cast<aiVector3D *>(&node->scale.value)->Equal(vector)) {
|
||||
node->scale.isPresent = true;
|
||||
}
|
||||
if (!reinterpret_cast<aiVector3D *>(&node->translation.value)->Equal(vector)) {
|
||||
node->translation.isPresent = true;
|
||||
}
|
||||
node->rotation.isPresent = true;
|
||||
node->rotation.value[0] = quaternion.x;
|
||||
node->rotation.value[1] = quaternion.y;
|
||||
node->rotation.value[2] = quaternion.z;
|
||||
node->rotation.value[3] = quaternion.w;
|
||||
node->matrix.isPresent = false;
|
||||
} else {
|
||||
node->matrix.isPresent = true;
|
||||
CopyValue(n->mTransformation, node->matrix.value);
|
||||
}
|
||||
node->matrix.isPresent = true;
|
||||
CopyValue(n->mTransformation, node->matrix.value);
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < n->mNumMeshes; ++i) {
|
||||
|
|
@ -1050,16 +959,10 @@ void glTF2Exporter::ExportMetadata()
|
|||
asset.version = "2.0";
|
||||
|
||||
char buffer[256];
|
||||
ai_snprintf(buffer, 256, "Open Asset Import Library (assimp v%d.%d.%x)",
|
||||
ai_snprintf(buffer, 256, "Open Asset Import Library (assimp v%d.%d.%d)",
|
||||
aiGetVersionMajor(), aiGetVersionMinor(), aiGetVersionRevision());
|
||||
|
||||
asset.generator = buffer;
|
||||
|
||||
// Copyright
|
||||
aiString copyright_str;
|
||||
if (mScene->mMetaData != nullptr && mScene->mMetaData->Get(AI_METADATA_SOURCE_COPYRIGHT, copyright_str)) {
|
||||
asset.copyright = copyright_str.C_Str();
|
||||
}
|
||||
}
|
||||
|
||||
inline Ref<Accessor> GetSamplerInputRef(Asset& asset, std::string& animId, Ref<Buffer>& buffer, std::vector<float>& times)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -74,7 +74,6 @@ namespace glTF2
|
|||
struct Texture;
|
||||
|
||||
// Vec/matrix types, as raw float arrays
|
||||
typedef float (vec2)[2];
|
||||
typedef float (vec3)[3];
|
||||
typedef float (vec4)[4];
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -84,7 +84,6 @@ private:
|
|||
void ImportLights(glTF2::Asset& a);
|
||||
void ImportNodes(glTF2::Asset& a);
|
||||
void ImportAnimations(glTF2::Asset& a);
|
||||
void ImportCommonMetadata(glTF2::Asset& a);
|
||||
};
|
||||
|
||||
} // Namespace assimp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue