void glTFExporter::ExportMeshes()
{
-// Not for
-// using IndicesType = decltype(aiFace::mNumIndices);
-// But yes for
-// using IndicesType = unsigned short;
-// because "ComponentType_UNSIGNED_SHORT" used for indices. And it's a maximal type according to glTF specification.
-typedef unsigned short IndicesType;
-
-// Variables needed for compression. BEGIN.
-// Indices, not pointers - because pointer to buffer is changin while writing to it.
-size_t idx_srcdata_begin;// Index of buffer before writing mesh data. Also, index of begin of coordinates array in buffer.
-size_t idx_srcdata_normal = SIZE_MAX;// Index of begin of normals array in buffer. SIZE_MAX - mean that mesh has no normals.
-std::vector<size_t> idx_srcdata_tc;// Array of indices. Every index point to begin of texture coordinates array in buffer.
-size_t idx_srcdata_ind;// Index of begin of coordinates indices array in buffer.
-bool comp_allow;// Point that data of current mesh can be compressed.
-// Variables needed for compression. END.
-
- std::string bufferId = mAsset->FindUniqueID("", "buffer");
-
- Ref<Buffer> b = mAsset->GetBodyBuffer();
- if (!b) {
- b = mAsset->buffers.Create(bufferId);
- }
++ // Not for
++ // using IndicesType = decltype(aiFace::mNumIndices);
++ // But yes for
++ // using IndicesType = unsigned short;
++ // because "ComponentType_UNSIGNED_SHORT" used for indices. And it's a maximal type according to glTF specification.
++ typedef unsigned short IndicesType;
++
++ // Variables needed for compression. BEGIN.
++ // Indices, not pointers - because pointer to buffer is changin while writing to it.
++ size_t idx_srcdata_begin;// Index of buffer before writing mesh data. Also, index of begin of coordinates array in buffer.
++ size_t idx_srcdata_normal = SIZE_MAX;// Index of begin of normals array in buffer. SIZE_MAX - mean that mesh has no normals.
++ std::vector<size_t> idx_srcdata_tc;// Array of indices. Every index point to begin of texture coordinates array in buffer.
++ size_t idx_srcdata_ind;// Index of begin of coordinates indices array in buffer.
++ bool comp_allow;// Point that data of current mesh can be compressed.
++ // Variables needed for compression. END.
++
+ std::string fname = std::string(mFilename);
+ std::string bufferIdPrefix = fname.substr(0, fname.find("."));
+ std::string bufferId = mAsset->FindUniqueID("", bufferIdPrefix.c_str());
+
+ Ref<Buffer> b = mAsset->GetBodyBuffer();
+ if (!b) {
- b = mAsset->buffers.Create(bufferId);
++ b = mAsset->buffers.Create(bufferId);
+ }
- for (unsigned int i = 0; i < mScene->mNumMeshes; ++i) {
- const aiMesh* aim = mScene->mMeshes[i];
+ for (unsigned int idx_mesh = 0; idx_mesh < mScene->mNumMeshes; ++idx_mesh) {
+ const aiMesh* aim = mScene->mMeshes[idx_mesh];
+
+ // Check if compressing requested and mesh can be encoded.
+ #ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
+ comp_allow = mProperties->GetPropertyBool("extensions.Open3DGC.use", false);
+ #else
+ comp_allow = false;
+ #endif
+
+ if(comp_allow && (aim->mPrimitiveTypes == aiPrimitiveType_TRIANGLE) && (aim->mNumVertices > 0) && (aim->mNumFaces > 0))
+ {
+ idx_srcdata_tc.clear();
+ idx_srcdata_tc.reserve(AI_MAX_NUMBER_OF_TEXTURECOORDS);
+ }
+ else
+ {
+ std::string msg;
+
+ if(aim->mPrimitiveTypes != aiPrimitiveType_TRIANGLE)
+ msg = "all primitives of the mesh must be a triangles.";
+ else
+ msg = "mesh must has vertices and faces.";
+
+ DefaultLogger::get()->warn("GLTF: can not use Open3DGC-compression: " + msg);
+ comp_allow = false;
+ }
std::string meshId = mAsset->FindUniqueID(aim->mName.C_Str(), "mesh");
Ref<Mesh> m = mAsset->meshes.Create(meshId);