Skip to content

Commit 07feb8d

Browse files
committed
Add extra field to hold model type
Useful to tell importers how to deal with the model
1 parent c251536 commit 07feb8d

3 files changed

Lines changed: 36 additions & 12 deletions

File tree

src/GLTF.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
#include "GLTF.hpp"
77

8+
#include <algorithm>
89
#include <format>
910
#include <iostream>
1011
#include <numbers>
11-
#include <algorithm>
1212

1313
bool 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

165179
std::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

217235
std::size_t GLTFExporter::buildPrimitiveTexcoord(std::vector<Face> faces)
@@ -230,8 +248,7 @@ std::size_t GLTFExporter::buildPrimitiveTexcoord(std::vector<Face> faces)
230248
}
231249

232250
template<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();

src/GLTF.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class MaterialMode
4545
}
4646
};
4747

48+
enum class ModelType {
49+
DIGIMON,
50+
DOOR,
51+
};
52+
4853
class GLTFExporter
4954
{
5055
private:
@@ -56,7 +61,7 @@ class GLTFExporter
5661
std::optional<TIMPalette> forcedPalette;
5762

5863
private:
59-
void buildAssetEntry();
64+
void buildAssetEntry(ModelType type);
6065
void buildMeshEntries();
6166
void buildStaticScene();
6267
void buildSkeletonScene();
@@ -73,7 +78,7 @@ class GLTFExporter
7378
std::size_t buildPrimitiveTexcoord(std::vector<Face> faces);
7479

7580
public:
76-
GLTFExporter(const Model& model, const AbstractTIM& tim, std::optional<TIMPalette> forcedPalette = {});
81+
GLTFExporter(const Model& model, const AbstractTIM& tim, ModelType type = ModelType::DIGIMON, std::optional<TIMPalette> forcedPalette = {});
7782

7883
bool save(const std::filesystem::path& filename);
7984
};

src/MAP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ bool MAPExporter::save(std::filesystem::path outputDir)
468468
auto pal = clutMapping[model.getClutY()];
469469
pal = TIMPalette(pal.begin() + model.getClutX(), pal.end());
470470

471-
GLTFExporter exporter(model, **image, pal);
471+
GLTFExporter exporter(model, **image, ModelType::DOOR, pal);
472472
exporter.save(outputDir / std::format("door_{}.gltf", id));
473473
}
474474

0 commit comments

Comments
 (0)