summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/assimp/code/glTFImporter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/assimp/code/glTFImporter.cpp')
-rw-r--r--src/3rdparty/assimp/code/glTFImporter.cpp99
1 files changed, 64 insertions, 35 deletions
diff --git a/src/3rdparty/assimp/code/glTFImporter.cpp b/src/3rdparty/assimp/code/glTFImporter.cpp
index 6a6619b81..5d1b5afab 100644
--- a/src/3rdparty/assimp/code/glTFImporter.cpp
+++ b/src/3rdparty/assimp/code/glTFImporter.cpp
@@ -1,8 +1,9 @@
-/*
+/*
Open Asset Import Library (assimp)
----------------------------------------------------------------------
-Copyright (c) 2006-2016, assimp team
+Copyright (c) 2006-2017, assimp team
+
All rights reserved.
Redistribution and use of this software in source and binary forms,
@@ -41,13 +42,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER
#include "glTFImporter.h"
-
#include "StringComparison.h"
+#include "StringUtils.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/ai_assert.h>
#include <assimp/DefaultLogger.hpp>
+#include <assimp/importerdesc.h>
+
#include <memory>
#include "MakeVerboseFormat.h"
@@ -97,24 +100,19 @@ const aiImporterDesc* glTFImporter::GetInfo() const
bool glTFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
{
- const std::string& extension = GetExtension(pFile);
-
- if (extension == "gltf" || extension == "glb")
- return true;
-
- if ((checkSig || !extension.length()) && pIOHandler) {
- char buffer[4];
-
- std::unique_ptr<IOStream> pStream(pIOHandler->Open(pFile));
- if (pStream && pStream->Read(buffer, sizeof(buffer), 1) == 1) {
- if (memcmp(buffer, AI_GLB_MAGIC_NUMBER, sizeof(buffer)) == 0) {
- return true; // Has GLB header
- }
- else if (memcmp(buffer, "{\r\n ", sizeof(buffer)) == 0
- || memcmp(buffer, "{\n ", sizeof(buffer)) == 0) {
- // seems a JSON file, and we're the only format that can read them
- return true;
- }
+ const std::string &extension = GetExtension(pFile);
+
+ if (extension != "gltf" && extension != "glb")
+ return false;
+
+ if (checkSig && pIOHandler) {
+ glTF::Asset asset(pIOHandler);
+ try {
+ asset.Load(pFile, extension == "glb");
+ std::string version = asset.asset.version;
+ return !version.empty() && version[0] == '1';
+ } catch (...) {
+ return false;
}
}
@@ -156,7 +154,7 @@ static void CopyValue(const glTF::mat4& v, aiMatrix4x4& o)
o.a4 = v[12]; o.b4 = v[13]; o.c4 = v[14]; o.d4 = v[15];
}
-inline void SetMaterialColorProperty(std::vector<int>& embeddedTexIdxs, Asset& r, glTF::TexProperty prop, aiMaterial* mat,
+inline void SetMaterialColorProperty(std::vector<int>& embeddedTexIdxs, Asset& /*r*/, glTF::TexProperty prop, aiMaterial* mat,
aiTextureType texType, const char* pKey, unsigned int type, unsigned int idx)
{
if (prop.texture) {
@@ -176,9 +174,7 @@ inline void SetMaterialColorProperty(std::vector<int>& embeddedTexIdxs, Asset& r
else {
aiColor4D col;
CopyValue(prop.color, col);
- if (col.r != 1.f || col.g != 1.f || col.b != 1.f || col.a != 1.f) {
- mat->AddProperty(&col, 1, pKey, type, idx);
- }
+ mat->AddProperty(&col, 1, pKey, type, idx);
}
}
@@ -238,6 +234,7 @@ static inline void SetFace(aiFace& face, int a, int b, int c)
face.mIndices[2] = c;
}
+#ifdef ASSIMP_BUILD_DEBUG
static inline bool CheckValidFacesIndices(aiFace* faces, unsigned nFaces, unsigned nVerts)
{
for (unsigned i = 0; i < nFaces; ++i) {
@@ -249,6 +246,7 @@ static inline bool CheckValidFacesIndices(aiFace* faces, unsigned nFaces, unsign
}
return true;
}
+#endif // ASSIMP_BUILD_DEBUG
void glTFImporter::ImportMeshes(glTF::Asset& r)
{
@@ -259,7 +257,39 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
for (unsigned int m = 0; m < r.meshes.Size(); ++m) {
Mesh& mesh = r.meshes[m];
- meshOffsets.push_back(k);
+ // Check if mesh extensions is used
+ if(mesh.Extension.size() > 0)
+ {
+ for(Mesh::SExtension* cur_ext : mesh.Extension)
+ {
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
+ if(cur_ext->Type == Mesh::SExtension::EType::Compression_Open3DGC)
+ {
+ // Limitations for meshes when using Open3DGC-compression.
+ // It's a current limitation of sp... Specification have not this part still - about mesh compression. Why only one primitive?
+ // Because glTF is very flexibly. But in fact it ugly flexible. Every primitive can has own set of accessors and accessors can
+ // point to a-a-a-a-any part of buffer (through bufferview of course) and even to another buffer. We know that "Open3DGC-compression"
+ // is applicable only to part of buffer. As we can't guaranty continuity of the data for decoder, we will limit quantity of primitives.
+ // Yes indices, coordinates etc. still can br stored in different buffers, but with current specification it's a exporter problem.
+ // Also primitive can has only one of "POSITION", "NORMAL" and less then "AI_MAX_NUMBER_OF_TEXTURECOORDS" of "TEXCOORD". All accessor
+ // of primitive must point to one continuous region of the buffer.
+ if(mesh.primitives.size() > 2) throw DeadlyImportError("GLTF: When using Open3DGC compression then only one primitive per mesh are allowed.");
+
+ Mesh::SCompression_Open3DGC* o3dgc_ext = (Mesh::SCompression_Open3DGC*)cur_ext;
+ Ref<Buffer> buf = r.buffers.Get(o3dgc_ext->Buffer);
+
+ buf->EncodedRegion_SetCurrent(mesh.id);
+ }
+ else
+#endif
+ {
+ throw DeadlyImportError("GLTF: Can not import mesh: unknown mesh extension (code: \"" + to_string(cur_ext->Type) +
+ "\"), only Open3DGC is supported.");
+ }
+ }
+ }// if(mesh.Extension.size() > 0)
+
+ meshOffsets.push_back(k);
k += unsigned(mesh.primitives.size());
for (unsigned int p = 0; p < mesh.primitives.size(); ++p) {
@@ -294,16 +324,15 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
}
Mesh::Primitive::Attributes& attr = prim.attributes;
- if (attr.position.size() > 0 && attr.position[0]) {
+
+ if (attr.position.size() > 0 && attr.position[0]) {
aim->mNumVertices = attr.position[0]->count;
attr.position[0]->ExtractData(aim->mVertices);
- }
+ }
- if (attr.normal.size() > 0 && attr.normal[0]) {
- attr.normal[0]->ExtractData(aim->mNormals);
- }
+ if (attr.normal.size() > 0 && attr.normal[0]) attr.normal[0]->ExtractData(aim->mNormals);
- for (size_t tc = 0; tc < attr.texcoord.size() && tc <= AI_MAX_NUMBER_OF_TEXTURECOORDS; ++tc) {
+ for (size_t tc = 0; tc < attr.texcoord.size() && tc < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++tc) {
attr.texcoord[tc]->ExtractData(aim->mTextureCoords[tc]);
aim->mNumUVComponents[tc] = attr.texcoord[tc]->GetNumComponents();
@@ -315,7 +344,7 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
if (prim.indices) {
- aiFace* faces = 0;
+ aiFace* faces = 0;
unsigned int nFaces = 0;
unsigned int count = prim.indices->count;
@@ -641,9 +670,9 @@ void glTFImporter::InternReadFile(const std::string& pFile, aiScene* pScene, IOS
// TODO: it does not split the loaded vertices, should it?
//pScene->mFlags |= AI_SCENE_FLAGS_NON_VERBOSE_FORMAT;
- Assimp::MakeVerboseFormatProcess process;
+ MakeVerboseFormatProcess process;
process.Execute(pScene);
-
+
if (pScene->mNumMeshes == 0) {
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;