Make mjs_findElement find meshes by file name.

PiperOrigin-RevId: 780150428
Change-Id: Ie500062fa8cca755683b66540e84ede588d7c331
This commit is contained in:
Alessio Quaglino
2025-07-07 09:50:49 -07:00
committed by Copybara-Service
parent 7a09145161
commit 1a4ddca6cf
4 changed files with 26 additions and 10 deletions
+13 -7
View File
@@ -1338,19 +1338,25 @@ static T* findobject(std::string_view name, const vector<T*>& list, const mjKeyM
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];
template <class T>
mjCBase* mjCModel::FindAsset(std::string_view name, const std::vector<T*>& list) const {
for (unsigned int i=0; i < list.size(); i++) {
if (list[i]->name == name) {
return list[i];
}
if (textures_[i]->name.empty() &&
std::filesystem::path(textures_[i]->spec_file_).filename().stem() == name) {
return textures_[i];
if (list[i]->name.empty() &&
std::filesystem::path(list[i]->spec_file_).filename().stem() == name) {
return list[i];
}
}
return nullptr;
}
template mjCBase* mjCModel::FindAsset<mjCTexture>(
std::string_view name, const std::vector<mjCTexture*>& list) const;
template mjCBase* mjCModel::FindAsset<mjCMesh>(
std::string_view name, const std::vector<mjCMesh*>& list) const;
// find object in global lists given string type and name