Renamed Model to Spec in C API function names.
PiperOrigin-RevId: 613922860 Change-Id: Ic47a83aa33b57ef96bd742088442e6237282ee92
This commit is contained in:
committed by
Copybara-Service
parent
b97110967f
commit
655e3d0914
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// create model
|
// create model
|
||||||
mjSpec* mjm_createModel() {
|
mjSpec* mjm_createSpec() {
|
||||||
mjCModel* modelC = new mjCModel;
|
mjCModel* modelC = new mjCModel;
|
||||||
return &modelC->spec;
|
return &modelC->spec;
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ void mjm_copyBack(mjSpec* s, const mjModel* m) {
|
|||||||
|
|
||||||
|
|
||||||
// compile model
|
// compile model
|
||||||
mjModel* mjm_compileModel(mjSpec* s, const mjVFS* vfs) {
|
mjModel* mjm_compile(mjSpec* s, const mjVFS* vfs) {
|
||||||
mjCModel* modelC = reinterpret_cast<mjCModel*>(s->element);
|
mjCModel* modelC = reinterpret_cast<mjCModel*>(s->element);
|
||||||
return modelC->Compile(vfs);
|
return modelC->Compile(vfs);
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ int mjm_isWarning(mjSpec* s) {
|
|||||||
|
|
||||||
|
|
||||||
// delete model
|
// delete model
|
||||||
void mjm_deleteModel(mjSpec* s) {
|
void mjm_deleteSpec(mjSpec* s) {
|
||||||
mjCModel* model = reinterpret_cast<mjCModel*>(s->element);
|
mjCModel* model = reinterpret_cast<mjCModel*>(s->element);
|
||||||
delete model;
|
delete model;
|
||||||
}
|
}
|
||||||
@@ -392,7 +392,7 @@ mjmDefault* mjm_findDefault(mjSpec* s, const char* classname) {
|
|||||||
|
|
||||||
|
|
||||||
// get default[0] from model
|
// get default[0] from model
|
||||||
mjmDefault* mjm_getModelDefault(mjSpec* s) {
|
mjmDefault* mjm_getSpecDefault(mjSpec* s) {
|
||||||
mjCModel* modelC = reinterpret_cast<mjCModel*>(s->element);
|
mjCModel* modelC = reinterpret_cast<mjCModel*>(s->element);
|
||||||
mjCDef* def = modelC->defaults[0];
|
mjCDef* def = modelC->defaults[0];
|
||||||
if (!def) {
|
if (!def) {
|
||||||
|
|||||||
+6
-6
@@ -727,13 +727,13 @@ typedef struct _mjmDefault { // default specification
|
|||||||
//---------------------------------- API functions -------------------------------------------------
|
//---------------------------------- API functions -------------------------------------------------
|
||||||
|
|
||||||
// Create model.
|
// Create model.
|
||||||
MJAPI mjSpec* mjm_createModel();
|
MJAPI mjSpec* mjm_createSpec();
|
||||||
|
|
||||||
// Copy back model.
|
// Copy back model.
|
||||||
MJAPI void mjm_copyBack(mjSpec* s, const mjModel* m);
|
MJAPI void mjm_copyBack(mjSpec* s, const mjModel* m);
|
||||||
|
|
||||||
// Compile model.
|
// Compile model.
|
||||||
MJAPI mjModel* mjm_compileModel(mjSpec* s, const mjVFS* vfs);
|
MJAPI mjModel* mjm_compile(mjSpec* s, const mjVFS* vfs);
|
||||||
|
|
||||||
// Get error message from model.
|
// Get error message from model.
|
||||||
MJAPI const char* mjm_getError(mjSpec* s);
|
MJAPI const char* mjm_getError(mjSpec* s);
|
||||||
@@ -742,7 +742,7 @@ MJAPI const char* mjm_getError(mjSpec* s);
|
|||||||
MJAPI int mjm_isWarning(mjSpec* s);
|
MJAPI int mjm_isWarning(mjSpec* s);
|
||||||
|
|
||||||
// Delete model.
|
// Delete model.
|
||||||
MJAPI void mjm_deleteModel(mjSpec* s);
|
MJAPI void mjm_deleteSpec(mjSpec* s);
|
||||||
|
|
||||||
// Add child body to body, return child spec.
|
// Add child body to body, return child spec.
|
||||||
MJAPI mjmBody* mjm_addBody(mjmBody* body, mjmDefault* def);
|
MJAPI mjmBody* mjm_addBody(mjmBody* body, mjmDefault* def);
|
||||||
@@ -790,7 +790,7 @@ MJAPI mjmMaterial* mjm_addMaterial(mjSpec* s, mjmDefault* def);
|
|||||||
MJAPI mjmPair* mjm_addPair(mjSpec* s, mjmDefault* def);
|
MJAPI mjmPair* mjm_addPair(mjSpec* s, mjmDefault* def);
|
||||||
|
|
||||||
// Add excluded body pair to model.
|
// Add excluded body pair to model.
|
||||||
MJAPI mjmExclude* mjm_addExclude(mjSpec *model);
|
MJAPI mjmExclude* mjm_addExclude(mjSpec* s);
|
||||||
|
|
||||||
// Add equality to model.
|
// Add equality to model.
|
||||||
MJAPI mjmEquality* mjm_addEquality(mjSpec* s, mjmDefault* def);
|
MJAPI mjmEquality* mjm_addEquality(mjSpec* s, mjmDefault* def);
|
||||||
@@ -844,7 +844,7 @@ MJAPI mjmDefault* mjm_getDefault(mjElement element);
|
|||||||
MJAPI mjmDefault* mjm_findDefault(mjSpec* s, const char* classname);
|
MJAPI mjmDefault* mjm_findDefault(mjSpec* s, const char* classname);
|
||||||
|
|
||||||
// Get global default from model.
|
// Get global default from model.
|
||||||
MJAPI mjmDefault* mjm_getModelDefault(mjSpec* s);
|
MJAPI mjmDefault* mjm_getSpecDefault(mjSpec* s);
|
||||||
|
|
||||||
// Find body in model by name.
|
// Find body in model by name.
|
||||||
MJAPI mjmBody* mjm_findBody(mjSpec* s, const char* name);
|
MJAPI mjmBody* mjm_findBody(mjSpec* s, const char* name);
|
||||||
@@ -910,7 +910,7 @@ MJAPI const char* mjm_setFullInertia(mjmBody* body, double quat[4], double inert
|
|||||||
//---------------------------------- Initialization functions --------------------------------------
|
//---------------------------------- Initialization functions --------------------------------------
|
||||||
|
|
||||||
// Default model attributes.
|
// Default model attributes.
|
||||||
MJAPI void mjm_defaultModel(mjSpec& model);
|
MJAPI void mjm_defaultSpec(mjSpec& model);
|
||||||
|
|
||||||
// Default body attributes.
|
// Default body attributes.
|
||||||
MJAPI void mjm_defaultBody(mjmBody& body);
|
MJAPI void mjm_defaultBody(mjmBody& body);
|
||||||
|
|||||||
@@ -223,8 +223,8 @@ void mjCComposite::SetDefault(void) {
|
|||||||
|
|
||||||
|
|
||||||
// make composite object
|
// make composite object
|
||||||
bool mjCComposite::Make(mjSpec* modelspec, mjmBody* body, char* error, int error_sz) {
|
bool mjCComposite::Make(mjSpec* spec, mjmBody* body, char* error, int error_sz) {
|
||||||
mjCModel* model = (mjCModel*)modelspec->element;
|
mjCModel* model = (mjCModel*)spec->element;
|
||||||
|
|
||||||
// check geom type
|
// check geom type
|
||||||
if ((def[0].spec.geom->type!=mjGEOM_SPHERE &&
|
if ((def[0].spec.geom->type!=mjGEOM_SPHERE &&
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class mjCComposite {
|
|||||||
bool AddDefaultJoint(char* error = NULL, int error_sz = 0);
|
bool AddDefaultJoint(char* error = NULL, int error_sz = 0);
|
||||||
void AdjustSoft(mjtNum* solref, mjtNum* solimp, int level);
|
void AdjustSoft(mjtNum* solref, mjtNum* solimp, int level);
|
||||||
|
|
||||||
bool Make(mjSpec* modelspec, mjmBody* body, char* error, int error_sz);
|
bool Make(mjSpec* spec, mjmBody* body, char* error, int error_sz);
|
||||||
|
|
||||||
bool MakeParticle(mjCModel* model, 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);
|
bool MakeGrid(mjCModel* model, mjmBody* body, char* error, int error_sz);
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ mjCFlexcomp::mjCFlexcomp(void) {
|
|||||||
|
|
||||||
|
|
||||||
// make flexcomp object
|
// make flexcomp object
|
||||||
bool mjCFlexcomp::Make(mjSpec* modelspec, mjmBody* body, char* error, int error_sz) {
|
bool mjCFlexcomp::Make(mjSpec* spec, mjmBody* body, char* error, int error_sz) {
|
||||||
mjCModel* model = (mjCModel*)modelspec->element;
|
mjCModel* model = (mjCModel*)spec->element;
|
||||||
mjmFlex* dflex = def.spec.flex;
|
mjmFlex* dflex = def.spec.flex;
|
||||||
int dim = dflex->dim;
|
int dim = dflex->dim;
|
||||||
bool radial = (type==mjFCOMPTYPE_BOX ||
|
bool radial = (type==mjFCOMPTYPE_BOX ||
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ typedef enum _mjtFcompType {
|
|||||||
class mjCFlexcomp {
|
class mjCFlexcomp {
|
||||||
public:
|
public:
|
||||||
mjCFlexcomp(void);
|
mjCFlexcomp(void);
|
||||||
bool Make(mjSpec* modelspec, mjmBody* body, char* error, int error_sz);
|
bool Make(mjSpec* spec, mjmBody* body, char* error, int error_sz);
|
||||||
|
|
||||||
bool MakeGrid(char* error, int error_sz);
|
bool MakeGrid(char* error, int error_sz);
|
||||||
bool MakeBox(char* error, int error_sz);
|
bool MakeBox(char* error, int error_sz);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// default model attributes
|
// default model attributes
|
||||||
void mjm_defaultModel(mjSpec& model) {
|
void mjm_defaultSpec(mjSpec& model) {
|
||||||
memset(&model, 0, sizeof(mjSpec));
|
memset(&model, 0, sizeof(mjSpec));
|
||||||
|
|
||||||
// default statistics
|
// default statistics
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ static void copyvec(T1* dest, T2* src, int n) {
|
|||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
mjCModel::mjCModel() {
|
mjCModel::mjCModel() {
|
||||||
mjm_defaultModel(spec);
|
mjm_defaultSpec(spec);
|
||||||
spec_comment_.clear();
|
spec_comment_.clear();
|
||||||
spec_modelfiledir_.clear();
|
spec_modelfiledir_.clear();
|
||||||
spec_meshdir_.clear();
|
spec_meshdir_.clear();
|
||||||
|
|||||||
+2
-2
@@ -344,7 +344,7 @@ mjSpec* mjParseXML(const char* filename, const mjVFS* vfs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create model, set filedir
|
// create model, set filedir
|
||||||
model = mjm_createModel();
|
model = mjm_createSpec();
|
||||||
const char* dir;
|
const char* dir;
|
||||||
int ndir = 0;
|
int ndir = 0;
|
||||||
mju_getResourceDir(resource, &dir, &ndir);
|
mju_getResourceDir(resource, &dir, &ndir);
|
||||||
@@ -393,7 +393,7 @@ mjSpec* mjParseXML(const char* filename, const mjVFS* vfs,
|
|||||||
// catch known errors
|
// catch known errors
|
||||||
catch (mjXError err) {
|
catch (mjXError err) {
|
||||||
mjCopyError(error, err.message, error_sz);
|
mjCopyError(error, err.message, error_sz);
|
||||||
mjm_deleteModel(model);
|
mjm_deleteSpec(model);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -67,7 +67,7 @@ std::optional<std::string> GlobalModel::ToXML(const mjModel* m, char* error,
|
|||||||
void GlobalModel::Set(mjSpec* model) {
|
void GlobalModel::Set(mjSpec* model) {
|
||||||
std::lock_guard<std::mutex> lock(*mutex_);
|
std::lock_guard<std::mutex> lock(*mutex_);
|
||||||
if (model_ != nullptr) {
|
if (model_ != nullptr) {
|
||||||
mjm_deleteModel(model_);
|
mjm_deleteSpec(model_);
|
||||||
}
|
}
|
||||||
model_ = model;
|
model_ = model;
|
||||||
}
|
}
|
||||||
@@ -93,13 +93,13 @@ mjModel* mj_loadXML(const char* filename, const mjVFS* vfs,
|
|||||||
// parse new model
|
// parse new model
|
||||||
std::unique_ptr<mjSpec, std::function<void(mjSpec*)>> model(
|
std::unique_ptr<mjSpec, std::function<void(mjSpec*)>> model(
|
||||||
mjParseXML(filename, vfs, error, error_sz),
|
mjParseXML(filename, vfs, error, error_sz),
|
||||||
[](mjSpec* m) { mjm_deleteModel(m); });
|
[](mjSpec* m) { mjm_deleteSpec(m); });
|
||||||
if (!model) {
|
if (!model) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compile new model
|
// compile new model
|
||||||
mjModel* m = mjm_compileModel(model.get(), vfs);
|
mjModel* m = mjm_compile(model.get(), vfs);
|
||||||
if (!m) {
|
if (!m) {
|
||||||
mjCopyError(error, mjm_getError(model.get()), error_sz);
|
mjCopyError(error, mjm_getError(model.get()), error_sz);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -2643,7 +2643,7 @@ void mjXReader::Default(XMLElement* section, int parentid) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
thisid = 0;
|
thisid = 0;
|
||||||
def = mjm_getModelDefault(model);
|
def = mjm_getSpecDefault(model);
|
||||||
mjm_setString(def->name, text.c_str());
|
mjm_setString(def->name, text.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3046,7 +3046,7 @@ void mjXReader::Asset(XMLElement* section) {
|
|||||||
// get class if specified, otherwise use default0
|
// get class if specified, otherwise use default0
|
||||||
mjmDefault* def = GetClass(elem);
|
mjmDefault* def = GetClass(elem);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = mjm_getModelDefault(model);
|
def = mjm_getSpecDefault(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
// texture sub-element
|
// texture sub-element
|
||||||
@@ -3418,7 +3418,7 @@ void mjXReader::Contact(XMLElement* section) {
|
|||||||
// get class if specified, otherwise use default0
|
// get class if specified, otherwise use default0
|
||||||
mjmDefault* def = GetClass(elem);
|
mjmDefault* def = GetClass(elem);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = mjm_getModelDefault(model);
|
def = mjm_getSpecDefault(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
// geom pair to include
|
// geom pair to include
|
||||||
@@ -3463,7 +3463,7 @@ void mjXReader::Equality(XMLElement* section) {
|
|||||||
// get class if specified, otherwise use default0
|
// get class if specified, otherwise use default0
|
||||||
mjmDefault* def = GetClass(elem);
|
mjmDefault* def = GetClass(elem);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = mjm_getModelDefault(model);
|
def = mjm_getSpecDefault(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create equality constraint and parse
|
// create equality constraint and parse
|
||||||
@@ -3491,7 +3491,7 @@ void mjXReader::Deformable(XMLElement* section) {
|
|||||||
// get class if specified, otherwise use default0
|
// get class if specified, otherwise use default0
|
||||||
mjmDefault* def = GetClass(elem);
|
mjmDefault* def = GetClass(elem);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = mjm_getModelDefault(model);
|
def = mjm_getSpecDefault(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
// flex sub-element
|
// flex sub-element
|
||||||
@@ -3527,7 +3527,7 @@ void mjXReader::Tendon(XMLElement* section) {
|
|||||||
// get class if specified, otherwise use default0
|
// get class if specified, otherwise use default0
|
||||||
mjmDefault* def = GetClass(elem);
|
mjmDefault* def = GetClass(elem);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = mjm_getModelDefault(model);
|
def = mjm_getSpecDefault(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create equality constraint and parse
|
// create equality constraint and parse
|
||||||
@@ -3593,7 +3593,7 @@ void mjXReader::Actuator(XMLElement* section) {
|
|||||||
// get class if specified, otherwise use default0
|
// get class if specified, otherwise use default0
|
||||||
mjmDefault* def = GetClass(elem);
|
mjmDefault* def = GetClass(elem);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = mjm_getModelDefault(model);
|
def = mjm_getSpecDefault(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create actuator and parse
|
// create actuator and parse
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ using ::testing::NotNull;
|
|||||||
// ----------------------------- test set/get --------------------------------
|
// ----------------------------- test set/get --------------------------------
|
||||||
|
|
||||||
TEST_F(MujocoTest, ReadWriteData) {
|
TEST_F(MujocoTest, ReadWriteData) {
|
||||||
mjSpec* model = mjm_createModel();
|
mjSpec* spec = mjm_createSpec();
|
||||||
mjmBody* world = mjm_findBody(model, "world");
|
mjmBody* world = mjm_findBody(spec, "world");
|
||||||
mjmBody* body = mjm_addBody(world, 0);
|
mjmBody* body = mjm_addBody(world, 0);
|
||||||
mjmSite* site = mjm_addSite(body, 0);
|
mjmSite* site = mjm_addSite(body, 0);
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ TEST_F(MujocoTest, ReadWriteData) {
|
|||||||
EXPECT_EQ(vec[i], i);
|
EXPECT_EQ(vec[i], i);
|
||||||
}
|
}
|
||||||
|
|
||||||
mjm_deleteModel(model);
|
mjm_deleteSpec(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------- test recompilation multiple files ----------------------
|
// ------------------- test recompilation multiple files ----------------------
|
||||||
@@ -86,12 +86,12 @@ TEST_F(PluginTest, RecompileCompare) {
|
|||||||
|
|
||||||
// load model
|
// load model
|
||||||
std::array<char, 1000> error;
|
std::array<char, 1000> error;
|
||||||
mjSpec* model =
|
mjSpec* spec =
|
||||||
mjParseXML(xml.c_str(), nullptr, error.data(), error.size());
|
mjParseXML(xml.c_str(), nullptr, error.data(), error.size());
|
||||||
|
|
||||||
// compile twice
|
// compile twice
|
||||||
mjModel* m_old = mjm_compileModel(model, nullptr);
|
mjModel* m_old = mjm_compile(spec, nullptr);
|
||||||
mjModel* m_new = mjm_compileModel(model, nullptr);
|
mjModel* m_new = mjm_compile(spec, nullptr);
|
||||||
|
|
||||||
ASSERT_THAT(m_old, NotNull())
|
ASSERT_THAT(m_old, NotNull())
|
||||||
<< "Failed to compile " << xml << ": " << error.data();
|
<< "Failed to compile " << xml << ": " << error.data();
|
||||||
@@ -108,7 +108,7 @@ TEST_F(PluginTest, RecompileCompare) {
|
|||||||
<< "Different field: " << field << '\n';
|
<< "Different field: " << field << '\n';
|
||||||
|
|
||||||
// delete models
|
// delete models
|
||||||
mjm_deleteModel(model);
|
mjm_deleteSpec(spec);
|
||||||
mj_deleteModel(m_old);
|
mj_deleteModel(m_old);
|
||||||
mj_deleteModel(m_new);
|
mj_deleteModel(m_new);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user