Recast: fix trailing extension delimiter on model names when loading .gset files

The code assumed an extension of 3 characters, but .gset is 4 and is also supported, causing a trailing '.' as it only truncates the training 4 characters (including the null char). The code now searches for the extension delimiter and gets the actual model name regardless of the length of presence of an extension.
This commit is contained in:
Kawe Mazidjatari 2024-06-30 21:57:26 +02:00
parent 6a57cea9ef
commit 7ba2d2caf5

View File

@ -119,6 +119,15 @@ void generate_points(float* pts, int count, float dx, float dy, float dz)
}
}
void get_model_name(const std::string& nameIn, std::string& nameOut)
{
const size_t charPos = nameIn.find_last_of(".");
nameOut = charPos == string::npos
? nameIn
: nameIn.substr(0, charPos);
}
void auto_load(const char* path, BuildContext& ctx, Editor*& editor,InputGeom*& geom, string& meshName)
{
string geom_path = std::string(path);
@ -140,7 +149,7 @@ void auto_load(const char* path, BuildContext& ctx, Editor*& editor,InputGeom*&
if (editor && geom)
{
editor->handleMeshChanged(geom);
editor->m_modelName = meshName.substr(0, meshName.size() - 4);
get_model_name(meshName, editor->m_modelName);
}
}
@ -985,7 +994,7 @@ int not_main(int argc, char** argv)
if (editor && geom)
{
editor->handleMeshChanged(geom);
editor->m_modelName = meshName.substr(0, meshName.size() - 4);
get_model_name(meshName, editor->m_modelName);
}
if (geom || editor)
@ -1059,7 +1068,7 @@ int not_main(int argc, char** argv)
if (editor && geom)
{
editor->handleMeshChanged(geom);
editor->m_modelName = meshName.substr(0, meshName.size() - 4);
get_model_name(meshName, editor->m_modelName);
}
// This will ensure that tile & poly bits are updated in tiled editor.