Added functionality for user payload data in mjSpec.

PiperOrigin-RevId: 738343134
Change-Id: I6217362ced9993afcd5a2914c78718ffe3bf753a
This commit is contained in:
Alessio Quaglino
2025-03-19 04:35:12 -07:00
committed by Copybara-Service
parent dc50fbbb9b
commit 209d2bd2c5
9 changed files with 184 additions and 2 deletions
+13 -2
View File
@@ -23,11 +23,14 @@
#include <map>
#include <string>
#include <string_view>
#include <unordered_map>
#include <utility>
#include <vector>
#include <mujoco/mjmodel.h>
#include <mujoco/mjplugin.h>
#include <mujoco/mjspec.h>
#include <mujoco/mujoco.h>
#include <mujoco/mjtnum.h>
#include "user/user_cache.h"
#include "user/user_util.h"
#include <tiny_obj_loader.h>
@@ -274,12 +277,20 @@ class mjCBase : public mjCBase_ {
}
}
// Set and get user payload
void SetUserValue(std::string_view key, const void* data);
const void* GetUserValue(std::string_view key);
void DeleteUserValue(std::string_view key);
protected:
mjCBase(); // constructor
mjCBase(const mjCBase& other); // copy constructor
// reference count for allowing deleting an attached object
int refcount = 1;
// user payload
std::unordered_map<std::string, const void*> user_payload_;
};
@@ -781,7 +792,7 @@ class mjCLight : public mjCLight_, private mjsLight {
class mjCFlex_ : public mjCBase {
protected:
int nvert; // number of verices
int nvert; // number of vertices
int nnode; // number of nodes
int nedge; // number of edges
int nelem; // number of elements