Compile with glTF2 export option (currently same as glTF1 output)

pull/1363/head
jamesgk 2017-07-20 10:59:21 -07:00
parent 38626d4260
commit d7cbbaf23e
8 changed files with 52 additions and 51 deletions

View File

@ -661,6 +661,12 @@ ADD_ASSIMP_IMPORTER( GLTF
glTFImporter.h glTFImporter.h
glTFExporter.h glTFExporter.h
glTFExporter.cpp glTFExporter.cpp
glTF2Asset.h
glTF2Asset.inl
glTF2AssetWriter.h
glTF2AssetWriter.inl
glTF2Exporter.h
glTF2Exporter.cpp
) )
ADD_ASSIMP_IMPORTER( 3MF ADD_ASSIMP_IMPORTER( 3MF

View File

@ -90,6 +90,7 @@ void ExportScenePlyBinary(const char*, IOSystem*, const aiScene*, const ExportPr
void ExportScene3DS(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportScene3DS(const char*, IOSystem*, const aiScene*, const ExportProperties*);
void ExportSceneGLTF(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportSceneGLTF(const char*, IOSystem*, const aiScene*, const ExportProperties*);
void ExportSceneGLB(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportSceneGLB(const char*, IOSystem*, const aiScene*, const ExportProperties*);
void ExportSceneGLTF2(const char*, IOSystem*, const aiScene*, const ExportProperties*);
void ExportSceneAssbin(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportSceneAssbin(const char*, IOSystem*, const aiScene*, const ExportProperties*);
void ExportSceneAssxml(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportSceneAssxml(const char*, IOSystem*, const aiScene*, const ExportProperties*);
void ExportSceneX3D(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportSceneX3D(const char*, IOSystem*, const aiScene*, const ExportProperties*);
@ -144,6 +145,8 @@ Exporter::ExportFormatEntry gExporters[] =
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType), aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType),
Exporter::ExportFormatEntry( "glb", "GL Transmission Format (binary)", "glb", &ExportSceneGLB, Exporter::ExportFormatEntry( "glb", "GL Transmission Format (binary)", "glb", &ExportSceneGLB,
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType), aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType),
Exporter::ExportFormatEntry( "gltf2", "GL Transmission Format v. 2", "gltf", &ExportSceneGLTF2,
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType),
#endif #endif
#ifndef ASSIMP_BUILD_NO_ASSBIN_EXPORTER #ifndef ASSIMP_BUILD_NO_ASSBIN_EXPORTER

View File

@ -46,8 +46,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* KHR_binary_glTF: full * KHR_binary_glTF: full
* KHR_materials_common: full * KHR_materials_common: full
*/ */
#ifndef GLTFASSET_H_INC #ifndef GLTF2ASSET_H_INC
#define GLTFASSET_H_INC #define GLTF2ASSET_H_INC
#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER #ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER
@ -89,7 +89,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# endif # endif
#endif #endif
namespace glTF namespace glTF2
{ {
#ifdef ASSIMP_API #ifdef ASSIMP_API
using Assimp::IOStream; using Assimp::IOStream;
@ -1187,8 +1187,8 @@ namespace glTF
} }
// Include the implementation of the methods // Include the implementation of the methods
#include "glTFAsset.inl" #include "glTF2Asset.inl"
#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER #endif // ASSIMP_BUILD_NO_GLTF_IMPORTER
#endif // GLTFASSET_H_INC #endif // GLTF2ASSET_H_INC

View File

@ -51,7 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace Assimp; using namespace Assimp;
namespace glTF { namespace glTF2 {
namespace { namespace {

View File

@ -46,14 +46,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* KHR_binary_glTF: full * KHR_binary_glTF: full
* KHR_materials_common: full * KHR_materials_common: full
*/ */
#ifndef GLTFASSETWRITER_H_INC #ifndef GLTF2ASSETWRITER_H_INC
#define GLTFASSETWRITER_H_INC #define GLTF2ASSETWRITER_H_INC
#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER #ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER
#include "glTFAsset.h" #include "glTF2Asset.h"
namespace glTF namespace glTF2
{ {
using rapidjson::MemoryPoolAllocator; using rapidjson::MemoryPoolAllocator;
@ -88,8 +88,8 @@ public:
} }
// Include the implementation of the methods // Include the implementation of the methods
#include "glTFAssetWriter.inl" #include "glTF2AssetWriter.inl"
#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER #endif // ASSIMP_BUILD_NO_GLTF_IMPORTER
#endif // GLTFASSETWRITER_H_INC #endif // GLTF2ASSETWRITER_H_INC

View File

@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <rapidjson/writer.h> #include <rapidjson/writer.h>
#include <rapidjson/prettywriter.h> #include <rapidjson/prettywriter.h>
namespace glTF { namespace glTF2 {
using rapidjson::StringBuffer; using rapidjson::StringBuffer;
using rapidjson::PrettyWriter; using rapidjson::PrettyWriter;

View File

@ -41,7 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_EXPORT #ifndef ASSIMP_BUILD_NO_EXPORT
#ifndef ASSIMP_BUILD_NO_GLTF_EXPORTER #ifndef ASSIMP_BUILD_NO_GLTF_EXPORTER
#include "glTFExporter.h" #include "glTF2Exporter.h"
#include "Exceptional.h" #include "Exceptional.h"
#include "StringComparison.h" #include "StringComparison.h"
@ -60,7 +60,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <memory> #include <memory>
#include <inttypes.h> #include <inttypes.h>
#include "glTFAssetWriter.h" #include "glTF2AssetWriter.h"
#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC #ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
// Header files, Open3DGC. // Header files, Open3DGC.
@ -70,29 +70,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace rapidjson; using namespace rapidjson;
using namespace Assimp; using namespace Assimp;
using namespace glTF; using namespace glTF2;
namespace Assimp { namespace Assimp {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Worker function for exporting a scene to GLTF. Prototyped and registered in Exporter.cpp // Worker function for exporting a scene to GLTF. Prototyped and registered in Exporter.cpp
void ExportSceneGLTF(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties) void ExportSceneGLTF2(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
{ {
// invoke the exporter // invoke the exporter
glTFExporter exporter(pFile, pIOSystem, pScene, pProperties, false); glTF2Exporter exporter(pFile, pIOSystem, pScene, pProperties, false);
}
// ------------------------------------------------------------------------------------------------
// Worker function for exporting a scene to GLB. Prototyped and registered in Exporter.cpp
void ExportSceneGLB(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
{
// invoke the exporter
glTFExporter exporter(pFile, pIOSystem, pScene, pProperties, true);
} }
} // end of namespace Assimp } // end of namespace Assimp
glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiScene* pScene, glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const aiScene* pScene,
const ExportProperties* pProperties, bool isBinary) const ExportProperties* pProperties, bool isBinary)
: mFilename(filename) : mFilename(filename)
, mIOSystem(pIOSystem) , mIOSystem(pIOSystem)
@ -112,7 +104,7 @@ glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiSc
mScene = sceneCopy.get(); mScene = sceneCopy.get();
mAsset.reset( new glTF::Asset( pIOSystem ) ); mAsset.reset( new Asset( pIOSystem ) );
if (isBinary) { if (isBinary) {
mAsset->SetAsBinary(); mAsset->SetAsBinary();
@ -138,7 +130,7 @@ glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiSc
ExportAnimations(); ExportAnimations();
glTF::AssetWriter writer(*mAsset); AssetWriter writer(*mAsset);
if (isBinary) { if (isBinary) {
writer.WriteGLBFile(filename); writer.WriteGLBFile(filename);
@ -151,7 +143,7 @@ glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiSc
* Copy a 4x4 matrix from struct aiMatrix to typedef mat4. * Copy a 4x4 matrix from struct aiMatrix to typedef mat4.
* Also converts from row-major to column-major storage. * Also converts from row-major to column-major storage.
*/ */
static void CopyValue(const aiMatrix4x4& v, glTF::mat4& o) static void CopyValue(const aiMatrix4x4& v, mat4& o)
{ {
o[ 0] = v.a1; o[ 1] = v.b1; o[ 2] = v.c1; o[ 3] = v.d1; o[ 0] = v.a1; o[ 1] = v.b1; o[ 2] = v.c1; o[ 3] = v.d1;
o[ 4] = v.a2; o[ 5] = v.b2; o[ 6] = v.c2; o[ 7] = v.d2; o[ 4] = v.a2; o[ 5] = v.b2; o[ 6] = v.c2; o[ 7] = v.d2;
@ -167,7 +159,7 @@ static void CopyValue(const aiMatrix4x4& v, aiMatrix4x4& o)
o.d1 = v.d1; o.d2 = v.d2; o.d3 = v.d3; o.d4 = v.d4; o.d1 = v.d1; o.d2 = v.d2; o.d3 = v.d3; o.d4 = v.d4;
} }
static void IdentityMatrix4(glTF::mat4& o) static void IdentityMatrix4(mat4& o)
{ {
o[ 0] = 1; o[ 1] = 0; o[ 2] = 0; o[ 3] = 0; o[ 0] = 1; o[ 1] = 0; o[ 2] = 0; o[ 3] = 0;
o[ 4] = 0; o[ 5] = 1; o[ 6] = 0; o[ 7] = 0; o[ 4] = 0; o[ 5] = 1; o[ 6] = 0; o[ 7] = 0;
@ -248,7 +240,7 @@ namespace {
} }
} }
void glTFExporter::GetTexSampler(const aiMaterial* mat, glTF::TexProperty& prop) void glTF2Exporter::GetTexSampler(const aiMaterial* mat, TexProperty& prop)
{ {
std::string samplerId = mAsset->FindUniqueID("", "sampler"); std::string samplerId = mAsset->FindUniqueID("", "sampler");
prop.texture->sampler = mAsset->samplers.Create(samplerId); prop.texture->sampler = mAsset->samplers.Create(samplerId);
@ -294,7 +286,7 @@ void glTFExporter::GetTexSampler(const aiMaterial* mat, glTF::TexProperty& prop)
prop.texture->sampler->minFilter = SamplerMinFilter_Linear; prop.texture->sampler->minFilter = SamplerMinFilter_Linear;
} }
void glTFExporter::GetMatColorOrTex(const aiMaterial* mat, glTF::TexProperty& prop, const char* propName, int type, int idx, aiTextureType tt) void glTF2Exporter::GetMatColorOrTex(const aiMaterial* mat, TexProperty& prop, const char* propName, int type, int idx, aiTextureType tt)
{ {
aiString tex; aiString tex;
aiColor4D col; aiColor4D col;
@ -346,7 +338,7 @@ void glTFExporter::GetMatColorOrTex(const aiMaterial* mat, glTF::TexProperty& pr
} }
void glTFExporter::ExportMaterials() void glTF2Exporter::ExportMaterials()
{ {
aiString aiName; aiString aiName;
for (unsigned int i = 0; i < mScene->mNumMaterials; ++i) { for (unsigned int i = 0; i < mScene->mNumMaterials; ++i) {
@ -496,7 +488,7 @@ void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref<Mesh>& meshRef, Ref<Buf
delete[] vertexJointData; delete[] vertexJointData;
} }
void glTFExporter::ExportMeshes() void glTF2Exporter::ExportMeshes()
{ {
// Not for // Not for
// using IndicesType = decltype(aiFace::mNumIndices); // using IndicesType = decltype(aiFace::mNumIndices);
@ -768,7 +760,7 @@ void glTFExporter::ExportMeshes()
* Export the root node of the node hierarchy. * Export the root node of the node hierarchy.
* Calls ExportNode for all children. * Calls ExportNode for all children.
*/ */
unsigned int glTFExporter::ExportNodeHierarchy(const aiNode* n) unsigned int glTF2Exporter::ExportNodeHierarchy(const aiNode* n)
{ {
Ref<Node> node = mAsset->nodes.Create(mAsset->FindUniqueID(n->mName.C_Str(), "node")); Ref<Node> node = mAsset->nodes.Create(mAsset->FindUniqueID(n->mName.C_Str(), "node"));
@ -793,7 +785,7 @@ unsigned int glTFExporter::ExportNodeHierarchy(const aiNode* n)
* Export node and recursively calls ExportNode for all children. * Export node and recursively calls ExportNode for all children.
* Since these nodes are not the root node, we also export the parent Ref<Node> * Since these nodes are not the root node, we also export the parent Ref<Node>
*/ */
unsigned int glTFExporter::ExportNode(const aiNode* n, Ref<Node>& parent) unsigned int glTF2Exporter::ExportNode(const aiNode* n, Ref<Node>& parent)
{ {
Ref<Node> node = mAsset->nodes.Create(mAsset->FindUniqueID(n->mName.C_Str(), "node")); Ref<Node> node = mAsset->nodes.Create(mAsset->FindUniqueID(n->mName.C_Str(), "node"));
@ -817,7 +809,7 @@ unsigned int glTFExporter::ExportNode(const aiNode* n, Ref<Node>& parent)
} }
void glTFExporter::ExportScene() void glTF2Exporter::ExportScene()
{ {
const char* sceneName = "defaultScene"; const char* sceneName = "defaultScene";
Ref<Scene> scene = mAsset->scenes.Create(sceneName); Ref<Scene> scene = mAsset->scenes.Create(sceneName);
@ -831,9 +823,9 @@ void glTFExporter::ExportScene()
mAsset->scene = scene; mAsset->scene = scene;
} }
void glTFExporter::ExportMetadata() void glTF2Exporter::ExportMetadata()
{ {
glTF::AssetMetadata& asset = mAsset->asset; AssetMetadata& asset = mAsset->asset;
asset.version = 1; asset.version = 1;
char buffer[256]; char buffer[256];
@ -931,7 +923,7 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animati
} }
} }
void glTFExporter::ExportAnimations() void glTF2Exporter::ExportAnimations()
{ {
Ref<Buffer> bufferRef = mAsset->buffers.Get(unsigned (0)); Ref<Buffer> bufferRef = mAsset->buffers.Get(unsigned (0));

View File

@ -42,8 +42,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** @file GltfExporter.h /** @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
*/ */
#ifndef AI_GLTFEXPORTER_H_INC #ifndef AI_GLTF2EXPORTER_H_INC
#define AI_GLTFEXPORTER_H_INC #define AI_GLTF2EXPORTER_H_INC
#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER #ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER
@ -59,7 +59,7 @@ struct aiScene;
struct aiNode; struct aiNode;
struct aiMaterial; struct aiMaterial;
namespace glTF namespace glTF2
{ {
template<class T> template<class T>
class Ref; class Ref;
@ -78,11 +78,11 @@ namespace Assimp
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
/** Helper class to export a given scene to an glTF file. */ /** Helper class to export a given scene to an glTF file. */
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
class glTFExporter class glTF2Exporter
{ {
public: public:
/// Constructor for a specific scene to export /// Constructor for a specific scene to export
glTFExporter(const char* filename, IOSystem* pIOSystem, const aiScene* pScene, glTF2Exporter(const char* filename, IOSystem* pIOSystem, const aiScene* pScene,
const ExportProperties* pProperties, bool binary); const ExportProperties* pProperties, bool binary);
private: private:
@ -94,19 +94,19 @@ namespace Assimp
std::map<std::string, unsigned int> mTexturesByPath; std::map<std::string, unsigned int> mTexturesByPath;
std::shared_ptr<glTF::Asset> mAsset; std::shared_ptr<glTF2::Asset> mAsset;
std::vector<unsigned char> mBodyData; std::vector<unsigned char> mBodyData;
void WriteBinaryData(IOStream* outfile, std::size_t sceneLength); void WriteBinaryData(IOStream* outfile, std::size_t sceneLength);
void GetTexSampler(const aiMaterial* mat, glTF::TexProperty& prop); void GetTexSampler(const aiMaterial* mat, glTF2::TexProperty& prop);
void GetMatColorOrTex(const aiMaterial* mat, glTF::TexProperty& prop, const char* propName, int type, int idx, aiTextureType tt); void GetMatColorOrTex(const aiMaterial* mat, glTF2::TexProperty& prop, const char* propName, int type, int idx, aiTextureType tt);
void ExportMetadata(); void ExportMetadata();
void ExportMaterials(); void ExportMaterials();
void ExportMeshes(); void ExportMeshes();
unsigned int ExportNodeHierarchy(const aiNode* n); unsigned int ExportNodeHierarchy(const aiNode* n);
unsigned int ExportNode(const aiNode* node, glTF::Ref<glTF::Node>& parent); unsigned int ExportNode(const aiNode* node, glTF2::Ref<glTF2::Node>& parent);
void ExportScene(); void ExportScene();
void ExportAnimations(); void ExportAnimations();
}; };
@ -115,4 +115,4 @@ namespace Assimp
#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER #endif // ASSIMP_BUILD_NO_GLTF_IMPORTER
#endif // AI_GLTFEXPORTER_H_INC #endif // AI_GLTF2EXPORTER_H_INC