Replace mjCModel with mjmModel in mjXBase.

PiperOrigin-RevId: 611762880
Change-Id: I22254689b6cbf10fe7b61f9742b6ffd6c2074477
This commit is contained in:
Alessio Quaglino
2024-03-01 03:37:37 -08:00
committed by Copybara-Service
parent 419be4c605
commit 1bd44e73bb
18 changed files with 213 additions and 111 deletions
+61 -6
View File
@@ -28,12 +28,44 @@
// create model
mjmModel* mjm_createModel() {
mjCModel* modelC = new mjCModel();
mjCModel* modelC = new mjCModel;
return &modelC->spec;
}
// copy back model
void mjm_copyBack(mjmModel* model, const mjModel* m) {
mjCModel* modelC = reinterpret_cast<mjCModel*>(model->element);
modelC->CopyBack(m);
}
// compile model
mjModel* mjm_compileModel(mjmModel* model, const mjVFS* vfs) {
mjCModel* modelC = reinterpret_cast<mjCModel*>(model->element);
return modelC->Compile(vfs);
}
// get error message from model
const char* mjm_getError(mjmModel* model) {
mjCModel* modelC = reinterpret_cast<mjCModel*>(model->element);
return modelC->GetError().message;
}
// check if model has warnings
int mjm_isWarning(mjmModel* model) {
mjCModel* modelC = reinterpret_cast<mjCModel*>(model->element);
return modelC->GetError().warning;
}
// delete model
void mjm_deleteModel(mjmModel* modelspec) {
mjCModel* model = reinterpret_cast<mjCModel*>(modelspec->element);
@@ -320,8 +352,9 @@ mjmPlugin* mjm_addPlugin(mjmModel* model) {
// add default to model
mjmDefault* mjm_addDefault(mjmModel* model, const char* classname, int parentid) {
mjmDefault* mjm_addDefault(mjmModel* model, const char* classname, int parentid, int* id) {
mjCModel* modelC = reinterpret_cast<mjCModel*>(model->element);
*id = (int)modelC->defaults.size();
mjCDef* def = modelC->AddDef(classname, parentid);
if (def) {
return &def->spec;
@@ -346,10 +379,10 @@ mjmDefault* mjm_getDefault(mjElement element) {
// find default in model by class name
mjmDefault* mjm_findDefault(mjmModel* modelspec, const char* classname) {
mjCModel* model = reinterpret_cast<mjCModel*>(modelspec->element);
mjCDef* cdef = model->FindDef(classname);
// Find default with given name in model.
mjmDefault* mjm_findDefault(mjmModel* model, const char* classname) {
mjCModel* modelC = reinterpret_cast<mjCModel*>(model->element);
mjCDef* cdef = modelC->FindDef(classname);
if (!cdef) {
return nullptr;
}
@@ -358,6 +391,18 @@ mjmDefault* mjm_findDefault(mjmModel* modelspec, const char* classname) {
// get default[0] from model
mjmDefault* mjm_getModelDefault(mjmModel* model) {
mjCModel* modelC = reinterpret_cast<mjCModel*>(model->element);
mjCDef* def = modelC->defaults[0];
if (!def) {
return nullptr;
}
return &def->spec;
}
// find body in model by name
mjmBody* mjm_findBody(mjmModel* modelspec, const char* name) {
mjCModel* model = reinterpret_cast<mjCModel*>(modelspec->element);
@@ -539,6 +584,16 @@ void mjm_setPluginAttributes(mjmPlugin* plugin, void* attributes) {
// Set active plugins.
void mjm_setActivePlugins(mjmModel* model, void* activeplugins) {
mjCModel* modelC = reinterpret_cast<mjCModel*>(model->element);
std::vector<std::pair<const mjpPlugin*, int>>* active_plugins =
reinterpret_cast<std::vector<std::pair<const mjpPlugin*, int>>*>(activeplugins);
modelC->active_plugins = std::move(*active_plugins);
}
// compute full inertia
const char* mjm_setFullInertia(mjmBody* bodyspec, double quat[4], double inertia[3]) {
mjCBody* body = reinterpret_cast<mjCBody*>(bodyspec->element);
+19 -1
View File
@@ -729,6 +729,18 @@ typedef struct _mjmDefault { // default specification
// Create model.
MJAPI mjmModel* mjm_createModel();
// Copy back model.
MJAPI void mjm_copyBack(mjmModel* model, const mjModel* m);
// Compile model.
MJAPI mjModel* mjm_compileModel(mjmModel* model, const mjVFS* vfs);
// Get error message from model.
MJAPI const char* mjm_getError(mjmModel* model);
// Return 1 if model has warnings.
MJAPI int mjm_isWarning(mjmModel* model);
// Delete model.
MJAPI void mjm_deleteModel(mjmModel* modelspec);
@@ -820,7 +832,7 @@ MJAPI mjmKey* mjm_addKey(mjmModel* model);
MJAPI mjmPlugin* mjm_addPlugin(mjmModel* model);
// Add default to model.
MJAPI mjmDefault* mjm_addDefault(mjmModel* model, const char* classname, int parentid);
MJAPI mjmDefault* mjm_addDefault(mjmModel* model, const char* classname, int parentid, int* id);
// Get model from body.
MJAPI mjmModel* mjm_getModel(mjmBody* body);
@@ -831,6 +843,9 @@ MJAPI mjmDefault* mjm_getDefault(mjElement element);
// Find default in model by class name.
MJAPI mjmDefault* mjm_findDefault(mjmModel* model, const char* classname);
// Get global default from model.
MJAPI mjmDefault* mjm_getModelDefault(mjmModel* model);
// Find body in model by name.
MJAPI mjmBody* mjm_findBody(mjmModel* model, const char* name);
@@ -879,6 +894,9 @@ MJAPI const double* mjm_getDouble(mjDoubleVec source, int* size);
// Set plugin attributes.
MJAPI void mjm_setPluginAttributes(mjmPlugin* plugin, void* attributes);
// Set active plugins.
MJAPI void mjm_setActivePlugins(mjmModel* model, void* activeplugins);
// Set default.
MJAPI void mjm_setDefault(mjElement element, mjmDefault* def);
+3 -1
View File
@@ -223,7 +223,9 @@ void mjCComposite::SetDefault(void) {
// make composite object
bool mjCComposite::Make(mjCModel* model, mjmBody* body, char* error, int error_sz) {
bool mjCComposite::Make(mjmModel* modelspec, mjmBody* body, char* error, int error_sz) {
mjCModel* model = (mjCModel*)modelspec->element;
// check geom type
if ((def[0].spec.geom->type!=mjGEOM_SPHERE &&
def[0].spec.geom->type!=mjGEOM_CAPSULE &&
+1 -1
View File
@@ -69,7 +69,7 @@ class mjCComposite {
bool AddDefaultJoint(char* error = NULL, int error_sz = 0);
void AdjustSoft(mjtNum* solref, mjtNum* solimp, int level);
bool Make(mjCModel* model, mjmBody* body, char* error, int error_sz);
bool Make(mjmModel* modelspec, mjmBody* body, char* error, int error_sz);
bool MakeParticle(mjCModel* model, mjmBody* body, char* error, int error_sz);
bool MakeGrid(mjCModel* model, mjmBody* body, char* error, int error_sz);
+2 -1
View File
@@ -82,7 +82,8 @@ mjCFlexcomp::mjCFlexcomp(void) {
// make flexcomp object
bool mjCFlexcomp::Make(mjCModel* model, mjmBody* body, char* error, int error_sz) {
bool mjCFlexcomp::Make(mjmModel* modelspec, mjmBody* body, char* error, int error_sz) {
mjCModel* model = (mjCModel*)modelspec->element;
mjmFlex* dflex = def.spec.flex;
int dim = dflex->dim;
bool radial = (type==mjFCOMPTYPE_BOX ||
+1 -1
View File
@@ -42,7 +42,7 @@ typedef enum _mjtFcompType {
class mjCFlexcomp {
public:
mjCFlexcomp(void);
bool Make(mjCModel* model, mjmBody* body, char* error, int error_sz);
bool Make(mjmModel* modelspec, mjmBody* body, char* error, int error_sz);
bool MakeGrid(char* error, int error_sz);
bool MakeBox(char* error, int error_sz);
+9 -2
View File
@@ -175,6 +175,13 @@ mjCModel::mjCModel() {
mjCModel::mjCModel(const mjCModel& other) {
*this = other;
PointToLocal();
}
void mjCModel::PointToLocal() {
spec.element = (mjElement)this;
spec.comment = (mjString)&spec_comment_;
@@ -504,8 +511,8 @@ int mjCModel::GetFixed(void) {
// copy of error object
mjCError mjCModel::GetError(void) {
// get reference of error object
const mjCError& mjCModel::GetError(void) {
return errInfo;
}
+2 -1
View File
@@ -61,6 +61,7 @@ class mjCModel : private mjmModel {
public:
mjCModel();
mjCModel(const mjCModel& other);
~mjCModel();
void CopyFromSpec(); // copy spec to private attributes
void PointToLocal();
@@ -105,7 +106,7 @@ class mjCModel : private mjmModel {
// API for access to other variables
bool IsCompiled(); // is model already compiled
int GetFixed(); // number of fixed massless bodies
mjCError GetError(); // copy of error object
const mjCError& GetError(void); // get reference of error object
mjCBody* GetWorld(); // pointer to world body
mjCDef* FindDef(std::string name); // find default class name
mjCDef* AddDef(std::string name, int parentid); // add default class to array