Make mjs_findElement find textures by file name.

This is done if the model is uncompiled and their name is empty.

PiperOrigin-RevId: 772885774
Change-Id: I827d5b679637fa0571cfb0a69833ed688df16304
This commit is contained in:
Alessio Quaglino
2025-06-18 05:53:16 -07:00
committed by Copybara-Service
parent 9e2c21a17d
commit 92bc486558
4 changed files with 29 additions and 0 deletions
+18
View File
@@ -24,6 +24,7 @@
#include <cstdlib>
#include <cstring>
#include <exception>
#include <filesystem> // NOLINT(build/c++17)
#include <functional>
#include <mutex>
#include <string>
@@ -1369,6 +1370,23 @@ static T* findobject(std::string_view name, const vector<T*>& list, const mjKeyM
return list[id->second];
}
mjCBase* mjCModel::FindTexture(std::string_view name) const {
for (unsigned int i=0; i < textures_.size(); i++) {
if (textures_[i]->name == name) {
return textures_[i];
}
if (textures_[i]->name.empty() &&
std::filesystem::path(textures_[i]->spec_file_).filename().stem() == name) {
return textures_[i];
}
}
return nullptr;
}
// find object in global lists given string type and name
mjCBase* mjCModel::FindObject(mjtObj type, string name) const {
if (!object_lists_[type]) {