Allow studio to search for models in predetermined search paths.

A future CL will allow users to specify search paths in their settings.

PiperOrigin-RevId: 846240293
Change-Id: I1a1a4027d0fc85004a12fe01a406f50fd929f3e4
This commit is contained in:
Haroon Qureshi
2025-12-18 06:31:34 -08:00
committed by Copybara-Service
parent 7190bd4912
commit bebdd62943
4 changed files with 55 additions and 4 deletions
+6 -4
View File
@@ -201,10 +201,12 @@ void App::LoadModel(std::string data, ContentType type) {
// Store the file path as the model name. Note that we use this model name
// to perform reload operations.
model_name_ = std::move(data);
if (model_name_.ends_with(".mjb")) {
model_ = mj_loadModel(model_name_.c_str(), 0);
} else if (model_name_.ends_with(".xml")) {
spec_ = mj_parseXML(model_name_.c_str(), nullptr, err, sizeof(err));
const std::string resolved_file =
platform::ResolveFile(model_name_, search_paths_);
if (resolved_file.ends_with(".mjb")) {
model_ = mj_loadModel(resolved_file.c_str(), 0);
} else if (resolved_file.ends_with(".xml")) {
spec_ = mj_parseXML(resolved_file.c_str(), nullptr, err, sizeof(err));
if (spec_ && err[0] == 0) {
model_ = mj_compile(spec_, nullptr);
}
+2
View File
@@ -185,6 +185,8 @@ class App {
platform::SimProfiler profiler_;
platform::SimHistory history_;
std::vector<std::string> search_paths_;
mjSpec* spec_ = nullptr;
mjModel* model_ = nullptr;
mjData* data_ = nullptr;