Experimental support for glTF
parent
64a020965f
commit
148a20a703
|
@ -562,9 +562,12 @@ ADD_ASSIMP_IMPORTER(X
|
|||
XFileExporter.cpp
|
||||
)
|
||||
|
||||
ADD_ASSIMP_IMPORTER( glFT
|
||||
glTFImporter.cpp
|
||||
glTFImporter.h
|
||||
ADD_ASSIMP_IMPORTER(GLTF
|
||||
glTFImporter.cpp
|
||||
glTFImporter.h
|
||||
glTFUtil.cpp
|
||||
glTFUtil.h
|
||||
glTFFileData.h
|
||||
)
|
||||
|
||||
SET( Step_SRCS
|
||||
|
@ -654,6 +657,8 @@ SET( picojson_SRCS
|
|||
)
|
||||
SOURCE_GROUP( picojson FILES ${picojson_SRCS} )
|
||||
|
||||
INCLUDE_DIRECTORIES( "../contrib/rapidjson/include" )
|
||||
|
||||
# VC2010 fixes
|
||||
if(MSVC10)
|
||||
option( VC10_STDINT_FIX "Fix for VC10 Compiler regarding pstdint.h redefinition errors" OFF )
|
||||
|
|
|
@ -167,6 +167,9 @@ corresponding preprocessor flag to selectively disable formats.
|
|||
#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
|
||||
# include "FBXImporter.h"
|
||||
#endif
|
||||
#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER
|
||||
# include "glTFImporter.h"
|
||||
#endif
|
||||
#ifndef ASSIMP_BUILD_NO_ASSBIN_IMPORTER
|
||||
# include "AssbinLoader.h"
|
||||
#endif
|
||||
|
@ -302,6 +305,9 @@ void GetImporterInstanceList(std::vector< BaseImporter* >& out)
|
|||
#if ( !defined ASSIMP_BUILD_NO_FBX_IMPORTER )
|
||||
out.push_back( new FBXImporter() );
|
||||
#endif
|
||||
#if ( !defined ASSIMP_BUILD_NO_GLTF_IMPORTER )
|
||||
out.push_back( new glTFImporter() );
|
||||
#endif
|
||||
#if ( !defined ASSIMP_BUILD_NO_ASSBIN_IMPORTER )
|
||||
out.push_back( new AssbinImporter() );
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2015, assimp team
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef AI_GLTFFILEDATA_H_INC
|
||||
#define AI_GLTFFILEDATA_H_INC
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Assimp {
|
||||
namespace glTF {
|
||||
|
||||
|
||||
//! Magic number for GLB files
|
||||
#define AI_GLB_MAGIC_NUMBER "glTF"
|
||||
|
||||
|
||||
#include "./../include/assimp/Compiler/pushpack1.h"
|
||||
|
||||
// KHR_binary_glTF (binary .glb file)
|
||||
// 20-byte header (+ the JSON + a "body" data section)
|
||||
struct GLB_Header
|
||||
{
|
||||
//! Magic number: "glTF"
|
||||
unsigned char magic[4]; // "glTF"
|
||||
|
||||
//! Version number (always 1 as of the last update)
|
||||
uint32_t version;
|
||||
|
||||
//! Total length of the Binary glTF, including header, scene, and body, in bytes
|
||||
uint32_t length;
|
||||
|
||||
//! Length, in bytes, of the glTF scene
|
||||
uint32_t sceneLength;
|
||||
|
||||
//! Specifies the format of the glTF scene (see the SceneFormat enum)
|
||||
uint32_t sceneFormat;
|
||||
} PACK_STRUCT;
|
||||
|
||||
#include "./../include/assimp/Compiler/poppack1.h"
|
||||
|
||||
|
||||
|
||||
//! Values for the GLB_Header::sceneFormat field
|
||||
enum SceneFormat
|
||||
{
|
||||
SceneFormat_JSON = 0
|
||||
};
|
||||
|
||||
|
||||
//! Values for the mesh primitive modes
|
||||
enum PrimitiveMode
|
||||
{
|
||||
PrimitiveMode_POINTS = 0,
|
||||
PrimitiveMode_LINES = 1,
|
||||
PrimitiveMode_LINE_LOOP = 2,
|
||||
PrimitiveMode_LINE_STRIP = 3,
|
||||
PrimitiveMode_TRIANGLES = 4,
|
||||
PrimitiveMode_TRIANGLE_STRIP = 5,
|
||||
PrimitiveMode_TRIANGLE_FAN = 6
|
||||
};
|
||||
|
||||
|
||||
//! Values for the accessors component type field
|
||||
enum ComponentType
|
||||
{
|
||||
ComponentType_BYTE = 5120,
|
||||
ComponentType_UNSIGNED_BYTE = 5121,
|
||||
ComponentType_SHORT = 5122,
|
||||
ComponentType_UNSIGNED_SHORT = 5123,
|
||||
ComponentType_FLOAT = 5126
|
||||
};
|
||||
|
||||
|
||||
//! Will hold the enabled extensions
|
||||
struct Extensions
|
||||
{
|
||||
bool KHR_binary_glTF;
|
||||
};
|
||||
|
||||
|
||||
} // end namespaces
|
||||
}
|
||||
|
||||
|
||||
#endif // AI_GLTFFILEDATA_H_INC
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -41,10 +41,34 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#define AI_GLTFIMPORTER_H_INC
|
||||
|
||||
#include "BaseImporter.h"
|
||||
#include "LogAux.h"
|
||||
#include "DefaultIOSystem.h"
|
||||
|
||||
#if _MSC_VER > 1500 || (defined __GNUC___)
|
||||
# define ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
|
||||
# else
|
||||
# define gltf_unordered_map map
|
||||
# define gltf_unordered_multimap multimap
|
||||
#endif
|
||||
|
||||
#ifdef ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
|
||||
# include <unordered_map>
|
||||
# if _MSC_VER > 1600
|
||||
# define gltf_unordered_map unordered_map
|
||||
# define gltf_unordered_multimap unordered_multimap
|
||||
# else
|
||||
# define gltf_unordered_map tr1::unordered_map
|
||||
# define gltf_unordered_multimap tr1::unordered_multimap
|
||||
# endif
|
||||
#endif
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
class glTFImporter : public BaseImporter {
|
||||
/**
|
||||
* Load the glTF format.
|
||||
* https://github.com/KhronosGroup/glTF/tree/master/specification
|
||||
*/
|
||||
class glTFImporter : public BaseImporter, public LogFunctions<glTFImporter> {
|
||||
public:
|
||||
glTFImporter();
|
||||
virtual ~glTFImporter();
|
||||
|
@ -55,8 +79,10 @@ protected:
|
|||
virtual void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler );
|
||||
|
||||
private:
|
||||
aiScene *m_scene;
|
||||
std::vector<char> m_buffer;
|
||||
void ReadBinaryHeader(IOStream& stream);
|
||||
|
||||
std::size_t mSceneLength;
|
||||
std::size_t mBodyOffset, mBodyLength;
|
||||
};
|
||||
|
||||
} // Namespace assimp
|
||||
|
|
|
@ -0,0 +1,164 @@
|
|||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2015, assimp team
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#include "glTFUtil.h"
|
||||
|
||||
|
||||
using namespace Assimp;
|
||||
using namespace Assimp::glTF;
|
||||
|
||||
|
||||
bool Assimp::glTF::IsDataURI(const char* uri)
|
||||
{
|
||||
return strncmp(uri, "data:", 5) == 0;
|
||||
}
|
||||
|
||||
|
||||
static const uint8_t tableDecodeBase64[128] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F,
|
||||
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
|
||||
0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
|
||||
0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
|
||||
0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
|
||||
0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
|
||||
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
|
||||
0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
|
||||
0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
static inline char EncodeCharBase64(uint8_t b)
|
||||
{
|
||||
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="[b];
|
||||
}
|
||||
|
||||
static inline uint8_t DecodeCharBase64(char c)
|
||||
{
|
||||
return tableDecodeBase64[c]; // TODO faster with lookup table or ifs?
|
||||
/*if (c >= 'A' && c <= 'Z') return c - 'A';
|
||||
if (c >= 'a' && c <= 'z') return c - 'a' + 26;
|
||||
if (c >= '0' && c <= '9') return c - '0' + 52;
|
||||
return c == '+' ? 62 : 63;*/
|
||||
}
|
||||
|
||||
std::size_t Assimp::glTF::DecodeBase64(
|
||||
const char* in, uint8_t*& out)
|
||||
{
|
||||
return DecodeBase64(in, strlen(in), out);
|
||||
}
|
||||
|
||||
std::size_t Assimp::glTF::DecodeBase64(
|
||||
const char* in, std::size_t inLength, uint8_t*& out)
|
||||
{
|
||||
ai_assert(dataLen % 4 == 0);
|
||||
|
||||
if (inLength < 4) {
|
||||
out = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nEquals = int(in[inLength - 1] == '=') +
|
||||
int(in[inLength - 2] == '=');
|
||||
|
||||
std::size_t outLength = (inLength * 3) / 4 - nEquals;
|
||||
out = new uint8_t[outLength];
|
||||
memset(out, 0, outLength);
|
||||
|
||||
std::size_t j = 0;
|
||||
|
||||
for (std::size_t i = 0; i < inLength; i += 4) {
|
||||
uint8_t b0 = DecodeCharBase64(in[i]);
|
||||
uint8_t b1 = DecodeCharBase64(in[i + 1]);
|
||||
uint8_t b2 = DecodeCharBase64(in[i + 2]);
|
||||
uint8_t b3 = DecodeCharBase64(in[i + 3]);
|
||||
|
||||
out[j++] = (uint8_t)((b0 << 2) | (b1 >> 4));
|
||||
out[j++] = (uint8_t)((b1 << 4) | (b2 >> 2));
|
||||
out[j++] = (uint8_t)((b2 << 6) | b3);
|
||||
}
|
||||
|
||||
return outLength;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Assimp::glTF::EncodeBase64(
|
||||
const uint8_t* in, std::size_t inLength,
|
||||
std::string& out)
|
||||
{
|
||||
std::size_t outLength = ((inLength + 2) / 3) * 4;
|
||||
|
||||
out.resize(outLength);
|
||||
|
||||
std::size_t j = 0;
|
||||
for (std::size_t i = 0; i < inLength; i += 3) {
|
||||
uint8_t b = (in[i] & 0xFC) >> 2;
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
|
||||
b = (in[i] & 0x03) << 4;
|
||||
if (i + 1 < inLength) {
|
||||
b |= (in[i + 1] & 0xF0) >> 4;
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
|
||||
b = (in[i + 1] & 0x0F) << 2;
|
||||
if (i + 2 < inLength) {
|
||||
b |= (in[i + 2] & 0xC0) >> 6;
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
|
||||
b = in[i + 2] & 0x3F;
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
}
|
||||
else {
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
out[j++] = '=';
|
||||
}
|
||||
}
|
||||
else {
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
out[j++] = '=';
|
||||
out[j++] = '=';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2015, assimp team
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef AI_GLTFUTIL_H_INC
|
||||
#define AI_GLTFUTIL_H_INC
|
||||
|
||||
//#include "StreamReader.h"
|
||||
//#include "MemoryIOWrapper.h"
|
||||
#include "StringComparison.h"
|
||||
|
||||
namespace Assimp {
|
||||
namespace glTF {
|
||||
|
||||
//
|
||||
// Misc
|
||||
//
|
||||
|
||||
std::size_t DecodeBase64(const char* in, uint8_t*& out);
|
||||
std::size_t DecodeBase64(const char* in, std::size_t inLength, uint8_t*& out);
|
||||
|
||||
void EncodeBase64(const uint8_t* in, std::size_t inLength, std::string& out);
|
||||
|
||||
|
||||
bool IsDataURI(const char* uri);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // AI_GLTFUTIL_H_INC
|
||||
|
Loading…
Reference in New Issue