mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-23 05:15:34 +00:00
Updated Assimp
Added initial behavior for ImageAssets to hold a list of GFX resources of different texture profiles to avoid mem leaks with incorrect-typed usages Added function to ImageAsset to get best-fit asset, allowing for fallbacks if the requested assetID is not found Added function to ShapeAsset to get best-fit asset, allowing for fallbacks if the requested assetID is not found Disabled fields for dynamic and static shadowmap refresh rates Moved noShape model to core/rendering/shapes to place it in a more logical module position Added an include to avoid undefined type compile error and removed unneeded semicolon from zone code Added call to reload probe textures when a reloadTextures call is made Adjusted default directional light shadowmap settings to not be as extreme Added utility function to probe manager to allow any class to request a 'best fit' list of probes that would affect a given location, allowing other classes such as fog or particles to utilize IBL. Also updated probeManager's forward rendering to utilize same function to reduce code duplication. Shifted shape loader code to utilize assimp for loader consistency and testing Changed render bin used for SSAO postfx so it runs at the right time Made Core_Rendering module scan for assets Updated loose file references to a number of assets to follow proper formatting Refactored asset import code to follow a more consistent object heirarchy structure on importing assets, allowing more reliable cross-referencing between inbound items Updated asset import logic for materials/images so that they properly utilize ImageType. Images correctly save out the assigned image type, materials reference the images' type to know what map slot they should be used in. Importer logic also updated to better find-and-add associated images based on type. Cleaned up a bunch of old, outdated code in the asset importer Added initial handling for in-place importing of files without needing to process them through the UI. Added ability to edit module script from RMB context menu if torsion path is set Updated list field code for variable inspector to utilize correct ownerObject field
This commit is contained in:
parent
2d015bc426
commit
6ade6f08ce
545 changed files with 15077 additions and 8437 deletions
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -198,6 +198,7 @@ namespace glTF2
|
|||
//! Values for the BufferView::target field
|
||||
enum BufferViewTarget
|
||||
{
|
||||
BufferViewTarget_NONE = 0,
|
||||
BufferViewTarget_ARRAY_BUFFER = 34962,
|
||||
BufferViewTarget_ELEMENT_ARRAY_BUFFER = 34963
|
||||
};
|
||||
|
|
@ -387,8 +388,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<float> max; //!< Maximum value of each component in this attribute.
|
||||
std::vector<float> min; //!< Minimum value of each component in this attribute.
|
||||
std::vector<double> max; //!< Maximum value of each component in this attribute.
|
||||
std::vector<double> min; //!< Minimum value of each component in this attribute.
|
||||
|
||||
unsigned int GetNumComponents();
|
||||
unsigned int GetBytesPerComponent();
|
||||
|
|
@ -685,6 +686,13 @@ 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
|
||||
|
|
@ -776,7 +784,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 assed where data will be stored.
|
||||
/// \param [out] pAsset_Root - reference to root asset where data will be stored.
|
||||
void Read(Value& pJSON_Object, Asset& pAsset_Root);
|
||||
};
|
||||
|
||||
|
|
@ -1024,9 +1032,15 @@ 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;
|
||||
|
||||
AssetMetadata asset;
|
||||
|
||||
|
||||
|
|
@ -1069,6 +1083,7 @@ namespace glTF2
|
|||
, textures (*this, "textures")
|
||||
{
|
||||
memset(&extensionsUsed, 0, sizeof(extensionsUsed));
|
||||
memset(&extensionsRequired, 0, sizeof(extensionsRequired));
|
||||
}
|
||||
|
||||
//! Main function
|
||||
|
|
@ -1087,6 +1102,7 @@ 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-2019, assimp team
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -270,13 +270,14 @@ Ref<T> LazyDict<T>::Retrieve(unsigned int i)
|
|||
throw DeadlyImportError("GLTF: Object at index \"" + to_string(i) + "\" is not a JSON object");
|
||||
}
|
||||
|
||||
T* inst = new T();
|
||||
// Unique ptr prevents memory leak in case of Read throws an exception
|
||||
auto inst = std::unique_ptr<T>(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);
|
||||
return Add(inst.release());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
|
|
@ -383,7 +384,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) {
|
||||
|
|
@ -751,6 +752,7 @@ 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();
|
||||
|
|
@ -763,8 +765,10 @@ 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
|
||||
this->mData.reset(data);
|
||||
this->mDataLength = length;
|
||||
uint8_t *temp = new uint8_t[length];
|
||||
memcpy(temp, data, length);
|
||||
this->mData.reset(temp);
|
||||
this->mDataLength = length;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -800,8 +804,34 @@ inline void Texture::Read(Value& obj, Asset& r)
|
|||
}
|
||||
|
||||
namespace {
|
||||
inline void SetTextureProperties(Asset& r, Value* prop, TextureInfo& out)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Value* index = FindUInt(*prop, "index")) {
|
||||
out.texture = r.textures.Retrieve(index->GetUint());
|
||||
}
|
||||
|
|
@ -877,6 +907,9 @@ inline void Material::Read(Value& material, Asset& r)
|
|||
}
|
||||
}
|
||||
|
||||
if (r.extensionsUsed.KHR_texture_transform) {
|
||||
}
|
||||
|
||||
unlit = nullptr != FindObject(*extensions, "KHR_materials_unlit");
|
||||
}
|
||||
}
|
||||
|
|
@ -1403,6 +1436,12 @@ 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) {
|
||||
|
|
@ -1449,6 +1488,29 @@ 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)
|
||||
{
|
||||
|
|
@ -1463,12 +1525,10 @@ 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-2019, assimp team
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -54,8 +54,8 @@ namespace glTF2 {
|
|||
|
||||
namespace {
|
||||
|
||||
template<size_t N>
|
||||
inline Value& MakeValue(Value& val, float(&r)[N], MemoryPoolAllocator<>& al) {
|
||||
template<typename T, size_t N>
|
||||
inline Value& MakeValue(Value& val, T(&r)[N], MemoryPoolAllocator<>& al) {
|
||||
val.SetArray();
|
||||
val.Reserve(N, al);
|
||||
for (decltype(N) i = 0; i < N; ++i) {
|
||||
|
|
@ -64,7 +64,8 @@ namespace glTF2 {
|
|||
return val;
|
||||
}
|
||||
|
||||
inline Value& MakeValue(Value& val, const std::vector<float> & r, MemoryPoolAllocator<>& al) {
|
||||
template<typename T>
|
||||
inline Value& MakeValue(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) {
|
||||
|
|
@ -73,8 +74,19 @@ namespace glTF2 {
|
|||
return val;
|
||||
}
|
||||
|
||||
inline Value& MakeValue(Value& val, float r, MemoryPoolAllocator<>& /*al*/) {
|
||||
val.SetDouble(r);
|
||||
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);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
|
@ -104,8 +116,13 @@ namespace glTF2 {
|
|||
obj.AddMember("type", StringRef(AttribType::ToString(a.type)), w.mAl);
|
||||
|
||||
Value vTmpMax, vTmpMin;
|
||||
obj.AddMember("max", MakeValue(vTmpMax, a.max, w.mAl), w.mAl);
|
||||
obj.AddMember("min", MakeValue(vTmpMin, a.min, w.mAl), w.mAl);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
inline void Write(Value& obj, Animation& a, AssetWriter& w)
|
||||
|
|
@ -159,13 +176,13 @@ namespace glTF2 {
|
|||
valSampler.AddMember("input", s.input->index, w.mAl);
|
||||
switch (s.interpolation) {
|
||||
case Interpolation_LINEAR:
|
||||
valSampler.AddMember("path", "LINEAR", w.mAl);
|
||||
valSampler.AddMember("interpolation", "LINEAR", w.mAl);
|
||||
break;
|
||||
case Interpolation_STEP:
|
||||
valSampler.AddMember("path", "STEP", w.mAl);
|
||||
valSampler.AddMember("interpolation", "STEP", w.mAl);
|
||||
break;
|
||||
case Interpolation_CUBICSPLINE:
|
||||
valSampler.AddMember("path", "CUBICSPLINE", w.mAl);
|
||||
valSampler.AddMember("interpolation", "CUBICSPLINE", w.mAl);
|
||||
break;
|
||||
}
|
||||
valSampler.AddMember("output", s.output->index, w.mAl);
|
||||
|
|
@ -192,7 +209,7 @@ namespace glTF2 {
|
|||
if (bv.byteStride != 0) {
|
||||
obj.AddMember("byteStride", bv.byteStride, w.mAl);
|
||||
}
|
||||
if (bv.target != 0) {
|
||||
if (bv.target != BufferViewTarget_NONE) {
|
||||
obj.AddMember("target", int(bv.target), w.mAl);
|
||||
}
|
||||
}
|
||||
|
|
@ -429,6 +446,24 @@ 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);
|
||||
}
|
||||
|
|
@ -703,6 +738,8 @@ 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-2019, assimp team
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -46,6 +46,7 @@ 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>
|
||||
|
|
@ -58,6 +59,7 @@ 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;
|
||||
|
|
@ -139,10 +141,7 @@ static void CopyValue(const aiMatrix4x4& v, mat4& o) {
|
|||
}
|
||||
|
||||
static void CopyValue(const aiMatrix4x4& v, aiMatrix4x4& o) {
|
||||
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;
|
||||
memcpy(&o, &v, sizeof(aiMatrix4x4));
|
||||
}
|
||||
|
||||
static void IdentityMatrix4(mat4& o) {
|
||||
|
|
@ -152,8 +151,64 @@ 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, bool isIndices = false)
|
||||
size_t count, void* data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, BufferViewTarget target = BufferViewTarget_NONE)
|
||||
{
|
||||
if (!count || !data) {
|
||||
return Ref<Accessor>();
|
||||
|
|
@ -176,7 +231,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 = isIndices ? BufferViewTarget_ELEMENT_ARRAY_BUFFER : BufferViewTarget_ARRAY_BUFFER;
|
||||
bv->target = target;
|
||||
|
||||
// accessor
|
||||
Ref<Accessor> acc = a.accessors.Create(a.FindUniqueID(meshName, "accessor"));
|
||||
|
|
@ -187,33 +242,7 @@ inline Ref<Accessor> ExportData(Asset& a, std::string& meshName, Ref<Buffer>& bu
|
|||
acc->type = typeOut;
|
||||
|
||||
// calculate min and max values
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SetAccessorRange(compType, acc, data, count, numCompsIn, numCompsOut);
|
||||
|
||||
// copy the data
|
||||
acc->WriteData(count, data, numCompsIn*bytesPerComp);
|
||||
|
|
@ -319,11 +348,11 @@ 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();
|
||||
|
||||
// copy data since lifetime control is handed over to the asset
|
||||
uint8_t* data = new uint8_t[tex->mWidth];
|
||||
memcpy(data, tex->pcData, tex->mWidth);
|
||||
texture->source->SetData(data, tex->mWidth, *mAsset);
|
||||
// The asset has its own buffer, see Image::SetData
|
||||
texture->source->SetData(reinterpret_cast<uint8_t*> (tex->pcData), tex->mWidth, *mAsset);
|
||||
|
||||
if (tex->achFormatHint[0]) {
|
||||
std::string mimeType = "image/";
|
||||
|
|
@ -715,7 +744,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);
|
||||
Ref<Accessor> v = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mVertices, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER);
|
||||
if (v) p.attributes.position.push_back(v);
|
||||
|
||||
/******************** Normals ********************/
|
||||
|
|
@ -726,7 +755,7 @@ void glTF2Exporter::ExportMeshes()
|
|||
}
|
||||
}
|
||||
|
||||
Ref<Accessor> n = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mNormals, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
|
||||
Ref<Accessor> n = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mNormals, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER);
|
||||
if (n) p.attributes.normal.push_back(n);
|
||||
|
||||
/************** Texture coordinates **************/
|
||||
|
|
@ -744,14 +773,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, false);
|
||||
Ref<Accessor> tc = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mTextureCoords[i], AttribType::VEC3, type, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER);
|
||||
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, false);
|
||||
Ref<Accessor> c = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mColors[indexColorChannel], AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER);
|
||||
if (c)
|
||||
p.attributes.color.push_back(c);
|
||||
}
|
||||
|
|
@ -767,7 +796,7 @@ void glTF2Exporter::ExportMeshes()
|
|||
}
|
||||
}
|
||||
|
||||
p.indices = ExportData(*mAsset, meshId, b, indices.size(), &indices[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_UNSIGNED_INT, true);
|
||||
p.indices = ExportData(*mAsset, meshId, b, indices.size(), &indices[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_UNSIGNED_INT, BufferViewTarget_ELEMENT_ARRAY_BUFFER);
|
||||
}
|
||||
|
||||
switch (aim->mPrimitiveTypes) {
|
||||
|
|
@ -785,6 +814,47 @@ 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?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
|
@ -924,8 +994,27 @@ unsigned int glTF2Exporter::ExportNode(const aiNode* n, Ref<Node>& parent)
|
|||
node->name = name;
|
||||
|
||||
if (!n->mTransformation.IsIdentity()) {
|
||||
node->matrix.isPresent = true;
|
||||
CopyValue(n->mTransformation, node->matrix.value);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < n->mNumMeshes; ++i) {
|
||||
|
|
@ -961,10 +1050,16 @@ void glTF2Exporter::ExportMetadata()
|
|||
asset.version = "2.0";
|
||||
|
||||
char buffer[256];
|
||||
ai_snprintf(buffer, 256, "Open Asset Import Library (assimp v%d.%d.%d)",
|
||||
ai_snprintf(buffer, 256, "Open Asset Import Library (assimp v%d.%d.%x)",
|
||||
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-2019, assimp team
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -74,6 +74,7 @@ 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-2019, assimp team
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -84,6 +84,7 @@ 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