55
66#include " GLTF.hpp"
77
8+ #include < algorithm>
89#include < format>
910#include < iostream>
1011#include < numbers>
11- #include < algorithm>
1212
1313bool hasValidNormals (const Mesh& mesh, const Face& face)
1414{
@@ -156,10 +156,24 @@ template<> TexCoord myMax(TexCoord& a, TexCoord& b)
156156 return out;
157157}
158158
159- void GLTFExporter::buildAssetEntry ()
159+ std::string to_string (ModelType type)
160+ {
161+ switch (type)
162+ {
163+ case ModelType::DIGIMON: return " digimon" ;
164+ case ModelType::DOOR: return " door" ;
165+ default : return " undefined" ;
166+ }
167+ }
168+
169+ void GLTFExporter::buildAssetEntry (ModelType type)
160170{
171+ tinygltf::Value::Object extras;
172+ extras.emplace (" model_type" , to_string (type));
173+
161174 model.asset .version = " 2.0" ;
162175 model.asset .generator = std::format (" {} v{}" , PROJECT_NAME, PROJECT_VERSION);
176+ model.asset .extras = tinygltf::Value (extras);
163177}
164178
165179std::size_t GLTFExporter::buildPrimitiveVertex (const Mesh& mesh, std::vector<Face> faces)
@@ -211,7 +225,11 @@ std::size_t GLTFExporter::buildPrimitiveColor(std::vector<Face> faces)
211225 data.push_back (face.color3 );
212226 }
213227
214- return buildAccessor (data, TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE, TINYGLTF_TYPE_VEC3, TINYGLTF_TARGET_ARRAY_BUFFER, true );
228+ return buildAccessor (data,
229+ TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE,
230+ TINYGLTF_TYPE_VEC3,
231+ TINYGLTF_TARGET_ARRAY_BUFFER,
232+ true );
215233}
216234
217235std::size_t GLTFExporter::buildPrimitiveTexcoord (std::vector<Face> faces)
@@ -230,8 +248,7 @@ std::size_t GLTFExporter::buildPrimitiveTexcoord(std::vector<Face> faces)
230248}
231249
232250template <typename T>
233- std::size_t
234- GLTFExporter::buildAccessor (std::vector<T> data, int componentType, int type, int target, bool normalized)
251+ std::size_t GLTFExporter::buildAccessor (std::vector<T> data, int componentType, int type, int target, bool normalized)
235252{
236253 tinygltf::Buffer buffer;
237254 T min = data[0 ];
@@ -250,8 +267,7 @@ GLTFExporter::buildAccessor(std::vector<T> data, int componentType, int type, in
250267 tinygltf::BufferView view;
251268 view.buffer = bufferId;
252269 view.byteLength = buffer.data .size ();
253- if (target == TINYGLTF_TARGET_ARRAY_BUFFER)
254- view.byteStride = sizeof (T);
270+ if (target == TINYGLTF_TARGET_ARRAY_BUFFER) view.byteStride = sizeof (T);
255271 view.byteOffset = 0 ;
256272 view.target = target;
257273
@@ -570,12 +586,15 @@ void GLTFExporter::buildTexture()
570586 push (model.textures , tex);
571587}
572588
573- GLTFExporter::GLTFExporter (const Model& mmd, const AbstractTIM& tim, std::optional<TIMPalette> forcedPalette)
589+ GLTFExporter::GLTFExporter (const Model& mmd,
590+ const AbstractTIM& tim,
591+ ModelType type,
592+ std::optional<TIMPalette> forcedPalette)
574593 : mmd(mmd)
575594 , tim(tim)
576595 , forcedPalette(forcedPalette)
577596{
578- buildAssetEntry ();
597+ buildAssetEntry (type );
579598 buildMeshEntries ();
580599 buildAnimations ();
581600 buildTexture ();
0 commit comments