From d7cbbaf23e6a0a066c4869d1a211850c4fc59c05 Mon Sep 17 00:00:00 2001 From: jamesgk Date: Thu, 20 Jul 2017 10:59:21 -0700 Subject: [PATCH] Compile with glTF2 export option (currently same as glTF1 output) --- code/CMakeLists.txt | 6 +++++ code/Exporter.cpp | 3 +++ code/glTF2Asset.h | 10 ++++---- code/glTF2Asset.inl | 2 +- code/glTF2AssetWriter.h | 12 +++++----- code/glTF2AssetWriter.inl | 2 +- code/glTF2Exporter.cpp | 48 ++++++++++++++++----------------------- code/glTF2Exporter.h | 20 ++++++++-------- 8 files changed, 52 insertions(+), 51 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 0477f5fef..8c9a248c4 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -661,6 +661,12 @@ ADD_ASSIMP_IMPORTER( GLTF glTFImporter.h glTFExporter.h glTFExporter.cpp + glTF2Asset.h + glTF2Asset.inl + glTF2AssetWriter.h + glTF2AssetWriter.inl + glTF2Exporter.h + glTF2Exporter.cpp ) ADD_ASSIMP_IMPORTER( 3MF diff --git a/code/Exporter.cpp b/code/Exporter.cpp index f03702869..7af7d2cf5 100644 --- a/code/Exporter.cpp +++ b/code/Exporter.cpp @@ -90,6 +90,7 @@ void ExportScenePlyBinary(const char*, IOSystem*, const aiScene*, const ExportPr void ExportScene3DS(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 ExportSceneGLTF2(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 ExportSceneX3D(const char*, IOSystem*, const aiScene*, const ExportProperties*); @@ -144,6 +145,8 @@ Exporter::ExportFormatEntry gExporters[] = aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType), Exporter::ExportFormatEntry( "glb", "GL Transmission Format (binary)", "glb", &ExportSceneGLB, aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType), + Exporter::ExportFormatEntry( "gltf2", "GL Transmission Format v. 2", "gltf", &ExportSceneGLTF2, + aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType), #endif #ifndef ASSIMP_BUILD_NO_ASSBIN_EXPORTER diff --git a/code/glTF2Asset.h b/code/glTF2Asset.h index 41d0dfd06..3331c1128 100644 --- a/code/glTF2Asset.h +++ b/code/glTF2Asset.h @@ -46,8 +46,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * KHR_binary_glTF: full * KHR_materials_common: full */ -#ifndef GLTFASSET_H_INC -#define GLTFASSET_H_INC +#ifndef GLTF2ASSET_H_INC +#define GLTF2ASSET_H_INC #ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER @@ -89,7 +89,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # endif #endif -namespace glTF +namespace glTF2 { #ifdef ASSIMP_API using Assimp::IOStream; @@ -1187,8 +1187,8 @@ namespace glTF } // Include the implementation of the methods -#include "glTFAsset.inl" +#include "glTF2Asset.inl" #endif // ASSIMP_BUILD_NO_GLTF_IMPORTER -#endif // GLTFASSET_H_INC +#endif // GLTF2ASSET_H_INC diff --git a/code/glTF2Asset.inl b/code/glTF2Asset.inl index fe29dde70..9065cedb5 100644 --- a/code/glTF2Asset.inl +++ b/code/glTF2Asset.inl @@ -51,7 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -namespace glTF { +namespace glTF2 { namespace { diff --git a/code/glTF2AssetWriter.h b/code/glTF2AssetWriter.h index 186d32a15..976f23f9a 100644 --- a/code/glTF2AssetWriter.h +++ b/code/glTF2AssetWriter.h @@ -46,14 +46,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * KHR_binary_glTF: full * KHR_materials_common: full */ -#ifndef GLTFASSETWRITER_H_INC -#define GLTFASSETWRITER_H_INC +#ifndef GLTF2ASSETWRITER_H_INC +#define GLTF2ASSETWRITER_H_INC #ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER -#include "glTFAsset.h" +#include "glTF2Asset.h" -namespace glTF +namespace glTF2 { using rapidjson::MemoryPoolAllocator; @@ -88,8 +88,8 @@ public: } // Include the implementation of the methods -#include "glTFAssetWriter.inl" +#include "glTF2AssetWriter.inl" #endif // ASSIMP_BUILD_NO_GLTF_IMPORTER -#endif // GLTFASSETWRITER_H_INC +#endif // GLTF2ASSETWRITER_H_INC diff --git a/code/glTF2AssetWriter.inl b/code/glTF2AssetWriter.inl index d3a553c27..9bf1c5697 100644 --- a/code/glTF2AssetWriter.inl +++ b/code/glTF2AssetWriter.inl @@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -namespace glTF { +namespace glTF2 { using rapidjson::StringBuffer; using rapidjson::PrettyWriter; diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index aeb5069aa..e6dc2c4b1 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -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_GLTF_EXPORTER -#include "glTFExporter.h" +#include "glTF2Exporter.h" #include "Exceptional.h" #include "StringComparison.h" @@ -60,7 +60,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "glTFAssetWriter.h" +#include "glTF2AssetWriter.h" #ifdef ASSIMP_IMPORTER_GLTF_USE_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 Assimp; -using namespace glTF; +using namespace glTF2; namespace Assimp { // ------------------------------------------------------------------------------------------------ // 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 - glTFExporter 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); + glTF2Exporter exporter(pFile, pIOSystem, pScene, pProperties, false); } } // 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) : mFilename(filename) , mIOSystem(pIOSystem) @@ -112,7 +104,7 @@ glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiSc mScene = sceneCopy.get(); - mAsset.reset( new glTF::Asset( pIOSystem ) ); + mAsset.reset( new Asset( pIOSystem ) ); if (isBinary) { mAsset->SetAsBinary(); @@ -138,7 +130,7 @@ glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiSc ExportAnimations(); - glTF::AssetWriter writer(*mAsset); + AssetWriter writer(*mAsset); if (isBinary) { 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. * 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[ 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; } -static void IdentityMatrix4(glTF::mat4& o) +static void IdentityMatrix4(mat4& o) { o[ 0] = 1; o[ 1] = 0; o[ 2] = 0; o[ 3] = 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"); 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; } -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; aiColor4D col; @@ -346,7 +338,7 @@ void glTFExporter::GetMatColorOrTex(const aiMaterial* mat, glTF::TexProperty& pr } -void glTFExporter::ExportMaterials() +void glTF2Exporter::ExportMaterials() { aiString aiName; for (unsigned int i = 0; i < mScene->mNumMaterials; ++i) { @@ -496,7 +488,7 @@ void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref& meshRef, Ref 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. * Since these nodes are not the root node, we also export the parent Ref */ -unsigned int glTFExporter::ExportNode(const aiNode* n, Ref& parent) +unsigned int glTF2Exporter::ExportNode(const aiNode* n, Ref& parent) { Ref node = mAsset->nodes.Create(mAsset->FindUniqueID(n->mName.C_Str(), "node")); @@ -817,7 +809,7 @@ unsigned int glTFExporter::ExportNode(const aiNode* n, Ref& parent) } -void glTFExporter::ExportScene() +void glTF2Exporter::ExportScene() { const char* sceneName = "defaultScene"; Ref scene = mAsset->scenes.Create(sceneName); @@ -831,9 +823,9 @@ void glTFExporter::ExportScene() mAsset->scene = scene; } -void glTFExporter::ExportMetadata() +void glTF2Exporter::ExportMetadata() { - glTF::AssetMetadata& asset = mAsset->asset; + AssetMetadata& asset = mAsset->asset; asset.version = 1; char buffer[256]; @@ -931,7 +923,7 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref bufferRef = mAsset->buffers.Get(unsigned (0)); diff --git a/code/glTF2Exporter.h b/code/glTF2Exporter.h index c813fff44..1378fa9f8 100644 --- a/code/glTF2Exporter.h +++ b/code/glTF2Exporter.h @@ -42,8 +42,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** @file GltfExporter.h * Declares the exporter class to write a scene to a gltf/glb file */ -#ifndef AI_GLTFEXPORTER_H_INC -#define AI_GLTFEXPORTER_H_INC +#ifndef AI_GLTF2EXPORTER_H_INC +#define AI_GLTF2EXPORTER_H_INC #ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER @@ -59,7 +59,7 @@ struct aiScene; struct aiNode; struct aiMaterial; -namespace glTF +namespace glTF2 { template class Ref; @@ -78,11 +78,11 @@ namespace Assimp // ------------------------------------------------------------------------------------------------ /** Helper class to export a given scene to an glTF file. */ // ------------------------------------------------------------------------------------------------ - class glTFExporter + class glTF2Exporter { public: /// 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); private: @@ -94,19 +94,19 @@ namespace Assimp std::map mTexturesByPath; - std::shared_ptr mAsset; + std::shared_ptr mAsset; std::vector mBodyData; void WriteBinaryData(IOStream* outfile, std::size_t sceneLength); - void GetTexSampler(const aiMaterial* mat, glTF::TexProperty& prop); - void GetMatColorOrTex(const aiMaterial* mat, glTF::TexProperty& prop, const char* propName, int type, int idx, aiTextureType tt); + void GetTexSampler(const aiMaterial* mat, glTF2::TexProperty& prop); + void GetMatColorOrTex(const aiMaterial* mat, glTF2::TexProperty& prop, const char* propName, int type, int idx, aiTextureType tt); void ExportMetadata(); void ExportMaterials(); void ExportMeshes(); unsigned int ExportNodeHierarchy(const aiNode* n); - unsigned int ExportNode(const aiNode* node, glTF::Ref& parent); + unsigned int ExportNode(const aiNode* node, glTF2::Ref& parent); void ExportScene(); void ExportAnimations(); }; @@ -115,4 +115,4 @@ namespace Assimp #endif // ASSIMP_BUILD_NO_GLTF_IMPORTER -#endif // AI_GLTFEXPORTER_H_INC +#endif // AI_GLTF2EXPORTER_H_INC