Initial implementation of toolbox-based "Studio" app.
PiperOrigin-RevId: 809966748 Change-Id: Ic6333259ca1d112a2e42d47ccc44326bfcea3bdd
This commit is contained in:
committed by
Copybara-Service
parent
7fc6b29afd
commit
6eea3d8ec0
@@ -0,0 +1,66 @@
|
||||
// Copyright 2025 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Main entry point for the Filament-based MuJoCo renderer.
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "third_party/absl/flags/flag.h"
|
||||
#include "third_party/mujoco/google/runfiles/runfiles.h"
|
||||
#include "experimental/studio/app.h"
|
||||
|
||||
ABSL_FLAG(int, window_width, 1400, "Window width");
|
||||
ABSL_FLAG(int, window_height, 700, "Window height");
|
||||
ABSL_FLAG(std::string, model_file, "", "MuJoCo model file.");
|
||||
|
||||
constexpr char kDataPath[] = "third_party/mujoco/google/filament/assets/data/";
|
||||
|
||||
static std::vector<std::byte> LoadAsset(std::string_view path) {
|
||||
std::ifstream file(path, std::ios::binary | std::ios::ate);
|
||||
if (!file.is_open()) {
|
||||
return {};
|
||||
}
|
||||
std::streampos file_size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
std::vector<std::byte> buffer(file_size);
|
||||
if (!file.read(reinterpret_cast<char*>(buffer.data()), file_size)) {
|
||||
return {};
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv, char** envp) {
|
||||
|
||||
const int width = absl::GetFlag(FLAGS_window_width);
|
||||
const int height = absl::GetFlag(FLAGS_window_height);
|
||||
const std::string ini_path = file::JoinPath(getenv("HOME"), ".mujoco.ini");
|
||||
mujoco::studio::App app(width, height, ini_path, LoadAsset);
|
||||
|
||||
// If the model file is not specified, try to load it from the first argument
|
||||
std::string model_file = absl::GetFlag(FLAGS_model_file);
|
||||
if (model_file.empty() && argc > 1 && argv[1][0] != '-') model_file = argv[1];
|
||||
app.LoadModel(model_file);
|
||||
while (app.Update()) {
|
||||
app.Sync();
|
||||
app.BuildGui();
|
||||
app.Render();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user