Simplify mjs_addDefault.

PiperOrigin-RevId: 646534046
Change-Id: I658224e4800849231e68ed02d8fad07b8d796231
This commit is contained in:
Alessio Quaglino
2024-06-25 10:50:55 -07:00
committed by Copybara-Service
parent 5e39fc0564
commit 6be4e0697e
11 changed files with 32 additions and 32 deletions
+4 -3
View File
@@ -437,10 +437,11 @@ mjsPlugin* mjs_addPlugin(mjSpec* s) {
// add default to model
mjsDefault* mjs_addDefault(mjSpec* s, const char* classname, int parentid, int* id) {
mjsDefault* mjs_addDefault(mjSpec* s, const char* classname, const mjsDefault* parent) {
mjCModel* modelC = static_cast<mjCModel*>(s->element);
*id = (int)modelC->NumDefaults();
mjCDef* def = modelC->AddDefault(classname, parentid);
mjCDef* parentC = parent ? static_cast<mjCDef*>(parent->element) :
static_cast<mjCModel*>(s->element)->Defaults(0);
mjCDef* def = modelC->AddDefault(classname, parentC);
if (def) {
return &def->spec;
} else {
+1 -1
View File
@@ -156,7 +156,7 @@ MJAPI mjsKey* mjs_addKey(mjSpec* s);
MJAPI mjsPlugin* mjs_addPlugin(mjSpec* s);
// Add default.
MJAPI mjsDefault* mjs_addDefault(mjSpec* s, const char* classname, int parentid, int* id);
MJAPI mjsDefault* mjs_addDefault(mjSpec* s, const char* classname, const mjsDefault* parent);
//---------------------------------- Add assets ----------------------------------------------------
+4 -1
View File
@@ -741,7 +741,9 @@ mjCDef* mjCModel::FindDefault(string name) {
// add default class to array
mjCDef* mjCModel::AddDefault(string name, int parentid) {
mjCDef* mjCModel::AddDefault(string name, mjCDef* parent) {
int parentid = parent ? parent->id : 0;
// check for repeated name
int thisid = (int)defaults_.size();
for (int i=0; i<thisid; i++) {
@@ -753,6 +755,7 @@ mjCDef* mjCModel::AddDefault(string name, int parentid) {
// create new object
mjCDef* def = new mjCDef;
defaults_.push_back(def);
def->id = thisid;
// initialize contents
if (parentid>=0 && parentid<thisid) {
+9 -9
View File
@@ -205,15 +205,15 @@ class mjCModel : public mjCModel_, private mjSpec {
mjCBase* GetObject(mjtObj type, int id); // pointer to specified object
// API for access to other variables
bool IsCompiled() const; // is model already compiled
const mjCError& GetError() const; // get reference of error object
mjCBody* GetWorld(); // pointer to world body
mjCDef* FindDefault(std::string name); // find defaults class name
mjCDef* AddDefault(std::string name, int parentid); // add defaults class to array
mjCBase* FindObject(mjtObj type, std::string name) const; // find object given type and name
mjCBody* FindBody(mjCBody* body, std::string name); // find body given name
mjCFrame* FindFrame(mjCBody* body, std::string name) const; // find frame given name
bool IsNullPose(const mjtNum* pos, const mjtNum* quat) const; // detect null pose
bool IsCompiled() const; // is model already compiled
const mjCError& GetError() const; // get reference of error object
mjCBody* GetWorld(); // pointer to world body
mjCDef* FindDefault(std::string name); // find defaults class name
mjCDef* AddDefault(std::string name, mjCDef* parent = nullptr); // add defaults class to array
mjCBase* FindObject(mjtObj type, std::string name) const; // find object given type and name
mjCBody* FindBody(mjCBody* body, std::string name); // find body given name
mjCFrame* FindFrame(mjCBody* body, std::string name) const; // find frame given name
bool IsNullPose(const mjtNum* pos, const mjtNum* quat) const; // detect null pose
void SetActivePlugins(const std::vector<std::pair<const mjpPlugin*, int>>&& active_plugins) {
active_plugins_ = std::move(active_plugins);
}
+1
View File
@@ -517,6 +517,7 @@ int mjCBoundingVolumeHierarchy::MakeBVH(
// constructor
mjCDef::mjCDef() {
name.clear();
id = 0;
parentid = -1;
childid.clear();
mjs_defaultJoint(&joint_.spec);
+1
View File
@@ -1651,6 +1651,7 @@ class mjCDef : public mjsElement {
// identifiers
std::string name; // class name
int id; // id of this default
int parentid; // id of parent class
std::vector<int> childid; // ids of child classes