Parcourir la source

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

jamesgk il y a 8 ans
Parent
commit
d7cbbaf23e

+ 6 - 0
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

+ 3 - 0
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

+ 5 - 5
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

+ 1 - 1
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 {
 

+ 6 - 6
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

+ 1 - 1
code/glTF2AssetWriter.inl

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

+ 20 - 28
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 <memory>
 #include <inttypes.h>
 
-#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<Mesh>& meshRef, Ref<Buf
     delete[] vertexJointData;
 }
 
-void glTFExporter::ExportMeshes()
+void glTF2Exporter::ExportMeshes()
 {
     // Not for
     //     using IndicesType = decltype(aiFace::mNumIndices);
@@ -768,7 +760,7 @@ void glTFExporter::ExportMeshes()
  * Export the root node of the node hierarchy.
  * 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"));
 
@@ -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<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"));
 
@@ -817,7 +809,7 @@ unsigned int glTFExporter::ExportNode(const aiNode* n, Ref<Node>& parent)
 }
 
 
-void glTFExporter::ExportScene()
+void glTF2Exporter::ExportScene()
 {
     const char* sceneName = "defaultScene";
     Ref<Scene> 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<Animati
     }
 }
 
-void glTFExporter::ExportAnimations()
+void glTF2Exporter::ExportAnimations()
 {
     Ref<Buffer> bufferRef = mAsset->buffers.Get(unsigned (0));
 

+ 10 - 10
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 T>
     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<std::string, unsigned int> mTexturesByPath;
 
-        std::shared_ptr<glTF::Asset> mAsset;
+        std::shared_ptr<glTF2::Asset> mAsset;
 
         std::vector<unsigned char> 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<glTF::Node>& parent);
+        unsigned int ExportNode(const aiNode* node, glTF2::Ref<glTF2::Node>& 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