23 using std::unique_ptr;
82 inline static int main(
int argc,
char** argv) {
85 for (
auto i = 1; i < argc; i++) {
86 string argumentValue = argv[i];
87 if (argumentValue ==
"--no-texture-compression") {
94 return convertToTMApplication->run(argc, argv,
"Convert to tm Application",
nullptr, Application::WINDOW_HINT_INVISIBLE);
99 Console::println(
"Exporting models: Using BC7 texture compression: " +
string(
useBC7TextureCompression ==
true?
"true":
"false"));
102 auto scaleTo = 1024.0f;
105 auto outputFileName = StringTools::substring(inputFileName, 0, inputFileName.rfind(
'.')) +
".tm";
107 Console::println(
"Loading model: " + inputFileName);
108 auto model = unique_ptr<Model>(
110 FileSystem::getInstance()->getPathName(inputFileName),
111 FileSystem::getInstance()->getFileName(inputFileName),
115 for (
const auto& [materialId, material]: model->getMaterials()) {
116 auto specularMaterialProperties = material->getSpecularMaterialProperties();
118 if (specularMaterialProperties !=
nullptr) {
121 auto texture = specularMaterialProperties->getDiffuseTexture();
122 if (texture !=
nullptr) {
123 auto widthScale = scaleTo / texture->getTextureWidth();
124 auto heightScale = scaleTo / texture->getTextureHeight();
125 auto scale = Math::min(widthScale, heightScale);
127 auto scaledTexture = TextureReader::scale(texture, texture->getTextureWidth() * scale, texture->getTextureHeight() * scale,
string());
128 specularMaterialProperties->setDiffuseTexture(scaledTexture);
129 scaledTexture->releaseReference();
135 auto texture = specularMaterialProperties->getSpecularTexture();
136 if (texture !=
nullptr) {
137 auto widthScale = scaleTo / texture->getTextureWidth();
138 auto heightScale = scaleTo / texture->getTextureHeight();
139 auto scale = Math::min(widthScale, heightScale);
141 auto scaledTexture = TextureReader::scale(texture, texture->getTextureWidth() * scale, texture->getTextureHeight() * scale,
string());
142 specularMaterialProperties->setSpecularTexture(scaledTexture);
143 scaledTexture->releaseReference();
149 auto texture = specularMaterialProperties->getNormalTexture();
150 if (texture !=
nullptr) {
151 auto widthScale = scaleTo / texture->getTextureWidth();
152 auto heightScale = scaleTo / texture->getTextureHeight();
153 auto scale = Math::min(widthScale, heightScale);
155 auto scaledTexture = TextureReader::scale(texture, texture->getTextureWidth() * scale, texture->getTextureHeight() * scale,
string());
156 specularMaterialProperties->setNormalTexture(scaledTexture);
157 scaledTexture->releaseReference();
163 auto pbrMaterialProperties = material->getPBRMaterialProperties();
165 if (pbrMaterialProperties !=
nullptr) {
168 auto texture = pbrMaterialProperties->getBaseColorTexture();
169 if (texture !=
nullptr) {
170 auto widthScale = scaleTo / texture->getTextureWidth();
171 auto heightScale = scaleTo / texture->getTextureHeight();
172 auto scale = Math::min(widthScale, heightScale);
174 auto scaledTexture = TextureReader::scale(texture, texture->getTextureWidth() * scale, texture->getTextureHeight() * scale,
string());
175 pbrMaterialProperties->setBaseColorTexture(scaledTexture);
176 scaledTexture->releaseReference();
182 auto texture = pbrMaterialProperties->getMetallicRoughnessTexture();
183 if (texture !=
nullptr) {
184 auto widthScale = scaleTo / texture->getTextureWidth();
185 auto heightScale = scaleTo / texture->getTextureHeight();
186 auto scale = Math::min(widthScale, heightScale);
188 auto scaledTexture = TextureReader::scale(texture, texture->getTextureWidth() * scale, texture->getTextureHeight() * scale,
string());
189 pbrMaterialProperties->setMetallicRoughnessTexture(scaledTexture);
190 scaledTexture->releaseReference();
196 auto texture = pbrMaterialProperties->getNormalTexture();
197 if (texture !=
nullptr) {
198 auto widthScale = scaleTo / texture->getTextureWidth();
199 auto heightScale = scaleTo / texture->getTextureHeight();
200 auto scale = Math::min(widthScale, heightScale);
202 auto scaledTexture = TextureReader::scale(texture, texture->getTextureWidth() * scale, texture->getTextureHeight() * scale,
string());
203 pbrMaterialProperties->setNormalTexture(scaledTexture);
204 scaledTexture->releaseReference();
211 Console::println(
"Exporting model: " + outputFileName);
214 FileSystem::getInstance()->getPathName(outputFileName),
215 FileSystem::getInstance()->getFileName(outputFileName),
219 Console::println(
"An error occurred: " +
string(exception.what()));
223 Console::println(
"An error occurred: " +
string(exception.what()));
225 Application::exit(0);
229 Engine::getInstance()->dispose();
233 Engine::getInstance()->initialize();
236 void reshape(int32_t width, int32_t height)
override {
237 Engine::getInstance()->reshape(width, height);
245 int main(
int argc,
char** argv)
247 Console::println(
string(
"converttotm ") + Version::getVersion());
248 Console::println(Version::getCopyright());
251 Console::println(
"Usage: converttotm [--no-texture-compression] inputfile1 [inputfileN]");
252 Application::exit(Application::EXITCODE_FAILURE);
Application base class, please make sure to allocate application on heap to have correct application ...
Representation of a 3D model.
Represents specular material properties.
Represents specular material properties.
File system singleton class.
int main(int argc, char **argv)
std::exception Exception
Exception base class.
#define FORBID_CLASS_COPY(CLASS)